6722ef5946b874408639e4ad7cedae90fe47750c
[ctsim.git] / src / docs.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          doc.cpp
5 **   Purpose:       Document routines for CTSim program
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  July 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: docs.cpp,v 1.3 2000/09/07 01:28:33 kevin Exp $
13 **
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.
17 **
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.
22 **
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 ******************************************************************************/
27
28 #ifdef __GNUG__
29 // #pragma implementation
30 #endif
31
32 // For compilers that support precompilation, includes "wx/wx.h".
33 #include "wx/wxprec.h"
34
35 #ifdef __BORLANDC__
36 #pragma hdrstop
37 #endif
38
39 #ifndef WX_PRECOMP
40 #include "wx/wx.h"
41 #endif
42 #include "wx/txtstrm.h"
43 #include "wx/file.h"
44
45 #if !wxUSE_DOC_VIEW_ARCHITECTURE
46 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
47 #endif
48
49 #include "ct.h"
50 #include "ctsim.h"
51 #include "docs.h"
52 #include "views.h"
53
54
55 // ImageFileDocument
56
57 IMPLEMENT_DYNAMIC_CLASS(ImageFileDocument, wxDocument)
58
59 bool ImageFileDocument::OnSaveDocument(const wxString& filename)
60 {
61   if (! m_imageFile.fileWrite (filename)) {
62     *theApp->getLog() << "Unable to write image file " << filename << "\n";
63     return false;
64   }
65   *theApp->getLog() << "Wrote image file " << filename << "\n";
66   Modify(false);
67   return true;
68 }
69
70 bool ImageFileDocument::OnOpenDocument(const wxString& filename)
71 {
72   if (filename == "untitled.if") {
73     wxString untitledFilename = theApp->getUntitledFilename();
74     SetFilename (untitledFilename, true);
75   } else {
76     if (! m_imageFile.fileRead (filename)) {
77       *theApp->getLog() << "Unable to read image file " << filename << "\n";
78       return false;
79     }
80     *theApp->getLog() << "Read image file " << filename << "\n";
81     SetFilename(filename, true);
82   }
83   Modify(false);
84   UpdateAllViews();
85   return true;
86 }
87
88 bool ImageFileDocument::IsModified(void) const
89 {
90   return wxDocument::IsModified();
91 }
92
93 void ImageFileDocument::Modify(bool mod)
94 {
95     wxDocument::Modify(mod);
96 }
97
98 bool ImageFileDocument::OnCloseDocument ()
99 {
100   bool bReturn = wxDocument::OnCloseDocument();
101   return bReturn;
102 }
103
104 // ProjectionFileDocument
105
106 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileDocument, wxDocument)
107
108 bool ProjectionFileDocument::OnSaveDocument(const wxString& filename)
109 {
110   if (! m_projectionFile.write (filename)) {
111     *theApp->getLog() << "Unable to write projection file " << filename << "\n";
112     return false;
113   }
114   *theApp->getLog() << "Wrote projection file " << filename << "\n";
115   Modify(false);
116   return true;
117 }
118
119 bool ProjectionFileDocument::OnOpenDocument(const wxString& filename)
120 {
121   if (filename == "untitled.pj") {
122     wxString untitledFilename = theApp->getUntitledFilename();
123     SetFilename (untitledFilename, true);
124   } else {
125     if (! m_projectionFile.read (filename)) {
126       *theApp->getLog() << "Unable to read projection file " << filename << "\n";
127       return false;
128     }
129     *theApp->getLog() << "Read projection file " << filename << "\n";
130     SetFilename(filename, true);
131   }
132   Modify(false);
133   UpdateAllViews();
134   return true;
135 }
136
137 bool ProjectionFileDocument::IsModified(void) const
138 {
139   return wxDocument::IsModified();
140 }
141
142 void ProjectionFileDocument::Modify(bool mod)
143 {
144     wxDocument::Modify(mod);
145 }
146
147
148 bool ProjectionFileDocument::OnCloseDocument ()
149 {
150   bool bReturn = wxDocument::OnCloseDocument();
151   return bReturn;
152 }
153
154 // PhantomDocument
155
156 IMPLEMENT_DYNAMIC_CLASS(PhantomDocument, wxDocument)
157
158 bool PhantomDocument::OnOpenDocument(const wxString& filename)
159 {
160   wxString myFilename = filename;
161   if (wxFile::Exists (myFilename)) {
162     m_phantom.createFromFile (myFilename);
163     *theApp->getLog() << "Read phantom file " << filename << "\n";
164   } else {
165     myFilename.Replace (".phm", "");
166     m_phantom.createFromPhantom (myFilename);
167   }
168   m_namePhantom = myFilename;
169   SetFilename (myFilename, true);
170   if (m_phantom.fail()) {
171     *theApp->getLog() << "Failure creating phantom " << myFilename << "\n";
172     return false;
173   }
174   m_idPhantom = m_phantom.id();
175   Modify(false);
176   UpdateAllViews();
177   return true;
178 }
179
180 bool PhantomDocument::OnCloseDocument ()
181 {
182   bool bReturn = wxDocument::OnCloseDocument();
183   return bReturn;
184 }
185
186 bool PhantomDocument::IsModified(void) const
187 {
188   return wxDocument::IsModified();
189 }
190
191 void PhantomDocument::Modify(bool mod)
192 {
193     wxDocument::Modify(mod);
194 }
195