]> Creatis software - creaContours.git/blob - lib/Interface_ManagerContour_NDimensions/PanelBullEyeOptions.cxx
9ad29387dfea3bb47e768a8f9215e6935626cc96
[creaContours.git] / lib / Interface_ManagerContour_NDimensions / PanelBullEyeOptions.cxx
1
2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 //#include "wxContourEventHandler.h"
6 #include "PanelBullEyeOptions.h"
7
8 //------------------------------------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------------------------------------
11
12 PanelBullEyeOptions::PanelBullEyeOptions (wxWindow * parent, wxSize size) :
13                  wxPanel(parent, -1, wxDefaultPosition, size)
14 {
15
16         _maxLevels              = 5;
17         _maxSections    = 10;
18         wxSize sizepanel(190,300);
19         wxPanel *panel = this;
20
21
22         wxString lstOptions[2];
23         lstOptions[0]= wxString("General options",wxConvUTF8);
24         lstOptions[1]= wxString("Detail options",wxConvUTF8);
25         _radioboxBullEyeGenOpt  = new wxRadioBox(panel, -1, wxString("General/Detail options",wxConvUTF8), wxDefaultPosition, wxSize(200,45), 2 , lstOptions,  2, wxRA_SPECIFY_COLS);
26         _radioboxBullEyeGenOpt->SetSelection(0);
27
28         _spinctrlBullEyeNumOfCrowns = new wxSpinCtrl( panel , -1,_T("B"),wxDefaultPosition, wxSize(40,20) );
29         _spinctrlBullEyeNumOfCrowns->SetRange(1,_maxLevels);
30         _spinctrlBullEyeNumOfCrowns->SetValue(3);
31
32         _spinctrlBullEyeNumOfSec = new wxSpinCtrl( panel , -1,_T("A"),wxDefaultPosition, wxSize(40,20) );
33         _spinctrlBullEyeNumOfSec->SetRange(1,_maxSections);
34         _spinctrlBullEyeNumOfSec->SetValue(5);
35
36
37         _sliderBullEyeAngle = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
38
39         wxFlexGridSizer * sizerGeneralOptions                           = new wxFlexGridSizer(10);
40
41         wxFlexGridSizer * sizerGeneralOptionsA                          = new wxFlexGridSizer(1);
42         wxFlexGridSizer * sizerGeneralOptionsB                          = new wxFlexGridSizer(1);
43         wxFlexGridSizer * sizerGeneralOptionsC                          = new wxFlexGridSizer(1);
44         sizerGeneralOptionsA -> Add( new wxStaticText(panel,-1,_T("Crowns")) , 1, wxGROW );
45         sizerGeneralOptionsA -> Add( _spinctrlBullEyeNumOfCrowns , 1/*, wxGROW*/ );
46         sizerGeneralOptionsB -> Add( new wxStaticText(panel,-1,_T("Sections")) , 1, wxGROW );
47         sizerGeneralOptionsB -> Add( _spinctrlBullEyeNumOfSec , 1/*, wxGROW*/ );
48         sizerGeneralOptionsC -> Add( new wxStaticText(panel,-1,_T("      Angle")) , 1, wxGROW );
49         sizerGeneralOptionsC -> Add( _sliderBullEyeAngle , 1/*, wxGROW*/ );
50
51         sizerGeneralOptions -> Add( sizerGeneralOptionsA  , 1/*, wxGROW*/ );
52         sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T("   ")) , 1, wxGROW );
53         sizerGeneralOptions -> Add( sizerGeneralOptionsB  , 1/*, wxGROW*/ );
54         sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T("   ")) , 1, wxGROW );
55         sizerGeneralOptions -> Add( sizerGeneralOptionsC  , 1/*, wxGROW*/ );
56
57
58         wxSpinCtrl      *tmpSpinSection;
59         wxSlider        *tmpSliderRadio;
60         wxSlider        *tmpSliderAng;
61
62         wxFlexGridSizer * sizerDetailOptions                            = new wxFlexGridSizer(6);
63
64         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("Crown ")) , 1, wxGROW );
65         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("  Sections  ")) , 1, wxGROW );
66         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("  ")) , 1, wxGROW );
67         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("      Radio %")) , 1, wxGROW );
68         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("  ")) , 1, wxGROW );
69         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("      Angle")) , 1, wxGROW );
70
71         wxString tmpwxstring;
72         int i;
73         for (i=0;i<_maxLevels;i++){
74                 tmpSpinSection = new wxSpinCtrl( panel  , -1,_T(""),wxDefaultPosition, wxSize(40,20) );
75                 tmpSliderRadio = new wxSlider( panel    , -1 ,0,0,100, wxDefaultPosition, wxSize(110,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
76                 tmpSliderAng   = new wxSlider( panel    , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
77
78                 tmpSpinSection ->SetRange(1,_maxSections);
79
80                 tmpwxstring.Printf(_T("  %d.  "),i+1);
81                 sizerDetailOptions -> Add( new wxStaticText(panel,-1,tmpwxstring) , 1, wxGROW );
82                 sizerDetailOptions -> Add( tmpSpinSection, 1 );
83                 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("  ")) , 1, wxGROW );
84                 sizerDetailOptions -> Add( tmpSliderRadio, 1, wxGROW );
85                 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("  ")) , 1, wxGROW );
86                 sizerDetailOptions -> Add( tmpSliderAng, 1, wxGROW );
87
88                 tmpSpinSection  -> SetValue(5);
89                 tmpSliderRadio  -> SetValue( 100-(double)((i)*100.0/_maxLevels) );
90                 tmpSliderAng    -> SetValue(0);
91                 
92                 Connect( tmpSliderRadio->GetId(),       wxEVT_SCROLL_THUMBRELEASE  , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
93                 Connect( tmpSliderRadio->GetId(),       wxEVT_SCROLL_CHANGED  , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
94
95                 _lstBullEyeDetailNumOfSec.push_back( tmpSpinSection );
96                 _lstBullEyeDetailRadio.push_back( tmpSliderRadio );
97                 _lstBullEyeDetailAngle.push_back( tmpSliderAng );
98
99         } //for
100
101         wxFlexGridSizer * sizer                         = new wxFlexGridSizer(1);
102         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
103         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
104         sizer -> Add( _radioboxBullEyeGenOpt , 1, wxGROW );
105         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
106         sizer -> Add( new wxStaticText(panel,-1,_T("      -- Bull Eye general options --")) , 1, wxGROW );
107         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
108         sizer -> Add(  sizerGeneralOptions , 1, wxGROW );
109         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
110         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
111         sizer -> Add( new wxStaticText(panel,-1,_T("      -- Bull Eye detail options --")) , 1, wxGROW );
112         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
113         sizer -> Add(  sizerDetailOptions  , 1, wxGROW );
114
115         Connect( _radioboxBullEyeGenOpt->GetId(),       wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel ); 
116         Connect( _spinctrlBullEyeNumOfCrowns->GetId(),  wxEVT_COMMAND_TEXT_UPDATED              , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
117         
118         panel->SetSizer( sizer );
119         panel->SetSize( sizepanel );
120         panel->SetAutoLayout( true );
121         panel->Layout();
122
123         RefreshPanel();
124
125 }
126
127 //------------------------------------------------------------------------------------------------------------
128 PanelBullEyeOptions::~PanelBullEyeOptions() 
129 {
130 }
131
132 //------------------------------------------------------------------------------------------------------------
133 void PanelBullEyeOptions::onRefreshPanel( wxCommandEvent& event )
134 {
135         RefreshPanel();
136 }
137
138 //------------------------------------------------------------------------------------------------------------
139 void PanelBullEyeOptions::RefreshPanel()
140 {
141         int i;
142         bool ok;
143         if (this->_radioboxBullEyeGenOpt->GetSelection()==0){
144                 for (i=0; i<_maxLevels; i++)
145                 {
146                         _lstBullEyeDetailNumOfSec[i]    -> Enable(false);
147                         _lstBullEyeDetailRadio[i]               -> Enable(false);
148                         _lstBullEyeDetailAngle[i]               -> Enable(false);
149                 } // for
150         } else {
151                 int spinSelec = _spinctrlBullEyeNumOfCrowns->GetValue(); 
152                 for (i=0; i<_maxLevels; i++)
153                 {
154                         ok = (i < spinSelec);
155                         _lstBullEyeDetailNumOfSec[i]    -> Enable(ok);
156                         _lstBullEyeDetailRadio[i]               -> Enable(ok);
157                         _lstBullEyeDetailAngle[i]               -> Enable(ok);
158
159                         if (i>0){
160                                 if (_lstBullEyeDetailRadio[i]->GetValue() > _lstBullEyeDetailRadio[i-1]->GetValue())
161                                 {
162                                         _lstBullEyeDetailRadio[i]->SetValue( _lstBullEyeDetailRadio[i-1]->GetValue() );
163                                 } 
164                         }// if i>0
165                 } // for
166         } // if
167 }
168
169 //------------------------------------------------------------------------------------------------------------
170 int PanelBullEyeOptions::GetNumberOfCrowns()
171 {
172         return this->_spinctrlBullEyeNumOfCrowns->GetValue();
173 }
174
175 //------------------------------------------------------------------------------------------------------------
176 int PanelBullEyeOptions::GetNumberOfSections(int nCrown)
177 {
178         int result;
179         if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
180         { 
181                 result = this->_spinctrlBullEyeNumOfSec->GetValue();
182         } else {
183                 result = this->_lstBullEyeDetailNumOfSec[nCrown]->GetValue();
184         }
185         return result;
186 }
187
188 //------------------------------------------------------------------------------------------------------------
189 int PanelBullEyeOptions::GetRadioOfCrown(int nCrown)
190 {
191         int result;
192         double sizeCrowns;
193         if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
194         { 
195                 sizeCrowns = (double)( this->_spinctrlBullEyeNumOfCrowns->GetValue() );
196                 result = 100.0 * (nCrown+1)/sizeCrowns ;
197         } else {
198                 result = this->_lstBullEyeDetailRadio[nCrown]->GetValue();
199         }
200         return result;
201 }
202
203 //------------------------------------------------------------------------------------------------------------
204 double PanelBullEyeOptions::GetAngOfCrownSection(int nCrown,int section)
205 {
206         double angle;
207         if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
208         { 
209                 angle = this->_sliderBullEyeAngle->GetValue();
210         } else {
211                 angle = this->_lstBullEyeDetailAngle[nCrown]->GetValue();
212         }
213 //      double numOfSec = (double)GetNumberOfSections(nCrown);
214         double deltaSec = GetAngDeltaOfCrownSection(nCrown);
215         return angle + section*deltaSec ;
216 }
217
218 //------------------------------------------------------------------------------------------------------------
219 double PanelBullEyeOptions::GetAngDeltaOfCrownSection(int nCrown)
220 {
221         double numOfSec = (double)GetNumberOfSections(nCrown);
222         return 360.0/numOfSec;
223 }
224