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.77 2001/02/14 18:39:47 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"
47 #include "wx/msw/helpchm.h"
50 #if !wxUSE_DOC_VIEW_ARCHITECTURE
51 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
57 #include "ctsim-map.h"
62 #if defined(HAVE_CONFIG_H)
66 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
76 static const char* rcsindent = "$Id: ctsim.cpp,v 1.77 2001/02/14 18:39:47 kevin Exp $";
78 struct option CTSimApp::ctsimOptions[] =
80 {"help", 0, 0, O_HELP},
81 {"version", 0, 0, O_VERSION},
85 IMPLEMENT_APP(CTSimApp)
88 : m_docManager(NULL), m_pFrame(NULL), m_pLog(0), m_pLogDoc(0), m_pConfig(0),
89 m_bAdvancedOptions(false), m_bSetModifyNewDocs(true)
94 #ifdef HAVE_SYS_TIME_H
98 #ifdef HAVE_SYS_RESOURCE_H
99 #include <sys/resource.h>
105 #ifdef HAVE_SETPRIORITY
106 setpriority (PRIO_PROCESS, 0, 15); // set to low scheduling priority
111 g_bRunningWXWindows = true;
114 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
120 std::cout << rcsindent << std::endl;
122 std::cout << "Version: CTSIMVERSION" << std::endl;
123 #elif defined(VERSION)
124 std::cout << "Version: VERSION" << std::endl;
137 m_docManager = new wxDocManager (wxDEFAULT_DOCMAN_FLAGS, true);
139 m_pDocTemplImage = new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile", "ImageView", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
140 m_pDocTemplProjection = new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile", "ProjectionView", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
141 m_pDocTemplPhantom = new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "PhantomFile", "PhantomView", CLASSINFO(PhantomFileDocument), CLASSINFO(PhantomFileView));
142 m_pDocTemplPlot = new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "PlotFile", "PlotView", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
143 m_pDocTemplText = new wxDocTemplate (m_docManager, "TextFile", "*.txt", "", "txt", "TextFile", "TextView", CLASSINFO(TextFileDocument), CLASSINFO(TextFileView), wxTEMPLATE_INVISIBLE);
145 m_pDocTemplGraph3d = new wxDocTemplate (m_docManager, "Graph3dFile", "*.g3d", "", "g3d", "Graph3dFile", "Graph3dView", CLASSINFO(Graph3dFileDocument), CLASSINFO(Graph3dFileView), wxTEMPLATE_INVISIBLE);
149 wxImage::AddHandler(new wxGIFHandler); // Required for images in the online documentation
152 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
153 wxFileSystem::AddHandler(new wxZipFSHandler); // Required for advanced HTML help
156 // Create the main frame window
157 int xDisplay, yDisplay;
158 ::wxDisplaySize (&xDisplay, &yDisplay);
159 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0),
160 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .755)), wxDEFAULT_FRAME_STYLE);
162 setIconForFrame (m_pFrame);
163 m_pFrame->Centre(wxBOTH);
164 m_pFrame->Show(true);
165 SetTopWindow (m_pFrame);
168 m_docManager->FileHistoryLoad(*m_pConfig);
171 m_pLogDoc = newTextDoc();
173 m_pLog = m_pLogDoc->getTextCtrl();
174 m_pLogDoc->SetDocumentName("Log.txt");
175 m_pLogDoc->SetFilename("Log.txt");
176 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
178 m_pFrame->GetClientSize(&xSize, &ySize);
179 int yLogSize = ySize / 4;
180 m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
181 m_pLogDoc->getView()->getFrame()->Show (true);
184 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
186 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
189 if (! m_pConfig->Read("HelpDir", &helpDir))
190 helpDir = ::wxGetCwd();
192 if (! m_pFrame->getWinHelpController().Initialize(helpDir + "/ctsim"))
193 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
195 if (! m_pFrame->getHtmlHelpController().Initialize(helpDir + "/ctsim") &&
196 ! m_pFrame->getHtmlHelpController().Initialize("/usr/local/man/ctsim"))
197 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
199 if (::wxDirExists ("/tmp"))
200 m_pFrame->getHtmlHelpController().SetTempDir(_T("/tmp"));
201 m_pFrame->getHtmlHelpController().UseConfig (m_pConfig);
205 for (int i = optind + 1; i <= argc; i++) {
206 wxString filename = argv [i - 1];
207 m_docManager->CreateDocument (filename, wxDOC_SILENT);
214 #include "./ctsim.xpm"
216 CTSimApp::setIconForFrame(wxFrame* pFrame)
218 wxIcon iconApp (ctsim16_xpm);
221 pFrame->SetIcon (iconApp);
225 CTSimApp::usage(const char* program)
227 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
228 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
230 std::cout << " --version Display version\n";
231 std::cout << " --help Display this help message\n";
246 CTSimApp::openConfig()
249 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", "", "", wxCONFIG_USE_LOCAL_FILE);
251 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", ".ctsim", "", wxCONFIG_USE_LOCAL_FILE);
254 wxConfigBase::Set(m_pConfig);
255 m_pConfig->Read ("AdvancedOptions", &m_bAdvancedOptions);
256 m_pConfig->Read ("SetModifyNewDocs", &m_bSetModifyNewDocs);
260 CTSimApp::closeConfig()
262 m_pConfig->Write ("AdvancedOptions", m_bAdvancedOptions);
263 m_pConfig->Write ("SetModifyNewDocs", m_bSetModifyNewDocs);
269 CTSimApp::getUntitledFilename()
271 static int untitledNumber = 1;
273 wxString filename ("Untitled");
274 filename << untitledNumber++;
280 // Top-level window for CTSim
283 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
285 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
287 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
289 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
292 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
293 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
294 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
295 EVT_MENU(MAINMENU_HELP_TOPICS, MainFrame::OnHelpTopics)
296 EVT_SIZE(MainFrame::OnSize)
298 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
299 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
301 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
302 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
303 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
304 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
305 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
306 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
307 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
308 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
309 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
310 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
311 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
312 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
313 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
314 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
315 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
316 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
317 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
318 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
319 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
320 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
321 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
322 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
323 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
324 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
325 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
331 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
332 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
334 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
335 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
338 m_bShuttingDown = false;
341 wxMenu *file_menu = new wxMenu;
343 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
344 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
345 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
347 file_menu->AppendSeparator();
348 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
349 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
351 // history of files visited
352 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
353 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
356 m_pWindowMenu = new wxMenu;
357 m_pWindowMenu->UpdateUI (this);
360 wxMenu* help_menu = new wxMenu;
361 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
362 help_menu->Append (MAINMENU_HELP_TOPICS, "&Topics\tCtrl-T");
363 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
364 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
366 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
368 wxMenuBar* menu_bar = new wxMenuBar;
370 menu_bar->Append(file_menu, "&File");
372 menu_bar->Append(m_pWindowMenu, "&Window");
374 menu_bar->Append(help_menu, "&Help");
376 SetMenuBar(menu_bar);
380 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
381 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
382 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
383 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
387 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
388 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
389 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
390 m_iDefaultFilterXSize = 256;
391 m_iDefaultFilterYSize = 256;
392 m_dDefaultFilterParam = 1.;
393 m_dDefaultFilterBandwidth = 1.;
394 m_dDefaultFilterInputScale = 1.;
395 m_dDefaultFilterOutputScale = 1.;
397 wxAcceleratorEntry accelEntries[15];
398 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
399 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
400 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
401 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
403 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
404 for (i = 0; i < 10; i++)
405 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
406 wxAcceleratorTable accelTable (15, accelEntries);
408 wxAcceleratorTable accelTable (4, accelEntries);
411 SetAcceleratorTable (accelTable);
414 MainFrame::~MainFrame()
416 m_bShuttingDown = true; // Currently used so that Log Window will close
418 // delete all non-modified documents
419 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
420 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
421 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
422 if (pDoc && ! pDoc->IsModified()) {
423 theApp->getDocManager()->RemoveDocument(pDoc);
429 if (theApp->getConfig())
430 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
432 delete theApp->getDocManager();
437 MainFrame::OnSize (wxSizeEvent& event)
440 if (theApp->getLogDoc()) {
442 GetClientSize(&xSize, &ySize);
443 int yLogSize = ySize / 4;
444 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
445 theApp->getLogDoc()->getView()->getFrame()->Show (true);
450 wxDocMDIParentFrame::OnSize (event);
452 wxDocParentFrame::OnSize (event);
457 MainFrame::OnCreatePhantom(wxCommandEvent& event)
459 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
460 int dialogReturn = dialogPhantom.ShowModal();
461 if (dialogReturn == wxID_OK) {
462 wxString selection (dialogPhantom.getPhantom());
463 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
464 wxString filename = selection + ".phm";
465 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
466 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
472 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
474 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
475 int dialogReturn = dialogFilter.ShowModal();
476 if (dialogReturn == wxID_OK) {
477 wxString strFilter (dialogFilter.getFilterName());
478 wxString strDomain (dialogFilter.getDomainName());
479 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
480 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
481 m_iDefaultFilterXSize = dialogFilter.getXSize();
482 m_iDefaultFilterYSize = dialogFilter.getYSize();
483 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
484 m_dDefaultFilterParam= dialogFilter.getFilterParam();
485 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
486 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
487 std::ostringstream os;
488 os << "Generate Filter=" << strFilter.c_str()
489 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
490 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
491 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
492 *theApp->getLog() << os.str().c_str() << "\n";
493 wxString filename = "untitled.if";
494 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
495 pFilterDoc->setBadFileOpen();
497 sys_error (ERR_SEVERE, "Unable to create filter image");
500 ImageFile& rIF = pFilterDoc->getImageFile();
501 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
502 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
503 rIF.labelAdd (os.str().c_str());
504 pFilterDoc->Modify (true);
505 pFilterDoc->UpdateAllViews();
506 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
507 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
508 pFilterDoc->getView()->getFrame()->Show(true);
513 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
515 const ImageFile& rIF = pIFDoc->getImageFile();
516 unsigned int nx = rIF.nx();
517 unsigned int ny = rIF.ny();
518 wxList& rListDocs = m_docManager->GetDocuments();
519 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
520 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
521 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
522 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
523 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
524 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
525 vecIF.push_back (pIFCompareDoc);
531 MainFrame::OnHelpTopics (wxCommandEvent& event)
533 showHelp (event.GetId());
537 MainFrame::OnHelpContents (wxCommandEvent& event)
539 showHelp (event.GetId());
542 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
544 MainFrame::OnHelpSecondary (wxCommandEvent& event)
546 m_htmlHelp.DisplayContents();
551 MainFrame::showHelp (int commandID)
555 case MAINMENU_HELP_CONTENTS:
557 m_winHelp.DisplayContents ();
559 m_htmlHelp.DisplayContents ();
563 case MAINMENU_HELP_TOPICS:
565 m_winHelp.DisplaySection (introduction);
567 m_htmlHelp.DisplayIndex();
572 *theApp->getLog() << "Unknown help command # " << commandID << "\n";
578 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
584 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
588 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
589 wxNode* pNode = rListDocs.GetFirst();
590 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
591 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
592 wxString strFilename = pDoc->GetFilename();
594 strFilename += "\tCtrl-";
595 strFilename += static_cast<char>('0' + iPos);
597 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
598 m_apWindowMenuData[iPos] = pDoc;
599 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
601 pNode = pNode->GetNext();
603 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
604 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
605 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
606 m_apWindowMenuData[i] = NULL;
611 #ifdef CTSIM_CUSTOM_MRU
613 MainFrame::OnMRUFile (wxCommandEvent& event)
615 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
617 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
622 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
624 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
625 wxString strFilename = pDoc->GetFilename();
626 const wxView* pView = pDoc->GetFirstView();
628 wxFrame* pFrame = pView->GetFrame();
635 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
636 { DoWindowMenu (0, event); }
638 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
639 { DoWindowMenu (1, event); }
641 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
642 { DoWindowMenu (2, event); }
644 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
645 { DoWindowMenu (3, event); }
647 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
648 { DoWindowMenu (4, event); }
650 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
651 { DoWindowMenu (5, event); }
653 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
654 { DoWindowMenu (6, event); }
656 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
657 { DoWindowMenu (7, event); }
659 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
660 { DoWindowMenu (8, event); }
662 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
663 { DoWindowMenu (9, event); }
665 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
666 { DoWindowMenu (10, event); }
668 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
669 { DoWindowMenu (11, event); }
671 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
672 { DoWindowMenu (12, event); }
674 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
675 { DoWindowMenu (13, event); }
677 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
678 { DoWindowMenu (14, event); }
680 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
681 { DoWindowMenu (15, event); }
683 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
684 { DoWindowMenu (16, event); }
686 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
687 { DoWindowMenu (17, event); }
689 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
690 { DoWindowMenu (18, event); }
692 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
693 { DoWindowMenu (19, event); }
696 class BitmapControl : public wxPanel
699 DECLARE_DYNAMIC_CLASS (BitmapControl)
700 DECLARE_EVENT_TABLE ()
704 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
705 const wxPoint& pos = wxDefaultPosition,
706 const wxSize& size = wxDefaultSize,
707 long style = wxSTATIC_BORDER,
708 const wxValidator& validator = wxDefaultValidator,
709 const wxString& name = "BitmapCtrl");
712 virtual ~BitmapControl();
714 virtual wxSize GetBestSize() const;
716 wxBitmap* getBitmap()
717 { return m_pBitmap; }
719 void OnPaint(wxPaintEvent& event);
723 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
724 EVT_PAINT(BitmapControl::OnPaint)
727 IMPLEMENT_CLASS(BitmapControl, wxPanel)
730 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
731 long style, const wxValidator& validator, const wxString& name)
734 Create(parent, id, pos, size, style, name);
736 SetSize (GetBestSize());
740 BitmapControl::GetBestSize () const
743 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
748 BitmapControl::~BitmapControl()
752 BitmapControl::OnPaint (wxPaintEvent& event)
756 dc.DrawBitmap (*m_pBitmap, 0, 0);
760 class BitmapDialog : public wxDialog {
762 BitmapControl* m_pBitmapCtrl;
765 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
766 virtual ~BitmapDialog();
769 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
770 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
772 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
774 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
776 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
777 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
778 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
780 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
782 SetAutoLayout (true);
783 SetSizer (pTopSizer);
784 pTopSizer->Fit (this);
785 pTopSizer->SetSizeHints (this);
788 BitmapDialog::~BitmapDialog()
793 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
795 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
796 theApp->getAskDeleteNewDocs());
797 if (dlg.ShowModal() == wxID_OK) {
798 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
799 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
804 #include "./splash.xpm"
806 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
808 wxBitmap bmp (splash);
810 BitmapDialog dlg (&bmp, "About CTSim");
813 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
818 #elif defined(VERSION)
819 msg << "Version: " << VERSION << "\n\n";
821 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
823 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
828 ProjectionFileDocument*
829 CTSimApp::newProjectionDoc()
831 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
833 ProjectionFileView* pView = newDoc->getView();
835 wxFrame* pFrame = pView->getFrame();
837 pFrame->SetSize (0,0);
838 pFrame->Show (false);
841 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
842 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
843 newDoc->OnNewDocument();
850 CTSimApp::newImageDoc()
852 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
854 ImageFileView* pView = newDoc->getView();
856 wxFrame* pFrame = pView->getFrame();
858 pFrame->SetSize (0,0);
859 pFrame->Show (false);
862 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
863 newDoc->SetDocumentTemplate (m_pDocTemplImage);
864 newDoc->OnNewDocument();
871 CTSimApp::newPlotDoc()
873 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
875 PlotFileView* pView = newDoc->getView();
877 wxFrame* pFrame = pView->getFrame();
880 m_pFrame->GetClientSize (&size.x, &size.y);
881 pFrame->SetSize (size.x / 2, size.y / 2);
882 pFrame->Show (false);
885 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
886 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
887 newDoc->OnNewDocument();
895 CTSimApp::newTextDoc()
897 wxString strFilename (getUntitledFilename());
898 strFilename += ".txt";
900 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
902 TextFileView* pView = newDoc->getView();
904 wxFrame* pFrame = pView->getFrame();
907 m_pFrame->GetClientSize (&size.x, &size.y);;
908 pFrame->SetSize (size.x / 2, size.y / 2);
909 pFrame->Show (false);
912 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
913 newDoc->SetDocumentTemplate (m_pDocTemplText);
914 newDoc->OnNewDocument();
922 CTSimApp::newPhantomDoc()
924 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
926 PhantomFileView* pView = newDoc->getView();
928 wxFrame* pFrame = pView->getFrame();
930 pFrame->SetSize (0,0);
932 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
933 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
934 newDoc->OnNewDocument();
943 CTSimApp::newGraph3dDoc()
945 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
947 Graph3dFileView* pView = newDoc->getView();
949 wxFrame* pFrame = pView->getFrame();
951 pFrame->SetSize (0,0);
953 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
954 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
955 newDoc->OnNewDocument();