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.12 2001/01/06 15:33:15 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);
99 bool ImageFileDocument::OnCloseDocument ()
101 bool bReturn = wxDocument::OnCloseDocument();
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 (filename == "untitled.pj") {
123 wxString untitledFilename = theApp->getUntitledFilename();
124 SetFilename (untitledFilename, true);
126 if (! m_projectionFile.read (filename.c_str())) {
127 *theApp->getLog() << "Unable to read projection file " << filename << "\n";
130 *theApp->getLog() << "Read projection file " << filename << "\n";
131 SetFilename(filename, true);
135 GetFirstView()->OnUpdate (GetFirstView(), NULL);
140 bool ProjectionFileDocument::IsModified(void) const
142 return wxDocument::IsModified();
145 void ProjectionFileDocument::Modify(bool mod)
147 wxDocument::Modify(mod);
151 bool ProjectionFileDocument::OnCloseDocument ()
153 bool bReturn = wxDocument::OnCloseDocument();
159 IMPLEMENT_DYNAMIC_CLASS(PhantomDocument, wxDocument)
161 bool PhantomDocument::OnOpenDocument(const wxString& filename)
163 wxString myFilename = filename;
164 if (wxFile::Exists (myFilename)) {
165 m_phantom.createFromFile (myFilename);
166 *theApp->getLog() << "Read phantom file " << filename << "\n";
168 myFilename.Replace (".phm", "");
169 m_phantom.createFromPhantom (myFilename);
171 m_namePhantom = myFilename;
172 SetFilename (myFilename, true);
173 if (m_phantom.fail()) {
174 *theApp->getLog() << "Failure creating phantom " << myFilename << "\n";
177 m_idPhantom = m_phantom.id();
180 GetFirstView()->OnUpdate (GetFirstView(), NULL);
185 bool PhantomDocument::OnSaveDocument(const wxString& filename)
187 if (! m_phantom.fileWrite (filename.c_str())) {
188 *theApp->getLog() << "Unable to write phantom file " << filename << "\n";
191 *theApp->getLog() << "Wrote phantom file " << filename << "\n";
196 bool PhantomDocument::OnCloseDocument ()
198 bool bReturn = wxDocument::OnCloseDocument();
202 bool PhantomDocument::IsModified(void) const
204 return wxDocument::IsModified();
207 void PhantomDocument::Modify(bool mod)
209 wxDocument::Modify(mod);
215 IMPLEMENT_DYNAMIC_CLASS(PlotFileDocument, wxDocument)
217 bool PlotFileDocument::OnSaveDocument(const wxString& filename)
219 m_namePlot = filename.c_str();
220 if (! m_plot.fileWrite (filename)) {
221 *theApp->getLog() << "Unable to write plot file " << filename << "\n";
224 *theApp->getLog() << "Wrote plot file " << filename << "\n";
229 bool PlotFileDocument::OnOpenDocument(const wxString& filename)
231 if (filename == "untitled.plt") {
232 wxString untitledFilename = theApp->getUntitledFilename();
233 SetFilename (untitledFilename, true);
235 if (! m_plot.fileRead (filename.c_str())) {
236 *theApp->getLog() << "Unable to read plot file " << filename << "\n";
239 *theApp->getLog() << "Read plot file " << filename << "\n";
240 SetFilename (filename, true);
241 m_namePlot = filename.c_str();
245 GetFirstView()->OnUpdate (NULL, NULL);
250 bool PlotFileDocument::OnCloseDocument ()
252 bool bReturn = wxDocument::OnCloseDocument();
256 bool PlotFileDocument::IsModified(void) const
258 return wxDocument::IsModified();
261 void PlotFileDocument::Modify(bool mod)
263 wxDocument::Modify(mod);