r310: plotfile updates
[ctsim.git] / src / views.cpp
index 81eb051098485141b32c14cdf0d802ae5f259476..68b03759361524e097517c4725b87ba3d5c27741 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: views.cpp,v 1.31 2000/12/19 21:37:51 kevin Exp $
+**  $Id: views.cpp,v 1.35 2000/12/21 03:40:58 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
@@ -90,7 +90,7 @@ ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
        ImageFileArrayConst v = rIF.getArray();\r
        int nx = rIF.nx();\r
        int ny = rIF.ny();\r
-\r
+       \r
        dc.SetLogicalFunction (wxINVERT);\r
        dc.SetPen (*wxGREEN_PEN);\r
        dc.DrawLine (0, y, nx, y);\r
@@ -103,7 +103,7 @@ ImageFileCanvas::GetCurrentCursor (int& x, int& y)
 {\r
        x = m_xCursor;\r
        y = m_yCursor;\r
-\r
+       \r
        if (m_xCursor >= 0 && m_yCursor >= 0)\r
                return true;\r
        else\r
@@ -120,7 +120,7 @@ ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
     PrepareDC(dc);
     
     wxPoint pt(event.GetLogicalPosition(dc));
-\r
+       \r
     if (event.RightIsDown()) {\r
                const ImageFile& rIF = m_pView->GetDocument()->getImageFile();\r
                ImageFileArrayConst v = rIF.getArray();\r
@@ -134,7 +134,7 @@ ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
                } else\r
                        *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";\r
     }\r
-    else if (event.LeftIsDown()) {\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
@@ -147,11 +147,13 @@ ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
                        DrawRubberBandCursor (dc, pt.x, pt.y);\r
                        m_xCursor = pt.x;\r
                        m_yCursor = pt.y;\r
+               } else\r
+                       *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";\r
+       }\r
+    if (event.LeftUp()) {\r
                        std::ostringstream os;\r
                        os << "Selected column" << pt.x << " and row" << pt.y << "\n";\r
                        *theApp->getLog() << os.str().c_str();\r
-               } else\r
-                       *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";\r
     }\r
 }
 
@@ -163,7 +165,8 @@ BEGIN_EVENT_TABLE(ImageFileView, wxView)
 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)\r
-EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
+EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)\r
+EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)\r
 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)\r
 END_EVENT_TABLE()
 
@@ -198,17 +201,20 @@ void
 ImageFileView::OnScaleAuto (wxCommandEvent& event)
 {
     const ImageFile& rIF = GetDocument()->getImageFile();
-    DialogAutoScaleParameters dialogAutoScale (m_frame, rIF, m_dAutoScaleFactor);
+    double min, max, mean, mode, median, stddev;\r
+       rIF.statistics(min, max, mean, mode, median, stddev);\r
+    DialogAutoScaleParameters dialogAutoScale (m_frame, mean, mode, median, stddev, m_dAutoScaleFactor);
     int iRetVal = dialogAutoScale.ShowModal();
     if (iRetVal == wxID_OK) {
                m_bMinSpecified = true;
                m_bMaxSpecified = true;
-               double dMin, dMax;
-               dialogAutoScale.getMinMax (&dMin, &dMax);
-               m_dMinPixel = dMin;
-               m_dMaxPixel = dMax;
-               m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
-               OnUpdate (this, NULL);
+               double dMin, dMax;\r
+               if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
+                       m_dMinPixel = dMin;
+                       m_dMaxPixel = dMax;
+                       m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
+                       OnUpdate (this, NULL);\r
+               }
     }
 }
 
@@ -225,7 +231,7 @@ ImageFileView::OnScaleMinMax (wxCommandEvent& event)
     if (m_bMaxSpecified)
                max = m_dMaxPixel;
        
-    DialogGetImageMinMax dialogMinMax (m_frame, rIF, min, max);
+    DialogGetMinMax dialogMinMax (m_frame, "Set Image Minimum & Maximum", min, max);
     int retVal = dialogMinMax.ShowModal();
     if (retVal == wxID_OK) {
                m_bMinSpecified = true;
@@ -235,7 +241,31 @@ ImageFileView::OnScaleMinMax (wxCommandEvent& event)
                OnUpdate (this, NULL);
     }
 }
