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.58 2001/01/29 23:11:32 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.58 2001/01/29 23:11:32 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), m_pLogDoc(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),
154 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .755)), wxDEFAULT_FRAME_STYLE);
156 setIconForFrame (m_pFrame);
157 m_pFrame->Centre(wxBOTH);
158 m_pFrame->Show(true);
159 SetTopWindow (m_pFrame);
161 for (int i = optind + 1; i <= argc; i++) {
162 wxString filename = argv [i - 1];
163 m_docManager->CreateDocument (filename, wxDOC_SILENT);
167 m_docManager->FileHistoryLoad(*m_pConfig);
170 m_pLogDoc = newTextDoc();
172 m_pLog = m_pLogDoc->getTextCtrl();
173 m_pLogDoc->SetDocumentName("Log.txt");
174 m_pLogDoc->SetFilename("Log.txt");
175 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
177 m_pFrame->GetClientSize(&xSize, &ySize);
178 int yLogSize = ySize / 3;
179 m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
180 m_pLogDoc->getView()->getFrame()->Show (true);
183 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
185 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
188 if (! m_pFrame->getWinHelpController().Initialize("ctsim"))
189 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
191 if (! m_pFrame->getHtmlHelpController().Initialize(::wxGetCwd() + "/ctsim"))
192 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
198 #include "./ctsim.xpm"
200 CTSimApp::setIconForFrame(wxFrame* pFrame)
202 wxIcon iconApp (ctsim16_xpm);
205 pFrame->SetIcon (iconApp);
209 CTSimApp::usage(const char* program)
211 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
212 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
214 std::cout << " --version Display version\n";
215 std::cout << " --help Display this help message\n";
228 CTSimApp::getUntitledFilename()
230 static int untitledNumber = 1;
232 wxString filename ("Untitled");
233 filename << untitledNumber++;
239 // Top-level window for CTSim
242 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
244 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
246 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
248 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
251 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
252 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
253 EVT_MENU(MAINMENU_HELP_TOPICS, MainFrame::OnHelpTopics)
254 EVT_SIZE(MainFrame::OnSize)
256 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
257 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
259 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
260 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
261 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
262 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
263 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
264 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
265 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
266 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
267 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
268 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
269 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
270 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
271 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
272 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
273 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
274 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
275 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
276 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
277 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
278 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
279 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
280 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
281 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
282 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
283 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
289 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
290 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
292 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
293 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
297 wxMenu *file_menu = new wxMenu;
299 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
300 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
301 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
303 file_menu->AppendSeparator();
304 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
306 // history of files visited
307 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
308 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
311 m_pWindowMenu = new wxMenu;
312 m_pWindowMenu->UpdateUI (this);
315 wxMenu* help_menu = new wxMenu;
316 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
317 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-T");
318 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
319 help_menu->Append(MAINMENU_HELP_SECONDARY, "&Secondary Help");
321 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
323 wxMenuBar* menu_bar = new wxMenuBar;
325 menu_bar->Append(file_menu, "&File");
327 menu_bar->Append(m_pWindowMenu, "&Window");
329 menu_bar->Append(help_menu, "&Help");
331 SetMenuBar(menu_bar);
335 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
336 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
337 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
338 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
342 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
343 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
344 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
345 m_iDefaultFilterXSize = 256;
346 m_iDefaultFilterYSize = 256;
347 m_dDefaultFilterParam = 1.;
348 m_dDefaultFilterBandwidth = 1.;
349 m_dDefaultFilterInputScale = 1.;
350 m_dDefaultFilterOutputScale = 1.;
352 wxAcceleratorEntry accelEntries[15];
353 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
354 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
355 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
356 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
358 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
359 for (i = 0; i < 10; i++)
360 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
361 wxAcceleratorTable accelTable (15, accelEntries);
363 wxAcceleratorTable accelTable (4, accelEntries);
366 SetAcceleratorTable (accelTable);
369 MainFrame::~MainFrame()
371 if (theApp->getConfig())
372 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
373 delete theApp->getDocManager();
378 MainFrame::OnSize (wxSizeEvent& event)
382 wxMDIParentFrame::GetClientSize(&xSize, &ySize);
384 if (theApp->getLogDoc()) {
385 GetClientSize(&xSize, &ySize);
386 int yLogSize = ySize / 3;
387 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
388 theApp->getLogDoc()->getView()->getFrame()->Show (true);
390 //GetClientWindow()->SetSize (0, 0, sizeClient.x, sizeClient.y);
391 //GetClientWindow()->Refresh();
395 wxDocMDIParentFrame::OnSize (event);
397 wxDocParentFrame::OnSize (event);
402 MainFrame::OnCreatePhantom(wxCommandEvent& event)
404 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
405 int dialogReturn = dialogPhantom.ShowModal();
406 if (dialogReturn == wxID_OK) {
407 wxString selection (dialogPhantom.getPhantom());
408 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
409 wxString filename = selection + ".phm";
410 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
411 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
417 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
419 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
420 int dialogReturn = dialogFilter.ShowModal();
421 if (dialogReturn == wxID_OK) {
422 wxString strFilter (dialogFilter.getFilterName());
423 wxString strDomain (dialogFilter.getDomainName());
424 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
425 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
426 m_iDefaultFilterXSize = dialogFilter.getXSize();
427 m_iDefaultFilterYSize = dialogFilter.getYSize();
428 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
429 m_dDefaultFilterParam= dialogFilter.getFilterParam();
430 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
431 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
432 std::ostringstream os;
433 os << "Generate Filter=" << strFilter.c_str()
434 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
435 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
436 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
437 *theApp->getLog() << os.str().c_str() << "\n";
438 wxString filename = "untitled.if";
439 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
441 sys_error (ERR_SEVERE, "Unable to create filter image");
444 ImageFile& rIF = pFilterDoc->getImageFile();
445 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
446 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
447 rIF.labelAdd (os.str().c_str());
448 pFilterDoc->Modify (true);
449 pFilterDoc->UpdateAllViews();
450 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
451 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
452 pFilterDoc->getView()->getFrame()->Show(true);
457 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
459 const ImageFile& rIF = pIFDoc->getImageFile();
460 unsigned int nx = rIF.nx();
461 unsigned int ny = rIF.ny();
462 wxList& rListDocs = m_docManager->GetDocuments();
463 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
464 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
465 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
466 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
467 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
468 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
469 vecIF.push_back (pIFCompareDoc);
475 MainFrame::OnHelpTopics (wxCommandEvent& event)
477 showHelp (event.GetId());
481 MainFrame::OnHelpContents (wxCommandEvent& event)
483 showHelp (event.GetId());
486 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
488 MainFrame::OnHelpSecondary (wxCommandEvent& event)
490 m_htmlHelp.DisplayContents();
495 MainFrame::showHelp (int commandID)
498 m_winHelp.LoadFile();
500 m_htmlHelp.LoadFile();
505 case MAINMENU_HELP_CONTENTS:
507 m_winHelp.DisplayContents ();
509 m_htmlHelp.DisplayContents ();
513 case MAINMENU_HELP_TOPICS:
515 m_winHelp.DisplaySection (introduction);
517 m_htmlHelp.DisplayIndex();
522 *theApp->getLog() << "Unknown help command # " << commandID << "\n";
528 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
534 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
538 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
539 wxNode* pNode = rListDocs.GetFirst();
540 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
541 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
542 wxString strFilename = pDoc->GetFilename();
544 strFilename += "\tCtrl-";
545 strFilename += static_cast<char>('0' + iPos);
547 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
548 m_apWindowMenuData[iPos] = pDoc;
549 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
551 pNode = pNode->GetNext();
553 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
554 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
555 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
556 m_apWindowMenuData[i] = NULL;
561 #ifdef CTSIM_CUSTOM_MRU
563 MainFrame::OnMRUFile (wxCommandEvent& event)
565 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
567 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
572 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
574 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
575 wxString strFilename = pDoc->GetFilename();
576 const wxView* pView = pDoc->GetFirstView();
578 wxFrame* pFrame = pView->GetFrame();
585 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
586 { DoWindowMenu (0, event); }
588 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
589 { DoWindowMenu (1, event); }
591 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
592 { DoWindowMenu (2, event); }
594 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
595 { DoWindowMenu (3, event); }
597 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
598 { DoWindowMenu (4, event); }
600 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
601 { DoWindowMenu (5, event); }
603 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
604 { DoWindowMenu (6, event); }
606 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
607 { DoWindowMenu (7, event); }
609 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
610 { DoWindowMenu (8, event); }
612 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
613 { DoWindowMenu (9, event); }
615 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
616 { DoWindowMenu (10, event); }
618 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
619 { DoWindowMenu (11, event); }
621 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
622 { DoWindowMenu (12, event); }
624 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
625 { DoWindowMenu (13, event); }
627 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
628 { DoWindowMenu (14, event); }
630 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
631 { DoWindowMenu (15, event); }
633 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
634 { DoWindowMenu (16, event); }
636 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
637 { DoWindowMenu (17, event); }
639 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
640 { DoWindowMenu (18, event); }
642 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
643 { DoWindowMenu (19, event); }
646 class BitmapControl : public wxPanel
649 DECLARE_DYNAMIC_CLASS (BitmapControl)
650 DECLARE_EVENT_TABLE ()
654 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
655 const wxPoint& pos = wxDefaultPosition,
656 const wxSize& size = wxDefaultSize,
657 long style = wxSTATIC_BORDER,
658 const wxValidator& validator = wxDefaultValidator,
659 const wxString& name = "BitmapCtrl");
662 virtual ~BitmapControl();
664 virtual wxSize GetBestSize() const;
666 wxBitmap* getBitmap()
667 { return m_pBitmap; }
669 void OnPaint(wxPaintEvent& event);
673 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
674 EVT_PAINT(BitmapControl::OnPaint)
677 IMPLEMENT_CLASS(BitmapControl, wxPanel)
680 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
681 long style, const wxValidator& validator, const wxString& name)
684 Create(parent, id, pos, size, style, name);
686 SetSize (GetBestSize());
690 BitmapControl::GetBestSize () const
693 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
698 BitmapControl::~BitmapControl()
702 BitmapControl::OnPaint (wxPaintEvent& event)
706 dc.DrawBitmap (*m_pBitmap, 0, 0);
710 class BitmapDialog : public wxDialog {
712 BitmapControl* m_pBitmapCtrl;
715 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
716 virtual ~BitmapDialog();
719 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
720 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
722 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
724 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
726 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
727 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
728 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
730 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
732 SetAutoLayout (true);
733 SetSizer (pTopSizer);
734 pTopSizer->Fit (this);
735 pTopSizer->SetSizeHints (this);
738 BitmapDialog::~BitmapDialog()
742 #include "./splash.xpm"
744 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
746 wxBitmap bmp (splash);
748 BitmapDialog dlg (&bmp, "About CTSim");
751 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
756 #elif defined(VERSION)
757 msg << "Version: " << VERSION << "\n\n";
759 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
761 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
766 ProjectionFileDocument*
767 CTSimApp::newProjectionDoc()
769 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
771 ProjectionFileView* pView = newDoc->getView();
773 wxFrame* pFrame = pView->getFrame();
775 pFrame->SetSize (0,0);
776 pFrame->Show (false);
779 // newDoc->OnNewDocument();
786 CTSimApp::newImageDoc()
788 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
790 ImageFileView* pView = newDoc->getView();
792 wxFrame* pFrame = pView->getFrame();
794 pFrame->SetSize (0,0);
795 pFrame->Show (false);
798 // newDoc->OnNewDocument();
805 CTSimApp::newPlotDoc()
807 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
809 PlotFileView* pView = newDoc->getView();
811 wxFrame* pFrame = pView->getFrame();
814 m_pFrame->GetClientSize (&size.x, &size.y);
815 pFrame->SetSize (size.x / 2, size.y / 2);
816 pFrame->Show (false);
819 // newDoc->OnNewDocument();
827 CTSimApp::newTextDoc()
829 wxString strFilename (getUntitledFilename());
830 strFilename += ".txt";
832 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
834 TextFileView* pView = newDoc->getView();
836 wxFrame* pFrame = pView->getFrame();
839 m_pFrame->GetClientSize (&size.x, &size.y);;
840 pFrame->SetSize (size.x / 2, size.y / 2);
841 pFrame->Show (false);
844 // newDoc->OnNewDocument();
852 CTSimApp::newPhantomDoc()
854 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
856 PhantomFileView* pView = newDoc->getView();
858 wxFrame* pFrame = pView->getFrame();
860 pFrame->SetSize (0,0);
862 // newDoc->OnNewDocument();