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.85 2001/02/21 20:13:03 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.85 2001/02/21 20:13:03 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), m_bVerboseLogging(false),
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);
279 m_pConfig->Read ("VerboseLogging", &m_bVerboseLogging);
283 CTSimApp::closeConfig()
285 m_pConfig->Write ("AdvancedOptions", m_bAdvancedOptions);
286 m_pConfig->Write ("SetModifyNewDocs", m_bSetModifyNewDocs);
287 m_pConfig->Write ("VerboseLogging", m_bVerboseLogging);
293 CTSimApp::getUntitledFilename()
295 static int untitledNumber = 1;
297 wxString filename ("Untitled");
298 filename << untitledNumber++;
304 // Top-level window for CTSim
307 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
309 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
311 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
313 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
316 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
317 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
318 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
319 EVT_MENU(IDH_QUICKSTART, MainFrame::OnHelpButton)
320 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
321 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
322 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
323 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
324 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
325 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
326 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
327 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
328 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
329 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
330 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
332 EVT_SIZE(MainFrame::OnSize)
334 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
335 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
337 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
338 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
339 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
340 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
341 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
342 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
343 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
344 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
345 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
346 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
347 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
348 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
349 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
350 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
351 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
352 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
353 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
354 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
355 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
356 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
357 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
358 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
359 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
360 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
361 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
367 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
368 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
370 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
371 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
374 m_bShuttingDown = false;
377 wxMenu *file_menu = new wxMenu;
379 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
380 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
381 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
383 file_menu->AppendSeparator();
384 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
385 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
387 // history of files visited
388 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
389 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
392 m_pWindowMenu = new wxMenu;
393 m_pWindowMenu->UpdateUI (this);
396 wxMenu* help_menu = new wxMenu;
397 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
399 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
400 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
401 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
403 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
405 wxMenuBar* menu_bar = new wxMenuBar;
407 menu_bar->Append(file_menu, "&File");
409 menu_bar->Append(m_pWindowMenu, "&Window");
411 menu_bar->Append(help_menu, "&Help");
413 SetMenuBar(menu_bar);
417 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
418 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
419 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
420 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
424 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
425 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
426 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
427 m_iDefaultFilterXSize = 256;
428 m_iDefaultFilterYSize = 256;
429 m_dDefaultFilterParam = 1.;
430 m_dDefaultFilterBandwidth = 1.;
431 m_dDefaultFilterInputScale = 1.;
432 m_dDefaultFilterOutputScale = 1.;
434 wxAcceleratorEntry accelEntries[15];
435 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
436 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
437 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
438 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
440 for (i = 0; i < 10; i++)
441 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
442 wxAcceleratorTable accelTable (15, accelEntries);
444 wxAcceleratorTable accelTable (5, accelEntries);
447 SetAcceleratorTable (accelTable);
450 MainFrame::~MainFrame()
452 m_bShuttingDown = true; // Currently used so that Log Window will close
454 // delete all non-modified documents
455 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
456 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
457 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
458 if (pDoc && ! pDoc->IsModified()) {
459 theApp->getDocManager()->RemoveDocument(pDoc);
465 if (theApp->getConfig())
466 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
468 delete theApp->getDocManager();
473 MainFrame::OnSize (wxSizeEvent& event)
476 if (theApp->getLogDoc()) {
478 GetClientSize(&xSize, &ySize);
479 int yLogSize = ySize / 4;
480 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
481 theApp->getLogDoc()->getView()->getFrame()->Show (true);
486 wxDocMDIParentFrame::OnSize (event);
488 wxDocParentFrame::OnSize (event);
493 MainFrame::OnCreatePhantom(wxCommandEvent& event)
495 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
496 int dialogReturn = dialogPhantom.ShowModal();
497 if (dialogReturn == wxID_OK) {
498 wxString selection (dialogPhantom.getPhantom());
499 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
500 wxString filename = selection + ".phm";
501 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
502 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
508 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
510 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
511 int dialogReturn = dialogFilter.ShowModal();
512 if (dialogReturn == wxID_OK) {
513 wxString strFilter (dialogFilter.getFilterName());
514 wxString strDomain (dialogFilter.getDomainName());
515 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
516 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
517 m_iDefaultFilterXSize = dialogFilter.getXSize();
518 m_iDefaultFilterYSize = dialogFilter.getYSize();
519 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
520 m_dDefaultFilterParam= dialogFilter.getFilterParam();
521 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
522 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
523 std::ostringstream os;
524 os << "Generate Filter=" << strFilter.c_str()
525 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
526 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
527 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
528 *theApp->getLog() << os.str().c_str() << "\n";
529 wxString filename = "untitled.if";
530 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
531 pFilterDoc->setBadFileOpen();
533 sys_error (ERR_SEVERE, "Unable to create filter image");
536 ImageFile& rIF = pFilterDoc->getImageFile();
537 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
538 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
539 rIF.labelAdd (os.str().c_str());
540 pFilterDoc->Modify (true);
541 pFilterDoc->UpdateAllViews();
542 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
543 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
544 pFilterDoc->getView()->getFrame()->Show(true);
549 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
551 const ImageFile& rIF = pIFDoc->getImageFile();
552 unsigned int nx = rIF.nx();
553 unsigned int ny = rIF.ny();
554 wxList& rListDocs = m_docManager->GetDocuments();
555 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
556 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
557 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
558 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
559 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
560 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
561 vecIF.push_back (pIFCompareDoc);
568 MainFrame::OnHelpContents (wxCommandEvent& event)
570 showHelp (event.GetId());
574 MainFrame::OnHelpButton (wxCommandEvent& event)
576 showHelp (event.GetId());
579 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
581 MainFrame::OnHelpSecondary (wxCommandEvent& event)
583 m_htmlHelp.DisplayContents();
588 MainFrame::showHelp (int commandID)
592 case MAINMENU_HELP_CONTENTS:
594 m_winHelp.DisplayContents ();
596 m_htmlHelp.DisplayContents ();
603 m_winHelp.DisplaySection (commandID);
605 m_htmlHelp.Display (commandID);
612 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
618 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
622 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
623 wxNode* pNode = rListDocs.GetFirst();
624 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
625 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
626 wxString strFilename = pDoc->GetFilename();
628 strFilename += "\tCtrl-";
629 strFilename += static_cast<char>('0' + iPos);
631 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
632 m_apWindowMenuData[iPos] = pDoc;
633 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
635 pNode = pNode->GetNext();
637 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
638 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
639 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
640 m_apWindowMenuData[i] = NULL;
645 #ifdef CTSIM_CUSTOM_MRU
647 MainFrame::OnMRUFile (wxCommandEvent& event)
649 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
651 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
656 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
658 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
659 wxString strFilename = pDoc->GetFilename();
660 const wxView* pView = pDoc->GetFirstView();
662 wxFrame* pFrame = pView->GetFrame();
669 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
670 { DoWindowMenu (0, event); }
672 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
673 { DoWindowMenu (1, event); }
675 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
676 { DoWindowMenu (2, event); }
678 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
679 { DoWindowMenu (3, event); }
681 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
682 { DoWindowMenu (4, event); }
684 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
685 { DoWindowMenu (5, event); }
687 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
688 { DoWindowMenu (6, event); }
690 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
691 { DoWindowMenu (7, event); }
693 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
694 { DoWindowMenu (8, event); }
696 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
697 { DoWindowMenu (9, event); }
699 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
700 { DoWindowMenu (10, event); }
702 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
703 { DoWindowMenu (11, event); }
705 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
706 { DoWindowMenu (12, event); }
708 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
709 { DoWindowMenu (13, event); }
711 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
712 { DoWindowMenu (14, event); }
714 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
715 { DoWindowMenu (15, event); }
717 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
718 { DoWindowMenu (16, event); }
720 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
721 { DoWindowMenu (17, event); }
723 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
724 { DoWindowMenu (18, event); }
726 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
727 { DoWindowMenu (19, event); }
730 class BitmapControl : public wxPanel
733 DECLARE_DYNAMIC_CLASS (BitmapControl)
734 DECLARE_EVENT_TABLE ()
738 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
739 const wxPoint& pos = wxDefaultPosition,
740 const wxSize& size = wxDefaultSize,
741 long style = wxSTATIC_BORDER,
742 const wxValidator& validator = wxDefaultValidator,
743 const wxString& name = "BitmapCtrl");
746 virtual ~BitmapControl();
748 virtual wxSize GetBestSize() const;
750 wxBitmap* getBitmap()
751 { return m_pBitmap; }
753 void OnPaint(wxPaintEvent& event);
757 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
758 EVT_PAINT(BitmapControl::OnPaint)
761 IMPLEMENT_CLASS(BitmapControl, wxPanel)
764 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
765 long style, const wxValidator& validator, const wxString& name)
768 Create(parent, id, pos, size, style, name);
770 SetSize (GetBestSize());
774 BitmapControl::GetBestSize () const
777 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
782 BitmapControl::~BitmapControl()
786 BitmapControl::OnPaint (wxPaintEvent& event)
790 dc.DrawBitmap (*m_pBitmap, 0, 0);
794 class BitmapDialog : public wxDialog {
796 BitmapControl* m_pBitmapCtrl;
799 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
800 virtual ~BitmapDialog();
803 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
804 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
806 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
808 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
810 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
811 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
812 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
814 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
816 SetAutoLayout (true);
817 SetSizer (pTopSizer);
818 pTopSizer->Fit (this);
819 pTopSizer->SetSizeHints (this);
822 BitmapDialog::~BitmapDialog()
827 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
829 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
830 theApp->getAskDeleteNewDocs(), theApp->getVerboseLogging());
831 if (dlg.ShowModal() == wxID_OK) {
832 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
833 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
834 theApp->setVerboseLogging (dlg.getVerboseLogging());
839 #include "./splash.xpm"
841 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
843 long lFreeMem = ::wxGetFreeMemory() / (1024L * 1024L);
844 wxString strOSDesc = ::wxGetOsDescription();
845 *theApp->getLog() << "Operation System: " << strOSDesc;
847 *theApp->getLog() << ", Free Memory: " << lFreeMem << " MB";
848 *theApp->getLog() << "\n";
850 wxBitmap bmp (splash);
852 BitmapDialog dlg (&bmp, "About CTSim");
855 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
860 #elif defined(VERSION)
861 msg << "Version: " << VERSION << "\n\n";
863 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
865 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
870 ProjectionFileDocument*
871 CTSimApp::newProjectionDoc()
873 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
875 ProjectionFileView* pView = newDoc->getView();
877 wxFrame* pFrame = pView->getFrame();
879 pFrame->SetSize (0,0);
880 pFrame->Show (false);
883 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
884 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
885 newDoc->OnNewDocument();
892 CTSimApp::newImageDoc()
894 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
896 ImageFileView* pView = newDoc->getView();
898 wxFrame* pFrame = pView->getFrame();
900 pFrame->SetSize (0,0);
901 pFrame->Show (false);
904 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
905 newDoc->SetDocumentTemplate (m_pDocTemplImage);
906 newDoc->OnNewDocument();
913 CTSimApp::newPlotDoc()
915 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
917 PlotFileView* pView = newDoc->getView();
919 wxFrame* pFrame = pView->getFrame();
922 m_pFrame->GetClientSize (&size.x, &size.y);
923 pFrame->SetSize (size.x / 2, size.y / 2);
924 pFrame->Show (false);
927 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
928 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
929 newDoc->OnNewDocument();
937 CTSimApp::newTextDoc()
939 wxString strFilename (getUntitledFilename());
940 strFilename += ".txt";
942 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
944 TextFileView* pView = newDoc->getView();
946 wxFrame* pFrame = pView->getFrame();
949 m_pFrame->GetClientSize (&size.x, &size.y);;
950 pFrame->SetSize (size.x / 2, size.y / 2);
951 pFrame->Show (false);
954 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
955 newDoc->SetDocumentTemplate (m_pDocTemplText);
956 newDoc->OnNewDocument();
964 CTSimApp::newPhantomDoc()
966 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
968 PhantomFileView* pView = newDoc->getView();
970 wxFrame* pFrame = pView->getFrame();
972 pFrame->SetSize (0,0);
974 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
975 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
976 newDoc->OnNewDocument();
985 CTSimApp::newGraph3dDoc()
987 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
989 Graph3dFileView* pView = newDoc->getView();
991 wxFrame* pFrame = pView->getFrame();
993 pFrame->SetSize (0,0);
995 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
996 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
997 newDoc->OnNewDocument();