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.46 2001/01/27 01:51: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 #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.46 2001/01/27 01:51:47 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";
226 CTSimApp::getUntitledFilename()
228 static int untitledNumber = 1;
230 wxString filename ("Untitled");
231 filename << untitledNumber++;
237 // Top-level window for CTSim
240 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
242 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
244 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
246 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
249 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
250 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
251 EVT_MENU(MAINMENU_HELP_TOPICS, MainFrame::OnHelpTopics)
252 EVT_SIZE(MainFrame::OnSize)
254 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
255 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
257 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
258 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
259 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
260 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
261 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
262 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
263 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
264 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
265 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
266 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
267 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
268 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
269 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
270 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
271 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
272 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
273 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
274 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
275 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
276 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
277 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
278 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
279 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
280 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
281 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
287 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
288 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
290 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
291 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
295 wxMenu *file_menu = new wxMenu;
297 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
298 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
299 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
301 file_menu->AppendSeparator();
302 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
304 // history of files visited
305 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
306 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
309 m_pWindowMenu = new wxMenu;
310 m_pWindowMenu->UpdateUI (this);
313 wxMenu* help_menu = new wxMenu;
314 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
315 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-T");
316 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
317 help_menu->Append(MAINMENU_HELP_SECONDARY, "&Secondary Help");
319 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
321 wxMenuBar* menu_bar = new wxMenuBar;
323 menu_bar->Append(file_menu, "&File");
325 menu_bar->Append(m_pWindowMenu, "&Window");
327 menu_bar->Append(help_menu, "&Help");
329 SetMenuBar(menu_bar);
333 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
334 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
335 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
336 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
340 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
341 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
342 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
343 m_iDefaultFilterXSize = 256;
344 m_iDefaultFilterYSize = 256;
345 m_dDefaultFilterParam = 1.;
346 m_dDefaultFilterBandwidth = 1.;
347 m_dDefaultFilterInputScale = 1.;
348 m_dDefaultFilterOutputScale = 1.;
350 wxAcceleratorEntry accelEntries[15];
351 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
352 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
353 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
354 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
356 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
357 for (i = 0; i < 10; i++)
358 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
359 wxAcceleratorTable accelTable (15, accelEntries);
361 wxAcceleratorTable accelTable (4, accelEntries);
364 SetAcceleratorTable (accelTable);
367 MainFrame::~MainFrame()
369 if (theApp->getConfig())
370 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
371 delete theApp->getDocManager();
375 MainFrame::OnSize (wxSizeEvent& event)
377 wxSize sizeClient = GetClientSize();
378 wxSize sizeLog = sizeClient;
379 if (sizeClient.y < 100) {
383 sizeLog.x = sizeClient.x;
386 sizeClient.x -= sizeLog.x;
387 sizeClient.y -= sizeLog.y;
388 // m_pLog->SetSize (0, sizeClient.y, sizeLog.x, sizeLog.y);
389 // GetClientWindow()->SetSize (0, 0, sizeClient.x, sizeClient.y);
390 // GetClientWindow()->Refresh();
392 wxDocMDIParentFrame::OnSize (event);
394 wxDocParentFrame::OnSize (event);
399 MainFrame::OnCreatePhantom(wxCommandEvent& event)
401 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
402 int dialogReturn = dialogPhantom.ShowModal();
403 if (dialogReturn == wxID_OK) {
404 wxString selection (dialogPhantom.getPhantom());
405 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
406 wxString filename = selection + ".phm";
407 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
408 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
414 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
416 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
417 int dialogReturn = dialogFilter.ShowModal();
418 if (dialogReturn == wxID_OK) {
419 wxString strFilter (dialogFilter.getFilterName());
420 wxString strDomain (dialogFilter.getDomainName());
421 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
422 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
423 m_iDefaultFilterXSize = dialogFilter.getXSize();
424 m_iDefaultFilterYSize = dialogFilter.getYSize();
425 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
426 m_dDefaultFilterParam= dialogFilter.getFilterParam();
427 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
428 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
429 std::ostringstream os;
430 os << "Generate Filter=" << strFilter.c_str()
431 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
432 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
433 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
434 *theApp->getLog() << os.str().c_str() << "\n";
435 wxString filename = "untitled.if";
436 ImageFileDocument* pFilterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument ("untitled.if", wxDOC_SILENT));
438 sys_error (ERR_SEVERE, "Unable to create filter image");
441 ImageFile& rIF = pFilterDoc->getImageFile();
442 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
443 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
444 rIF.labelAdd (os.str().c_str());
445 if (theApp->getSetModifyNewDocs())
446 pFilterDoc->Modify (true);
447 pFilterDoc->UpdateAllViews();
448 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
453 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
455 const ImageFile& rIF = pIFDoc->getImageFile();
456 unsigned int nx = rIF.nx();
457 unsigned int ny = rIF.ny();
458 wxList& rListDocs = m_docManager->GetDocuments();
459 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
460 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
461 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
462 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
463 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
464 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
465 vecIF.push_back (pIFCompareDoc);
471 MainFrame::OnHelpTopics (wxCommandEvent& event)
473 showHelp (event.GetId());
477 MainFrame::OnHelpContents (wxCommandEvent& event)
479 showHelp (event.GetId());
482 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
484 MainFrame::OnHelpSecondary (wxCommandEvent& event)
486 m_htmlHelp.DisplayContents();
491 MainFrame::showHelp (int commandID)
494 m_winHelp.LoadFile();
496 m_htmlHelp.LoadFile();
501 case MAINMENU_HELP_CONTENTS:
503 m_winHelp.DisplayContents ();
505 m_htmlHelp.DisplayContents ();
509 case MAINMENU_HELP_TOPICS:
511 m_winHelp.DisplaySection (introduction);
513 m_htmlHelp.DisplayIndex();
518 *theApp->getLog() << "Unknown help command # " << commandID << "\n";
524 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
530 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
533 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
534 wxNode* pNode = rListDocs.GetFirst();
535 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
536 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
537 wxString strFilename = pDoc->GetFilename();
539 strFilename += "\tCtrl-";
540 strFilename += static_cast<char>('0' + iPos);
542 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
543 m_apWindowMenuData[iPos] = pDoc;
544 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
546 pNode = pNode->GetNext();
548 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
549 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
550 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
551 m_apWindowMenuData[i] = NULL;
556 #ifdef CTSIM_CUSTOM_MRU
558 MainFrame::OnMRUFile (wxCommandEvent& event)
560 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
562 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
567 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
569 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
570 wxString strFilename = pDoc->GetFilename();
571 const wxView* pView = pDoc->GetFirstView();
573 wxFrame* pFrame = pView->GetFrame();
580 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
581 { DoWindowMenu (0, event); }
583 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
584 { DoWindowMenu (1, event); }
586 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
587 { DoWindowMenu (2, event); }
589 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
590 { DoWindowMenu (3, event); }
592 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
593 { DoWindowMenu (4, event); }
595 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
596 { DoWindowMenu (5, event); }
598 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
599 { DoWindowMenu (6, event); }
601 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
602 { DoWindowMenu (7, event); }
604 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
605 { DoWindowMenu (8, event); }
607 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
608 { DoWindowMenu (9, event); }
610 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
611 { DoWindowMenu (10, event); }
613 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
614 { DoWindowMenu (11, event); }
616 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
617 { DoWindowMenu (12, event); }
619 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
620 { DoWindowMenu (13, event); }
622 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
623 { DoWindowMenu (14, event); }
625 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
626 { DoWindowMenu (15, event); }
628 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
629 { DoWindowMenu (16, event); }
631 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
632 { DoWindowMenu (17, event); }
634 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
635 { DoWindowMenu (18, event); }
637 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
638 { DoWindowMenu (19, event); }
641 class BitmapControl : public wxPanel
644 DECLARE_DYNAMIC_CLASS (BitmapControl)
645 DECLARE_EVENT_TABLE ()
649 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
650 const wxPoint& pos = wxDefaultPosition,
651 const wxSize& size = wxDefaultSize,
652 long style = wxSTATIC_BORDER,
653 const wxValidator& validator = wxDefaultValidator,
654 const wxString& name = "BitmapCtrl");
657 virtual ~BitmapControl();
659 virtual wxSize GetBestSize() const;
661 wxBitmap* getBitmap()
662 { return m_pBitmap; }
664 void OnPaint(wxPaintEvent& event);
668 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
669 EVT_PAINT(BitmapControl::OnPaint)
672 IMPLEMENT_CLASS(BitmapControl, wxPanel)
675 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
676 long style, const wxValidator& validator, const wxString& name)
679 Create(parent, id, pos, size, style, name);
681 SetSize (GetBestSize());
685 BitmapControl::GetBestSize () const
688 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
693 BitmapControl::~BitmapControl()
697 BitmapControl::OnPaint (wxPaintEvent& event)
701 dc.DrawBitmap (*m_pBitmap, 0, 0);
705 class BitmapDialog : public wxDialog {
707 BitmapControl* m_pBitmapCtrl;
710 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
711 virtual ~BitmapDialog();
714 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
715 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
717 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
719 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
721 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
722 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
723 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
725 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
727 SetAutoLayout (true);
728 SetSizer (pTopSizer);
729 pTopSizer->Fit (this);
730 pTopSizer->SetSizeHints (this);
733 BitmapDialog::~BitmapDialog()
737 #include "./splash.xpm"
739 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
741 wxBitmap bmp (splash);
743 BitmapDialog dlg (&bmp, "About CTSim");
746 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
751 #elif defined(VERSION)
752 msg << "Version: " << VERSION << "\n\n";
754 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
756 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
761 ProjectionFileDocument*
762 CTSimApp::newProjectionDoc()
764 wxString strFilename (getUntitledFilename());
765 strFilename += ".pj";
767 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (strFilename));
769 ProjectionFileView* pView = newDoc->getView();
771 wxFrame* pFrame = pView->getFrame();
773 pFrame->SetSize(0,0);
774 pFrame->Show (false);
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);
797 pFrame->Show (false);
800 newDoc->OnNewDocument();
801 // newDoc->SetFilename(strFilename, true);
808 CTSimApp::newPlotDoc()
810 wxString strFilename (getUntitledFilename());
811 strFilename += ".plt";
813 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (strFilename));
815 PlotFileView* pView = newDoc->getView();
817 wxFrame* pFrame = pView->getFrame();
819 pFrame->SetSize(0,0);
821 newDoc->OnNewDocument();
822 // newDoc->SetFilename(strFilename, true);
830 CTSimApp::newTextDoc()
832 wxString strFilename (getUntitledFilename());
833 strFilename += ".txt";
835 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (strFilename));
837 TextFileView* pView = newDoc->getView();
839 wxFrame* pFrame = pView->getFrame();
841 pFrame->SetSize(0,0);
843 newDoc->OnNewDocument();
844 // newDoc->SetFilename(strFilename, true);
852 CTSimApp::newPhantomDoc()
854 wxString strFilename (getUntitledFilename());
855 strFilename += ".phm";
857 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (strFilename));
859 PhantomFileView* pView = newDoc->getView();
861 wxFrame* pFrame = pView->getFrame();
863 pFrame->SetSize(0,0);
865 newDoc->OnNewDocument();
866 // newDoc->SetFilename(strFilename, true);