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