1 /*****************************************************************************
5 ** Purpose: Top-level routines of CTSim program
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: July 2000
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: ctsim.cpp,v 1.75 2001/02/11 21:57:08 kevin Exp $
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.
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.
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 ******************************************************************************/
29 #define strdup _strdup
32 // For compilers that support precompilation, includes "wx/wx.h".
33 #include "wx/wxprec.h"
44 #include "wx/filesys.h"
45 #include "wx/fs_zip.h"
46 #include "wx/msw/helpchm.h"
48 #if !wxUSE_DOC_VIEW_ARCHITECTURE
49 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
55 #include "ctsim-map.h"
60 #if defined(HAVE_CONFIG_H)
64 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
74 static const char* rcsindent = "$Id: ctsim.cpp,v 1.75 2001/02/11 21:57:08 kevin Exp $";
76 struct option CTSimApp::ctsimOptions[] =
78 {"help", 0, 0, O_HELP},
79 {"version", 0, 0, O_VERSION},
83 IMPLEMENT_APP(CTSimApp)
86 : m_docManager(NULL), m_pFrame(NULL), m_pLog(0), m_pLogDoc(0), m_pConfig(0),
87 m_bAdvancedOptions(false), m_bSetModifyNewDocs(true)
92 #ifdef HAVE_SYS_TIME_H
96 #ifdef HAVE_SYS_RESOURCE_H
97 #include <sys/resource.h>
103 #ifdef HAVE_SETPRIORITY
104 setpriority (PRIO_PROCESS, 0, 15); // set to low scheduling priority
109 g_bRunningWXWindows = true;
112 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
118 std::cout << rcsindent << std::endl;
120 std::cout << "Version: CTSIMVERSION" << std::endl;
121 #elif defined(VERSION)
122 std::cout << "Version: VERSION" << std::endl;
135 m_docManager = new wxDocManager (wxDEFAULT_DOCMAN_FLAGS, true);
137 m_pDocTemplImage = new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile", "ImageView", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
138 m_pDocTemplProjection = new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile", "ProjectionView", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
139 m_pDocTemplPhantom = new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "PhantomFile", "PhantomView", CLASSINFO(PhantomFileDocument), CLASSINFO(PhantomFileView));
140 m_pDocTemplPlot = new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "PlotFile", "PlotView", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
141 m_pDocTemplText = new wxDocTemplate (m_docManager, "TextFile", "*.txt", "", "txt", "TextFile", "TextView", CLASSINFO(TextFileDocument), CLASSINFO(TextFileView), wxTEMPLATE_INVISIBLE);
143 m_pDocTemplGraph3d = new wxDocTemplate (m_docManager, "Graph3dFile", "*.g3d", "", "g3d", "Graph3dFile", "Graph3dView", CLASSINFO(Graph3dFileDocument), CLASSINFO(Graph3dFileView), wxTEMPLATE_INVISIBLE);
147 wxImage::AddHandler(new wxGIFHandler); // Required for images in the online documentation
150 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
151 wxFileSystem::AddHandler(new wxZipFSHandler); // Required for advanced HTML help
154 // Create the main frame window
155 int xDisplay, yDisplay;
156 ::wxDisplaySize (&xDisplay, &yDisplay);
157 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0),
158 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .755)), wxDEFAULT_FRAME_STYLE);
160 setIconForFrame (m_pFrame);
161 m_pFrame->Centre(wxBOTH);
162 m_pFrame->Show(true);
163 SetTopWindow (m_pFrame);
166 m_docManager->FileHistoryLoad(*m_pConfig);
169 m_pLogDoc = newTextDoc();
171 m_pLog = m_pLogDoc->getTextCtrl();
172 m_pLogDoc->SetDocumentName("Log.txt");
173 m_pLogDoc->SetFilename("Log.txt");
174 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
176 m_pFrame->GetClientSize(&xSize, &ySize);
177 int yLogSize = ySize / 4;
178 m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
179 m_pLogDoc->getView()->getFrame()->Show (true);
182 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
184 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
187 if (! m_pConfig->Read("HelpDir", &helpDir))
188 helpDir = ::wxGetCwd();
190 if (! m_pFrame->getWinHelpController().Initialize(helpDir + "/ctsim"))
191 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
193 if (! m_pFrame->getHtmlHelpController().Initialize(helpDir + "/ctsim") &&
194 ! m_pFrame->getHtmlHelpController().Initialize("/usr/local/man/ctsim"))
195 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
197 if (::wxDirExists ("/tmp"))
198 m_pFrame->getHtmlHelpController().SetTempDir(_T("/tmp"));
199 m_pFrame->getHtmlHelpController().UseConfig (m_pConfig);
203 for (int i = optind + 1; i <= argc; i++) {
204 wxString filename = argv [i - 1];
205 m_docManager->CreateDocument (filename, wxDOC_SILENT);
212 #include "./ctsim.xpm"
214 CTSimApp::setIconForFrame(wxFrame* pFrame)
216 wxIcon iconApp (ctsim16_xpm);
219 pFrame->SetIcon (iconApp);
223 CTSimApp::usage(const char* program)
225 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
226 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
228 std::cout << " --version Display version\n";
229 std::cout << " --help Display this help message\n";
244 CTSimApp::openConfig()
247 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", "", "", wxCONFIG_USE_LOCAL_FILE);
249 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", ".ctsim", "", wxCONFIG_USE_LOCAL_FILE);
252 wxConfigBase::Set(m_pConfig);
253 m_pConfig->Read ("AdvancedOptions", &m_bAdvancedOptions);
254 m_pConfig->Read ("SetModifyNewDocs", &m_bSetModifyNewDocs);
258 CTSimApp::closeConfig()
260 m_pConfig->Write ("AdvancedOptions", m_bAdvancedOptions);
261 m_pConfig->Write ("SetModifyNewDocs", m_bSetModifyNewDocs);
267 CTSimApp::getUntitledFilename()
269 static int untitledNumber = 1;
271 wxString filename ("Untitled");
272 filename << untitledNumber++;
278 // Top-level window for CTSim
281 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
283 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
285 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
287 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
290 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
291 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
292 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
293 EVT_MENU(MAINMENU_HELP_TOPICS, MainFrame::OnHelpTopics)
294 EVT_SIZE(MainFrame::OnSize)
296 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
297 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
299 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
300 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
301 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
302 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
303 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
304 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
305 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
306 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
307 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
308 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
309 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
310 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
311 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
312 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
313 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
314 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
315 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
316 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
317 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
318 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
319 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
320 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
321 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
322 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
323 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
329 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
330 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
332 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
333 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
336 m_bShuttingDown = false;
339 wxMenu *file_menu = new wxMenu;
341 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
342 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
343 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
345 file_menu->AppendSeparator();
346 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Pr&eferences...");
347 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
349 // history of files visited
350 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
351 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
354 m_pWindowMenu = new wxMenu;
355 m_pWindowMenu->UpdateUI (this);
358 wxMenu* help_menu = new wxMenu;
359 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
360 help_menu->Append (MAINMENU_HELP_TOPICS, "&Topics\tCtrl-T");
361 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
362 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
364 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
366 wxMenuBar* menu_bar = new wxMenuBar;
368 menu_bar->Append(file_menu, "&File");
370 menu_bar->Append(m_pWindowMenu, "&Window");
372 menu_bar->Append(help_menu, "&Help");
374 SetMenuBar(menu_bar);
378 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
379 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
380 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
381 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
385 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
386 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
387 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
388 m_iDefaultFilterXSize = 256;
389 m_iDefaultFilterYSize = 256;
390 m_dDefaultFilterParam = 1.;
391 m_dDefaultFilterBandwidth = 1.;
392 m_dDefaultFilterInputScale = 1.;
393 m_dDefaultFilterOutputScale = 1.;
395 wxAcceleratorEntry accelEntries[15];
396 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
397 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
398 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
399 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
401 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
402 for (i = 0; i < 10; i++)
403 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
404 wxAcceleratorTable accelTable (15, accelEntries);
406 wxAcceleratorTable accelTable (4, accelEntries);
409 SetAcceleratorTable (accelTable);
412 MainFrame::~MainFrame()
414 m_bShuttingDown = true; // Currently used so that Log Window will close
416 // delete all non-modified documents
417 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
418 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
419 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
420 if (pDoc && ! pDoc->IsModified()) {
421 theApp->getDocManager()->RemoveDocument(pDoc);
427 if (theApp->getConfig())
428 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
430 delete theApp->getDocManager();
435 MainFrame::OnSize (wxSizeEvent& event)
438 if (theApp->getLogDoc()) {
440 GetClientSize(&xSize, &ySize);
441 int yLogSize = ySize / 4;
442 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
443 theApp->getLogDoc()->getView()->getFrame()->Show (true);
448 wxDocMDIParentFrame::OnSize (event);
450 wxDocParentFrame::OnSize (event);
455 MainFrame::OnCreatePhantom(wxCommandEvent& event)
457 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
458 int dialogReturn = dialogPhantom.ShowModal();
459 if (dialogReturn == wxID_OK) {
460 wxString selection (dialogPhantom.getPhantom());
461 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
462 wxString filename = selection + ".phm";
463 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
464 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
470 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
472 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
473 int dialogReturn = dialogFilter.ShowModal();
474 if (dialogReturn == wxID_OK) {
475 wxString strFilter (dialogFilter.getFilterName());
476 wxString strDomain (dialogFilter.getDomainName());
477 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
478 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
479 m_iDefaultFilterXSize = dialogFilter.getXSize();
480 m_iDefaultFilterYSize = dialogFilter.getYSize();
481 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
482 m_dDefaultFilterParam= dialogFilter.getFilterParam();
483 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
484 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
485 std::ostringstream os;
486 os << "Generate Filter=" << strFilter.c_str()
487 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
488 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
489 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
490 *theApp->getLog() << os.str().c_str() << "\n";
491 wxString filename = "untitled.if";
492 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
493 pFilterDoc->setBadFileOpen();
495 sys_error (ERR_SEVERE, "Unable to create filter image");
498 ImageFile& rIF = pFilterDoc->getImageFile();
499 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
500 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
501 rIF.labelAdd (os.str().c_str());
502 pFilterDoc->Modify (true);
503 pFilterDoc->UpdateAllViews();
504 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
505 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
506 pFilterDoc->getView()->getFrame()->Show(true);
511 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
513 const ImageFile& rIF = pIFDoc->getImageFile();
514 unsigned int nx = rIF.nx();
515 unsigned int ny = rIF.ny();
516 wxList& rListDocs = m_docManager->GetDocuments();
517 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
518 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
519 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
520 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
521 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
522 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
523 vecIF.push_back (pIFCompareDoc);
529 MainFrame::OnHelpTopics (wxCommandEvent& event)
531 showHelp (event.GetId());
535 MainFrame::OnHelpContents (wxCommandEvent& event)
537 showHelp (event.GetId());
540 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
542 MainFrame::OnHelpSecondary (wxCommandEvent& event)
544 m_htmlHelp.DisplayContents();
549 MainFrame::showHelp (int commandID)
553 case MAINMENU_HELP_CONTENTS:
555 m_winHelp.DisplayContents ();
557 m_htmlHelp.DisplayContents ();
561 case MAINMENU_HELP_TOPICS:
563 m_winHelp.DisplaySection (introduction);
565 m_htmlHelp.DisplayIndex();
570 *theApp->getLog() << "Unknown help command # " << commandID << "\n";
576 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
582 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
586 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
587 wxNode* pNode = rListDocs.GetFirst();
588 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
589 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
590 wxString strFilename = pDoc->GetFilename();
592 strFilename += "\tCtrl-";
593 strFilename += static_cast<char>('0' + iPos);
595 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
596 m_apWindowMenuData[iPos] = pDoc;
597 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
599 pNode = pNode->GetNext();
601 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
602 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
603 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
604 m_apWindowMenuData[i] = NULL;
609 #ifdef CTSIM_CUSTOM_MRU
611 MainFrame::OnMRUFile (wxCommandEvent& event)
613 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
615 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
620 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
622 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
623 wxString strFilename = pDoc->GetFilename();
624 const wxView* pView = pDoc->GetFirstView();
626 wxFrame* pFrame = pView->GetFrame();
633 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
634 { DoWindowMenu (0, event); }
636 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
637 { DoWindowMenu (1, event); }
639 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
640 { DoWindowMenu (2, event); }
642 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
643 { DoWindowMenu (3, event); }
645 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
646 { DoWindowMenu (4, event); }
648 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
649 { DoWindowMenu (5, event); }
651 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
652 { DoWindowMenu (6, event); }
654 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
655 { DoWindowMenu (7, event); }
657 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
658 { DoWindowMenu (8, event); }
660 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
661 { DoWindowMenu (9, event); }
663 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
664 { DoWindowMenu (10, event); }
666 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
667 { DoWindowMenu (11, event); }
669 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
670 { DoWindowMenu (12, event); }
672 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
673 { DoWindowMenu (13, event); }
675 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
676 { DoWindowMenu (14, event); }
678 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
679 { DoWindowMenu (15, event); }
681 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
682 { DoWindowMenu (16, event); }
684 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
685 { DoWindowMenu (17, event); }
687 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
688 { DoWindowMenu (18, event); }
690 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
691 { DoWindowMenu (19, event); }
694 class BitmapControl : public wxPanel
697 DECLARE_DYNAMIC_CLASS (BitmapControl)
698 DECLARE_EVENT_TABLE ()
702 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
703 const wxPoint& pos = wxDefaultPosition,
704 const wxSize& size = wxDefaultSize,
705 long style = wxSTATIC_BORDER,
706 const wxValidator& validator = wxDefaultValidator,
707 const wxString& name = "BitmapCtrl");
710 virtual ~BitmapControl();
712 virtual wxSize GetBestSize() const;
714 wxBitmap* getBitmap()
715 { return m_pBitmap; }
717 void OnPaint(wxPaintEvent& event);
721 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
722 EVT_PAINT(BitmapControl::OnPaint)
725 IMPLEMENT_CLASS(BitmapControl, wxPanel)
728 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
729 long style, const wxValidator& validator, const wxString& name)
732 Create(parent, id, pos, size, style, name);
734 SetSize (GetBestSize());
738 BitmapControl::GetBestSize () const
741 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
746 BitmapControl::~BitmapControl()
750 BitmapControl::OnPaint (wxPaintEvent& event)
754 dc.DrawBitmap (*m_pBitmap, 0, 0);
758 class BitmapDialog : public wxDialog {
760 BitmapControl* m_pBitmapCtrl;
763 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
764 virtual ~BitmapDialog();
767 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
768 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
770 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
772 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
774 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
775 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
776 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
778 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
780 SetAutoLayout (true);
781 SetSizer (pTopSizer);
782 pTopSizer->Fit (this);
783 pTopSizer->SetSizeHints (this);
786 BitmapDialog::~BitmapDialog()
791 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
793 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
794 theApp->getAskDeleteNewDocs());
795 if (dlg.ShowModal() == wxID_OK) {
796 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
797 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
802 #include "./splash.xpm"
804 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
806 wxBitmap bmp (splash);
808 BitmapDialog dlg (&bmp, "About CTSim");
811 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
816 #elif defined(VERSION)
817 msg << "Version: " << VERSION << "\n\n";
819 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
821 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
826 ProjectionFileDocument*
827 CTSimApp::newProjectionDoc()
829 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
831 ProjectionFileView* pView = newDoc->getView();
833 wxFrame* pFrame = pView->getFrame();
835 pFrame->SetSize (0,0);
836 pFrame->Show (false);
839 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
840 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
841 newDoc->OnNewDocument();
848 CTSimApp::newImageDoc()
850 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
852 ImageFileView* pView = newDoc->getView();
854 wxFrame* pFrame = pView->getFrame();
856 pFrame->SetSize (0,0);
857 pFrame->Show (false);
860 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
861 newDoc->SetDocumentTemplate (m_pDocTemplImage);
862 newDoc->OnNewDocument();
869 CTSimApp::newPlotDoc()
871 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
873 PlotFileView* pView = newDoc->getView();
875 wxFrame* pFrame = pView->getFrame();
878 m_pFrame->GetClientSize (&size.x, &size.y);
879 pFrame->SetSize (size.x / 2, size.y / 2);
880 pFrame->Show (false);
883 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
884 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
885 newDoc->OnNewDocument();
893 CTSimApp::newTextDoc()
895 wxString strFilename (getUntitledFilename());
896 strFilename += ".txt";
898 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
900 TextFileView* pView = newDoc->getView();
902 wxFrame* pFrame = pView->getFrame();
905 m_pFrame->GetClientSize (&size.x, &size.y);;
906 pFrame->SetSize (size.x / 2, size.y / 2);
907 pFrame->Show (false);
910 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
911 newDoc->SetDocumentTemplate (m_pDocTemplText);
912 newDoc->OnNewDocument();
920 CTSimApp::newPhantomDoc()
922 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
924 PhantomFileView* pView = newDoc->getView();
926 wxFrame* pFrame = pView->getFrame();
928 pFrame->SetSize (0,0);
930 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
931 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
932 newDoc->OnNewDocument();
941 CTSimApp::newGraph3dDoc()
943 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
945 Graph3dFileView* pView = newDoc->getView();
947 wxFrame* pFrame = pView->getFrame();
949 pFrame->SetSize (0,0);
951 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
952 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
953 newDoc->OnNewDocument();