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.83 2001/02/21 00:09:31 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.83 2001/02/21 00:09:31 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 ();
600 m_winHelp.DisplaySection (commandID);
602 m_htmlHelp.Display (_T("Quick Start"));
606 case IDH_DLG_PROJECTIONS:
608 m_winHelp.DisplaySection (commandID);
610 m_htmlHelp.DisplaySection (_T("IDH_DLG_PROJECTIONS"));
616 m_winHelp.DisplaySection (commandID);
618 m_htmlHelp.Display (commandID);
625 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
631 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
635 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
636 wxNode* pNode = rListDocs.GetFirst();
637 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
638 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
639 wxString strFilename = pDoc->GetFilename();
641 strFilename += "\tCtrl-";
642 strFilename += static_cast<char>('0' + iPos);
644 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
645 m_apWindowMenuData[iPos] = pDoc;
646 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
648 pNode = pNode->GetNext();
650 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
651 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
652 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
653 m_apWindowMenuData[i] = NULL;
658 #ifdef CTSIM_CUSTOM_MRU
660 MainFrame::OnMRUFile (wxCommandEvent& event)
662 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
664 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
669 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
671 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
672 wxString strFilename = pDoc->GetFilename();
673 const wxView* pView = pDoc->GetFirstView();
675 wxFrame* pFrame = pView->GetFrame();
682 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
683 { DoWindowMenu (0, event); }
685 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
686 { DoWindowMenu (1, event); }
688 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
689 { DoWindowMenu (2, event); }
691 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
692 { DoWindowMenu (3, event); }
694 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
695 { DoWindowMenu (4, event); }
697 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
698 { DoWindowMenu (5, event); }
700 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
701 { DoWindowMenu (6, event); }
703 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
704 { DoWindowMenu (7, event); }
706 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
707 { DoWindowMenu (8, event); }
709 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
710 { DoWindowMenu (9, event); }
712 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
713 { DoWindowMenu (10, event); }
715 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
716 { DoWindowMenu (11, event); }
718 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
719 { DoWindowMenu (12, event); }
721 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
722 { DoWindowMenu (13, event); }
724 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
725 { DoWindowMenu (14, event); }
727 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
728 { DoWindowMenu (15, event); }
730 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
731 { DoWindowMenu (16, event); }
733 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
734 { DoWindowMenu (17, event); }
736 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
737 { DoWindowMenu (18, event); }
739 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
740 { DoWindowMenu (19, event); }
743 class BitmapControl : public wxPanel
746 DECLARE_DYNAMIC_CLASS (BitmapControl)
747 DECLARE_EVENT_TABLE ()
751 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
752 const wxPoint& pos = wxDefaultPosition,
753 const wxSize& size = wxDefaultSize,
754 long style = wxSTATIC_BORDER,
755 const wxValidator& validator = wxDefaultValidator,
756 const wxString& name = "BitmapCtrl");
759 virtual ~BitmapControl();
761 virtual wxSize GetBestSize() const;
763 wxBitmap* getBitmap()
764 { return m_pBitmap; }
766 void OnPaint(wxPaintEvent& event);
770 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
771 EVT_PAINT(BitmapControl::OnPaint)
774 IMPLEMENT_CLASS(BitmapControl, wxPanel)
777 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
778 long style, const wxValidator& validator, const wxString& name)
781 Create(parent, id, pos, size, style, name);
783 SetSize (GetBestSize());
787 BitmapControl::GetBestSize () const
790 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
795 BitmapControl::~BitmapControl()
799 BitmapControl::OnPaint (wxPaintEvent& event)
803 dc.DrawBitmap (*m_pBitmap, 0, 0);
807 class BitmapDialog : public wxDialog {
809 BitmapControl* m_pBitmapCtrl;
812 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
813 virtual ~BitmapDialog();
816 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
817 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
819 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
821 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
823 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
824 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
825 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
827 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
829 SetAutoLayout (true);
830 SetSizer (pTopSizer);
831 pTopSizer->Fit (this);
832 pTopSizer->SetSizeHints (this);
835 BitmapDialog::~BitmapDialog()
840 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
842 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
843 theApp->getAskDeleteNewDocs());
844 if (dlg.ShowModal() == wxID_OK) {
845 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
846 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
851 #include "./splash.xpm"
853 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
855 wxBitmap bmp (splash);
857 BitmapDialog dlg (&bmp, "About CTSim");
860 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
865 #elif defined(VERSION)
866 msg << "Version: " << VERSION << "\n\n";
868 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
870 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
875 ProjectionFileDocument*
876 CTSimApp::newProjectionDoc()
878 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
880 ProjectionFileView* pView = newDoc->getView();
882 wxFrame* pFrame = pView->getFrame();
884 pFrame->SetSize (0,0);
885 pFrame->Show (false);
888 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
889 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
890 newDoc->OnNewDocument();
897 CTSimApp::newImageDoc()
899 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
901 ImageFileView* pView = newDoc->getView();
903 wxFrame* pFrame = pView->getFrame();
905 pFrame->SetSize (0,0);
906 pFrame->Show (false);
909 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
910 newDoc->SetDocumentTemplate (m_pDocTemplImage);
911 newDoc->OnNewDocument();
918 CTSimApp::newPlotDoc()
920 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
922 PlotFileView* pView = newDoc->getView();
924 wxFrame* pFrame = pView->getFrame();
927 m_pFrame->GetClientSize (&size.x, &size.y);
928 pFrame->SetSize (size.x / 2, size.y / 2);
929 pFrame->Show (false);
932 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
933 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
934 newDoc->OnNewDocument();
942 CTSimApp::newTextDoc()
944 wxString strFilename (getUntitledFilename());
945 strFilename += ".txt";
947 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
949 TextFileView* pView = newDoc->getView();
951 wxFrame* pFrame = pView->getFrame();
954 m_pFrame->GetClientSize (&size.x, &size.y);;
955 pFrame->SetSize (size.x / 2, size.y / 2);
956 pFrame->Show (false);
959 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
960 newDoc->SetDocumentTemplate (m_pDocTemplText);
961 newDoc->OnNewDocument();
969 CTSimApp::newPhantomDoc()
971 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
973 PhantomFileView* pView = newDoc->getView();
975 wxFrame* pFrame = pView->getFrame();
977 pFrame->SetSize (0,0);
979 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
980 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
981 newDoc->OnNewDocument();
990 CTSimApp::newGraph3dDoc()
992 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
994 Graph3dFileView* pView = newDoc->getView();
996 wxFrame* pFrame = pView->getFrame();
998 pFrame->SetSize (0,0);
1000 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
1001 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
1002 newDoc->OnNewDocument();