1 /*****************************************************************************
5 ** Purpose: Document routines for CTSim program
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: July 2000
9 ** This is part of the CTSim program
10 ** Copyright (c) 1983-2001 Kevin Rosenberg
12 ** $Id: docs.cpp,v 1.23 2001/02/03 18:42:21 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
29 // #pragma implementation
32 // For compilers that support precompilation, includes "wx/wx.h".
33 #include "wx/wxprec.h"
42 #include "wx/txtstrm.h"
45 #if !wxUSE_DOC_VIEW_ARCHITECTURE
46 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
56 IMPLEMENT_DYNAMIC_CLASS(ImageFileDocument, wxDocument)
58 bool ImageFileDocument::OnSaveDocument(const wxString& filename)
60 if (! m_pImageFile->fileWrite (filename)) {
61 *theApp->getLog() << "Unable to write image file " << filename << "\n";
64 *theApp->getLog() << "Wrote image file " << filename << "\n";
69 bool ImageFileDocument::OnOpenDocument(const wxString& filename)
71 if (! OnSaveModified())
74 if (! m_pImageFile->fileRead (filename.c_str())) {
75 *theApp->getLog() << "Unable to read image file " << filename << "\n";
76 m_bBadFileOpen = true;
79 *theApp->getLog() << "Read image file " << filename << "\n";
80 SetFilename(filename, true);
83 getView()->OnUpdate (getView(), NULL);
84 m_bBadFileOpen = false;
90 ImageFileDocument::IsModified(void) const
92 return wxDocument::IsModified();
96 ImageFileDocument::Modify(bool mod)
98 wxDocument::Modify(mod);
102 ImageFileDocument::getView() const
104 return dynamic_cast<ImageFileView*>(GetFirstView());
109 ImageFileDocument::Revert ()
112 wxString msg ("Revert to saved ");
113 msg += GetFilename();
115 wxMessageDialog dialog (getView()->getFrame(), msg, "Are you sure?", wxYES_NO | wxNO_DEFAULT);
116 if (dialog.ShowModal() == wxID_YES) {
117 *theApp->getLog() << "Reverting to saved " << GetFilename() << "\n";
119 OnOpenDocument (GetFilename());
122 getView()->OnUpdate (getView(), NULL);
128 // ProjectionFileDocument
130 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileDocument, wxDocument)
133 ProjectionFileDocument::OnSaveDocument(const wxString& filename)
135 if (! m_pProjectionFile->write (filename.c_str())) {
136 *theApp->getLog() << "Unable to write projection file " << filename << "\n";
139 *theApp->getLog() << "Wrote projection file " << filename << "\n";
145 ProjectionFileDocument::OnOpenDocument(const wxString& filename)
147 if (! OnSaveModified())
150 if (! m_pProjectionFile->read (filename.c_str())) {
151 *theApp->getLog() << "Unable to read projection file " << filename << "\n";
152 m_bBadFileOpen = true;
155 *theApp->getLog() << "Read projection file " << filename << "\n";
156 SetFilename(filename, true);
159 GetFirstView()->OnUpdate (GetFirstView(), NULL);
160 m_bBadFileOpen = false;
166 ProjectionFileDocument::IsModified(void) const
168 return wxDocument::IsModified();
172 ProjectionFileDocument::Modify(bool mod)
174 wxDocument::Modify(mod);
179 ProjectionFileDocument::getView() const
181 return dynamic_cast<ProjectionFileView*>(GetFirstView());
184 // PhantomFileDocument
186 IMPLEMENT_DYNAMIC_CLASS(PhantomFileDocument, wxDocument)
189 PhantomFileDocument::OnOpenDocument(const wxString& filename)
191 if (! OnSaveModified())
194 wxString myFilename = filename;
195 if (wxFile::Exists (myFilename)) {
196 m_phantom.createFromFile (myFilename);
197 *theApp->getLog() << "Read phantom file " << filename << "\n";
199 myFilename.Replace (".phm", "");
200 m_phantom.createFromPhantom (myFilename);
202 m_namePhantom = myFilename;
203 SetFilename (myFilename, true);
204 if (m_phantom.fail()) {
205 *theApp->getLog() << "Failure creating phantom " << myFilename << "\n";
206 m_bBadFileOpen = true;
209 m_idPhantom = m_phantom.id();
212 GetFirstView()->OnUpdate (GetFirstView(), NULL);
213 m_bBadFileOpen = false;
219 PhantomFileDocument::OnSaveDocument(const wxString& filename)
221 if (! m_phantom.fileWrite (filename.c_str())) {
222 *theApp->getLog() << "Unable to write phantom file " << filename << "\n";
225 *theApp->getLog() << "Wrote phantom file " << filename << "\n";
231 PhantomFileDocument::IsModified(void) const
237 PhantomFileDocument::Modify(bool mod)
239 wxDocument::Modify(mod);
244 PhantomFileDocument::getView() const
246 return dynamic_cast<PhantomFileView*>(GetFirstView());
251 IMPLEMENT_DYNAMIC_CLASS(PlotFileDocument, wxDocument)
254 PlotFileDocument::OnSaveDocument(const wxString& filename)
256 m_namePlot = filename.c_str();
257 if (! m_plot.fileWrite (filename)) {
258 *theApp->getLog() << "Unable to write plot file " << filename << "\n";
261 *theApp->getLog() << "Wrote plot file " << filename << "\n";
267 PlotFileDocument::OnOpenDocument(const wxString& filename)
269 if (! OnSaveModified())
272 if (! m_plot.fileRead (filename.c_str())) {
273 *theApp->getLog() << "Unable to read plot file " << filename << "\n";
274 m_bBadFileOpen = true;
277 *theApp->getLog() << "Read plot file " << filename << "\n";
278 SetFilename (filename, true);
279 m_namePlot = filename.c_str();
282 GetFirstView()->OnUpdate (NULL, NULL);
283 m_bBadFileOpen = false;
290 PlotFileDocument::IsModified(void) const
292 return wxDocument::IsModified();
296 PlotFileDocument::Modify (bool mod)
298 wxDocument::Modify(mod);
302 PlotFileDocument::getView() const
304 return dynamic_cast<PlotFileView*>(GetFirstView());
307 //////////////////////////////////////////////////////////////////////////
311 //////////////////////////////////////////////////////////////////////////
313 IMPLEMENT_DYNAMIC_CLASS(TextFileDocument, wxDocument)
316 TextFileDocument::OnSaveDocument(const wxString& filename)
318 TextFileView *view = getView();
319 if (! view->getTextCtrl()->SaveFile(filename))
326 TextFileDocument::OnOpenDocument(const wxString& filename)
328 TextFileView *view = getView();
330 if (! view->getTextCtrl()->LoadFile(filename)) {
331 m_bBadFileOpen = true;
335 SetFilename (filename, true);
338 m_bBadFileOpen = false;
343 TextFileDocument::IsModified(void) const
347 TextFileView *view = getView();
350 return (wxDocument::IsModified() || view->getTextCtrl()->IsModified());
352 return wxDocument::IsModified();
357 TextFileDocument::getView() const
359 return dynamic_cast<TextFileView*>(GetFirstView());
363 TextFileDocument::getTextCtrl()
365 return dynamic_cast<TextFileView*>(GetFirstView())->getTextCtrl();
368 //////////////////////////////////////////////////////////////////////////
370 // Graph3dFileDocument
372 //////////////////////////////////////////////////////////////////////////
376 IMPLEMENT_DYNAMIC_CLASS(Graph3dFileDocument, wxDocument)
378 Graph3dFileDocument::Graph3dFileDocument(void)
379 : m_bBadFileOpen(false), m_nVertices(0), m_pVertices(0), m_pNormals(0),m_nx(0),m_ny(0),m_array(0)
383 Graph3dFileDocument::~Graph3dFileDocument()
385 // delete [] m_pVertices;
386 // delete [] m_pNormals;
390 Graph3dFileDocument::OnSaveDocument(const wxString& filename)
397 Graph3dFileDocument::OnOpenDocument(const wxString& filename)
399 SetFilename (filename, true);
402 m_bBadFileOpen = false;
407 Graph3dFileDocument::IsModified(void) const
409 return wxDocument::IsModified();
414 Graph3dFileDocument::getView() const
416 return dynamic_cast<Graph3dFileView*>(GetFirstView());
420 Graph3dFileDocument::createFromImageFile (const ImageFile& rImageFile)
422 // delete [] m_pVertices;
423 // delete [] m_pNormals;
426 m_nx = rImageFile.nx();
427 m_ny = rImageFile.ny();
428 m_array = rImageFile.getArray();
433 #endif // wxUSE_GLCANVAS