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