+
+// PlotFileCanvas
+PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
+: wxScrolledWindow(frame, -1, pos, size, style)
+{
+ m_pView = v;
+}
+
+void
+PlotFileCanvas::OnDraw(wxDC& dc)
+{
+ if (m_pView)
+ m_pView->OnDraw(& dc);
+}\r
+
+
+// PlotFileView
+
+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)
+: wxView(), m_canvas(NULL), m_frame(NULL)
+{
+}
+
+PlotFileView::~PlotFileView(void)
+{
+}
+
+void
+PlotFileView::OnProperties (wxCommandEvent& event)
+{
+ const PlotFile& rProj = GetDocument()->getPlotFile();
+ std::ostringstream os;\r
+ os << "Columns: " << rProj.getNumColumns() << ", Records: " << rProj.getNumRecords() << "\n";
+ *theApp->getLog() << os.str().c_str();
+ wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
+ dialogMsg.ShowModal();
+}
+
+
+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)
+{
+ PlotFileCanvas* pCanvas;
+ int width, height;
+ parent->GetClientSize(&width, &height);
+
+ pCanvas = new PlotFileCanvas (dynamic_cast<PlotFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
+
+ pCanvas->SetBackgroundColour(*wxWHITE);
+ pCanvas->Clear();
+
+ return pCanvas;
+}
+
+wxFrame*
+PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
+{
+ wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
+
+ wxMenu *file_menu = new wxMenu;
+
+ file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
+ file_menu->Append(wxID_OPEN, "&Open...");
+ file_menu->Append(wxID_SAVE, "&Save");
+ file_menu->Append(wxID_SAVEAS, "Save &As...");
+ file_menu->Append(wxID_CLOSE, "&Close");
+
+ file_menu->AppendSeparator();
+ file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
+
+ file_menu->AppendSeparator();
+ file_menu->Append(wxID_PRINT, "&Print...");
+ 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();
+ help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
+
+ wxMenuBar *menu_bar = new wxMenuBar;
+
+ menu_bar->Append(file_menu, "&File");\r
+ menu_bar->Append(view_menu, "&View");
+ menu_bar->Append(help_menu, "&Help");
+
+ subframe->SetMenuBar(menu_bar);
+
+ subframe->Centre(wxBOTH);
+
+ return subframe;
+}
+
+
+bool
+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");
+ m_canvas = CreateCanvas (this, m_frame);
+
+#ifdef __X__
+ int x, y; // X requires a forced resize
+ m_frame->GetSize(&x, &y);
+ m_frame->SetSize(-1, -1, x, y);
+#endif
+
+ m_frame->Show(true);
+ Activate(true);
+
+ return true;
+}
+
+void
+PlotFileView::OnDraw (wxDC* dc)
+{
+ 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
+ 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
+ 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) )
+{
+ if (m_canvas)
+ m_canvas->Refresh();
+}
+
+bool
+PlotFileView::OnClose (bool deleteWindow)
+{
+ if (!GetDocument()->Close())
+ return false;
+
+ m_canvas->Clear();
+ m_canvas->m_pView = NULL;
+ m_canvas = NULL;
+ wxString s(wxTheApp->GetAppName());
+ if (m_frame)
+ m_frame->SetTitle(s);
+ SetFrame(NULL);
+
+ Activate(false);
+
+ if (deleteWindow) {
+ delete m_frame;