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.109 2002/05/05 09:51: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!
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.109 2002/05/05 09:51:23 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);
163 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0),
165 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .75)),
167 wxSize(nearest<int>(xDisplay * .25), nearest<int>(yDisplay * .25)),
169 wxDEFAULT_FRAME_STYLE);
171 setIconForFrame (m_pFrame);
172 m_pFrame->Centre(wxBOTH);
173 m_pFrame->Show(true);
174 SetTopWindow (m_pFrame);
177 m_docManager->FileHistoryLoad(*m_pConfig);
180 m_pLogDoc = newTextDoc();
182 m_pLog = m_pLogDoc->getTextCtrl();
183 m_pLogDoc->SetDocumentName("Log.txt");
184 m_pLogDoc->SetFilename("Log.txt");
185 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
187 m_pFrame->GetClientSize(&xSize, &ySize);
188 int yLogSize = ySize / 4;
189 m_pLogDoc->getView()->getFrame()->SetClientSize (0, ySize - yLogSize, xSize, yLogSize);
190 m_pLogDoc->getView()->getFrame()->Show (true);
193 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
195 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
198 if (! m_pConfig->Read("HelpDir", &helpDir))
199 helpDir = ::wxGetCwd();
201 if (! m_pFrame->getWinHelpController().Initialize(helpDir + "/ctsim"))
202 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
204 wxString docDir (DATADIR);
205 wxString docFile = docDir + "ctsim.htb";
206 if (! m_pFrame->getHtmlHelpController().AddBook(docFile) &&
207 ! m_pFrame->getHtmlHelpController().Initialize("/usr/share/ctsim/ctsim.htb"))
208 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
210 if (::wxDirExists ("/tmp"))
211 m_pFrame->getHtmlHelpController().SetTempDir(_T("/tmp"));
212 m_pFrame->getHtmlHelpController().UseConfig (m_pConfig);
216 for (int i = optind + 1; i <= argc; i++) {
217 wxString filename = argv [i - 1];
218 wxDocument* pNewDoc = m_docManager->CreateDocument (filename, wxDOC_SILENT);
220 wxView* pNewView = pNewDoc->GetFirstView();
221 wxPrintout *printout = pNewView->OnCreatePrintout();
224 printer.Print(pNewView->GetFrame(), printout, TRUE);
227 wxCommandEvent nullEvent;
228 nullEvent.SetId (wxID_CLOSE);
229 m_docManager->OnFileClose (nullEvent);
233 wxCommandEvent closeEvent;
234 closeEvent.SetInt (MAINMENU_FILE_EXIT);
235 m_pFrame->AddPendingEvent(closeEvent);
238 if (getStartupTips())
241 #ifdef HAVE_WXTHREADS
242 m_pBackgroundMgr = new BackgroundManager;
251 CTSimTipProvider tipProvider (m_iCurrentTip);
252 setStartupTips (::wxShowTip (m_pFrame, &tipProvider, getStartupTips()));
253 m_iCurrentTip = tipProvider.GetCurrentTip();
257 #include "./ctsim.xpm"
259 CTSimApp::setIconForFrame(wxFrame* pFrame)
261 wxIcon iconApp (ctsim16_xpm);
264 pFrame->SetIcon (iconApp);
268 CTSimApp::usage(const char* program)
270 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
271 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
273 std::cout << " --version Display version\n";
274 std::cout << " --help Display this help message\n";
289 CTSimApp::openConfig()
292 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", "", "", wxCONFIG_USE_LOCAL_FILE);
294 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", ".ctsim", "", wxCONFIG_USE_LOCAL_FILE);
297 wxConfigBase::Set(m_pConfig);
298 m_pConfig->Read ("AdvancedOptions", &m_bAdvancedOptions);
299 m_pConfig->Read ("SetModifyNewDocs", &m_bSetModifyNewDocs);
300 m_pConfig->Read ("VerboseLogging", &m_bVerboseLogging);
301 m_pConfig->Read ("StartupTips", &m_bShowStartupTips);
302 m_pConfig->Read ("CurrentTip", &m_iCurrentTip);
303 m_pConfig->Read ("UseBackgroundTasks", &m_bUseBackgroundTasks);
305 wxString strFftwWisdom;
306 m_pConfig->Read ("FftwWisdom", strFftwWisdom);
307 if (strFftwWisdom.size() > 0)
308 fftw_import_wisdom_from_string (strFftwWisdom.c_str());
313 CTSimApp::closeConfig()
315 m_pConfig->Write ("AdvancedOptions", m_bAdvancedOptions);
316 m_pConfig->Write ("SetModifyNewDocs", m_bSetModifyNewDocs);
317 m_pConfig->Write ("VerboseLogging", m_bVerboseLogging);
318 m_pConfig->Write ("StartupTips", m_bShowStartupTips);
319 m_pConfig->Write ("CurrentTip", m_iCurrentTip);
320 m_pConfig->Write ("UseBackgroundTasks", m_bUseBackgroundTasks);
322 const char* const pszWisdom = fftw_export_wisdom_to_string();
323 wxString strFftwWisdom (pszWisdom);
324 fftw_free ((void*) pszWisdom);
325 m_pConfig->Write ("FftwWisdom", strFftwWisdom);
333 CTSimApp::getUntitledFilename()
335 static int untitledNumber = 1;
337 wxString filename ("Untitled");
338 filename << untitledNumber++;
344 // Top-level window for CTSim
347 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
349 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
351 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
353 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
356 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
357 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
358 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
359 EVT_MENU(MAINMENU_HELP_TIPS, MainFrame::OnHelpTips)
360 EVT_MENU(MAINMENU_IMPORT, MainFrame::OnImport)
361 EVT_MENU(IDH_QUICKSTART, MainFrame::OnHelpButton)
362 EVT_MENU(MAINMENU_LOG_EVENT, MainFrame::OnLogEvent)
363 EVT_MENU(NEW_IMAGEFILE_EVENT, MainFrame::OnNewImageFile)
364 EVT_MENU(NEW_PROJECTIONFILE_EVENT, MainFrame::OnNewProjectionFile)
365 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
366 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
367 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
368 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
369 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
370 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
371 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
372 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
373 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
374 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
375 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
377 EVT_SIZE(MainFrame::OnSize)
379 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
380 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
382 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
383 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
384 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
385 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
386 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
387 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
388 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
389 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
390 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
391 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
392 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
393 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
394 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
395 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
396 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
397 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
398 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
399 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
400 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
401 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
402 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
403 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
404 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
405 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
406 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
412 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
413 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
415 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
416 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
419 m_bShuttingDown = false;
422 wxMenu *file_menu = new wxMenu;
424 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
425 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
426 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
428 file_menu->AppendSeparator();
429 file_menu->Append (MAINMENU_IMPORT, "&Import...\tCtrl-M");
430 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
431 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
433 // history of files visited
434 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
435 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
438 m_pWindowMenu = new wxMenu;
439 m_pWindowMenu->UpdateUI (this);
442 wxMenu* help_menu = new wxMenu;
443 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
444 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
445 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
446 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
447 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
449 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
451 wxMenuBar* menu_bar = new wxMenuBar;
453 menu_bar->Append(file_menu, "&File");
455 menu_bar->Append(m_pWindowMenu, "&Window");
457 menu_bar->Append(help_menu, "&Help");
459 SetMenuBar(menu_bar);
464 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
465 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
466 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
467 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
471 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
472 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
473 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
474 m_iDefaultFilterXSize = 256;
475 m_iDefaultFilterYSize = 256;
476 m_dDefaultFilterParam = 1.;
477 m_dDefaultFilterBandwidth = 1.;
478 m_dDefaultFilterInputScale = 1.;
479 m_dDefaultFilterOutputScale = 1.;
480 m_iDefaultImportFormat = ImageFile::IMPORT_FORMAT_PNG;
482 wxAcceleratorEntry accelEntries[15];
483 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
484 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
485 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
486 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('M'), MAINMENU_IMPORT);
487 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
489 for (i = 0; i < 10; i++)
490 accelEntries[i+5].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
491 wxAcceleratorTable accelTable (15, accelEntries);
493 wxAcceleratorTable accelTable (5, accelEntries);
496 SetAcceleratorTable (accelTable);
499 MainFrame::~MainFrame()
501 m_bShuttingDown = true; // Currently used so that Log Window will close
503 // delete all non-modified documents
504 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
505 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
506 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
507 if (pDoc && ! pDoc->IsModified()) {
508 theApp->getDocManager()->RemoveDocument(pDoc);
514 if (theApp->getConfig())
515 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
517 delete theApp->getDocManager();
522 MainFrame::OnSize (wxSizeEvent& event)
525 if (theApp->getLogDoc()) {
527 GetClientSize(&xSize, &ySize);
528 int yLogSize = ySize / 4;
529 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
530 theApp->getLogDoc()->getView()->getFrame()->Show (true);
535 wxDocMDIParentFrame::OnSize (event);
537 wxDocParentFrame::OnSize (event);
542 MainFrame::OnCreatePhantom(wxCommandEvent& event)
544 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
545 int dialogReturn = dialogPhantom.ShowModal();
546 if (dialogReturn == wxID_OK) {
547 wxString selection (dialogPhantom.getPhantom());
548 if (theApp->getVerboseLogging())
549 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
550 wxString filename = selection + ".phm";
551 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
552 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
558 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
560 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
561 int dialogReturn = dialogFilter.ShowModal();
562 if (dialogReturn == wxID_OK) {
563 wxString strFilter (dialogFilter.getFilterName());
564 wxString strDomain (dialogFilter.getDomainName());
565 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
566 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
567 m_iDefaultFilterXSize = dialogFilter.getXSize();
568 m_iDefaultFilterYSize = dialogFilter.getYSize();
569 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
570 m_dDefaultFilterParam= dialogFilter.getFilterParam();
571 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
572 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
573 std::ostringstream os;
574 os << "Generate Filter=" << strFilter.c_str()
575 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
576 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
577 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
578 *theApp->getLog() << os.str().c_str() << "\n";
579 wxString filename = "untitled.if";
580 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
581 pFilterDoc->setBadFileOpen();
583 sys_error (ERR_SEVERE, "Unable to create filter image");
586 ImageFile& rIF = pFilterDoc->getImageFile();
587 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
588 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
589 rIF.labelAdd (os.str().c_str());
590 if (theApp->getAskDeleteNewDocs())
591 pFilterDoc->Modify (true);
592 pFilterDoc->UpdateAllViews();
593 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
594 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
595 pFilterDoc->getView()->getFrame()->Show(true);
600 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
602 const ImageFile& rIF = pIFDoc->getImageFile();
603 unsigned int nx = rIF.nx();
604 unsigned int ny = rIF.ny();
605 wxList& rListDocs = m_docManager->GetDocuments();
606 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
607 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
608 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
609 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
610 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
611 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
612 vecIF.push_back (pIFCompareDoc);
619 MainFrame::OnNewImageFile (wxCommandEvent& event)
621 ImageFile* pImageFile = reinterpret_cast<ImageFile*>(event.GetClientData());
623 ImageFileDocument* pImageDoc = theApp->newImageDoc();
625 sys_error (ERR_SEVERE, "Unable to create image file");
628 pImageDoc->setImageFile (pImageFile);
629 if (theApp->getAskDeleteNewDocs())
630 pImageDoc->Modify (true);
634 MainFrame::OnNewProjectionFile (wxCommandEvent& event)
636 Projections* pProjections = reinterpret_cast<Projections*>(event.GetClientData());
637 ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
639 sys_error (ERR_SEVERE, "Unable to create projection file");
642 pProjDoc->setProjections (pProjections);
643 if (theApp->getAskDeleteNewDocs())
644 pProjDoc->Modify (true);
648 MainFrame::OnLogEvent (wxCommandEvent& event)
650 *theApp->getLog() << event.GetString();
654 MainFrame::OnHelpTips (wxCommandEvent& event)
660 MainFrame::OnHelpContents (wxCommandEvent& event)
662 showHelp (event.GetId());
666 MainFrame::OnHelpButton (wxCommandEvent& event)
668 showHelp (event.GetId());
671 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
673 MainFrame::OnHelpSecondary (wxCommandEvent& event)
675 m_htmlHelp.Display ("Contents");
680 MainFrame::showHelp (int commandID)
684 case MAINMENU_HELP_CONTENTS:
686 m_winHelp.DisplayContents ();
688 m_htmlHelp.Display ("Contents");
695 m_winHelp.DisplaySection (commandID);
697 m_htmlHelp.Display (commandID);
704 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
710 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
714 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
715 wxNode* pNode = rListDocs.GetFirst();
716 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
717 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
718 wxString strFilename = pDoc->GetFilename();
720 strFilename += "\tCtrl-";
721 strFilename += static_cast<char>('0' + iPos);
723 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
724 m_apWindowMenuData[iPos] = pDoc;
725 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
727 pNode = pNode->GetNext();
729 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
730 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
731 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
732 m_apWindowMenuData[i] = NULL;
739 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
741 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
742 wxString strFilename = pDoc->GetFilename();
743 const wxView* pView = pDoc->GetFirstView();
745 wxFrame* pFrame = pView->GetFrame();
752 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
753 { DoWindowMenu (0, event); }
755 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
756 { DoWindowMenu (1, event); }
758 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
759 { DoWindowMenu (2, event); }
761 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
762 { DoWindowMenu (3, event); }
764 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
765 { DoWindowMenu (4, event); }
767 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
768 { DoWindowMenu (5, event); }
770 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
771 { DoWindowMenu (6, event); }
773 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
774 { DoWindowMenu (7, event); }
776 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
777 { DoWindowMenu (8, event); }
779 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
780 { DoWindowMenu (9, event); }
782 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
783 { DoWindowMenu (10, event); }
785 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
786 { DoWindowMenu (11, event); }
788 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
789 { DoWindowMenu (12, event); }
791 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
792 { DoWindowMenu (13, event); }
794 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
795 { DoWindowMenu (14, event); }
797 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
798 { DoWindowMenu (15, event); }
800 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
801 { DoWindowMenu (16, event); }
803 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
804 { DoWindowMenu (17, event); }
806 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
807 { DoWindowMenu (18, event); }
809 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
810 { DoWindowMenu (19, event); }
813 class BitmapControl : public wxPanel
816 DECLARE_DYNAMIC_CLASS (BitmapControl)
817 DECLARE_EVENT_TABLE ()
821 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
822 const wxPoint& pos = wxDefaultPosition,
823 const wxSize& size = wxDefaultSize,
824 long style = wxSTATIC_BORDER,
825 const wxValidator& validator = wxDefaultValidator,
826 const wxString& name = "BitmapCtrl");
829 virtual ~BitmapControl();
831 virtual wxSize GetBestSize() const;
833 wxBitmap* getBitmap()
834 { return m_pBitmap; }
836 void OnPaint(wxPaintEvent& event);
840 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
841 EVT_PAINT(BitmapControl::OnPaint)
844 IMPLEMENT_CLASS(BitmapControl, wxPanel)
847 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
848 long style, const wxValidator& validator, const wxString& name)
851 Create(parent, id, pos, size, style, name);
853 SetSize (GetBestSize());
857 BitmapControl::GetBestSize () const
860 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
865 BitmapControl::~BitmapControl()
869 BitmapControl::OnPaint (wxPaintEvent& event)
873 dc.DrawBitmap (*m_pBitmap, 0, 0);
877 class BitmapDialog : public wxDialog {
879 BitmapControl* m_pBitmapCtrl;
882 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
883 virtual ~BitmapDialog();
886 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
887 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
889 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
891 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
893 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
894 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
895 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
897 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
899 SetAutoLayout (true);
900 SetSizer (pTopSizer);
901 pTopSizer->Fit (this);
902 pTopSizer->SetSizeHints (this);
905 BitmapDialog::~BitmapDialog()
910 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
912 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
913 theApp->getAskDeleteNewDocs(), theApp->getVerboseLogging(), theApp->getStartupTips(),
914 theApp->getUseBackgroundTasks());
915 if (dlg.ShowModal() == wxID_OK) {
916 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
917 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
918 theApp->setVerboseLogging (dlg.getVerboseLogging());
919 theApp->setStartupTips (dlg.getStartupTips());
920 theApp->setUseBackgroundTasks (dlg.getUseBackgroundTasks());
925 MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
927 DialogImportParameters dialogImport (this, m_iDefaultImportFormat);
928 if (dialogImport.ShowModal() != wxID_OK)
931 wxString strFormatName (dialogImport.getFormatName ());
932 m_iDefaultImportFormat = ImageFile::convertImportFormatNameToID (strFormatName.c_str());
935 wxString strWildcard;
936 if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM) {
938 strWildcard = "PPM Files (*.ppm)|*.ppm|PGM Files (*.pgm)|*.pgm";
941 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
943 strWildcard = "PNG Files (*.png)|*.png";
946 #ifdef HAVE_CTN_DICOM
947 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
949 strWildcard = "Dicom Files (*.*)|*.*";
956 wxString strFilename = wxFileSelector (wxString("Import Filename"), wxString(""),
957 wxString(""), strExt, strWildcard, wxHIDE_READONLY | wxOPEN);
958 if (! strFilename.IsEmpty()) {
959 if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
960 ImageFile* pIF = new ImageFile;
961 if (pIF->importImage (strFormatName.c_str(), strFilename.c_str())) {
962 ImageFileDocument* pIFDoc = theApp->newImageDoc();
963 pIFDoc->setImageFile(pIF);
964 pIFDoc->getView()->getFrame()->Show(true);
965 std::ostringstream os;
966 os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
967 pIF->labelAdd (os.str().c_str());
968 if (theApp->getAskDeleteNewDocs())
969 pIFDoc->Modify (true);
970 pIFDoc->UpdateAllViews();
971 pIFDoc->GetFirstView()->OnUpdate (NULL, NULL);
972 pIFDoc->getView()->getFrame()->Show(true);
976 #ifdef HAVE_CTN_DICOM
977 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
978 DicomImporter dicomImport (strFilename.c_str());
979 if (dicomImport.fail()) {
980 ::wxMessageBox (dicomImport.failMessage().c_str(), "Import Error");
981 } else if (dicomImport.testImage()) {
982 ImageFileDocument* pIFDoc = theApp->newImageDoc();
983 ImageFile* pIF = dicomImport.getImageFile();
984 pIFDoc->setImageFile (pIF);
985 pIFDoc->getView()->getFrame()->Show(true);
986 std::ostringstream os;
987 os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
988 pIF->labelAdd (os.str().c_str());
989 if (theApp->getAskDeleteNewDocs())
990 pIFDoc->Modify (true);
991 pIFDoc->UpdateAllViews();
992 pIFDoc->GetFirstView()->OnUpdate (NULL, NULL);
993 pIFDoc->getView()->getFrame()->Show(true);
994 } else if (dicomImport.testProjections()) {
995 ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
996 Projections* pProj = dicomImport.getProjections();
997 pProjDoc->setProjections (pProj);
998 pProjDoc->getView()->getFrame()->Show(true);
999 std::ostringstream os;
1000 os << "Import projection file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
1001 pProj->setRemark (os.str().c_str());
1002 if (theApp->getAskDeleteNewDocs())
1003 pProjDoc->Modify (true);
1004 pProjDoc->UpdateAllViews();
1005 pProjDoc->GetFirstView()->OnUpdate (NULL, NULL);
1006 pProjDoc->getView()->getFrame()->Show(true);
1008 ::wxMessageBox ("Unrecognized DICOM file contents", "Import Error");
1012 sys_error (ERR_WARNING, "Unknown import format type");
1016 #include "./splash.xpm"
1018 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
1020 long lFreeMem = ::wxGetFreeMemory() / (1024L * 1024L);
1021 wxString strOSDesc = ::wxGetOsDescription();
1022 *theApp->getLog() << "Operating System: " << strOSDesc;
1024 *theApp->getLog() << ", Free Memory: " << lFreeMem << " MB";
1025 *theApp->getLog() << ", wxWindows: " << wxVERSION_STRING;
1026 #ifdef __TIMESTAMP__
1027 *theApp->getLog() << ", Build Date: " << __TIMESTAMP__;
1030 *theApp->getLog() << ", CTSim Debug version";
1032 *theApp->getLog() << ", CTSim Release version";
1035 *theApp->getLog() << "\n";
1037 wxBitmap bmp (splash);
1039 BitmapDialog dlg (&bmp, "About CTSim");
1042 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
1045 msg += CTSIMVERSION;
1047 #elif defined(VERSION)
1048 msg << "Version: " << VERSION << "\n\n";
1050 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
1052 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
1053 *theApp->getLog() << msg << "\n";
1058 ProjectionFileDocument*
1059 CTSimApp::newProjectionDoc()
1061 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
1063 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
1064 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
1065 newDoc->OnNewDocument();
1072 CTSimApp::newImageDoc()
1074 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
1076 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
1077 newDoc->SetDocumentTemplate (m_pDocTemplImage);
1078 newDoc->OnNewDocument();
1085 CTSimApp::newPlotDoc()
1087 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
1089 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
1090 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
1091 newDoc->OnNewDocument();
1099 CTSimApp::newTextDoc()
1101 wxString strFilename (getUntitledFilename());
1102 strFilename += ".txt";
1104 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
1106 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
1107 newDoc->SetDocumentTemplate (m_pDocTemplText);
1108 newDoc->OnNewDocument();
1115 PhantomFileDocument*
1116 CTSimApp::newPhantomDoc()
1118 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
1120 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
1121 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
1122 newDoc->OnNewDocument();
1130 Graph3dFileDocument*
1131 CTSimApp::newGraph3dDoc()
1133 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
1135 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
1136 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
1137 newDoc->OnNewDocument();