PLplot
5.10.0
|
00001 // Copyright (C) 2005 Werner Smekal 00002 // 00003 // This file is part of PLplot. 00004 // 00005 // PLplot is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU Library General Public License as published 00007 // by the Free Software Foundation; either version 2 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // PLplot is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU Library General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Library General Public License 00016 // along with PLplot; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 // 00019 00020 #include <wx/window.h> 00021 #include <wx/dcclient.h> 00022 00023 //#include "plplotP.h" 00024 #include "wxPLplotwindow.h" 00025 #include "wxPLplotstream.h" 00026 00027 00028 BEGIN_EVENT_TABLE( wxPLplotwindow, wxWindow ) 00029 EVT_SIZE( wxPLplotwindow::OnSize ) 00030 EVT_PAINT( wxPLplotwindow::OnPaint ) 00031 EVT_ERASE_BACKGROUND( wxPLplotwindow::OnErase ) 00032 END_EVENT_TABLE() 00033 00034 00036 // 00037 wxPLplotwindow::wxPLplotwindow( wxWindow* parent, wxWindowID id, const wxPoint& pos, 00038 const wxSize& size, long style, int pl_style ) : 00039 wxWindow( parent, id, pos, size, style | wxFULL_REPAINT_ON_RESIZE ) 00040 { 00041 // create MemoryDC and set size - if size not set (-1, -1) than 00042 // set size to (640,400) 00043 MemPlotDC = new wxMemoryDC; 00044 if ( size.GetWidth() < 0 || size.GetHeight() < 0 ) 00045 { 00046 m_width = 640; 00047 m_height = 400; 00048 } 00049 else 00050 { 00051 m_width = size.GetWidth(); 00052 m_height = size.GetHeight(); 00053 } 00054 bitmapWidth = m_width; 00055 bitmapHeight = m_height; 00056 00057 MemPlotDCBitmap = new wxBitmap( bitmapWidth, bitmapHeight, -1 ); 00058 MemPlotDC->SelectObject( *MemPlotDCBitmap ); 00059 00060 m_stream = new wxPLplotstream( (wxDC *) MemPlotDC, m_width, m_height, pl_style ); 00061 00062 m_stream->cmd( PLESC_GETBACKEND, &m_backend ); 00063 m_backend = 1 << ( m_backend + 2 ); 00064 00065 // tell wxWidgets to leave the background painting to this control 00066 SetBackgroundStyle( wxBG_STYLE_CUSTOM ); 00067 } 00068 00069 00071 // 00072 wxPLplotwindow::~wxPLplotwindow( void ) 00073 { 00074 MemPlotDC->SelectObject( wxNullBitmap ); 00075 00076 if ( MemPlotDCBitmap ) 00077 delete MemPlotDCBitmap; 00078 00079 if ( m_stream ) 00080 delete m_stream; 00081 00082 if ( MemPlotDC ) 00083 delete MemPlotDC; 00084 } 00085 00086 00088 // later), we also implement our own double buffering here (since the PLplot wxWidgets driver draws 00089 // into a wxMemoryDC) 00090 // 00091 void wxPLplotwindow::OnPaint( wxPaintEvent &WXUNUSED( event ) ) 00092 { 00093 wxPaintDC dc( this ); 00094 dc.Blit( 0, 0, m_width, m_height, MemPlotDC, 0, 0 ); 00095 } 00096 00097 00098 void wxPLplotwindow::OnSize( wxSizeEvent& WXUNUSED( event ) ) 00099 { 00100 int width, height; 00101 GetClientSize( &width, &height ); 00102 00103 // Check if we window was resized 00104 if ( ( m_width != width ) || ( m_height != height ) ) 00105 { 00106 if ( ( width > bitmapWidth ) || ( height > bitmapHeight ) ) 00107 { 00108 bitmapWidth = bitmapWidth > width ? bitmapWidth : width; 00109 bitmapHeight = bitmapHeight > height ? bitmapHeight : height; 00110 00111 MemPlotDC->SelectObject( wxNullBitmap ); 00112 if ( MemPlotDCBitmap ) 00113 delete MemPlotDCBitmap; 00114 MemPlotDCBitmap = new wxBitmap( bitmapWidth, bitmapHeight, -1 ); 00115 MemPlotDC->SelectObject( *MemPlotDCBitmap ); 00116 } 00117 00118 m_stream->SetSize( width, height ); 00119 m_stream->RenewPlot(); 00120 00121 m_width = width; 00122 m_height = height; 00123 } 00124 else 00125 { 00126 m_stream->Update(); 00127 Refresh( false ); 00128 } 00129 } 00130 00131 00133 // is responsible that the background is not erased in order to prevent flickering. 00134 // 00135 void wxPLplotwindow::OnErase( wxEraseEvent &WXUNUSED( event ) ) 00136 { 00137 } 00138 00139 00141 // 00142 void wxPLplotwindow::RenewPlot( void ) 00143 { 00144 if ( m_stream ) 00145 { 00146 m_stream->RenewPlot(); 00147 Refresh( false ); 00148 } 00149 } 00150 00151 00153 // 00154 bool wxPLplotwindow::SavePlot( const wxString& devname, const wxString& filename ) 00155 { 00156 int pls, pls_save; 00157 FILE *sfile; 00158 00159 if ( ( sfile = fopen( filename.mb_str(), "wb+" ) ) == NULL ) 00160 { 00161 return false; 00162 } 00163 00164 plgstrm( &pls ); 00165 plmkstrm( &pls_save ); 00166 if ( pls_save < 0 ) 00167 { 00168 fclose( sfile ); 00169 return false; 00170 } 00171 plsdev( devname.mb_str() ); 00172 plsfile( sfile ); 00173 00174 plspage( 0., 0., 800, 600, 0, 0 ); 00175 plcpstrm( pls, 0 ); 00176 pladv( 0 ); 00177 plreplot(); 00178 plend1(); 00179 plsstrm( pls ); 00180 00181 return true; 00182 }