Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <wx/window.h>
00023 #include <wx/dcclient.h>
00024
00025
00026 #include "wxPLplotwindow.h"
00027 #include "wxPLplotstream.h"
00028
00029
00030 BEGIN_EVENT_TABLE( wxPLplotwindow, wxWindow )
00031 EVT_SIZE( wxPLplotwindow::OnSize )
00032 EVT_PAINT( wxPLplotwindow::OnPaint )
00033 EVT_ERASE_BACKGROUND( wxPLplotwindow::OnErase )
00034 END_EVENT_TABLE()
00035
00036
00038
00039 wxPLplotwindow::wxPLplotwindow( wxWindow* parent, wxWindowID id, const wxPoint& pos,
00040 const wxSize& size, long style, int pl_style ) :
00041 wxWindow( parent, id, pos, size, style | wxFULL_REPAINT_ON_RESIZE )
00042 {
00043
00044
00045 MemPlotDC = new wxMemoryDC;
00046 if ( size.GetWidth() < 0 || size.GetHeight() < 0 )
00047 {
00048 m_width = 640;
00049 m_height = 400;
00050 }
00051 else
00052 {
00053 m_width = size.GetWidth();
00054 m_height = size.GetHeight();
00055 }
00056 bitmapWidth = m_width;
00057 bitmapHeight = m_height;
00058
00059 MemPlotDCBitmap = new wxBitmap( bitmapWidth, bitmapHeight, -1 );
00060 MemPlotDC->SelectObject( *MemPlotDCBitmap );
00061
00062 m_stream = new wxPLplotstream( (wxDC *) MemPlotDC, m_width, m_height, pl_style );
00063
00064 m_stream->cmd( PLESC_GETBACKEND, &m_backend );
00065 m_backend = 1 << ( m_backend + 2 );
00066
00067
00068 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
00069 }
00070
00071
00073
00074 wxPLplotwindow::~wxPLplotwindow( void )
00075 {
00076 MemPlotDC->SelectObject( wxNullBitmap );
00077
00078 if ( MemPlotDCBitmap )
00079 delete MemPlotDCBitmap;
00080
00081 if ( m_stream )
00082 delete m_stream;
00083
00084 if ( MemPlotDC )
00085 delete MemPlotDC;
00086 }
00087
00088
00090
00091
00092
00093 void wxPLplotwindow::OnPaint( wxPaintEvent &WXUNUSED( event ) )
00094 {
00095 wxPaintDC dc( this );
00096 dc.Blit( 0, 0, m_width, m_height, MemPlotDC, 0, 0 );
00097 }
00098
00099
00100 void wxPLplotwindow::OnSize( wxSizeEvent& WXUNUSED( event ) )
00101 {
00102 int width, height;
00103 GetClientSize( &width, &height );
00104
00105
00106 if ( ( m_width != width ) || ( m_height != height ) )
00107 {
00108 if ( ( width > bitmapWidth ) || ( height > bitmapHeight ) )
00109 {
00110 bitmapWidth = bitmapWidth > width ? bitmapWidth : width;
00111 bitmapHeight = bitmapHeight > height ? bitmapHeight : height;
00112
00113 MemPlotDC->SelectObject( wxNullBitmap );
00114 if ( MemPlotDCBitmap )
00115 delete MemPlotDCBitmap;
00116 MemPlotDCBitmap = new wxBitmap( bitmapWidth, bitmapHeight, -1 );
00117 MemPlotDC->SelectObject( *MemPlotDCBitmap );
00118 }
00119
00120 m_stream->SetSize( width, height );
00121 m_stream->RenewPlot();
00122
00123 m_width = width;
00124 m_height = height;
00125 }
00126 else
00127 {
00128 m_stream->Update();
00129 Refresh( false );
00130 }
00131 }
00132
00133
00135
00136
00137 void wxPLplotwindow::OnErase( wxEraseEvent &WXUNUSED( event ) )
00138 {
00139 }
00140
00141
00143
00144 void wxPLplotwindow::RenewPlot( void )
00145 {
00146 if ( m_stream )
00147 {
00148 m_stream->RenewPlot();
00149 Refresh( false );
00150 }
00151 }
00152
00153
00155
00156 bool wxPLplotwindow::SavePlot( const wxString& devname, const wxString& filename )
00157 {
00158 int pls, pls_save;
00159 FILE *sfile;
00160
00161 if ( ( sfile = fopen( filename.mb_str(), "wb+" ) ) == NULL )
00162 {
00163 return false;
00164 }
00165
00166 plgstrm( &pls );
00167 plmkstrm( &pls_save );
00168 if ( pls_save < 0 )
00169 {
00170 fclose( sfile );
00171 return false;
00172 }
00173 plsdev( devname.mb_str() );
00174 plsfile( sfile );
00175
00176 plspage( 0., 0., 800, 600, 0, 0 );
00177 plcpstrm( pls, 0 );
00178 pladv( 0 );
00179 plreplot();
00180 plend1();
00181 plsstrm( pls );
00182
00183 return true;
00184 }