r148: *** 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.2 2000/07/15 08:36: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
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 // ProjectionFileDocument
99
100 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileDocument, wxDocument)
101
102 bool ProjectionFileDocument::OnSaveDocument(const wxString& filename)
103 {
104   if (! m_projectionFile.write (filename)) {
105     *theApp->getLog() << "Unable to write projection file " << filename << "\n";
106     return false;
107   }
108   *theApp->getLog() << "Wrote projection file " << filename << "\n";
109   Modify(false);
110   return true;
111 }
112
113 bool ProjectionFileDocument::OnOpenDocument(const wxString& filename)
114 {
115   if (filename == "untitled.pj") {
116     wxString untitledFilename = theApp->getUntitledFilename();
117     SetFilename (untitledFilename, true);
118   } else {
119     if (! m_projectionFile.read (filename)) {
120       *theApp->getLog() << "Unable to read projection file " << filename << "\n";
121       return false;
122     }
123     *theApp->getLog() << "Read projection file " << filename << "\n";
124     SetFilename(filename, true);
125   }
126   Modify(false);
127   UpdateAllViews();
128   return true;
129 }
130
131 bool ProjectionFileDocument::IsModified(void) const
132 {
133   return wxDocument::IsModified();
134 }
135
136 void ProjectionFileDocument::Modify(bool mod)
137 {
138     wxDocument::Modify(mod);
139 }
140
141
142 // PhantomDocument
143
144 IMPLEMENT_DYNAMIC_CLASS(PhantomDocument, wxDocument)
145
146 bool PhantomDocument::OnOpenDocument(const wxString& filename)
147 {
148   wxString myFilename = filename;
149   if (wxFile::Exists (myFilename)) {
150     m_phantom.createFromFile (myFilename);
151   } else {
152     myFilename.Replace (".phm", "");
153     m_phantom.createFromPhantom (myFilename);
154   }
155   m_namePhantom = myFilename;
156   SetFilename (myFilename, true);
157   if (m_phantom.fail()) {
158     *theApp->getLog() << "Failure creating phantom " << myFilename << "\n";
159     return false;
160   }
161   m_idPhantom = m_phantom.id();
162   Modify(false);
163   UpdateAllViews();
164   return true;
165 }
166
167 bool PhantomDocument::IsModified(void) const
168 {
169   return wxDocument::IsModified();
170 }
171
172 void PhantomDocument::Modify(bool mod)
173 {
174     wxDocument::Modify(mod);
175 }
176