Fix all remaining compiler warnings
[ctsim.git] / src / ctsim.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          ctsim.cpp
5 **   Purpose:       Top-level 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-2009 Kevin Rosenberg
11 **
12 **  This program is free software; you can redistribute it and/or modify
13 **  it under the terms of the GNU General Public License (version 2) as
14 **  published by the Free Software Foundation.
15 **
16 **  This program is distributed in the hope that it will be useful,
17 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 **  GNU General Public License for more details.
20 **
21 **  You should have received a copy of the GNU General Public License
22 **  along with this program; if not, write to the Free Software
23 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24 ******************************************************************************/
25
26 #ifdef MSVC
27 #define strdup _strdup
28 #endif
29
30 #include "wx/wxprec.h"
31
32 #ifndef WX_PRECOMP
33 #include "wx/wx.h"
34 #endif
35
36 #include "wx/image.h"
37 #include "wx/filesys.h"
38 #include "wx/fs_zip.h"
39 #include "wx/cmdline.h"
40 #ifdef __WXMSW__
41 #include "wx/msw/helpchm.h"
42 #endif
43
44 #if !wxUSE_DOC_VIEW_ARCHITECTURE
45 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
46 #endif
47
48 #include "ct.h"
49 #include "ctndicom.h"
50 #include "ctsim.h"
51 #include "docs.h"
52 #include "views.h"
53 #include "dialogs.h"
54 #include "tips.h"
55 #include "backgroundmgr.h"
56
57 #if defined(HAVE_CONFIG_H)
58 #include "config.h"
59 #endif
60
61 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
62 #ifdef MSVC
63 #define __STDC__ 1
64 #endif
65 #include "getopt.h"
66 #ifdef MSVC
67 #undef __STDC__
68 #endif
69 #endif
70
71
72 IMPLEMENT_APP(CTSimApp)
73
74 CTSimApp::CTSimApp()
75 : m_bAdvancedOptions(false), m_bSetModifyNewDocs(true), 
76   m_bVerboseLogging(false), m_bShowStartupTips(true),
77   m_iCurrentTip(0), m_bUseBackgroundTasks(false),
78   m_docManager(NULL), m_pFrame(NULL), m_pConfig(0), m_pLog(0), m_pLogDoc(0),
79   m_bPrintCmdLineImages(false), m_bCmdLineVerboseFlag(false)
80 {
81   theApp = this;
82 }
83
84 #ifdef HAVE_SYS_TIME_H
85 #include <sys/time.h>
86 #endif
87
88 #ifdef HAVE_SYS_RESOURCE_H
89 #include <sys/resource.h>
90 #endif
91
92
93 void CTSimApp::OnInitCmdLine(wxCmdLineParser& parser)
94 {
95   static const wxCmdLineEntryDesc cmdLineDesc[] = {
96     { wxCMD_LINE_SWITCH, wxT_2("l"), wxT_2("verbose"), wxT_2("verbose logging") },
97     { wxCMD_LINE_SWITCH, wxT_2("v"), wxT_2("version"), wxT_2("print version") },
98     { wxCMD_LINE_SWITCH, wxT_2("p"), wxT_2("print"), wxT_2("print images from command line"),
99       wxCMD_LINE_VAL_NONE,
100       wxCMD_LINE_PARAM_OPTIONAL },
101     { wxCMD_LINE_SWITCH, wxT_2("h"), wxT_2("help"), wxT_2("print this help message"),
102       wxCMD_LINE_VAL_NONE,
103       wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_OPTION_HELP },
104     { wxCMD_LINE_PARAM, NULL, NULL, wxT_2("input file"),
105       wxCMD_LINE_VAL_STRING,
106       wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
107     wxCMD_LINE_DESC_END
108   };
109
110   parser.SetDesc(cmdLineDesc);
111 }
112
113 bool CTSimApp::OnCmdLineParsed(wxCmdLineParser& parser)
114 {
115   if (wxApp::OnCmdLineParsed(parser) == false)
116     return false;
117
118   if (parser.Found(_T("version"))) {
119 #ifdef VERSION
120       std::cout << "Version: " << VERSION << std::endl;
121 #elif defined(CTSIMVERSION)
122       std::cout << "Version: " << CTSIMVERSION << std::endl;
123 #else
124       std::cout << "Version: " << "Unknown" << std::endl;
125 #endif
126       return false;
127   }
128   if (parser.Found(_T("print"))) {
129     m_bPrintCmdLineImages = true;
130   }
131   if (parser.Found(_T("verbose"))) {
132     m_bCmdLineVerboseFlag = true;
133   }
134
135   return true;
136 }
137
138 bool
139 CTSimApp::OnInit()
140 {
141   if (! wxApp::OnInit())
142     return false;
143
144 #ifdef HAVE_SETPRIORITY
145   setpriority (PRIO_PROCESS, 0, 15);  // set to low scheduling priority
146 #endif
147
148   openConfig();
149
150   g_bRunningWXWindows = true;
151   m_docManager = new wxDocManager (wxDEFAULT_DOCMAN_FLAGS, true);
152
153   m_pDocTemplImage = new wxDocTemplate (m_docManager, _T("ImageFile"), _T("*.if"), _T(""), _T("if"), _T("ImageFile"), _T("ImageView"), CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
154   m_pDocTemplProjection = new wxDocTemplate (m_docManager, _T("ProjectionFile"), _T("*.pj"), _T(""), _T("pj"), _T("ProjectionFile"), _T("ProjectionView"), CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
155   m_pDocTemplPhantom = new wxDocTemplate (m_docManager, _T("PhantomFile"), _T("*.phm"), _T(""), _T("phm"), _T("PhantomFile"), _T("PhantomView"), CLASSINFO(PhantomFileDocument), CLASSINFO(PhantomFileView));
156   m_pDocTemplPlot = new wxDocTemplate (m_docManager, _T("PlotFile"), _T("*.plt"), _T(""), _T("plt"), _T("PlotFile"), _T("PlotView"), CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
157   m_pDocTemplText = new wxDocTemplate (m_docManager, _T("TextFile"), _T("*.txt"), _T(""), _T("txt"), _T("TextFile"), _T("TextView"), CLASSINFO(TextFileDocument), CLASSINFO(TextFileView), wxTEMPLATE_INVISIBLE);
158 #if wxUSE_GLCANVAS
159   m_pDocTemplGraph3d = new wxDocTemplate (m_docManager, _T("Graph3dFile"), _T("*.g3d"), _T(""), _T("g3d"),
160                                           _T("Graph3dFile"), _T("Graph3dView"), CLASSINFO(Graph3dFileDocument), 
161                                           CLASSINFO(Graph3dFileView), wxTEMPLATE_INVISIBLE);
162 #endif
163
164 #if wxUSE_GIF
165   wxImage::AddHandler(new wxGIFHandler);     // Required for images in the online documentation
166 #endif
167
168 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
169   wxFileSystem::AddHandler(new wxZipFSHandler);     // Required for advanced HTML help
170 #endif
171
172   // Create the main frame window
173   int xDisplay, yDisplay;
174   ::wxDisplaySize (&xDisplay, &yDisplay);
175
176 #ifdef CTSIM_MDI
177   wxSize frameSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .75));
178 #else
179   wxSize frameSize(nearest<int>(xDisplay * .6), nearest<int>(yDisplay * .4));
180 #endif
181
182   m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, _T("CTSim"), wxPoint(0, 0), frameSize, wxDEFAULT_FRAME_STYLE);
183
184   setIconForFrame (m_pFrame);
185   m_pFrame->Centre(wxBOTH);
186   m_pFrame->Show(true);
187   SetTopWindow (m_pFrame);
188
189   if (m_pConfig)
190     m_docManager->FileHistoryLoad(*m_pConfig);
191
192 #ifdef CTSIM_MDI
193   m_pLogDoc = newTextDoc();
194   if (m_pLogDoc) {
195     m_pLog = m_pLogDoc->getTextCtrl();
196     m_pLogDoc->SetDocumentName(_T("Log.txt"));
197     m_pLogDoc->SetFilename(_T("Log.txt"));
198     m_pLogDoc->getView()->getFrame()->SetTitle(_T("Log"));
199     int xSize, ySize;
200     m_pFrame->GetClientSize(&xSize, &ySize);
201     int yLogSize = ySize / 4;
202     m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
203     m_pLogDoc->getView()->getFrame()->Show (true);
204   } else
205 #else
206     m_pLog = new wxTextCtrl (m_pFrame, -1, _T("Log Window\n"), wxPoint(0, 0), frameSize, wxTE_MULTILINE | wxTE_READONLY);
207 #endif
208   wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
209
210   wxString helpDir;
211   if (! m_pConfig->Read(_T("HelpDir"), &helpDir))
212     helpDir = ::wxGetCwd();
213 #ifdef CTSIM_WINHELP
214   if (! m_pFrame->getWinHelpController().Initialize(helpDir + _T("/ctsim")))
215     *m_pLog << _T("Cannot initialize the Windows Help system") << _T("\n");
216 #else
217 #ifdef DATADIR
218   wxString docDir (DATADIR, *wxConvCurrent);
219 #else
220   wxString docDir (::wxGetCwd());
221 #endif
222   wxString docFile = docDir + _T("ctsim.htb");
223   if (! m_pFrame->getHtmlHelpController().AddBook(docFile) &&
224       ! m_pFrame->getHtmlHelpController().AddBook(_T("/usr/share/ctsim/ctsim.htb")) &&
225       ! m_pFrame->getHtmlHelpController().AddBook(_T("/tmp/ctsim.htb")))
226     *m_pLog << _T("Cannot initialize the HTML Help system") << _T("\n");
227   else {
228     if (::wxDirExists (_T("/tmp")))
229       m_pFrame->getHtmlHelpController().SetTempDir(_T("/tmp"));
230     m_pFrame->getHtmlHelpController().UseConfig (m_pConfig);
231   }
232 #endif
233
234   for (int i = optind + 1; i <= argc; i++) {
235     wxString filename = argv [i - 1];
236     wxDocument* pNewDoc = m_docManager->CreateDocument (filename, wxDOC_SILENT);
237     if (m_bPrintCmdLineImages) {
238       wxView* pNewView = pNewDoc->GetFirstView();
239       wxPrintout *printout = pNewView->OnCreatePrintout();
240       if (printout) {
241         wxPrinter printer;
242         printer.Print(pNewView->GetFrame(), printout, TRUE);
243         delete printout;
244       }
245       wxCommandEvent nullEvent;
246       nullEvent.SetId (wxID_CLOSE);
247       m_docManager->OnFileClose (nullEvent);
248     }
249   }
250
251   if (m_bPrintCmdLineImages) {
252     wxCommandEvent closeEvent;
253     closeEvent.SetInt (MAINMENU_FILE_EXIT);
254     m_pFrame->GetEventHandler()->ProcessEvent(closeEvent);
255   }
256
257   if (getStartupTips())
258     ShowTips();
259
260 #ifdef HAVE_WXTHREADS
261   m_pBackgroundMgr = new BackgroundManager;
262 #endif
263
264   return true;
265 }
266
267 void
268 CTSimApp::ShowTips()
269 {
270   CTSimTipProvider tipProvider (m_iCurrentTip);
271   setStartupTips (::wxShowTip (m_pFrame, &tipProvider, getStartupTips()));
272   m_iCurrentTip = tipProvider.GetCurrentTip();
273 }
274
275
276 #include "./ctsim.xpm"
277 void
278 CTSimApp::setIconForFrame(wxFrame* pFrame)
279 {
280   wxIcon iconApp (ctsim16_xpm);
281
282   if (iconApp.Ok())
283     pFrame->SetIcon (iconApp);
284 }
285
286 void
287 CTSimApp::usage(const char* program)
288 {
289   std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
290   std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
291   std::cout << "\n";
292   std::cout << "  --version Display version\n";
293   std::cout << "  --help    Display this help message\n";
294 }
295
296 int
297 CTSimApp::OnExit()
298 {
299   closeConfig();
300
301 #ifdef HAVE_DMALLOC
302   dmalloc_shutdown();
303 #endif
304   return 0;
305 }
306
307 void
308 CTSimApp::openConfig()
309 {
310 #ifdef MSVC
311   m_pConfig = new wxConfig(_T("ctsim"), _T("Kevin Rosenberg"), _T(""), _T(""), wxCONFIG_USE_LOCAL_FILE);
312 #else
313   m_pConfig = new wxConfig(_T("ctsim"), _T("Kevin Rosenberg"), _T(".ctsim"), _T(""), wxCONFIG_USE_LOCAL_FILE);
314 #endif
315
316   wxConfigBase::Set(m_pConfig);
317   m_pConfig->Read (_T("AdvancedOptions"), &m_bAdvancedOptions);
318   m_pConfig->Read (_T("SetModifyNewDocs"), &m_bSetModifyNewDocs);
319   m_pConfig->Read (_T("VerboseLogging"), &m_bVerboseLogging);
320   m_pConfig->Read (_T("StartupTips"), &m_bShowStartupTips);
321   m_pConfig->Read (_T("CurrentTip"), &m_iCurrentTip);
322   m_pConfig->Read (_T("UseBackgroundTasks"), &m_bUseBackgroundTasks);
323 #ifdef HAVE_FFTW
324   wxString strFftwWisdom;
325   m_pConfig->Read (_T("FftwWisdom"), strFftwWisdom);
326   if (strFftwWisdom.size() > 0)
327     fftw_import_wisdom_from_string (strFftwWisdom.mb_str(wxConvUTF8));
328 #endif
329 }
330
331 void
332 CTSimApp::closeConfig()
333 {
334   m_pConfig->Write (_T("AdvancedOptions"), m_bAdvancedOptions);
335   m_pConfig->Write (_T("SetModifyNewDocs"), m_bSetModifyNewDocs);
336   m_pConfig->Write (_T("VerboseLogging"), m_bVerboseLogging);
337   m_pConfig->Write (_T("StartupTips"), m_bShowStartupTips);
338   m_pConfig->Write (_T("CurrentTip"), m_iCurrentTip);
339   m_pConfig->Write (_T("UseBackgroundTasks"), m_bUseBackgroundTasks);
340 #ifdef HAVE_FFTW
341   const char* const pszWisdom = fftw_export_wisdom_to_string();
342   wxString strFftwWisdom (pszWisdom, *wxConvCurrent);
343   fftw_free ((void*) pszWisdom);
344   m_pConfig->Write (_T("FftwWisdom"), strFftwWisdom);
345 #endif
346
347   delete m_pConfig;
348 }
349
350
351 // Top-level window for CTSim
352
353 #if CTSIM_MDI
354 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
355
356 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
357 #else
358 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
359
360 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
361 #endif
362
363 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
364 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
365 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
366 EVT_MENU(MAINMENU_HELP_TIPS, MainFrame::OnHelpTips)
367 EVT_MENU(MAINMENU_IMPORT, MainFrame::OnImport)
368 EVT_MENU(IDH_QUICKSTART, MainFrame::OnHelpButton)
369 EVT_MENU(MAINMENU_LOG_EVENT, MainFrame::OnLogEvent)
370 EVT_MENU(NEW_IMAGEFILE_EVENT, MainFrame::OnNewImageFile)
371 EVT_MENU(NEW_PROJECTIONFILE_EVENT, MainFrame::OnNewProjectionFile)
372 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
373 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
374 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
375 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
376 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
377 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
378 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
379 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
380 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
381 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
382 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
383
384 EVT_SIZE(MainFrame::OnSize)
385
386 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
387 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
388 #endif
389 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
390 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
391 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
392
393 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
394
395 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
396 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
397 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
398 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
399 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
400 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
401 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
402 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
403 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
404 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
405 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
406 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
407 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
408 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
409 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
410 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
411 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
412 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
413 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
414 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
415 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
416 END_EVENT_TABLE()
417
418
419
420 #if CTSIM_MDI
421 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
422 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, _T("MainFrame"))
423 #else
424 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
425 : wxDocParentFrame(manager, frame, id, title, pos, size, type, _T("MainFrame"))
426 #endif
427 {
428   m_bShuttingDown = false;
429
430   //// Make a menubar
431   wxMenu *file_menu = new wxMenu;
432
433   file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, _T("Cr&eate Phantom...\tCtrl-P"));
434   file_menu->Append(MAINMENU_FILE_CREATE_FILTER, _T("Create &Filter...\tCtrl-F"));
435   file_menu->Append(wxID_OPEN, _T("&Open...\tCtrl-O"));
436
437   file_menu->AppendSeparator();
438   file_menu->Append (MAINMENU_IMPORT, _T("&Import...\tCtrl-M"));
439   file_menu->Append (MAINMENU_FILE_PREFERENCES, _T("Prefere&nces..."));
440   file_menu->Append(MAINMENU_FILE_EXIT, _T("E&xit"));
441
442   //  history of files visited
443   theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
444   theApp->getDocManager()->FileHistoryUseMenu(file_menu);
445
446 #ifndef CTSIM_MDI
447   m_pWindowMenu = new wxMenu;
448   m_pWindowMenu->UpdateUI (this);
449 #endif
450
451   wxMenu* help_menu = new wxMenu;
452   help_menu->Append (MAINMENU_HELP_CONTENTS, _T("&Contents\tF1"));
453   help_menu->Append (MAINMENU_HELP_TIPS, _T("&Tips"));
454   help_menu->Append (IDH_QUICKSTART, _T("&Quick Start"));
455 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
456   help_menu->Append (MAINMENU_HELP_SECONDARY, _T("&Secondary Help"));
457 #endif
458   help_menu->Append (MAINMENU_HELP_ABOUT, _T("&About"));
459
460   wxMenuBar* menu_bar = new wxMenuBar;
461
462   menu_bar->Append(file_menu, _T("&File"));
463 #ifndef CTSIM_MDI
464   menu_bar->Append(m_pWindowMenu, _T("&Window"));
465 #endif
466   menu_bar->Append(help_menu, _T("&Help"));
467
468   SetMenuBar(menu_bar);
469
470
471 #ifndef CTSIM_MDI
472   int i;
473   for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
474     m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, _T("[EMPTY]"));
475     m_pWindowMenu->Append (m_apWindowMenuItems[i]);
476     m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
477   }
478 #endif
479
480   m_iDefaultPhantomID = Phantom::PHM_HERMAN;
481   m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
482   m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
483   m_iDefaultFilterXSize = 256;
484   m_iDefaultFilterYSize = 256;
485   m_dDefaultFilterParam = 1.;
486   m_dDefaultFilterBandwidth = 1.;
487   m_dDefaultFilterInputScale = 1.;
488   m_dDefaultFilterOutputScale = 1.;
489   m_iDefaultImportFormat = ImageFile::IMPORT_FORMAT_PNG;
490
491   wxAcceleratorEntry accelEntries[15];
492   accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
493   accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
494   accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
495   accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('M'), MAINMENU_IMPORT);
496   accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
497 #ifndef CTSIM_MDI
498   for (i = 0; i < 10; i++)
499     accelEntries[i+5].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
500   wxAcceleratorTable accelTable (15, accelEntries);
501 #else
502   wxAcceleratorTable accelTable (5, accelEntries);
503 #endif
504
505   SetAcceleratorTable (accelTable);
506 }
507
508 MainFrame::~MainFrame()
509 {
510   m_bShuttingDown = true; // Currently used so that Log Window will close
511 #if 0
512   // delete all non-modified documents
513   wxList& rListDocs = theApp->getDocManager()->GetDocuments();
514   for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
515     wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
516     if (pDoc && ! pDoc->IsModified()) {
517       theApp->getDocManager()->RemoveDocument(pDoc);
518       delete pDoc;
519     }
520   }
521 #endif
522   ::wxYield();
523   if (theApp->getConfig())
524     theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
525   ::wxYield();
526   delete theApp->getDocManager();
527
528 }
529
530 void
531 MainFrame::OnSize (wxSizeEvent& event)
532 {
533 #ifdef CTSIM_MDI
534   if (theApp->getLogDoc()) {
535     int xSize, ySize;
536     GetClientSize(&xSize, &ySize);
537     int yLogSize = ySize / 4;
538     theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
539     theApp->getLogDoc()->getView()->getFrame()->Show (true);
540   }
541 #endif
542
543 #if CTSIM_MDI
544   wxDocMDIParentFrame::OnSize (event);
545 #else
546   wxDocParentFrame::OnSize (event);
547 #endif
548 }
549
550 void
551 MainFrame::OnCreatePhantom(wxCommandEvent& event)
552 {
553   DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
554   int dialogReturn = dialogPhantom.ShowModal();
555   if (dialogReturn == wxID_OK) {
556     wxString selection (dialogPhantom.getPhantom(), *wxConvCurrent);
557     if (theApp->getVerboseLogging())
558       *theApp->getLog() << _T("Selected phantom ") << selection.c_str() << _T("\n");
559     wxString filename = selection + _T(".phm");
560     m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.mb_str(wxConvUTF8));
561     theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
562   }
563
564 }
565
566 void
567 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
568 {
569   DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
570   int dialogReturn = dialogFilter.ShowModal();
571   if (dialogReturn == wxID_OK) {
572     wxString strFilter (dialogFilter.getFilterName(), *wxConvCurrent);
573     wxString strDomain (dialogFilter.getDomainName(), *wxConvCurrent);
574     m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.mb_str(wxConvUTF8));
575     m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.mb_str(wxConvUTF8));
576     m_iDefaultFilterXSize = dialogFilter.getXSize();
577     m_iDefaultFilterYSize = dialogFilter.getYSize();
578     m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
579     m_dDefaultFilterParam= dialogFilter.getFilterParam();
580     m_dDefaultFilterInputScale = dialogFilter.getInputScale();
581     m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
582     wxString os;
583     os << _T("Generate Filter=") << strFilter
584        << _T(", size=(") << static_cast<int>(m_iDefaultFilterXSize) << _T(",")
585        << static_cast<int>(m_iDefaultFilterYSize)
586        << _T("), domain=") << strDomain.c_str() << _T(", filterParam=")
587        << m_dDefaultFilterParam << _T(", bandwidth=") <<
588       m_dDefaultFilterBandwidth
589        << _T(", inputScale=") << m_dDefaultFilterInputScale << _T(", outputScale=") << m_dDefaultFilterOutputScale;
590     *theApp->getLog() << os << _T("\n");
591     ImageFileDocument* pFilterDoc = theApp->newImageDoc();
592     pFilterDoc->setBadFileOpen();
593     if (! pFilterDoc) {
594       sys_error (ERR_SEVERE, "Unable to create filter image");
595       return;
596     }
597     ImageFile& rIF = pFilterDoc->getImageFile();
598     rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
599     rIF.filterResponse (strDomain.mb_str(wxConvUTF8), m_dDefaultFilterBandwidth, strFilter.mb_str(wxConvUTF8), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
600     rIF.labelAdd (os.mb_str(wxConvUTF8));
601     if (theApp->getAskDeleteNewDocs())
602       pFilterDoc->Modify (true);
603     pFilterDoc->UpdateAllViews();
604     pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
605     pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
606     pFilterDoc->getView()->getFrame()->Show(true);
607   }
608 }
609
610 void
611 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
612 {
613   const ImageFile& rIF = pIFDoc->getImageFile();
614   unsigned int nx = rIF.nx();
615   unsigned int ny = rIF.ny();
616   wxList& rListDocs = m_docManager->GetDocuments();
617   for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
618     wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
619     ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
620     if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
621       const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
622       if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
623         vecIF.push_back (pIFCompareDoc);
624     }
625   }
626 }
627
628
629 void
630 MainFrame::OnNewImageFile (wxCommandEvent& event)
631 {
632   ImageFile* pImageFile = reinterpret_cast<ImageFile*>(event.GetClientData());
633
634   ImageFileDocument* pImageDoc = theApp->newImageDoc();
635   if (! pImageDoc) {
636     sys_error (ERR_SEVERE, "Unable to create image file");
637     return;
638   }
639   pImageDoc->setImageFile (pImageFile);
640   if (theApp->getAskDeleteNewDocs())
641     pImageDoc->Modify (true);
642 }
643
644 void
645 MainFrame::OnNewProjectionFile (wxCommandEvent& event)
646 {
647   Projections* pProjections = reinterpret_cast<Projections*>(event.GetClientData());
648   ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
649   if (! pProjDoc) {
650     sys_error (ERR_SEVERE, "Unable to create projection file");
651     return;
652   }
653   pProjDoc->setProjections (pProjections);
654   if (theApp->getAskDeleteNewDocs())
655     pProjDoc->Modify (true);
656 }
657
658 void
659 MainFrame::OnLogEvent (wxCommandEvent& event)
660 {
661   *theApp->getLog() << event.GetString();
662 }
663
664 void
665 MainFrame::OnHelpTips (wxCommandEvent& event)
666 {
667   theApp->ShowTips();
668 }
669
670 void
671 MainFrame::OnHelpContents (wxCommandEvent& event)
672 {
673   showHelp (event.GetId());
674 }
675
676 void
677 MainFrame::OnHelpButton (wxCommandEvent& event)
678 {
679   showHelp (event.GetId());
680 }
681
682 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
683 void
684 MainFrame::OnHelpSecondary (wxCommandEvent& event)
685 {
686   m_htmlHelp.Display ("Contents");
687 }
688 #endif
689
690 void
691 MainFrame::showHelp (int commandID)
692 {
693   switch (commandID) {
694
695   case MAINMENU_HELP_CONTENTS:
696 #ifdef CTSIM_WINHELP
697     m_winHelp.DisplayContents ();
698 #else
699     m_htmlHelp.Display (_T("Contents"));
700 #endif
701     break;
702
703   default:
704 #ifdef CTSIM_WINHELP
705     m_winHelp.DisplaySection (commandID);
706 #else
707     m_htmlHelp.Display (commandID);
708 #endif
709     break;
710   }
711 }
712
713 void
714 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
715 {
716   Close(true);
717 }
718
719 void
720 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
721 {
722 #ifndef CTSIM_MDI
723   int iPos = 0;
724   wxList& rListDocs = theApp->getDocManager()->GetDocuments();
725   wxNode* pNode = rListDocs.GetFirst();
726   while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
727     wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
728     wxString strFilename = pDoc->GetFilename();
729     if (iPos < 10) {
730       strFilename += _T("\tCtrl-");
731       strFilename += static_cast<char>('0' + iPos);
732     }
733     static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetItemLabel (strFilename);
734     m_apWindowMenuData[iPos] = pDoc;
735     m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
736     iPos++;
737     pNode = pNode->GetNext();
738   }
739   for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
740     m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
741     static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetItemLabel (_T("[EMPTY]"));
742     m_apWindowMenuData[i] = NULL;
743   }
744 #endif
745 }
746
747
748 void
749 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
750 {
751   if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
752     wxString strFilename = pDoc->GetFilename();
753     const wxView* pView = pDoc->GetFirstView();
754     if (pView) {
755       wxWindow* pWindow = pView->GetFrame();
756       pWindow->SetFocus();
757       pWindow->Raise();
758     }
759   }
760 }
761
762 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
763 { DoWindowMenu (0, event); }
764
765 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
766 { DoWindowMenu (1, event); }
767
768 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
769 { DoWindowMenu (2, event); }
770
771 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
772 { DoWindowMenu (3, event); }
773
774 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
775 { DoWindowMenu (4, event); }
776
777 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
778 { DoWindowMenu (5, event); }
779
780 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
781 { DoWindowMenu (6, event); }
782
783 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
784 { DoWindowMenu (7, event); }
785
786 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
787 { DoWindowMenu (8, event); }
788
789 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
790 { DoWindowMenu (9, event); }
791
792 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
793 { DoWindowMenu (10, event); }
794
795 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
796 { DoWindowMenu (11, event); }
797
798 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
799 { DoWindowMenu (12, event); }
800
801 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
802 { DoWindowMenu (13, event); }
803
804 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
805 { DoWindowMenu (14, event); }
806
807 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
808 { DoWindowMenu (15, event); }
809
810 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
811 { DoWindowMenu (16, event); }
812
813 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
814 { DoWindowMenu (17, event); }
815
816 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
817 { DoWindowMenu (18, event); }
818
819 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
820 { DoWindowMenu (19, event); }
821
822
823 class BitmapControl : public wxPanel
824 {
825 private:
826   DECLARE_DYNAMIC_CLASS (BitmapControl)
827     DECLARE_EVENT_TABLE ()
828     wxBitmap* m_pBitmap;
829
830 public:
831   BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
832     const wxPoint& pos = wxDefaultPosition,
833     const wxSize& size = wxDefaultSize,
834     long style = wxSTATIC_BORDER,
835     const wxValidator& validator = wxDefaultValidator,
836                  const wxString& name = _T("BitmapCtrl"));
837
838
839   virtual ~BitmapControl();
840
841   virtual wxSize GetBestSize() const;
842
843   wxBitmap* getBitmap()
844   { return m_pBitmap; }
845
846   void OnPaint(wxPaintEvent& event);
847 };
848
849
850 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
851 EVT_PAINT(BitmapControl::OnPaint)
852 END_EVENT_TABLE()
853
854 IMPLEMENT_CLASS(BitmapControl, wxPanel)
855
856
857 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
858                               long style, const wxValidator& validator, const wxString& name)
859                               : m_pBitmap(pBitmap)
860 {
861   Create(parent, id, pos, size, style, name);
862
863   SetSize (GetBestSize());
864 }
865
866 wxSize
867 BitmapControl::GetBestSize () const
868 {
869   if (m_pBitmap)
870     return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
871   else
872     return wxSize(0,0);
873 }
874
875 BitmapControl::~BitmapControl()
876 {}
877
878 void
879 BitmapControl::OnPaint (wxPaintEvent& event)
880 {
881   wxPaintDC dc(this);
882   if (m_pBitmap)
883     dc.DrawBitmap (*m_pBitmap, 0, 0);
884 }
885
886
887 class BitmapDialog : public wxDialog {
888 private:
889   BitmapControl* m_pBitmapCtrl;
890
891 public:
892   BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
893   virtual ~BitmapDialog();
894 };
895
896 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
897   : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle,*wxConvCurrent))
898 {
899   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
900
901   pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
902
903   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
904   wxButton* pButtonOk = new wxButton (this, wxID_OK, _T("Ok"));
905   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
906
907   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
908
909   SetAutoLayout (true);
910   SetSizer (pTopSizer);
911   pTopSizer->Fit (this);
912   pTopSizer->SetSizeHints (this);
913 }
914
915 BitmapDialog::~BitmapDialog()
916 {}
917
918
919 void
920 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
921 {
922   DialogPreferences dlg (this, _T("CTSim Preferences"), theApp->getAdvancedOptions(),
923     theApp->getAskDeleteNewDocs(), theApp->getVerboseLogging(), theApp->getStartupTips(),
924     theApp->getUseBackgroundTasks());
925   if (dlg.ShowModal() == wxID_OK) {
926     theApp->setAdvancedOptions (dlg.getAdvancedOptions());
927     theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
928     theApp->setVerboseLogging (dlg.getVerboseLogging());
929     theApp->setStartupTips (dlg.getStartupTips());
930     theApp->setUseBackgroundTasks (dlg.getUseBackgroundTasks());
931   }
932 }
933
934 void
935 MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
936 {
937   DialogImportParameters dialogImport (this, m_iDefaultImportFormat);
938   if (dialogImport.ShowModal() != wxID_OK)
939     return;
940
941   wxString strFormatName (dialogImport.getFormatName (), *wxConvCurrent);
942   m_iDefaultImportFormat = ImageFile::convertImportFormatNameToID (strFormatName.mb_str(wxConvUTF8));
943
944   wxString strExt;
945   wxString strWildcard;
946   if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM) {
947     strExt = _T(".ppm");
948     strWildcard = _T("PPM Files (*.ppm)|*.ppm|PGM Files (*.pgm)|*.pgm");
949   }
950 #ifdef HAVE_PNG
951   else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
952     strExt = _T(".png");
953     strWildcard = _T("PNG Files (*.png)|*.png");
954   }
955 #endif
956 #ifdef HAVE_CTN_DICOM
957   else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
958     strExt = _T("*.*");
959     strWildcard = _T("Dicom Files (*.*)|*.*");
960   }
961 #endif
962   else {
963     return;
964   }
965
966   wxString strFilename = wxFileSelector (wxString(wxConvUTF8.cMB2WX("Import Filename")), wxString(wxConvUTF8.cMB2WX("")),
967                                          wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxFD_OPEN);
968
969   if (! strFilename.IsEmpty()) {
970     if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
971       ImageFile* pIF = new ImageFile;
972       if (pIF->importImage (strFormatName.mb_str(wxConvUTF8), strFilename.mb_str(wxConvUTF8))) {
973         ImageFileDocument* pIFDoc = theApp->newImageDoc();
974         pIFDoc->setImageFile(pIF);
975         pIFDoc->getView()->getFrame()->Show(true);
976         std::ostringstream os;
977         os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
978         pIF->labelAdd (os.str().c_str());
979         if (theApp->getAskDeleteNewDocs())
980           pIFDoc->Modify (true);
981         pIFDoc->UpdateAllViews();
982         pIFDoc->GetFirstView()->OnUpdate (NULL, NULL);
983         pIFDoc->getView()->getFrame()->Show(true);
984       } else
985         delete pIF;
986     }
987 #ifdef HAVE_CTN_DICOM
988     else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
989       DicomImporter dicomImport (strFilename.mb_str(wxConvUTF8));
990       if (dicomImport.fail()) {
991         ::wxMessageBox (wxConvUTF8.cMB2WX(dicomImport.failMessage().c_str()), _T("Import Error"));
992       } else if (dicomImport.testImage()) {
993         ImageFileDocument* pIFDoc = theApp->newImageDoc();
994         ImageFile* pIF = dicomImport.getImageFile();
995         pIFDoc->setImageFile (pIF);
996         std::ostringstream os;
997         os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
998         pIF->labelAdd (os.str().c_str());
999         if (theApp->getAskDeleteNewDocs())
1000           pIFDoc->Modify (true);
1001         pIFDoc->UpdateAllViews();
1002         pIFDoc->getView()->setInitialClientSize();
1003         pIFDoc->Activate();
1004       } else if (dicomImport.testProjections()) {
1005         ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
1006         Projections* pProj = dicomImport.getProjections();
1007         pProjDoc->setProjections (pProj);
1008         pProjDoc->getView()->getFrame()->Show(true);
1009         std::ostringstream os;
1010         os << "Import projection file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
1011         pProj->setRemark (os.str().c_str());
1012         if (theApp->getAskDeleteNewDocs())
1013           pProjDoc->Modify (true);
1014         pProjDoc->UpdateAllViews();
1015         pProjDoc->getView()->setInitialClientSize();
1016         pProjDoc->Activate();
1017       } else
1018         ::wxMessageBox (_T("Unrecognized DICOM file contents"), _T("Import Error"));
1019     }
1020 #endif
1021     else
1022       sys_error (ERR_WARNING, "Unknown import format type");
1023   }
1024 }
1025
1026 #include "./splash.xpm"
1027 void
1028 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
1029 {
1030   wxString strOSDesc = ::wxGetOsDescription();
1031   *theApp->getLog() << _T("Operating System: ") << strOSDesc;
1032   *theApp->getLog() << _T(", wxWindows: ") << wxVERSION_STRING;
1033 #ifdef _TIMESTAMP__
1034   *theApp->getLog() << _T(", Build Date: ") << wxConvUTF8.cMB2WX(_TIMESTAMP__);
1035 #endif
1036 #if defined(DEBUG)
1037   *theApp->getLog() << _T(", Debug version");
1038 #else
1039   *theApp->getLog() << _T(", Release version");
1040 #endif
1041 #ifdef VERSION
1042   *theApp->getLog() << _T(" ") <<  wxConvUTF8.cMB2WX(VERSION);
1043 #elif defined(CTSIMVERSION)
1044   *theApp->getLog() << _T(" ") <<  _T(CTSIMVERSION);
1045 #endif
1046     *theApp->getLog() << _T("\n");
1047
1048   wxBitmap bmp (splash);
1049   if (bmp.Ok()) {
1050     BitmapDialog dlg (&bmp, "About CTSim");
1051     dlg.ShowModal();
1052   } else {
1053     wxString msg = _T("CTSim\nThe Open Source Computed Tomography Simulator\n");
1054 #ifdef VERSION
1055     msg << _T("Version: ") <<  wxConvUTF8.cMB2WX(VERSION) << _T("\n\n");
1056 #elif defined(CTSIMVERSION)
1057     msg << _T("Version: ") <<  wxConvUTF8.cMB2WX(CTSIMVERSION) << _T("\n\n");
1058 #endif
1059     msg += _T("Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]");
1060
1061     wxMessageBox(msg, _T("About CTSim"), wxOK | wxICON_INFORMATION, this);
1062     *theApp->getLog() << msg << wxConvUTF8.cMB2WX("\n");
1063   }
1064 }
1065
1066
1067 // Create new documents
1068
1069 wxDocument* 
1070 CTSimApp::newDocumentHelper (wxDocTemplate* tmpl) {
1071   wxDocument* newDoc = tmpl->CreateDocument (_T(""));
1072   if (newDoc) {
1073     newDoc->SetDocumentTemplate (tmpl);
1074     newDoc->OnNewDocument();
1075     wxString fname = newDoc->GetFilename();
1076     fname += _T(".");
1077     fname += tmpl->GetDefaultExtension();
1078     newDoc->SetDocumentName(fname);
1079     newDoc->SetTitle(fname);
1080     newDoc->SetFilename(fname, true);
1081   }
1082
1083   return newDoc;
1084 }
1085
1086 ProjectionFileDocument*
1087 CTSimApp::newProjectionDoc()
1088 {
1089   ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>
1090     (newDocumentHelper(m_pDocTemplProjection));
1091   if (newDoc)
1092     newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
1093   return newDoc;
1094 }
1095
1096 ImageFileDocument*
1097 CTSimApp::newImageDoc()
1098 {
1099   ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>
1100     (newDocumentHelper(m_pDocTemplImage));
1101   if (newDoc)
1102     newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
1103
1104   return newDoc;
1105 }
1106
1107 PlotFileDocument*
1108 CTSimApp::newPlotDoc()
1109 {
1110   PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>
1111     (newDocumentHelper(m_pDocTemplPlot));
1112   if (newDoc)
1113     newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
1114
1115   return newDoc;
1116 }
1117
1118
1119 TextFileDocument*
1120 CTSimApp::newTextDoc()
1121 {
1122   TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>
1123     (newDocumentHelper(m_pDocTemplText));
1124   if (newDoc)
1125     newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
1126
1127   return newDoc;
1128 }
1129
1130
1131 PhantomFileDocument*
1132 CTSimApp::newPhantomDoc()
1133 {
1134   PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>
1135     (newDocumentHelper(m_pDocTemplPhantom));
1136   if (newDoc)
1137     newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
1138
1139   return newDoc;
1140 }
1141
1142
1143 #if wxUSE_GLCANVAS
1144 Graph3dFileDocument*
1145 CTSimApp::newGraph3dDoc()
1146 {
1147   Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>
1148     (newDocumentHelper(m_pDocTemplGraph3d));
1149   if (newDoc)
1150     newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
1151
1152   return newDoc;
1153 }
1154
1155 #endif