-
+\r
+void\r
+ImageFileView::OnCompare (wxCommandEvent& event)\r
+{\r
+  wxList& rListDocs = theApp->getDocManager()->GetDocuments();\r
+  std::vector<ImageFileDocument*> vecIF;\r
+  std::vector<std::string> vecFilename;\r
+  int nCompares = 0;\r
+  for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) {\r
+    wxDocument* pDoc = reinterpret_cast<wxDocument*>(pNode->GetData());\r
+       ImageFileDocument* pIFDoc = dynamic_cast<ImageFileDocument*>(pDoc);\r
+       if (pIFDoc) {\r
+               if (pIFDoc->GetFirstView() != this) {\r
+                       std::string strFilename = pDoc->GetFilename();\r
+                       vecIF.push_back (pIFDoc);\r
+                       vecFilename.push_back (strFilename);\r
+                       nCompares++;\r
+               }\r
+       }\r
+  }\r
+  for (int i = 0; i < nCompares; i++) {\r
+         const std::string& s = vecFilename[i];\r
+         *theApp->getLog() << s.c_str() << "\n";\r
+  }\r
+}
 
 ImageFileCanvas* 
 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
@@ -281,7 +311,10 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
        wxMenu *plot_menu = new wxMenu;\r
        plot_menu->Append (IFMENU_PLOT_ROW, "Plot &Row");\r
        plot_menu->Append (IFMENU_PLOT_COL, "Plot &Column");\r
-
+       
+       wxMenu *compare_menu = new wxMenu;\r
+       compare_menu->Append (IFMENU_COMPARE_IMAGES, "&Compare Images");\r
+\r
     wxMenu *help_menu = new wxMenu;
     help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
     
@@ -289,7 +322,8 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
     
     menu_bar->Append(file_menu, "&File");
     menu_bar->Append(view_menu, "&View");\r
-       menu_bar->Append(plot_menu, "&Plot");
+       menu_bar->Append(plot_menu, "&Plot");\r
+       menu_bar->Append(compare_menu, "&Compare");
     menu_bar->Append(help_menu, "&Help");
     
     subframe->SetMenuBar(menu_bar);
@@ -330,7 +364,7 @@ ImageFileView::OnDraw (wxDC* dc)
 {
        if (m_bitmap.Ok())
                dc->DrawBitmap(m_bitmap, 0, 0, false);
-\r
+       \r
        int xCursor, yCursor;\r
        if (m_canvas->GetCurrentCursor (xCursor, yCursor))\r
                m_canvas->DrawRubberBandCursor (*dc, xCursor, yCursor);\r
@@ -406,62 +440,46 @@ ImageFileView::OnClose (bool deleteWindow)
 \r
 #include "wx/plot.h"\r
 \r
-class VectorPlotCurve : wxPlotCurve {\r
-private:\r
-       int     m_nPoints;\r
-       std::vector<double> m_points;\r
-\r
-public:\r
-       VectorPlotCurve (const double* const points, int n, double minVal, double maxVal)\r
-               : wxPlotCurve (minVal, minVal, maxVal)\r
-       {\r
-               for (int i = 0; i < n; i++)\r
-                       m_points.push_back(points[i]);\r
-       }\r
-\r
-       wxInt32 GetStartX ()\r
-       { return 0; }\r
-\r
-       wxInt32 GetEndX ()\r
-       { return m_nPoints - 1; }\r
-\r
-       double GetY (wxInt32 x)\r
-       { return m_points[x]; }\r
-};\r
-\r
-
 void\r
 ImageFileView::OnPlotRow (wxCommandEvent& event)\r
 {\r
        int xCursor, yCursor;\r
        if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {\r
-               // os << "No row selected. Please use left mouse button on image to select row\n";\r
+               *theApp->getLog() << "No row selected. Please use left mouse button on image to select row\n";\r
                return;\r
        }\r
-\r
+       \r
     const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();\r
     ImageFileArrayConst v = rIF.getArray();\r
     int nx = rIF.nx();\r
     int ny = rIF.ny();\r
-\r
+       \r
     if (v != NULL && yCursor < ny) {\r
-               double* pVec = new double [nx];\r
-               double minVal = v[0][yCursor];\r
-               double maxVal = minVal;\r
+               double* pX = new double [nx];\r
+               double* pY = new double [nx];\r
                for (int i = 0; i < nx; i++) {\r
-                       pVec[i] = v[i][yCursor];\r
-                       if (pVec[i] < minVal)\r
-                               minVal = pVec[i];\r
-                       else if (pVec[i] > maxVal)\r
-                               maxVal = pVec[i];\r
+                       pX[i] = i;\r
+                       pY[i] = v[i][yCursor];\r
+               }\r
+               PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));\r
+               if (! pPlotDoc) {\r
+                       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
+                       rPlotFile.setCurveSize (2, nx);\r
+                       rPlotFile.addColumn (0, pX);\r
+                       rPlotFile.addColumn (1, pY);\r
                }\r
-               VectorPlotCurve* plotCurve = new VectorPlotCurve (pVec, nx, minVal, maxVal);\r
-               wxPlotWindow* plotWindow = new wxPlotWindow (m_canvas, NULL, wxPoint(0,0), wxSize(500,300));\r
-               plotWindow->Add (reinterpret_cast<wxPlotCurve*>(plotCurve));\r
-               plotWindow->Enable(TRUE);\r
-               plotWindow->Show();\r
+               delete pX;\r
+               delete pY;\r
+               pPlotDoc->Modify(true);\r
        }\r
