]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxRadioButton.cxx
7b670ad65d53c8e776171970e484f11326e69c04
[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     AddElements(  lstIn , In,title);
93     mBox->bbSetOutputOut( GetValue() );
94     mBox->bbSetInputIn( GetValue() );
95   }
96   
97   //-------------------------------------------------------------------------
98   
99   RadioButtonWidget::~RadioButtonWidget()
100   {
101   }
102
103   //-------------------------------------------------------------------------
104  
105   int RadioButtonWidget::GetValue()
106   { 
107     int result=-1;
108     int i;
109     for (i=0;i<MAX_RADIOBUTTON; i++)
110     {
111                 if ( mwxRadioButton[i]!=NULL)
112                 {
113                 if (mwxRadioButton[i]->GetValue()==true)
114                 {
115                                 result=i;
116                 }
117                 } // if GetValue
118       } // if mwxRadioButton
119     return result;
120   }
121
122   //--------------------------------------------------------------------------
123   void RadioButtonWidget::OnRadioButton(wxEvent& event)
124   {
125     mBox->bbSetOutputOut( GetValue() );
126     mBox->bbSetInputIn( GetValue() );
127     mBox->bbSignalOutputModification("Out");
128   }
129
130
131   //--------------------------------------------------------------------------
132   void RadioButtonWidget::AddElements( std::vector<wxString> lstIn ,int In, wxString title)
133   {
134         DestroyChildren();
135
136     MAX_RADIOBUTTON = lstIn.size();
137     wxPanel *panel      = this;
138     int i;
139     long style=wxRB_GROUP;
140     for (i=0;i<MAX_RADIOBUTTON; i++)
141     {
142            if ( lstIn[i]!=_T(""))
143            {
144     //---------------------------------------------------------------------
145     // 1) Creation of the components of the widget
146     // Any top level sub-widget must have the panel returned by panel
147     // for parent
148               mwxRadioButton[i] = new wxRadioButton( panel, -1, lstIn[i],wxDefaultPosition, wxDefaultSize, style);
149               style=0;
150               if (In==i)
151               {
152                       mwxRadioButton[i]->SetValue(true);
153               } else {
154                       mwxRadioButton[i]->SetValue(false);
155               }
156                Connect( mwxRadioButton[i]->GetId(),  
157                    wxEVT_COMMAND_RADIOBUTTON_SELECTED, 
158                   (wxObjectEventFunction) 
159                   (void (wxPanel::*)(wxEvent&))
160                   &RadioButtonWidget::OnRadioButton ); 
161            } else {
162                mwxRadioButton[i]=NULL;
163            } // if
164     } // for 
165     
166     //---------------------------------------------------------------------
167     // 2) Insertion of the components in the window
168     
169     // We use a FlexGridSizer
170
171 //EED 2018-04-18
172 //    wxFlexGridSizer *sizer    = new wxFlexGridSizer(1);
173     sizer       = new wxFlexGridSizer(1);
174
175     if (title!=_T(""))
176     {
177            sizer->Add( new wxStaticText(panel,-1, title ) ); 
178     }
179     for (i=0;i<MAX_RADIOBUTTON; i++)
180     {
181        if (mwxRadioButton[i]!=NULL)
182        {
183           sizer->Add( mwxRadioButton[i],1,wxGROW ); 
184        }
185     }
186     sizer->AddGrowableCol(0);
187     panel->SetSizer(sizer);
188
189     panel->SetAutoLayout(true);
190     panel->Layout();
191
192   }
193
194
195   //--------------------------------------------------------------------------
196   //-------------------------------------------------------------------------
197   //--------------------------------------------------------------------------
198   //--------------------------------------------------------------------------
199
200   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,RadioButton);
201   BBTK_BLACK_BOX_IMPLEMENTATION(RadioButton,bbtk::WxBlackBox);
202
203   
204         //-----------------------------------------------------------------     
205         void RadioButton::bbUserSetDefaultValues()
206         {
207                 bbSetInputIn(0);
208                 bbSetOutputOut( bbGetInputIn() );
209                 bbSetInputIn0("");
210                 bbSetInputIn1("");
211                 bbSetInputIn2("");
212                 bbSetInputIn3("");
213                 bbSetInputIn4("");
214                 bbSetInputIn5("");
215                 bbSetInputIn6("");
216                 bbSetInputIn7("");
217                 bbSetInputIn8("");
218                 bbSetInputIn9("");              
219         }
220         
221         //-----------------------------------------------------------------     
222         void RadioButton::bbUserInitializeProcessing()
223         {
224         }
225         
226         //-----------------------------------------------------------------     
227         void RadioButton::bbUserFinalizeProcessing()
228         {
229         }
230         
231   void RadioButton::Process() 
232   { 
233     bbtkDebugMessageInc("Core",9,"RadioButton::Process()"<<std::endl);
234     bbtkDebugDecTab("Core",9);
235     std::vector<wxString> lstIn;
236     lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
237     lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
238     lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
239     lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
240     lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
241     lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
242     lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
243     lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
244     lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
245     lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
246         if (bbGetOutputWidget()!=NULL) 
247         {
248                 ( (RadioButtonWidget*)bbGetOutputWidget() )->AddElements(lstIn, bbGetInputIn() , bbtk::std2wx(bbGetInputTitle()) );     
249         } // if bbGetOutputWidget
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