+ //GetDocumentManager()->ActivateView (this, false, true);
+ if (! GetDocument() || ! GetDocument()->Close())
+ return false;
+
+ Activate(false);
+ if (m_pCanvas) {
+ m_pCanvas->setView(NULL);
+ m_pCanvas = NULL;
+ }
+ wxString s(wxTheApp->GetAppName());
+ if (m_pFrame)
+ m_pFrame->SetTitle(s);
+
+ SetFrame(NULL);
+
+ if (deleteWindow) {
+ delete m_pFrame;
+ m_pFrame = NULL;
+ if (GetDocument() && GetDocument()->getBadFileOpen())
+ ::wxYield(); // wxWindows bug workaround
+ }
+
+ 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 ()
+{
+}
+
+wxSize
+PlotFileCanvas::GetBestSize() const
+{
+ return wxSize (500, 300);
+}
+
+
+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(PLOTMENU_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()
+: wxView(), m_pFrame(0), m_pCanvas(0), m_pEZPlot(0), m_pFileMenu(0),
+ m_bMinSpecified(false), m_bMaxSpecified(false)
+{
+}
+
+PlotFileView::~PlotFileView()
+{
+ if (m_pEZPlot)
+ delete m_pEZPlot;
+
+ GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
+ GetDocumentManager()->ActivateView(this, FALSE, TRUE);
+}
+
+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() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
+ wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
+ dialogMsg.ShowModal();
+ GetDocument()->Activate();
+}
+
+
+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);
+ }
+ }
+ GetDocument()->Activate();
+}
+
+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);
+ }
+ GetDocument()->Activate();
+}
+
+void
+PlotFileView::OnScaleFull (wxCommandEvent& event)
+{
+ if (m_bMinSpecified || m_bMaxSpecified) {
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ OnUpdate (this, NULL);
+ }
+ GetDocument()->Activate();
+}
+
+
+PlotFileCanvas*
+PlotFileView::CreateCanvas (wxFrame* parent)
+{
+ PlotFileCanvas* pCanvas;
+
+ pCanvas = new PlotFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0);
+ pCanvas->SetBackgroundColour(*wxWHITE);
+ pCanvas->Clear();
+
+ return pCanvas;
+}
+
+#if CTSIM_MDI
+wxDocMDIChildFrame*
+#else
+wxDocChildFrame*
+#endif
+PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
+{
+#ifdef CTSIM_MDI
+ wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
+#else
+ wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
+#endif
+ theApp->setIconForFrame (subframe);
+
+ 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(PLOTMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
+
+ 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");
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
+ m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
+ GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
+ GetDocumentManager()->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_TIPS, "&Tips");
+ help_menu->Append (IDH_QUICKSTART, "&Quick Start");
+ 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[4];
+ accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
+ accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
+ accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
+ accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
+ wxAcceleratorTable accelTable (4, accelEntries);
+ subframe->SetAcceleratorTable (accelTable);
+
+ return subframe;
+}
+
+
+bool
+PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
+{
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ m_dAutoScaleFactor = 1.;
+
+ m_pFrame = CreateChildFrame(doc, this);
+ SetFrame(m_pFrame);
+ m_pCanvas = CreateCanvas (m_pFrame);
+ m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
+ m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
+ m_pFrame->SetTitle ("Plot File");
+
+ m_pFrame->Show(true);
+ Activate(true);
+
+ return true;
+}
+
+void
+PlotFileView::setInitialClientSize ()
+{
+ if (m_pFrame && m_pCanvas) {
+ wxSize bestSize = m_pCanvas->GetBestSize();
+
+ m_pFrame->SetClientSize (bestSize);
+ m_pFrame->Show (true);
+ m_pFrame->SetFocus();
+ }
+}
+
+
+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_pCanvas->GetClientSize (&xsize, &ysize);
+ SGPDriver driver (dc, xsize, ysize);
+ SGP sgp (driver);
+ if (m_pEZPlot)
+ m_pEZPlot->plot (&sgp);
+ }
+}