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.84 2001/02/21 00:34:12 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 #include "wx/msw/helpchm.h"
50 #if !wxUSE_DOC_VIEW_ARCHITECTURE
51 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
61 #if defined(HAVE_CONFIG_H)
65 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
75 static const char* rcsindent = "$Id: ctsim.cpp,v 1.84 2001/02/21 00:34:12 kevin Exp $";
77 struct option CTSimApp::ctsimOptions[] =
79 {"help", 0, 0, O_HELP},
80 {"version", 0, 0, O_VERSION},
81 {"print", 0, 0, O_PRINT},
85 IMPLEMENT_APP(CTSimApp)
88 : m_bAdvancedOptions(false), m_bSetModifyNewDocs(true),
89 m_docManager(NULL), m_pFrame(NULL), m_pLog(0), m_pLogDoc(0), m_pConfig(0)
94 #ifdef HAVE_SYS_TIME_H
98 #ifdef HAVE_SYS_RESOURCE_H
99 #include <sys/resource.h>
105 #ifdef HAVE_SETPRIORITY
106 setpriority (PRIO_PROCESS, 0, 15); // set to low scheduling priority
111 g_bRunningWXWindows = true;
112 bool bPrintFiles = false;
115 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
121 std::cout << rcsindent << std::endl;
123 std::cout << "Version: CTSIMVERSION" << std::endl;
124 #elif defined(VERSION)
125 std::cout << "Version: VERSION" << std::endl;
141 m_docManager = new wxDocManager (wxDEFAULT_DOCMAN_FLAGS, true);
143 m_pDocTemplImage = new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile", "ImageView", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
144 m_pDocTemplProjection = new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile", "ProjectionView", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
145 m_pDocTemplPhantom = new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "PhantomFile", "PhantomView", CLASSINFO(PhantomFileDocument), CLASSINFO(PhantomFileView));
146 m_pDocTemplPlot = new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "PlotFile", "PlotView", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
147 m_pDocTemplText = new wxDocTemplate (m_docManager, "TextFile", "*.txt", "", "txt", "TextFile", "TextView", CLASSINFO(TextFileDocument), CLASSINFO(TextFileView), wxTEMPLATE_INVISIBLE);
149 m_pDocTemplGraph3d = new wxDocTemplate (m_docManager, "Graph3dFile", "*.g3d", "", "g3d", "Graph3dFile", "Graph3dView", CLASSINFO(Graph3dFileDocument), CLASSINFO(Graph3dFileView), wxTEMPLATE_INVISIBLE);
153 wxImage::AddHandler(new wxGIFHandler); // Required for images in the online documentation
156 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
157 wxFileSystem::AddHandler(new wxZipFSHandler); // Required for advanced HTML help
160 // Create the main frame window
161 int xDisplay, yDisplay;
162 ::wxDisplaySize (&xDisplay, &yDisplay);
163 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0),
164 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .755)), wxDEFAULT_FRAME_STYLE);
166 setIconForFrame (m_pFrame);
167 m_pFrame->Centre(wxBOTH);
168 m_pFrame->Show(true);
169 SetTopWindow (m_pFrame);
172 m_docManager->FileHistoryLoad(*m_pConfig);
175 m_pLogDoc = newTextDoc();
177 m_pLog = m_pLogDoc->getTextCtrl();
178 m_pLogDoc->SetDocumentName("Log.txt");
179 m_pLogDoc->SetFilename("Log.txt");
180 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
182 m_pFrame->GetClientSize(&xSize, &ySize);
183 int yLogSize = ySize / 4;
184 m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
185 m_pLogDoc->getView()->getFrame()->Show (true);
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));
193 if (! m_pConfig->Read("HelpDir", &helpDir))
194 helpDir = ::wxGetCwd();
196 if (! m_pFrame->getWinHelpController().Initialize(helpDir + "/ctsim"))
197 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
199 if (! m_pFrame->getHtmlHelpController().Initialize(helpDir + "/ctsim") &&
200 ! m_pFrame->getHtmlHelpController().Initialize("/usr/local/man/ctsim"))
201 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
203 if (::wxDirExists ("/tmp"))
204 m_pFrame->getHtmlHelpController().SetTempDir(_T("/tmp"));
205 m_pFrame->getHtmlHelpController().UseConfig (m_pConfig);
209 for (int i = optind + 1; i <= argc; i++) {
210 wxString filename = argv [i - 1];
211 wxDocument* pNewDoc = m_docManager->CreateDocument (filename, wxDOC_SILENT);
213 wxView* pNewView = pNewDoc->GetFirstView();
214 wxPrintout *printout = pNewView->OnCreatePrintout();
217 printer.Print(pNewView->GetFrame(), printout, TRUE);
220 wxCommandEvent nullEvent;
221 nullEvent.SetId (wxID_CLOSE);
222 m_docManager->OnFileClose (nullEvent);
226 wxCommandEvent closeEvent;
227 closeEvent.SetInt (MAINMENU_FILE_EXIT);
228 m_pFrame->AddPendingEvent(closeEvent);
236 #include "./ctsim.xpm"
238 CTSimApp::setIconForFrame(wxFrame* pFrame)
240 wxIcon iconApp (ctsim16_xpm);
243 pFrame->SetIcon (iconApp);
247 CTSimApp::usage(const char* program)
249 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
250 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
252 std::cout << " --version Display version\n";
253 std::cout << " --help Display this help message\n";
268 CTSimApp::openConfig()
271 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", "", "", wxCONFIG_USE_LOCAL_FILE);
273 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", ".ctsim", "", wxCONFIG_USE_LOCAL_FILE);
276 wxConfigBase::Set(m_pConfig);
277 m_pConfig->Read ("AdvancedOptions", &m_bAdvancedOptions);
278 m_pConfig->Read ("SetModifyNewDocs", &m_bSetModifyNewDocs);
282 CTSimApp::closeConfig()
284 m_pConfig->Write ("AdvancedOptions", m_bAdvancedOptions);
285 m_pConfig->Write ("SetModifyNewDocs", m_bSetModifyNewDocs);
291 CTSimApp::getUntitledFilename()
293 static int untitledNumber = 1;
295 wxString filename ("Untitled");
296 filename << untitledNumber++;
302 // Top-level window for CTSim
305 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
307 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
309 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
311 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
314 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
315 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
316 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
317 EVT_MENU(IDH_QUICKSTART, MainFrame::OnHelpButton)
318 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
319 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
320 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
321 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
322 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
323 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
324 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
325 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
326 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
327 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
328 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
330 EVT_SIZE(MainFrame::OnSize)
332 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
333 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
335 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
336 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
337 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
338 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
339 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
340 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
341 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
342 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
343 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
344 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
345 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
346 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
347 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
348 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
349 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
350 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
351 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
352 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
353 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
354 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
355 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
356 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
357 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
358 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
359 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
365 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
366 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
368 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
369 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
372 m_bShuttingDown = false;
375 wxMenu *file_menu = new wxMenu;
377 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
378 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
379 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
381 file_menu->AppendSeparator();
382 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
383 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
385 // history of files visited
386 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
387 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
390 m_pWindowMenu = new wxMenu;
391 m_pWindowMenu->UpdateUI (this);
394 wxMenu* help_menu = new wxMenu;
395 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
397 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
398 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
399 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
401 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
403 wxMenuBar* menu_bar = new wxMenuBar;
405 menu_bar->Append(file_menu, "&File");
407 menu_bar->Append(m_pWindowMenu, "&Window");
409 menu_bar->Append(help_menu, "&Help");
411 SetMenuBar(menu_bar);
415 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
416 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
417 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
418 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
422 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
423 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
424 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
425 m_iDefaultFilterXSize = 256;
426 m_iDefaultFilterYSize = 256;
427 m_dDefaultFilterParam = 1.;
428 m_dDefaultFilterBandwidth = 1.;
429 m_dDefaultFilterInputScale = 1.;
430 m_dDefaultFilterOutputScale = 1.;
432 wxAcceleratorEntry accelEntries[15];
433 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
434 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
435 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
436 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
438 for (i = 0; i < 10; i++)
439 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
440 wxAcceleratorTable accelTable (15, accelEntries);
442 wxAcceleratorTable accelTable (5, accelEntries);
445 SetAcceleratorTable (accelTable);
448 MainFrame::~MainFrame()
450 m_bShuttingDown = true; // Currently used so that Log Window will close
452 // delete all non-modified documents
453 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
454 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
455 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
456 if (pDoc && ! pDoc->IsModified()) {
457 theApp->getDocManager()->RemoveDocument(pDoc);
463 if (theApp->getConfig())
464 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
466 delete theApp->getDocManager();
471 MainFrame::OnSize (wxSizeEvent& event)
474 if (theApp->getLogDoc()) {
476 GetClientSize(&xSize, &ySize);
477 int yLogSize = ySize / 4;
478 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
479 theApp->getLogDoc()->getView()->getFrame()->Show (true);
484 wxDocMDIParentFrame::OnSize (event);
486 wxDocParentFrame::OnSize (event);
491 MainFrame::OnCreatePhantom(wxCommandEvent& event)
493 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
494 int dialogReturn = dialogPhantom.ShowModal();
495 if (dialogReturn == wxID_OK) {
496 wxString selection (dialogPhantom.getPhantom());
497 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
498 wxString filename = selection + ".phm";
499 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
500 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
506 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
508 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
509 int dialogReturn = dialogFilter.ShowModal();
510 if (dialogReturn == wxID_OK) {
511 wxString strFilter (dialogFilter.getFilterName());
512 wxString strDomain (dialogFilter.getDomainName());
513 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
514 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
515 m_iDefaultFilterXSize = dialogFilter.getXSize();
516 m_iDefaultFilterYSize = dialogFilter.getYSize();
517 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
518 m_dDefaultFilterParam= dialogFilter.getFilterParam();
519 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
520 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
521 std::ostringstream os;
522 os << "Generate Filter=" << strFilter.c_str()
523 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
524 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
525 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
526 *theApp->getLog() << os.str().c_str() << "\n";
527 wxString filename = "untitled.if";
528 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
529 pFilterDoc->setBadFileOpen();
531 sys_error (ERR_SEVERE, "Unable to create filter image");
534 ImageFile& rIF = pFilterDoc->getImageFile();
535 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
536 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
537 rIF.labelAdd (os.str().c_str());
538 pFilterDoc->Modify (true);
539 pFilterDoc->UpdateAllViews();
540 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
541 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
542 pFilterDoc->getView()->getFrame()->Show(true);
547 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
549 const ImageFile& rIF = pIFDoc->getImageFile();
550 unsigned int nx = rIF.nx();
551 unsigned int ny = rIF.ny();
552 wxList& rListDocs = m_docManager->GetDocuments();
553 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
554 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
555 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
556 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
557 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
558 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
559 vecIF.push_back (pIFCompareDoc);
566 MainFrame::OnHelpContents (wxCommandEvent& event)
568 showHelp (event.GetId());
572 MainFrame::OnHelpButton (wxCommandEvent& event)
574 showHelp (event.GetId());
577 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
579 MainFrame::OnHelpSecondary (wxCommandEvent& event)
581 m_htmlHelp.DisplayContents();
586 MainFrame::showHelp (int commandID)
590 case MAINMENU_HELP_CONTENTS:
592 m_winHelp.DisplayContents ();
594 m_htmlHelp.DisplayContents ();
601 m_winHelp.DisplaySection (commandID);
603 m_htmlHelp.Display (commandID);
610 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
616 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
620 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
621 wxNode* pNode = rListDocs.GetFirst();
622 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
623 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
624 wxString strFilename = pDoc->GetFilename();
626 strFilename += "\tCtrl-";
627 strFilename += static_cast<char>('0' + iPos);
629 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
630 m_apWindowMenuData[iPos] = pDoc;
631 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
633 pNode = pNode->GetNext();
635 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
636 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
637 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
638 m_apWindowMenuData[i] = NULL;
643 #ifdef CTSIM_CUSTOM_MRU
645 MainFrame::OnMRUFile (wxCommandEvent& event)
647 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
649 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
654 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
656 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
657 wxString strFilename = pDoc->GetFilename();
658 const wxView* pView = pDoc->GetFirstView();
660 wxFrame* pFrame = pView->GetFrame();
667 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
668 { DoWindowMenu (0, event); }
670 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
671 { DoWindowMenu (1, event); }
673 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
674 { DoWindowMenu (2, event); }
676 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
677 { DoWindowMenu (3, event); }
679 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
680 { DoWindowMenu (4, event); }
682 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
683 { DoWindowMenu (5, event); }
685 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
686 { DoWindowMenu (6, event); }
688 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
689 { DoWindowMenu (7, event); }
691 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
692 { DoWindowMenu (8, event); }
694 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
695 { DoWindowMenu (9, event); }
697 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
698 { DoWindowMenu (10, event); }
700 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
701 { DoWindowMenu (11, event); }
703 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
704 { DoWindowMenu (12, event); }
706 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
707 { DoWindowMenu (13, event); }
709 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
710 { DoWindowMenu (14, event); }
712 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
713 { DoWindowMenu (15, event); }
715 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
716 { DoWindowMenu (16, event); }
718 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
719 { DoWindowMenu (17, event); }
721 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
722 { DoWindowMenu (18, event); }
724 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
725 { DoWindowMenu (19, event); }
728 class BitmapControl : public wxPanel
731 DECLARE_DYNAMIC_CLASS (BitmapControl)
732 DECLARE_EVENT_TABLE ()
736 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
737 const wxPoint& pos = wxDefaultPosition,
738 const wxSize& size = wxDefaultSize,
739 long style = wxSTATIC_BORDER,
740 const wxValidator& validator = wxDefaultValidator,
741 const wxString& name = "BitmapCtrl");
744 virtual ~BitmapControl();
746 virtual wxSize GetBestSize() const;
748 wxBitmap* getBitmap()
749 { return m_pBitmap; }
751 void OnPaint(wxPaintEvent& event);
755 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
756 EVT_PAINT(BitmapControl::OnPaint)
759 IMPLEMENT_CLASS(BitmapControl, wxPanel)
762 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
763 long style, const wxValidator& validator, const wxString& name)
766 Create(parent, id, pos, size, style, name);
768 SetSize (GetBestSize());
772 BitmapControl::GetBestSize () const
775 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
780 BitmapControl::~BitmapControl()
784 BitmapControl::OnPaint (wxPaintEvent& event)
788 dc.DrawBitmap (*m_pBitmap, 0, 0);
792 class BitmapDialog : public wxDialog {
794 BitmapControl* m_pBitmapCtrl;
797 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
798 virtual ~BitmapDialog();
801 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
802 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
804 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
806 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
808 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
809 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
810 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
812 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
814 SetAutoLayout (true);
815 SetSizer (pTopSizer);
816 pTopSizer->Fit (this);
817 pTopSizer->SetSizeHints (this);
820 BitmapDialog::~BitmapDialog()
825 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
827 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
828 theApp->getAskDeleteNewDocs());
829 if (dlg.ShowModal() == wxID_OK) {
830 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
831 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
836 #include "./splash.xpm"
838 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
840 wxBitmap bmp (splash);
842 BitmapDialog dlg (&bmp, "About CTSim");
845 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
850 #elif defined(VERSION)
851 msg << "Version: " << VERSION << "\n\n";
853 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
855 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
860 ProjectionFileDocument*
861 CTSimApp::newProjectionDoc()
863 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
865 ProjectionFileView* pView = newDoc->getView();
867 wxFrame* pFrame = pView->getFrame();
869 pFrame->SetSize (0,0);
870 pFrame->Show (false);
873 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
874 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
875 newDoc->OnNewDocument();
882 CTSimApp::newImageDoc()
884 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
886 ImageFileView* pView = newDoc->getView();
888 wxFrame* pFrame = pView->getFrame();
890 pFrame->SetSize (0,0);
891 pFrame->Show (false);
894 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
895 newDoc->SetDocumentTemplate (m_pDocTemplImage);
896 newDoc->OnNewDocument();
903 CTSimApp::newPlotDoc()
905 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
907 PlotFileView* pView = newDoc->getView();
909 wxFrame* pFrame = pView->getFrame();
912 m_pFrame->GetClientSize (&size.x, &size.y);
913 pFrame->SetSize (size.x / 2, size.y / 2);
914 pFrame->Show (false);
917 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
918 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
919 newDoc->OnNewDocument();
927 CTSimApp::newTextDoc()
929 wxString strFilename (getUntitledFilename());
930 strFilename += ".txt";
932 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
934 TextFileView* pView = newDoc->getView();
936 wxFrame* pFrame = pView->getFrame();
939 m_pFrame->GetClientSize (&size.x, &size.y);;
940 pFrame->SetSize (size.x / 2, size.y / 2);
941 pFrame->Show (false);
944 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
945 newDoc->SetDocumentTemplate (m_pDocTemplText);
946 newDoc->OnNewDocument();
954 CTSimApp::newPhantomDoc()
956 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
958 PhantomFileView* pView = newDoc->getView();
960 wxFrame* pFrame = pView->getFrame();
962 pFrame->SetSize (0,0);
964 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
965 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
966 newDoc->OnNewDocument();
975 CTSimApp::newGraph3dDoc()
977 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
979 Graph3dFileView* pView = newDoc->getView();
981 wxFrame* pFrame = pView->getFrame();
983 pFrame->SetSize (0,0);
985 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
986 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
987 newDoc->OnNewDocument();