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.79 2001/02/16 02:36:18 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.79 2001/02/16 02:36:18 kevin Exp $";
77 struct option CTSimApp::ctsimOptions[] =
79 {"help", 0, 0, O_HELP},
80 {"version", 0, 0, O_VERSION},
84 IMPLEMENT_APP(CTSimApp)
87 : m_docManager(NULL), m_pFrame(NULL), m_pLog(0), m_pLogDoc(0), m_pConfig(0),
88 m_bAdvancedOptions(false), m_bSetModifyNewDocs(true)
93 #ifdef HAVE_SYS_TIME_H
97 #ifdef HAVE_SYS_RESOURCE_H
98 #include <sys/resource.h>
104 #ifdef HAVE_SETPRIORITY
105 setpriority (PRIO_PROCESS, 0, 15); // set to low scheduling priority
110 g_bRunningWXWindows = true;
113 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
119 std::cout << rcsindent << std::endl;
121 std::cout << "Version: CTSIMVERSION" << std::endl;
122 #elif defined(VERSION)
123 std::cout << "Version: VERSION" << std::endl;
136 m_docManager = new wxDocManager (wxDEFAULT_DOCMAN_FLAGS, true);
138 m_pDocTemplImage = new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile", "ImageView", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
139 m_pDocTemplProjection = new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile", "ProjectionView", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
140 m_pDocTemplPhantom = new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "PhantomFile", "PhantomView", CLASSINFO(PhantomFileDocument), CLASSINFO(PhantomFileView));
141 m_pDocTemplPlot = new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "PlotFile", "PlotView", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
142 m_pDocTemplText = new wxDocTemplate (m_docManager, "TextFile", "*.txt", "", "txt", "TextFile", "TextView", CLASSINFO(TextFileDocument), CLASSINFO(TextFileView), wxTEMPLATE_INVISIBLE);
144 m_pDocTemplGraph3d = new wxDocTemplate (m_docManager, "Graph3dFile", "*.g3d", "", "g3d", "Graph3dFile", "Graph3dView", CLASSINFO(Graph3dFileDocument), CLASSINFO(Graph3dFileView), wxTEMPLATE_INVISIBLE);
148 wxImage::AddHandler(new wxGIFHandler); // Required for images in the online documentation
151 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
152 wxFileSystem::AddHandler(new wxZipFSHandler); // Required for advanced HTML help
155 // Create the main frame window
156 int xDisplay, yDisplay;
157 ::wxDisplaySize (&xDisplay, &yDisplay);
158 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0),
159 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .755)), wxDEFAULT_FRAME_STYLE);
161 setIconForFrame (m_pFrame);
162 m_pFrame->Centre(wxBOTH);
163 m_pFrame->Show(true);
164 SetTopWindow (m_pFrame);
167 m_docManager->FileHistoryLoad(*m_pConfig);
170 m_pLogDoc = newTextDoc();
172 m_pLog = m_pLogDoc->getTextCtrl();
173 m_pLogDoc->SetDocumentName("Log.txt");
174 m_pLogDoc->SetFilename("Log.txt");
175 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
177 m_pFrame->GetClientSize(&xSize, &ySize);
178 int yLogSize = ySize / 4;
179 m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
180 m_pLogDoc->getView()->getFrame()->Show (true);
183 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
185 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
188 if (! m_pConfig->Read("HelpDir", &helpDir))
189 helpDir = ::wxGetCwd();
191 if (! m_pFrame->getWinHelpController().Initialize(helpDir + "/ctsim"))
192 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
194 if (! m_pFrame->getHtmlHelpController().Initialize(helpDir + "/ctsim") &&
195 ! m_pFrame->getHtmlHelpController().Initialize("/usr/local/man/ctsim"))
196 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
198 if (::wxDirExists ("/tmp"))
199 m_pFrame->getHtmlHelpController().SetTempDir(_T("/tmp"));
200 m_pFrame->getHtmlHelpController().UseConfig (m_pConfig);
204 for (int i = optind + 1; i <= argc; i++) {
205 wxString filename = argv [i - 1];
206 m_docManager->CreateDocument (filename, wxDOC_SILENT);
213 #include "./ctsim.xpm"
215 CTSimApp::setIconForFrame(wxFrame* pFrame)
217 wxIcon iconApp (ctsim16_xpm);
220 pFrame->SetIcon (iconApp);
224 CTSimApp::usage(const char* program)
226 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
227 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
229 std::cout << " --version Display version\n";
230 std::cout << " --help Display this help message\n";
245 CTSimApp::openConfig()
248 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", "", "", wxCONFIG_USE_LOCAL_FILE);
250 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", ".ctsim", "", wxCONFIG_USE_LOCAL_FILE);
253 wxConfigBase::Set(m_pConfig);
254 m_pConfig->Read ("AdvancedOptions", &m_bAdvancedOptions);
255 m_pConfig->Read ("SetModifyNewDocs", &m_bSetModifyNewDocs);
259 CTSimApp::closeConfig()
261 m_pConfig->Write ("AdvancedOptions", m_bAdvancedOptions);
262 m_pConfig->Write ("SetModifyNewDocs", m_bSetModifyNewDocs);
268 CTSimApp::getUntitledFilename()
270 static int untitledNumber = 1;
272 wxString filename ("Untitled");
273 filename << untitledNumber++;
279 // Top-level window for CTSim
282 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
284 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
286 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
288 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
291 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
292 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
293 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
294 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
295 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
296 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
297 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
298 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
299 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
300 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
301 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
302 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
303 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
304 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
305 EVT_SIZE(MainFrame::OnSize)
307 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
308 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
310 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
311 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
312 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
313 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
314 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
315 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
316 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
317 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
318 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
319 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
320 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
321 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
322 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
323 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
324 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
325 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
326 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
327 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
328 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
329 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
330 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
331 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
332 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
333 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
334 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
340 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
341 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
343 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
344 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
347 m_bShuttingDown = false;
350 wxMenu *file_menu = new wxMenu;
352 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
353 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
354 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
356 file_menu->AppendSeparator();
357 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
358 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
360 // history of files visited
361 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
362 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
365 m_pWindowMenu = new wxMenu;
366 m_pWindowMenu->UpdateUI (this);
369 wxMenu* help_menu = new wxMenu;
370 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
371 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
372 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
374 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
376 wxMenuBar* menu_bar = new wxMenuBar;
378 menu_bar->Append(file_menu, "&File");
380 menu_bar->Append(m_pWindowMenu, "&Window");
382 menu_bar->Append(help_menu, "&Help");
384 SetMenuBar(menu_bar);
388 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
389 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
390 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
391 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
395 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
396 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
397 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
398 m_iDefaultFilterXSize = 256;
399 m_iDefaultFilterYSize = 256;
400 m_dDefaultFilterParam = 1.;
401 m_dDefaultFilterBandwidth = 1.;
402 m_dDefaultFilterInputScale = 1.;
403 m_dDefaultFilterOutputScale = 1.;
405 wxAcceleratorEntry accelEntries[15];
406 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
407 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
408 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
410 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
411 for (i = 0; i < 10; i++)
412 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
413 wxAcceleratorTable accelTable (15, accelEntries);
415 wxAcceleratorTable accelTable (4, accelEntries);
418 SetAcceleratorTable (accelTable);
421 MainFrame::~MainFrame()
423 m_bShuttingDown = true; // Currently used so that Log Window will close
425 // delete all non-modified documents
426 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
427 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
428 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
429 if (pDoc && ! pDoc->IsModified()) {
430 theApp->getDocManager()->RemoveDocument(pDoc);
436 if (theApp->getConfig())
437 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
439 delete theApp->getDocManager();
444 MainFrame::OnSize (wxSizeEvent& event)
447 if (theApp->getLogDoc()) {
449 GetClientSize(&xSize, &ySize);
450 int yLogSize = ySize / 4;
451 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
452 theApp->getLogDoc()->getView()->getFrame()->Show (true);
457 wxDocMDIParentFrame::OnSize (event);
459 wxDocParentFrame::OnSize (event);
464 MainFrame::OnCreatePhantom(wxCommandEvent& event)
466 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
467 int dialogReturn = dialogPhantom.ShowModal();
468 if (dialogReturn == wxID_OK) {
469 wxString selection (dialogPhantom.getPhantom());
470 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
471 wxString filename = selection + ".phm";
472 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
473 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
479 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
481 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
482 int dialogReturn = dialogFilter.ShowModal();
483 if (dialogReturn == wxID_OK) {
484 wxString strFilter (dialogFilter.getFilterName());
485 wxString strDomain (dialogFilter.getDomainName());
486 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
487 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
488 m_iDefaultFilterXSize = dialogFilter.getXSize();
489 m_iDefaultFilterYSize = dialogFilter.getYSize();
490 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
491 m_dDefaultFilterParam= dialogFilter.getFilterParam();
492 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
493 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
494 std::ostringstream os;
495 os << "Generate Filter=" << strFilter.c_str()
496 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
497 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
498 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
499 *theApp->getLog() << os.str().c_str() << "\n";
500 wxString filename = "untitled.if";
501 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
502 pFilterDoc->setBadFileOpen();
504 sys_error (ERR_SEVERE, "Unable to create filter image");
507 ImageFile& rIF = pFilterDoc->getImageFile();
508 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
509 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
510 rIF.labelAdd (os.str().c_str());
511 pFilterDoc->Modify (true);
512 pFilterDoc->UpdateAllViews();
513 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
514 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
515 pFilterDoc->getView()->getFrame()->Show(true);
520 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
522 const ImageFile& rIF = pIFDoc->getImageFile();
523 unsigned int nx = rIF.nx();
524 unsigned int ny = rIF.ny();
525 wxList& rListDocs = m_docManager->GetDocuments();
526 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
527 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
528 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
529 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
530 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
531 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
532 vecIF.push_back (pIFCompareDoc);
539 MainFrame::OnHelpContents (wxCommandEvent& event)
541 showHelp (event.GetId());
545 MainFrame::OnHelpButton (wxCommandEvent& event)
547 showHelp (event.GetId());
550 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
552 MainFrame::OnHelpSecondary (wxCommandEvent& event)
554 m_htmlHelp.DisplayContents();
559 MainFrame::showHelp (int commandID)
563 case MAINMENU_HELP_CONTENTS:
565 m_winHelp.DisplayContents ();
567 m_htmlHelp.DisplayContents ();
573 m_winHelp.DisplaySection (commandID);
575 m_htmlHelp.DisplaySection (commandID);
582 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
588 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
592 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
593 wxNode* pNode = rListDocs.GetFirst();
594 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
595 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
596 wxString strFilename = pDoc->GetFilename();
598 strFilename += "\tCtrl-";
599 strFilename += static_cast<char>('0' + iPos);
601 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
602 m_apWindowMenuData[iPos] = pDoc;
603 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
605 pNode = pNode->GetNext();
607 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
608 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
609 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
610 m_apWindowMenuData[i] = NULL;
615 #ifdef CTSIM_CUSTOM_MRU
617 MainFrame::OnMRUFile (wxCommandEvent& event)
619 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
621 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
626 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
628 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
629 wxString strFilename = pDoc->GetFilename();
630 const wxView* pView = pDoc->GetFirstView();
632 wxFrame* pFrame = pView->GetFrame();
639 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
640 { DoWindowMenu (0, event); }
642 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
643 { DoWindowMenu (1, event); }
645 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
646 { DoWindowMenu (2, event); }
648 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
649 { DoWindowMenu (3, event); }
651 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
652 { DoWindowMenu (4, event); }
654 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
655 { DoWindowMenu (5, event); }
657 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
658 { DoWindowMenu (6, event); }
660 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
661 { DoWindowMenu (7, event); }
663 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
664 { DoWindowMenu (8, event); }
666 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
667 { DoWindowMenu (9, event); }
669 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
670 { DoWindowMenu (10, event); }
672 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
673 { DoWindowMenu (11, event); }
675 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
676 { DoWindowMenu (12, event); }
678 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
679 { DoWindowMenu (13, event); }
681 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
682 { DoWindowMenu (14, event); }
684 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
685 { DoWindowMenu (15, event); }
687 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
688 { DoWindowMenu (16, event); }
690 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
691 { DoWindowMenu (17, event); }
693 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
694 { DoWindowMenu (18, event); }
696 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
697 { DoWindowMenu (19, event); }
700 class BitmapControl : public wxPanel
703 DECLARE_DYNAMIC_CLASS (BitmapControl)
704 DECLARE_EVENT_TABLE ()
708 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
709 const wxPoint& pos = wxDefaultPosition,
710 const wxSize& size = wxDefaultSize,
711 long style = wxSTATIC_BORDER,
712 const wxValidator& validator = wxDefaultValidator,
713 const wxString& name = "BitmapCtrl");
716 virtual ~BitmapControl();
718 virtual wxSize GetBestSize() const;
720 wxBitmap* getBitmap()
721 { return m_pBitmap; }
723 void OnPaint(wxPaintEvent& event);
727 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
728 EVT_PAINT(BitmapControl::OnPaint)
731 IMPLEMENT_CLASS(BitmapControl, wxPanel)
734 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
735 long style, const wxValidator& validator, const wxString& name)
738 Create(parent, id, pos, size, style, name);
740 SetSize (GetBestSize());
744 BitmapControl::GetBestSize () const
747 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
752 BitmapControl::~BitmapControl()
756 BitmapControl::OnPaint (wxPaintEvent& event)
760 dc.DrawBitmap (*m_pBitmap, 0, 0);
764 class BitmapDialog : public wxDialog {
766 BitmapControl* m_pBitmapCtrl;
769 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
770 virtual ~BitmapDialog();
773 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
774 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
776 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
778 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
780 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
781 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
782 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
784 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
786 SetAutoLayout (true);
787 SetSizer (pTopSizer);
788 pTopSizer->Fit (this);
789 pTopSizer->SetSizeHints (this);
792 BitmapDialog::~BitmapDialog()
797 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
799 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
800 theApp->getAskDeleteNewDocs());
801 if (dlg.ShowModal() == wxID_OK) {
802 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
803 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
808 #include "./splash.xpm"
810 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
812 wxBitmap bmp (splash);
814 BitmapDialog dlg (&bmp, "About CTSim");
817 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
822 #elif defined(VERSION)
823 msg << "Version: " << VERSION << "\n\n";
825 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
827 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
832 ProjectionFileDocument*
833 CTSimApp::newProjectionDoc()
835 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
837 ProjectionFileView* pView = newDoc->getView();
839 wxFrame* pFrame = pView->getFrame();
841 pFrame->SetSize (0,0);
842 pFrame->Show (false);
845 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
846 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
847 newDoc->OnNewDocument();
854 CTSimApp::newImageDoc()
856 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
858 ImageFileView* pView = newDoc->getView();
860 wxFrame* pFrame = pView->getFrame();
862 pFrame->SetSize (0,0);
863 pFrame->Show (false);
866 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
867 newDoc->SetDocumentTemplate (m_pDocTemplImage);
868 newDoc->OnNewDocument();
875 CTSimApp::newPlotDoc()
877 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
879 PlotFileView* pView = newDoc->getView();
881 wxFrame* pFrame = pView->getFrame();
884 m_pFrame->GetClientSize (&size.x, &size.y);
885 pFrame->SetSize (size.x / 2, size.y / 2);
886 pFrame->Show (false);
889 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
890 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
891 newDoc->OnNewDocument();
899 CTSimApp::newTextDoc()
901 wxString strFilename (getUntitledFilename());
902 strFilename += ".txt";
904 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
906 TextFileView* pView = newDoc->getView();
908 wxFrame* pFrame = pView->getFrame();
911 m_pFrame->GetClientSize (&size.x, &size.y);;
912 pFrame->SetSize (size.x / 2, size.y / 2);
913 pFrame->Show (false);
916 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
917 newDoc->SetDocumentTemplate (m_pDocTemplText);
918 newDoc->OnNewDocument();
926 CTSimApp::newPhantomDoc()
928 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
930 PhantomFileView* pView = newDoc->getView();
932 wxFrame* pFrame = pView->getFrame();
934 pFrame->SetSize (0,0);
936 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
937 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
938 newDoc->OnNewDocument();
947 CTSimApp::newGraph3dDoc()
949 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
951 Graph3dFileView* pView = newDoc->getView();
953 wxFrame* pFrame = pView->getFrame();
955 pFrame->SetSize (0,0);
957 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
958 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
959 newDoc->OnNewDocument();