]> Creatis software - creaContours.git/blob - lib/Interface_ManagerContour_NDimensions/PanelBullEyeOptions.cxx
Feature #1772 Add licence terms for all files.
[creaContours.git] / lib / Interface_ManagerContour_NDimensions / PanelBullEyeOptions.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27 //----------------------------------------------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------------------------------------------
30 //#include "wxContourEventHandler.h"
31 #include "PanelBullEyeOptions.h"
32
33 //------------------------------------------------------------------------------------------------------------
34 //------------------------------------------------------------------------------------------------------------
35 //------------------------------------------------------------------------------------------------------------
36
37 PanelBullEyeOptions::PanelBullEyeOptions (wxWindow * parent, wxSize size) :
38                  wxPanel(parent, -1, wxDefaultPosition, size)
39 {
40
41         _maxLevels              = 5;
42         _maxSections    = 10;
43         wxSize sizepanel(190,300);
44         wxPanel *panel = this;
45
46
47         wxString lstOptions[2];
48         lstOptions[0]= wxString("General options",wxConvUTF8);
49         lstOptions[1]= wxString("Detail options",wxConvUTF8);
50         _radioboxBullEyeGenOpt  = new wxRadioBox(panel, -1, wxString("General/Detail options",wxConvUTF8), wxDefaultPosition, wxSize(200,45), 2 , lstOptions,  2, wxRA_SPECIFY_COLS);
51         _radioboxBullEyeGenOpt->SetSelection(0);
52
53         _spinctrlBullEyeNumOfCrowns = new wxSpinCtrl( panel , -1,_T("B"),wxDefaultPosition, wxSize(40,20) );
54         _spinctrlBullEyeNumOfCrowns->SetRange(1,_maxLevels);
55         _spinctrlBullEyeNumOfCrowns->SetValue(3);
56
57         _spinctrlBullEyeNumOfSec = new wxSpinCtrl( panel , -1,_T("A"),wxDefaultPosition, wxSize(40,20) );
58         _spinctrlBullEyeNumOfSec->SetRange(1,_maxSections);
59         _spinctrlBullEyeNumOfSec->SetValue(5);
60
61
62         _sliderBullEyeAngle = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
63
64         wxFlexGridSizer * sizerGeneralOptions                           = new wxFlexGridSizer(10);
65
66         wxFlexGridSizer * sizerGeneralOptionsA                          = new wxFlexGridSizer(1);
67         wxFlexGridSizer * sizerGeneralOptionsB                          = new wxFlexGridSizer(1);
68         wxFlexGridSizer * sizerGeneralOptionsC                          = new wxFlexGridSizer(1);
69         sizerGeneralOptionsA -> Add( new wxStaticText(panel,-1,_T("Crowns")) , 1, wxGROW );
70         sizerGeneralOptionsA -> Add( _spinctrlBullEyeNumOfCrowns , 1/*, wxGROW*/ );
71         sizerGeneralOptionsB -> Add( new wxStaticText(panel,-1,_T("Sections")) , 1, wxGROW );
72         sizerGeneralOptionsB -> Add( _spinctrlBullEyeNumOfSec , 1/*, wxGROW*/ );
73         sizerGeneralOptionsC -> Add( new wxStaticText(panel,-1,_T("      Angle")) , 1, wxGROW );
74         sizerGeneralOptionsC -> Add( _sliderBullEyeAngle , 1/*, wxGROW*/ );
75
76         sizerGeneralOptions -> Add( sizerGeneralOptionsA  , 1/*, wxGROW*/ );
77         sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T("   ")) , 1, wxGROW );
78         sizerGeneralOptions -> Add( sizerGeneralOptionsB  , 1/*, wxGROW*/ );
79         sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T("   ")) , 1, wxGROW );
80         sizerGeneralOptions -> Add( sizerGeneralOptionsC  , 1/*, wxGROW*/ );
81
82
83         wxSpinCtrl      *tmpSpinSection;
84         wxSlider        *tmpSliderRadio;
85         wxSlider        *tmpSliderAng;
86
87         wxFlexGridSizer * sizerDetailOptions                            = new wxFlexGridSizer(6);
88
89         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("Crown ")) , 1, wxGROW );
90         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("  Sections  ")) , 1, wxGROW );
91         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("  ")) , 1, wxGROW );
92         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("      Radio %")) , 1, wxGROW );
93         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("  ")) , 1, wxGROW );
94         sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("      Angle")) , 1, wxGROW );
95
96         wxString tmpwxstring;
97         int i;
98         for (i=0;i<_maxLevels;i++){
99                 tmpSpinSection = new wxSpinCtrl( panel  , -1,_T(""),wxDefaultPosition, wxSize(40,20) );
100                 tmpSliderRadio = new wxSlider( panel    , -1 ,0,0,100, wxDefaultPosition, wxSize(110,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
101                 tmpSliderAng   = new wxSlider( panel    , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
102
103                 tmpSpinSection ->SetRange(1,_maxSections);
104
105                 tmpwxstring.Printf(_T("  %d.  "),i+1);
106                 sizerDetailOptions -> Add( new wxStaticText(panel,-1,tmpwxstring) , 1, wxGROW );
107                 sizerDetailOptions -> Add( tmpSpinSection, 1 );
108                 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("  ")) , 1, wxGROW );
109                 sizerDetailOptions -> Add( tmpSliderRadio, 1, wxGROW );
110                 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("  ")) , 1, wxGROW );
111                 sizerDetailOptions -> Add( tmpSliderAng, 1, wxGROW );
112
113                 tmpSpinSection  -> SetValue(5);
114                 tmpSliderRadio  -> SetValue( 100-(double)((i)*100.0/_maxLevels) );
115                 tmpSliderAng    -> SetValue(0);
116                 
117                 Connect( tmpSliderRadio->GetId(),       wxEVT_SCROLL_THUMBRELEASE  , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
118                 Connect( tmpSliderRadio->GetId(),       wxEVT_SCROLL_CHANGED  , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
119
120                 _lstBullEyeDetailNumOfSec.push_back( tmpSpinSection );
121                 _lstBullEyeDetailRadio.push_back( tmpSliderRadio );
122                 _lstBullEyeDetailAngle.push_back( tmpSliderAng );
123
124         } //for
125
126         wxFlexGridSizer * sizer                         = new wxFlexGridSizer(1);
127         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
128         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
129         sizer -> Add( _radioboxBullEyeGenOpt , 1, wxGROW );
130         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
131         sizer -> Add( new wxStaticText(panel,-1,_T("      -- Bull Eye general options --")) , 1, wxGROW );
132         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
133         sizer -> Add(  sizerGeneralOptions , 1, wxGROW );
134         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
135         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
136         sizer -> Add( new wxStaticText(panel,-1,_T("      -- Bull Eye detail options --")) , 1, wxGROW );
137         sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
138         sizer -> Add(  sizerDetailOptions  , 1, wxGROW );
139
140         Connect( _radioboxBullEyeGenOpt->GetId(),       wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel ); 
141         Connect( _spinctrlBullEyeNumOfCrowns->GetId(),  wxEVT_COMMAND_TEXT_UPDATED              , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
142         
143         panel->SetSizer( sizer );
144         panel->SetSize( sizepanel );
145         panel->SetAutoLayout( true );
146         panel->Layout();
147
148         RefreshPanel();
149
150 }
151
152 //------------------------------------------------------------------------------------------------------------
153 PanelBullEyeOptions::~PanelBullEyeOptions() 
154 {
155 }
156
157 //------------------------------------------------------------------------------------------------------------
158 void PanelBullEyeOptions::onRefreshPanel( wxCommandEvent& event )
159 {
160         RefreshPanel();
161 }
162
163 //------------------------------------------------------------------------------------------------------------
164 void PanelBullEyeOptions::RefreshPanel()
165 {
166         int i;
167         bool ok;
168         if (this->_radioboxBullEyeGenOpt->GetSelection()==0){
169                 for (i=0; i<_maxLevels; i++)
170                 {
171                         _lstBullEyeDetailNumOfSec[i]    -> Enable(false);
172                         _lstBullEyeDetailRadio[i]               -> Enable(false);
173                         _lstBullEyeDetailAngle[i]               -> Enable(false);
174                 } // for
175         } else {
176                 int spinSelec = _spinctrlBullEyeNumOfCrowns->GetValue(); 
177                 for (i=0; i<_maxLevels; i++)
178                 {
179                         ok = (i < spinSelec);
180                         _lstBullEyeDetailNumOfSec[i]    -> Enable(ok);
181                         _lstBullEyeDetailRadio[i]               -> Enable(ok);
182                         _lstBullEyeDetailAngle[i]               -> Enable(ok);
183
184                         if (i>0){
185                                 if (_lstBullEyeDetailRadio[i]->GetValue() > _lstBullEyeDetailRadio[i-1]->GetValue())
186                                 {
187                                         _lstBullEyeDetailRadio[i]->SetValue( _lstBullEyeDetailRadio[i-1]->GetValue() );
188                                 } 
189                         }// if i>0
190                 } // for
191         } // if
192 }
193
194 //------------------------------------------------------------------------------------------------------------
195 int PanelBullEyeOptions::GetNumberOfCrowns()
196 {
197         return this->_spinctrlBullEyeNumOfCrowns->GetValue();
198 }
199
200 //------------------------------------------------------------------------------------------------------------
201 int PanelBullEyeOptions::GetNumberOfSections(int nCrown)
202 {
203         int result;
204         if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
205         { 
206                 result = this->_spinctrlBullEyeNumOfSec->GetValue();
207         } else {
208                 result = this->_lstBullEyeDetailNumOfSec[nCrown]->GetValue();
209         }
210         return result;
211 }
212
213 //------------------------------------------------------------------------------------------------------------
214 int PanelBullEyeOptions::GetRadioOfCrown(int nCrown)
215 {
216         int result;
217         double sizeCrowns;
218         if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
219         { 
220                 sizeCrowns = (double)( this->_spinctrlBullEyeNumOfCrowns->GetValue() );
221                 result = 100.0 * (nCrown+1)/sizeCrowns ;
222         } else {
223                 result = this->_lstBullEyeDetailRadio[nCrown]->GetValue();
224         }
225         return result;
226 }
227
228 //------------------------------------------------------------------------------------------------------------
229 double PanelBullEyeOptions::GetAngOfCrownSection(int nCrown,int section)
230 {
231         double angle;
232         if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
233         { 
234                 angle = this->_sliderBullEyeAngle->GetValue();
235         } else {
236                 angle = this->_lstBullEyeDetailAngle[nCrown]->GetValue();
237         }
238 //      double numOfSec = (double)GetNumberOfSections(nCrown);
239         double deltaSec = GetAngDeltaOfCrownSection(nCrown);
240         return angle + section*deltaSec ;
241 }
242
243 //------------------------------------------------------------------------------------------------------------
244 double PanelBullEyeOptions::GetAngDeltaOfCrownSection(int nCrown)
245 {
246         double numOfSec = (double)GetNumberOfSections(nCrown);
247         return 360.0/numOfSec;
248 }
249