00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
00015 #pragma implementation "common_ch_control.h"
00016 #endif
00017
00018
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
00031
00032 #include "common_ch_control.h"
00033
00036
00041 IMPLEMENT_DYNAMIC_CLASS( CommonChControl, CommonChControlBase )
00042
00043
00047 BEGIN_EVENT_TABLE( CommonChControl, CommonChControlBase )
00048
00050 EVT_TOGGLEBUTTON( ID_ENABLE_TOGGLEBUTTON, CommonChControl::OnEnableTogglebuttonClick )
00051
00052 EVT_BUTTON( ID_BUTTON, CommonChControl::OnButtonClick )
00053
00054 EVT_SPIN( ID_SPINBUTTON, CommonChControl::OnSpinbuttonUpdated )
00055
00057
00058 END_EVENT_TABLE()
00059
00064 CommonChControl::CommonChControl( ):
00065 m_p_board(NULL), m_p_board_channel(NULL), m_ch_index(0), m_ch_count(0)
00066 {
00067 }
00068
00069 CommonChControl::CommonChControl( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ):
00070 m_p_board(NULL), m_p_board_channel(NULL), m_ch_index(0), m_ch_count(0)
00071 {
00072 Create(parent, id, pos, size, style);
00073 }
00074
00079 bool CommonChControl::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
00080 {
00081
00083 m_main_sizer_text = NULL;
00084 m_ch_enable_control = NULL;
00085 m_ch_DAC_reset_control = NULL;
00086 m_ch_DAC_control = NULL;
00087 m_medium_value_control = NULL;
00088 m_overload_control = NULL;
00090
00092 CommonChControlBase::Create( parent, id, pos, size, style );
00093
00094 CreateControls();
00095 if (GetSizer())
00096 {
00097 GetSizer()->SetSizeHints(this);
00098 }
00099 Centre();
00101 return true;
00102 }
00103
00108 void CommonChControl::CreateControls()
00109 {
00111
00112
00113 CommonChControl* itemCommonChControlBase1 = this;
00114
00115 this->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxNORMAL, false, _T("Verdana")));
00116 m_main_sizer_text = new wxStaticBox(itemCommonChControlBase1, wxID_ANY, _("???"));
00117 wxStaticBoxSizer* itemStaticBoxSizer2 = new wxStaticBoxSizer(m_main_sizer_text, wxVERTICAL);
00118 itemCommonChControlBase1->SetSizer(itemStaticBoxSizer2);
00119
00120 m_ch_enable_control = new wxToggleButton( itemCommonChControlBase1, ID_ENABLE_TOGGLEBUTTON, _("???"), wxDefaultPosition, wxSize(65, -1), 0 );
00121 m_ch_enable_control->SetValue(true);
00122 m_ch_enable_control->SetHelpText(_("Enable/Disable channel"));
00123 if (ShowToolTips())
00124 m_ch_enable_control->SetToolTip(_("Enable/Disable channel"));
00125 m_ch_enable_control->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD, false, _T("Verdana")));
00126 itemStaticBoxSizer2->Add(m_ch_enable_control, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
00127
00128 wxStaticBox* itemStaticBoxSizer4Static = new wxStaticBox(itemCommonChControlBase1, wxID_ANY, _T(""));
00129 wxStaticBoxSizer* itemStaticBoxSizer4 = new wxStaticBoxSizer(itemStaticBoxSizer4Static, wxHORIZONTAL);
00130 itemStaticBoxSizer2->Add(itemStaticBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL, 2);
00131
00132 m_ch_DAC_reset_control = new wxButton( itemCommonChControlBase1, ID_BUTTON, _("0"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
00133 m_ch_DAC_reset_control->SetHelpText(_("Reset channel DAC offset"));
00134 if (ShowToolTips())
00135 m_ch_DAC_reset_control->SetToolTip(_("Reset channel DAC offset"));
00136 m_ch_DAC_reset_control->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD, false, _T("Tahoma")));
00137 itemStaticBoxSizer4->Add(m_ch_DAC_reset_control, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
00138
00139 m_ch_DAC_control = new wxSpinButton( itemCommonChControlBase1, ID_SPINBUTTON, wxDefaultPosition, wxDefaultSize, wxSP_VERTICAL );
00140 m_ch_DAC_control->SetHelpText(_("Set channel DAC offset"));
00141 if (ShowToolTips())
00142 m_ch_DAC_control->SetToolTip(_("Set channel DAC offset"));
00143 itemStaticBoxSizer4->Add(m_ch_DAC_control, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 2);
00144
00145 m_medium_value_control = new wxStaticText( itemCommonChControlBase1, wxID_STATIC, _("0"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
00146 m_medium_value_control->SetHelpText(_("The samples' medium value"));
00147 if (ShowToolTips())
00148 m_medium_value_control->SetToolTip(_("The samples' medium value"));
00149 itemStaticBoxSizer2->Add(m_medium_value_control, 0, wxGROW|wxALL|wxADJUST_MINSIZE, 5);
00150
00151 m_overload_control = new wxStaticText( itemCommonChControlBase1, wxID_STATIC, _T(""), wxDefaultPosition, wxSize(15, -1), wxSTATIC_BORDER );
00152 m_overload_control->SetHelpText(_("Channel overload status"));
00153 if (ShowToolTips())
00154 m_overload_control->SetToolTip(_("Channel overload status"));
00155 m_overload_control->SetBackgroundColour(wxColour(0, 255, 0));
00156 itemStaticBoxSizer2->Add(m_overload_control, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
00157
00159 this->m_ch_DAC_control->SetRange( -0x8000, 0x7fff);
00160 }
00161
00166 bool CommonChControl::ShowToolTips()
00167 {
00168 return true;
00169 }
00170
00175 wxBitmap CommonChControl::GetBitmapResource( const wxString& name )
00176 {
00177
00179 wxUnusedVar(name);
00180 return wxNullBitmap;
00182 }
00183
00188 wxIcon CommonChControl::GetIconResource( const wxString& name )
00189 {
00190
00192 wxUnusedVar(name);
00193 return wxNullIcon;
00195 }
00196 bool CommonChControl::SetupBoard( GenericBoard* p_board, int ch_index, int ch_count)
00197 {
00198 this->m_p_board= p_board;
00199 this->m_ch_index= ch_index;
00200 this->m_ch_count= ch_count;
00201 if( ( size_t)this->m_ch_index>= this->m_p_board->m_channel_array.GetCount())
00202 return false;
00203 this->m_p_board_channel= (PhysicalBoardChannel*)this->m_p_board->m_channel_array[ this->m_ch_index];
00204 this->m_p_board_channel->m_p_common_ch_control= this;
00205
00206 if( !this->UpdateControls())
00207 return false;
00208 return true;
00209 }
00210 bool CommonChControl::UpdateControls( )
00211 {
00212 this->m_main_sizer_text->SetLabel( wxString::Format( "%d", this->m_ch_count));
00213 this->m_ch_enable_control->SetValue( this->m_p_board_channel->m_enabled);
00214 this->m_ch_enable_control->SetLabel( this->m_ch_enable_control->GetValue( )? _("Disable"): _("Enable"));
00215 this->m_ch_DAC_control->SetValue( (int)(double)( this->m_p_board_channel->m_DAC_offset_bit));
00216 this->UpdateDAC();
00217
00218 return true;
00219 }
00220
00225 void CommonChControl::OnEnableTogglebuttonClick( wxCommandEvent& )
00226 {
00227 this->m_p_board_channel->m_enabled= this->m_ch_enable_control->GetValue( )!= 0;
00228 this->m_ch_enable_control->SetLabel( this->m_ch_enable_control->GetValue( )? _("Disable"): _("Enable"));
00229 this->m_p_board->WriteTriggerMode( this->m_p_board->IsRunning());
00230 this->m_p_board_channel->WriteChannelTrigger();
00231 for( int i= 0; i< SCOPE_NUM_PANELS; i++)
00232 {
00233 (this->m_p_board_channel->ScopeRefresh)( i, true);
00234 }
00235 }
00236
00237 void CommonChControl::UpdateDAC( void)
00238 {
00239 this->m_p_board_channel->m_DAC_offset_bit= this->m_ch_DAC_control->GetValue( );
00240 this->m_p_board_channel->WriteDACOffset( );
00241 }
00242
00247 void CommonChControl::OnButtonClick( wxCommandEvent& )
00248 {
00249 this->m_ch_DAC_control->SetValue( 0);
00250 this->UpdateDAC();
00251 }
00252
00257 void CommonChControl::OnSpinbuttonUpdated( wxSpinEvent& )
00258 {
00259 this->UpdateDAC();
00260 }
00261
00262 void CommonChControl::SetMediumLabel( double value)
00263 {
00264 this->m_medium_value_control->SetLabel( wxString::Format( "%.3f", value));
00265 }
00266 void CommonChControl::SetEnable( bool enable)
00267 {
00268 this->m_ch_enable_control->Enable( enable);
00269 }
00270
00271 void CommonChControl::SetOverloadBackground( const wxColor& color)
00272 {
00273 this->m_overload_control->SetBackgroundColour( color);
00274 this->m_overload_control->Refresh();
00275 }