a4049f17a94cd0bdc12dd7b1711811718961093b
[ctsim.git] / src / ctsim.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          ctsim.h
5 **   Purpose:       Header file for CTSim
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.52 2001/02/22 15:00:20 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 #ifdef __WXMSW__
43 #include "wx/msw/helpchm.h"
44 #endif
45
46 #ifdef MSVC
47 #define CTSIM_MDI 1
48 #endif
49 #define CTSIM_CUSTOM_MRU 1
50
51 #if defined(CTSIM_MDI) && !wxUSE_MDI_ARCHITECTURE
52 #error You must set wxUSE_MDI_ARCHITECTURE to 1 in setup.h!
53 #endif
54 #ifdef CTSIM_MDI
55 #include "wx/docmdi.h"
56 #endif
57
58 class wxMenu;
59 class wxDocument;
60 class ImageFileDocument;
61 class ProjectionFileDocument;
62 class PhantomFileDocument;
63 class PlotFileDocument;
64 class TextFileDocument;
65 class BackgroundManager;
66
67 #if wxUSE_GLCANVAS
68 class Graph3dFileDocument;
69 #endif
70
71 #include <vector>
72 #include "wx/docview.h"
73 #include "wx/textctrl.h"
74 #include "wx/menu.h"
75 #include "wx/help.h"
76 #include "wx/html/helpctrl.h"
77 #include "dlgezplot.h"
78 #include "ctsim-map.h"
79
80
81 #if defined(__WXMSW__) || defined (MSVC)
82 #define CTSIM_WINHELP   1
83 #endif
84
85 // Define a new frame for main window
86 #if CTSIM_MDI
87 class MainFrame: public wxDocMDIParentFrame
88 #else
89 class MainFrame: public wxDocParentFrame
90 #endif
91 {
92 private:
93   DECLARE_CLASS(MainFrame)
94   DECLARE_EVENT_TABLE()
95
96 #ifndef CTSIM_MDI
97   wxMenu* m_pWindowMenu;
98 #endif
99
100   enum { MAX_WINDOW_MENUITEMS = 20 };
101   wxMenuItem* m_apWindowMenuItems[MAX_WINDOW_MENUITEMS];
102   wxDocument* m_apWindowMenuData[MAX_WINDOW_MENUITEMS];
103   
104   int m_iDefaultPhantomID;
105   int m_iDefaultFilterID;
106   int m_iDefaultFilterDomainID;
107   unsigned int m_iDefaultFilterXSize;    
108   unsigned int m_iDefaultFilterYSize;
109   double m_dDefaultFilterParam;
110   double m_dDefaultFilterBandwidth;
111   double m_dDefaultFilterInputScale;
112   double m_dDefaultFilterOutputScale;
113
114   bool m_bShuttingDown;
115
116 #if CTSIM_WINHELP
117   wxCHMHelpController      m_winHelp;
118 #endif
119   wxHtmlHelpController     m_htmlHelp;
120
121 public:
122   MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type);
123   virtual ~MainFrame();
124
125 #ifdef CTSIM_CUSTOM_MRU
126   void OnMRUFile (wxCommandEvent& event);
127 #endif
128   void OnSize (wxSizeEvent& event);
129
130 #if CTSIM_WINHELP
131   wxCHMHelpController&   getWinHelpController()
132   {return m_winHelp; }
133 #endif
134   wxHtmlHelpController&  getHtmlHelpController()
135   { return m_htmlHelp; }
136
137   void showHelp (int commandID);
138
139   void OnAbout (wxCommandEvent& event);
140   void OnHelpContents (wxCommandEvent& event);
141   void OnHelpTips (wxCommandEvent& event);
142   void OnCreatePhantom (wxCommandEvent& event);
143   void OnPreferences (wxCommandEvent& event);
144   void OnLogEvent (wxCommandEvent& event);  // used by thread children
145
146   void OnHelpButton (wxCommandEvent& event);
147
148 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
149   void OnHelpSecondary (wxCommandEvent& event);
150 #endif
151
152   void OnCreateFilter (wxCommandEvent& event);
153   void OnExit (wxCommandEvent& event);
154   
155   void OnUpdateUI (wxUpdateUIEvent& event);
156   
157   void OnWindowMenu0 (wxCommandEvent& event);
158   void OnWindowMenu1 (wxCommandEvent& event);
159   void OnWindowMenu2 (wxCommandEvent& event);
160   void OnWindowMenu3 (wxCommandEvent& event);
161   void OnWindowMenu4 (wxCommandEvent& event);
162   void OnWindowMenu5 (wxCommandEvent& event);
163   void OnWindowMenu6 (wxCommandEvent& event);
164   void OnWindowMenu7 (wxCommandEvent& event);
165   void OnWindowMenu8 (wxCommandEvent& event);
166   void OnWindowMenu9 (wxCommandEvent& event);
167   void OnWindowMenu10 (wxCommandEvent& event);
168   void OnWindowMenu11 (wxCommandEvent& event);
169   void OnWindowMenu12 (wxCommandEvent& event);
170   void OnWindowMenu13 (wxCommandEvent& event);
171   void OnWindowMenu14 (wxCommandEvent& event);
172   void OnWindowMenu15 (wxCommandEvent& event);
173   void OnWindowMenu16 (wxCommandEvent& event);
174   void OnWindowMenu17 (wxCommandEvent& event);
175   void OnWindowMenu18 (wxCommandEvent& event);
176   void OnWindowMenu19 (wxCommandEvent& event);
177   
178   void DoWindowMenu (int iMenuPosition, wxCommandEvent& event);
179
180   bool getShuttingDown() const { return m_bShuttingDown; }
181 };
182
183
184 class wxDocManager;
185 class CTSimApp: public wxApp
186 {
187 private:
188   enum { O_HELP, O_PRINT, O_VERSION };
189   static struct option ctsimOptions[];
190
191   bool m_bAdvancedOptions;
192   bool m_bSetModifyNewDocs;
193   bool m_bVerboseLogging;
194   bool m_bShowStartupTips;
195   long m_iCurrentTip;
196   bool m_bUseBackgroundTasks;
197
198   wxDocManager* m_docManager;
199   MainFrame* m_pFrame;
200   wxConfig* m_pConfig;
201   wxTextCtrl* m_pLog;
202   wxDocTemplate* m_pDocTemplImage;
203   wxDocTemplate* m_pDocTemplProjection;
204   wxDocTemplate* m_pDocTemplPhantom;
205   wxDocTemplate* m_pDocTemplPlot;
206   wxDocTemplate* m_pDocTemplText;
207 #if wxUSE_GLCANVAS
208   wxDocTemplate* m_pDocTemplGraph3d;
209 #endif
210   
211   TextFileDocument* m_pLogDoc;
212
213   void usage (const char* program);
214   void openConfig();
215   void closeConfig();
216   BackgroundManager*  m_pBackgroundMgr;
217
218 public:
219   CTSimApp();
220   bool OnInit();
221   int OnExit();
222   MainFrame* getMainFrame() const
223   { return m_pFrame; }
224
225   wxTextCtrl* getLog()
226   { return m_pLog; }
227
228   wxDocManager* getDocManager() 
229   { return m_docManager; }
230   
231   wxString getUntitledFilename();
232
233   int getNumberCPU() const { return wxThread::GetCPUCount(); }
234
235   EZPlotDialog* makeEZPlotDialog()
236   { return new EZPlotDialog (m_pFrame); }
237   
238   void getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF);
239   bool getAdvancedOptions() const { return m_bAdvancedOptions; }
240   void setAdvancedOptions (bool bAdv) { m_bAdvancedOptions = bAdv; }
241   bool getVerboseLogging() const { return m_bVerboseLogging; }
242   void setVerboseLogging (bool bVerbose) { m_bVerboseLogging = bVerbose; }
243   bool getStartupTips() const { return m_bShowStartupTips; }
244   void setStartupTips(bool bTips) { m_bShowStartupTips = bTips; }
245   bool getUseBackgroundTasks() const { return m_bUseBackgroundTasks; }
246   void setUseBackgroundTasks(bool bBkgd) { m_bUseBackgroundTasks = bBkgd; }
247
248   BackgroundManager* getBackgroundManager() {return m_pBackgroundMgr;}
249
250   void ShowTips();
251
252   void setIconForFrame (wxFrame* pFrame);
253   wxConfig* getConfig()
254   { return m_pConfig; }
255   bool getAskDeleteNewDocs() const { return m_bSetModifyNewDocs; }
256   void setAskDeleteNewDocs(bool bAsk) { m_bSetModifyNewDocs = bAsk; }
257
258   wxDocTemplate* getDocTemplImage() { return m_pDocTemplImage; }
259   wxDocTemplate* getDocTemplProjection() { return m_pDocTemplProjection; }
260   wxDocTemplate* getDocTemplPhantom() { return m_pDocTemplPhantom; }
261   wxDocTemplate* getDocTemplPlot() { return m_pDocTemplPlot; }
262   wxDocTemplate* getDocTemplText() { return m_pDocTemplText; }
263 #if wxUSE_GLCANVAS
264   wxDocTemplate* getDocTemplGraph3d() { return m_pDocTemplGraph3d; }
265 #endif
266   TextFileDocument* getLogDoc() { return m_pLogDoc; }
267
268   ProjectionFileDocument* newProjectionDoc();
269   ImageFileDocument* newImageDoc();
270   PhantomFileDocument* newPhantomDoc();
271   PlotFileDocument* newPlotDoc();
272   TextFileDocument* newTextDoc();
273 #if wxUSE_GLCANVAS
274   Graph3dFileDocument* newGraph3dDoc();
275 #endif
276 };
277
278 DECLARE_APP(CTSimApp)
279
280 extern class CTSimApp* theApp;
281
282 enum {
283     MAINMENU_WINDOW_BASE = 500,
284     MAINMENU_HELP_ABOUT = 600,
285     MAINMENU_HELP_CONTENTS,
286     MAINMENU_HELP_TIPS,
287 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
288     MAINMENU_HELP_SECONDARY,
289 #endif
290     MAINMENU_FILE_CREATE_PHANTOM,
291     MAINMENU_FILE_CREATE_FILTER,
292     MAINMENU_FILE_EXIT,
293     MAINMENU_FILE_PREFERENCES,
294     MAINMENU_LOG_EVENT,
295         
296     PJMENU_FILE_PROPERTIES,
297     PJMENU_RECONSTRUCT_FBP,
298     PJMENU_RECONSTRUCT_FOURIER,
299     PJMENU_CONVERT_POLAR,
300     PJMENU_CONVERT_FFT_POLAR,
301     
302     IFMENU_FILE_EXPORT,
303     IFMENU_FILE_PROPERTIES,
304     
305     IFMENU_PLOT_ROW,
306     IFMENU_PLOT_COL,
307     IFMENU_PLOT_FFT_ROW,
308     IFMENU_PLOT_FFT_COL,
309     IFMENU_PLOT_HISTOGRAM,
310     
311     IFMENU_VIEW_SCALE_AUTO,
312     IFMENU_VIEW_SCALE_MINMAX,
313     IFMENU_VIEW_SCALE_FULL,
314     
315     IFMENU_COMPARE_IMAGES,
316     IFMENU_COMPARE_ROW,
317     IFMENU_COMPARE_COL,
318     IFMENU_IMAGE_SCALESIZE,
319     IFMENU_IMAGE_ADD,
320     IFMENU_IMAGE_SUBTRACT,
321     IFMENU_IMAGE_MULTIPLY,
322     IFMENU_IMAGE_DIVIDE,
323 #if wxUSE_GLCANVAS
324     IFMENU_IMAGE_CONVERT3D,
325 #endif
326
327     IFMENU_FILTER_INVERTVALUES,
328     IFMENU_FILTER_SQRT,
329     IFMENU_FILTER_SQUARE,
330     IFMENU_FILTER_LOG,
331     IFMENU_FILTER_EXP,
332     IFMENU_FILTER_FOURIER,
333     IFMENU_FILTER_INVERSE_FOURIER,
334     IFMENU_FILTER_FFT,
335     IFMENU_FILTER_IFFT,
336     IFMENU_FILTER_FFT_ROWS,
337     IFMENU_FILTER_FFT_COLS,
338     IFMENU_FILTER_IFFT_ROWS,
339     IFMENU_FILTER_IFFT_COLS,
340     IFMENU_FILTER_MAGNITUDE,
341     IFMENU_FILTER_PHASE,
342     IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER,
343     IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER,
344     
345     PHMMENU_FILE_PROPERTIES,
346     PHMMENU_PROCESS_RASTERIZE,
347     PHMMENU_PROCESS_PROJECTIONS,
348
349     PLOTMENU_FILE_PROPERTIES,
350     PLOTMENU_VIEW_SCALE_MINMAX,
351     PLOTMENU_VIEW_SCALE_AUTO,
352     PLOTMENU_VIEW_SCALE_FULL,    
353
354     GRAPH3D_VIEW_SURFACE,
355     GRAPH3D_VIEW_COLOR,
356     GRAPH3D_VIEW_LIGHTING,
357     GRAPH3D_VIEW_SMOOTH,
358     GRAPH3D_VIEW_SCALE_AUTO,
359     GRAPH3D_VIEW_SCALE_MINMAX,
360     GRAPH3D_VIEW_SCALE_FULL,
361
362     RECONSTRUCTION_THREAD_EVENT,
363 };
364
365 #endif