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