e2c7d1f0accc1c729259adf20e38b947667d2d2d
[ctsim.git] / src / docs.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          docs.h
5 **   Purpose:       Header file for Document routines of CTSim program
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  July 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (c) 1983-2001 Kevin Rosenberg
11 **
12 **  $Id: docs.h,v 1.30 2001/03/11 18:52:03 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 interface
30 #endif
31
32 #ifndef __DOCSH__
33 #define __DOCSH__
34
35 #include "wx/docview.h"
36
37 // #include "views.h"
38 #include "imagefile.h"
39 #include "phantom.h"
40 #include "projections.h"
41 #include "plotfile.h"
42 #include "threadrecon.h"
43
44 class ProjectionFileView;
45 class PhantomFileView;
46 class ImageFileView;
47 class PlotFileView;
48 class TextFileView;
49 class Graph3dFileView;
50
51 class ImageFileDocument: public wxDocument
52 {
53 private:
54     DECLARE_DYNAMIC_CLASS(ImageFileDocument)
55     ImageFile* m_pImageFile;
56     bool m_bBadFileOpen;
57
58 public:
59     virtual bool OnSaveDocument (const wxString& filename);
60     virtual bool OnOpenDocument (const wxString& filename);
61     virtual bool IsModified () const;
62     virtual bool Revert ();
63     virtual void Modify (bool mod);
64     
65     ImageFileDocument () 
66       : m_bBadFileOpen(false)
67     {
68       m_pImageFile = new ImageFile;
69     }
70
71     virtual ~ImageFileDocument () 
72     {
73       delete m_pImageFile;
74     }
75
76     const ImageFile& getImageFile() const { return *m_pImageFile; }
77     ImageFile& getImageFile() { return *m_pImageFile; }
78     void setImageFile (ImageFile* pImageFile)
79     { 
80       delete m_pImageFile;
81       m_pImageFile = pImageFile;
82     }
83
84     ImageFileView* getView() const;
85     bool getBadFileOpen() const { return m_bBadFileOpen; }
86     void setBadFileOpen() { m_bBadFileOpen = true; }
87     void Activate();
88 };
89
90 class BackgroundProcessingDocument : public wxDocument
91 {
92 private:
93     DECLARE_DYNAMIC_CLASS(BackgroundProcessingDocument)
94 #ifdef HAVE_WXTHREADS
95     typedef BackgroundSupervisor BackgroundObject;
96     typedef std::vector<BackgroundObject*> BackgroundContainer;
97     BackgroundContainer m_vecpBackgroundSupervisors;
98     wxCriticalSection m_criticalSection;
99 #endif
100
101 public:
102   BackgroundProcessingDocument()
103     : wxDocument()
104       {}
105
106   void cancelRunningTasks();
107 #ifdef HAVE_WXTHREADS
108   void addBackgroundSupervisor (BackgroundSupervisor* pSupervisor);
109   void removeBackgroundSupervisor (BackgroundSupervisor* pSupervisor);
110 #endif
111
112   DECLARE_EVENT_TABLE()
113 };
114
115 class ProjectionFileDocument: public BackgroundProcessingDocument
116 {
117 private:
118     DECLARE_DYNAMIC_CLASS(ProjectionFileDocument)
119     Projections* m_pProjectionFile;
120     bool m_bBadFileOpen;
121     
122 public:
123     virtual bool OnSaveDocument (const wxString& filename);
124     virtual bool OnOpenDocument (const wxString& filename);
125     virtual bool IsModified () const;
126     virtual void Modify (bool mod);
127     
128     ProjectionFileDocument () 
129           : m_bBadFileOpen(false)
130     {
131       m_pProjectionFile = new Projections;
132     }
133
134     virtual ~ProjectionFileDocument ();
135
136     const Projections& getProjections () const  { return *m_pProjectionFile; }
137     Projections& getProjections ()      { return *m_pProjectionFile; }
138
139     void setProjections (Projections* pProjections)
140     { delete m_pProjectionFile;
141       m_pProjectionFile = pProjections;
142     }
143
144     ProjectionFileView* getView() const;
145     bool getBadFileOpen() const { return m_bBadFileOpen; }
146     void setBadFileOpen() { m_bBadFileOpen = true; }
147     void Activate();
148 };
149
150
151 class PhantomFileDocument: public BackgroundProcessingDocument
152 {
153 private:
154     DECLARE_DYNAMIC_CLASS(PhantomFileDocument)
155     Phantom m_phantom;
156     int m_idPhantom;
157     wxString m_namePhantom;
158     bool m_bBadFileOpen;
159
160 public:
161     PhantomFileDocument () 
162         : m_idPhantom(Phantom::PHM_INVALID), m_bBadFileOpen(false)
163     {}
164
165     virtual ~PhantomFileDocument ();
166
167     const int getPhantomID () const { return m_idPhantom; }
168
169     const wxString& getPhantomName () const { return m_namePhantom; }
170
171     const Phantom& getPhantom () const  { return m_phantom; }
172
173     Phantom& getPhantom ()      { return m_phantom; }
174
175     virtual bool OnOpenDocument (const wxString& filename);
176     virtual bool OnSaveDocument (const wxString& filename);
177     virtual bool IsModified () const;
178     virtual void Modify (bool mod);
179     PhantomFileView* getView() const;
180     bool getBadFileOpen() const { return m_bBadFileOpen; }
181     void setBadFileOpen() { m_bBadFileOpen = true; }
182     void Activate();
183 };
184
185
186 class PlotFileDocument: public wxDocument
187 {
188 private:
189     DECLARE_DYNAMIC_CLASS(PlotFileDocument)
190     PlotFile m_plot;
191     wxString m_namePlot;
192     bool m_bBadFileOpen;
193
194 public:
195     PlotFileDocument () 
196       : m_bBadFileOpen(false)
197     {}
198
199     virtual ~PlotFileDocument () 
200         {}
201
202     const wxString& getPlotName () const
203         { return m_namePlot; }
204
205     const PlotFile& getPlotFile () const
206         { return m_plot; }
207
208     PlotFile& getPlotFile ()
209         { return m_plot; }
210
211     virtual bool OnOpenDocument (const wxString& filename);
212     virtual bool OnSaveDocument (const wxString& filename);
213     virtual bool IsModified () const;
214     virtual void Modify (bool mod);
215     PlotFileView* getView() const;
216     bool getBadFileOpen() const { return m_bBadFileOpen; }
217     void setBadFileOpen() { m_bBadFileOpen = true; }
218     void Activate();
219 };
220
221
222 class TextFileDocument: public wxDocument
223 {
224  private:
225   DECLARE_DYNAMIC_CLASS(TextFileDocument)
226   bool m_bBadFileOpen;
227
228  public:
229   TextFileDocument(void) 
230         : m_bBadFileOpen(false)
231   {}
232
233   virtual ~TextFileDocument(void) {}
234
235   virtual bool OnSaveDocument(const wxString& filename);
236   virtual bool OnOpenDocument(const wxString& filename);
237   virtual bool IsModified(void) const;
238
239   wxTextCtrl* getTextCtrl();
240
241   TextFileView* getView() const;
242   bool getBadFileOpen() const { return m_bBadFileOpen; }
243   void setBadFileOpen() { m_bBadFileOpen = true; }
244 };
245
246
247 #if wxUSE_GLCANVAS
248 #include <GL/gl.h>
249 #include <GL/glu.h>
250
251 typedef GLfloat glTripleFloat[3];
252
253 class Graph3dFileDocument: public wxDocument
254 {
255   friend Graph3dFileView;
256
257  private:
258   DECLARE_DYNAMIC_CLASS(Graph3dFileDocument)
259   bool m_bBadFileOpen;
260   GLint m_nVertices;
261   glTripleFloat* m_pVertices;
262   glTripleFloat* m_pNormals;
263   unsigned int m_nx;
264   unsigned int m_ny;
265   ImageFileArray m_array;
266
267  public:
268   Graph3dFileDocument(void);
269   virtual ~Graph3dFileDocument(void); 
270  
271   virtual bool OnSaveDocument (const wxString& filename);
272   virtual bool OnOpenDocument (const wxString& filename);
273   virtual bool IsModified () const;
274
275   Graph3dFileView* getView() const;
276   bool getBadFileOpen() const { return m_bBadFileOpen; }
277   void setBadFileOpen()       { m_bBadFileOpen = true; }
278   bool createFromImageFile (const ImageFile& rImageFile);
279
280   int nx() const  { return m_nx; }
281   int ny() const { return m_ny; }
282   ImageFileArray getArray() { return m_array; }
283   ImageFileArrayConst getArray() const { return m_array; }
284   void Activate();
285 };
286 #endif // wxUSE_GLCANVAS
287
288
289 #endif