r315: Coverted POL to C++ class
[ctsim.git] / src / views.cpp
index 740c81c03615fca0236f43947be4c453041d817c..465990360c18f9dc160ff598a4e48bca40db67ac 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: views.cpp,v 1.36 2000/12/22 04:18:00 kevin Exp $
+**  $Id: views.cpp,v 1.39 2000/12/27 03:16:02 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
@@ -91,9 +91,10 @@ ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
   int nx = rIF.nx();\r
   int ny = rIF.ny();\r
   \r
+  int yPt = ny - y - 1;\r
   dc.SetLogicalFunction (wxINVERT);\r
   dc.SetPen (*wxGREEN_PEN);\r
-  dc.DrawLine (0, y, nx, y);\r
+  dc.DrawLine (0, yPt, nx, yPt);\r
   dc.DrawLine (x, 0, x, ny);\r
   dc.SetLogicalFunction (wxCOPY);\r
 }\r
@@ -121,38 +122,33 @@ ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
   
   wxPoint pt(event.GetLogicalPosition(dc));
   \r
+  const ImageFile& rIF = m_pView->GetDocument()->getImageFile();\r
+  ImageFileArrayConst v = rIF.getArray();\r
+  int nx = rIF.nx();\r
+  int ny = rIF.ny();\r
+  const int yPt = ny - 1 - pt.y;\r
   if (event.RightIsDown()) {\r
-    const ImageFile& rIF = m_pView->GetDocument()->getImageFile();\r
-    ImageFileArrayConst v = rIF.getArray();\r
-    int nx = rIF.nx();\r
-    int ny = rIF.ny();\r
-    \r
     if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {\r
       std::ostringstream os;\r
-      os << "Image value (" << pt.x << "," << pt.y << ") = " << v[pt.x][ny - 1 - pt.y] << "\n";\r
+      os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt] << "\n";\r
       *theApp->getLog() << os.str().c_str();\r
     } else\r
-      *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";\r
+      *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";\r
   }\r
-  else if (event.LeftIsDown() || event.LeftUp()) {\r
-    const ImageFile& rIF = m_pView->GetDocument()->getImageFile();\r
-    ImageFileArrayConst v = rIF.getArray();\r
-    int nx = rIF.nx();\r
-    int ny = rIF.ny();\r
-    \r
+  else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {\r
     if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {\r
       if (m_xCursor >= 0 && m_yCursor >= 0) {\r
         DrawRubberBandCursor (dc, m_xCursor, m_yCursor);\r
       }\r
-      DrawRubberBandCursor (dc, pt.x, pt.y);\r
+      DrawRubberBandCursor (dc, pt.x, yPt);\r
       m_xCursor = pt.x;\r
-      m_yCursor = pt.y;\r
+      m_yCursor = yPt;\r
     } else\r
-      *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";\r
+      *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";\r
   }\r
   if (event.LeftUp()) {\r
     std::ostringstream os;\r
-    os << "Selected column" << pt.x << " and row" << pt.y << "\n";\r
+    os << "Selected column " << pt.x << " , row " << yPt << "\n";\r
     *theApp->getLog() << os.str().c_str();\r
   }\r
 }
@@ -284,7 +280,8 @@ ImageFileView::OnCompare (wxCommandEvent& event)
           return;\r
         }\r
 \r
-        pDifferenceDoc->Modify(true);\r
+        if (theApp->getSetModifyNewDocs())\r
+          pDifferenceDoc->Modify(true);\r
         pDifferenceDoc->UpdateAllViews(this);\r
         pDifferenceDoc->GetFirstView()->OnUpdate (this, NULL);\r
       }\r
@@ -493,18 +490,24 @@ ImageFileView::OnPlotRow (wxCommandEvent& event)
       sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");\r
     } else {\r
       PlotFile& rPlotFile = pPlotDoc->getPlotFile();\r
-      std::ostringstream title;\r
-      title << "Row " << yCursor;\r
-      rPlotFile.setTitle(title.str());\r
-      rPlotFile.setXLabel("Column");\r
-      rPlotFile.setYLabel("Pixel Value");\r
+      std::ostringstream os;\r
+      os << "Row " << yCursor;\r
+      std::string title("title ");\r
+      title += os.str();\r
+      rPlotFile.addEzsetCommand (title.c_str());\r
+      rPlotFile.addEzsetCommand ("xlabel Column");\r
+      rPlotFile.addEzsetCommand ("ylabel Pixel Value");\r
+      rPlotFile.addEzsetCommand ("lxfrac 0");\r
+      rPlotFile.addEzsetCommand ("box");\r
+      rPlotFile.addEzsetCommand ("grid");\r
       rPlotFile.setCurveSize (2, nx);\r
       rPlotFile.addColumn (0, pX);\r
       rPlotFile.addColumn (1, pY);\r
     }\r
     delete pX;\r
     delete pY;\r
