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.24 2001/02/21 20:13:03 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 if (theApp->getVerboseLogging())
65 *theApp->getLog() << "Wrote image file " << filename << "\n";
70 bool ImageFileDocument::OnOpenDocument(const wxString& filename)
72 if (! OnSaveModified())
75 if (! m_pImageFile->fileRead (filename.c_str())) {
76 *theApp->getLog() << "Unable to read image file " << filename << "\n";
77 m_bBadFileOpen = true;
80 if (theApp->getVerboseLogging())
81 *theApp->getLog() << "Read image file " << filename << "\n";
82 SetFilename(filename, true);
85 getView()->OnUpdate (getView(), NULL);
86 m_bBadFileOpen = false;
92 ImageFileDocument::IsModified(void) const
94 return wxDocument::IsModified();
98 ImageFileDocument::Modify(bool mod)
100 wxDocument::Modify(mod);
104 ImageFileDocument::getView() const
106 return dynamic_cast<ImageFileView*>(GetFirstView());
111 ImageFileDocument::Revert ()
114 wxString msg ("Revert to saved ");
115 msg += GetFilename();
117 wxMessageDialog dialog (getView()->getFrame(), msg, "Are you sure?", wxYES_NO | wxNO_DEFAULT);
118 if (dialog.ShowModal() == wxID_YES) {
119 if (theApp->getVerboseLogging())
120 *theApp->getLog() << "Reverting to saved " << GetFilename() << "\n";
122 OnOpenDocument (GetFilename());
125 getView()->OnUpdate (getView(), NULL);
131 // ProjectionFileDocument
133 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileDocument, wxDocument)
136 ProjectionFileDocument::OnSaveDocument(const wxString& filename)
138 if (! m_pProjectionFile->write (filename.c_str())) {
139 *theApp->getLog() << "Unable to write projection file " << filename << "\n";
142 if (theApp->getVerboseLogging())
143 *theApp->getLog() << "Wrote projection file " << filename << "\n";
149 ProjectionFileDocument::OnOpenDocument(const wxString& filename)
151 if (! OnSaveModified())
154 if (! m_pProjectionFile->read (filename.c_str())) {
155 *theApp->getLog() << "Unable to read projection file " << filename << "\n";
156 m_bBadFileOpen = true;
159 if (theApp->getVerboseLogging())
160 *theApp->getLog() << "Read projection file " << filename << "\n";
161 SetFilename(filename, true);
164 GetFirstView()->OnUpdate (GetFirstView(), NULL);
165 m_bBadFileOpen = false;
171 ProjectionFileDocument::IsModified(void) const
173 return wxDocument::IsModified();
177 ProjectionFileDocument::Modify(bool mod)
179 wxDocument::Modify(mod);
184 ProjectionFileDocument::getView() const
186 return dynamic_cast<ProjectionFileView*>(GetFirstView());
189 // PhantomFileDocument
191 IMPLEMENT_DYNAMIC_CLASS(PhantomFileDocument, wxDocument)
194 PhantomFileDocument::OnOpenDocument(const wxString& filename)
196 if (! OnSaveModified())
199 wxString myFilename = filename;
200 if (wxFile::Exists (myFilename)) {
201 m_phantom.createFromFile (myFilename);
202 if (theApp->getVerboseLogging())
203 *theApp->getLog() << "Read phantom file " << filename << "\n";
205 myFilename.Replace (".phm", "");
206 m_phantom.createFromPhantom (myFilename);
208 m_namePhantom = myFilename;
209 SetFilename (myFilename, true);
210 if (m_phantom.fail()) {
211 *theApp->getLog() << "Failure creating phantom " << myFilename << "\n";
212 m_bBadFileOpen = true;
215 m_idPhantom = m_phantom.id();
218 GetFirstView()->OnUpdate (GetFirstView(), NULL);
219 m_bBadFileOpen = false;
225 PhantomFileDocument::OnSaveDocument(const wxString& filename)
227 if (! m_phantom.fileWrite (filename.c_str())) {
228 *theApp->getLog() << "Unable to write phantom file " << filename << "\n";
231 if (theApp->getVerboseLogging())
232 *theApp->getLog() << "Wrote phantom file " << filename << "\n";
238 PhantomFileDocument::IsModified(void) const
244 PhantomFileDocument::Modify(bool mod)
246 wxDocument::Modify(mod);
251 PhantomFileDocument::getView() const
253 return dynamic_cast<PhantomFileView*>(GetFirstView());
258 IMPLEMENT_DYNAMIC_CLASS(PlotFileDocument, wxDocument)
261 PlotFileDocument::OnSaveDocument(const wxString& filename)
263 m_namePlot = filename.c_str();
264 if (! m_plot.fileWrite (filename)) {
265 *theApp->getLog() << "Unable to write plot file " << filename << "\n";
268 if (theApp->getVerboseLogging())
269 *theApp->getLog() << "Wrote plot file " << filename << "\n";
275 PlotFileDocument::OnOpenDocument(const wxString& filename)
277 if (! OnSaveModified())
280 if (! m_plot.fileRead (filename.c_str())) {
281 *theApp->getLog() << "Unable to read plot file " << filename << "\n";
282 m_bBadFileOpen = true;
285 if (theApp->getVerboseLogging())
286 *theApp->getLog() << "Read plot file " << filename << "\n";
287 SetFilename (filename, true);
288 m_namePlot = filename.c_str();
291 GetFirstView()->OnUpdate (NULL, NULL);
292 m_bBadFileOpen = false;
299 PlotFileDocument::IsModified(void) const
301 return wxDocument::IsModified();
305 PlotFileDocument::Modify (bool mod)
307 wxDocument::Modify(mod);
311 PlotFileDocument::getView() const
313 return dynamic_cast<PlotFileView*>(GetFirstView());
316 //////////////////////////////////////////////////////////////////////////
320 //////////////////////////////////////////////////////////////////////////
322 IMPLEMENT_DYNAMIC_CLASS(TextFileDocument, wxDocument)
325 TextFileDocument::OnSaveDocument(const wxString& filename)
327 TextFileView *view = getView();
328 if (! view->getTextCtrl()->SaveFile(filename))
335 TextFileDocument::OnOpenDocument(const wxString& filename)
337 TextFileView *view = getView();
339 if (! view->getTextCtrl()->LoadFile(filename)) {
340 m_bBadFileOpen = true;
344 SetFilename (filename, true);
347 m_bBadFileOpen = false;
352 TextFileDocument::IsModified(void) const
356 TextFileView *view = getView();
359 return (wxDocument::IsModified() || view->getTextCtrl()->IsModified());
361 return wxDocument::IsModified();
366 TextFileDocument::getView() const
368 return dynamic_cast<TextFileView*>(GetFirstView());
372 TextFileDocument::getTextCtrl()
374 return dynamic_cast<TextFileView*>(GetFirstView())->getTextCtrl();
377 //////////////////////////////////////////////////////////////////////////
379 // Graph3dFileDocument
381 //////////////////////////////////////////////////////////////////////////
385 IMPLEMENT_DYNAMIC_CLASS(Graph3dFileDocument, wxDocument)
387 Graph3dFileDocument::Graph3dFileDocument(void)
388 : m_bBadFileOpen(false), m_nVertices(0), m_pVertices(0), m_pNormals(0),m_nx(0),m_ny(0),m_array(0)
392 Graph3dFileDocument::~Graph3dFileDocument()
394 // delete [] m_pVertices;
395 // delete [] m_pNormals;
399 Graph3dFileDocument::OnSaveDocument(const wxString& filename)
406 Graph3dFileDocument::OnOpenDocument(const wxString& filename)
408 SetFilename (filename, true);
411 m_bBadFileOpen = false;
416 Graph3dFileDocument::IsModified(void) const
418 return wxDocument::IsModified();
423 Graph3dFileDocument::getView() const
425 return dynamic_cast<Graph3dFileView*>(GetFirstView());
429 Graph3dFileDocument::createFromImageFile (const ImageFile& rImageFile)
431 // delete [] m_pVertices;
432 // delete [] m_pNormals;
435 m_nx = rImageFile.nx();
436 m_ny = rImageFile.ny();
437 m_array = rImageFile.getArray();
442 #endif // wxUSE_GLCANVAS