r428: no message
[ctsim.git] / src / docs.cpp
index 6722ef5946b874408639e4ad7cedae90fe47750c..8bdb8d017925ec936583ec51403c3e78c00f4007 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: docs.cpp,v 1.3 2000/09/07 01:28:33 kevin Exp $
+**  $Id: docs.cpp,v 1.14 2001/01/20 17:43:41 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
@@ -51,7 +51,6 @@
 #include "docs.h"
 #include "views.h"
 
-
 // ImageFileDocument
 
 IMPLEMENT_DYNAMIC_CLASS(ImageFileDocument, wxDocument)
@@ -73,7 +72,7 @@ bool ImageFileDocument::OnOpenDocument(const wxString& filename)
     wxString untitledFilename = theApp->getUntitledFilename();
     SetFilename (untitledFilename, true);
   } else {
-    if (! m_imageFile.fileRead (filename)) {
+    if (! m_imageFile.fileRead (filename.c_str())) {
       *theApp->getLog() << "Unable to read image file " << filename << "\n";
       return false;
     }
@@ -82,6 +81,8 @@ bool ImageFileDocument::OnOpenDocument(const wxString& filename)
   }
   Modify(false);
   UpdateAllViews();
+  GetFirstView()->OnUpdate (GetFirstView(), NULL);
+
   return true;
 }
 
@@ -95,11 +96,6 @@ void ImageFileDocument::Modify(bool mod)
     wxDocument::Modify(mod);
 }
 
-bool ImageFileDocument::OnCloseDocument ()
-{
-  bool bReturn = wxDocument::OnCloseDocument();
-  return bReturn;
-}
 
 // ProjectionFileDocument
 
@@ -107,7 +103,7 @@ IMPLEMENT_DYNAMIC_CLASS(ProjectionFileDocument, wxDocument)
 
 bool ProjectionFileDocument::OnSaveDocument(const wxString& filename)
 {
-  if (! m_projectionFile.write (filename)) {
+  if (! m_projectionFile.write (filename.c_str())) {
     *theApp->getLog() << "Unable to write projection file " << filename << "\n";
     return false;
   }
@@ -122,7 +118,7 @@ bool ProjectionFileDocument::OnOpenDocument(const wxString& filename)
     wxString untitledFilename = theApp->getUntitledFilename();
     SetFilename (untitledFilename, true);
   } else {
-    if (! m_projectionFile.read (filename)) {
+    if (! m_projectionFile.read (filename.c_str())) {
       *theApp->getLog() << "Unable to read projection file " << filename << "\n";
       return false;
     }
@@ -131,6 +127,8 @@ bool ProjectionFileDocument::OnOpenDocument(const wxString& filename)
   }
   Modify(false);
   UpdateAllViews();
+  GetFirstView()->OnUpdate (GetFirstView(), NULL);
+
   return true;
 }
 
@@ -145,11 +143,6 @@ void ProjectionFileDocument::Modify(bool mod)
 }
 
 
-bool ProjectionFileDocument::OnCloseDocument ()
-{
-  bool bReturn = wxDocument::OnCloseDocument();
-  return bReturn;
-}
 
 // PhantomDocument
 
@@ -174,18 +167,25 @@ bool PhantomDocument::OnOpenDocument(const wxString& filename)
   m_idPhantom = m_phantom.id();
   Modify(false);
   UpdateAllViews();
+  GetFirstView()->OnUpdate (GetFirstView(), NULL);
+
   return true;
 }
 
-bool PhantomDocument::OnCloseDocument ()
+bool PhantomDocument::OnSaveDocument(const wxString& filename)
 {
-  bool bReturn = wxDocument::OnCloseDocument();
-  return bReturn;
+  if (! m_phantom.fileWrite (filename.c_str())) {
+    *theApp->getLog() << "Unable to write phantom file " << filename << "\n";
+    return false;
+  }
+  *theApp->getLog() << "Wrote phantom file " << filename << "\n";
+  Modify(false);
+  return true;
 }
 
 bool PhantomDocument::IsModified(void) const
 {
-  return wxDocument::IsModified();
+  return false;
 }
 
 void PhantomDocument::Modify(bool mod)
@@ -193,3 +193,96 @@ void PhantomDocument::Modify(bool mod)
     wxDocument::Modify(mod);
 }
 
+
+// PlotFileDocument
+
+IMPLEMENT_DYNAMIC_CLASS(PlotFileDocument, wxDocument)
+
+bool PlotFileDocument::OnSaveDocument(const wxString& filename)
+{
+  m_namePlot = filename.c_str();
+  if (! m_plot.fileWrite (filename)) {
+    *theApp->getLog() << "Unable to write plot file " << filename << "\n";
+    return false;
+  }
+  *theApp->getLog() << "Wrote plot file " << filename << "\n";
+  Modify(false);
+  return true;
+}
+
+bool PlotFileDocument::OnOpenDocument(const wxString& filename)
+{
+  if (filename == "untitled.plt") {
+    wxString untitledFilename = theApp->getUntitledFilename();
+    SetFilename (untitledFilename, true);
+  } else {
+    if (! m_plot.fileRead (filename.c_str())) {
+      *theApp->getLog() << "Unable to read plot file " << filename << "\n";
+      return false;
+    }
+    *theApp->getLog() << "Read plot file " << filename << "\n";
+    SetFilename (filename, true);
+    m_namePlot = filename.c_str();
+  }
+  Modify (false);
+  UpdateAllViews();
+  GetFirstView()->OnUpdate (NULL, NULL);
+
+  return true;
+}
+
+
+bool PlotFileDocument::IsModified(void) const
+{
+  return wxDocument::IsModified();
+}
+
+void PlotFileDocument::Modify(bool mod)
+{
+    wxDocument::Modify(mod);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+//
+// TextEditDocument
+//
+//////////////////////////////////////////////////////////////////////////
+
+IMPLEMENT_DYNAMIC_CLASS(TextEditDocument, wxDocument)
+
+// Since text windows have their own method for saving to/loading from files,
+// we override OnSave/OpenDocument instead of Save/LoadObject
+bool TextEditDocument::OnSaveDocument(const wxString& filename)
+{
+    TextEditView *view = dynamic_cast<TextEditView*>(GetFirstView());
+    if (! view->getTextCtrl()->SaveFile(filename))
+        return false;
+    Modify(false);
+    return true;
+}
+
+bool TextEditDocument::OnOpenDocument(const wxString& filename)
+{
+    TextEditView *view = dynamic_cast<TextEditView*>(GetFirstView());
+
+    if (filename != "Log.txt" && ! view->getTextCtrl()->LoadFile(filename))
+        return false;
+
+    SetFilename (filename, true);
+    Modify (false);
+    UpdateAllViews();
+    return true;
+}
+
+bool TextEditDocument::IsModified(void) const
+{
+  return false;
+
+  TextEditView *view = dynamic_cast<TextEditView*>(GetFirstView());
+  if (view)
+    return (wxDocument::IsModified() || view->getTextCtrl()->IsModified());
+  else
+    return wxDocument::IsModified();
+}
+