r302: *** empty log message ***
[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.6 2000/12/18 09:55:22 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();\r
84   ImageFileView* ifView = dynamic_cast<ImageFileView*>(GetFirstView());\r
85   if (ifView)\r
86           ifView->OnUpdate(ifView, NULL);\r
87
88   return true;
89 }
90
91 bool ImageFileDocument::IsModified(void) const
92 {
93   return wxDocument::IsModified();
94 }
95
96 void ImageFileDocument::Modify(bool mod)
97 {
98     wxDocument::Modify(mod);
99 }
100
101 bool ImageFileDocument::OnCloseDocument ()
102 {
103   bool bReturn = wxDocument::OnCloseDocument();
104   return bReturn;
105 }
106
107 // ProjectionFileDocument
108
109 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileDocument, wxDocument)
110
111 bool ProjectionFileDocument::OnSaveDocument(const wxString& filename)
112 {
113   if (! m_projectionFile.write (filename.c_str())) {
114     *theApp->getLog() << "Unable to write projection file " << filename << "\n";
115     return false;
116   }
117   *theApp->getLog() << "Wrote projection file " << filename << "\n";
118   Modify(false);
119   return true;
120 }
121
122 bool ProjectionFileDocument::OnOpenDocument(const wxString& filename)
123 {
124   if (filename == "untitled.pj") {
125     wxString untitledFilename = theApp->getUntitledFilename();
126     SetFilename (untitledFilename, true);
127   } else {
128     if (! m_projectionFile.read (filename.c_str())) {
129       *theApp->getLog() << "Unable to read projection file " << filename << "\n";
130       return false;
131     }
132     *theApp->getLog() << "Read projection file " << filename << "\n";
133     SetFilename(filename, true);
134   }
135   Modify(false);
136   UpdateAllViews();
137   return true;
138 }
139
140 bool ProjectionFileDocument::IsModified(void) const
141 {
142   return wxDocument::IsModified();
143 }
144
145 void ProjectionFileDocument::Modify(bool mod)
146 {
147     wxDocument::Modify(mod);
148 }
149
150
151 bool ProjectionFileDocument::OnCloseDocument ()
152 {
153   bool bReturn = wxDocument::OnCloseDocument();
154   return bReturn;
155 }
156
157 // PhantomDocument
158
159 IMPLEMENT_DYNAMIC_CLASS(PhantomDocument, wxDocument)
160
161 bool PhantomDocument::OnOpenDocument(const wxString& filename)
162 {
163   wxString myFilename = filename;
164   if (wxFile::Exists (myFilename)) {
165     m_phantom.createFromFile (myFilename);
166     *theApp->getLog() << "Read phantom file " << filename << "\n";
167   } else {
168     myFilename.Replace (".phm", "");
169     m_phantom.createFromPhantom (myFilename);
170   }
171   m_namePhantom = myFilename;
172   SetFilename (myFilename, true);
173   if (m_phantom.fail()) {
174     *theApp->getLog() << "Failure creating phantom " << myFilename << "\n";
175     return false;
176   }
177   m_idPhantom = m_phantom.id();
178   Modify(false);
179   UpdateAllViews();
180   return true;
181 }
182
183 bool PhantomDocument::OnCloseDocument ()
184 {
185   bool bReturn = wxDocument::OnCloseDocument();
186   return bReturn;
187 }
188
189 bool PhantomDocument::IsModified(void) const
190 {
191   return wxDocument::IsModified();
192 }
193
194 void PhantomDocument::Modify(bool mod)
195 {
196     wxDocument::Modify(mod);
197 }
198