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.121 2003/01/24 05:24:18 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.121 2003/01/24 05:24:18 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;
116 int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
123 std::cout << rcsindent << std::endl;
125 std::cout << "Version: " << VERSION << std::endl;
\r
126 #elif defined(CTSIMVERSION)
\r
127 std::cout << "Version: " << CTSIMVERSION << std::endl;
143 m_docManager = new wxDocManager (wxDEFAULT_DOCMAN_FLAGS, true);
145 m_pDocTemplImage = new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile", "ImageView", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
146 m_pDocTemplProjection = new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile", "ProjectionView", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
147 m_pDocTemplPhantom = new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "PhantomFile", "PhantomView", CLASSINFO(PhantomFileDocument), CLASSINFO(PhantomFileView));
148 m_pDocTemplPlot = new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "PlotFile", "PlotView", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
149 m_pDocTemplText = new wxDocTemplate (m_docManager, "TextFile", "*.txt", "", "txt", "TextFile", "TextView", CLASSINFO(TextFileDocument), CLASSINFO(TextFileView), wxTEMPLATE_INVISIBLE);
151 m_pDocTemplGraph3d = new wxDocTemplate (m_docManager, "Graph3dFile", "*.g3d", "", "g3d", "Graph3dFile", "Graph3dView", CLASSINFO(Graph3dFileDocument), CLASSINFO(Graph3dFileView), wxTEMPLATE_INVISIBLE);
155 wxImage::AddHandler(new wxGIFHandler); // Required for images in the online documentation
158 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
159 wxFileSystem::AddHandler(new wxZipFSHandler); // Required for advanced HTML help
162 // Create the main frame window
163 int xDisplay, yDisplay;
164 ::wxDisplaySize (&xDisplay, &yDisplay);
166 m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0),
168 wxSize(nearest<int>(xDisplay * .75), nearest<int>(yDisplay * .75)),
170 wxSize(nearest<int>(xDisplay * .6), nearest<int>(yDisplay * .4)),
172 wxDEFAULT_FRAME_STYLE);
174 setIconForFrame (m_pFrame);
175 m_pFrame->Centre(wxBOTH);
176 m_pFrame->Show(true);
177 SetTopWindow (m_pFrame);
180 m_docManager->FileHistoryLoad(*m_pConfig);
183 m_pLogDoc = newTextDoc();
185 m_pLog = m_pLogDoc->getTextCtrl();
186 m_pLogDoc->SetDocumentName("Log.txt");
187 m_pLogDoc->SetFilename("Log.txt");
188 m_pLogDoc->getView()->getFrame()->SetTitle("Log");
190 m_pFrame->GetClientSize(&xSize, &ySize);
191 int yLogSize = ySize / 4;
192 m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
193 m_pLogDoc->getView()->getFrame()->Show (true);
196 m_pLog = new wxTextCtrl (m_pFrame, -1, "Log Window\n", wxPoint(0, 0), wxSize(0,0), wxTE_MULTILINE | wxTE_READONLY);
198 wxLog::SetActiveTarget (new wxLogTextCtrl(m_pLog));
201 if (! m_pConfig->Read("HelpDir", &helpDir))
202 helpDir = ::wxGetCwd();
\r
204 if (! m_pFrame->getWinHelpController().Initialize(helpDir + "/ctsim"))
205 *m_pLog << "Cannot initialize the Windows Help system" << "\n";
208 wxString docDir (DATADIR);
\r
210 wxString docDir (::wxGetCwd());
\r
212 wxString docFile = docDir + "ctsim.htb";
213 if (! m_pFrame->getHtmlHelpController().AddBook(docFile) &&
214 ! m_pFrame->getHtmlHelpController().AddBook("/usr/share/ctsim/ctsim.htb") &&
215 ! m_pFrame->getHtmlHelpController().AddBook("/tmp/ctsim.htb"))
\r
216 *m_pLog << "Cannot initialize the HTML Help system" << "\n";
218 if (::wxDirExists ("/tmp"))
219 m_pFrame->getHtmlHelpController().SetTempDir(_T("/tmp"));
220 m_pFrame->getHtmlHelpController().UseConfig (m_pConfig);
224 for (int i = optind + 1; i <= argc; i++) {
225 wxString filename = argv [i - 1];
226 wxDocument* pNewDoc = m_docManager->CreateDocument (filename, wxDOC_SILENT);
228 wxView* pNewView = pNewDoc->GetFirstView();
229 wxPrintout *printout = pNewView->OnCreatePrintout();
232 printer.Print(pNewView->GetFrame(), printout, TRUE);
235 wxCommandEvent nullEvent;
236 nullEvent.SetId (wxID_CLOSE);
237 m_docManager->OnFileClose (nullEvent);
241 wxCommandEvent closeEvent;
242 closeEvent.SetInt (MAINMENU_FILE_EXIT);
243 m_pFrame->AddPendingEvent(closeEvent);
246 if (getStartupTips())
249 #ifdef HAVE_WXTHREADS
250 m_pBackgroundMgr = new BackgroundManager;
259 CTSimTipProvider tipProvider (m_iCurrentTip);
260 setStartupTips (::wxShowTip (m_pFrame, &tipProvider, getStartupTips()));
261 m_iCurrentTip = tipProvider.GetCurrentTip();
265 #include "./ctsim.xpm"
267 CTSimApp::setIconForFrame(wxFrame* pFrame)
269 wxIcon iconApp (ctsim16_xpm);
272 pFrame->SetIcon (iconApp);
276 CTSimApp::usage(const char* program)
278 std::cout << "usage: " << fileBasename(program) << " [files-to-open...] [OPTIONS]\n";
279 std::cout << "Computed Tomography Simulator (Graphical Shell)\n";
281 std::cout << " --version Display version\n";
282 std::cout << " --help Display this help message\n";
297 CTSimApp::openConfig()
300 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", "", "", wxCONFIG_USE_LOCAL_FILE);
302 m_pConfig = new wxConfig("ctsim", "Kevin Rosenberg", ".ctsim", "", wxCONFIG_USE_LOCAL_FILE);
305 wxConfigBase::Set(m_pConfig);
306 m_pConfig->Read ("AdvancedOptions", &m_bAdvancedOptions);
307 m_pConfig->Read ("SetModifyNewDocs", &m_bSetModifyNewDocs);
308 m_pConfig->Read ("VerboseLogging", &m_bVerboseLogging);
309 m_pConfig->Read ("StartupTips", &m_bShowStartupTips);
310 m_pConfig->Read ("CurrentTip", &m_iCurrentTip);
311 m_pConfig->Read ("UseBackgroundTasks", &m_bUseBackgroundTasks);
313 wxString strFftwWisdom;
314 m_pConfig->Read ("FftwWisdom", strFftwWisdom);
315 if (strFftwWisdom.size() > 0)
316 fftw_import_wisdom_from_string (strFftwWisdom.c_str());
321 CTSimApp::closeConfig()
323 m_pConfig->Write ("AdvancedOptions", m_bAdvancedOptions);
324 m_pConfig->Write ("SetModifyNewDocs", m_bSetModifyNewDocs);
325 m_pConfig->Write ("VerboseLogging", m_bVerboseLogging);
326 m_pConfig->Write ("StartupTips", m_bShowStartupTips);
327 m_pConfig->Write ("CurrentTip", m_iCurrentTip);
328 m_pConfig->Write ("UseBackgroundTasks", m_bUseBackgroundTasks);
330 const char* const pszWisdom = fftw_export_wisdom_to_string();
331 wxString strFftwWisdom (pszWisdom);
332 fftw_free ((void*) pszWisdom);
333 m_pConfig->Write ("FftwWisdom", strFftwWisdom);
341 CTSimApp::getUntitledFilename()
343 static int untitledNumber = 1;
345 wxString filename ("Untitled");
346 filename << untitledNumber++;
352 // Top-level window for CTSim
355 IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
357 BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
359 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
361 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
364 EVT_MENU(MAINMENU_FILE_PREFERENCES, MainFrame::OnPreferences)
365 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
366 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
367 EVT_MENU(MAINMENU_HELP_TIPS, MainFrame::OnHelpTips)
368 EVT_MENU(MAINMENU_IMPORT, MainFrame::OnImport)
369 EVT_MENU(IDH_QUICKSTART, MainFrame::OnHelpButton)
370 EVT_MENU(MAINMENU_LOG_EVENT, MainFrame::OnLogEvent)
371 EVT_MENU(NEW_IMAGEFILE_EVENT, MainFrame::OnNewImageFile)
372 EVT_MENU(NEW_PROJECTIONFILE_EVENT, MainFrame::OnNewProjectionFile)
373 EVT_BUTTON(IDH_DLG_RASTERIZE, MainFrame::OnHelpButton)
374 EVT_BUTTON(IDH_DLG_PROJECTIONS, MainFrame::OnHelpButton)
375 EVT_BUTTON(IDH_DLG_RECONSTRUCTION, MainFrame::OnHelpButton)
376 EVT_BUTTON(IDH_DLG_FILTER, MainFrame::OnHelpButton)
377 EVT_BUTTON(IDH_DLG_MINMAX, MainFrame::OnHelpButton)
378 EVT_BUTTON(IDH_DLG_EXPORT, MainFrame::OnHelpButton)
379 EVT_BUTTON(IDH_DLG_PHANTOM, MainFrame::OnHelpButton)
380 EVT_BUTTON(IDH_DLG_COMPARISON, MainFrame::OnHelpButton)
381 EVT_BUTTON(IDH_DLG_PREFERENCES, MainFrame::OnHelpButton)
382 EVT_BUTTON(IDH_DLG_POLAR, MainFrame::OnHelpButton)
383 EVT_BUTTON(IDH_DLG_AUTOSCALE, MainFrame::OnHelpButton)
385 EVT_SIZE(MainFrame::OnSize)
387 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
388 EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
390 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
391 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
392 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
393 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
394 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
395 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
396 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
397 EVT_MENU(MAINMENU_WINDOW_BASE+3, MainFrame::OnWindowMenu3)
398 EVT_MENU(MAINMENU_WINDOW_BASE+4, MainFrame::OnWindowMenu4)
399 EVT_MENU(MAINMENU_WINDOW_BASE+5, MainFrame::OnWindowMenu5)
400 EVT_MENU(MAINMENU_WINDOW_BASE+6, MainFrame::OnWindowMenu6)
401 EVT_MENU(MAINMENU_WINDOW_BASE+7, MainFrame::OnWindowMenu7)
402 EVT_MENU(MAINMENU_WINDOW_BASE+8, MainFrame::OnWindowMenu8)
403 EVT_MENU(MAINMENU_WINDOW_BASE+9, MainFrame::OnWindowMenu9)
404 EVT_MENU(MAINMENU_WINDOW_BASE+10, MainFrame::OnWindowMenu10)
405 EVT_MENU(MAINMENU_WINDOW_BASE+11, MainFrame::OnWindowMenu11)
406 EVT_MENU(MAINMENU_WINDOW_BASE+12, MainFrame::OnWindowMenu12)
407 EVT_MENU(MAINMENU_WINDOW_BASE+13, MainFrame::OnWindowMenu13)
408 EVT_MENU(MAINMENU_WINDOW_BASE+14, MainFrame::OnWindowMenu14)
409 EVT_MENU(MAINMENU_WINDOW_BASE+15, MainFrame::OnWindowMenu15)
410 EVT_MENU(MAINMENU_WINDOW_BASE+16, MainFrame::OnWindowMenu16)
411 EVT_MENU(MAINMENU_WINDOW_BASE+17, MainFrame::OnWindowMenu17)
412 EVT_MENU(MAINMENU_WINDOW_BASE+18, MainFrame::OnWindowMenu18)
413 EVT_MENU(MAINMENU_WINDOW_BASE+19, MainFrame::OnWindowMenu19)
414 EVT_UPDATE_UI_RANGE(MAINMENU_WINDOW_BASE, MAINMENU_WINDOW_BASE+20, MainFrame::OnUpdateUI)
420 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
421 : wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
423 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
424 : wxDocParentFrame(manager, frame, id, title, pos, size, type, "MainFrame")
427 m_bShuttingDown = false;
430 wxMenu *file_menu = new wxMenu;
432 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
433 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
434 file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
436 file_menu->AppendSeparator();
437 file_menu->Append (MAINMENU_IMPORT, "&Import...\tCtrl-M");
438 file_menu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
439 file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
441 // history of files visited
442 theApp->getDocManager()->FileHistoryAddFilesToMenu(file_menu);
443 theApp->getDocManager()->FileHistoryUseMenu(file_menu);
446 m_pWindowMenu = new wxMenu;
447 m_pWindowMenu->UpdateUI (this);
450 wxMenu* help_menu = new wxMenu;
451 help_menu->Append (MAINMENU_HELP_CONTENTS, "&Contents\tF1");
452 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
453 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
454 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
455 help_menu->Append (MAINMENU_HELP_SECONDARY, "&Secondary Help");
457 help_menu->Append (MAINMENU_HELP_ABOUT, "&About");
459 wxMenuBar* menu_bar = new wxMenuBar;
461 menu_bar->Append(file_menu, "&File");
463 menu_bar->Append(m_pWindowMenu, "&Window");
465 menu_bar->Append(help_menu, "&Help");
467 SetMenuBar(menu_bar);
472 for (i = 0; i < MAX_WINDOW_MENUITEMS; i++) {
473 m_apWindowMenuItems[i] = new wxMenuItem (m_pWindowMenu, MAINMENU_WINDOW_BASE+i, wxString("[EMPTY]"));
474 m_pWindowMenu->Append (m_apWindowMenuItems[i]);
475 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
479 m_iDefaultPhantomID = Phantom::PHM_HERMAN;
480 m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT;
481 m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY;
482 m_iDefaultFilterXSize = 256;
483 m_iDefaultFilterYSize = 256;
484 m_dDefaultFilterParam = 1.;
485 m_dDefaultFilterBandwidth = 1.;
486 m_dDefaultFilterInputScale = 1.;
487 m_dDefaultFilterOutputScale = 1.;
488 m_iDefaultImportFormat = ImageFile::IMPORT_FORMAT_PNG;
490 wxAcceleratorEntry accelEntries[15];
491 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
492 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
493 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
494 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('M'), MAINMENU_IMPORT);
495 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
497 for (i = 0; i < 10; i++)
498 accelEntries[i+5].Set (wxACCEL_CTRL, static_cast<int>('0'+i), MAINMENU_WINDOW_BASE+i);
499 wxAcceleratorTable accelTable (15, accelEntries);
501 wxAcceleratorTable accelTable (5, accelEntries);
504 SetAcceleratorTable (accelTable);
507 MainFrame::~MainFrame()
509 m_bShuttingDown = true; // Currently used so that Log Window will close
511 // delete all non-modified documents
512 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
513 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
514 wxDocument* pDoc = dynamic_cast<wxDocument*>(pNode->GetData());
515 if (pDoc && ! pDoc->IsModified()) {
516 theApp->getDocManager()->RemoveDocument(pDoc);
522 if (theApp->getConfig())
523 theApp->getDocManager()->FileHistorySave (*theApp->getConfig());
525 delete theApp->getDocManager();
530 MainFrame::OnSize (wxSizeEvent& event)
533 if (theApp->getLogDoc()) {
535 GetClientSize(&xSize, &ySize);
536 int yLogSize = ySize / 4;
537 theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize);
538 theApp->getLogDoc()->getView()->getFrame()->Show (true);
543 wxDocMDIParentFrame::OnSize (event);
545 wxDocParentFrame::OnSize (event);
550 MainFrame::OnCreatePhantom(wxCommandEvent& event)
552 DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
553 int dialogReturn = dialogPhantom.ShowModal();
554 if (dialogReturn == wxID_OK) {
555 wxString selection (dialogPhantom.getPhantom());
556 if (theApp->getVerboseLogging())
557 *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n";
558 wxString filename = selection + ".phm";
559 m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str());
560 theApp->getDocManager()->CreateDocument (filename, wxDOC_SILENT);
566 MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
568 DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
569 int dialogReturn = dialogFilter.ShowModal();
570 if (dialogReturn == wxID_OK) {
571 wxString strFilter (dialogFilter.getFilterName());
572 wxString strDomain (dialogFilter.getDomainName());
573 m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str());
574 m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str());
575 m_iDefaultFilterXSize = dialogFilter.getXSize();
576 m_iDefaultFilterYSize = dialogFilter.getYSize();
577 m_dDefaultFilterBandwidth = dialogFilter.getBandwidth();
578 m_dDefaultFilterParam= dialogFilter.getFilterParam();
579 m_dDefaultFilterInputScale = dialogFilter.getInputScale();
580 m_dDefaultFilterOutputScale = dialogFilter.getOutputScale();
581 std::ostringstream os;
582 os << "Generate Filter=" << strFilter.c_str()
583 << ", size=(" << static_cast<int>(m_iDefaultFilterXSize) << "," << static_cast<int>(m_iDefaultFilterYSize)
584 << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth
585 << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale;
586 *theApp->getLog() << os.str().c_str() << "\n";
587 wxString filename = "untitled.if";
588 ImageFileDocument* pFilterDoc = theApp->newImageDoc();
589 pFilterDoc->setBadFileOpen();
591 sys_error (ERR_SEVERE, "Unable to create filter image");
594 ImageFile& rIF = pFilterDoc->getImageFile();
595 rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize);
596 rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale);
597 rIF.labelAdd (os.str().c_str());
598 if (theApp->getAskDeleteNewDocs())
599 pFilterDoc->Modify (true);
600 pFilterDoc->UpdateAllViews();
601 pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL);
602 pFilterDoc->getView()->getFrame()->SetClientSize(m_iDefaultFilterXSize, m_iDefaultFilterYSize);
603 pFilterDoc->getView()->getFrame()->Show(true);
608 CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<ImageFileDocument*>& vecIF)
610 const ImageFile& rIF = pIFDoc->getImageFile();
611 unsigned int nx = rIF.nx();
612 unsigned int ny = rIF.ny();
613 wxList& rListDocs = m_docManager->GetDocuments();
614 for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {
615 wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());
616 ImageFileDocument* pIFCompareDoc = dynamic_cast<ImageFileDocument*>(pDoc);
617 if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) {
618 const ImageFile& rCompareIF = pIFCompareDoc->getImageFile();
619 if (rCompareIF.nx() == nx && rCompareIF.ny() == ny)
620 vecIF.push_back (pIFCompareDoc);
627 MainFrame::OnNewImageFile (wxCommandEvent& event)
629 ImageFile* pImageFile = reinterpret_cast<ImageFile*>(event.GetClientData());
631 ImageFileDocument* pImageDoc = theApp->newImageDoc();
633 sys_error (ERR_SEVERE, "Unable to create image file");
636 pImageDoc->setImageFile (pImageFile);
637 if (theApp->getAskDeleteNewDocs())
638 pImageDoc->Modify (true);
642 MainFrame::OnNewProjectionFile (wxCommandEvent& event)
644 Projections* pProjections = reinterpret_cast<Projections*>(event.GetClientData());
645 ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
647 sys_error (ERR_SEVERE, "Unable to create projection file");
650 pProjDoc->setProjections (pProjections);
651 if (theApp->getAskDeleteNewDocs())
652 pProjDoc->Modify (true);
656 MainFrame::OnLogEvent (wxCommandEvent& event)
658 *theApp->getLog() << event.GetString();
662 MainFrame::OnHelpTips (wxCommandEvent& event)
668 MainFrame::OnHelpContents (wxCommandEvent& event)
670 showHelp (event.GetId());
674 MainFrame::OnHelpButton (wxCommandEvent& event)
676 showHelp (event.GetId());
679 #if defined(CTSIM_WINHELP) && (defined(DEBUG) || defined(_DEBUG))
681 MainFrame::OnHelpSecondary (wxCommandEvent& event)
683 m_htmlHelp.Display ("Contents");
688 MainFrame::showHelp (int commandID)
692 case MAINMENU_HELP_CONTENTS:
694 m_winHelp.DisplayContents ();
696 m_htmlHelp.Display ("Contents");
702 m_winHelp.DisplaySection (commandID);
704 m_htmlHelp.Display (commandID);
711 MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) )
717 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
721 wxList& rListDocs = theApp->getDocManager()->GetDocuments();
722 wxNode* pNode = rListDocs.GetFirst();
723 while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
724 wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());
725 wxString strFilename = pDoc->GetFilename();
727 strFilename += "\tCtrl-";
728 strFilename += static_cast<char>('0' + iPos);
730 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[iPos])->SetName (strFilename);
731 m_apWindowMenuData[iPos] = pDoc;
732 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+iPos, true);
734 pNode = pNode->GetNext();
736 for (int i = iPos; i < MAX_WINDOW_MENUITEMS; i++) {
737 m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false);
738 static_cast<wxMenuItemBase*>(m_apWindowMenuItems[i])->SetName (wxString("[EMPTY]"));
739 m_apWindowMenuData[i] = NULL;
746 MainFrame::DoWindowMenu (int iMenuPosition, wxCommandEvent& event)
748 if (wxDocument* pDoc = m_apWindowMenuData [iMenuPosition]) {
749 wxString strFilename = pDoc->GetFilename();
750 const wxView* pView = pDoc->GetFirstView();
752 wxWindow* pWindow = pView->GetFrame();
759 void MainFrame::OnWindowMenu0 (wxCommandEvent& event)
760 { DoWindowMenu (0, event); }
762 void MainFrame::OnWindowMenu1 (wxCommandEvent& event)
763 { DoWindowMenu (1, event); }
765 void MainFrame::OnWindowMenu2 (wxCommandEvent& event)
766 { DoWindowMenu (2, event); }
768 void MainFrame::OnWindowMenu3 (wxCommandEvent& event)
769 { DoWindowMenu (3, event); }
771 void MainFrame::OnWindowMenu4 (wxCommandEvent& event)
772 { DoWindowMenu (4, event); }
774 void MainFrame::OnWindowMenu5 (wxCommandEvent& event)
775 { DoWindowMenu (5, event); }
777 void MainFrame::OnWindowMenu6 (wxCommandEvent& event)
778 { DoWindowMenu (6, event); }
780 void MainFrame::OnWindowMenu7 (wxCommandEvent& event)
781 { DoWindowMenu (7, event); }
783 void MainFrame::OnWindowMenu8 (wxCommandEvent& event)
784 { DoWindowMenu (8, event); }
786 void MainFrame::OnWindowMenu9 (wxCommandEvent& event)
787 { DoWindowMenu (9, event); }
789 void MainFrame::OnWindowMenu10 (wxCommandEvent& event)
790 { DoWindowMenu (10, event); }
792 void MainFrame::OnWindowMenu11 (wxCommandEvent& event)
793 { DoWindowMenu (11, event); }
795 void MainFrame::OnWindowMenu12 (wxCommandEvent& event)
796 { DoWindowMenu (12, event); }
798 void MainFrame::OnWindowMenu13 (wxCommandEvent& event)
799 { DoWindowMenu (13, event); }
801 void MainFrame::OnWindowMenu14 (wxCommandEvent& event)
802 { DoWindowMenu (14, event); }
804 void MainFrame::OnWindowMenu15 (wxCommandEvent& event)
805 { DoWindowMenu (15, event); }
807 void MainFrame::OnWindowMenu16 (wxCommandEvent& event)
808 { DoWindowMenu (16, event); }
810 void MainFrame::OnWindowMenu17 (wxCommandEvent& event)
811 { DoWindowMenu (17, event); }
813 void MainFrame::OnWindowMenu18 (wxCommandEvent& event)
814 { DoWindowMenu (18, event); }
816 void MainFrame::OnWindowMenu19 (wxCommandEvent& event)
817 { DoWindowMenu (19, event); }
820 class BitmapControl : public wxPanel
823 DECLARE_DYNAMIC_CLASS (BitmapControl)
824 DECLARE_EVENT_TABLE ()
828 BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
829 const wxPoint& pos = wxDefaultPosition,
830 const wxSize& size = wxDefaultSize,
831 long style = wxSTATIC_BORDER,
832 const wxValidator& validator = wxDefaultValidator,
833 const wxString& name = "BitmapCtrl");
836 virtual ~BitmapControl();
838 virtual wxSize GetBestSize() const;
840 wxBitmap* getBitmap()
841 { return m_pBitmap; }
843 void OnPaint(wxPaintEvent& event);
847 BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
848 EVT_PAINT(BitmapControl::OnPaint)
851 IMPLEMENT_CLASS(BitmapControl, wxPanel)
854 BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
855 long style, const wxValidator& validator, const wxString& name)
858 Create(parent, id, pos, size, style, name);
860 SetSize (GetBestSize());
864 BitmapControl::GetBestSize () const
867 return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
872 BitmapControl::~BitmapControl()
876 BitmapControl::OnPaint (wxPaintEvent& event)
880 dc.DrawBitmap (*m_pBitmap, 0, 0);
884 class BitmapDialog : public wxDialog {
886 BitmapControl* m_pBitmapCtrl;
889 BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
890 virtual ~BitmapDialog();
893 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
894 : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
896 wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
898 pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
900 wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
901 wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
902 pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
904 pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
906 SetAutoLayout (true);
907 SetSizer (pTopSizer);
908 pTopSizer->Fit (this);
909 pTopSizer->SetSizeHints (this);
912 BitmapDialog::~BitmapDialog()
917 MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
919 DialogPreferences dlg (this, "CTSim Preferences", theApp->getAdvancedOptions(),
920 theApp->getAskDeleteNewDocs(), theApp->getVerboseLogging(), theApp->getStartupTips(),
921 theApp->getUseBackgroundTasks());
922 if (dlg.ShowModal() == wxID_OK) {
923 theApp->setAdvancedOptions (dlg.getAdvancedOptions());
924 theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
925 theApp->setVerboseLogging (dlg.getVerboseLogging());
926 theApp->setStartupTips (dlg.getStartupTips());
927 theApp->setUseBackgroundTasks (dlg.getUseBackgroundTasks());
932 MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
934 DialogImportParameters dialogImport (this, m_iDefaultImportFormat);
935 if (dialogImport.ShowModal() != wxID_OK)
938 wxString strFormatName (dialogImport.getFormatName ());
939 m_iDefaultImportFormat = ImageFile::convertImportFormatNameToID (strFormatName.c_str());
942 wxString strWildcard;
943 if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM) {
945 strWildcard = "PPM Files (*.ppm)|*.ppm|PGM Files (*.pgm)|*.pgm";
948 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
950 strWildcard = "PNG Files (*.png)|*.png";
953 #ifdef HAVE_CTN_DICOM
954 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
956 strWildcard = "Dicom Files (*.*)|*.*";
963 wxString strFilename = wxFileSelector (wxString("Import Filename"), wxString(""),
964 wxString(""), strExt, strWildcard, wxHIDE_READONLY | wxOPEN);
965 if (! strFilename.IsEmpty()) {
966 if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
967 ImageFile* pIF = new ImageFile;
968 if (pIF->importImage (strFormatName.c_str(), strFilename.c_str())) {
969 ImageFileDocument* pIFDoc = theApp->newImageDoc();
970 pIFDoc->setImageFile(pIF);
971 pIFDoc->getView()->getFrame()->Show(true);
972 std::ostringstream os;
973 os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
974 pIF->labelAdd (os.str().c_str());
975 if (theApp->getAskDeleteNewDocs())
976 pIFDoc->Modify (true);
977 pIFDoc->UpdateAllViews();
978 pIFDoc->GetFirstView()->OnUpdate (NULL, NULL);
979 pIFDoc->getView()->getFrame()->Show(true);
983 #ifdef HAVE_CTN_DICOM
984 else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
985 DicomImporter dicomImport (strFilename.c_str());
986 if (dicomImport.fail()) {
987 ::wxMessageBox (dicomImport.failMessage().c_str(), "Import Error");
988 } else if (dicomImport.testImage()) {
989 ImageFileDocument* pIFDoc = theApp->newImageDoc();
990 ImageFile* pIF = dicomImport.getImageFile();
991 pIFDoc->setImageFile (pIF);
992 std::ostringstream os;
993 os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
994 pIF->labelAdd (os.str().c_str());
995 if (theApp->getAskDeleteNewDocs())
996 pIFDoc->Modify (true);
997 pIFDoc->UpdateAllViews();
998 pIFDoc->getView()->setInitialClientSize();
1000 } else if (dicomImport.testProjections()) {
1001 ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
1002 Projections* pProj = dicomImport.getProjections();
1003 pProjDoc->setProjections (pProj);
1004 pProjDoc->getView()->getFrame()->Show(true);
1005 std::ostringstream os;
1006 os << "Import projection file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
1007 pProj->setRemark (os.str().c_str());
1008 if (theApp->getAskDeleteNewDocs())
1009 pProjDoc->Modify (true);
1010 pProjDoc->UpdateAllViews();
1011 pProjDoc->getView()->setInitialClientSize();
1012 pProjDoc->Activate();
1014 ::wxMessageBox ("Unrecognized DICOM file contents", "Import Error");
1018 sys_error (ERR_WARNING, "Unknown import format type");
1022 #include "./splash.xpm"
1024 MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
1026 wxString strOSDesc = ::wxGetOsDescription();
1027 *theApp->getLog() << "Operating System: " << strOSDesc;
1028 *theApp->getLog() << ", wxWindows: " << wxVERSION_STRING;
1029 #ifdef __TIMESTAMP__
1030 *theApp->getLog() << ", Build Date: " << __TIMESTAMP__;
1033 *theApp->getLog() << ", Debug version";
1035 *theApp->getLog() << ", Release version";
1038 *theApp->getLog() << " " << VERSION;
1039 #elif defined(CTSIMVERSION)
1040 *theApp->getLog() << " " << CTSIMVERSION;
1042 *theApp->getLog() << "\n";
1044 wxBitmap bmp (splash);
1046 BitmapDialog dlg (&bmp, "About CTSim");
1049 wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
1051 msg << "Version: " << VERSION << "\n\n";
1052 #elif defined(CTSIMVERSION)
\r
1053 msg << "Version: " << CTSIMVERSION << "\n\n";
\r
1055 msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
1057 wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
1058 *theApp->getLog() << msg << "\n";
1063 // Create new documents
\r
1065 ProjectionFileDocument*
1066 CTSimApp::newProjectionDoc()
1068 ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
1070 newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
1071 newDoc->SetDocumentTemplate (m_pDocTemplProjection);
1072 newDoc->OnNewDocument();
1079 CTSimApp::newImageDoc()
1081 ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (""));
1083 newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
1084 newDoc->SetDocumentTemplate (m_pDocTemplImage);
1085 newDoc->OnNewDocument();
1092 CTSimApp::newPlotDoc()
1094 PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (""));
1096 newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
1097 newDoc->SetDocumentTemplate (m_pDocTemplPlot);
1098 newDoc->OnNewDocument();
1106 CTSimApp::newTextDoc()
1108 wxString strFilename (getUntitledFilename());
1109 strFilename += ".txt";
1111 TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
1113 newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
1114 newDoc->SetDocumentTemplate (m_pDocTemplText);
1115 newDoc->OnNewDocument();
1122 PhantomFileDocument*
1123 CTSimApp::newPhantomDoc()
1125 PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (""));
1127 newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
1128 newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
1129 newDoc->OnNewDocument();
1137 Graph3dFileDocument*
1138 CTSimApp::newGraph3dDoc()
1140 Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (""));
1142 newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
1143 newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
1144 newDoc->OnNewDocument();