-    pPlotDoc->Modify(true);\r
+    if (theApp->getSetModifyNewDocs())\r
+       pPlotDoc->Modify(true);\r
   }\r
   \r
 }\r
@@ -535,18 +538,24 @@ ImageFileView::OnPlotCol (wxCommandEvent& event)
       sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");\r
     } else {\r
       PlotFile& rPlotFile = pPlotDoc->getPlotFile();\r
-      std::ostringstream title;\r
-      title << "Column " << xCursor;\r
-      rPlotFile.setTitle(title.str());\r
-      rPlotFile.setXLabel("Row");\r
-      rPlotFile.setYLabel("Pixel Value");\r
+      std::ostringstream os;\r
+      os << "Column " << xCursor;\r
+      std::string title("title ");\r
+      title += os.str();\r
+      rPlotFile.addEzsetCommand (title.c_str());\r
+      rPlotFile.addEzsetCommand ("xlabel Row");\r
+      rPlotFile.addEzsetCommand ("ylabel Pixel Value");\r
+      rPlotFile.addEzsetCommand ("lxfrac 0");\r
+      rPlotFile.addEzsetCommand ("box");\r
+      rPlotFile.addEzsetCommand ("grid");\r
       rPlotFile.setCurveSize (2, nx);\r
       rPlotFile.addColumn (0, pX);\r
       rPlotFile.addColumn (1, pY);\r
     }\r
     delete pX;\r
     delete pY;\r
-    pPlotDoc->Modify(true);\r
+    if (theApp->getSetModifyNewDocs())\r
+      pPlotDoc->Modify(true);\r
   }\r
 }\r
 \r
@@ -561,7 +570,10 @@ ImageFileView::OnCompareCol (wxCommandEvent& event)
   \r
   std::vector<ImageFileDocument*> vecIFDoc;\r
   theApp->getCompatibleImages (GetDocument(), vecIFDoc);\r
-  \r
+  if (vecIFDoc.size() == 0) {\r
+    wxMessageBox ("No compatible images for Column Comparison", "Error");\r
+    return;\r
+  }\r
   DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false);\r
   \r
   if (dialogGetCompare.ShowModal() == wxID_OK) {\r
@@ -588,11 +600,21 @@ ImageFileView::OnCompareCol (wxCommandEvent& event)
         sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");\r
       } else {\r
         PlotFile& rPlotFile = pPlotDoc->getPlotFile();\r
-        std::ostringstream title;\r
-        title << "Comparison of Column " << xCursor;\r
-        rPlotFile.setTitle(title.str());\r
-        rPlotFile.setXLabel("Row");\r
-        rPlotFile.setYLabel("Pixel Value");\r
+        std::ostringstream os;\r
+        os << "Column " << xCursor << " Comparison";\r
+        std::string title("title ");\r
+        title += os.str();\r
+        rPlotFile.addEzsetCommand (title.c_str());\r
+        rPlotFile.addEzsetCommand ("xlabel Row");\r
+        rPlotFile.addEzsetCommand ("ylabel Pixel Value");\r
+        rPlotFile.addEzsetCommand ("lxfrac 0");\r
+        rPlotFile.addEzsetCommand ("curve 1");\r
+        rPlotFile.addEzsetCommand ("color 2");\r
+        rPlotFile.addEzsetCommand ("curve 2");\r
+        rPlotFile.addEzsetCommand ("color 4");\r
+        rPlotFile.addEzsetCommand ("dash 5");\r
+        rPlotFile.addEzsetCommand ("box");\r
+        rPlotFile.addEzsetCommand ("grid");\r
         rPlotFile.setCurveSize (3, nx);\r
         rPlotFile.addColumn (0, pX);\r
         rPlotFile.addColumn (1, pY1);\r
@@ -601,7 +623,8 @@ ImageFileView::OnCompareCol (wxCommandEvent& event)
       delete pX;\r
       delete pY1;\r
       delete pY2;\r
-      pPlotDoc->Modify(true);\r
+      if (theApp->getSetModifyNewDocs())\r
+        pPlotDoc->Modify(true);\r
     }\r
   }\r
 }\r
@@ -618,6 +641,11 @@ ImageFileView::OnCompareRow (wxCommandEvent& event)
   std::vector<ImageFileDocument*> vecIFDoc;\r
   theApp->getCompatibleImages (GetDocument(), vecIFDoc);\r
   \r
