]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxRadioButton.cxx
#3189 BBTK Bug New Normal - Refresh RadioButton Box
[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
66     int GetValue();
67     void OnRadioButton(wxEvent& event);
68         void AddElements(std::vector<wxString> lstIn, int In, wxString title);
69
70   private:
71     RadioButton      *mBox;
72     int              MAX_RADIOBUTTON;
73     wxRadioButton    *mwxRadioButton[10];
74
75         wxFlexGridSizer  *sizer;
76   };
77   
78   //------------------------------------------------------------------------
79   //------------------------------------------------------------------------
80   //------------------------------------------------------------------------
81
82   //-------------------------------------------------------------------------
83   RadioButtonWidget::RadioButtonWidget( RadioButton* box,
84                wxWindow *parent,
85                int In,
86                wxString title,
87                std::vector<wxString> lstIn )
88     :
89     wxPanel( parent, -1) ,
90     mBox(box)
91   {
92
93 /*
94     MAX_RADIOBUTTON = lstIn.size();
95     wxPanel *panel      = this;
96     int i;
97     long style=wxRB_GROUP;
98     for (i=0;i<MAX_RADIOBUTTON; i++)
99     {
100            if ( lstIn[i]!=_T(""))
101            {
102     //---------------------------------------------------------------------
103     // 1) Creation of the components of the widget
104     // Any top level sub-widget must have the panel returned by panel
105     // for parent
106               mwxRadioButton[i] = new wxRadioButton( panel, -1, lstIn[i],wxDefaultPosition, wxDefaultSize, style);
107               style=0;
108               if (In==i)
109               {
110                       mwxRadioButton[i]->SetValue(true);
111               } else {
112                       mwxRadioButton[i]->SetValue(false);
113               }
114                Connect( mwxRadioButton[i]->GetId(),  
115                    wxEVT_COMMAND_RADIOBUTTON_SELECTED, 
116                   (wxObjectEventFunction) 
117                   (void (wxPanel::*)(wxEvent&))
118                   &RadioButtonWidget::OnRadioButton ); 
119            } else {
120                mwxRadioButton[i]=NULL;
121            } // if
122     } // for 
123     
124     //---------------------------------------------------------------------
125     // 2) Insertion of the components in the window
126     
127     // We use a FlexGridSizer
128
129 //EED 2018-04-18
130 //    wxFlexGridSizer *sizer    = new wxFlexGridSizer(1);
131     sizer       = new wxFlexGridSizer(1);
132
133     if (title!=_T(""))
134     {
135            sizer->Add( new wxStaticText(panel,-1, title ) ); 
136     }
137     for (i=0;i<MAX_RADIOBUTTON; i++)
138     {
139        if (mwxRadioButton[i]!=NULL)
140        {
141           sizer->Add( mwxRadioButton[i],1,wxGROW ); 
142        }
143     }
144     sizer->AddGrowableCol(0);
145     panel->SetSizer(sizer);
146
147 //    panel->SetAutoLayout(true);
148 //    panel->Layout();
149 */
150
151   }
152   //-------------------------------------------------------------------------
153   
154   RadioButtonWidget::~RadioButtonWidget()
155   {
156   }
157
158   //-------------------------------------------------------------------------
159  
160   int RadioButtonWidget::GetValue()
161   { 
162     int result=-1;
163     int i;
164     for (i=0;i<MAX_RADIOBUTTON; i++)
165       {
166         if ( mwxRadioButton[i]!=NULL)
167           {
168             if (mwxRadioButton[i]->GetValue()==true)
169               {
170                 result=i;
171               }
172           }
173       }
174     return result;
175   }
176
177   //--------------------------------------------------------------------------
178   void RadioButtonWidget::OnRadioButton(wxEvent& event)
179   {
180     mBox->bbSetOutputOut( GetValue() );
181     mBox->bbSetInputIn( GetValue() );
182     mBox->bbSignalOutputModification("Out");
183   }
184
185
186   //--------------------------------------------------------------------------
187   void RadioButtonWidget::AddElements( std::vector<wxString> lstIn ,int In, wxString title)
188   {
189         DestroyChildren();
190
191     MAX_RADIOBUTTON = lstIn.size();
192     wxPanel *panel      = this;
193     int i;
194     long style=wxRB_GROUP;
195     for (i=0;i<MAX_RADIOBUTTON; i++)
196     {
197            if ( lstIn[i]!=_T(""))
198            {
199     //---------------------------------------------------------------------
200     // 1) Creation of the components of the widget
201     // Any top level sub-widget must have the panel returned by panel
202     // for parent
203               mwxRadioButton[i] = new wxRadioButton( panel, -1, lstIn[i],wxDefaultPosition, wxDefaultSize, style);
204               style=0;
205               if (In==i)
206               {
207                       mwxRadioButton[i]->SetValue(true);
208               } else {
209                       mwxRadioButton[i]->SetValue(false);
210               }
211                Connect( mwxRadioButton[i]->GetId(),  
212                    wxEVT_COMMAND_RADIOBUTTON_SELECTED, 
213                   (wxObjectEventFunction) 
214                   (void (wxPanel::*)(wxEvent&))
215                   &RadioButtonWidget::OnRadioButton ); 
216            } else {
217                mwxRadioButton[i]=NULL;
218            } // if
219     } // for 
220     
221     //---------------------------------------------------------------------
222     // 2) Insertion of the components in the window
223     
224     // We use a FlexGridSizer
225
226 //EED 2018-04-18
227 //    wxFlexGridSizer *sizer    = new wxFlexGridSizer(1);
228     sizer       = new wxFlexGridSizer(1);
229
230     if (title!=_T(""))
231     {
232            sizer->Add( new wxStaticText(panel,-1, title ) ); 
233     }
234     for (i=0;i<MAX_RADIOBUTTON; i++)
235     {
236        if (mwxRadioButton[i]!=NULL)
237        {
238           sizer->Add( mwxRadioButton[i],1,wxGROW ); 
239        }
240     }
241     sizer->AddGrowableCol(0);
242     panel->SetSizer(sizer);
243
244 //    panel->SetAutoLayout(true);
245 //    panel->Layout();
246
247
248
249   }
250
251
252   //--------------------------------------------------------------------------
253   //-------------------------------------------------------------------------
254   //--------------------------------------------------------------------------
255   //--------------------------------------------------------------------------
256
257   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,RadioButton);
258   BBTK_BLACK_BOX_IMPLEMENTATION(RadioButton,bbtk::WxBlackBox);
259
260   
261         //-----------------------------------------------------------------     
262         void RadioButton::bbUserSetDefaultValues()
263         {
264                 bbSetInputIn(0);
265                 bbSetOutputOut( bbGetInputIn() );
266                 bbSetInputIn0("");
267                 bbSetInputIn1("");
268                 bbSetInputIn2("");
269                 bbSetInputIn3("");
270                 bbSetInputIn4("");
271                 bbSetInputIn5("");
272                 bbSetInputIn6("");
273                 bbSetInputIn7("");
274                 bbSetInputIn8("");
275                 bbSetInputIn9("");              
276         }
277         
278         //-----------------------------------------------------------------     
279         void RadioButton::bbUserInitializeProcessing()
280         {
281         }
282         
283         //-----------------------------------------------------------------     
284         void RadioButton::bbUserFinalizeProcessing()
285         {
286         }
287         
288   void RadioButton::Process() 
289   { 
290     bbtkDebugMessageInc("Core",9,"RadioButton::Process()"<<std::endl);
291     bbtkDebugDecTab("Core",9);
292
293
294     std::vector<wxString> lstIn;
295     lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
296     lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
297     lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
298     lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
299     lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
300     lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
301     lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
302     lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
303     lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
304     lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
305
306
307         ( (RadioButtonWidget*)bbGetOutputWidget() )->AddElements(lstIn, bbGetInputIn() , bbtk::std2wx(bbGetInputTitle()) );
308
309
310   }
311
312   /**
313    * \brief  Create wxWidget . 
314    *
315    *
316    */ 
317  void RadioButton::CreateWidget(wxWindow* parent)
318   {
319
320     std::vector<wxString> lstIn;
321     lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
322     lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
323     lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
324     lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
325     lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
326     lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
327     lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
328     lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
329     lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
330     lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
331
332     RadioButtonWidget *w = new RadioButtonWidget(
333                          this,
334 //                         bbGetWxParent(),
335                                                  parent,        
336                          bbGetInputIn() ,
337                          bbtk::std2wx(bbGetInputTitle()),
338                          lstIn );
339
340    bbSetOutputOut( bbGetInputIn() );
341    bbSetOutputWidget( w );
342
343   }
344
345
346
347
348 }//namespace bbtk
349
350 #endif // _USE_WXWIDGETS_ 
351