r2105: *** empty log message ***
[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.32 2002/06/04 19:19:40 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 extern const char szNEW_IMAGE_FILENAME[];
52 extern const char szNEW_PROJECTION_FILENAME[];
53 extern const char szNEW_GRAPH3D_FILENAME[];
54 extern const char szNEW_PLOT_FILENAME[];
55
56
57 class ImageFileDocument: public wxDocument
58 {
59 private:
60     DECLARE_DYNAMIC_CLASS(ImageFileDocument)
61     ImageFile* m_pImageFile;
62     bool m_bBadFileOpen;
63
64 public:
65     virtual bool OnSaveDocument (const wxString& filename);
66     virtual bool OnOpenDocument (const wxString& filename);
67     virtual bool IsModified () const;
68     virtual bool Revert ();
69     virtual void Modify (bool mod);
70     
71     ImageFileDocument () 
72       : m_bBadFileOpen(false)
73     {
74       m_pImageFile = new ImageFile;
75     }
76
77     virtual ~ImageFileDocument () 
78     {
79       delete m_pImageFile;
80     }
81
82     const ImageFile& getImageFile() const { return *m_pImageFile; }
83     ImageFile& getImageFile() { return *m_pImageFile; }
84     void setImageFile (ImageFile* pImageFile)
85     { 
86       delete m_pImageFile;
87       m_pImageFile = pImageFile;
88     }
89
90     ImageFileView* getView() const;
91     bool getBadFileOpen() const { return m_bBadFileOpen; }
92     void setBadFileOpen() { m_bBadFileOpen = true; }
93     void Activate();
94 };
95
96 class BackgroundProcessingDocument : public wxDocument
97 {
98 private:
99     DECLARE_DYNAMIC_CLASS(BackgroundProcessingDocument)
100 #ifdef HAVE_WXTHREADS
101     typedef BackgroundSupervisor BackgroundObject;
102     typedef std::vector<BackgroundObject*> BackgroundContainer;
103     BackgroundContainer m_vecpBackgroundSupervisors;
104     wxCriticalSection m_criticalSection;
105 #endif
106
107 public:
108   BackgroundProcessingDocument()
109     : wxDocument()
110       {}
111
112   void cancelRunningTasks();
113 #ifdef HAVE_WXTHREADS
114   void addBackgroundSupervisor (BackgroundSupervisor* pSupervisor);
115   void removeBackgroundSupervisor (BackgroundSupervisor* pSupervisor);
116 #endif
117
118   DECLARE_EVENT_TABLE()
119 };
120
121 class ProjectionFileDocument: public BackgroundProcessingDocument
122 {
123 private:
124     DECLARE_DYNAMIC_CLASS(ProjectionFileDocument)
125     Projections* m_pProjectionFile;
126     bool m_bBadFileOpen;
127     
128 public:
129     virtual bool OnSaveDocument (const wxString& filename);
130     virtual bool OnOpenDocument (const wxString& filename);
131     virtual bool IsModified () const;
132     virtual void Modify (bool mod);
133     
134     ProjectionFileDocument () 
135           : m_bBadFileOpen(false)
136     {
137       m_pProjectionFile = new Projections;
138     }
139
140     virtual ~ProjectionFileDocument ();
141
142     const Projections& getProjections () const  { return *m_pProjectionFile; }
143     Projections& getProjections ()      { return *m_pProjectionFile; }
144
145     void setProjections (Projections* pProjections)
146     { delete m_pProjectionFile;
147       m_pProjectionFile = pProjections;
148     }
149
150     ProjectionFileView* getView() const;
151     bool getBadFileOpen() const { return m_bBadFileOpen; }
152     void setBadFileOpen() { m_bBadFileOpen = true; }
153     void Activate();
154 };
155
156
157 class PhantomFileDocument: public BackgroundProcessingDocument
158 {
159 private:
160     DECLARE_DYNAMIC_CLASS(PhantomFileDocument)
161     Phantom m_phantom;
162     int m_idPhantom;
163     wxString m_namePhantom;
164     bool m_bBadFileOpen;
165
166 public:
167     PhantomFileDocument () 
168         : m_idPhantom(Phantom::PHM_INVALID), m_bBadFileOpen(false)
169     {}
170
171     virtual ~PhantomFileDocument ();
172
173     const int getPhantomID () const { return m_idPhantom; }
174
175     const wxString& getPhantomName () const { return m_namePhantom; }
176
177     const Phantom& getPhantom () const  { return m_phantom; }
178
179     Phantom& getPhantom ()      { return m_phantom; }
180
181     virtual bool OnOpenDocument (const wxString& filename);
182     virtual bool OnSaveDocument (const wxString& filename);
183     virtual bool IsModified () const;
184     virtual void Modify (bool mod);
185     PhantomFileView* getView() const;
186     bool getBadFileOpen() const { return m_bBadFileOpen; }
187     void setBadFileOpen() { m_bBadFileOpen = true; }
188     void Activate();
189 };
190
191
192 class PlotFileDocument: public wxDocument
193 {
194 private:
195     DECLARE_DYNAMIC_CLASS(PlotFileDocument)
196     PlotFile m_plot;
197     wxString m_namePlot;
198     bool m_bBadFileOpen;
199
200 public:
201     PlotFileDocument () 
202       : m_bBadFileOpen(false)
203     {}
204
205     virtual ~PlotFileDocument () 
206         {}
207
208     const wxString& getPlotName () const
209         { return m_namePlot; }
210
211     const PlotFile& getPlotFile () const
212         { return m_plot; }
213
214     PlotFile& getPlotFile ()
215         { return m_plot; }
216
217     virtual bool OnOpenDocument (const wxString& filename);
218     virtual bool OnSaveDocument (const wxString& filename);
219     virtual bool IsModified () const;
220     virtual void Modify (bool mod);
221     PlotFileView* getView() const;
222     bool getBadFileOpen() const { return m_bBadFileOpen; }
223     void setBadFileOpen() { m_bBadFileOpen = true; }
224     void Activate();
225 };
226
227
228 class TextFileDocument: public wxDocument
229 {
230  private:
231   DECLARE_DYNAMIC_CLASS(TextFileDocument)
232   bool m_bBadFileOpen;
233
234  public:
235   TextFileDocument(void) 
236         : m_bBadFileOpen(false)
237   {}
238
239   virtual ~TextFileDocument(void) {}
240
241   virtual bool OnSaveDocument(const wxString& filename);
242   virtual bool OnOpenDocument(const wxString& filename);
243   virtual bool IsModified(void) const;
244
245   wxTextCtrl* getTextCtrl();
246
247   TextFileView* getView() const;
248   bool getBadFileOpen() const { return m_bBadFileOpen; }
249   void setBadFileOpen() { m_bBadFileOpen = true; }
250 };
251
252
253 #if wxUSE_GLCANVAS
254 #include <GL/gl.h>
255 #include <GL/glu.h>
256
257 typedef GLfloat glTripleFloat[3];
258
259 class Graph3dFileDocument: public wxDocument
260 {
261   friend class Graph3dFileView;
262
263  private:
264   DECLARE_DYNAMIC_CLASS(Graph3dFileDocument)
265   bool m_bBadFileOpen;
266   GLint m_nVertices;
267   glTripleFloat* m_pVertices;
268   glTripleFloat* m_pNormals;
269   unsigned int m_nx;
270   unsigned int m_ny;
271   ImageFileArray m_array;
272
273  public:
274   Graph3dFileDocument(void);
275   virtual ~Graph3dFileDocument(void); 
276  
277   virtual bool OnSaveDocument (const wxString& filename);
278   virtual bool OnOpenDocument (const wxString& filename);
279   virtual bool IsModified () const;
280
281   Graph3dFileView* getView() const;
282   bool getBadFileOpen() const { return m_bBadFileOpen; }
283   void setBadFileOpen()       { m_bBadFileOpen = true; }
284   bool createFromImageFile (const ImageFile& rImageFile);
285
286   int nx() const  { return m_nx; }
287   int ny() const { return m_ny; }
288   ImageFileArray getArray() { return m_array; }
289   ImageFileArrayConst getArray() const { return m_array; }
290   void Activate();
291 };
292 #endif // wxUSE_GLCANVAS
293
294
295 #endif