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.14 2001/01/20 17:43:41 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 (filename == "untitled.if") {
72 wxString untitledFilename = theApp->getUntitledFilename();
73 SetFilename (untitledFilename, true);
75 if (! m_imageFile.fileRead (filename.c_str())) {
76 *theApp->getLog() << "Unable to read image file " << filename << "\n";
79 *theApp->getLog() << "Read image file " << filename << "\n";
80 SetFilename(filename, true);
84 GetFirstView()->OnUpdate (GetFirstView(), NULL);
89 bool ImageFileDocument::IsModified(void) const
91 return wxDocument::IsModified();
94 void ImageFileDocument::Modify(bool mod)
96 wxDocument::Modify(mod);
100 // ProjectionFileDocument
102 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileDocument, wxDocument)
104 bool ProjectionFileDocument::OnSaveDocument(const wxString& filename)
106 if (! m_projectionFile.write (filename.c_str())) {
107 *theApp->getLog() << "Unable to write projection file " << filename << "\n";
110 *theApp->getLog() << "Wrote projection file " << filename << "\n";
115 bool ProjectionFileDocument::OnOpenDocument(const wxString& filename)
117 if (filename == "untitled.pj") {
118 wxString untitledFilename = theApp->getUntitledFilename();
119 SetFilename (untitledFilename, true);
121 if (! m_projectionFile.read (filename.c_str())) {
122 *theApp->getLog() << "Unable to read projection file " << filename << "\n";
125 *theApp->getLog() << "Read projection file " << filename << "\n";
126 SetFilename(filename, true);
130 GetFirstView()->OnUpdate (GetFirstView(), NULL);
135 bool ProjectionFileDocument::IsModified(void) const
137 return wxDocument::IsModified();
140 void ProjectionFileDocument::Modify(bool mod)
142 wxDocument::Modify(mod);
149 IMPLEMENT_DYNAMIC_CLASS(PhantomDocument, wxDocument)
151 bool PhantomDocument::OnOpenDocument(const wxString& filename)
153 wxString myFilename = filename;
154 if (wxFile::Exists (myFilename)) {
155 m_phantom.createFromFile (myFilename);
156 *theApp->getLog() << "Read phantom file " << filename << "\n";
158 myFilename.Replace (".phm", "");
159 m_phantom.createFromPhantom (myFilename);
161 m_namePhantom = myFilename;
162 SetFilename (myFilename, true);
163 if (m_phantom.fail()) {
164 *theApp->getLog() << "Failure creating phantom " << myFilename << "\n";
167 m_idPhantom = m_phantom.id();
170 GetFirstView()->OnUpdate (GetFirstView(), NULL);
175 bool PhantomDocument::OnSaveDocument(const wxString& filename)
177 if (! m_phantom.fileWrite (filename.c_str())) {
178 *theApp->getLog() << "Unable to write phantom file " << filename << "\n";
181 *theApp->getLog() << "Wrote phantom file " << filename << "\n";
186 bool PhantomDocument::IsModified(void) const
191 void PhantomDocument::Modify(bool mod)
193 wxDocument::Modify(mod);
199 IMPLEMENT_DYNAMIC_CLASS(PlotFileDocument, wxDocument)
201 bool PlotFileDocument::OnSaveDocument(const wxString& filename)
203 m_namePlot = filename.c_str();
204 if (! m_plot.fileWrite (filename)) {
205 *theApp->getLog() << "Unable to write plot file " << filename << "\n";
208 *theApp->getLog() << "Wrote plot file " << filename << "\n";
213 bool PlotFileDocument::OnOpenDocument(const wxString& filename)
215 if (filename == "untitled.plt") {
216 wxString untitledFilename = theApp->getUntitledFilename();
217 SetFilename (untitledFilename, true);
219 if (! m_plot.fileRead (filename.c_str())) {
220 *theApp->getLog() << "Unable to read plot file " << filename << "\n";
223 *theApp->getLog() << "Read plot file " << filename << "\n";
224 SetFilename (filename, true);
225 m_namePlot = filename.c_str();
229 GetFirstView()->OnUpdate (NULL, NULL);
235 bool PlotFileDocument::IsModified(void) const
237 return wxDocument::IsModified();
240 void PlotFileDocument::Modify(bool mod)
242 wxDocument::Modify(mod);
246 //////////////////////////////////////////////////////////////////////////
250 //////////////////////////////////////////////////////////////////////////
252 IMPLEMENT_DYNAMIC_CLASS(TextEditDocument, wxDocument)
254 // Since text windows have their own method for saving to/loading from files,
255 // we override OnSave/OpenDocument instead of Save/LoadObject
256 bool TextEditDocument::OnSaveDocument(const wxString& filename)
258 TextEditView *view = dynamic_cast<TextEditView*>(GetFirstView());
259 if (! view->getTextCtrl()->SaveFile(filename))
265 bool TextEditDocument::OnOpenDocument(const wxString& filename)
267 TextEditView *view = dynamic_cast<TextEditView*>(GetFirstView());
269 if (filename != "Log.txt" && ! view->getTextCtrl()->LoadFile(filename))
272 SetFilename (filename, true);
278 bool TextEditDocument::IsModified(void) const
282 TextEditView *view = dynamic_cast<TextEditView*>(GetFirstView());
284 return (wxDocument::IsModified() || view->getTextCtrl()->IsModified());
286 return wxDocument::IsModified();