+  if (vecIFDoc.size() == 0) {\r
+    wxMessageBox ("No compatible images for Row Comparison", "Error");\r
+    return;\r
+  }\r
+\r
   DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false);\r
   \r
   if (dialogGetCompare.ShowModal() == wxID_OK) {\r
@@ -644,11 +672,21 @@ ImageFileView::OnCompareRow (wxCommandEvent& event)
         sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");\r
       } else {\r
         PlotFile& rPlotFile = pPlotDoc->getPlotFile();\r
-        std::ostringstream title;\r
-        title << "Comparison of Row " << yCursor;\r
-        rPlotFile.setTitle(title.str());\r
-        rPlotFile.setXLabel("Column");\r
-        rPlotFile.setYLabel("Pixel Value");\r
+        std::ostringstream os;\r
+        os << "Row " << yCursor << " Comparison";\r
+        std::string title("title ");\r
+        title += os.str();\r
+        rPlotFile.addEzsetCommand (title.c_str());\r
+        rPlotFile.addEzsetCommand ("xlabel Column");\r
+        rPlotFile.addEzsetCommand ("ylabel Pixel Value");\r
+        rPlotFile.addEzsetCommand ("lxfrac 0");\r
+        rPlotFile.addEzsetCommand ("curve 1");\r
+        rPlotFile.addEzsetCommand ("color 2");\r
+        rPlotFile.addEzsetCommand ("curve 2");\r
+        rPlotFile.addEzsetCommand ("color 4");\r
+        rPlotFile.addEzsetCommand ("dash 5");\r
+        rPlotFile.addEzsetCommand ("box");\r
+        rPlotFile.addEzsetCommand ("grid");\r
         rPlotFile.setCurveSize (3, ny);\r
         rPlotFile.addColumn (0, pX);\r
         rPlotFile.addColumn (1, pY1);\r
@@ -657,7 +695,8 @@ ImageFileView::OnCompareRow (wxCommandEvent& event)
       delete pX;\r
       delete pY1;\r
       delete pY2;\r
-      pPlotDoc->Modify(true);\r
+      if (theApp->getSetModifyNewDocs())\r
+        pPlotDoc->Modify(true);\r
     }\r
   }\r
 }\r
@@ -800,7 +839,8 @@ PhantomView::OnProjections (wxCommandEvent& event)
         theApp->getDocManager()->ActivateView (pView, true, false);
       }
       ::wxYield();
-      pProjectionDoc->Modify(true);
+      if (theApp->getSetModifyNewDocs())\r
+        pProjectionDoc->Modify(true);
       pProjectionDoc->UpdateAllViews(this);
     }
   }
@@ -836,7 +876,8 @@ PhantomView::OnRasterize (wxCommandEvent& event)
           return;
         }
       }
-      pRasterDoc->Modify(true);
+      if (theApp->getSetModifyNewDocs())\r
+        pRasterDoc->Modify(true);
       pRasterDoc->UpdateAllViews(this);
       ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pRasterDoc->GetFirstView());\r
       if (rasterView) {\r
@@ -1060,7 +1101,7 @@ ProjectionFileView::OnReconstruct (wxCommandEvent& event)
     m_iDefaultTrace = dialogReconstruction.getTrace();
     if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
       ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));\r
-      if (pReconDoc) {\r
+      if (pReconDoc) {\r
         sys_error (ERR_SEVERE, "Unable to create image file");\r
         return;\r
       }
@@ -1122,7 +1163,8 @@ ProjectionFileView::OnReconstruct (wxCommandEvent& event)
         }
       }
       delete pReconstruct;
-      pReconDoc->Modify(true);
+      if (theApp->getSetModifyNewDocs())\r
+        pReconDoc->Modify(true);
       pReconDoc->UpdateAllViews(this);
       ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pReconDoc->GetFirstView());\r
       if (rasterView) {\r
@@ -1498,25 +1540,11 @@ PlotFileView::OnDraw (wxDC* dc)
     m_canvas->GetClientSize (&xsize, &ysize);\r
     SGPDriver driver (dc, xsize, ysize);\r
     SGP sgp (driver);\r
-    const PlotFile& rPhantom = GetDocument()->getPlotFile();\r
     EZPlot plot (sgp);\r
-    \r
-    if (! rPlotFile.getTitle().empty()) {\r
-      std::string s("title ");\r
-      s += rPlotFile.getTitle();\r
-      plot.ezset (s);\r
-    }\r
-    if (! rPlotFile.getXLabel().empty()) {\r
-      std::string s("xlabel ");\r
-      s += rPlotFile.getXLabel();\r
-      plot.ezset (s);\r
-    }\r
-    if (! rPlotFile.getYLabel().empty()) {\r
-      std::string s("ylabel ");\r
-      s += rPlotFile.getYLabel();\r
-      plot.ezset (s);\r
-    }\r
-    \r
+\r
+    for (int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)\r
+       plot.ezset (rPlotFile.getEzsetCommand (iEzset));\r
+\r
     if (m_bMinSpecified) {\r
       std::ostringstream os;\r
       os << "ymin " << m_dMinPixel;\r