+class BitmapControl : public wxPanel
+{
+private:
+ DECLARE_DYNAMIC_CLASS (BitmapControl)
+ DECLARE_EVENT_TABLE ()
+ wxBitmap* m_pBitmap;
+
+public:
+ BitmapControl (wxBitmap* pBitmap, wxWindow *parent, wxWindowID id = -1,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize,
+ long style = wxSTATIC_BORDER,
+ const wxValidator& validator = wxDefaultValidator,
+ const wxString& name = "BitmapCtrl");
+
+
+ virtual ~BitmapControl();
+
+ virtual wxSize GetBestSize() const;
+
+ wxBitmap* getBitmap()
+ { return m_pBitmap; }
+
+ void OnPaint(wxPaintEvent& event);
+};
+
+
+BEGIN_EVENT_TABLE(BitmapControl, wxPanel)
+EVT_PAINT(BitmapControl::OnPaint)
+END_EVENT_TABLE()
+
+IMPLEMENT_CLASS(BitmapControl, wxPanel)
+
+
+BitmapControl::BitmapControl (wxBitmap* pBitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
+ long style, const wxValidator& validator, const wxString& name)
+ : m_pBitmap(pBitmap)
+{
+ Create(parent, id, pos, size, style, name);
+
+ SetSize (GetBestSize());
+}
+
+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), 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, "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, "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 ());
+ m_iDefaultImportFormat = ImageFile::convertImportFormatNameToID (strFormatName.c_str());
+
+ wxString strExt;
+ wxString strWildcard;
+ if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM) {
+ strExt = ".ppm";
+ strWildcard = "PPM Files (*.ppm)|*.ppm|PGM Files (*.pgm)|*.pgm";
+ }
+#ifdef HAVE_PNG
+ else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
+ strExt = ".png";
+ strWildcard = "PNG Files (*.png)|*.png";
+ }
+#endif
+#ifdef HAVE_CTN_DICOM
+ else if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_DICOM) {
+ strExt = "*.*";
+ strWildcard = "Dicom Files (*.*)|*.*";
+ }
+#endif
+ else {
+ return;
+ }
+
+ wxString strFilename = wxFileSelector (wxString("Import Filename"), wxString(""),
+ wxString(""), strExt, strWildcard, wxHIDE_READONLY | wxOPEN);
+ if (! strFilename.IsEmpty()) {
+ if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
+ ImageFile* pIF = new ImageFile;
+ if (pIF->importImage (strFormatName.c_str(), strFilename.c_str())) {
+ 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.c_str());
+ if (dicomImport.fail()) {
+ ::wxMessageBox (dicomImport.failMessage().c_str(), "Import Error");
+ } else if (dicomImport.testImage()) {
+ ImageFileDocument* pIFDoc = theApp->newImageDoc();
+ ImageFile* pIF = dicomImport.getImageFile();
+ 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 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->GetFirstView()->OnUpdate (NULL, NULL);
+ pProjDoc->getView()->getFrame()->Show(true);
+ } else
+ ::wxMessageBox ("Unrecognized DICOM file contents", "Import Error");
+ }
+#endif
+ else
+ sys_error (ERR_WARNING, "Unknown import format type");
+ }
+}
+
+#include "./splash.xpm"
+void
+MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
+{
+ long lFreeMem = ::wxGetFreeMemory() / (1024L * 1024L);
+ wxString strOSDesc = ::wxGetOsDescription();
+ *theApp->getLog() << "Operating System: " << strOSDesc;
+ if (lFreeMem > 0)
+ *theApp->getLog() << ", Free Memory: " << lFreeMem << " MB";
+ *theApp->getLog() << ", wxWindows: " << wxVERSION_STRING;
+#ifdef __TIMESTAMP__
+ *theApp->getLog() << ", Build Date: " << __TIMESTAMP__;
+#endif
+#if defined(DEBUG)
+ *theApp->getLog() << ", CTSim Debug version";
+#else
+ *theApp->getLog() << ", CTSim Release version";
+#endif
+
+ *theApp->getLog() << "\n";
+
+ wxBitmap bmp (splash);
+ if (bmp.Ok()) {
+ BitmapDialog dlg (&bmp, "About CTSim");
+ dlg.ShowModal();
+ } else {
+ wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n";
+#ifdef CTSIMVERSION
+ msg += "Version ";
+ msg += CTSIMVERSION;
+ msg += "\n\n";
+#elif defined(VERSION)
+ msg << "Version: " << VERSION << "\n\n";
+#endif
+ msg += "Author: Kevin Rosenberg <kevin@rosenberg.net>\nUsage: ctsim [files-to-open..] [--help]";
+
+ wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this);
+ *theApp->getLog() << msg << "\n";
+ }
+}
+
+
+ProjectionFileDocument*
+CTSimApp::newProjectionDoc()
+{
+ ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (""));
+ 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 (""));
+ 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 (""));
+ if (newDoc) {
+ newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
+ newDoc->SetDocumentTemplate (m_pDocTemplPlot);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+
+
+TextFileDocument*
+CTSimApp::newTextDoc()
+{
+ wxString strFilename (getUntitledFilename());
+ strFilename += ".txt";
+
+ TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (""));
+ 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 (""));
+ 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 (""));
+ if (newDoc) {
+ newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
+ newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
+ newDoc->OnNewDocument();
+ }
+
+ return newDoc;
+}
+#endif