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.78 2001/02/16 00:28:41 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.78 2001/02/16 00:28:41 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_MENU(MAINMENU_HELP_TOPICS, MainFrame::OnHelpTopics)
295 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
296 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
297 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
298 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
299 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
300 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
301 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
302 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
303 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
304 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
305 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
306 EVT_SIZE(MainFrame::OnSize)
308 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
309 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
311 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
312 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
313 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
314 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
315 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
316 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
317 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
318 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
319 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
320 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
321 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
322 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
323 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
324 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
325 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
326 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
327 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
328 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
329 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
330 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
331 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
332 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
333 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
334 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
335 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
341 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
342 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
344 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
345 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
348 m_bShuttingDown = false;
351 wxMenu *file_menu = new wxMenu;
353 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
354 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
355 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
357 file_menu->AppendSeparator();
358 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
359 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
361 // history of files visited
362 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
363 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
366 m_pWindowMenu = new wxMenu;
367 m_pWindowMenu->UpdateUI (this);
370 wxMenu* help_menu = new wxMenu;
371 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
372 help_menu->Append (MAINMENU_HELP_TOPICS, "&Topics\tCtrl-T");
373 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
374 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
376 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
378 wxMenuBar* menu_bar = new wxMenuBar;
380 menu_bar->Append(file_menu, "&File");
382 menu_bar->Append(m_pWindowMenu, "&Window");
384 menu_bar->Append(help_menu, "&Help");
386 SetMenuBar(menu_bar);
390 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
391 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
392 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
393 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
397 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
398 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
399 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
400 m_iDefaultFilterXSize = 256;
401 m_iDefaultFilterYSize = 256;
402 m_dDefaultFilterParam = 1.;
403 m_dDefaultFilterBandwidth = 1.;
404 m_dDefaultFilterInputScale = 1.;
405 m_dDefaultFilterOutputScale = 1.;
407 wxAcceleratorEntry accelEntries[15];
408 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
409 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
410 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
411 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
413 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
414 for (i = 0; i < 10; i++)
415 accelEntries[i+4].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
416 wxAcceleratorTable accelTable (15, accelEntries);
418 wxAcceleratorTable accelTable (4, accelEntries);
421 SetAcceleratorTable (accelTable);
424 MainFrame::~MainFrame()
426 m_bShuttingDown = true; // Currently used so that Log Window will close
428 // delete all non-modified documents
429 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
430 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
431 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
432 if (pDoc && ! pDoc->IsModified()) {
433 theApp->getDocManager()->RemoveDocument(pDoc);
439 if (theApp->getConfig())
440 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
442 delete theApp->getDocManager();
447 MainFrame::OnSize (wxSizeEvent& event)
450 if (theApp->getLogDoc()) {
452 GetClientSize(&xSize, &ySize);
453 int yLogSize = ySize / 4;
454 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
455 theApp->getLogDoc()->getView()->getFrame()->Show (true);
460 wxDocMDIParentFrame::OnSize (event);
462 wxDocParentFrame::OnSize (event);
467 MainFrame::OnCreatePhantom(wxCommandEvent& event)
469 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
470 int dialogReturn = dialogPhantom.ShowModal();
471 if (dialogReturn == wxID_OK) {
472 wxString selection (dialogPhantom.getPhantom());
473 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
474 wxString filename = selection + ".phm";
475 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
476 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
482 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
484 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
485 int dialogReturn = dialogFilter.ShowModal();
486 if (dialogReturn == wxID_OK) {
487 wxString strFilter (dialogFilter.getFilterName());
488 wxString strDomain (dialogFilter.getDomainName());
489 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
490 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
491 m_iDefaultFilterXSize = dialogFilter.getXSize();
492 m_iDefaultFilterYSize = dialogFilter.getYSize();
493 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
494 m_dDefaultFilterParam= dialogFilter.getFilterParam();
495 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
496 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
497 std::ostringstream os;
498 os << "Generate Filter=" << strFilter.c_str()
499 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
500 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
501 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
502 *theApp->getLog() << os.str().c_str() << "\n";
503 wxString filename = "untitled.if";
504 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
505 pFilterDoc->setBadFileOpen();
507 sys_error (ERR_SEVERE, "Unable to create filter image");
510 ImageFile& rIF = pFilterDoc->getImageFile();
511 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
512 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
513 rIF.labelAdd (os.str().c_str());
514 pFilterDoc->Modify (true);
515 pFilterDoc->UpdateAllViews();
516 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
517 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
518 pFilterDoc->getView()->getFrame()->Show(true);
523 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
525 const ImageFile& rIF = pIFDoc->getImageFile();
526 unsigned int nx = rIF.nx();
527 unsigned int ny = rIF.ny();
528 wxList& rListDocs = m_docManager->GetDocuments();
529 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
530 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
531 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
532 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
533 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
534 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
535 vecIF.push_back (pIFCompareDoc);
541 MainFrame::OnHelpTopics (wxCommandEvent& event)
543 showHelp (event.GetId());
547 MainFrame::OnHelpContents (wxCommandEvent& event)
549 showHelp (event.GetId());
553 MainFrame::OnHelpButton (wxCommandEvent& event)
555 showHelp (event.GetId());
558 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
560 MainFrame::OnHelpSecondary (wxCommandEvent& event)
562 m_htmlHelp.DisplayContents();
567 MainFrame::showHelp (int commandID)
571 case MAINMENU_HELP_CONTENTS:
573 m_winHelp.DisplayContents ();
575 m_htmlHelp.DisplayContents ();
579 case MAINMENU_HELP_TOPICS:
581 m_winHelp.DisplaySection (IDH_INTRODUCTION);
583 m_htmlHelp.DisplayIndex();
589 m_winHelp.DisplaySection (commandID);
591 m_htmlHelp.DisplaySection (commandID);
598 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
604 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
608 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
609 wxNode* pNode = rListDocs.GetFirst();
610 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
611 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
612 wxString strFilename = pDoc->GetFilename();
614 strFilename += "\tCtrl-";
615 strFilename += static_cast<char>('0' + iPos);
617 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
618 m_apWindowMenuData[iPos] = pDoc;
619 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
621 pNode = pNode->GetNext();
623 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
624 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
625 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
626 m_apWindowMenuData[i] = NULL;
631 #ifdef CTSIM_CUSTOM_MRU
633 MainFrame::OnMRUFile (wxCommandEvent& event)
635 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
637 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
642 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
644 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
645 wxString strFilename = pDoc->GetFilename();
646 const wxView* pView = pDoc->GetFirstView();
648 wxFrame* pFrame = pView->GetFrame();
655 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
656 { DoWindowMenu (0, event); }
658 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
659 { DoWindowMenu (1, event); }
661 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
662 { DoWindowMenu (2, event); }
664 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
665 { DoWindowMenu (3, event); }
667 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
668 { DoWindowMenu (4, event); }
670 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
671 { DoWindowMenu (5, event); }
673 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
674 { DoWindowMenu (6, event); }
676 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
677 { DoWindowMenu (7, event); }
679 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
680 { DoWindowMenu (8, event); }
682 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
683 { DoWindowMenu (9, event); }
685 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
686 { DoWindowMenu (10, event); }
688 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
689 { DoWindowMenu (11, event); }
691 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
692 { DoWindowMenu (12, event); }
694 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
695 { DoWindowMenu (13, event); }
697 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
698 { DoWindowMenu (14, event); }
700 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
701 { DoWindowMenu (15, event); }
703 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
704 { DoWindowMenu (16, event); }
706 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
707 { DoWindowMenu (17, event); }
709 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
710 { DoWindowMenu (18, event); }
712 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
713 { DoWindowMenu (19, event); }
716 class BitmapControl : public wxPanel
719 DECLARE_DYNAMIC_CLASS (BitmapControl)
720 DECLARE_EVENT_TABLE ()
724 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
725 const wxPoint& pos = wxDefaultPosition,
726 const wxSize& size = wxDefaultSize,
727 long style = wxSTATIC_BORDER,
728 const wxValidator& validator = wxDefaultValidator,
729 const wxString& name = "BitmapCtrl");
732 virtual ~BitmapControl();
734 virtual wxSize GetBestSize() const;
736 wxBitmap* getBitmap()
737 { return m_pBitmap; }
739 void OnPaint(wxPaintEvent& event);
743 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
744 EVT_PAINT(BitmapControl::OnPaint)
747 IMPLEMENT_CLASS(BitmapControl, wxPanel)
750 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
751 long style, const wxValidator& validator, const wxString& name)
754 Create(parent, id, pos, size, style, name);
756 SetSize (GetBestSize());
760 BitmapControl::GetBestSize () const
763 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
768 BitmapControl::~BitmapControl()
772 BitmapControl::OnPaint (wxPaintEvent& event)
776 dc.DrawBitmap (*m_pBitmap, 0, 0);
780 class BitmapDialog : public wxDialog {
782 BitmapControl* m_pBitmapCtrl;
785 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
786 virtual ~BitmapDialog();
789 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
790 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
792 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
794 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
796 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
797 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
798 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
800 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
802 SetAutoLayout (true);
803 SetSizer (pTopSizer);
804 pTopSizer->Fit (this);
805 pTopSizer->SetSizeHints (this);
808 BitmapDialog::~BitmapDialog()
813 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
815 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
816 theApp->getAskDeleteNewDocs());
817 if (dlg.ShowModal() == wxID_OK) {
818 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
819 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
824 #include "./splash.xpm"
826 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
828 wxBitmap bmp (splash);
830 BitmapDialog dlg (&bmp, "About CTSim");
833 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
838 #elif defined(VERSION)
839 msg << "Version: " << VERSION << "\n\n";
841 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
843 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
848 ProjectionFileDocument*
849 CTSimApp::newProjectionDoc()
851 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
853 ProjectionFileView* pView = newDoc->getView();
855 wxFrame* pFrame = pView->getFrame();
857 pFrame->SetSize (0,0);
858 pFrame->Show (false);
861 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
862 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
863 newDoc->OnNewDocument();
870 CTSimApp::newImageDoc()
872 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
874 ImageFileView* pView = newDoc->getView();
876 wxFrame* pFrame = pView->getFrame();
878 pFrame->SetSize (0,0);
879 pFrame->Show (false);
882 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
883 newDoc->SetDocumentTemplate (m_pDocTemplImage);
884 newDoc->OnNewDocument();
891 CTSimApp::newPlotDoc()
893 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
895 PlotFileView* pView = newDoc->getView();
897 wxFrame* pFrame = pView->getFrame();
900 m_pFrame->GetClientSize (&size.x, &size.y);
901 pFrame->SetSize (size.x / 2, size.y / 2);
902 pFrame->Show (false);
905 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
906 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
907 newDoc->OnNewDocument();
915 CTSimApp::newTextDoc()
917 wxString strFilename (getUntitledFilename());
918 strFilename += ".txt";
920 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
922 TextFileView* 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_pDocTemplText->GetDocumentName());
933 newDoc->SetDocumentTemplate (m_pDocTemplText);
934 newDoc->OnNewDocument();
942 CTSimApp::newPhantomDoc()
944 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
946 PhantomFileView* pView = newDoc->getView();
948 wxFrame* pFrame = pView->getFrame();
950 pFrame->SetSize (0,0);
952 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
953 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
954 newDoc->OnNewDocument();
963 CTSimApp::newGraph3dDoc()
965 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
967 Graph3dFileView* pView = newDoc->getView();
969 wxFrame* pFrame = pView->getFrame();
971 pFrame->SetSize (0,0);
973 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
974 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
975 newDoc->OnNewDocument();