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.66 2001/02/02 23:04:06 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.66 2001/02/02 23:04:06 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);
142 m_pDocTemplGraph3d = new wxDocTemplate (m_docManager, "Graph3dFile", "*.g3d", "", "g3d", "Graph3dFile", "Graph3dView", CLASSINFO(Graph3dFileDocument), CLASSINFO(Graph3dFileView), wxTEMPLATE_INVISIBLE);
146 wxImage::AddHandler(new wxGIFHandler); // Required for images in the online documentation
149 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
150 wxFileSystem::AddHandler(new wxZipFSHandler); // Required for advanced HTML help
153 // Create the main frame window
154 int xDisplay, yDisplay;
155 ::wxDisplaySize (&xDisplay, &yDisplay);
156 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0),
157 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .755)), wxDEFAULT_FRAME_STYLE);
159 setIconForFrame (m_pFrame);
160 m_pFrame->Centre(wxBOTH);
161 m_pFrame->Show(true);
162 SetTopWindow (m_pFrame);
164 for (int i = optind + 1; i <= argc; i++) {
165 wxString filename = argv [i - 1];
166 m_docManager->CreateDocument (filename, wxDOC_SILENT);
170 m_docManager->FileHistoryLoad(*m_pConfig);
174 m_pLogDoc = newTextDoc();
176 m_pLog = m_pLogDoc->getTextCtrl();
177 m_pLogDoc->SetDocumentName("Log.txt");
178 m_pLogDoc->SetFilename("Log.txt");
179 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
181 m_pFrame->GetClientSize(&xSize, &ySize);
182 int yLogSize = ySize / 4;
183 m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
184 m_pLogDoc->getView()->getFrame()->Show (true);
187 // wxMDIChildFrame *pLogFrame = new wxMDIChildFrame (m_pFrame, -1, "Log", wxDefaultPosition, wxSize(0,0), wxTHICK_FRAME, "Log");
188 m_pLog = new wxTextCtrl(m_pFrame->GetClientWindow(), -1, "", wxPoint(0,0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
190 m_pFrame->GetClientSize(&xSize, &ySize);
191 int yLogSize = ySize / 5;
192 m_pLog->SetSize (0, ySize - yLogSize, xSize, yLogSize);
194 m_pLog->Enable (true);
197 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
199 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
202 if (! m_pFrame->getWinHelpController().Initialize("ctsim"))
203 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
205 if (! m_pFrame->getHtmlHelpController().Initialize(::wxGetCwd() + "/ctsim"))
206 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
212 #include "./ctsim.xpm"
214 CTSimApp::setIconForFrame(wxFrame* pFrame)
216 wxIcon iconApp (ctsim16_xpm);
219 pFrame->SetIcon (iconApp);
223 CTSimApp::usage(const char* program)
225 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
226 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
228 std::cout << " --version Display version\n";
229 std::cout << " --help Display this help message\n";
242 CTSimApp::getUntitledFilename()
244 static int untitledNumber = 1;
246 wxString filename ("Untitled");
247 filename << untitledNumber++;
253 // Top-level window for CTSim
256 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
258 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
260 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
262 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
265 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
266 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
267 EVT_MENU(MAINMENU_HELP_TOPICS, MainFrame::OnHelpTopics)
268 EVT_SIZE(MainFrame::OnSize)
270 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
271 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
273 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
274 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
275 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
276 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
277 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
278 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
279 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
280 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
281 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
282 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
283 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
284 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
285 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
286 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
287 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
288 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
289 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
290 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
291 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
292 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
293 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
294 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
295 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
296 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
297 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
303 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
304 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
306 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
307 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
310 m_bShuttingDown = false;
313 wxMenu *file_menu = new wxMenu;
315 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
316 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
317 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
319 file_menu->AppendSeparator();
320 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
322 // history of files visited
323 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
324 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
327 m_pWindowMenu = new wxMenu;
328 m_pWindowMenu->UpdateUI (this);
331 wxMenu* help_menu = new wxMenu;
332 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
333 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-T");
334 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
335 help_menu->Append(MAINMENU_HELP_SECONDARY, "&Secondary Help");
337 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
339 wxMenuBar* menu_bar = new wxMenuBar;
341 menu_bar->Append(file_menu, "&File");
343 menu_bar->Append(m_pWindowMenu, "&Window");
345 menu_bar->Append(help_menu, "&Help");
347 SetMenuBar(menu_bar);
351 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
352 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
353 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
354 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
358 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
359 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
360 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
361 m_iDefaultFilterXSize = 256;
362 m_iDefaultFilterYSize = 256;
363 m_dDefaultFilterParam = 1.;
364 m_dDefaultFilterBandwidth = 1.;
365 m_dDefaultFilterInputScale = 1.;
366 m_dDefaultFilterOutputScale = 1.;
368 wxAcceleratorEntry accelEntries[15];
369 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
370 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
371 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
372 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
374 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
375 for (i = 0; i < 10; i++)
376 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
377 wxAcceleratorTable accelTable (15, accelEntries);
379 wxAcceleratorTable accelTable (4, accelEntries);
382 SetAcceleratorTable (accelTable);
385 MainFrame::~MainFrame()
387 m_bShuttingDown = true; // Currently used so that Log Window will close
389 // delete all non-modified documents
390 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
391 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
392 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
393 if (pDoc && ! pDoc->IsModified()) {
394 theApp->getDocManager()->RemoveDocument(pDoc);
400 if (theApp->getConfig())
401 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
403 delete theApp->getDocManager();
408 MainFrame::OnSize (wxSizeEvent& event)
411 if (theApp->getLogDoc()) {
413 GetClientSize(&xSize, &ySize);
414 int yLogSize = ySize / 4;
415 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
416 theApp->getLogDoc()->getView()->getFrame()->Show (true);
421 wxDocMDIParentFrame::OnSize (event);
423 wxDocParentFrame::OnSize (event);
428 MainFrame::OnCreatePhantom(wxCommandEvent& event)
430 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
431 int dialogReturn = dialogPhantom.ShowModal();
432 if (dialogReturn == wxID_OK) {
433 wxString selection (dialogPhantom.getPhantom());
434 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
435 wxString filename = selection + ".phm";
436 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
437 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
443 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
445 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
446 int dialogReturn = dialogFilter.ShowModal();
447 if (dialogReturn == wxID_OK) {
448 wxString strFilter (dialogFilter.getFilterName());
449 wxString strDomain (dialogFilter.getDomainName());
450 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
451 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
452 m_iDefaultFilterXSize = dialogFilter.getXSize();
453 m_iDefaultFilterYSize = dialogFilter.getYSize();
454 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
455 m_dDefaultFilterParam= dialogFilter.getFilterParam();
456 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
457 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
458 std::ostringstream os;
459 os << "Generate Filter=" << strFilter.c_str()
460 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
461 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
462 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
463 *theApp->getLog() << os.str().c_str() << "\n";
464 wxString filename = "untitled.if";
465 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
466 pFilterDoc->setBadFileOpen();
468 sys_error (ERR_SEVERE, "Unable to create filter image");
471 ImageFile& rIF = pFilterDoc->getImageFile();
472 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
473 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
474 rIF.labelAdd (os.str().c_str());
475 pFilterDoc->Modify (true);
476 pFilterDoc->UpdateAllViews();
477 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
478 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
479 pFilterDoc->getView()->getFrame()->Show(true);
484 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
486 const ImageFile& rIF = pIFDoc->getImageFile();
487 unsigned int nx = rIF.nx();
488 unsigned int ny = rIF.ny();
489 wxList& rListDocs = m_docManager->GetDocuments();
490 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
491 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
492 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
493 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
494 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
495 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
496 vecIF.push_back (pIFCompareDoc);
502 MainFrame::OnHelpTopics (wxCommandEvent& event)
504 showHelp (event.GetId());
508 MainFrame::OnHelpContents (wxCommandEvent& event)
510 showHelp (event.GetId());
513 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
515 MainFrame::OnHelpSecondary (wxCommandEvent& event)
517 m_htmlHelp.DisplayContents();
522 MainFrame::showHelp (int commandID)
525 m_winHelp.LoadFile();
527 m_htmlHelp.LoadFile();
532 case MAINMENU_HELP_CONTENTS:
534 m_winHelp.DisplayContents ();
536 m_htmlHelp.DisplayContents ();
540 case MAINMENU_HELP_TOPICS:
542 m_winHelp.DisplaySection (introduction);
544 m_htmlHelp.DisplayIndex();
549 *theApp->getLog() << "Unknown help command # " << commandID << "\n";
555 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
561 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
565 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
566 wxNode* pNode = rListDocs.GetFirst();
567 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
568 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
569 wxString strFilename = pDoc->GetFilename();
571 strFilename += "\tCtrl-";
572 strFilename += static_cast<char>('0' + iPos);
574 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
575 m_apWindowMenuData[iPos] = pDoc;
576 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
578 pNode = pNode->GetNext();
580 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
581 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
582 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
583 m_apWindowMenuData[i] = NULL;
588 #ifdef CTSIM_CUSTOM_MRU
590 MainFrame::OnMRUFile (wxCommandEvent& event)
592 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
594 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
599 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
601 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
602 wxString strFilename = pDoc->GetFilename();
603 const wxView* pView = pDoc->GetFirstView();
605 wxFrame* pFrame = pView->GetFrame();
612 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
613 { DoWindowMenu (0, event); }
615 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
616 { DoWindowMenu (1, event); }
618 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
619 { DoWindowMenu (2, event); }
621 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
622 { DoWindowMenu (3, event); }
624 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
625 { DoWindowMenu (4, event); }
627 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
628 { DoWindowMenu (5, event); }
630 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
631 { DoWindowMenu (6, event); }
633 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
634 { DoWindowMenu (7, event); }
636 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
637 { DoWindowMenu (8, event); }
639 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
640 { DoWindowMenu (9, event); }
642 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
643 { DoWindowMenu (10, event); }
645 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
646 { DoWindowMenu (11, event); }
648 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
649 { DoWindowMenu (12, event); }
651 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
652 { DoWindowMenu (13, event); }
654 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
655 { DoWindowMenu (14, event); }
657 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
658 { DoWindowMenu (15, event); }
660 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
661 { DoWindowMenu (16, event); }
663 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
664 { DoWindowMenu (17, event); }
666 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
667 { DoWindowMenu (18, event); }
669 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
670 { DoWindowMenu (19, event); }
673 class BitmapControl : public wxPanel
676 DECLARE_DYNAMIC_CLASS (BitmapControl)
677 DECLARE_EVENT_TABLE ()
681 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
682 const wxPoint& pos = wxDefaultPosition,
683 const wxSize& size = wxDefaultSize,
684 long style = wxSTATIC_BORDER,
685 const wxValidator& validator = wxDefaultValidator,
686 const wxString& name = "BitmapCtrl");
689 virtual ~BitmapControl();
691 virtual wxSize GetBestSize() const;
693 wxBitmap* getBitmap()
694 { return m_pBitmap; }
696 void OnPaint(wxPaintEvent& event);
700 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
701 EVT_PAINT(BitmapControl::OnPaint)
704 IMPLEMENT_CLASS(BitmapControl, wxPanel)
707 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
708 long style, const wxValidator& validator, const wxString& name)
711 Create(parent, id, pos, size, style, name);
713 SetSize (GetBestSize());
717 BitmapControl::GetBestSize () const
720 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
725 BitmapControl::~BitmapControl()
729 BitmapControl::OnPaint (wxPaintEvent& event)
733 dc.DrawBitmap (*m_pBitmap, 0, 0);
737 class BitmapDialog : public wxDialog {
739 BitmapControl* m_pBitmapCtrl;
742 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
743 virtual ~BitmapDialog();
746 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
747 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
749 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
751 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
753 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
754 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
755 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
757 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
759 SetAutoLayout (true);
760 SetSizer (pTopSizer);
761 pTopSizer->Fit (this);
762 pTopSizer->SetSizeHints (this);
765 BitmapDialog::~BitmapDialog()
769 #include "./splash.xpm"
771 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
773 wxBitmap bmp (splash);
775 BitmapDialog dlg (&bmp, "About CTSim");
778 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
783 #elif defined(VERSION)
784 msg << "Version: " << VERSION << "\n\n";
786 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
788 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
793 ProjectionFileDocument*
794 CTSimApp::newProjectionDoc()
796 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
798 ProjectionFileView* pView = newDoc->getView();
800 wxFrame* pFrame = pView->getFrame();
802 pFrame->SetSize (0,0);
803 pFrame->Show (false);
806 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
807 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
808 newDoc->OnNewDocument();
815 CTSimApp::newImageDoc()
817 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
819 ImageFileView* pView = newDoc->getView();
821 wxFrame* pFrame = pView->getFrame();
823 pFrame->SetSize (0,0);
824 pFrame->Show (false);
827 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
828 newDoc->SetDocumentTemplate (m_pDocTemplImage);
829 newDoc->OnNewDocument();
836 CTSimApp::newPlotDoc()
838 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
840 PlotFileView* pView = newDoc->getView();
842 wxFrame* pFrame = pView->getFrame();
845 m_pFrame->GetClientSize (&size.x, &size.y);
846 pFrame->SetSize (size.x / 2, size.y / 2);
847 pFrame->Show (false);
850 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
851 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
852 newDoc->OnNewDocument();
860 CTSimApp::newTextDoc()
862 wxString strFilename (getUntitledFilename());
863 strFilename += ".txt";
865 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
867 TextFileView* pView = newDoc->getView();
869 wxFrame* pFrame = pView->getFrame();
872 m_pFrame->GetClientSize (&size.x, &size.y);;
873 pFrame->SetSize (size.x / 2, size.y / 2);
874 pFrame->Show (false);
877 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
878 newDoc->SetDocumentTemplate (m_pDocTemplText);
879 newDoc->OnNewDocument();
887 CTSimApp::newPhantomDoc()
889 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
891 PhantomFileView* pView = newDoc->getView();
893 wxFrame* pFrame = pView->getFrame();
895 pFrame->SetSize (0,0);
897 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
898 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
899 newDoc->OnNewDocument();
908 CTSimApp::newGraph3dDoc()
910 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
912 Graph3dFileView* pView = newDoc->getView();
914 wxFrame* pFrame = pView->getFrame();
916 pFrame->SetSize (0,0);
918 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
919 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
920 newDoc->OnNewDocument();