r348: fix linefeed problem
[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.11 2001/01/02 16:02:13 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 // ImageFileDocument
55
56 IMPLEMENT_DYNAMIC_CLASS(ImageFileDocument, wxDocument)
57
58 bool ImageFileDocument::OnSaveDocument(const wxString& filename)
59 {
60   if (! m_imageFile.fileWrite (filename)) {
61     *theApp->getLog() << "Unable to write image file " << filename << "\n";
62     return false;
63   }
64   *theApp->getLog() << "Wrote image file " << filename << "\n";
65   Modify(false);
66   return true;
67 }
68
69 bool ImageFileDocument::OnOpenDocument(const wxString& filename)
70 {
71   if (filename == "untitled.if") {
72     wxString untitledFilename = theApp->getUntitledFilename();
73     SetFilename (untitledFilename, true);
74   } else {
75     if (! m_imageFile.fileRead (filename.c_str())) {
76       *theApp->getLog() << "Unable to read image file " << filename << "\n";
77       return false;
78     }
79     *theApp->getLog() << "Read image file " << filename << "\n";
80     SetFilename(filename, true);
81   }
82   Modify(false);
83   UpdateAllViews();
84   GetFirstView()->OnUpdate (GetFirstView(), NULL);
85
86   return true;
87 }
88
89 bool ImageFileDocument::IsModified(void) const
90 {
91   return wxDocument::IsModified();
92 }
93
94 void ImageFileDocument::Modify(bool mod)
95 {
96     wxDocument::Modify(mod);
97 }
98
99 bool ImageFileDocument::OnCloseDocument ()
100 {
101   bool bReturn = wxDocument::OnCloseDocument();
102   return bReturn;
103 }
104
105 // ProjectionFileDocument
106
107 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileDocument, wxDocument)
108
109 bool ProjectionFileDocument::OnSaveDocument(const wxString& filename)
110 {
111   if (! m_projectionFile.write (filename.c_str())) {
112     *theApp->getLog() << "Unable to write projection file " << filename << "\n";
113     return false;
114   }
115   *theApp->getLog() << "Wrote projection file " << filename << "\n";
116   Modify(false);
117   return true;
118 }
119
120 bool ProjectionFileDocument::OnOpenDocument(const wxString& filename)
121 {
122   if (filename == "untitled.pj") {
123     wxString untitledFilename = theApp->getUntitledFilename();
124     SetFilename (untitledFilename, true);
125   } else {
126     if (! m_projectionFile.read (filename.c_str())) {
127       *theApp->getLog() << "Unable to read projection file " << filename << "\n";
128       return false;
129     }
130     *theApp->getLog() << "Read projection file " << filename << "\n";
131     SetFilename(filename, true);
132   }
133   Modify(false);
134   UpdateAllViews();
135
136   return true;
137 }
138
139 bool ProjectionFileDocument::IsModified(void) const
140 {
141   return wxDocument::IsModified();
142 }
143
144 void ProjectionFileDocument::Modify(bool mod)
145 {
146     wxDocument::Modify(mod);
147 }
148
149
150 bool ProjectionFileDocument::OnCloseDocument ()
151 {
152   bool bReturn = wxDocument::OnCloseDocument();
153   return bReturn;
154 }
155
156 // PhantomDocument
157
158 IMPLEMENT_DYNAMIC_CLASS(PhantomDocument, wxDocument)
159
160 bool PhantomDocument::OnOpenDocument(const wxString& filename)
161 {
162   wxString myFilename = filename;
163   if (wxFile::Exists (myFilename)) {
164     m_phantom.createFromFile (myFilename);
165     *theApp->getLog() << "Read phantom file " << filename << "\n";
166   } else {
167     myFilename.Replace (".phm", "");
168     m_phantom.createFromPhantom (myFilename);
169   }
170   m_namePhantom = myFilename;
171   SetFilename (myFilename, true);
172   if (m_phantom.fail()) {
173     *theApp->getLog() << "Failure creating phantom " << myFilename << "\n";
174     return false;
175   }
176   m_idPhantom = m_phantom.id();
177   Modify(false);
178   UpdateAllViews();
179
180   return true;
181 }
182
183 bool PhantomDocument::OnSaveDocument(const wxString& filename)
184 {
185   if (! m_phantom.fileWrite (filename.c_str())) {
186     *theApp->getLog() << "Unable to write phantom file " << filename << "\n";
187     return false;
188   }
189   *theApp->getLog() << "Wrote phantom file " << filename << "\n";
190   Modify(false);
191   return true;
192 }
193
194 bool PhantomDocument::OnCloseDocument ()
195 {
196   bool bReturn = wxDocument::OnCloseDocument();
197   return bReturn;
198 }
199
200 bool PhantomDocument::IsModified(void) const
201 {
202   return wxDocument::IsModified();
203 }
204
205 void PhantomDocument::Modify(bool mod)
206 {
207     wxDocument::Modify(mod);
208 }
209
210
211 // PlotFileDocument
212
213 IMPLEMENT_DYNAMIC_CLASS(PlotFileDocument, wxDocument)
214
215 bool PlotFileDocument::OnSaveDocument(const wxString& filename)
216 {
217   m_namePlot = filename.c_str();
218   if (! m_plot.fileWrite (filename)) {
219     *theApp->getLog() << "Unable to write plot file " << filename << "\n";
220     return false;
221   }
222   *theApp->getLog() << "Wrote plot file " << filename << "\n";
223   Modify(false);
224   return true;
225 }
226
227 bool PlotFileDocument::OnOpenDocument(const wxString& filename)
228 {
229   if (filename == "untitled.plt") {
230     wxString untitledFilename = theApp->getUntitledFilename();
231     SetFilename (untitledFilename, true);
232   } else {
233     if (! m_plot.fileRead (filename.c_str())) {
234       *theApp->getLog() << "Unable to read plot file " << filename << "\n";
235       return false;
236     }
237     *theApp->getLog() << "Read plot file " << filename << "\n";
238     SetFilename (filename, true);
239     m_namePlot = filename.c_str();
240   }
241   Modify (false);
242   UpdateAllViews();
243   GetFirstView()->OnUpdate (NULL, NULL);
244
245   return true;
246 }
247
248 bool PlotFileDocument::OnCloseDocument ()
249 {
250   bool bReturn = wxDocument::OnCloseDocument();
251   return bReturn;
252 }
253
254 bool PlotFileDocument::IsModified(void) const
255 {
256   return wxDocument::IsModified();
257 }
258
259 void PlotFileDocument::Modify(bool mod)
260 {
261     wxDocument::Modify(mod);
262 }
263