-\r
+       \r
 }\r
 
 void\r
@@ -472,27 +490,43 @@ ImageFileView::OnPlotCol (wxCommandEvent& event)
                // os << "No column selected. Please use left mouse button on image to select column\n";\r
                return;\r
        }\r
-\r
+       \r
     const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();\r
     ImageFileArrayConst v = rIF.getArray();\r
     int nx = rIF.nx();\r
     int ny = rIF.ny();\r
-\r
+       \r
     if (v != NULL && xCursor < nx) {\r
-               double* pVec = new double [ny];\r
+               double* pX = new double [ny];\r
+               double* pY = new double [ny];\r
                double minVal = v[xCursor][0];\r
                double maxVal = minVal;\r
                for (int i = 0; i < ny; i++) {\r
-                       if (minVal < v[xCursor][i])\r
-                               minVal = v[xCursor][i];\r
-                       else if (maxVal > v[xCursor][i])\r
-                               maxVal = v[xCursor][i];\r
-                       pVec[i] = v[xCursor][i];\r
+                       double y = v[xCursor][i];\r
+                       if (minVal < y)\r
+                               minVal = y;\r
+                       else if (maxVal > y)\r
+                               maxVal = y;\r
+                       pX[i] = i;\r
+                       pY[i] = y;\r
                }\r
-\r
-               VectorPlotCurve* plotCurve = new VectorPlotCurve (pVec, ny, minVal, maxVal);\r
-               wxPlotWindow plotWindow (m_canvas, NULL, wxPoint(0,0), wxSize(500,300));\r
-               plotWindow.Add (reinterpret_cast<wxPlotCurve*>(plotCurve));\r
+               PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));\r
+               if (! pPlotDoc) {\r
+                       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
+                       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
        }\r
 }\r
 \r
@@ -573,7 +607,11 @@ PhantomView::OnProjections (wxCommandEvent& event)
                
                if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
                        const Phantom& rPhantom = GetDocument()->getPhantom();
-                       ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
+                       ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));\r
+                       if (! pProjectionDoc) {\r
+                               sys_error (ERR_SEVERE, "Unable to create projection document");\r
+                               return;\r
+                       }
                        Projections& rProj = pProjectionDoc->getProjections();
                        Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
                        if (theScanner.fail()) {
@@ -650,7 +688,11 @@ PhantomView::OnRasterize (wxCommandEvent& event)
                        nSamples = 1;
                if (xSize > 0 && ySize > 0) {
                        const Phantom& rPhantom = GetDocument()->getPhantom();
-                       ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
+                       ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));\r
+                       if (! pRasterDoc) {\r
+                               sys_error (ERR_SEVERE, "Unable to create image file");\r
+                               return;\r
+                       }
                        ImageFile& imageFile = pRasterDoc->getImageFile();
                        
                        imageFile.setArraySize (xSize, ySize);
