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