]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxRadioButton.cxx
Clean Code
[bbtk.git] / packages / wx / src / bbwxRadioButton.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbwxRadioButton.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:52:14 $
33   Version:   $Revision: 1.10 $
34 =========================================================================*/
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40
41
42 #ifdef _USE_WXWIDGETS_
43
44
45 #include "bbwxRadioButton.h"
46 #include "bbwxPackage.h"
47
48 #include <vector>
49
50 namespace bbwx
51 {
52     
53   
54   //--------------------------------------------------------------------------
55   // The widget created by the box 
56   class RadioButtonWidget : public wxPanel
57   {
58   public:
59     RadioButtonWidget( RadioButton* box, wxWindow *parent, 
60                       int In, 
61                       wxString title, 
62                       std::vector<wxString> lstIn );
63
64     ~RadioButtonWidget();
65     int GetValue();
66     void OnRadioButton(wxEvent& event);
67         void AddElements(std::vector<wxString> lstIn, int In, wxString title);
68   private:
69     RadioButton      *mBox;
70     int              MAX_RADIOBUTTON;
71     wxRadioButton    *mwxRadioButton[25];
72         wxFlexGridSizer  *sizer;
73   };
74   
75   //------------------------------------------------------------------------
76   //------------------------------------------------------------------------
77   //------------------------------------------------------------------------
78
79   //-------------------------------------------------------------------------
80   RadioButtonWidget::RadioButtonWidget( RadioButton* box,
81                wxWindow *parent,
82                int In,
83                wxString title,
84                std::vector<wxString> lstIn )
85     :
86     wxPanel( parent, -1) ,
87     mBox(box)
88   {
89     AddElements(  lstIn , In,title);
90     mBox->bbSetOutputOut( GetValue() );
91 //    mBox->bbSetInputIn( GetValue() );
92   }
93   
94   //-------------------------------------------------------------------------
95   
96   RadioButtonWidget::~RadioButtonWidget()
97   {
98   }
99
100   //-------------------------------------------------------------------------
101  
102   int RadioButtonWidget::GetValue()
103   { 
104     int result=-1;
105     int i;
106     for (i=0;i<MAX_RADIOBUTTON; i++)
107     {
108                 if ( mwxRadioButton[i]!=NULL)
109                 {
110                 if (mwxRadioButton[i]->GetValue()==true)
111                 {
112                                 result=i;
113                 } // if Value
114                 } // if NULL
115     } // for i
116     
117     return result;
118   }
119
120   //--------------------------------------------------------------------------
121   void RadioButtonWidget::OnRadioButton(wxEvent& event)
122   {
123     mBox->bbSetOutputOut( GetValue() );
124     mBox->bbSetInputIn( GetValue() );
125     mBox->bbSignalOutputModification("Out");
126   }
127
128
129   //--------------------------------------------------------------------------
130   void RadioButtonWidget::AddElements( std::vector<wxString> lstIn ,int In, wxString title)
131   {
132         DestroyChildren();
133
134     MAX_RADIOBUTTON = lstIn.size();
135     wxPanel *panel      = this;
136     int i;
137     long style=wxRB_GROUP;
138     for (i=0;i<MAX_RADIOBUTTON; i++)
139     {
140            if ( lstIn[i]!=_T(""))
141            {
142     //---------------------------------------------------------------------
143     // 1) Creation of the components of the widget
144     // Any top level sub-widget must have the panel returned by panel
145     // for parent
146               mwxRadioButton[i] = new wxRadioButton( panel, -1, lstIn[i],wxDefaultPosition, wxDefaultSize, style);
147               style = 0;
148               if (i==In)
149               {
150                       mwxRadioButton[i]->SetValue(true);
151               } else {
152                       mwxRadioButton[i]->SetValue(false);
153               }
154                Connect( mwxRadioButton[i]->GetId(),  
155                    wxEVT_COMMAND_RADIOBUTTON_SELECTED, 
156                   (wxObjectEventFunction) 
157                   (void (wxPanel::*)(wxEvent&))
158                   &RadioButtonWidget::OnRadioButton ); 
159            } else {
160                mwxRadioButton[i]=NULL;
161            } // if not =_T("")
162     } // for i
163     
164     //---------------------------------------------------------------------
165     // 2) Insertion of the components in the window
166     
167     // We use a FlexGridSizer
168
169 //EED 2018-04-18
170 //    wxFlexGridSizer *sizer    = new wxFlexGridSizer(1);
171     sizer       = new wxFlexGridSizer(1);
172
173     if (title!=_T(""))
174     {
175            sizer->Add( new wxStaticText(panel,-1, title ) ); 
176     } // if
177     for (i=0;i<MAX_RADIOBUTTON; i++)
178     {
179        if (mwxRadioButton[i]!=NULL)
180        {
181           sizer->Add( mwxRadioButton[i],1,wxGROW ); 
182        } // if
183     } // for i
184     sizer->AddGrowableCol(0);
185     panel->SetSizer(sizer);
186
187     panel->SetAutoLayout(true);
188     panel->Layout();
189
190   }
191
192
193   //--------------------------------------------------------------------------
194   //-------------------------------------------------------------------------
195   //--------------------------------------------------------------------------
196   //--------------------------------------------------------------------------
197
198   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,RadioButton);
199   BBTK_BLACK_BOX_IMPLEMENTATION(RadioButton,bbtk::WxBlackBox);
200
201   
202         //-----------------------------------------------------------------     
203         void RadioButton::bbUserSetDefaultValues()
204         {
205                 bbSetInputIn(0);
206                 bbSetOutputOut( bbGetInputIn() );
207                 bbSetInputIn0("");
208                 bbSetInputIn1("");
209                 bbSetInputIn2("");
210                 bbSetInputIn3("");
211                 bbSetInputIn4("");
212                 bbSetInputIn5("");
213                 bbSetInputIn6("");
214                 bbSetInputIn7("");
215                 bbSetInputIn8("");
216                 bbSetInputIn9("");              
217         }
218         
219         //-----------------------------------------------------------------     
220         void RadioButton::bbUserInitializeProcessing()
221         {
222         }
223         
224         //-----------------------------------------------------------------     
225         void RadioButton::bbUserFinalizeProcessing()
226         {
227         }
228         
229   void RadioButton::Process() 
230   { 
231     bbtkDebugMessageInc("Core",9,"RadioButton::Process()"<<std::endl);
232     bbtkDebugDecTab("Core",9);
233     std::vector<wxString> lstIn;
234     lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
235     lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
236     lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
237     lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
238     lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
239     lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
240     lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
241     lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
242     lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
243     lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
244         if (bbGetOutputWidget()!=NULL) 
245         {
246                 ( (RadioButtonWidget*)bbGetOutputWidget() )->AddElements(lstIn, bbGetInputIn() , bbtk::std2wx(bbGetInputTitle()) );     
247         } // if bbGetOutputWidget
248   }
249
250   /**
251    * \brief  Create wxWidget . 
252    *
253    *
254    */ 
255  void RadioButton::CreateWidget(wxWindow* parent)
256   {
257
258     std::vector<wxString> lstIn;
259     lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
260     lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
261     lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
262     lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
263     lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
264     lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
265     lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
266     lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
267     lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
268     lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
269
270     RadioButtonWidget *w = new RadioButtonWidget(
271                          this,
272                                                  parent,        
273                          bbGetInputIn() ,
274                          bbtk::std2wx(bbGetInputTitle()),
275                          lstIn );
276
277    bbSetOutputOut( bbGetInputIn() );
278    bbSetOutputWidget( w );
279
280   }
281
282
283
284
285 }//namespace bbtk
286
287 #endif // _USE_WXWIDGETS_ 
288