@@ -885,7 +927,11 @@ ProjectionFileView::OnReconstruct (wxCommandEvent& event)
                m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
                m_iDefaultTrace = dialogReconstruction.getTrace();
                if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
-                       ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
+                       ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));\r
+                       if (pReconDoc) {\r
+                               sys_error (ERR_SEVERE, "Unable to create image file");\r
+                               return;\r
+                       }
                        ImageFile& imageFile = pReconDoc->getImageFile();
                        const Projections& rProj = GetDocument()->getProjections();
                        imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
@@ -1126,7 +1172,6 @@ ProjectionFileView::OnClose (bool deleteWindow)
 
 
 // PlotFileCanvas
-
 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
 : wxScrolledWindow(frame, -1, pos, size, style)
 {
@@ -1138,7 +1183,8 @@ PlotFileCanvas::OnDraw(wxDC& dc)
 {
     if (m_pView)
         m_pView->OnDraw(& dc);
-}
+}\r
+
 
 // PlotFileView
 
@@ -1146,6 +1192,8 @@ IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
 
 BEGIN_EVENT_TABLE(PlotFileView, wxView)
 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
+EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)\r
+EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)\r
 END_EVENT_TABLE()
 
 PlotFileView::PlotFileView(void) 
@@ -1160,7 +1208,7 @@ PlotFileView::~PlotFileView(void)
 void
 PlotFileView::OnProperties (wxCommandEvent& event)
 {
-       const PlotFile& rProj = GetDocument()->getPlot();
+       const PlotFile& rProj = GetDocument()->getPlotFile();
        std::ostringstream os;\r
        os << "Columns: " << rProj.getNumColumns() << ", Records: " << rProj.getNumRecords() << "\n";
        *theApp->getLog() << os.str().c_str();
@@ -1169,6 +1217,57 @@ PlotFileView::OnProperties (wxCommandEvent& event)
 }
 
 
