drawing_left_canvas.cpp

Go to the documentation of this file.
00001 
00002 // Name:        drawing_left_canvas.cpp
00003 // Purpose:     
00004 // Author:      NDA
00005 // Modified by: 
00006 // Created:     10/10/2006 15:55:30
00007 // RCS-ID:      
00008 // Copyright:   CAEN S.p.A All rights reserved.
00009 // Licence:     
00011 
00012 // Generated by DialogBlocks (unregistered), 10/10/2006 15:55:30
00013 
00014 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
00015 #pragma implementation "drawing_left_canvas.h"
00016 #endif
00017 
00018 // For compilers that support precompilation, includes "wx/wx.h".
00019 #include "wx/wxprec.h"
00020 
00021 #ifdef __BORLANDC__
00022 #pragma hdrstop
00023 #endif
00024 
00025 #ifndef WX_PRECOMP
00026 #include "wx/wx.h"
00027 #endif
00028 #include <wx/dcbuffer.h>
00029 
00032 
00033 #include "drawing_left_canvas.h"
00034 #include "drawing_panel.h"
00035 
00038 
00043 IMPLEMENT_DYNAMIC_CLASS( DrawingLeftCanvas, wxPanel )
00044 
00045 
00049 BEGIN_EVENT_TABLE( DrawingLeftCanvas, wxPanel )
00050 
00052     EVT_SIZE( DrawingLeftCanvas::OnSize )
00053     EVT_PAINT( DrawingLeftCanvas::OnPaint )
00054     EVT_ERASE_BACKGROUND( DrawingLeftCanvas::OnEraseBackground )
00055 
00057 
00058 END_EVENT_TABLE()
00059 
00064 DrawingLeftCanvas::DrawingLeftCanvas( ): m_parent( NULL), m_first_time(true), m_scope_index( 0)
00065 {
00066         this->m_p_back_bitmap= new wxBitmap( 1, 1);
00067 }
00068 
00069 DrawingLeftCanvas::DrawingLeftCanvas( int scope_index, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ): m_parent( (DrawingPanel*)parent), m_first_time(true)
00070 {
00071         this->m_scope_index= scope_index;
00072         this->m_p_back_bitmap= new wxBitmap( 1, 1);
00073     Create(parent, id, pos, size, style);
00074 }
00075 DrawingLeftCanvas::~DrawingLeftCanvas()
00076 {
00077         delete this->m_p_back_bitmap; 
00078 }
00079 
00084 bool DrawingLeftCanvas::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
00085 {
00088 
00090     wxPanel::Create( parent, id, pos, size, style );
00091 
00092     CreateControls();
00093     Centre();
00095     return true;
00096 }
00097 
00102 void DrawingLeftCanvas::CreateControls()
00103 {    
00105     // Generated by DialogBlocks, 10/10/2006 16:06:16 (unregistered)
00106 
00107     DrawingLeftCanvas* itemPanel1 = this;
00108 
00110 }
00111 
00116 bool DrawingLeftCanvas::ShowToolTips()
00117 {
00118     return true;
00119 }
00120 
00125 wxBitmap DrawingLeftCanvas::GetBitmapResource( const wxString& name )
00126 {
00127     // Bitmap retrieval
00129     wxUnusedVar(name);
00130     return wxNullBitmap;
00132 }
00133 
00138 wxIcon DrawingLeftCanvas::GetIconResource( const wxString& name )
00139 {
00140     // Icon retrieval
00142     wxUnusedVar(name);
00143     return wxNullIcon;
00145 }
00150 void DrawingLeftCanvas::OnSize( wxSizeEvent& event )
00151 {
00152         this->RefreshBackBitmap();
00153     event.Skip();
00154 }
00155 
00160 void DrawingLeftCanvas::OnPaint( wxPaintEvent& event )
00161 {
00162         if( this->m_parent->IsFreezed())
00163         {
00164                 event.Skip();
00165                 return;
00166         }
00167         if( this->m_first_time )
00168         {
00169                 this->RefreshBackBitmap();
00170                 this->m_first_time= false;
00171         }
00172 
00173         // wxMutexLocker lock( this->m_mutex);
00174         if( this->m_parent->m_app_settings== NULL)
00175                 return;
00176 
00177     wxBufferedPaintDC dc( this /*, wxBUFFER_VIRTUAL_AREA*/);
00178         dc.DrawBitmap( *this->m_p_back_bitmap, 0, 0, false);
00179 }
00180 
00185 void DrawingLeftCanvas::OnEraseBackground( wxEraseEvent& /* event*/ )
00186 {
00187 }
00188 
00189 void DrawingLeftCanvas::DrawPosition( wxDC &dc)
00190 {
00191         //
00192         // Loop boards
00193         for( size_t i= 0; i< this->m_parent->m_app_settings->m_board_array.GetCount(); i++)
00194         {
00195                 GenericBoard *board= ( GenericBoard *)this->m_parent->m_app_settings->m_board_array[ i];
00196                 board->DrawPosition( this->m_scope_index, dc);
00197         }
00198 }
00199 void DrawingLeftCanvas:: RefreshBackBitmap( )
00200 {
00201         if( this->m_parent->m_app_settings== NULL)
00202                 return;
00203         if( this->m_parent->IsFreezed())
00204         {
00205                 return;
00206         }
00207         this->m_pix_X= this->GetRect().width;
00208         this->m_pix_Y= this->GetRect().height;
00209 
00210         // Loop boards
00211         for( size_t i= 0; i< this->m_parent->m_app_settings->m_board_array.GetCount(); i++)
00212         {
00213                 GenericBoard *board= ( GenericBoard *)this->m_parent->m_app_settings->m_board_array[ i];
00214                 board->SetLeftDiv2Pix( this->m_scope_index, (double)this->m_pix_Y/ DrawingCanvas::NUM_DIV_PER_SCREEN);
00215                 board->SetLeftPix( this->m_scope_index, this->m_pix_X, this->m_pix_Y);
00216         }
00217 
00218 
00219         if(( this->m_p_back_bitmap->GetWidth()!= this->m_pix_X)||
00220                 ( this->m_p_back_bitmap->GetHeight()!= this->m_pix_Y))
00221         {
00222                 delete this->m_p_back_bitmap;
00223                 this->m_p_back_bitmap= new wxBitmap( this->m_pix_X, this->m_pix_Y);
00224         }
00225 
00226         wxMemoryDC dc;
00227         dc.SelectObject( *this->m_p_back_bitmap);
00228 
00229         this->DrawBackground( dc);
00230         this->DrawPosition( dc);
00231         dc.SelectObject( wxNullBitmap);
00232 
00233 }
00234 void DrawingLeftCanvas::DrawBackground( wxDC &dc)
00235 {
00236         wxMutexLocker lock( this->m_parent->m_app_settings->m_mutex);
00237 
00238         if( this->m_parent->m_app_settings->m_back_brush[ this->m_scope_index]== NULL)
00239                 return;
00240         dc.SetBackground( *this->m_parent->m_app_settings->m_back_brush[ this->m_scope_index]);
00241         dc.Clear();
00242         // Restore original brush
00243         dc.SetBackground( *this->m_parent->m_app_settings->m_back_brush[ this->m_scope_index]);
00244 }
00245 

Generated on Mon Mar 19 17:14:07 2007 for CAENScope by  doxygen 1.4.6-NO