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-2001 Kevin Rosenberg
12 ** $Id: ctsim.cpp,v 1.87 2001/02/22 11:05:38 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 #include "wx/wxprec.h"
39 #include "wx/filesys.h"
40 #include "wx/fs_zip.h"
42 #include "wx/msw/helpchm.h"
45 #if !wxUSE_DOC_VIEW_ARCHITECTURE
46 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
57 #if defined(HAVE_CONFIG_H)
61 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
71 static const char* rcsindent = "$Id: ctsim.cpp,v 1.87 2001/02/22 11:05:38 kevin Exp $";
73 struct option CTSimApp::ctsimOptions[] =
75 {"help", 0, 0, O_HELP},
76 {"version", 0, 0, O_VERSION},
77 {"print", 0, 0, O_PRINT},
81 IMPLEMENT_APP(CTSimApp)
84 : m_bAdvancedOptions(false), m_bSetModifyNewDocs(true), m_bVerboseLogging(false), m_bShowStartupTips(true),
86 m_docManager(NULL), m_pFrame(NULL), m_pLog(0), m_pLogDoc(0), m_pConfig(0)
91 #ifdef HAVE_SYS_TIME_H
95 #ifdef HAVE_SYS_RESOURCE_H
96 #include <sys/resource.h>
102 #ifdef HAVE_SETPRIORITY
103 setpriority (PRIO_PROCESS, 0, 15); // set to low scheduling priority
108 g_bRunningWXWindows = true;
109 bool bPrintFiles = false;
112 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
118 std::cout << rcsindent << std::endl;
120 std::cout << "Version: CTSIMVERSION" << std::endl;
121 #elif defined(VERSION)
122 std::cout << "Version: VERSION" << std::endl;
138 m_docManager = new wxDocManager (wxDEFAULT_DOCMAN_FLAGS, true);
140 m_pDocTemplImage = new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile", "ImageView", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
141 m_pDocTemplProjection = new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile", "ProjectionView", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
142 m_pDocTemplPhantom = new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "PhantomFile", "PhantomView", CLASSINFO(PhantomFileDocument), CLASSINFO(PhantomFileView));
143 m_pDocTemplPlot = new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "PlotFile", "PlotView", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
144 m_pDocTemplText = new wxDocTemplate (m_docManager, "TextFile", "*.txt", "", "txt", "TextFile", "TextView", CLASSINFO(TextFileDocument), CLASSINFO(TextFileView), wxTEMPLATE_INVISIBLE);
146 m_pDocTemplGraph3d = new wxDocTemplate (m_docManager, "Graph3dFile", "*.g3d", "", "g3d", "Graph3dFile", "Graph3dView", CLASSINFO(Graph3dFileDocument), CLASSINFO(Graph3dFileView), wxTEMPLATE_INVISIBLE);
150 wxImage::AddHandler(new wxGIFHandler); // Required for images in the online documentation
153 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
154 wxFileSystem::AddHandler(new wxZipFSHandler); // Required for advanced HTML help
157 // Create the main frame window
158 int xDisplay, yDisplay;
159 ::wxDisplaySize (&xDisplay, &yDisplay);
160 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0),
161 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .755)), wxDEFAULT_FRAME_STYLE);
163 setIconForFrame (m_pFrame);
164 m_pFrame->Centre(wxBOTH);
165 m_pFrame->Show(true);
166 SetTopWindow (m_pFrame);
169 m_docManager->FileHistoryLoad(*m_pConfig);
172 m_pLogDoc = newTextDoc();
174 m_pLog = m_pLogDoc->getTextCtrl();
175 m_pLogDoc->SetDocumentName("Log.txt");
176 m_pLogDoc->SetFilename("Log.txt");
177 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
179 m_pFrame->GetClientSize(&xSize, &ySize);
180 int yLogSize = ySize / 4;
181 m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
182 m_pLogDoc->getView()->getFrame()->Show (true);
185 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
187 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
190 if (! m_pConfig->Read("HelpDir", &helpDir))
191 helpDir = ::wxGetCwd();
193 if (! m_pFrame->getWinHelpController().Initialize(helpDir + "/ctsim"))
194 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
196 if (! m_pFrame->getHtmlHelpController().Initialize(helpDir + "/ctsim") &&
197 ! m_pFrame->getHtmlHelpController().Initialize("/usr/local/man/ctsim"))
198 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
200 if (::wxDirExists ("/tmp"))
201 m_pFrame->getHtmlHelpController().SetTempDir(_T("/tmp"));
202 m_pFrame->getHtmlHelpController().UseConfig (m_pConfig);
206 for (int i = optind + 1; i <= argc; i++) {
207 wxString filename = argv [i - 1];
208 wxDocument* pNewDoc = m_docManager->CreateDocument (filename, wxDOC_SILENT);
210 wxView* pNewView = pNewDoc->GetFirstView();
211 wxPrintout *printout = pNewView->OnCreatePrintout();
214 printer.Print(pNewView->GetFrame(), printout, TRUE);
217 wxCommandEvent nullEvent;
218 nullEvent.SetId (wxID_CLOSE);
219 m_docManager->OnFileClose (nullEvent);
223 wxCommandEvent closeEvent;
224 closeEvent.SetInt (MAINMENU_FILE_EXIT);
225 m_pFrame->AddPendingEvent(closeEvent);
228 if (getStartupTips())
237 CTSimTipProvider tipProvider (m_iCurrentTip);
238 setStartupTips (::wxShowTip (m_pFrame, &tipProvider, getStartupTips()));
239 m_iCurrentTip = tipProvider.GetCurrentTip();
243 #include "./ctsim.xpm"
245 CTSimApp::setIconForFrame(wxFrame* pFrame)
247 wxIcon iconApp (ctsim16_xpm);
250 pFrame->SetIcon (iconApp);
254 CTSimApp::usage(const char* program)
256 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
257 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
259 std::cout << " --version Display version\n";
260 std::cout << " --help Display this help message\n";
275 CTSimApp::openConfig()
278 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", "", "", wxCONFIG_USE_LOCAL_FILE);
280 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", ".ctsim", "", wxCONFIG_USE_LOCAL_FILE);
283 wxConfigBase::Set(m_pConfig);
284 m_pConfig->Read ("AdvancedOptions", &m_bAdvancedOptions);
285 m_pConfig->Read ("SetModifyNewDocs", &m_bSetModifyNewDocs);
286 m_pConfig->Read ("VerboseLogging", &m_bVerboseLogging);
287 m_pConfig->Read ("StartupTips", &m_bShowStartupTips);
288 m_pConfig->Read ("CurrentTip", &m_iCurrentTip);
292 CTSimApp::closeConfig()
294 m_pConfig->Write ("AdvancedOptions", m_bAdvancedOptions);
295 m_pConfig->Write ("SetModifyNewDocs", m_bSetModifyNewDocs);
296 m_pConfig->Write ("VerboseLogging", m_bVerboseLogging);
297 m_pConfig->Write ("StartupTips", m_bShowStartupTips);
298 m_pConfig->Write ("CurrentTip", m_iCurrentTip);
305 CTSimApp::getUntitledFilename()
307 static int untitledNumber = 1;
309 wxString filename ("Untitled");
310 filename << untitledNumber++;
316 // Top-level window for CTSim
319 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
321 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
323 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
325 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
328 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
329 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
330 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
331 EVT_MENU(MAINMENU_HELP_TIPS, MainFrame::OnHelpTips)
332 EVT_MENU(IDH_QUICKSTART, MainFrame::OnHelpButton)
333 EVT_MENU(MAINMENU_LOG_EVENT, MainFrame::OnLogEvent)
334 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
335 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
336 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
337 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
338 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
339 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
340 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
341 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
342 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
343 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
344 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
346 EVT_SIZE(MainFrame::OnSize)
348 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
349 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
351 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
352 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
353 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
354 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
355 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
356 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
357 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
358 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
359 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
360 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
361 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
362 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
363 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
364 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
365 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
366 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
367 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
368 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
369 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
370 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
371 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
372 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
373 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
374 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
375 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
381 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
382 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
384 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
385 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
388 m_bShuttingDown = false;
391 wxMenu *file_menu = new wxMenu;
393 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
394 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
395 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
397 file_menu->AppendSeparator();
398 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
399 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
401 // history of files visited
402 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
403 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
406 m_pWindowMenu = new wxMenu;
407 m_pWindowMenu->UpdateUI (this);
410 wxMenu* help_menu = new wxMenu;
411 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
412 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
413 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
414 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
415 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
417 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
419 wxMenuBar* menu_bar = new wxMenuBar;
421 menu_bar->Append(file_menu, "&File");
423 menu_bar->Append(m_pWindowMenu, "&Window");
425 menu_bar->Append(help_menu, "&Help");
427 SetMenuBar(menu_bar);
431 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
432 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
433 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
434 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
438 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
439 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
440 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
441 m_iDefaultFilterXSize = 256;
442 m_iDefaultFilterYSize = 256;
443 m_dDefaultFilterParam = 1.;
444 m_dDefaultFilterBandwidth = 1.;
445 m_dDefaultFilterInputScale = 1.;
446 m_dDefaultFilterOutputScale = 1.;
448 wxAcceleratorEntry accelEntries[15];
449 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
450 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
451 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
452 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
454 for (i = 0; i < 10; i++)
455 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
456 wxAcceleratorTable accelTable (15, accelEntries);
458 wxAcceleratorTable accelTable (5, accelEntries);
461 SetAcceleratorTable (accelTable);
464 MainFrame::~MainFrame()
466 m_bShuttingDown = true; // Currently used so that Log Window will close
468 // delete all non-modified documents
469 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
470 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
471 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
472 if (pDoc && ! pDoc->IsModified()) {
473 theApp->getDocManager()->RemoveDocument(pDoc);
479 if (theApp->getConfig())
480 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
482 delete theApp->getDocManager();
487 MainFrame::OnSize (wxSizeEvent& event)
490 if (theApp->getLogDoc()) {
492 GetClientSize(&xSize, &ySize);
493 int yLogSize = ySize / 4;
494 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
495 theApp->getLogDoc()->getView()->getFrame()->Show (true);
500 wxDocMDIParentFrame::OnSize (event);
502 wxDocParentFrame::OnSize (event);
507 MainFrame::OnCreatePhantom(wxCommandEvent& event)
509 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
510 int dialogReturn = dialogPhantom.ShowModal();
511 if (dialogReturn == wxID_OK) {
512 wxString selection (dialogPhantom.getPhantom());
513 if (theApp->getVerboseLogging())
514 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
515 wxString filename = selection + ".phm";
516 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
517 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
523 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
525 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
526 int dialogReturn = dialogFilter.ShowModal();
527 if (dialogReturn == wxID_OK) {
528 wxString strFilter (dialogFilter.getFilterName());
529 wxString strDomain (dialogFilter.getDomainName());
530 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
531 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
532 m_iDefaultFilterXSize = dialogFilter.getXSize();
533 m_iDefaultFilterYSize = dialogFilter.getYSize();
534 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
535 m_dDefaultFilterParam= dialogFilter.getFilterParam();
536 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
537 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
538 std::ostringstream os;
539 os << "Generate Filter=" << strFilter.c_str()
540 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
541 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
542 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
543 *theApp->getLog() << os.str().c_str() << "\n";
544 wxString filename = "untitled.if";
545 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
546 pFilterDoc->setBadFileOpen();
548 sys_error (ERR_SEVERE, "Unable to create filter image");
551 ImageFile& rIF = pFilterDoc->getImageFile();
552 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
553 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
554 rIF.labelAdd (os.str().c_str());
555 pFilterDoc->Modify (true);
556 pFilterDoc->UpdateAllViews();
557 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
558 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
559 pFilterDoc->getView()->getFrame()->Show(true);
564 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
566 const ImageFile& rIF = pIFDoc->getImageFile();
567 unsigned int nx = rIF.nx();
568 unsigned int ny = rIF.ny();
569 wxList& rListDocs = m_docManager->GetDocuments();
570 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
571 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
572 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
573 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
574 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
575 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
576 vecIF.push_back (pIFCompareDoc);
583 MainFrame::OnLogEvent (wxCommandEvent& event)
585 *theApp->getLog() << event.GetString();
589 MainFrame::OnHelpTips (wxCommandEvent& event)
595 MainFrame::OnHelpContents (wxCommandEvent& event)
597 showHelp (event.GetId());
601 MainFrame::OnHelpButton (wxCommandEvent& event)
603 showHelp (event.GetId());
606 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
608 MainFrame::OnHelpSecondary (wxCommandEvent& event)
610 m_htmlHelp.DisplayContents();
615 MainFrame::showHelp (int commandID)
619 case MAINMENU_HELP_CONTENTS:
621 m_winHelp.DisplayContents ();
623 m_htmlHelp.DisplayContents ();
630 m_winHelp.DisplaySection (commandID);
632 m_htmlHelp.Display (commandID);
639 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
645 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
649 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
650 wxNode* pNode = rListDocs.GetFirst();
651 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
652 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
653 wxString strFilename = pDoc->GetFilename();
655 strFilename += "\tCtrl-";
656 strFilename += static_cast<char>('0' + iPos);
658 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
659 m_apWindowMenuData[iPos] = pDoc;
660 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
662 pNode = pNode->GetNext();
664 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
665 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
666 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
667 m_apWindowMenuData[i] = NULL;
672 #ifdef CTSIM_CUSTOM_MRU
674 MainFrame::OnMRUFile (wxCommandEvent& event)
676 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
678 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
683 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
685 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
686 wxString strFilename = pDoc->GetFilename();
687 const wxView* pView = pDoc->GetFirstView();
689 wxFrame* pFrame = pView->GetFrame();
696 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
697 { DoWindowMenu (0, event); }
699 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
700 { DoWindowMenu (1, event); }
702 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
703 { DoWindowMenu (2, event); }
705 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
706 { DoWindowMenu (3, event); }
708 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
709 { DoWindowMenu (4, event); }
711 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
712 { DoWindowMenu (5, event); }
714 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
715 { DoWindowMenu (6, event); }
717 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
718 { DoWindowMenu (7, event); }
720 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
721 { DoWindowMenu (8, event); }
723 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
724 { DoWindowMenu (9, event); }
726 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
727 { DoWindowMenu (10, event); }
729 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
730 { DoWindowMenu (11, event); }
732 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
733 { DoWindowMenu (12, event); }
735 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
736 { DoWindowMenu (13, event); }
738 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
739 { DoWindowMenu (14, event); }
741 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
742 { DoWindowMenu (15, event); }
744 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
745 { DoWindowMenu (16, event); }
747 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
748 { DoWindowMenu (17, event); }
750 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
751 { DoWindowMenu (18, event); }
753 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
754 { DoWindowMenu (19, event); }
757 class BitmapControl : public wxPanel
760 DECLARE_DYNAMIC_CLASS (BitmapControl)
761 DECLARE_EVENT_TABLE ()
765 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
766 const wxPoint& pos = wxDefaultPosition,
767 const wxSize& size = wxDefaultSize,
768 long style = wxSTATIC_BORDER,
769 const wxValidator& validator = wxDefaultValidator,
770 const wxString& name = "BitmapCtrl");
773 virtual ~BitmapControl();
775 virtual wxSize GetBestSize() const;
777 wxBitmap* getBitmap()
778 { return m_pBitmap; }
780 void OnPaint(wxPaintEvent& event);
784 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
785 EVT_PAINT(BitmapControl::OnPaint)
788 IMPLEMENT_CLASS(BitmapControl, wxPanel)
791 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
792 long style, const wxValidator& validator, const wxString& name)
795 Create(parent, id, pos, size, style, name);
797 SetSize (GetBestSize());
801 BitmapControl::GetBestSize () const
804 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
809 BitmapControl::~BitmapControl()
813 BitmapControl::OnPaint (wxPaintEvent& event)
817 dc.DrawBitmap (*m_pBitmap, 0, 0);
821 class BitmapDialog : public wxDialog {
823 BitmapControl* m_pBitmapCtrl;
826 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
827 virtual ~BitmapDialog();
830 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
831 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
833 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
835 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
837 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
838 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
839 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
841 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
843 SetAutoLayout (true);
844 SetSizer (pTopSizer);
845 pTopSizer->Fit (this);
846 pTopSizer->SetSizeHints (this);
849 BitmapDialog::~BitmapDialog()
854 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
856 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
857 theApp->getAskDeleteNewDocs(), theApp->getVerboseLogging(), theApp->getStartupTips());
858 if (dlg.ShowModal() == wxID_OK) {
859 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
860 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
861 theApp->setVerboseLogging (dlg.getVerboseLogging());
862 theApp->setStartupTips (dlg.getStartupTips());
867 #include "./splash.xpm"
869 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
871 long lFreeMem = ::wxGetFreeMemory() / (1024L * 1024L);
872 wxString strOSDesc = ::wxGetOsDescription();
873 *theApp->getLog() << "Operation System: " << strOSDesc;
875 *theApp->getLog() << ", Free Memory: " << lFreeMem << " MB";
876 *theApp->getLog() << "\n";
878 wxBitmap bmp (splash);
880 BitmapDialog dlg (&bmp, "About CTSim");
883 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
888 #elif defined(VERSION)
889 msg << "Version: " << VERSION << "\n\n";
891 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
893 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
898 ProjectionFileDocument*
899 CTSimApp::newProjectionDoc()
901 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
903 ProjectionFileView* pView = newDoc->getView();
905 wxFrame* pFrame = pView->getFrame();
907 pFrame->SetSize (0,0);
908 pFrame->Show (false);
911 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
912 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
913 newDoc->OnNewDocument();
920 CTSimApp::newImageDoc()
922 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
924 ImageFileView* pView = newDoc->getView();
926 wxFrame* pFrame = pView->getFrame();
928 pFrame->SetSize (0,0);
929 pFrame->Show (false);
932 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
933 newDoc->SetDocumentTemplate (m_pDocTemplImage);
934 newDoc->OnNewDocument();
941 CTSimApp::newPlotDoc()
943 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
945 PlotFileView* pView = newDoc->getView();
947 wxFrame* pFrame = pView->getFrame();
950 m_pFrame->GetClientSize (&size.x, &size.y);
951 pFrame->SetSize (size.x / 2, size.y / 2);
952 pFrame->Show (false);
955 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
956 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
957 newDoc->OnNewDocument();
965 CTSimApp::newTextDoc()
967 wxString strFilename (getUntitledFilename());
968 strFilename += ".txt";
970 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
972 TextFileView* pView = newDoc->getView();
974 wxFrame* pFrame = pView->getFrame();
977 m_pFrame->GetClientSize (&size.x, &size.y);;
978 pFrame->SetSize (size.x / 2, size.y / 2);
979 pFrame->Show (false);
982 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
983 newDoc->SetDocumentTemplate (m_pDocTemplText);
984 newDoc->OnNewDocument();
992 CTSimApp::newPhantomDoc()
994 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
996 PhantomFileView* pView = newDoc->getView();
998 wxFrame* pFrame = pView->getFrame();
1000 pFrame->SetSize (0,0);
1002 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
1003 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
1004 newDoc->OnNewDocument();
1012 Graph3dFileDocument*
1013 CTSimApp::newGraph3dDoc()
1015 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
1017 Graph3dFileView* pView = newDoc->getView();
1019 wxFrame* pFrame = pView->getFrame();
1021 pFrame->SetSize (0,0);
1023 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
1024 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
1025 newDoc->OnNewDocument();