+void \r
+PlotFileView::OnScaleAuto (wxCommandEvent& event)\r
+{\r
+       const PlotFile& rPlotFile = GetDocument()->getPlotFile();\r
+       double min, max, mean, mode, median, stddev;\r
+       rPlotFile.statistics (1, min, max, mean, mode, median, stddev);\r
+       DialogAutoScaleParameters dialogAutoScale (m_frame, mean, mode, median, stddev, m_dAutoScaleFactor);\r
+    int iRetVal = dialogAutoScale.ShowModal();\r
+    if (iRetVal == wxID_OK) {\r
+               m_bMinSpecified = true;\r
+               m_bMaxSpecified = true;\r
+               double dMin, dMax;\r
+               if (dialogAutoScale.getMinMax (&dMin, &dMax)) {\r
+                       m_dMinPixel = dMin;\r
+                       m_dMaxPixel = dMax;\r
+                       m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();\r
+                       OnUpdate (this, NULL);\r
+               }\r
+    }\r
+}\r
+\r
+void \r
+PlotFileView::OnScaleMinMax (wxCommandEvent& event)\r
+{\r
+       const PlotFile& rPlotFile = GetDocument()->getPlotFile();\r
+    double min, max;\r
+\r
+    if (! m_bMinSpecified && ! m_bMaxSpecified) {\r
+               if (! rPlotFile.getMinMax (1, min, max)) {\r
+                       *theApp->getLog() << "Error: unable to find Min/Max\n";\r
+                       return;\r
+       }\r
+       }\r
+       \r
+    if (m_bMinSpecified)\r
+               min = m_dMinPixel;\r
+    if (m_bMaxSpecified)\r
+               max = m_dMaxPixel;\r
+       \r
+    DialogGetMinMax dialogMinMax (m_frame, "Set Y-axis Minimum & Maximum", min, max);\r
+    int retVal = dialogMinMax.ShowModal();\r
+    if (retVal == wxID_OK) {\r
+               m_bMinSpecified = true;\r
+               m_bMaxSpecified = true;\r
+               m_dMinPixel = dialogMinMax.getMinimum();\r
+               m_dMaxPixel = dialogMinMax.getMaximum();\r
+               OnUpdate (this, NULL);\r
+    }\r
+}\r
+\r
+\r
 PlotFileCanvas* 
 PlotFileView::CreateCanvas (wxView *view, wxFrame *parent)
 {
@@ -1205,6 +1304,10 @@ PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
     file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
     file_menu->Append(wxID_PREVIEW, "Print Pre&view");
     
+    wxMenu *view_menu = new wxMenu;\r
+    view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");\r
+    view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");\r
+    \r
     wxMenu *help_menu = new wxMenu;
     help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
     help_menu->AppendSeparator();
@@ -1212,7 +1315,8 @@ PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
     
     wxMenuBar *menu_bar = new wxMenuBar;
     
-    menu_bar->Append(file_menu, "&File");
+    menu_bar->Append(file_menu, "&File");\r
+       menu_bar->Append(view_menu, "&View");
     menu_bar->Append(help_menu, "&Help");
     
     subframe->SetMenuBar(menu_bar);
@@ -1229,6 +1333,10 @@ PlotFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
     m_frame = CreateChildFrame(doc, this);
     SetFrame(m_frame);
     
+       m_bMinSpecified = false;\r
+       m_bMaxSpecified = false;\r
+    m_dAutoScaleFactor = 1.;\r
+\r
     int width, height;
     m_frame->GetClientSize(&width, &height);
     m_frame->SetTitle ("Plot File");
@@ -1249,25 +1357,71 @@ PlotFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
 void 
 PlotFileView::OnDraw (wxDC* dc)
 {
-    if (m_bitmap.Ok())
-      dc->DrawBitmap (m_bitmap, 0, 0, false);
+    const PlotFile& rPlotFile = GetDocument()->getPlotFile();\r
+    const int iNColumns = rPlotFile.getNumColumns();\r
+       const int iNRecords = rPlotFile.getNumRecords();\r
+       \r
+       if (iNColumns > 0 && iNRecords > 0) {\r
+               int xsize, ysize;\r
+               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
+               if (m_bMinSpecified) {\r
+                       std::ostringstream os;\r
+                       os << "ymin " << m_dMinPixel;\r
+                       plot.ezset (os.str());\r
+               }\r
+\r
+               if (m_bMaxSpecified) {\r
+                       std::ostringstream os;\r
+                       os << "ymax " << m_dMaxPixel;\r
+                       plot.ezset (os.str());\r
+               }\r
+\r
+               plot.ezset("box");\r
+               plot.ezset("grid");\r
+               \r
+               double* pdXaxis = new double [iNRecords];\r
+               rPlotFile.getColumn (0, pdXaxis);\r
+               \r
+               double* pdY = new double [iNRecords];\r
+               for (int iCol = 1; iCol < iNColumns; iCol++) {\r
+                       rPlotFile.getColumn (iCol, pdY);\r
+                       plot.addCurve (pdXaxis, pdY, iNRecords);\r
+               }\r
+               \r
+               delete pdXaxis;\r
+               delete pdY;\r
+               \r
+               plot.plot();\r
+       }\r
 }
 
 
 void 
 PlotFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
 {
-    const PlotFile& rPlot = GetDocument()->getPlotFile();
-    const int iNColumns = rPlot.getNumColumns();\r
-       const int iNRecords = rPlot.getNumRecords();
-    if (iNColumns > 0 && iNRecords > 0) {
-//      int xSize, ySize;\r
-//      m_frame->SetClientSize (xSize, ySize);
-//    m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
-    }
-    
     if (m_canvas)
-      m_canvas->Refresh();
+               m_canvas->Refresh();
 }
 
 bool 
@@ -1281,14 +1435,14 @@ PlotFileView::OnClose (bool deleteWindow)
     m_canvas = NULL;
     wxString s(wxTheApp->GetAppName());
     if (m_frame)
-      m_frame->SetTitle(s);
+               m_frame->SetTitle(s);
     SetFrame(NULL);
        
     Activate(false);
     
     if (deleteWindow) {
-      delete m_frame;
-      return true;
+               delete m_frame;
+               return true;
     }
     return true;
 }