+ if (!GetDocument()->Close())
+ return false;
+
+ //m_canvas->Clear();
+ //m_canvas->setView(NULL);
+ m_canvas = NULL;
+// wxString s(wxTheApp->GetAppName());
+// if (m_frame)
+// m_frame->SetTitle(s);
+ SetFrame(NULL);
+
+ Activate(false);
+
+ if (deleteWindow) {
+ delete m_frame;
+ return true;
+ }
+ return true;
+}
+
+
+
+// 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;
+}
+
+PlotFileCanvas::~PlotFileCanvas ()
+{
+ if (m_pView) {
+ wxMenu* pMenu = m_pView->getFileMenu();
+ theApp->getDocManager()->FileHistoryRemoveMenu (pMenu);
+ m_pView->canvasClosed();
+ m_pView = NULL;
+ }
+}
+
+void
+PlotFileCanvas::OnDraw(wxDC& dc)
+{
+ if (m_pView)
+ m_pView->OnDraw(& dc);
+}
+
+
+// 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)
+EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
+EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
+END_EVENT_TABLE()
+
+PlotFileView::PlotFileView(void)
+: wxView(), m_canvas(NULL), m_frame(NULL), m_pEZPlot(NULL), m_pFileMenu(0)
+{
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+}
+
+PlotFileView::~PlotFileView(void)
+{
+ if (m_pEZPlot)
+ delete m_pEZPlot;
+}
+
+void
+PlotFileView::OnProperties (wxCommandEvent& event)
+{
+ const PlotFile& rPlot = GetDocument()->getPlotFile();
+ std::ostringstream os;
+ os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
+ rPlot.printHeadersBrief (os);
+ *theApp->getLog() << os.str().c_str();
+ wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
+ dialogMsg.ShowModal();
+}
+
+
+void
+PlotFileView::OnScaleAuto (wxCommandEvent& event)
+{
+ const PlotFile& rPlotFile = GetDocument()->getPlotFile();
+ double min, max, mean, mode, median, stddev;
+ rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
+ DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
+ int iRetVal = dialogAutoScale.ShowModal();
+ if (iRetVal == wxID_OK) {
+ m_bMinSpecified = true;
+ m_bMaxSpecified = true;
+ double dMin, dMax;
+ if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
+ m_dMinPixel = dMin;
+ m_dMaxPixel = dMax;
+ m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
+ OnUpdate (this, NULL);
+ }
+ }
+}
+
+void
+PlotFileView::OnScaleMinMax (wxCommandEvent& event)
+{
+ const PlotFile& rPlotFile = GetDocument()->getPlotFile();
+ double min;
+ double max;
+
+ if (! m_bMinSpecified || ! m_bMaxSpecified) {
+ if (! rPlotFile.getMinMax (1, min, max)) {
+ *theApp->getLog() << "Error: unable to find Min/Max\n";
+ return;
+ }
+ }
+
+ if (m_bMinSpecified)
+ min = m_dMinPixel;
+ if (m_bMaxSpecified)
+ max = m_dMaxPixel;
+
+ DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
+ int retVal = dialogMinMax.ShowModal();
+ if (retVal == wxID_OK) {
+ m_bMinSpecified = true;
+ m_bMaxSpecified = true;
+ m_dMinPixel = dialogMinMax.getMinimum();
+ m_dMaxPixel = dialogMinMax.getMaximum();
+ OnUpdate (this, NULL);
+ }
+}
+
+void
+PlotFileView::OnScaleFull (wxCommandEvent& event)
+{
+ if (m_bMinSpecified || m_bMaxSpecified) {
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ OnUpdate (this, NULL);
+ }
+}
+
+
+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)
+{
+#ifdef CTSIM_MDI
+ wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
+#else
+ wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
+#endif
+ theApp->setIconForFrame (subframe);
+
+ wxMenu *m_pFileMenu = new wxMenu;
+
+ m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
+ m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
+ m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
+ m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
+ m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
+ m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
+
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
+
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append(wxID_PRINT, "&Print...");
+ m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
+ m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
+#ifdef CTSIM_MDI
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
+#endif
+ theApp->getDocManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
+ theApp->getDocManager()->FileHistoryUseMenu(m_pFileMenu);
+
+ wxMenu *view_menu = new wxMenu;
+ view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
+ view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
+ view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
+
+ wxMenu *help_menu = new wxMenu;
+ help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
+ help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
+ help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
+
+ wxMenuBar *menu_bar = new wxMenuBar;
+
+ menu_bar->Append(m_pFileMenu, "&File");
+ menu_bar->Append(view_menu, "&View");
+ menu_bar->Append(help_menu, "&Help");
+
+ subframe->SetMenuBar(menu_bar);
+ subframe->Centre(wxBOTH);
+
+ wxAcceleratorEntry accelEntries[10];
+ accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
+ accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
+ accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
+ accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
+ accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
+ accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
+ accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
+ accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
+ accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
+ accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
+ wxAcceleratorTable accelTable (10, accelEntries);
+ subframe->SetAcceleratorTable (accelTable);
+
+ return subframe;
+}
+
+
+bool
+PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
+{
+ m_frame = CreateChildFrame(doc, this);
+ SetFrame(m_frame);
+
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ m_dAutoScaleFactor = 1.;
+
+ 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();
+ const int iNColumns = rPlotFile.getNumColumns();
+ const int iNRecords = rPlotFile.getNumRecords();
+
+ if (iNColumns > 0 && iNRecords > 0) {
+ int xsize, ysize;
+ m_canvas->GetClientSize (&xsize, &ysize);
+ SGPDriver driver (dc, xsize, ysize);
+ SGP sgp (driver);
+ if (m_pEZPlot)
+ m_pEZPlot->plot (&sgp);
+ }
+}