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-2000 Kevin Rosenberg
12 ** $Id: docs.cpp,v 1.15 2001/01/26 05:37:24 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_imageFile.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 (! m_imageFile.fileRead (filename.c_str())) {
72 *theApp->getLog() << "Unable to read image file " << filename << "\n";
75 *theApp->getLog() << "Read image file " << filename << "\n";
76 SetFilename(filename, true);
80 GetFirstView()->OnUpdate (GetFirstView(), NULL);
85 bool ImageFileDocument::IsModified(void) const
87 return wxDocument::IsModified();
90 void ImageFileDocument::Modify(bool mod)
92 wxDocument::Modify(mod);
96 ImageFileDocument::getView() const
98 return dynamic_cast<ImageFileView*>(GetFirstView());
101 // ProjectionFileDocument
103 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileDocument, wxDocument)
105 bool ProjectionFileDocument::OnSaveDocument(const wxString& filename)
107 if (! m_projectionFile.write (filename.c_str())) {
108 *theApp->getLog() << "Unable to write projection file " << filename << "\n";
111 *theApp->getLog() << "Wrote projection file " << filename << "\n";
116 bool ProjectionFileDocument::OnOpenDocument(const wxString& filename)
118 if (! m_projectionFile.read (filename.c_str())) {
119 *theApp->getLog() << "Unable to read projection file " << filename << "\n";
122 *theApp->getLog() << "Read projection file " << filename << "\n";
123 SetFilename(filename, true);
126 GetFirstView()->OnUpdate (GetFirstView(), NULL);
131 bool ProjectionFileDocument::IsModified(void) const
133 return wxDocument::IsModified();
136 void ProjectionFileDocument::Modify(bool mod)
138 wxDocument::Modify(mod);
143 ProjectionFileDocument::getView() const
145 return dynamic_cast<ProjectionFileView*>(GetFirstView());
148 // PhantomFileDocument
150 IMPLEMENT_DYNAMIC_CLASS(PhantomFileDocument, wxDocument)
152 bool PhantomFileDocument::OnOpenDocument(const wxString& filename)
154 wxString myFilename = filename;
155 if (wxFile::Exists (myFilename)) {
156 m_phantom.createFromFile (myFilename);
157 *theApp->getLog() << "Read phantom file " << filename << "\n";
159 myFilename.Replace (".phm", "");
160 m_phantom.createFromPhantom (myFilename);
162 m_namePhantom = myFilename;
163 SetFilename (myFilename, true);
164 if (m_phantom.fail()) {
165 *theApp->getLog() << "Failure creating phantom " << myFilename << "\n";
168 m_idPhantom = m_phantom.id();
171 GetFirstView()->OnUpdate (GetFirstView(), NULL);
176 bool PhantomFileDocument::OnSaveDocument(const wxString& filename)
178 if (! m_phantom.fileWrite (filename.c_str())) {
179 *theApp->getLog() << "Unable to write phantom file " << filename << "\n";
182 *theApp->getLog() << "Wrote phantom file " << filename << "\n";
187 bool PhantomFileDocument::IsModified(void) const
192 void PhantomFileDocument::Modify(bool mod)
194 wxDocument::Modify(mod);
199 PhantomFileDocument::getView() const
201 return dynamic_cast<PhantomFileView*>(GetFirstView());
206 IMPLEMENT_DYNAMIC_CLASS(PlotFileDocument, wxDocument)
208 bool PlotFileDocument::OnSaveDocument(const wxString& filename)
210 m_namePlot = filename.c_str();
211 if (! m_plot.fileWrite (filename)) {
212 *theApp->getLog() << "Unable to write plot file " << filename << "\n";
215 *theApp->getLog() << "Wrote plot file " << filename << "\n";
220 bool PlotFileDocument::OnOpenDocument(const wxString& filename)
222 if (! m_plot.fileRead (filename.c_str())) {
223 *theApp->getLog() << "Unable to read plot file " << filename << "\n";
226 *theApp->getLog() << "Read plot file " << filename << "\n";
227 SetFilename (filename, true);
228 m_namePlot = filename.c_str();
231 GetFirstView()->OnUpdate (NULL, NULL);
237 bool PlotFileDocument::IsModified(void) const
239 return wxDocument::IsModified();
242 void PlotFileDocument::Modify(bool mod)
244 wxDocument::Modify(mod);
248 PlotFileDocument::getView() const
250 return dynamic_cast<PlotFileView*>(GetFirstView());
253 //////////////////////////////////////////////////////////////////////////
257 //////////////////////////////////////////////////////////////////////////
259 IMPLEMENT_DYNAMIC_CLASS(TextFileDocument, wxDocument)
261 // Since text windows have their own method for saving to/loading from files,
262 // we override OnSave/OpenDocument instead of Save/LoadObject
263 bool TextFileDocument::OnSaveDocument(const wxString& filename)
265 TextFileView *view = getView();
266 if (! view->getTextCtrl()->SaveFile(filename))
272 bool TextFileDocument::OnOpenDocument(const wxString& filename)
274 TextFileView *view = getView();
276 if (! view->getTextCtrl()->LoadFile(filename))
279 SetFilename (filename, true);
285 bool TextFileDocument::IsModified(void) const
289 TextFileView *view = getView();
292 return (wxDocument::IsModified() || view->getTextCtrl()->IsModified());
294 return wxDocument::IsModified();
299 TextFileDocument::getView() const
301 return dynamic_cast<TextFileView*>(GetFirstView());