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.101 2001/03/30 19:17:32 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!
57 #include "backgroundmgr.h"
59 #if defined(HAVE_CONFIG_H)
63 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
73 static const char* rcsindent = "$Id: ctsim.cpp,v 1.101 2001/03/30 19:17:32 kevin Exp $";
75 struct option CTSimApp::ctsimOptions[] =
77 {"help", 0, 0, O_HELP},
78 {"version", 0, 0, O_VERSION},
79 {"print", 0, 0, O_PRINT},
83 IMPLEMENT_APP(CTSimApp)
86 : m_bAdvancedOptions(false), m_bSetModifyNewDocs(true), m_bVerboseLogging(false), m_bShowStartupTips(true),
87 m_iCurrentTip(0), m_bUseBackgroundTasks(false),
88 m_docManager(NULL), m_pFrame(NULL), m_pConfig(0), m_pLog(0), m_pLogDoc(0)
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;
111 bool bPrintFiles = false;
114 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
120 std::cout << rcsindent << std::endl;
122 std::cout << "Version: CTSIMVERSION" << std::endl;
123 #elif defined(VERSION)
124 std::cout << "Version: VERSION" << std::endl;
140 m_docManager = new wxDocManager (wxDEFAULT_DOCMAN_FLAGS, true);
142 m_pDocTemplImage = new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile", "ImageView", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
143 m_pDocTemplProjection = new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile", "ProjectionView", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
144 m_pDocTemplPhantom = new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "PhantomFile", "PhantomView", CLASSINFO(PhantomFileDocument), CLASSINFO(PhantomFileView));
145 m_pDocTemplPlot = new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "PlotFile", "PlotView", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
146 m_pDocTemplText = new wxDocTemplate (m_docManager, "TextFile", "*.txt", "", "txt", "TextFile", "TextView", CLASSINFO(TextFileDocument), CLASSINFO(TextFileView), wxTEMPLATE_INVISIBLE);
148 m_pDocTemplGraph3d = new wxDocTemplate (m_docManager, "Graph3dFile", "*.g3d", "", "g3d", "Graph3dFile", "Graph3dView", CLASSINFO(Graph3dFileDocument), CLASSINFO(Graph3dFileView), wxTEMPLATE_INVISIBLE);
152 wxImage::AddHandler(new wxGIFHandler); // Required for images in the online documentation
155 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
156 wxFileSystem::AddHandler(new wxZipFSHandler); // Required for advanced HTML help
159 // Create the main frame window
160 int xDisplay, yDisplay;
161 ::wxDisplaySize (&xDisplay, &yDisplay);
162 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0),
163 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .755)), wxDEFAULT_FRAME_STYLE);
165 setIconForFrame (m_pFrame);
166 m_pFrame->Centre(wxBOTH);
167 m_pFrame->Show(true);
168 SetTopWindow (m_pFrame);
171 m_docManager->FileHistoryLoad(*m_pConfig);
174 m_pLogDoc = newTextDoc();
176 m_pLog = m_pLogDoc->getTextCtrl();
177 m_pLogDoc->SetDocumentName("Log.txt");
178 m_pLogDoc->SetFilename("Log.txt");
179 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
181 m_pFrame->GetClientSize(&xSize, &ySize);
182 int yLogSize = ySize / 4;
183 m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
184 m_pLogDoc->getView()->getFrame()->Show (true);
187 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
189 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
192 if (! m_pConfig->Read("HelpDir", &helpDir))
193 helpDir = ::wxGetCwd();
195 if (! m_pFrame->getWinHelpController().Initialize(helpDir + "/ctsim"))
196 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
198 if (! m_pFrame->getHtmlHelpController().Initialize(helpDir + "/ctsim") &&
199 ! m_pFrame->getHtmlHelpController().Initialize("/usr/local/man/ctsim"))
200 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
202 if (::wxDirExists ("/tmp"))
203 m_pFrame->getHtmlHelpController().SetTempDir(_T("/tmp"));
204 m_pFrame->getHtmlHelpController().UseConfig (m_pConfig);
208 for (int i = optind + 1; i <= argc; i++) {
209 wxString filename = argv [i - 1];
210 wxDocument* pNewDoc = m_docManager->CreateDocument (filename, wxDOC_SILENT);
212 wxView* pNewView = pNewDoc->GetFirstView();
213 wxPrintout *printout = pNewView->OnCreatePrintout();
216 printer.Print(pNewView->GetFrame(), printout, TRUE);
219 wxCommandEvent nullEvent;
220 nullEvent.SetId (wxID_CLOSE);
221 m_docManager->OnFileClose (nullEvent);
225 wxCommandEvent closeEvent;
226 closeEvent.SetInt (MAINMENU_FILE_EXIT);
227 m_pFrame->AddPendingEvent(closeEvent);
230 if (getStartupTips())
233 #ifdef HAVE_WXTHREADS
234 m_pBackgroundMgr = new BackgroundManager;
243 CTSimTipProvider tipProvider (m_iCurrentTip);
244 setStartupTips (::wxShowTip (m_pFrame, &tipProvider, getStartupTips()));
245 m_iCurrentTip = tipProvider.GetCurrentTip();
249 #include "./ctsim.xpm"
251 CTSimApp::setIconForFrame(wxFrame* pFrame)
253 wxIcon iconApp (ctsim16_xpm);
256 pFrame->SetIcon (iconApp);
260 CTSimApp::usage(const char* program)
262 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
263 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
265 std::cout << " --version Display version\n";
266 std::cout << " --help Display this help message\n";
281 CTSimApp::openConfig()
284 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", "", "", wxCONFIG_USE_LOCAL_FILE);
286 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", ".ctsim", "", wxCONFIG_USE_LOCAL_FILE);
289 wxConfigBase::Set(m_pConfig);
290 m_pConfig->Read ("AdvancedOptions", &m_bAdvancedOptions);
291 m_pConfig->Read ("SetModifyNewDocs", &m_bSetModifyNewDocs);
292 m_pConfig->Read ("VerboseLogging", &m_bVerboseLogging);
293 m_pConfig->Read ("StartupTips", &m_bShowStartupTips);
294 m_pConfig->Read ("CurrentTip", &m_iCurrentTip);
295 m_pConfig->Read ("UseBackgroundTasks", &m_bUseBackgroundTasks);
297 wxString strFftwWisdom;
298 m_pConfig->Read ("FftwWisdom", strFftwWisdom);
299 if (strFftwWisdom.size() > 0)
300 fftw_import_wisdom_from_string (strFftwWisdom.c_str());
305 CTSimApp::closeConfig()
307 m_pConfig->Write ("AdvancedOptions", m_bAdvancedOptions);
308 m_pConfig->Write ("SetModifyNewDocs", m_bSetModifyNewDocs);
309 m_pConfig->Write ("VerboseLogging", m_bVerboseLogging);
310 m_pConfig->Write ("StartupTips", m_bShowStartupTips);
311 m_pConfig->Write ("CurrentTip", m_iCurrentTip);
312 m_pConfig->Write ("UseBackgroundTasks", m_bUseBackgroundTasks);
314 const char* const pszWisdom = fftw_export_wisdom_to_string();
315 wxString strFftwWisdom (pszWisdom);
316 fftw_free ((void*) pszWisdom);
317 m_pConfig->Write ("FftwWisdom", strFftwWisdom);
325 CTSimApp::getUntitledFilename()
327 static int untitledNumber = 1;
329 wxString filename ("Untitled");
330 filename << untitledNumber++;
336 // Top-level window for CTSim
339 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
341 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
343 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
345 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
348 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
349 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
350 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
351 EVT_MENU(MAINMENU_HELP_TIPS, MainFrame::OnHelpTips)
352 EVT_MENU(MAINMENU_IMPORT, MainFrame::OnImport)
353 EVT_MENU(IDH_QUICKSTART, MainFrame::OnHelpButton)
354 EVT_MENU(MAINMENU_LOG_EVENT, MainFrame::OnLogEvent)
355 EVT_MENU(NEW_IMAGEFILE_EVENT, MainFrame::OnNewImageFile)
356 EVT_MENU(NEW_PROJECTIONFILE_EVENT, MainFrame::OnNewProjectionFile)
357 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
358 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
359 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
360 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
361 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
362 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
363 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
364 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
365 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
366 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
367 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
369 EVT_SIZE(MainFrame::OnSize)
371 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
372 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
374 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
375 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
376 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
377 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
378 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
379 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
380 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
381 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
382 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
383 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
384 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
385 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
386 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
387 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
388 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
389 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
390 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
391 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
392 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
393 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
394 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
395 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
396 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
397 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
398 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
404 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
405 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
407 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
408 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
411 m_bShuttingDown = false;
414 wxMenu *file_menu = new wxMenu;
416 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
417 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
418 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
420 file_menu->AppendSeparator();
421 file_menu->Append (MAINMENU_IMPORT, "&Import...\tCtrl-M");
422 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
423 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
425 // history of files visited
426 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
427 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
430 m_pWindowMenu = new wxMenu;
431 m_pWindowMenu->UpdateUI (this);
434 wxMenu* help_menu = new wxMenu;
435 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
436 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
437 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
438 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
439 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
441 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
443 wxMenuBar* menu_bar = new wxMenuBar;
445 menu_bar->Append(file_menu, "&File");
447 menu_bar->Append(m_pWindowMenu, "&Window");
449 menu_bar->Append(help_menu, "&Help");
451 SetMenuBar(menu_bar);
456 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
457 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
458 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
459 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
463 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
464 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
465 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
466 m_iDefaultFilterXSize = 256;
467 m_iDefaultFilterYSize = 256;
468 m_dDefaultFilterParam = 1.;
469 m_dDefaultFilterBandwidth = 1.;
470 m_dDefaultFilterInputScale = 1.;
471 m_dDefaultFilterOutputScale = 1.;
472 m_iDefaultImportFormat = ImageFile::IMPORT_FORMAT_PNG;
474 wxAcceleratorEntry accelEntries[15];
475 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
476 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
477 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
478 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('M'), MAINMENU_IMPORT);
479 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
481 for (i = 0; i < 10; i++)
482 accelEntries[i+5].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
483 wxAcceleratorTable accelTable (15, accelEntries);
485 wxAcceleratorTable accelTable (5, accelEntries);
488 SetAcceleratorTable (accelTable);
491 MainFrame::~MainFrame()
493 m_bShuttingDown = true; // Currently used so that Log Window will close
495 // delete all non-modified documents
496 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
497 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
498 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
499 if (pDoc && ! pDoc->IsModified()) {
500 theApp->getDocManager()->RemoveDocument(pDoc);
506 if (theApp->getConfig())
507 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
509 delete theApp->getDocManager();
514 MainFrame::OnSize (wxSizeEvent& event)
517 if (theApp->getLogDoc()) {
519 GetClientSize(&xSize, &ySize);
520 int yLogSize = ySize / 4;
521 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
522 theApp->getLogDoc()->getView()->getFrame()->Show (true);
527 wxDocMDIParentFrame::OnSize (event);
529 wxDocParentFrame::OnSize (event);
534 MainFrame::OnCreatePhantom(wxCommandEvent& event)
536 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
537 int dialogReturn = dialogPhantom.ShowModal();
538 if (dialogReturn == wxID_OK) {
539 wxString selection (dialogPhantom.getPhantom());
540 if (theApp->getVerboseLogging())
541 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
542 wxString filename = selection + ".phm";
543 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
544 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
550 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
552 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
553 int dialogReturn = dialogFilter.ShowModal();
554 if (dialogReturn == wxID_OK) {
555 wxString strFilter (dialogFilter.getFilterName());
556 wxString strDomain (dialogFilter.getDomainName());
557 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
558 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
559 m_iDefaultFilterXSize = dialogFilter.getXSize();
560 m_iDefaultFilterYSize = dialogFilter.getYSize();
561 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
562 m_dDefaultFilterParam= dialogFilter.getFilterParam();
563 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
564 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
565 std::ostringstream os;
566 os << "Generate Filter=" << strFilter.c_str()
567 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
568 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
569 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
570 *theApp->getLog() << os.str().c_str() << "\n";
571 wxString filename = "untitled.if";
572 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
573 pFilterDoc->setBadFileOpen();
575 sys_error (ERR_SEVERE, "Unable to create filter image");
578 ImageFile& rIF = pFilterDoc->getImageFile();
579 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
580 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
581 rIF.labelAdd (os.str().c_str());
582 if (theApp->getAskDeleteNewDocs())
583 pFilterDoc->Modify (true);
584 pFilterDoc->UpdateAllViews();
585 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
586 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
587 pFilterDoc->getView()->getFrame()->Show(true);
592 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
594 const ImageFile& rIF = pIFDoc->getImageFile();
595 unsigned int nx = rIF.nx();
596 unsigned int ny = rIF.ny();
597 wxList& rListDocs = m_docManager->GetDocuments();
598 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
599 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
600 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
601 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
602 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
603 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
604 vecIF.push_back (pIFCompareDoc);
611 MainFrame::OnNewImageFile (wxCommandEvent& event)
613 ImageFile* pImageFile = reinterpret_cast<ImageFile*>(event.GetClientData());
615 ImageFileDocument* pImageDoc = theApp->newImageDoc();
617 sys_error (ERR_SEVERE, "Unable to create image file");
620 pImageDoc->setImageFile (pImageFile);
621 pImageDoc->UpdateAllViews (NULL);
622 if (ImageFileView* imageView = pImageDoc->getView()) {
623 imageView->OnUpdate (imageView, NULL);
624 imageView->getFrame()->SetFocus();
625 imageView->getFrame()->Show(true);
627 if (theApp->getAskDeleteNewDocs())
628 pImageDoc->Modify (true);
633 MainFrame::OnNewProjectionFile (wxCommandEvent& event)
635 Projections* pProjections = reinterpret_cast<Projections*>(event.GetClientData());
636 ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
638 sys_error (ERR_SEVERE, "Unable to create projection file");
641 pProjDoc->setProjections (pProjections);
642 pProjDoc->UpdateAllViews (NULL);
643 if (ProjectionFileView* projView = pProjDoc->getView()) {
644 projView->OnUpdate (projView, NULL);
645 projView->getFrame()->SetFocus();
646 projView->getFrame()->Show(true);
649 if (theApp->getAskDeleteNewDocs())
650 pProjDoc->Modify (true);
654 MainFrame::OnLogEvent (wxCommandEvent& event)
656 *theApp->getLog() << event.GetString();
660 MainFrame::OnHelpTips (wxCommandEvent& event)
666 MainFrame::OnHelpContents (wxCommandEvent& event)
668 showHelp (event.GetId());
672 MainFrame::OnHelpButton (wxCommandEvent& event)
674 showHelp (event.GetId());
677 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
679 MainFrame::OnHelpSecondary (wxCommandEvent& event)
681 m_htmlHelp.DisplayContents();
686 MainFrame::showHelp (int commandID)
690 case MAINMENU_HELP_CONTENTS:
692 m_winHelp.DisplayContents ();
694 m_htmlHelp.DisplayContents ();
701 m_winHelp.DisplaySection (commandID);
703 m_htmlHelp.Display (commandID);
710 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
716 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
720 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
721 wxNode* pNode = rListDocs.GetFirst();
722 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
723 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
724 wxString strFilename = pDoc->GetFilename();
726 strFilename += "\tCtrl-";
727 strFilename += static_cast<char>('0' + iPos);
729 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
730 m_apWindowMenuData[iPos] = pDoc;
731 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
733 pNode = pNode->GetNext();
735 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
736 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
737 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
738 m_apWindowMenuData[i] = NULL;
743 #ifdef CTSIM_CUSTOM_MRU
745 MainFrame::OnMRUFile (wxCommandEvent& event)
747 wxString fileName (theApp->getDocManager()->GetHistoryFile(event.GetId() - wxID_FILE1));
749 theApp->getDocManager()->CreateDocument(fileName, wxDOC_SILENT);
754 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
756 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
757 wxString strFilename = pDoc->GetFilename();
758 const wxView* pView = pDoc->GetFirstView();
760 wxFrame* pFrame = pView->GetFrame();
767 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
768 { DoWindowMenu (0, event); }
770 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
771 { DoWindowMenu (1, event); }
773 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
774 { DoWindowMenu (2, event); }
776 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
777 { DoWindowMenu (3, event); }
779 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
780 { DoWindowMenu (4, event); }
782 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
783 { DoWindowMenu (5, event); }
785 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
786 { DoWindowMenu (6, event); }
788 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
789 { DoWindowMenu (7, event); }
791 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
792 { DoWindowMenu (8, event); }
794 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
795 { DoWindowMenu (9, event); }
797 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
798 { DoWindowMenu (10, event); }
800 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
801 { DoWindowMenu (11, event); }
803 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
804 { DoWindowMenu (12, event); }
806 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
807 { DoWindowMenu (13, event); }
809 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
810 { DoWindowMenu (14, event); }
812 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
813 { DoWindowMenu (15, event); }
815 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
816 { DoWindowMenu (16, event); }
818 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
819 { DoWindowMenu (17, event); }
821 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
822 { DoWindowMenu (18, event); }
824 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
825 { DoWindowMenu (19, event); }
828 class BitmapControl : public wxPanel
831 DECLARE_DYNAMIC_CLASS (BitmapControl)
832 DECLARE_EVENT_TABLE ()
836 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
837 const wxPoint& pos = wxDefaultPosition,
838 const wxSize& size = wxDefaultSize,
839 long style = wxSTATIC_BORDER,
840 const wxValidator& validator = wxDefaultValidator,
841 const wxString& name = "BitmapCtrl");
844 virtual ~BitmapControl();
846 virtual wxSize GetBestSize() const;
848 wxBitmap* getBitmap()
849 { return m_pBitmap; }
851 void OnPaint(wxPaintEvent& event);
855 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
856 EVT_PAINT(BitmapControl::OnPaint)
859 IMPLEMENT_CLASS(BitmapControl, wxPanel)
862 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
863 long style, const wxValidator& validator, const wxString& name)
866 Create(parent, id, pos, size, style, name);
868 SetSize (GetBestSize());
872 BitmapControl::GetBestSize () const
875 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
880 BitmapControl::~BitmapControl()
884 BitmapControl::OnPaint (wxPaintEvent& event)
888 dc.DrawBitmap (*m_pBitmap, 0, 0);
892 class BitmapDialog : public wxDialog {
894 BitmapControl* m_pBitmapCtrl;
897 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
898 virtual ~BitmapDialog();
901 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
902 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
904 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
906 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
908 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
909 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
910 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
912 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
914 SetAutoLayout (true);
915 SetSizer (pTopSizer);
916 pTopSizer->Fit (this);
917 pTopSizer->SetSizeHints (this);
920 BitmapDialog::~BitmapDialog()
925 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
927 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
928 theApp->getAskDeleteNewDocs(), theApp->getVerboseLogging(), theApp->getStartupTips(),
929 theApp->getUseBackgroundTasks());
930 if (dlg.ShowModal() == wxID_OK) {
931 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
932 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
933 theApp->setVerboseLogging (dlg.getVerboseLogging());
934 theApp->setStartupTips (dlg.getStartupTips());
935 theApp->setUseBackgroundTasks (dlg.getUseBackgroundTasks());
940 MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
942 DialogImportParameters dialogImport (this, m_iDefaultImportFormat);
943 if (dialogImport.ShowModal() != wxID_OK)
946 wxString strFormatName (dialogImport.getFormatName ());
947 m_iDefaultImportFormat = ImageFile::convertImportFormatNameToID (strFormatName.c_str());
950 wxString strWildcard;
951 if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM) {
953 strWildcard = "PPM Files (*.ppm)|*.ppm|PGM Files (*.pgm)|*.pgm";
956 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
958 strWildcard = "PNG Files (*.png)|*.png";
961 #ifdef HAVE_CTN_DICOM
962 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
964 strWildcard = "Dicom Files (*.*)|*.*";
971 wxString strFilename = wxFileSelector (wxString("Import Filename"), wxString(""),
972 wxString(""), strExt, strWildcard, wxHIDE_READONLY | wxOPEN);
973 if (! strFilename.IsEmpty()) {
974 if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
975 ImageFile* pIF = new ImageFile;
976 if (pIF->importImage (strFormatName.c_str(), strFilename.c_str())) {
977 ImageFileDocument* pIFDoc = theApp->newImageDoc();
978 pIFDoc->setImageFile(pIF);
979 pIFDoc->getView()->getFrame()->Show(true);
980 std::ostringstream os;
981 os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
982 pIF->labelAdd (os.str().c_str());
983 if (theApp->getAskDeleteNewDocs())
984 pIFDoc->Modify (true);
985 pIFDoc->UpdateAllViews();
986 pIFDoc->GetFirstView()->OnUpdate (NULL, NULL);
987 pIFDoc->getView()->getFrame()->Show(true);
991 #ifdef HAVE_CTN_DICOM
992 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
993 DicomImporter dicomImport (strFilename.c_str());
994 if (dicomImport.fail()) {
995 ::wxMessageBox (dicomImport.failMessage().c_str(), "Import Error");
996 } else if (dicomImport.testImage()) {
997 ImageFileDocument* pIFDoc = theApp->newImageDoc();
998 ImageFile* pIF = dicomImport.getImageFile();
999 pIFDoc->setImageFile (pIF);
1000 pIFDoc->getView()->getFrame()->Show(true);
1001 std::ostringstream os;
1002 os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
1003 pIF->labelAdd (os.str().c_str());
1004 if (theApp->getAskDeleteNewDocs())
1005 pIFDoc->Modify (true);
1006 pIFDoc->UpdateAllViews();
1007 pIFDoc->GetFirstView()->OnUpdate (NULL, NULL);
1008 pIFDoc->getView()->getFrame()->Show(true);
1009 } else if (dicomImport.testProjections()) {
1010 ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
1011 Projections* pProj = dicomImport.getProjections();
1012 pProjDoc->setProjections (pProj);
1013 pProjDoc->getView()->getFrame()->Show(true);
1014 std::ostringstream os;
1015 os << "Import projection file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
1016 pProj->setRemark (os.str().c_str());
1017 if (theApp->getAskDeleteNewDocs())
1018 pProjDoc->Modify (true);
1019 pProjDoc->UpdateAllViews();
1020 pProjDoc->GetFirstView()->OnUpdate (NULL, NULL);
1021 pProjDoc->getView()->getFrame()->Show(true);
1023 ::wxMessageBox ("Unrecognized DICOM file contents", "Import Error");
1027 sys_error (ERR_WARNING, "Unknown import format type");
1031 #include "./splash.xpm"
1033 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
1035 long lFreeMem = ::wxGetFreeMemory() / (1024L * 1024L);
1036 wxString strOSDesc = ::wxGetOsDescription();
1037 *theApp->getLog() << "Operating System: " << strOSDesc;
1039 *theApp->getLog() << ", Free Memory: " << lFreeMem << " MB";
1040 *theApp->getLog() << ", wxWindows: " << wxVERSION_STRING;
1041 #ifdef __TIMESTAMP__
1042 *theApp->getLog() << ", Build Date: " << __TIMESTAMP__;
1045 *theApp->getLog() << ", CTSim Debug version";
1047 *theApp->getLog() << ", CTSim Release version";
1050 *theApp->getLog() << "\n";
1052 wxBitmap bmp (splash);
1054 BitmapDialog dlg (&bmp, "About CTSim");
1057 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
1060 msg += CTSIMVERSION;
1062 #elif defined(VERSION)
1063 msg << "Version: " << VERSION << "\n\n";
1065 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
1067 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
1068 *theApp->getLog() << msg << "\n";
1073 ProjectionFileDocument*
1074 CTSimApp::newProjectionDoc()
1076 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
1078 ProjectionFileView* pView = newDoc->getView();
1080 wxFrame* pFrame = pView->getFrame();
1082 pFrame->SetSize (0,0);
1083 pFrame->Show (false);
1086 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
1087 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
1088 newDoc->OnNewDocument();
1095 CTSimApp::newImageDoc()
1097 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
1099 ImageFileView* pView = newDoc->getView();
1101 wxFrame* pFrame = pView->getFrame();
1103 pFrame->SetSize (0,0);
1104 pFrame->Show (false);
1107 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
1108 newDoc->SetDocumentTemplate (m_pDocTemplImage);
1109 newDoc->OnNewDocument();
1116 CTSimApp::newPlotDoc()
1118 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
1120 PlotFileView* pView = newDoc->getView();
1122 wxFrame* pFrame = pView->getFrame();
1125 m_pFrame->GetClientSize (&size.x, &size.y);
1126 pFrame->SetSize (size.x / 2, size.y / 2);
1127 pFrame->Show (false);
1130 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
1131 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
1132 newDoc->OnNewDocument();
1140 CTSimApp::newTextDoc()
1142 wxString strFilename (getUntitledFilename());
1143 strFilename += ".txt";
1145 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
1147 TextFileView* pView = newDoc->getView();
1149 wxFrame* pFrame = pView->getFrame();
1152 m_pFrame->GetClientSize (&size.x, &size.y);;
1153 pFrame->SetSize (size.x / 2, size.y / 2);
1154 pFrame->Show (false);
1157 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
1158 newDoc->SetDocumentTemplate (m_pDocTemplText);
1159 newDoc->OnNewDocument();
1166 PhantomFileDocument*
1167 CTSimApp::newPhantomDoc()
1169 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
1171 PhantomFileView* pView = newDoc->getView();
1173 wxFrame* pFrame = pView->getFrame();
1175 pFrame->SetSize (0,0);
1177 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
1178 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
1179 newDoc->OnNewDocument();
1187 Graph3dFileDocument*
1188 CTSimApp::newGraph3dDoc()
1190 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
1192 Graph3dFileView* pView = newDoc->getView();
1194 wxFrame* pFrame = pView->getFrame();
1196 pFrame->SetSize (0,0);
1198 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
1199 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
1200 newDoc->OnNewDocument();