1 /*****************************************************************************
5 ** Purpose: Top-level routines of CTSim program
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: July 2000
9 ** This is part of the CTSim program
10 ** Copyright (c) 1983-2001 Kevin Rosenberg
12 ** $Id: ctsim.cpp,v 1.96 2001/03/05 20:29:23 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
29 #define strdup _strdup
32 #include "wx/wxprec.h"
39 #include "wx/filesys.h"
40 #include "wx/fs_zip.h"
42 #include "wx/msw/helpchm.h"
45 #if !wxUSE_DOC_VIEW_ARCHITECTURE
46 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
56 #include "backgroundmgr.h"
58 #if defined(HAVE_CONFIG_H)
62 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
72 static const char* rcsindent = "$Id: ctsim.cpp,v 1.96 2001/03/05 20:29:23 kevin Exp $";
74 struct option CTSimApp::ctsimOptions[] =
76 {"help", 0, 0, O_HELP},
77 {"version", 0, 0, O_VERSION},
78 {"print", 0, 0, O_PRINT},
82 IMPLEMENT_APP(CTSimApp)
85 : m_bAdvancedOptions(false), m_bSetModifyNewDocs(true), m_bVerboseLogging(false), m_bShowStartupTips(true),
86 m_iCurrentTip(0), m_bUseBackgroundTasks(false),
87 m_docManager(NULL), m_pFrame(NULL), m_pConfig(0), m_pLog(0), m_pLogDoc(0)
92 #ifdef HAVE_SYS_TIME_H
96 #ifdef HAVE_SYS_RESOURCE_H
97 #include <sys/resource.h>
103 #ifdef HAVE_SETPRIORITY
104 setpriority (PRIO_PROCESS, 0, 15); // set to low scheduling priority
109 g_bRunningWXWindows = true;
110 bool bPrintFiles = false;
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;
139 m_docManager = new wxDocManager (wxDEFAULT_DOCMAN_FLAGS, true);
141 m_pDocTemplImage = new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile", "ImageView", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
142 m_pDocTemplProjection = new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile", "ProjectionView", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
143 m_pDocTemplPhantom = new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "PhantomFile", "PhantomView", CLASSINFO(PhantomFileDocument), CLASSINFO(PhantomFileView));
144 m_pDocTemplPlot = new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "PlotFile", "PlotView", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
145 m_pDocTemplText = new wxDocTemplate (m_docManager, "TextFile", "*.txt", "", "txt", "TextFile", "TextView", CLASSINFO(TextFileDocument), CLASSINFO(TextFileView), wxTEMPLATE_INVISIBLE);
147 m_pDocTemplGraph3d = new wxDocTemplate (m_docManager, "Graph3dFile", "*.g3d", "", "g3d", "Graph3dFile", "Graph3dView", CLASSINFO(Graph3dFileDocument), CLASSINFO(Graph3dFileView), wxTEMPLATE_INVISIBLE);
151 wxImage::AddHandler(new wxGIFHandler); // Required for images in the online documentation
154 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
155 wxFileSystem::AddHandler(new wxZipFSHandler); // Required for advanced HTML help
158 // Create the main frame window
159 int xDisplay, yDisplay;
160 ::wxDisplaySize (&xDisplay, &yDisplay);
161 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0),
162 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .755)), wxDEFAULT_FRAME_STYLE);
164 setIconForFrame (m_pFrame);
165 m_pFrame->Centre(wxBOTH);
166 m_pFrame->Show(true);
167 SetTopWindow (m_pFrame);
170 m_docManager->FileHistoryLoad(*m_pConfig);
173 m_pLogDoc = newTextDoc();
175 m_pLog = m_pLogDoc->getTextCtrl();
176 m_pLogDoc->SetDocumentName("Log.txt");
177 m_pLogDoc->SetFilename("Log.txt");
178 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
180 m_pFrame->GetClientSize(&xSize, &ySize);
181 int yLogSize = ySize / 4;
182 m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
183 m_pLogDoc->getView()->getFrame()->Show (true);
186 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
188 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
191 if (! m_pConfig->Read("HelpDir", &helpDir))
192 helpDir = ::wxGetCwd();
194 if (! m_pFrame->getWinHelpController().Initialize(helpDir + "/ctsim"))
195 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
197 if (! m_pFrame->getHtmlHelpController().Initialize(helpDir + "/ctsim") &&
198 ! m_pFrame->getHtmlHelpController().Initialize("/usr/local/man/ctsim"))
199 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
201 if (::wxDirExists ("/tmp"))
202 m_pFrame->getHtmlHelpController().SetTempDir(_T("/tmp"));
203 m_pFrame->getHtmlHelpController().UseConfig (m_pConfig);
207 for (int i = optind + 1; i <= argc; i++) {
208 wxString filename = argv [i - 1];
209 wxDocument* pNewDoc = m_docManager->CreateDocument (filename, wxDOC_SILENT);
211 wxView* pNewView = pNewDoc->GetFirstView();
212 wxPrintout *printout = pNewView->OnCreatePrintout();
215 printer.Print(pNewView->GetFrame(), printout, TRUE);
218 wxCommandEvent nullEvent;
219 nullEvent.SetId (wxID_CLOSE);
220 m_docManager->OnFileClose (nullEvent);
224 wxCommandEvent closeEvent;
225 closeEvent.SetInt (MAINMENU_FILE_EXIT);
226 m_pFrame->AddPendingEvent(closeEvent);
229 if (getStartupTips())
232 #ifdef HAVE_WXTHREADS
233 m_pBackgroundMgr = new BackgroundManager;
242 CTSimTipProvider tipProvider (m_iCurrentTip);
243 setStartupTips (::wxShowTip (m_pFrame, &tipProvider, getStartupTips()));
244 m_iCurrentTip = tipProvider.GetCurrentTip();
248 #include "./ctsim.xpm"
250 CTSimApp::setIconForFrame(wxFrame* pFrame)
252 wxIcon iconApp (ctsim16_xpm);
255 pFrame->SetIcon (iconApp);
259 CTSimApp::usage(const char* program)
261 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
262 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
264 std::cout << " --version Display version\n";
265 std::cout << " --help Display this help message\n";
280 CTSimApp::openConfig()
283 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", "", "", wxCONFIG_USE_LOCAL_FILE);
285 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", ".ctsim", "", wxCONFIG_USE_LOCAL_FILE);
288 wxConfigBase::Set(m_pConfig);
289 m_pConfig->Read ("AdvancedOptions", &m_bAdvancedOptions);
290 m_pConfig->Read ("SetModifyNewDocs", &m_bSetModifyNewDocs);
291 m_pConfig->Read ("VerboseLogging", &m_bVerboseLogging);
292 m_pConfig->Read ("StartupTips", &m_bShowStartupTips);
293 m_pConfig->Read ("CurrentTip", &m_iCurrentTip);
294 m_pConfig->Read ("UseBackgroundTasks", &m_bUseBackgroundTasks);
298 CTSimApp::closeConfig()
300 m_pConfig->Write ("AdvancedOptions", m_bAdvancedOptions);
301 m_pConfig->Write ("SetModifyNewDocs", m_bSetModifyNewDocs);
302 m_pConfig->Write ("VerboseLogging", m_bVerboseLogging);
303 m_pConfig->Write ("StartupTips", m_bShowStartupTips);
304 m_pConfig->Write ("CurrentTip", m_iCurrentTip);
305 m_pConfig->Write ("UseBackgroundTasks", m_bUseBackgroundTasks);
312 CTSimApp::getUntitledFilename()
314 static int untitledNumber = 1;
316 wxString filename ("Untitled");
317 filename << untitledNumber++;
323 // Top-level window for CTSim
326 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
328 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
330 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
332 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
335 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
336 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
337 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
338 EVT_MENU(MAINMENU_HELP_TIPS, MainFrame::OnHelpTips)
339 EVT_MENU(MAINMENU_IMPORT, MainFrame::OnImport)
340 EVT_MENU(IDH_QUICKSTART, MainFrame::OnHelpButton)
341 EVT_MENU(MAINMENU_LOG_EVENT, MainFrame::OnLogEvent)
342 EVT_MENU(NEW_IMAGEFILE_EVENT, MainFrame::OnNewImageFile)
343 EVT_MENU(NEW_PROJECTIONFILE_EVENT, MainFrame::OnNewProjectionFile)
344 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
345 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
346 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
347 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
348 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
349 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
350 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
351 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
352 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
353 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
354 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
356 EVT_SIZE(MainFrame::OnSize)
358 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
359 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
361 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
362 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
363 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
364 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
365 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
366 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
367 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
368 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
369 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
370 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
371 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
372 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
373 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
374 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
375 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
376 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
377 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
378 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
379 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
380 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
381 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
382 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
383 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
384 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
385 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
391 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
392 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
394 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
395 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
398 m_bShuttingDown = false;
401 wxMenu *file_menu = new wxMenu;
403 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
404 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
405 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
407 file_menu->AppendSeparator();
408 file_menu->Append (MAINMENU_IMPORT, "&Import...\tCtrl-M");
409 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
410 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
412 // history of files visited
413 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
414 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
417 m_pWindowMenu = new wxMenu;
418 m_pWindowMenu->UpdateUI (this);
421 wxMenu* help_menu = new wxMenu;
422 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
423 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
424 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
425 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
426 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
428 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
430 wxMenuBar* menu_bar = new wxMenuBar;
432 menu_bar->Append(file_menu, "&File");
434 menu_bar->Append(m_pWindowMenu, "&Window");
436 menu_bar->Append(help_menu, "&Help");
438 SetMenuBar(menu_bar);
443 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
444 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
445 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
446 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
450 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
451 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
452 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
453 m_iDefaultFilterXSize = 256;
454 m_iDefaultFilterYSize = 256;
455 m_dDefaultFilterParam = 1.;
456 m_dDefaultFilterBandwidth = 1.;
457 m_dDefaultFilterInputScale = 1.;
458 m_dDefaultFilterOutputScale = 1.;
459 m_iDefaultImportFormat = ImageFile::IMPORT_FORMAT_PPM;
461 wxAcceleratorEntry accelEntries[15];
462 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
463 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
464 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
465 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('M'), MAINMENU_IMPORT);
466 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
468 for (i = 0; i < 10; i++)
469 accelEntries[i+5].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
470 wxAcceleratorTable accelTable (15, accelEntries);
472 wxAcceleratorTable accelTable (5, accelEntries);
475 SetAcceleratorTable (accelTable);
478 MainFrame::~MainFrame()
480 m_bShuttingDown = true; // Currently used so that Log Window will close
482 // delete all non-modified documents
483 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
484 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
485 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
486 if (pDoc && ! pDoc->IsModified()) {
487 theApp->getDocManager()->RemoveDocument(pDoc);
493 if (theApp->getConfig())
494 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
496 delete theApp->getDocManager();
501 MainFrame::OnSize (wxSizeEvent& event)
504 if (theApp->getLogDoc()) {
506 GetClientSize(&xSize, &ySize);
507 int yLogSize = ySize / 4;
508 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
509 theApp->getLogDoc()->getView()->getFrame()->Show (true);
514 wxDocMDIParentFrame::OnSize (event);
516 wxDocParentFrame::OnSize (event);
521 MainFrame::OnCreatePhantom(wxCommandEvent& event)
523 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
524 int dialogReturn = dialogPhantom.ShowModal();
525 if (dialogReturn == wxID_OK) {
526 wxString selection (dialogPhantom.getPhantom());
527 if (theApp->getVerboseLogging())
528 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
529 wxString filename = selection + ".phm";
530 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
531 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
537 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
539 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
540 int dialogReturn = dialogFilter.ShowModal();
541 if (dialogReturn == wxID_OK) {
542 wxString strFilter (dialogFilter.getFilterName());
543 wxString strDomain (dialogFilter.getDomainName());
544 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
545 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
546 m_iDefaultFilterXSize = dialogFilter.getXSize();
547 m_iDefaultFilterYSize = dialogFilter.getYSize();
548 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
549 m_dDefaultFilterParam= dialogFilter.getFilterParam();
550 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
551 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
552 std::ostringstream os;
553 os << "Generate Filter=" << strFilter.c_str()
554 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
555 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
556 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
557 *theApp->getLog() << os.str().c_str() << "\n";
558 wxString filename = "untitled.if";
559 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
560 pFilterDoc->setBadFileOpen();
562 sys_error (ERR_SEVERE, "Unable to create filter image");
565 ImageFile& rIF = pFilterDoc->getImageFile();
566 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
567 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
568 rIF.labelAdd (os.str().c_str());
569 if (theApp->getAskDeleteNewDocs())
570 pFilterDoc->Modify (true);
571 pFilterDoc->UpdateAllViews();
572 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
573 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
574 pFilterDoc->getView()->getFrame()->Show(true);
579 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
581 const ImageFile& rIF = pIFDoc->getImageFile();
582 unsigned int nx = rIF.nx();
583 unsigned int ny = rIF.ny();
584 wxList& rListDocs = m_docManager->GetDocuments();
585 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
586 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
587 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
588 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
589 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
590 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
591 vecIF.push_back (pIFCompareDoc);
598 MainFrame::OnNewImageFile (wxCommandEvent& event)
600 ImageFile* pImageFile = reinterpret_cast<ImageFile*>(event.GetClientData());
602 ImageFileDocument* pImageDoc = theApp->newImageDoc();
604 sys_error (ERR_SEVERE, "Unable to create image file");
607 pImageDoc->setImageFile (pImageFile);
608 pImageDoc->UpdateAllViews (NULL);
609 if (ImageFileView* imageView = pImageDoc->getView()) {
610 imageView->OnUpdate (imageView, NULL);
611 imageView->getFrame()->SetFocus();
612 imageView->getFrame()->Show(true);
614 if (theApp->getAskDeleteNewDocs())
615 pImageDoc->Modify (true);
620 MainFrame::OnNewProjectionFile (wxCommandEvent& event)
622 Projections* pProjections = reinterpret_cast<Projections*>(event.GetClientData());
623 ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
625 sys_error (ERR_SEVERE, "Unable to create projection file");
628 pProjDoc->setProjections (pProjections);
629 pProjDoc->UpdateAllViews (NULL);
630 if (ProjectionFileView* projView = pProjDoc->getView()) {
631 projView->OnUpdate (projView, NULL);
632 projView->getFrame()->SetFocus();
633 projView->getFrame()->Show(true);
636 if (theApp->getAskDeleteNewDocs())
637 pProjDoc->Modify (true);
641 MainFrame::OnLogEvent (wxCommandEvent& event)
643 *theApp->getLog() << event.GetString();
647 MainFrame::OnHelpTips (wxCommandEvent& event)
653 MainFrame::OnHelpContents (wxCommandEvent& event)
655 showHelp (event.GetId());
659 MainFrame::OnHelpButton (wxCommandEvent& event)
661 showHelp (event.GetId());
664 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
666 MainFrame::OnHelpSecondary (wxCommandEvent& event)
668 m_htmlHelp.DisplayContents();
673 MainFrame::showHelp (int commandID)
677 case MAINMENU_HELP_CONTENTS:
679 m_winHelp.DisplayContents ();
681 m_htmlHelp.DisplayContents ();
688 m_winHelp.DisplaySection (commandID);
690 m_htmlHelp.Display (commandID);
697 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
703 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
707 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
708 wxNode* pNode = rListDocs.GetFirst();
709 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
710 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
711 wxString strFilename = pDoc->GetFilename();
713 strFilename += "\tCtrl-";
714 strFilename += static_cast<char>('0' + iPos);
716 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
717 m_apWindowMenuData[iPos] = pDoc;
718 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
720 pNode = pNode->GetNext();
722 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
723 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
724 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
725 m_apWindowMenuData[i] = NULL;
730 #ifdef CTSIM_CUSTOM_MRU
732 MainFrame::OnMRUFile (wxCommandEvent& event)
734 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
736 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
741 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
743 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
744 wxString strFilename = pDoc->GetFilename();
745 const wxView* pView = pDoc->GetFirstView();
747 wxFrame* pFrame = pView->GetFrame();
754 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
755 { DoWindowMenu (0, event); }
757 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
758 { DoWindowMenu (1, event); }
760 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
761 { DoWindowMenu (2, event); }
763 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
764 { DoWindowMenu (3, event); }
766 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
767 { DoWindowMenu (4, event); }
769 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
770 { DoWindowMenu (5, event); }
772 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
773 { DoWindowMenu (6, event); }
775 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
776 { DoWindowMenu (7, event); }
778 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
779 { DoWindowMenu (8, event); }
781 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
782 { DoWindowMenu (9, event); }
784 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
785 { DoWindowMenu (10, event); }
787 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
788 { DoWindowMenu (11, event); }
790 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
791 { DoWindowMenu (12, event); }
793 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
794 { DoWindowMenu (13, event); }
796 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
797 { DoWindowMenu (14, event); }
799 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
800 { DoWindowMenu (15, event); }
802 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
803 { DoWindowMenu (16, event); }
805 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
806 { DoWindowMenu (17, event); }
808 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
809 { DoWindowMenu (18, event); }
811 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
812 { DoWindowMenu (19, event); }
815 class BitmapControl : public wxPanel
818 DECLARE_DYNAMIC_CLASS (BitmapControl)
819 DECLARE_EVENT_TABLE ()
823 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
824 const wxPoint& pos = wxDefaultPosition,
825 const wxSize& size = wxDefaultSize,
826 long style = wxSTATIC_BORDER,
827 const wxValidator& validator = wxDefaultValidator,
828 const wxString& name = "BitmapCtrl");
831 virtual ~BitmapControl();
833 virtual wxSize GetBestSize() const;
835 wxBitmap* getBitmap()
836 { return m_pBitmap; }
838 void OnPaint(wxPaintEvent& event);
842 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
843 EVT_PAINT(BitmapControl::OnPaint)
846 IMPLEMENT_CLASS(BitmapControl, wxPanel)
849 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
850 long style, const wxValidator& validator, const wxString& name)
853 Create(parent, id, pos, size, style, name);
855 SetSize (GetBestSize());
859 BitmapControl::GetBestSize () const
862 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
867 BitmapControl::~BitmapControl()
871 BitmapControl::OnPaint (wxPaintEvent& event)
875 dc.DrawBitmap (*m_pBitmap, 0, 0);
879 class BitmapDialog : public wxDialog {
881 BitmapControl* m_pBitmapCtrl;
884 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
885 virtual ~BitmapDialog();
888 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
889 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
891 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
893 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
895 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
896 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
897 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
899 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
901 SetAutoLayout (true);
902 SetSizer (pTopSizer);
903 pTopSizer->Fit (this);
904 pTopSizer->SetSizeHints (this);
907 BitmapDialog::~BitmapDialog()
912 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
914 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
915 theApp->getAskDeleteNewDocs(), theApp->getVerboseLogging(), theApp->getStartupTips(),
916 theApp->getUseBackgroundTasks());
917 if (dlg.ShowModal() == wxID_OK) {
918 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
919 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
920 theApp->setVerboseLogging (dlg.getVerboseLogging());
921 theApp->setStartupTips (dlg.getStartupTips());
922 theApp->setUseBackgroundTasks (dlg.getUseBackgroundTasks());
927 MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
929 DialogImportParameters dialogImport (this, m_iDefaultImportFormat);
930 if (dialogImport.ShowModal() != wxID_OK)
933 wxString strFormatName (dialogImport.getFormatName ());
934 m_iDefaultImportFormat = ImageFile::convertImportFormatNameToID (strFormatName.c_str());
937 wxString strWildcard;
938 if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM) {
940 strWildcard = "PPM Files (*.ppm)|*.ppm|PGM Files (*.pgm)|*.pgm";
943 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
945 strWildcard = "PNG Files (*.png)|*.png";
948 #ifdef HAVE_CTN_DICOM
949 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
951 strWildcard = "Dicom Files (*.*)|*.*";
958 wxString strFilename = wxFileSelector (wxString("Import Filename"), wxString(""),
959 wxString(""), strExt, strWildcard, wxHIDE_READONLY | wxOPEN);
960 if (! strFilename.IsEmpty()) {
961 if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
962 ImageFile* pIF = new ImageFile;
963 if (pIF->importImage (strFormatName.c_str(), strFilename.c_str())) {
964 ImageFileDocument* pIFDoc = theApp->newImageDoc();
965 pIFDoc->setImageFile(pIF);
966 pIFDoc->getView()->getFrame()->Show(true);
967 std::ostringstream os;
968 os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
969 pIF->labelAdd (os.str().c_str());
970 if (theApp->getAskDeleteNewDocs())
971 pIFDoc->Modify (true);
972 pIFDoc->UpdateAllViews();
973 pIFDoc->GetFirstView()->OnUpdate (NULL, NULL);
974 pIFDoc->getView()->getFrame()->Show(true);
978 #ifdef HAVE_CTN_DICOM
979 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
980 DicomImporter dicomImport (strFilename.c_str());
981 if (dicomImport.fail()) {
982 ::wxMessageBox (dicomImport.failMessage().c_str(), "Import Error");
983 } else if (dicomImport.testImage()) {
984 ImageFileDocument* pIFDoc = theApp->newImageDoc();
985 ImageFile* pIF = dicomImport.getImageFile();
986 pIFDoc->setImageFile (pIF);
987 pIFDoc->getView()->getFrame()->Show(true);
988 std::ostringstream os;
989 os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
990 pIF->labelAdd (os.str().c_str());
991 if (theApp->getAskDeleteNewDocs())
992 pIFDoc->Modify (true);
993 pIFDoc->UpdateAllViews();
994 pIFDoc->GetFirstView()->OnUpdate (NULL, NULL);
995 pIFDoc->getView()->getFrame()->Show(true);
996 } else if (dicomImport.testProjections()) {
997 ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
998 Projections* pProj = dicomImport.getProjections();
999 pProjDoc->setProjections (pProj);
1000 pProjDoc->getView()->getFrame()->Show(true);
1001 std::ostringstream os;
1002 os << "Import projection file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
1003 pProj->setRemark (os.str().c_str());
1004 if (theApp->getAskDeleteNewDocs())
1005 pProjDoc->Modify (true);
1006 pProjDoc->UpdateAllViews();
1007 pProjDoc->GetFirstView()->OnUpdate (NULL, NULL);
1008 pProjDoc->getView()->getFrame()->Show(true);
1010 ::wxMessageBox ("Unrecognized DICOM file contents", "Import Error");
1014 sys_error (ERR_WARNING, "Unknown import format type");
1018 #include "./splash.xpm"
1020 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
1022 long lFreeMem = ::wxGetFreeMemory() / (1024L * 1024L);
1023 wxString strOSDesc = ::wxGetOsDescription();
1024 *theApp->getLog() << "Operation System: " << strOSDesc;
1026 *theApp->getLog() << ", Free Memory: " << lFreeMem << " MB";
1027 *theApp->getLog() << "\n";
1029 wxBitmap bmp (splash);
1031 BitmapDialog dlg (&bmp, "About CTSim");
1034 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
1037 msg += CTSIMVERSION;
1039 #elif defined(VERSION)
1040 msg << "Version: " << VERSION << "\n\n";
1042 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
1044 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
1049 ProjectionFileDocument*
1050 CTSimApp::newProjectionDoc()
1052 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
1054 ProjectionFileView* pView = newDoc->getView();
1056 wxFrame* pFrame = pView->getFrame();
1058 pFrame->SetSize (0,0);
1059 pFrame->Show (false);
1062 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
1063 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
1064 newDoc->OnNewDocument();
1071 CTSimApp::newImageDoc()
1073 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
1075 ImageFileView* pView = newDoc->getView();
1077 wxFrame* pFrame = pView->getFrame();
1079 pFrame->SetSize (0,0);
1080 pFrame->Show (false);
1083 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
1084 newDoc->SetDocumentTemplate (m_pDocTemplImage);
1085 newDoc->OnNewDocument();
1092 CTSimApp::newPlotDoc()
1094 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
1096 PlotFileView* pView = newDoc->getView();
1098 wxFrame* pFrame = pView->getFrame();
1101 m_pFrame->GetClientSize (&size.x, &size.y);
1102 pFrame->SetSize (size.x / 2, size.y / 2);
1103 pFrame->Show (false);
1106 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
1107 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
1108 newDoc->OnNewDocument();
1116 CTSimApp::newTextDoc()
1118 wxString strFilename (getUntitledFilename());
1119 strFilename += ".txt";
1121 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
1123 TextFileView* pView = newDoc->getView();
1125 wxFrame* pFrame = pView->getFrame();
1128 m_pFrame->GetClientSize (&size.x, &size.y);;
1129 pFrame->SetSize (size.x / 2, size.y / 2);
1130 pFrame->Show (false);
1133 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
1134 newDoc->SetDocumentTemplate (m_pDocTemplText);
1135 newDoc->OnNewDocument();
1142 PhantomFileDocument*
1143 CTSimApp::newPhantomDoc()
1145 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
1147 PhantomFileView* pView = newDoc->getView();
1149 wxFrame* pFrame = pView->getFrame();
1151 pFrame->SetSize (0,0);
1153 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
1154 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
1155 newDoc->OnNewDocument();
1163 Graph3dFileDocument*
1164 CTSimApp::newGraph3dDoc()
1166 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
1168 Graph3dFileView* pView = newDoc->getView();
1170 wxFrame* pFrame = pView->getFrame();
1172 pFrame->SetSize (0,0);
1174 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
1175 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
1176 newDoc->OnNewDocument();