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.120 2002/10/24 15:54:25 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.120 2002/10/24 15:54:25 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: " << VERSION << std::endl;
\r
122 #elif defined(CTSIMVERSION)
\r
123 std::cout << "Version: " << CTSIMVERSION << 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);
162 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0),
164 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .75)),
166 wxSize(nearest<int>(xDisplay * .6), nearest<int>(yDisplay * .4)),
168 wxDEFAULT_FRAME_STYLE);
170 setIconForFrame (m_pFrame);
171 m_pFrame->Centre(wxBOTH);
172 m_pFrame->Show(true);
173 SetTopWindow (m_pFrame);
176 m_docManager->FileHistoryLoad(*m_pConfig);
179 m_pLogDoc = newTextDoc();
181 m_pLog = m_pLogDoc->getTextCtrl();
182 m_pLogDoc->SetDocumentName("Log.txt");
183 m_pLogDoc->SetFilename("Log.txt");
184 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
186 m_pFrame->GetClientSize(&xSize, &ySize);
187 int yLogSize = ySize / 4;
188 m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
189 m_pLogDoc->getView()->getFrame()->Show (true);
192 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
194 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
197 if (! m_pConfig->Read("HelpDir", &helpDir))
198 helpDir = ::wxGetCwd();
\r
200 if (! m_pFrame->getWinHelpController().Initialize(helpDir + "/ctsim"))
201 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
204 wxString docDir (DATADIR);
\r
206 wxString docDir (::wxGetCwd());
\r
208 wxString docFile = docDir + "ctsim.htb";
209 if (! m_pFrame->getHtmlHelpController().AddBook(docFile) &&
210 ! m_pFrame->getHtmlHelpController().AddBook("/usr/share/ctsim/ctsim.htb") &&
211 ! m_pFrame->getHtmlHelpController().AddBook("/tmp/ctsim.htb"))
\r
212 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
214 if (::wxDirExists ("/tmp"))
215 m_pFrame->getHtmlHelpController().SetTempDir(_T("/tmp"));
216 m_pFrame->getHtmlHelpController().UseConfig (m_pConfig);
220 for (int i = optind + 1; i <= argc; i++) {
221 wxString filename = argv [i - 1];
222 wxDocument* pNewDoc = m_docManager->CreateDocument (filename, wxDOC_SILENT);
224 wxView* pNewView = pNewDoc->GetFirstView();
225 wxPrintout *printout = pNewView->OnCreatePrintout();
228 printer.Print(pNewView->GetFrame(), printout, TRUE);
231 wxCommandEvent nullEvent;
232 nullEvent.SetId (wxID_CLOSE);
233 m_docManager->OnFileClose (nullEvent);
237 wxCommandEvent closeEvent;
238 closeEvent.SetInt (MAINMENU_FILE_EXIT);
239 m_pFrame->AddPendingEvent(closeEvent);
242 if (getStartupTips())
245 #ifdef HAVE_WXTHREADS
246 m_pBackgroundMgr = new BackgroundManager;
255 CTSimTipProvider tipProvider (m_iCurrentTip);
256 setStartupTips (::wxShowTip (m_pFrame, &tipProvider, getStartupTips()));
257 m_iCurrentTip = tipProvider.GetCurrentTip();
261 #include "./ctsim.xpm"
263 CTSimApp::setIconForFrame(wxFrame* pFrame)
265 wxIcon iconApp (ctsim16_xpm);
268 pFrame->SetIcon (iconApp);
272 CTSimApp::usage(const char* program)
274 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
275 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
277 std::cout << " --version Display version\n";
278 std::cout << " --help Display this help message\n";
293 CTSimApp::openConfig()
296 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", "", "", wxCONFIG_USE_LOCAL_FILE);
298 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", ".ctsim", "", wxCONFIG_USE_LOCAL_FILE);
301 wxConfigBase::Set(m_pConfig);
302 m_pConfig->Read ("AdvancedOptions", &m_bAdvancedOptions);
303 m_pConfig->Read ("SetModifyNewDocs", &m_bSetModifyNewDocs);
304 m_pConfig->Read ("VerboseLogging", &m_bVerboseLogging);
305 m_pConfig->Read ("StartupTips", &m_bShowStartupTips);
306 m_pConfig->Read ("CurrentTip", &m_iCurrentTip);
307 m_pConfig->Read ("UseBackgroundTasks", &m_bUseBackgroundTasks);
309 wxString strFftwWisdom;
310 m_pConfig->Read ("FftwWisdom", strFftwWisdom);
311 if (strFftwWisdom.size() > 0)
312 fftw_import_wisdom_from_string (strFftwWisdom.c_str());
317 CTSimApp::closeConfig()
319 m_pConfig->Write ("AdvancedOptions", m_bAdvancedOptions);
320 m_pConfig->Write ("SetModifyNewDocs", m_bSetModifyNewDocs);
321 m_pConfig->Write ("VerboseLogging", m_bVerboseLogging);
322 m_pConfig->Write ("StartupTips", m_bShowStartupTips);
323 m_pConfig->Write ("CurrentTip", m_iCurrentTip);
324 m_pConfig->Write ("UseBackgroundTasks", m_bUseBackgroundTasks);
326 const char* const pszWisdom = fftw_export_wisdom_to_string();
327 wxString strFftwWisdom (pszWisdom);
328 fftw_free ((void*) pszWisdom);
329 m_pConfig->Write ("FftwWisdom", strFftwWisdom);
337 CTSimApp::getUntitledFilename()
339 static int untitledNumber = 1;
341 wxString filename ("Untitled");
342 filename << untitledNumber++;
348 // Top-level window for CTSim
351 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
353 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
355 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
357 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
360 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
361 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
362 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
363 EVT_MENU(MAINMENU_HELP_TIPS, MainFrame::OnHelpTips)
364 EVT_MENU(MAINMENU_IMPORT, MainFrame::OnImport)
365 EVT_MENU(IDH_QUICKSTART, MainFrame::OnHelpButton)
366 EVT_MENU(MAINMENU_LOG_EVENT, MainFrame::OnLogEvent)
367 EVT_MENU(NEW_IMAGEFILE_EVENT, MainFrame::OnNewImageFile)
368 EVT_MENU(NEW_PROJECTIONFILE_EVENT, MainFrame::OnNewProjectionFile)
369 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
370 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
371 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
372 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
373 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
374 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
375 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
376 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
377 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
378 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
379 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
381 EVT_SIZE(MainFrame::OnSize)
383 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
384 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
386 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
387 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
388 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
389 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
390 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
391 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
392 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
393 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
394 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
395 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
396 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
397 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
398 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
399 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
400 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
401 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
402 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
403 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
404 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
405 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
406 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
407 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
408 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
409 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
410 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
416 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
417 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
419 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
420 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
423 m_bShuttingDown = false;
426 wxMenu *file_menu = new wxMenu;
428 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
429 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
430 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
432 file_menu->AppendSeparator();
433 file_menu->Append (MAINMENU_IMPORT, "&Import...\tCtrl-M");
434 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
435 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
437 // history of files visited
438 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
439 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
442 m_pWindowMenu = new wxMenu;
443 m_pWindowMenu->UpdateUI (this);
446 wxMenu* help_menu = new wxMenu;
447 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
448 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
449 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
450 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
451 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
453 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
455 wxMenuBar* menu_bar = new wxMenuBar;
457 menu_bar->Append(file_menu, "&File");
459 menu_bar->Append(m_pWindowMenu, "&Window");
461 menu_bar->Append(help_menu, "&Help");
463 SetMenuBar(menu_bar);
468 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
469 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
470 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
471 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
475 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
476 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
477 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
478 m_iDefaultFilterXSize = 256;
479 m_iDefaultFilterYSize = 256;
480 m_dDefaultFilterParam = 1.;
481 m_dDefaultFilterBandwidth = 1.;
482 m_dDefaultFilterInputScale = 1.;
483 m_dDefaultFilterOutputScale = 1.;
484 m_iDefaultImportFormat = ImageFile::IMPORT_FORMAT_PNG;
486 wxAcceleratorEntry accelEntries[15];
487 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
488 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
489 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
490 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('M'), MAINMENU_IMPORT);
491 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
493 for (i = 0; i < 10; i++)
494 accelEntries[i+5].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
495 wxAcceleratorTable accelTable (15, accelEntries);
497 wxAcceleratorTable accelTable (5, accelEntries);
500 SetAcceleratorTable (accelTable);
503 MainFrame::~MainFrame()
505 m_bShuttingDown = true; // Currently used so that Log Window will close
507 // delete all non-modified documents
508 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
509 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
510 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
511 if (pDoc && ! pDoc->IsModified()) {
512 theApp->getDocManager()->RemoveDocument(pDoc);
518 if (theApp->getConfig())
519 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
521 delete theApp->getDocManager();
526 MainFrame::OnSize (wxSizeEvent& event)
529 if (theApp->getLogDoc()) {
531 GetClientSize(&xSize, &ySize);
532 int yLogSize = ySize / 4;
533 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
534 theApp->getLogDoc()->getView()->getFrame()->Show (true);
539 wxDocMDIParentFrame::OnSize (event);
541 wxDocParentFrame::OnSize (event);
546 MainFrame::OnCreatePhantom(wxCommandEvent& event)
548 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
549 int dialogReturn = dialogPhantom.ShowModal();
550 if (dialogReturn == wxID_OK) {
551 wxString selection (dialogPhantom.getPhantom());
552 if (theApp->getVerboseLogging())
553 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
554 wxString filename = selection + ".phm";
555 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
556 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
562 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
564 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
565 int dialogReturn = dialogFilter.ShowModal();
566 if (dialogReturn == wxID_OK) {
567 wxString strFilter (dialogFilter.getFilterName());
568 wxString strDomain (dialogFilter.getDomainName());
569 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
570 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
571 m_iDefaultFilterXSize = dialogFilter.getXSize();
572 m_iDefaultFilterYSize = dialogFilter.getYSize();
573 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
574 m_dDefaultFilterParam= dialogFilter.getFilterParam();
575 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
576 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
577 std::ostringstream os;
578 os << "Generate Filter=" << strFilter.c_str()
579 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
580 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
581 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
582 *theApp->getLog() << os.str().c_str() << "\n";
583 wxString filename = "untitled.if";
584 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
585 pFilterDoc->setBadFileOpen();
587 sys_error (ERR_SEVERE, "Unable to create filter image");
590 ImageFile& rIF = pFilterDoc->getImageFile();
591 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
592 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
593 rIF.labelAdd (os.str().c_str());
594 if (theApp->getAskDeleteNewDocs())
595 pFilterDoc->Modify (true);
596 pFilterDoc->UpdateAllViews();
597 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
598 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
599 pFilterDoc->getView()->getFrame()->Show(true);
604 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
606 const ImageFile& rIF = pIFDoc->getImageFile();
607 unsigned int nx = rIF.nx();
608 unsigned int ny = rIF.ny();
609 wxList& rListDocs = m_docManager->GetDocuments();
610 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
611 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
612 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
613 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
614 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
615 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
616 vecIF.push_back (pIFCompareDoc);
623 MainFrame::OnNewImageFile (wxCommandEvent& event)
625 ImageFile* pImageFile = reinterpret_cast<ImageFile*>(event.GetClientData());
627 ImageFileDocument* pImageDoc = theApp->newImageDoc();
629 sys_error (ERR_SEVERE, "Unable to create image file");
632 pImageDoc->setImageFile (pImageFile);
633 if (theApp->getAskDeleteNewDocs())
634 pImageDoc->Modify (true);
638 MainFrame::OnNewProjectionFile (wxCommandEvent& event)
640 Projections* pProjections = reinterpret_cast<Projections*>(event.GetClientData());
641 ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
643 sys_error (ERR_SEVERE, "Unable to create projection file");
646 pProjDoc->setProjections (pProjections);
647 if (theApp->getAskDeleteNewDocs())
648 pProjDoc->Modify (true);
652 MainFrame::OnLogEvent (wxCommandEvent& event)
654 *theApp->getLog() << event.GetString();
658 MainFrame::OnHelpTips (wxCommandEvent& event)
664 MainFrame::OnHelpContents (wxCommandEvent& event)
666 showHelp (event.GetId());
670 MainFrame::OnHelpButton (wxCommandEvent& event)
672 showHelp (event.GetId());
675 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
677 MainFrame::OnHelpSecondary (wxCommandEvent& event)
679 m_htmlHelp.Display ("Contents");
684 MainFrame::showHelp (int commandID)
688 case MAINMENU_HELP_CONTENTS:
690 m_winHelp.DisplayContents ();
692 m_htmlHelp.Display ("Contents");
698 m_winHelp.DisplaySection (commandID);
700 m_htmlHelp.Display (commandID);
707 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
713 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
717 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
718 wxNode* pNode = rListDocs.GetFirst();
719 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
720 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
721 wxString strFilename = pDoc->GetFilename();
723 strFilename += "\tCtrl-";
724 strFilename += static_cast<char>('0' + iPos);
726 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
727 m_apWindowMenuData[iPos] = pDoc;
728 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
730 pNode = pNode->GetNext();
732 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
733 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
734 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
735 m_apWindowMenuData[i] = NULL;
742 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
744 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
745 wxString strFilename = pDoc->GetFilename();
746 const wxView* pView = pDoc->GetFirstView();
748 wxWindow* pWindow = pView->GetFrame();
755 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
756 { DoWindowMenu (0, event); }
758 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
759 { DoWindowMenu (1, event); }
761 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
762 { DoWindowMenu (2, event); }
764 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
765 { DoWindowMenu (3, event); }
767 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
768 { DoWindowMenu (4, event); }
770 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
771 { DoWindowMenu (5, event); }
773 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
774 { DoWindowMenu (6, event); }
776 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
777 { DoWindowMenu (7, event); }
779 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
780 { DoWindowMenu (8, event); }
782 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
783 { DoWindowMenu (9, event); }
785 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
786 { DoWindowMenu (10, event); }
788 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
789 { DoWindowMenu (11, event); }
791 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
792 { DoWindowMenu (12, event); }
794 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
795 { DoWindowMenu (13, event); }
797 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
798 { DoWindowMenu (14, event); }
800 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
801 { DoWindowMenu (15, event); }
803 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
804 { DoWindowMenu (16, event); }
806 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
807 { DoWindowMenu (17, event); }
809 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
810 { DoWindowMenu (18, event); }
812 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
813 { DoWindowMenu (19, event); }
816 class BitmapControl : public wxPanel
819 DECLARE_DYNAMIC_CLASS (BitmapControl)
820 DECLARE_EVENT_TABLE ()
824 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
825 const wxPoint& pos = wxDefaultPosition,
826 const wxSize& size = wxDefaultSize,
827 long style = wxSTATIC_BORDER,
828 const wxValidator& validator = wxDefaultValidator,
829 const wxString& name = "BitmapCtrl");
832 virtual ~BitmapControl();
834 virtual wxSize GetBestSize() const;
836 wxBitmap* getBitmap()
837 { return m_pBitmap; }
839 void OnPaint(wxPaintEvent& event);
843 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
844 EVT_PAINT(BitmapControl::OnPaint)
847 IMPLEMENT_CLASS(BitmapControl, wxPanel)
850 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
851 long style, const wxValidator& validator, const wxString& name)
854 Create(parent, id, pos, size, style, name);
856 SetSize (GetBestSize());
860 BitmapControl::GetBestSize () const
863 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
868 BitmapControl::~BitmapControl()
872 BitmapControl::OnPaint (wxPaintEvent& event)
876 dc.DrawBitmap (*m_pBitmap, 0, 0);
880 class BitmapDialog : public wxDialog {
882 BitmapControl* m_pBitmapCtrl;
885 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
886 virtual ~BitmapDialog();
889 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
890 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
892 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
894 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
896 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
897 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
898 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
900 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
902 SetAutoLayout (true);
903 SetSizer (pTopSizer);
904 pTopSizer->Fit (this);
905 pTopSizer->SetSizeHints (this);
908 BitmapDialog::~BitmapDialog()
913 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
915 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
916 theApp->getAskDeleteNewDocs(), theApp->getVerboseLogging(), theApp->getStartupTips(),
917 theApp->getUseBackgroundTasks());
918 if (dlg.ShowModal() == wxID_OK) {
919 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
920 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
921 theApp->setVerboseLogging (dlg.getVerboseLogging());
922 theApp->setStartupTips (dlg.getStartupTips());
923 theApp->setUseBackgroundTasks (dlg.getUseBackgroundTasks());
928 MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
930 DialogImportParameters dialogImport (this, m_iDefaultImportFormat);
931 if (dialogImport.ShowModal() != wxID_OK)
934 wxString strFormatName (dialogImport.getFormatName ());
935 m_iDefaultImportFormat = ImageFile::convertImportFormatNameToID (strFormatName.c_str());
938 wxString strWildcard;
939 if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM) {
941 strWildcard = "PPM Files (*.ppm)|*.ppm|PGM Files (*.pgm)|*.pgm";
944 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
946 strWildcard = "PNG Files (*.png)|*.png";
949 #ifdef HAVE_CTN_DICOM
950 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
952 strWildcard = "Dicom Files (*.*)|*.*";
959 wxString strFilename = wxFileSelector (wxString("Import Filename"), wxString(""),
960 wxString(""), strExt, strWildcard, wxHIDE_READONLY | wxOPEN);
961 if (! strFilename.IsEmpty()) {
962 if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
963 ImageFile* pIF = new ImageFile;
964 if (pIF->importImage (strFormatName.c_str(), strFilename.c_str())) {
965 ImageFileDocument* pIFDoc = theApp->newImageDoc();
966 pIFDoc->setImageFile(pIF);
967 pIFDoc->getView()->getFrame()->Show(true);
968 std::ostringstream os;
969 os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
970 pIF->labelAdd (os.str().c_str());
971 if (theApp->getAskDeleteNewDocs())
972 pIFDoc->Modify (true);
973 pIFDoc->UpdateAllViews();
974 pIFDoc->GetFirstView()->OnUpdate (NULL, NULL);
975 pIFDoc->getView()->getFrame()->Show(true);
979 #ifdef HAVE_CTN_DICOM
980 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
981 DicomImporter dicomImport (strFilename.c_str());
982 if (dicomImport.fail()) {
983 ::wxMessageBox (dicomImport.failMessage().c_str(), "Import Error");
984 } else if (dicomImport.testImage()) {
985 ImageFileDocument* pIFDoc = theApp->newImageDoc();
986 ImageFile* pIF = dicomImport.getImageFile();
987 pIFDoc->setImageFile (pIF);
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->getView()->setInitialClientSize();
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->getView()->setInitialClientSize();
1008 pProjDoc->Activate();
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 wxString strOSDesc = ::wxGetOsDescription();
1023 *theApp->getLog() << "Operating System: " << strOSDesc;
1024 *theApp->getLog() << ", wxWindows: " << wxVERSION_STRING;
1025 #ifdef __TIMESTAMP__
1026 *theApp->getLog() << ", Build Date: " << __TIMESTAMP__;
1029 *theApp->getLog() << ", Debug version";
1031 *theApp->getLog() << ", Release version";
1034 *theApp->getLog() << " " << VERSION;
1035 #elif defined(CTSIMVERSION)
1036 *theApp->getLog() << " " << CTSIMVERSION;
1038 *theApp->getLog() << "\n";
1040 wxBitmap bmp (splash);
1042 BitmapDialog dlg (&bmp, "About CTSim");
1045 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
1047 msg << "Version: " << VERSION << "\n\n";
1048 #elif defined(CTSIMVERSION)
\r
1049 msg << "Version: " << CTSIMVERSION << "\n\n";
\r
1051 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
1053 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
1054 *theApp->getLog() << msg << "\n";
1059 // Create new documents
\r
1061 ProjectionFileDocument*
1062 CTSimApp::newProjectionDoc()
1064 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
1066 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
1067 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
1068 newDoc->OnNewDocument();
1075 CTSimApp::newImageDoc()
1077 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
1079 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
1080 newDoc->SetDocumentTemplate (m_pDocTemplImage);
1081 newDoc->OnNewDocument();
1088 CTSimApp::newPlotDoc()
1090 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
1092 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
1093 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
1094 newDoc->OnNewDocument();
1102 CTSimApp::newTextDoc()
1104 wxString strFilename (getUntitledFilename());
1105 strFilename += ".txt";
1107 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
1109 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
1110 newDoc->SetDocumentTemplate (m_pDocTemplText);
1111 newDoc->OnNewDocument();
1118 PhantomFileDocument*
1119 CTSimApp::newPhantomDoc()
1121 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
1123 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
1124 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
1125 newDoc->OnNewDocument();
1133 Graph3dFileDocument*
1134 CTSimApp::newGraph3dDoc()
1136 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
1138 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
1139 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
1140 newDoc->OnNewDocument();