• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

wxPLplotwindow.cpp

Go to the documentation of this file.
00001 // $Id: wxPLplotwindow.cpp 11760 2011-06-01 19:29:11Z airwin $
00002 //
00003 // Copyright (C) 2005  Werner Smekal
00004 //
00005 // This file is part of PLplot.
00006 //
00007 // PLplot is free software; you can redistribute it and/or modify
00008 // it under the terms of the GNU Library General Public License as published
00009 // by the Free Software Foundation; either version 2 of the License, or
00010 // (at your option) any later version.
00011 //
00012 // PLplot is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU Library General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU Library General Public License
00018 // along with PLplot; if not, write to the Free Software
00019 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020 //
00021 
00022 #include <wx/window.h>
00023 #include <wx/dcclient.h>
00024 
00025 //#include "plplotP.h"
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     // create MemoryDC and set size - if size not set (-1, -1) than
00044     // set size to (640,400)
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     // tell wxWidgets to leave the background painting to this control
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 //  later), we also implement our own double buffering here (since the PLplot wxWidgets driver draws
00091 //  into a wxMemoryDC)
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     // Check if we window was resized
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 //  is responsible that the background is not erased in order to prevent flickering.
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 }

Generated on Wed Oct 12 2011 20:42:23 for PLplot by  doxygen 1.7.1