Fix extension for 3d graph
[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, _T("l"), _T("verbose"), _T("verbose logging") },
97     { wxCMD_LINE_SWITCH, _T("v"), _T("version"), _T("print version") },
98     { wxCMD_LINE_SWITCH, _T("p"), _T("print"), _T("print images from command line"),
99       wxCMD_LINE_VAL_NONE,
100       wxCMD_LINE_PARAM_OPTIONAL },
101     { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("print this help message"),
102       wxCMD_LINE_VAL_NONE,
103       wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_OPTION_HELP },
104     { wxCMD_LINE_PARAM, NULL, NULL, _T("input file"),
105       wxCMD_LINE_VAL_STRING,
106       wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
107     { wxCMD_LINE_NONE }
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("Log.txt");
197     m_pLogDoc->SetFilename("Log.txt");
198     m_pLogDoc->getView()->getFrame()->SetTitle("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   if (m_bPrintCmdLineImages) {
251     wxCommandEvent closeEvent;
252     closeEvent.SetInt (MAINMENU_FILE_EXIT);
253     m_pFrame->AddPendingEvent(closeEvent);
254   }
255
256   if (getStartupTips())
257     ShowTips();
258
259 #ifdef HAVE_WXTHREADS
260   m_pBackgroundMgr = new BackgroundManager;
261 #endif
262
263   return true;
264 }
265
266 void
267 CTSimApp::ShowTips()
268 {
269   CTSimTipProvider tipProvider (m_iCurrentTip);
270   setStartupTips (::wxShowTip (m_pFrame, &tipProvider, getStartupTips()));
271   m_iCurrentTip = tipProvider.GetCurrentTip();
272 }
273
274
275 #include "./ctsim.xpm"
276 void
277 CTSimApp::setIconForFrame(wxFrame* pFrame)
278 {
279   wxIcon iconApp (ctsim16_xpm);
280
281   if (iconApp.Ok())
282     pFrame->SetIcon (iconApp);
283 }
284
285 void
286 CTSimApp::usage(const char* program)
287 {
288   std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
289   std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
290   std::cout << "\n";
291   std::cout << "  --version Display version\n";
292   std::cout << "  --help    Display this help message\n";
293 }
294
295 int
296 CTSimApp::OnExit()
297 {
298   closeConfig();
299
300 #ifdef HAVE_DMALLOC
301   dmalloc_shutdown();
302 #endif
303   return 0;
304 }
305
306 void
307 CTSimApp::openConfig()
308 {
309 #ifdef MSVC
310   m_pConfig = new wxConfig(_T("ctsim"), _T("Kevin Rosenberg"), _T(""), _T(""), wxCONFIG_USE_LOCAL_FILE);
311 #else
312   m_pConfig = new wxConfig(_T("ctsim"), _T("Kevin Rosenberg"), _T(".ctsim"), _T(""), wxCONFIG_USE_LOCAL_FILE);
313 #endif
314
315   wxConfigBase::Set(m_pConfig);
316   m_pConfig->Read (_T("AdvancedOptions"), &m_bAdvancedOptions);
317   m_pConfig->Read (_T("SetModifyNewDocs"), &m_bSetModifyNewDocs);
318   m_pConfig->Read (_T("VerboseLogging"), &m_bVerboseLogging);
319   m_pConfig->Read (_T("StartupTips"), &m_bShowStartupTips);
320   m_pConfig->Read (_T("CurrentTip"), &m_iCurrentTip);
321   m_pConfig->Read (_T("UseBackgroundTasks"), &m_bUseBackgroundTasks);
322 #ifdef HAVE_FFTW
323   wxString strFftwWisdom;
324   m_pConfig->Read (_T("FftwWisdom"), strFftwWisdom);
325   if (strFftwWisdom.size() > 0)
326     fftw_import_wisdom_from_string (strFftwWisdom.mb_str(wxConvUTF8));
327 #endif
328 }
329
330 void
331 CTSimApp::closeConfig()
332 {
333   m_pConfig->Write (_T("AdvancedOptions"), m_bAdvancedOptions);
334   m_pConfig->Write (_T("SetModifyNewDocs"), m_bSetModifyNewDocs);
335   m_pConfig->Write (_T("VerboseLogging"), m_bVerboseLogging);
336   m_pConfig->Write (_T("StartupTips"), m_bShowStartupTips);
337   m_pConfig->Write (_T("CurrentTip"), m_iCurrentTip);
338   m_pConfig->Write (_T("UseBackgroundTasks"), m_bUseBackgroundTasks);
339 #ifdef HAVE_FFTW
340   const char* const pszWisdom = fftw_export_wisdom_to_string();
341   wxString strFftwWisdom (pszWisdom, *wxConvCurrent);
342   fftw_free ((void*) pszWisdom);
343   m_pConfig->Write (_T("FftwWisdom"), strFftwWisdom);
344 #endif
345
346   delete m_pConfig;
347 }
348
349
350 // Top-level window for CTSim
351
352 #if CTSIM_MDI
353 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
354
355 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
356 #else
357 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
358
359 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
360 #endif
361
362 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
363 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
364 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
365 EVT_MENU(MAINMENU_HELP_TIPS, MainFrame::OnHelpTips)
366 EVT_MENU(MAINMENU_IMPORT, MainFrame::OnImport)
367 EVT_MENU(IDH_QUICKSTART, MainFrame::OnHelpButton)
368 EVT_MENU(MAINMENU_LOG_EVENT, MainFrame::OnLogEvent)
369 EVT_MENU(NEW_IMAGEFILE_EVENT, MainFrame::OnNewImageFile)
370 EVT_MENU(NEW_PROJECTIONFILE_EVENT, MainFrame::OnNewProjectionFile)
371 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
372 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
373 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
374 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
375 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
376 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
377 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
378 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
379 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
380 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
381 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
382
383 EVT_SIZE(MainFrame::OnSize)
384
385 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
386 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
387 #endif
388 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
389 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
390 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
391 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
392 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
393 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
394 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
395 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
396 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
397 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
398 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
399 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
400 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
401 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
402 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
403 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
404 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
405 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
406 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
407 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
408 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
409 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
410 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
411 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
412 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
413 END_EVENT_TABLE()
414
415
416
417 #if CTSIM_MDI
418 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
419 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
420 #else
421 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
422 : wxDocParentFrame(manager, frame, id, title, pos, size, type, _T("MainFrame"))
423 #endif
424 {
425   m_bShuttingDown = false;
426
427   //// Make a menubar
428   wxMenu *file_menu = new wxMenu;
429
430   file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, _T("Cr&eate Phantom...\tCtrl-P"));
431   file_menu->Append(MAINMENU_FILE_CREATE_FILTER, _T("Create &Filter...\tCtrl-F"));
432   file_menu->Append(wxID_OPEN, _T("&Open...\tCtrl-O"));
433
434   file_menu->AppendSeparator();
435   file_menu->Append (MAINMENU_IMPORT, _T("&Import...\tCtrl-M"));
436   file_menu->Append (MAINMENU_FILE_PREFERENCES, _T("Prefere&nces..."));
437   file_menu->Append(MAINMENU_FILE_EXIT, _T("E&xit"));
438
439   //  history of files visited
440   theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
441   theApp->getDocManager()->FileHistoryUseMenu(file_menu);
442
443 #ifndef CTSIM_MDI
444   m_pWindowMenu = new wxMenu;
445   m_pWindowMenu->UpdateUI (this);
446 #endif
447
448   wxMenu* help_menu = new wxMenu;
449   help_menu->Append (MAINMENU_HELP_CONTENTS, _T("&Contents\tF1"));
450   help_menu->Append (MAINMENU_HELP_TIPS, _T("&Tips"));
451   help_menu->Append (IDH_QUICKSTART, _T("&Quick Start"));
452 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
453   help_menu->Append (MAINMENU_HELP_SECONDARY, _T("&Secondary Help"));
454 #endif
455   help_menu->Append (MAINMENU_HELP_ABOUT, _T("&About"));
456
457   wxMenuBar* menu_bar = new wxMenuBar;
458
459   menu_bar->Append(file_menu, _T("&File"));
460 #ifndef CTSIM_MDI
461   menu_bar->Append(m_pWindowMenu, _T("&Window"));
462 #endif
463   menu_bar->Append(help_menu, _T("&Help"));
464
465   SetMenuBar(menu_bar);
466
467
468 #ifndef CTSIM_MDI
469   int i;
470   for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
471     m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, _T("[EMPTY]"));
472     m_pWindowMenu->Append (m_apWindowMenuItems[i]);
473     m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
474   }
475 #endif
476
477   m_iDefaultPhantomID = Phantom::PHM_HERMAN;
478   m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
479   m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
480   m_iDefaultFilterXSize = 256;
481   m_iDefaultFilterYSize = 256;
482   m_dDefaultFilterParam = 1.;
483   m_dDefaultFilterBandwidth = 1.;
484   m_dDefaultFilterInputScale = 1.;
485   m_dDefaultFilterOutputScale = 1.;
486   m_iDefaultImportFormat = ImageFile::IMPORT_FORMAT_PNG;
487
488   wxAcceleratorEntry accelEntries[15];
489   accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
490   accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
491   accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
492   accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('M'), MAINMENU_IMPORT);
493   accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
494 #ifndef CTSIM_MDI
495   for (i = 0; i < 10; i++)
496     accelEntries[i+5].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
497   wxAcceleratorTable accelTable (15, accelEntries);
498 #else
499   wxAcceleratorTable accelTable (5, accelEntries);
500 #endif
501
502   SetAcceleratorTable (accelTable);
503 }
504
505 MainFrame::~MainFrame()
506 {
507   m_bShuttingDown = true; // Currently used so that Log Window will close
508 #if 0
509   // delete all non-modified documents
510   wxList& rListDocs = theApp->getDocManager()->GetDocuments();
511   for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
512     wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
513     if (pDoc && ! pDoc->IsModified()) {
514       theApp->getDocManager()->RemoveDocument(pDoc);
515       delete pDoc;
516     }
517   }
518 #endif
519   ::wxYield();
520   if (theApp->getConfig())
521     theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
522   ::wxYield();
523   delete theApp->getDocManager();
524
525 }
526
527 void
528 MainFrame::OnSize (wxSizeEvent& event)
529 {
530 #ifdef CTSIM_MDI
531   if (theApp->getLogDoc()) {
532     int xSize, ySize;
533     GetClientSize(&xSize, &ySize);
534     int yLogSize = ySize / 4;
535     theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
536     theApp->getLogDoc()->getView()->getFrame()->Show (true);
537   }
538 #endif
539
540 #if CTSIM_MDI
541   wxDocMDIParentFrame::OnSize (event);
542 #else
543   wxDocParentFrame::OnSize (event);
544 #endif
545 }
546
547 void
548 MainFrame::OnCreatePhantom(wxCommandEvent& event)
549 {
550   DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
551   int dialogReturn = dialogPhantom.ShowModal();
552   if (dialogReturn == wxID_OK) {
553     wxString selection (dialogPhantom.getPhantom(), *wxConvCurrent);
554     if (theApp->getVerboseLogging())
555       *theApp->getLog() << _T("Selected phantom ") << selection.c_str() << _T("\n");
556     wxString filename = selection + _T(".phm");
557     m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.mb_str(wxConvUTF8));
558     theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
559   }
560
561 }
562
563 void
564 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
565 {
566   DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
567   int dialogReturn = dialogFilter.ShowModal();
568   if (dialogReturn == wxID_OK) {
569     wxString strFilter (dialogFilter.getFilterName(), *wxConvCurrent);
570     wxString strDomain (dialogFilter.getDomainName(), *wxConvCurrent);
571     m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.mb_str(wxConvUTF8));
572     m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.mb_str(wxConvUTF8));
573     m_iDefaultFilterXSize = dialogFilter.getXSize();
574     m_iDefaultFilterYSize = dialogFilter.getYSize();
575     m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
576     m_dDefaultFilterParam= dialogFilter.getFilterParam();
577     m_dDefaultFilterInputScale = dialogFilter.getInputScale();
578     m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
579     wxString os;
580     os << _T("Generate Filter=") << strFilter
581        << _T(", size=(") << static_cast<int>(m_iDefaultFilterXSize) << _T(",")
582        << static_cast<int>(m_iDefaultFilterYSize)
583        << _T("), domain=") << strDomain.c_str() << _T(", filterParam=")
584        << m_dDefaultFilterParam << _T(", bandwidth=") <<
585       m_dDefaultFilterBandwidth
586        << _T(", inputScale=") << m_dDefaultFilterInputScale << _T(", outputScale=") << m_dDefaultFilterOutputScale;
587     *theApp->getLog() << os << _T("\n");
588     ImageFileDocument* pFilterDoc = theApp->newImageDoc();
589     pFilterDoc->setBadFileOpen();
590     if (! pFilterDoc) {
591       sys_error (ERR_SEVERE, "Unable to create filter image");
592       return;
593     }
594     ImageFile& rIF = pFilterDoc->getImageFile();
595     rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
596     rIF.filterResponse (strDomain.mb_str(wxConvUTF8), m_dDefaultFilterBandwidth, strFilter.mb_str(wxConvUTF8), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
597     rIF.labelAdd (os.mb_str(wxConvUTF8));
598     if (theApp->getAskDeleteNewDocs())
599       pFilterDoc->Modify (true);
600     pFilterDoc->UpdateAllViews();
601     pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
602     pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
603     pFilterDoc->getView()->getFrame()->Show(true);
604   }
605 }
606
607 void
608 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
609 {
610   const ImageFile& rIF = pIFDoc->getImageFile();
611   unsigned int nx = rIF.nx();
612   unsigned int ny = rIF.ny();
613   wxList& rListDocs = m_docManager->GetDocuments();
614   for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
615     wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
616     ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
617     if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
618       const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
619       if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
620         vecIF.push_back (pIFCompareDoc);
621     }
622   }
623 }
624
625
626 void
627 MainFrame::OnNewImageFile (wxCommandEvent& event)
628 {
629   ImageFile* pImageFile = reinterpret_cast<ImageFile*>(event.GetClientData());
630
631   ImageFileDocument* pImageDoc = theApp->newImageDoc();
632   if (! pImageDoc) {
633     sys_error (ERR_SEVERE, "Unable to create image file");
634     return;
635   }
636   pImageDoc->setImageFile (pImageFile);
637   if (theApp->getAskDeleteNewDocs())
638     pImageDoc->Modify (true);
639 }
640
641 void
642 MainFrame::OnNewProjectionFile (wxCommandEvent& event)
643 {
644   Projections* pProjections = reinterpret_cast<Projections*>(event.GetClientData());
645   ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
646   if (! pProjDoc) {
647     sys_error (ERR_SEVERE, "Unable to create projection file");
648     return;
649   }
650   pProjDoc->setProjections (pProjections);
651   if (theApp->getAskDeleteNewDocs())
652     pProjDoc->Modify (true);
653 }
654
655 void
656 MainFrame::OnLogEvent (wxCommandEvent& event)
657 {
658   *theApp->getLog() << event.GetString();
659 }
660
661 void
662 MainFrame::OnHelpTips (wxCommandEvent& event)
663 {
664   theApp->ShowTips();
665 }
666
667 void
668 MainFrame::OnHelpContents (wxCommandEvent& event)
669 {
670   showHelp (event.GetId());
671 }
672
673 void
674 MainFrame::OnHelpButton (wxCommandEvent& event)
675 {
676   showHelp (event.GetId());
677 }
678
679 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
680 void
681 MainFrame::OnHelpSecondary (wxCommandEvent& event)
682 {
683   m_htmlHelp.Display ("Contents");
684 }
685 #endif
686
687 void
688 MainFrame::showHelp (int commandID)
689 {
690   switch (commandID) {
691
692   case MAINMENU_HELP_CONTENTS:
693 #ifdef CTSIM_WINHELP
694     m_winHelp.DisplayContents ();
695 #else
696     m_htmlHelp.Display (_T("Contents"));
697 #endif
698     break;
699
700   default:
701 #ifdef CTSIM_WINHELP
702     m_winHelp.DisplaySection (commandID);
703 #else
704     m_htmlHelp.Display (commandID);
705 #endif
706     break;
707   }
708 }
709
710 void
711 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
712 {
713   Close(true);
714 }
715
716 void
717 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
718 {
719 #ifndef CTSIM_MDI
720   int iPos = 0;
721   wxList& rListDocs = theApp->getDocManager()->GetDocuments();
722   wxNode* pNode = rListDocs.GetFirst();
723   while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
724     wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
725     wxString strFilename = pDoc->GetFilename();
726     if (iPos < 10) {
727       strFilename += _T("\tCtrl-");
728       strFilename += static_cast<char>('0' + iPos);
729     }
730     static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
731     m_apWindowMenuData[iPos] = pDoc;
732     m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
733     iPos++;
734     pNode = pNode->GetNext();
735   }
736   for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
737     m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
738     static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (_T("[EMPTY]"));
739     m_apWindowMenuData[i] = NULL;
740   }
741 #endif
742 }
743
744
745 void
746 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
747 {
748   if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
749     wxString strFilename = pDoc->GetFilename();
750     const wxView* pView = pDoc->GetFirstView();
751     if (pView) {
752       wxWindow* pWindow = pView->GetFrame();
753       pWindow->SetFocus();
754       pWindow->Raise();
755     }
756   }
757 }
758
759 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
760 { DoWindowMenu (0, event); }
761
762 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
763 { DoWindowMenu (1, event); }
764
765 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
766 { DoWindowMenu (2, event); }
767
768 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
769 { DoWindowMenu (3, event); }
770
771 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
772 { DoWindowMenu (4, event); }
773
774 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
775 { DoWindowMenu (5, event); }
776
777 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
778 { DoWindowMenu (6, event); }
779
780 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
781 { DoWindowMenu (7, event); }
782
783 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
784 { DoWindowMenu (8, event); }
785
786 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
787 { DoWindowMenu (9, event); }
788
789 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
790 { DoWindowMenu (10, event); }
791
792 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
793 { DoWindowMenu (11, event); }
794
795 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
796 { DoWindowMenu (12, event); }
797
798 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
799 { DoWindowMenu (13, event); }
800
801 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
802 { DoWindowMenu (14, event); }
803
804 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
805 { DoWindowMenu (15, event); }
806
807 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
808 { DoWindowMenu (16, event); }
809
810 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
811 { DoWindowMenu (17, event); }
812
813 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
814 { DoWindowMenu (18, event); }
815
816 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
817 { DoWindowMenu (19, event); }
818
819
820 class BitmapControl : public wxPanel
821 {
822 private:
823   DECLARE_DYNAMIC_CLASS (BitmapControl)
824     DECLARE_EVENT_TABLE ()
825     wxBitmap* m_pBitmap;
826
827 public:
828   BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
829     const wxPoint& pos = wxDefaultPosition,
830     const wxSize& size = wxDefaultSize,
831     long style = wxSTATIC_BORDER,
832     const wxValidator& validator = wxDefaultValidator,
833                  const wxString& name = _T("BitmapCtrl"));
834
835
836   virtual ~BitmapControl();
837
838   virtual wxSize GetBestSize() const;
839
840   wxBitmap* getBitmap()
841   { return m_pBitmap; }
842
843   void OnPaint(wxPaintEvent& event);
844 };
845
846
847 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
848 EVT_PAINT(BitmapControl::OnPaint)
849 END_EVENT_TABLE()
850
851 IMPLEMENT_CLASS(BitmapControl, wxPanel)
852
853
854 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
855                               long style, const wxValidator& validator, const wxString& name)
856                               : m_pBitmap(pBitmap)
857 {
858   Create(parent, id, pos, size, style, name);
859
860   SetSize (GetBestSize());
861 }
862
863 wxSize
864 BitmapControl::GetBestSize () const
865 {
866   if (m_pBitmap)
867     return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
868   else
869     return wxSize(0,0);
870 }
871
872 BitmapControl::~BitmapControl()
873 {}
874
875 void
876 BitmapControl::OnPaint (wxPaintEvent& event)
877 {
878   wxPaintDC dc(this);
879   if (m_pBitmap)
880     dc.DrawBitmap (*m_pBitmap, 0, 0);
881 }
882
883
884 class BitmapDialog : public wxDialog {
885 private:
886   BitmapControl* m_pBitmapCtrl;
887
888 public:
889   BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
890   virtual ~BitmapDialog();
891 };
892
893 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
894   : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle,*wxConvCurrent), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
895 {
896   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
897
898   pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
899
900   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
901   wxButton* pButtonOk = new wxButton (this, wxID_OK, _T("Ok"));
902   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
903
904   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
905
906   SetAutoLayout (true);
907   SetSizer (pTopSizer);
908   pTopSizer->Fit (this);
909   pTopSizer->SetSizeHints (this);
910 }
911
912 BitmapDialog::~BitmapDialog()
913 {}
914
915
916 void
917 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
918 {
919   DialogPreferences dlg (this, _T("CTSim Preferences"), theApp->getAdvancedOptions(),
920     theApp->getAskDeleteNewDocs(), theApp->getVerboseLogging(), theApp->getStartupTips(),
921     theApp->getUseBackgroundTasks());
922   if (dlg.ShowModal() == wxID_OK) {
923     theApp->setAdvancedOptions (dlg.getAdvancedOptions());
924     theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
925     theApp->setVerboseLogging (dlg.getVerboseLogging());
926     theApp->setStartupTips (dlg.getStartupTips());
927     theApp->setUseBackgroundTasks (dlg.getUseBackgroundTasks());
928   }
929 }
930
931 void
932 MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
933 {
934   DialogImportParameters dialogImport (this, m_iDefaultImportFormat);
935   if (dialogImport.ShowModal() != wxID_OK)
936     return;
937
938   wxString strFormatName (dialogImport.getFormatName (), *wxConvCurrent);
939   m_iDefaultImportFormat = ImageFile::convertImportFormatNameToID (strFormatName.mb_str(wxConvUTF8));
940
941   wxString strExt;
942   wxString strWildcard;
943   if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM) {
944     strExt = _T(".ppm");
945     strWildcard = _T("PPM Files (*.ppm)|*.ppm|PGM Files (*.pgm)|*.pgm");
946   }
947 #ifdef HAVE_PNG
948   else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
949     strExt = _T(".png");
950     strWildcard = _T("PNG Files (*.png)|*.png");
951   }
952 #endif
953 #ifdef HAVE_CTN_DICOM
954   else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
955     strExt = _T("*.*");
956     strWildcard = _T("Dicom Files (*.*)|*.*");
957   }
958 #endif
959   else {
960     return;
961   }
962
963   wxString strFilename = wxFileSelector (wxString(wxConvUTF8.cMB2WX("Import Filename")), wxString(wxConvUTF8.cMB2WX("")),
964                                          wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxOPEN);
965
966   if (! strFilename.IsEmpty()) {
967     if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
968       ImageFile* pIF = new ImageFile;
969       if (pIF->importImage (strFormatName.mb_str(wxConvUTF8), strFilename.mb_str(wxConvUTF8))) {
970         ImageFileDocument* pIFDoc = theApp->newImageDoc();
971         pIFDoc->setImageFile(pIF);
972         pIFDoc->getView()->getFrame()->Show(true);
973         std::ostringstream os;
974         os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
975         pIF->labelAdd (os.str().c_str());
976         if (theApp->getAskDeleteNewDocs())
977           pIFDoc->Modify (true);
978         pIFDoc->UpdateAllViews();
979         pIFDoc->GetFirstView()->OnUpdate (NULL, NULL);
980         pIFDoc->getView()->getFrame()->Show(true);
981       } else
982         delete pIF;
983     }
984 #ifdef HAVE_CTN_DICOM
985     else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
986       DicomImporter dicomImport (strFilename.mb_str(wxConvUTF8));
987       if (dicomImport.fail()) {
988         ::wxMessageBox (wxConvUTF8.cMB2WX(dicomImport.failMessage().c_str()), _T("Import Error"));
989       } else if (dicomImport.testImage()) {
990         ImageFileDocument* pIFDoc = theApp->newImageDoc();
991         ImageFile* pIF = dicomImport.getImageFile();
992         pIFDoc->setImageFile (pIF);
993         std::ostringstream os;
994         os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
995         pIF->labelAdd (os.str().c_str());
996         if (theApp->getAskDeleteNewDocs())
997           pIFDoc->Modify (true);
998         pIFDoc->UpdateAllViews();
999         pIFDoc->getView()->setInitialClientSize();
1000         pIFDoc->Activate();
1001       } else if (dicomImport.testProjections()) {
1002         ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
1003         Projections* pProj = dicomImport.getProjections();
1004         pProjDoc->setProjections (pProj);
1005         pProjDoc->getView()->getFrame()->Show(true);
1006         std::ostringstream os;
1007         os << "Import projection file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
1008         pProj->setRemark (os.str().c_str());
1009         if (theApp->getAskDeleteNewDocs())
1010           pProjDoc->Modify (true);
1011         pProjDoc->UpdateAllViews();
1012         pProjDoc->getView()->setInitialClientSize();
1013         pProjDoc->Activate();
1014       } else
1015         ::wxMessageBox (_T("Unrecognized DICOM file contents"), _T("Import Error"));
1016     }
1017 #endif
1018     else
1019       sys_error (ERR_WARNING, "Unknown import format type");
1020   }
1021 }
1022
1023 #include "./splash.xpm"
1024 void
1025 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
1026 {
1027   wxString strOSDesc = ::wxGetOsDescription();
1028   *theApp->getLog() << _T("Operating System: ") << strOSDesc;
1029   *theApp->getLog() << _T(", wxWindows: ") << wxVERSION_STRING;
1030 #ifdef _TIMESTAMP__
1031   *theApp->getLog() << _T(", Build Date: ") << wxConvUTF8.cMB2WX(_TIMESTAMP__);
1032 #endif
1033 #if defined(DEBUG)
1034   *theApp->getLog() << _T(", Debug version");
1035 #else
1036   *theApp->getLog() << _T(", Release version");
1037 #endif
1038 #ifdef VERSION
1039   *theApp->getLog() << _T(" ") <<  wxConvUTF8.cMB2WX(VERSION);
1040 #elif defined(CTSIMVERSION)
1041   *theApp->getLog() << _T(" ") <<  _T(CTSIMVERSION);
1042 #endif
1043     *theApp->getLog() << _T("\n");
1044
1045   wxBitmap bmp (splash);
1046   if (bmp.Ok()) {
1047     BitmapDialog dlg (&bmp, "About CTSim");
1048     dlg.ShowModal();
1049   } else {
1050     wxString msg = _T("CTSim\nThe Open Source Computed Tomography Simulator\n");
1051 #ifdef VERSION
1052     msg << _T("Version: ") <<  wxConvUTF8.cMB2WX(VERSION) << _T("\n\n");
1053 #elif defined(CTSIMVERSION)
1054     msg << _T("Version: ") <<  wxConvUTF8.cMB2WX(CTSIMVERSION) << _T("\n\n");
1055 #endif
1056     msg += _T("Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]");
1057
1058     wxMessageBox(msg, _T("About CTSim"), wxOK | wxICON_INFORMATION, this);
1059     *theApp->getLog() << msg << wxConvUTF8.cMB2WX("\n");
1060   }
1061 }
1062
1063
1064 // Create new documents
1065
1066 ProjectionFileDocument*
1067 CTSimApp::newProjectionDoc()
1068 {
1069   wxString fname;
1070   m_docManager->MakeDefaultName(fname);
1071   fname += _T(".pj");
1072   ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (fname));
1073   if (newDoc) {
1074     newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
1075     newDoc->SetDocumentTemplate (m_pDocTemplProjection);
1076     newDoc->OnNewDocument();
1077     newDoc->SetFilename(fname);
1078   }
1079
1080   return newDoc;
1081 }
1082
1083 ImageFileDocument*
1084 CTSimApp::newImageDoc()
1085 {
1086   wxString fname;
1087   m_docManager->MakeDefaultName(fname);
1088   fname += _T(".if");
1089   ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (fname));
1090   if (newDoc) {
1091     newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
1092     newDoc->SetDocumentTemplate (m_pDocTemplImage);
1093     newDoc->OnNewDocument();
1094     newDoc->SetFilename(fname);
1095   }
1096
1097   return newDoc;
1098 }
1099
1100 PlotFileDocument*
1101 CTSimApp::newPlotDoc()
1102 {
1103   wxString fname;
1104   m_docManager->MakeDefaultName(fname);
1105   fname += _T(".plt");
1106   PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (fname));
1107   if (newDoc) {
1108     newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
1109     newDoc->SetDocumentTemplate (m_pDocTemplPlot);
1110     newDoc->OnNewDocument();
1111     newDoc->SetFilename(fname);
1112   }
1113
1114   return newDoc;
1115 }
1116
1117
1118 TextFileDocument*
1119 CTSimApp::newTextDoc()
1120 {
1121   wxString fname;
1122   m_docManager->MakeDefaultName(fname);
1123   fname += _T(".txt");
1124
1125   TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (fname));
1126   if (newDoc) {
1127     newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
1128     newDoc->SetDocumentTemplate (m_pDocTemplText);
1129     newDoc->OnNewDocument();
1130     newDoc->SetFilename (fname);
1131   }
1132
1133   return newDoc;
1134 }
1135
1136
1137 PhantomFileDocument*
1138 CTSimApp::newPhantomDoc()
1139 {
1140   wxString fname;
1141   m_docManager->MakeDefaultName(fname);
1142   fname += _T(".phm");
1143   PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (fname));
1144   if (newDoc) {
1145     newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
1146     newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
1147     newDoc->OnNewDocument();
1148     newDoc->SetFilename(fname);
1149   }
1150
1151   return newDoc;
1152 }
1153
1154
1155 #if wxUSE_GLCANVAS
1156 Graph3dFileDocument*
1157 CTSimApp::newGraph3dDoc()
1158 {
1159   wxString fname;
1160   m_docManager->MakeDefaultName(fname);
1161   fname += _T(".g3d");
1162   Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (fname));
1163   if (newDoc) {
1164     newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
1165     newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
1166     newDoc->OnNewDocument();
1167     newDoc->SetFilename(fname);
1168   }
1169
1170   return newDoc;
1171 }
1172
1173 #endif