]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxRadioButton.cxx
375092be431d940e54e2b1ca3ff70daca73d049c
[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   //-------------------------------------------------------------------------
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               }
114           }
115       }
116     return result;
117   }
118
119   //--------------------------------------------------------------------------
120   void RadioButtonWidget::OnRadioButton(wxEvent& event)
121   {
122     mBox->bbSetOutputOut( GetValue() );
123     mBox->bbSetInputIn( GetValue() );
124     mBox->bbSignalOutputModification("Out");
125   }
126
127
128   //--------------------------------------------------------------------------
129   void RadioButtonWidget::AddElements( std::vector<wxString> lstIn ,int In, wxString title)
130   {
131         DestroyChildren();
132
133     MAX_RADIOBUTTON = lstIn.size();
134     wxPanel *panel      = this;
135     int i;
136     long style=wxRB_GROUP;
137     for (i=0;i<MAX_RADIOBUTTON; i++)
138     {
139            if ( lstIn[i]!=_T(""))
140            {
141     //---------------------------------------------------------------------
142     // 1) Creation of the components of the widget
143     // Any top level sub-widget must have the panel returned by panel
144     // for parent
145               mwxRadioButton[i] = new wxRadioButton( panel, -1, lstIn[i],wxDefaultPosition, wxDefaultSize, style);
146               style=0;
147               if (In==i)
148               {
149                       mwxRadioButton[i]->SetValue(true);
150               } else {
151                       mwxRadioButton[i]->SetValue(false);
152               }
153                Connect( mwxRadioButton[i]->GetId(),  
154                    wxEVT_COMMAND_RADIOBUTTON_SELECTED, 
155                   (wxObjectEventFunction) 
156                   (void (wxPanel::*)(wxEvent&))
157                   &RadioButtonWidget::OnRadioButton ); 
158            } else {
159                mwxRadioButton[i]=NULL;
160            } // if
161     } // for 
162     
163     //---------------------------------------------------------------------
164     // 2) Insertion of the components in the window
165     
166     // We use a FlexGridSizer
167
168 //EED 2018-04-18
169 //    wxFlexGridSizer *sizer    = new wxFlexGridSizer(1);
170     sizer       = new wxFlexGridSizer(1);
171
172     if (title!=_T(""))
173     {
174            sizer->Add( new wxStaticText(panel,-1, title ) ); 
175     }
176     for (i=0;i<MAX_RADIOBUTTON; i++)
177     {
178        if (mwxRadioButton[i]!=NULL)
179        {
180           sizer->Add( mwxRadioButton[i],1,wxGROW ); 
181        }
182     }
183     sizer->AddGrowableCol(0);
184     panel->SetSizer(sizer);
185
186     panel->SetAutoLayout(true);
187     panel->Layout();
188
189   }
190
191
192   //--------------------------------------------------------------------------
193   //-------------------------------------------------------------------------
194   //--------------------------------------------------------------------------
195   //--------------------------------------------------------------------------
196
197   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,RadioButton);
198   BBTK_BLACK_BOX_IMPLEMENTATION(RadioButton,bbtk::WxBlackBox);
199
200   
201         //-----------------------------------------------------------------     
202         void RadioButton::bbUserSetDefaultValues()
203         {
204                 bbSetInputIn(0);
205                 bbSetOutputOut( bbGetInputIn() );
206                 bbSetInputIn0("");
207                 bbSetInputIn1("");
208                 bbSetInputIn2("");
209                 bbSetInputIn3("");
210                 bbSetInputIn4("");
211                 bbSetInputIn5("");
212                 bbSetInputIn6("");
213                 bbSetInputIn7("");
214                 bbSetInputIn8("");
215                 bbSetInputIn9("");              
216         }
217         
218         //-----------------------------------------------------------------     
219         void RadioButton::bbUserInitializeProcessing()
220         {
221         }
222         
223         //-----------------------------------------------------------------     
224         void RadioButton::bbUserFinalizeProcessing()
225         {
226         }
227         
228   void RadioButton::Process() 
229   { 
230     bbtkDebugMessageInc("Core",9,"RadioButton::Process()"<<std::endl);
231     bbtkDebugDecTab("Core",9);
232
233
234     std::vector<wxString> lstIn;
235     lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
236     lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
237     lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
238     lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
239     lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
240     lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
241     lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
242     lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
243     lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
244     lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
245
246
247         ( (RadioButtonWidget*)bbGetOutputWidget() )->AddElements(lstIn, bbGetInputIn() , bbtk::std2wx(bbGetInputTitle()) );
248
249
250   }
251
252   /**
253    * \brief  Create wxWidget . 
254    *
255    *
256    */ 
257  void RadioButton::CreateWidget(wxWindow* parent)
258   {
259
260     std::vector<wxString> lstIn;
261     lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
262     lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
263     lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
264     lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
265     lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
266     lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
267     lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
268     lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
269     lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
270     lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
271
272     RadioButtonWidget *w = new RadioButtonWidget(
273                          this,
274                                                  parent,        
275                          bbGetInputIn() ,
276                          bbtk::std2wx(bbGetInputTitle()),
277                          lstIn );
278
279    bbSetOutputOut( bbGetInputIn() );
280    bbSetOutputWidget( w );
281
282   }
283
284
285
286
287 }//namespace bbtk
288
289 #endif // _USE_WXWIDGETS_ 
290