view_ch_control.cpp

Go to the documentation of this file.
00001 
00002 // Name:        view_ch_control.cpp
00003 // Purpose:     
00004 // Author:      NDA
00005 // Modified by: 
00006 // Created:     06/04/2006 10:37:55
00007 // RCS-ID:      
00008 // Copyright:   CAEN S.p.A All rights reserved.
00009 // Licence:     
00011 
00012 // Generated by DialogBlocks (unregistered), 06/04/2006 10:37:55
00013 
00014 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
00015 #pragma implementation "view_ch_control.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/cmndata.h>
00029 #include <wx/colordlg.h>
00030 
00033 
00034 #include "view_ch_control.h"
00035 
00038 
00043 IMPLEMENT_DYNAMIC_CLASS( ViewChControl, wxPanel )
00044 
00045 
00049 BEGIN_EVENT_TABLE( ViewChControl, wxPanel )
00050 
00052     EVT_TOGGLEBUTTON( ID_VIEW_ENABLE_TOGGLEBUTTON, ViewChControl::OnViewEnableTogglebuttonClick )
00053 
00054     EVT_BUTTON( ID_CHOOSE_COLOR_BUTTON, ViewChControl::OnChooseColorButtonClick )
00055 
00056     EVT_SPINCTRL( ID_LINE_WIDTH_SPINCTRL, ViewChControl::OnLineWidthSpinctrlUpdated )
00057 
00058     EVT_BUTTON( ID_OFFSET_Y_RESET_BUTTON, ViewChControl::OnOffsetYResetButtonClick )
00059 
00060     EVT_SPIN( ID_SPINBUTTON1, ViewChControl::OnSpinbutton1Updated )
00061 
00062     EVT_SPINCTRL( ID_VOLT_PER_DIV_SPINCTRL, ViewChControl::OnVoltPerDivSpinctrlUpdated )
00063 
00065 
00066     EVT_TEXT_ENTER( ID_LINE_WIDTH_SPINCTRL, ViewChControl::OnLineWidthSpinctrlTextUpdated )
00067     EVT_TEXT_ENTER( ID_VOLT_PER_DIV_SPINCTRL, ViewChControl::OnVoltPerDivSpinctrlTextUpdated )
00068 END_EVENT_TABLE()
00069 
00074 ViewChControl::ViewChControl( )
00075 {
00076 }
00077 
00078 ViewChControl::ViewChControl( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
00079 {
00080     Create(parent, id, pos, size, style);
00081 }
00082 
00087 bool ViewChControl::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
00088 {
00090     m_main_sizer_text = NULL;
00091     m_view_enable_control = NULL;
00092     m_color_control = NULL;
00093     m_line_width_control = NULL;
00094     m_ch_offset_reset_control = NULL;
00095     m_ch_offset_control = NULL;
00096     m_ch_volt_per_div_control = NULL;
00098 
00100     wxPanel::Create( parent, id, pos, size, style );
00101 
00102     CreateControls();
00103     if (GetSizer())
00104     {
00105         GetSizer()->SetSizeHints(this);
00106     }
00107     Centre();
00109     return true;
00110 }
00111 
00116 void ViewChControl::CreateControls()
00117 {    
00119     // Generated by DialogBlocks, 08/01/2007 16:38:14 (unregistered)
00120 
00121     ViewChControl* itemPanel1 = this;
00122 
00123     m_main_sizer_text = new wxStaticBox(itemPanel1, wxID_ANY, _("???"));
00124     wxStaticBoxSizer* itemStaticBoxSizer2 = new wxStaticBoxSizer(m_main_sizer_text, wxHORIZONTAL);
00125     itemPanel1->SetSizer(itemStaticBoxSizer2);
00126 
00127     m_view_enable_control = new wxToggleButton( itemPanel1, ID_VIEW_ENABLE_TOGGLEBUTTON, _("???"), wxDefaultPosition, wxSize(65, -1), 0 );
00128     m_view_enable_control->SetValue(true);
00129     m_view_enable_control->SetHelpText(_("Enable/Disable channel view"));
00130     if (ShowToolTips())
00131         m_view_enable_control->SetToolTip(_("Enable/Disable channel view"));
00132     m_view_enable_control->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD, false, _T("Verdana")));
00133     itemStaticBoxSizer2->Add(m_view_enable_control, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 3);
00134 
00135     m_color_control = new wxPanel( itemPanel1, ID_COLOR_PANEL, wxDefaultPosition, wxSize(30, 15), wxSIMPLE_BORDER|wxTAB_TRAVERSAL );
00136     itemStaticBoxSizer2->Add(m_color_control, 0, wxALIGN_CENTER_VERTICAL|wxALL, 1);
00137 
00138     wxButton* itemButton5 = new wxButton( itemPanel1, ID_CHOOSE_COLOR_BUTTON, _("..."), wxDefaultPosition, wxSize(30, 20), 0 );
00139     itemButton5->SetHelpText(_("Choose channel color"));
00140     if (ShowToolTips())
00141         itemButton5->SetToolTip(_("Choose channel color"));
00142     itemButton5->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD, false, _T("Verdana")));
00143     itemStaticBoxSizer2->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 1);
00144 
00145     m_line_width_control = new wxSpinCtrl( itemPanel1, ID_LINE_WIDTH_SPINCTRL, _T("1"), wxDefaultPosition, wxSize(45, -1), wxSP_ARROW_KEYS, 1, 20, 1 );
00146     m_line_width_control->SetHelpText(_("Set line width"));
00147     if (ShowToolTips())
00148         m_line_width_control->SetToolTip(_("Set line width"));
00149     itemStaticBoxSizer2->Add(m_line_width_control, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxTOP, 1);
00150 
00151     wxStaticBox* itemStaticBoxSizer7Static = new wxStaticBox(itemPanel1, wxID_ANY, _T(""));
00152     wxStaticBoxSizer* itemStaticBoxSizer7 = new wxStaticBoxSizer(itemStaticBoxSizer7Static, wxHORIZONTAL);
00153     itemStaticBoxSizer2->Add(itemStaticBoxSizer7, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 2);
00154 
00155     m_ch_offset_reset_control = new wxButton( itemPanel1, ID_OFFSET_Y_RESET_BUTTON, _("0"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
00156     m_ch_offset_reset_control->SetHelpText(_("Reset channel view offset"));
00157     if (ShowToolTips())
00158         m_ch_offset_reset_control->SetToolTip(_("Reset channel view offset"));
00159     m_ch_offset_reset_control->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD, false, _T("Tahoma")));
00160     itemStaticBoxSizer7->Add(m_ch_offset_reset_control, 0, wxALIGN_CENTER_VERTICAL, 5);
00161 
00162     m_ch_offset_control = new wxSpinButton( itemPanel1, ID_SPINBUTTON1, wxDefaultPosition, wxDefaultSize, wxSP_VERTICAL );
00163     m_ch_offset_control->SetHelpText(_("Set channel view offset"));
00164     if (ShowToolTips())
00165         m_ch_offset_control->SetToolTip(_("Set channel view offset"));
00166     itemStaticBoxSizer7->Add(m_ch_offset_control, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 3);
00167 
00168     m_ch_volt_per_div_control = new wxSpinCtrl( itemPanel1, ID_VOLT_PER_DIV_SPINCTRL, _T("1000"), wxDefaultPosition, wxSize(57, -1), wxSP_ARROW_KEYS, 1, 99999, 1000 );
00169     m_ch_volt_per_div_control->SetHelpText(_("Set channel view scale (mV/Div)"));
00170     if (ShowToolTips())
00171         m_ch_volt_per_div_control->SetToolTip(_("Set channel view scale (mV/Div)"));
00172     itemStaticBoxSizer2->Add(m_ch_volt_per_div_control, 0, wxALIGN_CENTER_VERTICAL|wxTOP, 1);
00173 
00175 
00176         this->m_ch_offset_control->SetRange( -200, 200);
00177 }
00178 
00183 bool ViewChControl::ShowToolTips()
00184 {
00185     return true;
00186 }
00187 
00192 wxBitmap ViewChControl::GetBitmapResource( const wxString& name )
00193 {
00194     // Bitmap retrieval
00196     wxUnusedVar(name);
00197     return wxNullBitmap;
00199 }
00200 
00205 wxIcon ViewChControl::GetIconResource( const wxString& name )
00206 {
00207     // Icon retrieval
00209     wxUnusedVar(name);
00210     return wxNullIcon;
00212 }
00213 
00214 bool ViewChControl::SetupBoard( GenericBoard* p_board, int ch_index, int ch_count, int scope_index, bool is_virtual)
00215 {
00216         this->m_is_virtual= is_virtual;
00217         this->m_p_board= p_board;
00218         this->m_ch_index= ch_index;
00219         this->m_ch_count= ch_count;
00220         this->m_scope_index= scope_index;
00221         if( this->m_is_virtual)
00222         {
00223                 if( ( size_t)this->m_ch_index>= this->m_p_board->m_virtual_channel_array.GetCount())
00224                         return false;
00225                 this->m_p_board_channel= (GenericBoardChannel*)this->m_p_board->m_virtual_channel_array[ this->m_ch_index];
00226         }
00227         else
00228         {
00229                 if( ( size_t)this->m_ch_index>= this->m_p_board->m_channel_array.GetCount())
00230                         return false;
00231                 this->m_p_board_channel= (GenericBoardChannel*)this->m_p_board->m_channel_array[ this->m_ch_index];
00232         }
00233         
00234         if( !this->UpdateControls())
00235                 return false;
00236         return true;
00237 }
00238 bool ViewChControl::UpdateControls( )
00239 {
00240         if( this->m_is_virtual)
00241                 this->m_main_sizer_text->SetLabel( wxString::Format( "VIRT %d", this->m_ch_count));
00242         else
00243                 this->m_main_sizer_text->SetLabel( wxString::Format( "%d", this->m_ch_count));
00244         this->m_color_control->SetBackgroundColour( this->m_p_board_channel->m_line_color[ this->m_scope_index]);
00245         this->m_line_width_control->SetValue( this->m_p_board_channel->m_line_width[ this->m_scope_index]);
00246 
00247         this->m_ch_offset_control->SetValue( (int)(double)(this->m_p_board_channel->m_offset_y[ this->m_scope_index]* 10.0));
00248         if( this->m_p_board_channel->m_volt_2_div[ this->m_scope_index]== 0)
00249                 this->m_p_board_channel->m_volt_2_div[ this->m_scope_index]= 0.01;
00250         this->m_ch_volt_per_div_control->SetValue( (int)(double)(1000.0/ this->m_p_board_channel->m_volt_2_div[ this->m_scope_index]));
00251         this->UpdateLinePen();
00252 
00253         this->m_view_enable_control->SetValue( this->m_p_board_channel->m_scope_view_enabled[ this->m_scope_index]);
00254         this->m_view_enable_control->SetLabel( this->m_view_enable_control->GetValue( )? _("Disable"): _("Enable"));
00255 
00256         return true;
00257 }
00262 void ViewChControl::OnChooseColorButtonClick( wxCommandEvent& /* event*/ )
00263 {
00264         wxColourData colour_data;
00265         colour_data.SetColour( this->m_p_board_channel->m_line_color[ this->m_scope_index]);
00266         wxColourDialog *dlg= new wxColourDialog( this, &colour_data);
00267         dlg->Centre();
00268         if( dlg->ShowModal()== wxID_OK)
00269         {
00270                 this->m_p_board_channel->m_line_color[ this->m_scope_index]= dlg->GetColourData().GetColour();
00271                 this->m_color_control->SetBackgroundColour( this->m_p_board_channel->m_line_color[ this->m_scope_index]);
00272                 this->m_color_control->Refresh();
00273                 this->UpdateLinePen();
00274         }
00275         delete dlg;
00276 }
00277 
00278 
00283 void ViewChControl::OnLineWidthSpinctrlUpdated( wxSpinEvent& event )
00284 {
00285         this->UpdateLineWidth( event.GetPosition());
00286 }
00287 
00288 
00289 void ViewChControl::UpdateLinePen( )
00290 {
00291         int wx_pen_style= wxSOLID;
00292 
00293         wxPen line_pen= wxPen( this->m_p_board_channel->m_line_color[ this->m_scope_index], this->m_p_board_channel->m_line_width[ this->m_scope_index], wx_pen_style);
00294         wxPen trigger_pen= wxPen( this->m_p_board_channel->m_line_color[ this->m_scope_index], 1, wxSOLID);
00295         this->m_p_board_channel->SetLinePen( this->m_scope_index, &line_pen, &trigger_pen);
00296         (this->m_p_board_channel->ScopeRefresh)( this->m_scope_index, true);
00297 }
00298 
00299 
00304 void ViewChControl::OnLineWidthSpinctrlTextUpdated( wxCommandEvent& /* event*/ )
00305 {
00306     int value= atoi( this->m_line_width_control->GetLabel());
00307     this->UpdateLineWidth( value);
00308 }
00309 
00310 
00311 void ViewChControl::UpdateLineWidth( int value)
00312 {
00313         this->m_p_board_channel->m_line_width[ this->m_scope_index]= value;
00314         this->UpdateLinePen();
00315 }
00316 
00317 void ViewChControl::UpdateOffset( void)
00318 {
00319         this->m_p_board_channel->m_offset_y[ this->m_scope_index]= (double)this->m_ch_offset_control->GetValue( )* 0.1;
00320         (this->m_p_board_channel->ScopeRefresh)( this->m_scope_index, true);
00321 }
00322 void ViewChControl::UpdateVoltPerDiv( int value)
00323 {
00324         if( value== 0)
00325                 value= 1;
00326         this->m_p_board_channel->SetVolt2Div( this->m_scope_index, 1000.0/ (double)value);
00327         (this->m_p_board_channel->ScopeRefresh)( this->m_scope_index, true);
00328 }
00333 void ViewChControl::OnVoltPerDivSpinctrlUpdated( wxSpinEvent& event)
00334 {
00335         this->UpdateVoltPerDiv( event.GetPosition());
00336 }
00337 
00342 void ViewChControl::OnVoltPerDivSpinctrlTextUpdated( wxCommandEvent& /* event*/ )
00343 {
00344     int value= atoi( this->m_ch_volt_per_div_control->GetLabel( ));
00345         this->UpdateVoltPerDiv( value);
00346 }
00347 
00348 
00353 void ViewChControl::OnOffsetYResetButtonClick( wxCommandEvent& /* event*/)
00354 {
00355         this->m_ch_offset_control->SetValue( 0);
00356         this->UpdateOffset();
00357 }
00358 
00363 void ViewChControl::OnSpinbutton1Updated( wxSpinEvent& /* event*/ )
00364 {
00365         this->UpdateOffset();
00366 }
00367 
00372 void ViewChControl::OnViewEnableTogglebuttonClick( wxCommandEvent& /*event*/ )
00373 {
00374         this->m_p_board_channel->m_scope_view_enabled[ this->m_scope_index]= this->m_view_enable_control->GetValue( )!= 0;
00375         this->m_view_enable_control->SetLabel( this->m_view_enable_control->GetValue( )? _("Disable"): _("Enable"));
00376         (this->m_p_board_channel->ScopeRefresh)( this->m_scope_index, true);
00377 }
00378 
00379 

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