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