r471: Fixed shutdown crash, added Revert
[ctsim.git] / src / ctsim.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          ctsim.cpp
5 **   Purpose:       Top-level 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-2001 Kevin Rosenberg
11 **
12 **  $Id: ctsim.h,v 1.36 2001/01/30 05:05:41 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 __CTSIMH__
29 #define __CTSIMH__
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34 #ifdef HAVE_DMALLOC
35 #include <dmalloc.h>
36 #endif
37
38 #ifndef WX_PRECOMP
39 #include "wx/wx.h"
40 #endif
41 #include "wx/config.h"
42
43 #ifdef MSVC
44 #define CTSIM_MDI 1
45 #endif
46 #define CTSIM_CUSTOM_MRU 1
47
48 #if defined(CTSIM_MDI) && !wxUSE_MDI_ARCHITECTURE
49 #error You must set wxUSE_MDI_ARCHITECTURE to 1 in setup.h!
50 #endif
51 #ifdef CTSIM_MDI
52 #include "wx/docmdi.h"
53 #endif
54
55 class wxMenu;
56 class wxDocument;
57 class ImageFileDocument;
58 class ProjectionFileDocument;
59 class PhantomFileDocument;
60 class PlotFileDocument;
61 class TextFileDocument;
62
63 #include <vector>
64 #include "wx/docview.h"
65 #include "wx/textctrl.h"
66 #include "wx/menu.h"
67 #include "wx/help.h"
68 #include "wx/html/helpctrl.h"
69 #include "dlgezplot.h"
70
71
72 #if defined(__WXMSW__)
73 #define CTSIM_WINHELP   1
74 #endif
75
76 // Define a new frame for main window
77 #if CTSIM_MDI
78 class MainFrame: public wxDocMDIParentFrame
79 #else
80 class MainFrame: public wxDocParentFrame
81 #endif
82 {
83 private:
84   DECLARE_CLASS(MainFrame)
85   DECLARE_EVENT_TABLE()
86
87 #ifndef CTSIM_MDI
88   wxMenu* m_pWindowMenu;
89 #endif
90
91   enum { MAX_WINDOW_MENUITEMS = 20 };
92   wxMenuItem* m_apWindowMenuItems[MAX_WINDOW_MENUITEMS];
93   wxDocument* m_apWindowMenuData[MAX_WINDOW_MENUITEMS];
94   
95   int m_iDefaultPhantomID;
96   int m_iDefaultFilterID;
97   int m_iDefaultFilterDomainID;
98   unsigned int m_iDefaultFilterXSize;    
99   unsigned int m_iDefaultFilterYSize;
100   double m_dDefaultFilterParam;
101   double m_dDefaultFilterBandwidth;
102   double m_dDefaultFilterInputScale;
103   double m_dDefaultFilterOutputScale;
104
105   bool m_bShuttingDown;
106
107 #if CTSIM_WINHELP
108   wxWinHelpController      m_winHelp;
109 #endif
110   wxHtmlHelpController     m_htmlHelp;
111   
112 public:
113   MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type);
114   virtual ~MainFrame();
115
116 #ifdef CTSIM_CUSTOM_MRU
117   void OnMRUFile (wxCommandEvent& event);
118 #endif
119   void OnSize (wxSizeEvent& event);
120
121 #if CTSIM_WINHELP
122   wxWinHelpController&   getWinHelpController()
123   {return m_winHelp; }
124 #endif
125   wxHtmlHelpController&  getHtmlHelpController()
126   { return m_htmlHelp; }
127
128   void showHelp (int commandID);
129
130   void OnAbout (wxCommandEvent& event);
131   void OnHelpTopics (wxCommandEvent& event);
132   void OnHelpContents (wxCommandEvent& event);
133   void OnCreatePhantom (wxCommandEvent& event);
134   
135 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
136   void OnHelpSecondary (wxCommandEvent& event);
137 #endif
138
139   void OnCreateFilter (wxCommandEvent& event);
140   void OnExit (wxCommandEvent& event);
141   
142   void OnUpdateUI (wxUpdateUIEvent& event);
143   
144   void OnWindowMenu0 (wxCommandEvent& event);
145   void OnWindowMenu1 (wxCommandEvent& event);
146   void OnWindowMenu2 (wxCommandEvent& event);
147   void OnWindowMenu3 (wxCommandEvent& event);
148   void OnWindowMenu4 (wxCommandEvent& event);
149   void OnWindowMenu5 (wxCommandEvent& event);
150   void OnWindowMenu6 (wxCommandEvent& event);
151   void OnWindowMenu7 (wxCommandEvent& event);
152   void OnWindowMenu8 (wxCommandEvent& event);
153   void OnWindowMenu9 (wxCommandEvent& event);
154   void OnWindowMenu10 (wxCommandEvent& event);
155   void OnWindowMenu11 (wxCommandEvent& event);
156   void OnWindowMenu12 (wxCommandEvent& event);
157   void OnWindowMenu13 (wxCommandEvent& event);
158   void OnWindowMenu14 (wxCommandEvent& event);
159   void OnWindowMenu15 (wxCommandEvent& event);
160   void OnWindowMenu16 (wxCommandEvent& event);
161   void OnWindowMenu17 (wxCommandEvent& event);
162   void OnWindowMenu18 (wxCommandEvent& event);
163   void OnWindowMenu19 (wxCommandEvent& event);
164   
165   void DoWindowMenu (int iMenuPosition, wxCommandEvent& event);
166
167   bool getShuttingDown() const { return m_bShuttingDown; }
168 };
169
170
171 class wxDocManager;
172 class CTSimApp: public wxApp
173 {
174 private:
175   enum { O_HELP, O_VERSION };
176   static struct option ctsimOptions[];
177   
178   wxDocManager* m_docManager;
179   MainFrame* m_pFrame;
180   wxConfig* m_pConfig;
181   wxTextCtrl* m_pLog;
182   wxDocTemplate* m_pDocTemplImage;
183   wxDocTemplate* m_pDocTemplProjection;
184   wxDocTemplate* m_pDocTemplPhantom;
185   wxDocTemplate* m_pDocTemplPlot;
186   wxDocTemplate* m_pDocTemplText;
187   TextFileDocument* m_pLogDoc;
188
189   void usage (const char* program);
190   
191 public:
192   CTSimApp();
193   bool OnInit();
194   int OnExit();
195   MainFrame* getMainFrame() const
196   { return m_pFrame; }
197
198   wxTextCtrl* getLog()
199   { return m_pLog; }
200
201   wxDocManager* getDocManager() 
202   { return m_docManager; }
203   
204   wxString getUntitledFilename();
205   
206   EZPlotDialog* makeEZPlotDialog()
207   { return new EZPlotDialog (m_pFrame); }
208   
209   void getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF);
210   
211   void setIconForFrame (wxFrame* pFrame);
212   wxConfig* getConfig()
213   { return m_pConfig; }
214
215   wxDocTemplate* getDocTemplImage() { return m_pDocTemplImage; }
216   wxDocTemplate* getDocTemplProjection() { return m_pDocTemplProjection; }
217   wxDocTemplate* getDocTemplPhantom() { return m_pDocTemplPhantom; }
218   wxDocTemplate* getDocTemplPlot() { return m_pDocTemplPlot; }
219   wxDocTemplate* getDocTemplText() { return m_pDocTemplText; }
220   TextFileDocument* getLogDoc() { return m_pLogDoc; }
221
222   ProjectionFileDocument* newProjectionDoc();
223   ImageFileDocument* newImageDoc();
224   PhantomFileDocument* newPhantomDoc();
225   PlotFileDocument* newPlotDoc();
226   TextFileDocument* newTextDoc();
227
228 };
229
230 DECLARE_APP(CTSimApp)
231
232 extern class CTSimApp* theApp;
233
234 enum {
235     MAINMENU_WINDOW_BASE = 500,
236     MAINMENU_HELP_ABOUT = 600,
237     MAINMENU_HELP_CONTENTS,
238     MAINMENU_HELP_TOPICS,
239     MAINMENU_HELP_SECONDARY,
240     MAINMENU_FILE_CREATE_PHANTOM,
241     
242     MAINMENU_FILE_CREATE_FILTER,
243     MAINMENU_FILE_EXIT,
244     
245     PJMENU_FILE_PROPERTIES,
246     PJMENU_RECONSTRUCT_FBP,
247     PJMENU_RECONSTRUCT_FOURIER,
248     PJMENU_CONVERT_POLAR,
249     PJMENU_CONVERT_FFT_POLAR,
250     
251     IFMENU_FILE_EXPORT,
252     IFMENU_FILE_PROPERTIES,
253     
254     IFMENU_PLOT_ROW,
255     IFMENU_PLOT_COL,
256     IFMENU_PLOT_FFT_ROW,
257     IFMENU_PLOT_FFT_COL,
258     IFMENU_PLOT_HISTOGRAM,
259     
260     IFMENU_VIEW_SCALE_AUTO,
261     IFMENU_VIEW_SCALE_MINMAX,
262     IFMENU_VIEW_SCALE_FULL,
263     
264     IFMENU_COMPARE_IMAGES,
265     IFMENU_COMPARE_ROW,
266     IFMENU_COMPARE_COL,
267     IFMENU_IMAGE_SCALESIZE,
268     IFMENU_IMAGE_ADD,
269     IFMENU_IMAGE_SUBTRACT,
270     IFMENU_IMAGE_MULTIPLY,
271     IFMENU_IMAGE_DIVIDE,
272     
273     IFMENU_FILTER_INVERTVALUES,
274     IFMENU_FILTER_SQRT,
275     IFMENU_FILTER_SQUARE,
276     IFMENU_FILTER_LOG,
277     IFMENU_FILTER_EXP,
278     IFMENU_FILTER_FOURIER,
279     IFMENU_FILTER_INVERSE_FOURIER,
280     IFMENU_FILTER_FFT,
281     IFMENU_FILTER_IFFT,
282     IFMENU_FILTER_FFT_ROWS,
283     IFMENU_FILTER_FFT_COLS,
284     IFMENU_FILTER_IFFT_ROWS,
285     IFMENU_FILTER_IFFT_COLS,
286     IFMENU_FILTER_MAGNITUDE,
287     IFMENU_FILTER_PHASE,
288     IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER,
289     IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER,
290     
291     PHMMENU_FILE_PROPERTIES,
292     PHMMENU_PROCESS_RASTERIZE,
293     PHMMENU_PROCESS_PROJECTIONS,
294     
295     PLOTMENU_VIEW_SCALE_MINMAX,
296     PLOTMENU_VIEW_SCALE_AUTO,
297     PLOTMENU_VIEW_SCALE_FULL,    
298 };
299
300 #endif