+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");
+ }
+}
+