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

wxPLplotstream.cpp

Go to the documentation of this file.
00001 // $Id: wxPLplotstream.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 // wxwidgets headers
00023 #include "wx/wx.h"
00024 
00025 // plplot headers
00026 #include "plplotP.h"
00027 
00028 #include "wxPLplotstream.h"
00029 
00031 //  Here we set the driver (wxwidgets :), and tell plplot in which dc to
00032 //  plot to and the size of the canvas. We also check and set several
00033 //  device style options.
00034 //
00035 wxPLplotstream::wxPLplotstream( wxDC *dc, int width, int height, int style ) : plstream()
00036 {
00037     Create( dc, width, height, style );
00038 }
00039 
00040 
00041 wxPLplotstream::wxPLplotstream() : plstream()
00042 {
00043 }
00044 
00045 
00046 void wxPLplotstream::Create( wxDC *dc, int width, int height, int style )
00047 {
00048     const size_t bufferSize = 256;
00049 
00050     m_dc     = dc;
00051     m_width  = width;
00052     m_height = height;
00053     m_style  = style;
00054     m_image  = NULL;
00055 
00056     sdev( "wxwidgets" );
00057     spage( 0.0, 0.0, m_width, m_height, 0, 0 );
00058 
00059     // use freetype, antialized canvas?
00060     char drvopt[bufferSize], buffer[bufferSize];
00061     drvopt[0] = '\0';
00062 #ifdef WX_TEMP_HAVE_FREETYPE_IS_ON
00063     sprintf( buffer, "freetype=%d,smooth=%d,",
00064         m_style & wxPLPLOT_FREETYPE ? 1 : 0,
00065         m_style & wxPLPLOT_SMOOTH_TEXT ? 1 : 0 );
00066     strcat( drvopt, buffer );
00067 #endif
00068 
00069     int backend;
00070     if ( m_style & wxPLPLOT_BACKEND_GC )
00071         backend = 2;
00072     else if ( m_style & wxPLPLOT_BACKEND_AGG )
00073         backend = 1;
00074     else
00075         backend = 0;
00076 
00077     sprintf( buffer, "hrshsym=%d,text=%d,backend=%d",
00078         m_style & wxPLPLOT_USE_HERSHEY_SYMBOLS ? 1 : 0,
00079         m_style & wxPLPLOT_DRAW_TEXT ? 1 : 0,
00080         backend );
00081     strncat( drvopt, buffer, bufferSize - strlen( drvopt ) );
00082 
00083     setopt( "-drvopt", drvopt );
00084 
00085     init();
00086 
00087     cmd( PLESC_GETBACKEND, &m_backend );
00088     m_backend = 1 << ( m_backend + 2 );
00089 
00090     if ( m_backend == wxPLPLOT_BACKEND_AGG )
00091     {
00092         m_image = new wxImage( m_width, m_height );
00093         cmd( PLESC_DEVINIT, (void *) m_image );
00094     }
00095     else
00096         cmd( PLESC_DEVINIT, (void *) m_dc );
00097 }
00098 
00099 
00100 wxPLplotstream::~wxPLplotstream()
00101 {
00102     if ( m_image )
00103         delete m_image;
00104 }
00105 
00106 
00108 //  code processed before every call of a plplot functions, since set_stream()
00109 //  is called before every plplot function. Not used in the moment.
00110 //
00111 void wxPLplotstream::set_stream()
00112 {
00113     plstream::set_stream();
00114 }
00115 
00116 
00118 //  to set the new size. You need to call RenewPlot afterwards.
00119 //
00120 void wxPLplotstream::SetSize( int width, int height )
00121 {
00122     // For the AGG backend it is important to set first the new image buffer
00123     //       and tell the driver the new size if the buffer size increases and
00124     //       the other way round if the buffer size decreases. There is no impact
00125     //       for the other backends. This is kind of hacky, but I have no better
00126     //       idea in the moment
00127     if ( width * height > m_width * m_height )
00128     {
00129         if ( m_image )
00130         {
00131             delete m_image;
00132             m_image = new wxImage( width, height );
00133             cmd( PLESC_DEVINIT, (void *) m_image );
00134         }
00135         wxSize size( width, height );
00136         cmd( PLESC_RESIZE, (void *) &size );
00137     }
00138     else
00139     {
00140         wxSize size( width, height );
00141         cmd( PLESC_RESIZE, (void *) &size );
00142         if ( m_image )
00143         {
00144             delete m_image;
00145             m_image = new wxImage( width, height );
00146             cmd( PLESC_DEVINIT, (void *) m_image );
00147         }
00148     }
00149 
00150     m_width  = width;
00151     m_height = height;
00152 }
00153 
00154 
00156 //
00157 void wxPLplotstream::RenewPlot()
00158 {
00159     replot();
00160     Update();
00161 }
00162 
00163 
00164 // After calling plot commands it is not sure, that the dc
00165 // gets updated properly, therefore you need to call this function.
00166 //
00167 void wxPLplotstream::Update()
00168 {
00169     if ( m_image )
00170     {
00171         wxMemoryDC MemoryDC;
00172         wxBitmap   bitmap( *m_image, -1 );
00173         MemoryDC.SelectObject( bitmap );
00174         m_dc->Blit( 0, 0, m_width, m_height, &MemoryDC, 0, 0 );
00175         MemoryDC.SelectObject( wxNullBitmap );
00176     }
00177 }

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