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.40 2001/01/20 17:43:41 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.40 2001/01/20 17:43:41 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 new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile", "ImageView", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
137 new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile", "ProjectionView", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
138 new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "PhantomFile", "PhantomView", CLASSINFO(PhantomDocument), CLASSINFO(PhantomView));
139 new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "PlotFile", "PlotView", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
140 new wxDocTemplate (m_docManager, "TextEdit", "*.txt", "", "txt", "TextFile", "TextView", CLASSINFO(TextEditDocument), CLASSINFO(TextEditView), 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 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
153 setIconForFrame (m_pFrame);
154 m_pFrame->Centre(wxBOTH);
155 m_pFrame->Show(true);
156 SetTopWindow (m_pFrame);
158 for (int i = optind + 1; i <= argc; i++) {
159 wxString filename = argv [i - 1];
160 m_docManager->CreateDocument (filename, wxDOC_SILENT);
164 m_docManager->FileHistoryLoad(*m_pConfig);
167 if (! m_pFrame->getWinHelpController().Initialize("ctsim"))
168 ::wxMessageBox ("Cannot initialize the help system", "Error");
170 if (! m_pFrame->getHtmlHelpController().Initialize(::wxGetCwd() + "/ctsim"))
171 ::wxMessageBox ("Cannot initialize the help system", "Error");
174 TextEditDocument* pLogDoc = dynamic_cast<TextEditDocument*>(m_docManager->CreateDocument("Log.txt", wxDOC_SILENT));
176 m_pLog = pLogDoc->getTextCtrl();
179 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
181 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
187 #include "./ctsim.xpm"
189 CTSimApp::setIconForFrame(wxFrame* pFrame)
191 wxIcon iconApp (ctsim16_xpm);
194 pFrame->SetIcon (iconApp);
198 CTSimApp::usage(const char* program)
200 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
201 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
203 std::cout << " --version Display version\n";
204 std::cout << " --help Display this help message\n";
217 CTSimApp::getUntitledFilename()
219 static int untitledNumber = 1;
221 wxString filename ("Untitled");
222 filename << untitledNumber++;
228 // Top-level window for CTSim
231 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
233 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
235 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
237 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
240 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
241 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
242 EVT_MENU(MAINMENU_HELP_TOPICS, MainFrame::OnHelpTopics)
243 EVT_SIZE(MainFrame::OnSize)
245 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
246 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
248 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
249 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
250 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
251 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
252 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
253 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
254 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
255 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
256 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
257 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
258 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
259 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
260 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
261 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
262 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
263 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
264 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
265 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
266 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
267 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
268 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
269 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
270 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
271 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
272 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
278 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
279 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
281 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
282 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
286 wxMenu *file_menu = new wxMenu;
288 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
289 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
290 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
292 file_menu->AppendSeparator();
293 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
295 // history of files visited
296 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
299 m_pWindowMenu = new wxMenu;
300 m_pWindowMenu->UpdateUI (this);
303 wxMenu* help_menu = new wxMenu;
304 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
305 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-T");
306 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
307 help_menu->Append(MAINMENU_HELP_SECONDARY, "&Secondary Help");
309 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
311 wxMenuBar* menu_bar = new wxMenuBar;
313 menu_bar->Append(file_menu, "&File");
315 menu_bar->Append(m_pWindowMenu, "&Window");
317 menu_bar->Append(help_menu, "&Help");
319 SetMenuBar(menu_bar);
322 for (int i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
323 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
324 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
325 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
329 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
330 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
331 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
332 m_iDefaultFilterXSize = 256;
333 m_iDefaultFilterYSize = 256;
334 m_dDefaultFilterParam = 1.;
335 m_dDefaultFilterBandwidth = 1.;
336 m_dDefaultFilterInputScale = 1.;
337 m_dDefaultFilterOutputScale = 1.;
339 wxAcceleratorEntry accelEntries[15];
340 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
341 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
342 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
343 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
345 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
346 for (i = 0; i < 10; i++)
347 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
348 wxAcceleratorTable accelTable (15, accelEntries);
350 wxAcceleratorTable accelTable (4, accelEntries);
353 SetAcceleratorTable (accelTable);
356 MainFrame::~MainFrame()
358 if (theApp->getConfig())
359 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
360 delete theApp->getDocManager();
364 MainFrame::OnSize (wxSizeEvent& event)
366 wxSize sizeClient = GetClientSize();
367 wxSize sizeLog = sizeClient;
368 if (sizeClient.y < 100) {
372 sizeLog.x = sizeClient.x;
375 sizeClient.x -= sizeLog.x;
376 sizeClient.y -= sizeLog.y;
377 // m_pLog->SetSize (0, sizeClient.y, sizeLog.x, sizeLog.y);
378 // GetClientWindow()->SetSize (0, 0, sizeClient.x, sizeClient.y);
379 // GetClientWindow()->Refresh();
381 wxDocMDIParentFrame::OnSize (event);
383 wxDocParentFrame::OnSize (event);
388 MainFrame::OnCreatePhantom(wxCommandEvent& event)
390 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
391 int dialogReturn = dialogPhantom.ShowModal();
392 if (dialogReturn == wxID_OK) {
393 wxString selection (dialogPhantom.getPhantom());
394 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
395 wxString filename = selection + ".phm";
396 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
397 theApp->getDocManager()->CreateDocument(filename, wxDOC_SILENT);
403 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
405 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
406 int dialogReturn = dialogFilter.ShowModal();
407 if (dialogReturn == wxID_OK) {
408 wxString strFilter (dialogFilter.getFilterName());
409 wxString strDomain (dialogFilter.getDomainName());
410 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
411 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
412 m_iDefaultFilterXSize = dialogFilter.getXSize();
413 m_iDefaultFilterYSize = dialogFilter.getYSize();
414 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
415 m_dDefaultFilterParam= dialogFilter.getFilterParam();
416 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
417 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
418 std::ostringstream os;
419 os << "Generate Filter=" << strFilter.c_str()
420 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
421 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
422 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
423 *theApp->getLog() << os.str().c_str() << "\n";
424 wxString filename = "untitled.if";
425 ImageFileDocument* pFilterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument ("untitled.if", wxDOC_SILENT));
427 sys_error (ERR_SEVERE, "Unable to create filter image");
430 ImageFile& rIF = pFilterDoc->getImageFile();
431 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
432 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
433 rIF.labelAdd (os.str().c_str());
434 if (theApp->getSetModifyNewDocs())
435 pFilterDoc->Modify (true);
436 pFilterDoc->UpdateAllViews();
437 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
442 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
444 const ImageFile& rIF = pIFDoc->getImageFile();
445 unsigned int nx = rIF.nx();
446 unsigned int ny = rIF.ny();
447 wxList& rListDocs = m_docManager->GetDocuments();
448 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
449 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
450 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
451 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
452 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
453 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
454 vecIF.push_back (pIFCompareDoc);
460 MainFrame::OnHelpTopics (wxCommandEvent& event)
462 showHelp (event.GetId());
466 MainFrame::OnHelpContents (wxCommandEvent& event)
468 showHelp (event.GetId());
471 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
473 MainFrame::OnHelpSecondary (wxCommandEvent& event)
475 m_htmlHelp.DisplayContents();
480 MainFrame::showHelp (int commandID)
483 m_winHelp.LoadFile();
485 m_htmlHelp.LoadFile();
490 case MAINMENU_HELP_CONTENTS:
492 m_winHelp.DisplayContents ();
494 m_htmlHelp.DisplayContents ();
498 case MAINMENU_HELP_TOPICS:
500 m_winHelp.DisplaySection (introduction);
502 m_htmlHelp.DisplayIndex();
507 *theApp->getLog() << "Unknown help command # " << commandID << "\n";
513 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
519 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
522 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
523 wxNode* pNode = rListDocs.GetFirst();
524 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
525 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
526 wxString strFilename = pDoc->GetFilename();
528 strFilename += "\tCtrl-";
529 strFilename += static_cast<char>('0' + iPos);
531 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
532 m_apWindowMenuData[iPos] = pDoc;
533 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
535 pNode = pNode->GetNext();
537 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
538 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
539 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
540 m_apWindowMenuData[i] = NULL;
545 #ifdef CTSIM_CUSTOM_MRU
547 MainFrame::OnMRUFile (wxCommandEvent& event)
549 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetSelection()));
551 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
556 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
558 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
559 wxString strFilename = pDoc->GetFilename();
560 const wxView* pView = pDoc->GetFirstView();
562 wxFrame* pFrame = pView->GetFrame();
569 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
570 { DoWindowMenu (0, event); }
572 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
573 { DoWindowMenu (1, event); }
575 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
576 { DoWindowMenu (2, event); }
578 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
579 { DoWindowMenu (3, event); }
581 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
582 { DoWindowMenu (4, event); }
584 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
585 { DoWindowMenu (5, event); }
587 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
588 { DoWindowMenu (6, event); }
590 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
591 { DoWindowMenu (7, event); }
593 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
594 { DoWindowMenu (8, event); }
596 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
597 { DoWindowMenu (9, event); }
599 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
600 { DoWindowMenu (10, event); }
602 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
603 { DoWindowMenu (11, event); }
605 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
606 { DoWindowMenu (12, event); }
608 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
609 { DoWindowMenu (13, event); }
611 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
612 { DoWindowMenu (14, event); }
614 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
615 { DoWindowMenu (15, event); }
617 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
618 { DoWindowMenu (16, event); }
620 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
621 { DoWindowMenu (17, event); }
623 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
624 { DoWindowMenu (18, event); }
626 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
627 { DoWindowMenu (19, event); }
630 class BitmapControl : public wxPanel
633 DECLARE_DYNAMIC_CLASS (BitmapControl)
634 DECLARE_EVENT_TABLE ()
638 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
639 const wxPoint& pos = wxDefaultPosition,
640 const wxSize& size = wxDefaultSize,
641 long style = wxSTATIC_BORDER,
642 const wxValidator& validator = wxDefaultValidator,
643 const wxString& name = "BitmapCtrl");
646 virtual ~BitmapControl();
648 virtual wxSize GetBestSize() const;
650 wxBitmap* getBitmap()
651 { return m_pBitmap; }
653 void OnPaint(wxPaintEvent& event);
657 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
658 EVT_PAINT(BitmapControl::OnPaint)
661 IMPLEMENT_CLASS(BitmapControl, wxPanel)
664 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
665 long style, const wxValidator& validator, const wxString& name)
668 Create(parent, id, pos, size, style, name);
670 SetSize (GetBestSize());
674 BitmapControl::GetBestSize () const
677 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
682 BitmapControl::~BitmapControl()
686 BitmapControl::OnPaint (wxPaintEvent& event)
690 dc.DrawBitmap (*m_pBitmap, 0, 0);
694 class BitmapDialog : public wxDialog {
696 BitmapControl* m_pBitmapCtrl;
699 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
700 virtual ~BitmapDialog();
703 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
704 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
706 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
708 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
710 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
711 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
712 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
714 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
716 SetAutoLayout (true);
717 SetSizer (pTopSizer);
718 pTopSizer->Fit (this);
719 pTopSizer->SetSizeHints (this);
722 BitmapDialog::~BitmapDialog()
726 #include "./splash.xpm"
728 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
730 wxBitmap bmp (splash);
732 BitmapDialog dlg (&bmp, "About CTSim");
735 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
740 #elif defined(VERSION)
741 msg << "Version: " << VERSION << "\n\n";
743 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
745 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);