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.17 2001/01/30 02:20:50 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 (! OnSaveModified())
74 if (! m_imageFile.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 GetFirstView()->OnUpdate (GetFirstView(), NULL);
84 m_bBadFileOpen = false;
89 bool ImageFileDocument::IsModified(void) const
91 return wxDocument::IsModified();
94 void ImageFileDocument::Modify(bool mod)
96 wxDocument::Modify(mod);
100 ImageFileDocument::getView() const
102 return dynamic_cast<ImageFileView*>(GetFirstView());
105 // ProjectionFileDocument
107 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileDocument, wxDocument)
109 bool ProjectionFileDocument::OnSaveDocument(const wxString& filename)
111 if (! m_projectionFile.write (filename.c_str())) {
112 *theApp->getLog() << "Unable to write projection file " << filename << "\n";
115 *theApp->getLog() << "Wrote projection file " << filename << "\n";
120 bool ProjectionFileDocument::OnOpenDocument(const wxString& filename)
122 if (! OnSaveModified())
125 if (! m_projectionFile.read (filename.c_str())) {
126 *theApp->getLog() << "Unable to read projection file " << filename << "\n";
127 m_bBadFileOpen = true;
130 *theApp->getLog() << "Read projection file " << filename << "\n";
131 SetFilename(filename, true);
134 GetFirstView()->OnUpdate (GetFirstView(), NULL);
135 m_bBadFileOpen = false;
140 bool ProjectionFileDocument::IsModified(void) const
142 return wxDocument::IsModified();
145 void ProjectionFileDocument::Modify(bool mod)
147 wxDocument::Modify(mod);
152 ProjectionFileDocument::getView() const
154 return dynamic_cast<ProjectionFileView*>(GetFirstView());
157 // PhantomFileDocument
159 IMPLEMENT_DYNAMIC_CLASS(PhantomFileDocument, wxDocument)
161 bool PhantomFileDocument::OnOpenDocument(const wxString& filename)
163 if (! OnSaveModified())
166 wxString myFilename = filename;
167 if (wxFile::Exists (myFilename)) {
168 m_phantom.createFromFile (myFilename);
169 *theApp->getLog() << "Read phantom file " << filename << "\n";
171 myFilename.Replace (".phm", "");
172 m_phantom.createFromPhantom (myFilename);
174 m_namePhantom = myFilename;
175 SetFilename (myFilename, true);
176 if (m_phantom.fail()) {
177 *theApp->getLog() << "Failure creating phantom " << myFilename << "\n";
178 m_bBadFileOpen = true;
181 m_idPhantom = m_phantom.id();
184 GetFirstView()->OnUpdate (GetFirstView(), NULL);
185 m_bBadFileOpen = false;
190 bool PhantomFileDocument::OnSaveDocument(const wxString& filename)
192 if (! m_phantom.fileWrite (filename.c_str())) {
193 *theApp->getLog() << "Unable to write phantom file " << filename << "\n";
196 *theApp->getLog() << "Wrote phantom file " << filename << "\n";
201 bool PhantomFileDocument::IsModified(void) const
206 void PhantomFileDocument::Modify(bool mod)
208 wxDocument::Modify(mod);
213 PhantomFileDocument::getView() const
215 return dynamic_cast<PhantomFileView*>(GetFirstView());
220 IMPLEMENT_DYNAMIC_CLASS(PlotFileDocument, wxDocument)
222 bool PlotFileDocument::OnSaveDocument(const wxString& filename)
224 m_namePlot = filename.c_str();
225 if (! m_plot.fileWrite (filename)) {
226 *theApp->getLog() << "Unable to write plot file " << filename << "\n";
229 *theApp->getLog() << "Wrote plot file " << filename << "\n";
234 bool PlotFileDocument::OnOpenDocument(const wxString& filename)
236 if (! OnSaveModified())
239 if (! m_plot.fileRead (filename.c_str())) {
240 *theApp->getLog() << "Unable to read plot file " << filename << "\n";
241 m_bBadFileOpen = true;
244 *theApp->getLog() << "Read plot file " << filename << "\n";
245 SetFilename (filename, true);
246 m_namePlot = filename.c_str();
249 GetFirstView()->OnUpdate (NULL, NULL);
250 m_bBadFileOpen = false;
256 bool PlotFileDocument::IsModified(void) const
258 return wxDocument::IsModified();
261 void PlotFileDocument::Modify(bool mod)
263 wxDocument::Modify(mod);
267 PlotFileDocument::getView() const
269 return dynamic_cast<PlotFileView*>(GetFirstView());
272 //////////////////////////////////////////////////////////////////////////
276 //////////////////////////////////////////////////////////////////////////
278 IMPLEMENT_DYNAMIC_CLASS(TextFileDocument, wxDocument)
280 // Since text windows have their own method for saving to/loading from files,
281 // we override OnSave/OpenDocument instead of Save/LoadObject
282 bool TextFileDocument::OnSaveDocument(const wxString& filename)
284 TextFileView *view = getView();
285 if (! view->getTextCtrl()->SaveFile(filename))
291 bool TextFileDocument::OnOpenDocument(const wxString& filename)
293 TextFileView *view = getView();
295 if (! view->getTextCtrl()->LoadFile(filename)) {
296 m_bBadFileOpen = true;
300 SetFilename (filename, true);
303 m_bBadFileOpen = false;
307 bool TextFileDocument::IsModified(void) const
311 TextFileView *view = getView();
314 return (wxDocument::IsModified() || view->getTextCtrl()->IsModified());
316 return wxDocument::IsModified();
321 TextFileDocument::getView() const
323 return dynamic_cast<TextFileView*>(GetFirstView());
327 TextFileDocument::getTextCtrl()
329 return dynamic_cast<TextFileView*>(GetFirstView())->getTextCtrl();