+wxSize
+BitmapControl::GetBestSize () const
+{
+ if (m_pBitmap)
+ return wxSize (m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
+ else
+ return wxSize(0,0);
+}
+
+BitmapControl::~BitmapControl()
+{}
+
+void
+BitmapControl::OnPaint (wxPaintEvent& event)
+{
+ wxPaintDC dc(this);
+ if (m_pBitmap)
+ dc.DrawBitmap (*m_pBitmap, 0, 0);
+}
+
+
+class BitmapDialog : public wxDialog {
+private:
+ BitmapControl* m_pBitmapCtrl;
+
+public:
+ BitmapDialog (wxBitmap* pBitmap, char const* pszTitle);
+ virtual ~BitmapDialog();
+};
+
+BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
+ : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle,*wxConvCurrent), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
+{
+ wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
+
+ pTopSizer->Add (new BitmapControl (pBitmap, this), 0, wxALIGN_CENTER | wxALL, 5);
+
+ wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
+ wxButton* pButtonOk = new wxButton (this, wxID_OK, _T("Ok"));
+ pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
+
+ pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
+
+ SetAutoLayout (true);
+ SetSizer (pTopSizer);
+ pTopSizer->Fit (this);
+ pTopSizer->SetSizeHints (this);
+}
+
+BitmapDialog::~BitmapDialog()
+{}
+
+
+void
+MainFrame::OnPreferences (wxCommandEvent& WXUNUSED(event) )
+{
+ DialogPreferences dlg (this, _T("CTSim Preferences"), theApp->getAdvancedOptions(),
+ theApp->getAskDeleteNewDocs(), theApp->getVerboseLogging(), theApp->getStartupTips(),
+ theApp->getUseBackgroundTasks());
+ if (dlg.ShowModal() == wxID_OK) {
+ theApp->setAdvancedOptions (dlg.getAdvancedOptions());
+ theApp->setAskDeleteNewDocs (dlg.getAskDeleteNewDocs());
+ theApp->setVerboseLogging (dlg.getVerboseLogging());
+ theApp->setStartupTips (dlg.getStartupTips());
+ theApp->setUseBackgroundTasks (dlg.getUseBackgroundTasks());
+ }
+}
+
+void
+MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
+{
+ DialogImportParameters dialogImport (this, m_iDefaultImportFormat);
+ if (dialogImport.ShowModal() != wxID_OK)
+ return;
+
+ wxString strFormatName (dialogImport.getFormatName (), *wxConvCurrent);
+ m_iDefaultImportFormat = ImageFile::convertImportFormatNameToID (strFormatName.mb_str(wxConvUTF8));
+
+ wxString strExt;
+ wxString strWildcard;
+ if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM) {
+ strExt = _T(".ppm");
+ strWildcard = _T("PPM Files (*.ppm)|*.ppm|PGM Files (*.pgm)|*.pgm");
+ }
+#ifdef HAVE_PNG
+ else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
+ strExt = _T(".png");
+ strWildcard = _T("PNG Files (*.png)|*.png");
+ }
+#endif
+#ifdef HAVE_CTN_DICOM
+ else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
+ strExt = _T("*.*");
+ strWildcard = _T("Dicom Files (*.*)|*.*");
+ }
+#endif
+ else {
+ return;
+ }
+
+#if WXWIN_COMPATIBILITY_2_4
+ wxString strFilename = wxFileSelector (wxString(wxConvUTF8.cMB2WX("Import Filename")), wxString(wxConvUTF8.cMB2WX("")),
+ wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxHIDE_READONLY | wxOPEN);
+#else
+ wxString strFilename = wxFileSelector (wxString(wxConvUTF8.cMB2WX("Import Filename")), wxString(wxConvUTF8.cMB2WX("")),
+ wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxOPEN);
+#endif
+
+ if (! strFilename.IsEmpty()) {
+ if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
+ ImageFile* pIF = new ImageFile;
+ if (pIF->importImage (strFormatName.mb_str(wxConvUTF8), strFilename.mb_str(wxConvUTF8))) {
+ ImageFileDocument* pIFDoc = theApp->newImageDoc();
+ pIFDoc->setImageFile(pIF);
+ pIFDoc->getView()->getFrame()->Show(true);
+ std::ostringstream os;
+ os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
+ pIF->labelAdd (os.str().c_str());
+ if (theApp->getAskDeleteNewDocs())
+ pIFDoc->Modify (true);
+ pIFDoc->UpdateAllViews();
+ pIFDoc->GetFirstView()->OnUpdate (NULL, NULL);
+ pIFDoc->getView()->getFrame()->Show(true);
+ } else
+ delete pIF;
+ }
+#ifdef HAVE_CTN_DICOM
+ else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
+ DicomImporter dicomImport (strFilename.mb_str(wxConvUTF8));
+ if (dicomImport.fail()) {
+ ::wxMessageBox (wxConvUTF8.cMB2WX(dicomImport.failMessage().c_str()), _T("Import Error"));
+ } else if (dicomImport.testImage()) {
+ ImageFileDocument* pIFDoc = theApp->newImageDoc();
+ ImageFile* pIF = dicomImport.getImageFile();
+ pIFDoc->setImageFile (pIF);
+ std::ostringstream os;
+ os << "Import file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
+ pIF->labelAdd (os.str().c_str());
+ if (theApp->getAskDeleteNewDocs())
+ pIFDoc->Modify (true);
+ pIFDoc->UpdateAllViews();
+ pIFDoc->getView()->setInitialClientSize();
+ pIFDoc->Activate();
+ } else if (dicomImport.testProjections()) {
+ ProjectionFileDocument* pProjDoc = theApp->newProjectionDoc();
+ Projections* pProj = dicomImport.getProjections();
+ pProjDoc->setProjections (pProj);
+ pProjDoc->getView()->getFrame()->Show(true);
+ std::ostringstream os;
+ os << "Import projection file " << strFilename.c_str() << " (type " << strFormatName.c_str() << ")";
+ pProj->setRemark (os.str().c_str());
+ if (theApp->getAskDeleteNewDocs())
+ pProjDoc->Modify (true);
+ pProjDoc->UpdateAllViews();
+ pProjDoc->getView()->setInitialClientSize();
+ pProjDoc->Activate();
+ } else
+ ::wxMessageBox (_T("Unrecognized DICOM file contents"), _T("Import Error"));
+ }
+#endif
+ else
+ sys_error (ERR_WARNING, "Unknown import format type");
+ }
+}
+
+#include "./splash.xpm"
+void
+MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
+{
+ wxString strOSDesc = ::wxGetOsDescription();
+ *theApp->getLog() << _T("Operating System: ") << strOSDesc;
+ *theApp->getLog() << _T(", wxWindows: ") << wxVERSION_STRING;
+#ifdef _TIMESTAMP__
+ *theApp->getLog() << _T(", Build Date: ") << wxConvUTF8.cMB2WX(_TIMESTAMP__);
+#endif
+#if defined(DEBUG)
+ *theApp->getLog() << _T(", Debug version");
+#else
+ *theApp->getLog() << _T(", Release version");
+#endif
+#ifdef VERSION
+ *theApp->getLog() << _T(" ") << wxConvUTF8.cMB2WX(VERSION);
+#elif defined(CTSIMVERSION)
+ *theApp->getLog() << _T(" ") << _T(CTSIMVERSION);
+#endif
+ *theApp->getLog() << _T("\n");
+
+ wxBitmap bmp (splash);
+ if (bmp.Ok()) {
+ BitmapDialog dlg (&bmp, "About CTSim");
+ dlg.ShowModal();
+ } else {
+ wxString msg = _T("CTSim\nThe Open Source Computed Tomography Simulator\n");
+#ifdef VERSION
+ msg << _T("Version: ") << wxConvUTF8.cMB2WX(VERSION) << _T("\n\n");
+#elif defined(CTSIMVERSION)
+ msg << _T("Version: ") << wxConvUTF8.cMB2WX(CTSIMVERSION) << _T("\n\n");
+#endif
+ msg += _T("Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]");
+
+ wxMessageBox(msg, _T("About CTSim"), wxOK | wxICON_INFORMATION, this);
+ *theApp->getLog() << msg << wxConvUTF8.cMB2WX("\n");
+ }
+}
+
+
+// Create new documents
+
+ProjectionFileDocument*
+CTSimApp::newProjectionDoc()
+{
+ ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (_T("")));
+ if (newDoc) {
+ newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
+ newDoc->SetDocumentTemplate (m_pDocTemplProjection);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+
+ImageFileDocument*
+CTSimApp::newImageDoc()
+{
+ ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (_T("")));
+ if (newDoc) {
+ newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
+ newDoc->SetDocumentTemplate (m_pDocTemplImage);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+
+PlotFileDocument*
+CTSimApp::newPlotDoc()
+{
+ PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (_T("")));
+ if (newDoc) {
+ newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
+ newDoc->SetDocumentTemplate (m_pDocTemplPlot);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+
+
+TextFileDocument*
+CTSimApp::newTextDoc()
+{
+ wxString strFilename (getUntitledFilename());
+ strFilename += wxString(".txt", *wxConvCurrent);
+
+ TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (_T("")));
+ if (newDoc) {
+ newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
+ newDoc->SetDocumentTemplate (m_pDocTemplText);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+
+
+PhantomFileDocument*
+CTSimApp::newPhantomDoc()
+{
+ PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (_T("")));
+ if (newDoc) {
+ newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
+ newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+
+
+#if wxUSE_GLCANVAS
+Graph3dFileDocument*
+CTSimApp::newGraph3dDoc()
+{
+ Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (_T("")));
+ if (newDoc) {
+ newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
+ newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+#endif