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