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.44 2001/01/26 21:22:37 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 #if !wxUSE_DOC_VIEW_ARCHITECTURE
48 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
54 #include "ctsim-map.h"
59 #if defined(HAVE_CONFIG_H)
63 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
73 static const char* rcsindent = "$Id: ctsim.cpp,v 1.44 2001/01/26 21:22:37 kevin Exp $";
75 struct option CTSimApp::ctsimOptions[] =
77 {"help", 0, 0, O_HELP},
78 {"version", 0, 0, O_VERSION},
82 IMPLEMENT_APP(CTSimApp)
85 : m_docManager(NULL), m_pFrame(NULL), m_pLog(0)
90 #ifdef HAVE_SYS_TIME_H
94 #ifdef HAVE_SYS_RESOURCE_H
95 #include <sys/resource.h>
101 #ifdef HAVE_SETPRIORITY
102 setpriority (PRIO_PROCESS, 0, 15); // set to low scheduling priority
105 m_pConfig = new wxConfig("ctsim");
106 wxConfigBase::Set(m_pConfig);
108 g_bRunningWXWindows = true;
111 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
117 std::cout << rcsindent << std::endl;
119 std::cout << "Version: CTSIMVERSION" << std::endl;
120 #elif defined(VERSION)
121 std::cout << "Version: VERSION" << std::endl;
134 m_docManager = new wxDocManager (wxDEFAULT_DOCMAN_FLAGS, true);
136 m_pDocTemplImage = new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile", "ImageView", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
137 m_pDocTemplProjection = new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile", "ProjectionView", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
138 m_pDocTemplPhantom = new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "PhantomFile", "PhantomView", CLASSINFO(PhantomFileDocument), CLASSINFO(PhantomFileView));
139 m_pDocTemplPlot = new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "PlotFile", "PlotView", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
140 m_pDocTemplText = new wxDocTemplate (m_docManager, "TextFile", "*.txt", "", "txt", "TextFile", "TextView", CLASSINFO(TextFileDocument), CLASSINFO(TextFileView), wxTEMPLATE_INVISIBLE);
143 wxImage::AddHandler(new wxGIFHandler); // Required for images in the online documentation
146 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
147 wxFileSystem::AddHandler(new wxZipFSHandler); // Required for advanced HTML help
150 // Create the main frame window
151 int xDisplay, yDisplay;
152 ::wxDisplaySize (&xDisplay, &yDisplay);
153 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0), wxSize(xDisplay * .75, yDisplay * .755), wxDEFAULT_FRAME_STYLE);
155 setIconForFrame (m_pFrame);
156 m_pFrame->Centre(wxBOTH);
157 m_pFrame->Show(true);
158 SetTopWindow (m_pFrame);
160 for (int i = optind + 1; i <= argc; i++) {
161 wxString filename = argv [i - 1];
162 m_docManager->CreateDocument (filename, wxDOC_SILENT);
166 m_docManager->FileHistoryLoad(*m_pConfig);
169 if (! m_pFrame->getWinHelpController().Initialize("ctsim"))
170 ::wxMessageBox ("Cannot initialize the help system", "Error");
172 if (! m_pFrame->getHtmlHelpController().Initialize(::wxGetCwd() + "/ctsim"))
173 ::wxMessageBox ("Cannot initialize the help system", "Error");
176 TextFileDocument* pLogDoc = newTextDoc();
178 m_pLog = pLogDoc->getTextCtrl();
179 pLogDoc->SetDocumentName("Log.txt");
180 pLogDoc->SetFilename("Log.txt");
181 pLogDoc->getView()->getFrame()->SetTitle("Log");
183 m_pFrame->GetClientSize(&xSize, &ySize);
184 int yLogSize = ySize / 3;
185 pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
188 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
190 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
196 #include "./ctsim.xpm"
198 CTSimApp::setIconForFrame(wxFrame* pFrame)
200 wxIcon iconApp (ctsim16_xpm);
203 pFrame->SetIcon (iconApp);
207 CTSimApp::usage(const char* program)
209 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
210 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
212 std::cout << " --version Display version\n";
213 std::cout << " --help Display this help message\n";
219 if (theApp->getConfig())
220 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
221 delete theApp->getDocManager();
222 // m_docManager = NULL;
231 CTSimApp::getUntitledFilename()
233 static int untitledNumber = 1;
235 wxString filename ("Untitled");
236 filename << untitledNumber++;
242 // Top-level window for CTSim
245 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
247 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
249 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
251 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
254 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
255 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
256 EVT_MENU(MAINMENU_HELP_TOPICS, MainFrame::OnHelpTopics)
257 EVT_SIZE(MainFrame::OnSize)
259 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
260 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
262 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
263 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
264 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
265 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
266 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
267 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
268 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
269 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
270 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
271 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
272 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
273 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
274 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
275 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
276 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
277 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
278 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
279 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
280 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
281 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
282 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
283 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
284 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
285 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
286 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
292 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
293 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
295 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
296 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
300 wxMenu *file_menu = new wxMenu;
302 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
303 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
304 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
306 file_menu->AppendSeparator();
307 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
309 // history of files visited
310 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
311 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
314 m_pWindowMenu = new wxMenu;
315 m_pWindowMenu->UpdateUI (this);
318 wxMenu* help_menu = new wxMenu;
319 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
320 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-T");
321 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
322 help_menu->Append(MAINMENU_HELP_SECONDARY, "&Secondary Help");
324 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
326 wxMenuBar* menu_bar = new wxMenuBar;
328 menu_bar->Append(file_menu, "&File");
330 menu_bar->Append(m_pWindowMenu, "&Window");
332 menu_bar->Append(help_menu, "&Help");
334 SetMenuBar(menu_bar);
338 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
339 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
340 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
341 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
345 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
346 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
347 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
348 m_iDefaultFilterXSize = 256;
349 m_iDefaultFilterYSize = 256;
350 m_dDefaultFilterParam = 1.;
351 m_dDefaultFilterBandwidth = 1.;
352 m_dDefaultFilterInputScale = 1.;
353 m_dDefaultFilterOutputScale = 1.;
355 wxAcceleratorEntry accelEntries[15];
356 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
357 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
358 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
359 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
361 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
362 for (i = 0; i < 10; i++)
363 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
364 wxAcceleratorTable accelTable (15, accelEntries);
366 wxAcceleratorTable accelTable (4, accelEntries);
369 SetAcceleratorTable (accelTable);
372 MainFrame::~MainFrame()
377 MainFrame::OnSize (wxSizeEvent& event)
379 wxSize sizeClient = GetClientSize();
380 wxSize sizeLog = sizeClient;
381 if (sizeClient.y < 100) {
385 sizeLog.x = sizeClient.x;
388 sizeClient.x -= sizeLog.x;
389 sizeClient.y -= sizeLog.y;
390 // m_pLog->SetSize (0, sizeClient.y, sizeLog.x, sizeLog.y);
391 // GetClientWindow()->SetSize (0, 0, sizeClient.x, sizeClient.y);
392 // GetClientWindow()->Refresh();
394 wxDocMDIParentFrame::OnSize (event);
396 wxDocParentFrame::OnSize (event);
401 MainFrame::OnCreatePhantom(wxCommandEvent& event)
403 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
404 int dialogReturn = dialogPhantom.ShowModal();
405 if (dialogReturn == wxID_OK) {
406 wxString selection (dialogPhantom.getPhantom());
407 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
408 wxString filename = selection + ".phm";
409 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
410 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
416 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
418 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
419 int dialogReturn = dialogFilter.ShowModal();
420 if (dialogReturn == wxID_OK) {
421 wxString strFilter (dialogFilter.getFilterName());
422 wxString strDomain (dialogFilter.getDomainName());
423 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
424 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
425 m_iDefaultFilterXSize = dialogFilter.getXSize();
426 m_iDefaultFilterYSize = dialogFilter.getYSize();
427 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
428 m_dDefaultFilterParam= dialogFilter.getFilterParam();
429 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
430 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
431 std::ostringstream os;
432 os << "Generate Filter=" << strFilter.c_str()
433 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
434 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
435 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
436 *theApp->getLog() << os.str().c_str() << "\n";
437 wxString filename = "untitled.if";
438 ImageFileDocument* pFilterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument ("untitled.if", wxDOC_SILENT));
440 sys_error (ERR_SEVERE, "Unable to create filter image");
443 ImageFile& rIF = pFilterDoc->getImageFile();
444 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
445 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
446 rIF.labelAdd (os.str().c_str());
447 if (theApp->getSetModifyNewDocs())
448 pFilterDoc->Modify (true);
449 pFilterDoc->UpdateAllViews();
450 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
455 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
457 const ImageFile& rIF = pIFDoc->getImageFile();
458 unsigned int nx = rIF.nx();
459 unsigned int ny = rIF.ny();
460 wxList& rListDocs = m_docManager->GetDocuments();
461 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
462 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
463 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
464 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
465 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
466 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
467 vecIF.push_back (pIFCompareDoc);
473 MainFrame::OnHelpTopics (wxCommandEvent& event)
475 showHelp (event.GetId());
479 MainFrame::OnHelpContents (wxCommandEvent& event)
481 showHelp (event.GetId());
484 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
486 MainFrame::OnHelpSecondary (wxCommandEvent& event)
488 m_htmlHelp.DisplayContents();
493 MainFrame::showHelp (int commandID)
496 m_winHelp.LoadFile();
498 m_htmlHelp.LoadFile();
503 case MAINMENU_HELP_CONTENTS:
505 m_winHelp.DisplayContents ();
507 m_htmlHelp.DisplayContents ();
511 case MAINMENU_HELP_TOPICS:
513 m_winHelp.DisplaySection (introduction);
515 m_htmlHelp.DisplayIndex();
520 *theApp->getLog() << "Unknown help command # " << commandID << "\n";
526 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
532 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
535 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
536 wxNode* pNode = rListDocs.GetFirst();
537 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
538 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
539 wxString strFilename = pDoc->GetFilename();
541 strFilename += "\tCtrl-";
542 strFilename += static_cast<char>('0' + iPos);
544 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
545 m_apWindowMenuData[iPos] = pDoc;
546 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
548 pNode = pNode->GetNext();
550 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
551 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
552 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
553 m_apWindowMenuData[i] = NULL;
558 #ifdef CTSIM_CUSTOM_MRU
560 MainFrame::OnMRUFile (wxCommandEvent& event)
562 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
564 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
569 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
571 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
572 wxString strFilename = pDoc->GetFilename();
573 const wxView* pView = pDoc->GetFirstView();
575 wxFrame* pFrame = pView->GetFrame();
582 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
583 { DoWindowMenu (0, event); }
585 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
586 { DoWindowMenu (1, event); }
588 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
589 { DoWindowMenu (2, event); }
591 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
592 { DoWindowMenu (3, event); }
594 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
595 { DoWindowMenu (4, event); }
597 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
598 { DoWindowMenu (5, event); }
600 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
601 { DoWindowMenu (6, event); }
603 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
604 { DoWindowMenu (7, event); }
606 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
607 { DoWindowMenu (8, event); }
609 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
610 { DoWindowMenu (9, event); }
612 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
613 { DoWindowMenu (10, event); }
615 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
616 { DoWindowMenu (11, event); }
618 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
619 { DoWindowMenu (12, event); }
621 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
622 { DoWindowMenu (13, event); }
624 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
625 { DoWindowMenu (14, event); }
627 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
628 { DoWindowMenu (15, event); }
630 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
631 { DoWindowMenu (16, event); }
633 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
634 { DoWindowMenu (17, event); }
636 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
637 { DoWindowMenu (18, event); }
639 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
640 { DoWindowMenu (19, event); }
643 class BitmapControl : public wxPanel
646 DECLARE_DYNAMIC_CLASS (BitmapControl)
647 DECLARE_EVENT_TABLE ()
651 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
652 const wxPoint& pos = wxDefaultPosition,
653 const wxSize& size = wxDefaultSize,
654 long style = wxSTATIC_BORDER,
655 const wxValidator& validator = wxDefaultValidator,
656 const wxString& name = "BitmapCtrl");
659 virtual ~BitmapControl();
661 virtual wxSize GetBestSize() const;
663 wxBitmap* getBitmap()
664 { return m_pBitmap; }
666 void OnPaint(wxPaintEvent& event);
670 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
671 EVT_PAINT(BitmapControl::OnPaint)
674 IMPLEMENT_CLASS(BitmapControl, wxPanel)
677 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
678 long style, const wxValidator& validator, const wxString& name)
681 Create(parent, id, pos, size, style, name);
683 SetSize (GetBestSize());
687 BitmapControl::GetBestSize () const
690 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
695 BitmapControl::~BitmapControl()
699 BitmapControl::OnPaint (wxPaintEvent& event)
703 dc.DrawBitmap (*m_pBitmap, 0, 0);
707 class BitmapDialog : public wxDialog {
709 BitmapControl* m_pBitmapCtrl;
712 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
713 virtual ~BitmapDialog();
716 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
717 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
719 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
721 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
723 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
724 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
725 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
727 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
729 SetAutoLayout (true);
730 SetSizer (pTopSizer);
731 pTopSizer->Fit (this);
732 pTopSizer->SetSizeHints (this);
735 BitmapDialog::~BitmapDialog()
739 #include "./splash.xpm"
741 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
743 wxBitmap bmp (splash);
745 BitmapDialog dlg (&bmp, "About CTSim");
748 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
753 #elif defined(VERSION)
754 msg << "Version: " << VERSION << "\n\n";
756 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
758 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
763 ProjectionFileDocument*
764 CTSimApp::newProjectionDoc()
766 wxString strFilename (getUntitledFilename());
767 strFilename += ".pj";
769 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (strFilename));
771 ProjectionFileView* pView = newDoc->getView();
773 wxFrame* pFrame = pView->getFrame();
775 pFrame->SetSize(0,0);
777 newDoc->OnNewDocument();
778 // newDoc->SetFilename(strFilename, true);
785 CTSimApp::newImageDoc()
787 wxString strFilename (getUntitledFilename());
788 strFilename += ".pj";
790 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (strFilename));
792 ImageFileView* pView = newDoc->getView();
794 wxFrame* pFrame = pView->getFrame();
796 pFrame->SetSize(0,0);
798 newDoc->OnNewDocument();
799 // newDoc->SetFilename(strFilename, true);
806 CTSimApp::newPlotDoc()
808 wxString strFilename (getUntitledFilename());
809 strFilename += ".plt";
811 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (strFilename));
813 PlotFileView* pView = newDoc->getView();
815 wxFrame* pFrame = pView->getFrame();
817 pFrame->SetSize(0,0);
819 newDoc->OnNewDocument();
820 // newDoc->SetFilename(strFilename, true);
828 CTSimApp::newTextDoc()
830 wxString strFilename (getUntitledFilename());
831 strFilename += ".txt";
833 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (strFilename));
835 TextFileView* pView = newDoc->getView();
837 wxFrame* pFrame = pView->getFrame();
839 pFrame->SetSize(0,0);
841 newDoc->OnNewDocument();
842 // newDoc->SetFilename(strFilename, true);
850 CTSimApp::newPhantomDoc()
852 wxString strFilename (getUntitledFilename());
853 strFilename += ".phm";
855 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (strFilename));
857 PhantomFileView* pView = newDoc->getView();
859 wxFrame* pFrame = pView->getFrame();
861 pFrame->SetSize(0,0);
863 newDoc->OnNewDocument();
864 // newDoc->SetFilename(strFilename, true);