r593: no message
[ctsim.git] / src / ctsim.cpp
index 5d192706725348a1ed2f0a8345c3ed5821f3ecbb..3449d480187da0834fe3a3c0f99d7da6c4ada2a3 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: ctsim.cpp,v 1.90 2001/03/01 20:02:18 kevin Exp $
+**  $Id: ctsim.cpp,v 1.91 2001/03/02 02:08:14 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -69,7 +69,7 @@
 #endif
 #endif
 
-static const char* rcsindent = "$Id: ctsim.cpp,v 1.90 2001/03/01 20:02:18 kevin Exp $";
+static const char* rcsindent = "$Id: ctsim.cpp,v 1.91 2001/03/02 02:08:14 kevin Exp $";
 
 struct option CTSimApp::ctsimOptions[] = 
 {
@@ -889,13 +889,19 @@ MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
   wxString strWildcard;
   if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM) {
     strExt = ".ppm";
-    strWildcard = "PPM Files (*.ppm)|*.pgm|PGM Files (*.pgm)|*.pgm";
+    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;
@@ -904,21 +910,60 @@ MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
   wxString strFilename = wxFileSelector (wxString("Import Filename"), wxString(""), 
     wxString(""), strExt, strWildcard, wxHIDE_READONLY | wxOPEN);
   if (! strFilename.IsEmpty()) {
-    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;
+    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");
   }
 }