00001
00002
00003
00004
00005
00006 #include "PanelBullEyeOptions.h"
00007
00008
00009
00010
00011
00012 PanelBullEyeOptions::PanelBullEyeOptions (wxWindow * parent, wxSize size) :
00013 wxPanel(parent, -1, wxDefaultPosition, size)
00014 {
00015
00016 _maxLevels = 5;
00017 _maxSections = 10;
00018 wxSize sizepanel(190,300);
00019 wxPanel *panel = this;
00020
00021
00022 wxString lstOptions[2];
00023 lstOptions[0]= wxString("General options",wxConvUTF8);
00024 lstOptions[1]= wxString("Detail options",wxConvUTF8);
00025 _radioboxBullEyeGenOpt = new wxRadioBox(panel, -1, wxString("General/Detail options",wxConvUTF8), wxDefaultPosition, wxSize(200,45), 2 , lstOptions, 2, wxRA_SPECIFY_COLS);
00026 _radioboxBullEyeGenOpt->SetSelection(0);
00027
00028 _spinctrlBullEyeNumOfCrowns = new wxSpinCtrl( panel , -1,_T("B"),wxDefaultPosition, wxSize(40,20) );
00029 _spinctrlBullEyeNumOfCrowns->SetRange(1,_maxLevels);
00030 _spinctrlBullEyeNumOfCrowns->SetValue(3);
00031
00032 _spinctrlBullEyeNumOfSec = new wxSpinCtrl( panel , -1,_T("A"),wxDefaultPosition, wxSize(40,20) );
00033 _spinctrlBullEyeNumOfSec->SetRange(1,_maxSections);
00034 _spinctrlBullEyeNumOfSec->SetValue(5);
00035
00036
00037 _sliderBullEyeAngle = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
00038
00039 wxFlexGridSizer * sizerGeneralOptions = new wxFlexGridSizer(10);
00040
00041 wxFlexGridSizer * sizerGeneralOptionsA = new wxFlexGridSizer(1);
00042 wxFlexGridSizer * sizerGeneralOptionsB = new wxFlexGridSizer(1);
00043 wxFlexGridSizer * sizerGeneralOptionsC = new wxFlexGridSizer(1);
00044 sizerGeneralOptionsA -> Add( new wxStaticText(panel,-1,_T("Crowns")) , 1, wxGROW );
00045 sizerGeneralOptionsA -> Add( _spinctrlBullEyeNumOfCrowns , 1 );
00046 sizerGeneralOptionsB -> Add( new wxStaticText(panel,-1,_T("Sections")) , 1, wxGROW );
00047 sizerGeneralOptionsB -> Add( _spinctrlBullEyeNumOfSec , 1 );
00048 sizerGeneralOptionsC -> Add( new wxStaticText(panel,-1,_T(" Angle")) , 1, wxGROW );
00049 sizerGeneralOptionsC -> Add( _sliderBullEyeAngle , 1 );
00050
00051 sizerGeneralOptions -> Add( sizerGeneralOptionsA , 1 );
00052 sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
00053 sizerGeneralOptions -> Add( sizerGeneralOptionsB , 1 );
00054 sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
00055 sizerGeneralOptions -> Add( sizerGeneralOptionsC , 1 );
00056
00057
00058 wxSpinCtrl *tmpSpinSection;
00059 wxSlider *tmpSliderRadio;
00060 wxSlider *tmpSliderAng;
00061
00062 wxFlexGridSizer * sizerDetailOptions = new wxFlexGridSizer(6);
00063
00064 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("Crown ")) , 1, wxGROW );
00065 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Sections ")) , 1, wxGROW );
00066 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
00067 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Radio %")) , 1, wxGROW );
00068 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
00069 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Angle")) , 1, wxGROW );
00070
00071 wxString tmpwxstring;
00072 int i;
00073 for (i=0;i<_maxLevels;i++){
00074 tmpSpinSection = new wxSpinCtrl( panel , -1,_T(""),wxDefaultPosition, wxSize(40,20) );
00075 tmpSliderRadio = new wxSlider( panel , -1 ,0,0,100, wxDefaultPosition, wxSize(110,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
00076 tmpSliderAng = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
00077
00078 tmpSpinSection ->SetRange(1,_maxSections);
00079
00080 tmpwxstring.Printf(_T(" %d. "),i+1);
00081 sizerDetailOptions -> Add( new wxStaticText(panel,-1,tmpwxstring) , 1, wxGROW );
00082 sizerDetailOptions -> Add( tmpSpinSection, 1 );
00083 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
00084 sizerDetailOptions -> Add( tmpSliderRadio, 1, wxGROW );
00085 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
00086 sizerDetailOptions -> Add( tmpSliderAng, 1, wxGROW );
00087
00088 tmpSpinSection -> SetValue(5);
00089 tmpSliderRadio -> SetValue( 100-(double)((i)*100.0/_maxLevels) );
00090 tmpSliderAng -> SetValue(0);
00091
00092 Connect( tmpSliderRadio->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
00093 Connect( tmpSliderRadio->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
00094
00095 _lstBullEyeDetailNumOfSec.push_back( tmpSpinSection );
00096 _lstBullEyeDetailRadio.push_back( tmpSliderRadio );
00097 _lstBullEyeDetailAngle.push_back( tmpSliderAng );
00098
00099 }
00100
00101 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
00102 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
00103 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
00104 sizer -> Add( _radioboxBullEyeGenOpt , 1, wxGROW );
00105 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
00106 sizer -> Add( new wxStaticText(panel,-1,_T(" -- Bull Eye general options --")) , 1, wxGROW );
00107 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
00108 sizer -> Add( sizerGeneralOptions , 1, wxGROW );
00109 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
00110 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
00111 sizer -> Add( new wxStaticText(panel,-1,_T(" -- Bull Eye detail options --")) , 1, wxGROW );
00112 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
00113 sizer -> Add( sizerDetailOptions , 1, wxGROW );
00114
00115 Connect( _radioboxBullEyeGenOpt->GetId(), wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
00116 Connect( _spinctrlBullEyeNumOfCrowns->GetId(), wxEVT_COMMAND_TEXT_UPDATED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
00117
00118 panel->SetSizer( sizer );
00119 panel->SetSize( sizepanel );
00120 panel->SetAutoLayout( true );
00121 panel->Layout();
00122
00123 RefreshPanel();
00124
00125 }
00126
00127
00128 PanelBullEyeOptions::~PanelBullEyeOptions()
00129 {
00130 }
00131
00132
00133 void PanelBullEyeOptions::onRefreshPanel( wxCommandEvent& event )
00134 {
00135 RefreshPanel();
00136 }
00137
00138
00139 void PanelBullEyeOptions::RefreshPanel()
00140 {
00141 int i;
00142 bool ok;
00143 if (this->_radioboxBullEyeGenOpt->GetSelection()==0){
00144 for (i=0; i<_maxLevels; i++)
00145 {
00146 _lstBullEyeDetailNumOfSec[i] -> Enable(false);
00147 _lstBullEyeDetailRadio[i] -> Enable(false);
00148 _lstBullEyeDetailAngle[i] -> Enable(false);
00149 }
00150 } else {
00151 int spinSelec = _spinctrlBullEyeNumOfCrowns->GetValue();
00152 for (i=0; i<_maxLevels; i++)
00153 {
00154 ok = (i < spinSelec);
00155 _lstBullEyeDetailNumOfSec[i] -> Enable(ok);
00156 _lstBullEyeDetailRadio[i] -> Enable(ok);
00157 _lstBullEyeDetailAngle[i] -> Enable(ok);
00158
00159 if (i>0){
00160 if (_lstBullEyeDetailRadio[i]->GetValue() > _lstBullEyeDetailRadio[i-1]->GetValue())
00161 {
00162 _lstBullEyeDetailRadio[i]->SetValue( _lstBullEyeDetailRadio[i-1]->GetValue() );
00163 }
00164 }
00165 }
00166 }
00167 }
00168
00169
00170 int PanelBullEyeOptions::GetNumberOfCrowns()
00171 {
00172 return this->_spinctrlBullEyeNumOfCrowns->GetValue();
00173 }
00174
00175
00176 int PanelBullEyeOptions::GetNumberOfSections(int nCrown)
00177 {
00178 int result;
00179 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
00180 {
00181 result = this->_spinctrlBullEyeNumOfSec->GetValue();
00182 } else {
00183 result = this->_lstBullEyeDetailNumOfSec[nCrown]->GetValue();
00184 }
00185 return result;
00186 }
00187
00188
00189 int PanelBullEyeOptions::GetRadioOfCrown(int nCrown)
00190 {
00191 int result;
00192 double sizeCrowns;
00193 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
00194 {
00195 sizeCrowns = (double)( this->_spinctrlBullEyeNumOfCrowns->GetValue() );
00196 result = 100.0 * (nCrown+1)/sizeCrowns ;
00197 } else {
00198 result = this->_lstBullEyeDetailRadio[nCrown]->GetValue();
00199 }
00200 return result;
00201 }
00202
00203
00204 double PanelBullEyeOptions::GetAngOfCrownSection(int nCrown,int section)
00205 {
00206 double angle;
00207 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
00208 {
00209 angle = this->_sliderBullEyeAngle->GetValue();
00210 } else {
00211 angle = this->_lstBullEyeDetailAngle[nCrown]->GetValue();
00212 }
00213
00214 double deltaSec = GetAngDeltaOfCrownSection(nCrown);
00215 return angle + section*deltaSec ;
00216 }
00217
00218
00219 double PanelBullEyeOptions::GetAngDeltaOfCrownSection(int nCrown)
00220 {
00221 double numOfSec = (double)GetNumberOfSections(nCrown);
00222 return 360.0/numOfSec;
00223 }
00224