]> Creatis software - bbtk.git/commitdiff
re-add RadioButton
authorjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Mon, 11 Feb 2008 14:47:12 +0000 (14:47 +0000)
committerjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Mon, 11 Feb 2008 14:47:12 +0000 (14:47 +0000)
(last bug to be fixed by Eduardo :-( )

packages/wx/src/bbwxRadioButton.cxx [new file with mode: 0644]
packages/wx/src/bbwxRadioButton.h [new file with mode: 0644]

diff --git a/packages/wx/src/bbwxRadioButton.cxx b/packages/wx/src/bbwxRadioButton.cxx
new file mode 100644 (file)
index 0000000..6527cfa
--- /dev/null
@@ -0,0 +1,205 @@
+/*=========================================================================
+                                                                                
+  Program:   bbtk
+  Module:    $RCSfile: bbwxRadioButton.cxx,v $
+  Language:  C++
+  Date:      $Date: 2008/02/11 14:47:12 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+/**
+ *  \file 
+ *  \brief 
+ */
+
+
+#ifdef _USE_WXWIDGETS_
+
+
+#include "bbwxRadioButton.h"
+#include "bbwxPackage.h"
+
+#include <vector>
+
+namespace bbwx
+{
+  BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,RadioButton);
+  
+  //-------------------------------------------------------------------------
+  RadioButtonWidget::RadioButtonWidget( RadioButton* box,
+               wxWindow *parent,
+               int In,
+               wxString title,
+               std::vector<wxString> lstIn )
+    :
+    wxPanel( parent, -1)
+  {
+
+    wxPanel *panel     = this;
+    MAX_RADIOBUTTON = lstIn.size();
+    int i;
+    long style=wxRB_GROUP;
+    for (i=0;i<MAX_RADIOBUTTON; i++)
+    {
+          if ( lstIn[i]!=_T(""))
+          {
+    //---------------------------------------------------------------------
+    // 1) Creation of the components of the widget
+    // Any top level sub-widget must have the panel returned by panel
+    // for parent
+             mwxRadioButton[i] = new wxRadioButton( panel, -1, lstIn[i],wxDefaultPosition, wxDefaultSize, style);
+             style=0;
+             if (In==i)
+             {
+                     mwxRadioButton[i]->SetValue(true);
+             } 
+             else 
+             {
+                     mwxRadioButton[i]->SetValue(false);
+             }
+              Connect( mwxRadioButton[i]->GetId(),  
+                   wxEVT_COMMAND_RADIOBUTTON_SELECTED, 
+                  (wxObjectEventFunction) 
+                  (void (wxPanel::*)(wxEvent&))
+                  &RadioButtonWidget::OnRadioButton ); 
+          } 
+          else 
+          {
+              mwxRadioButton[i]=NULL;
+          }
+    }
+    
+    //---------------------------------------------------------------------
+    // 2) Insertion of the components in the window
+    
+    // We use a FlexGridSizer
+    wxFlexGridSizer *sizer     = new wxFlexGridSizer(1);
+    if (title!=_T(""))
+    {
+          sizer->Add( new wxStaticText(panel,-1, title ) ); 
+    }
+    for (i=0;i<MAX_RADIOBUTTON; i++)
+    {
+       if (mwxRadioButton[i]!=NULL)
+       {
+          sizer->Add( mwxRadioButton[i],1,wxGROW ); 
+       }
+    }
+    sizer->AddGrowableCol(0);
+
+    panel->SetSizer(sizer);
+    panel->SetAutoLayout(true);
+    panel->Layout();
+
+  }
+  //-------------------------------------------------------------------------
+  
+  RadioButtonWidget::~RadioButtonWidget()
+  {
+  }
+
+  //-------------------------------------------------------------------------
+  int RadioButtonWidget::GetValue()
+  { 
+    int result=-1;
+    int i;
+    for (i=0;i<MAX_RADIOBUTTON; i++)
+      {
+       if ( mwxRadioButton[i]!=NULL)
+         {
+           if (mwxRadioButton[i]->GetValue()==true)
+             {
+               result=i;
+             }
+         }
+      }
+    return result;
+  }
+
+  //--------------------------------------------------------------------------
+  void RadioButtonWidget::OnRadioButton(wxEvent& event)
+  {
+    mBox->bbSetOutputOut( GetValue() );
+    mBox->bbSetInputIn( GetValue() );
+    mBox->bbSignalOutputModification("Out");
+  }
+
+  //--------------------------------------------------------------------------
+  //-------------------------------------------------------------------------
+  //--------------------------------------------------------------------------
+  //--------------------------------------------------------------------------
+
+
+  BBTK_USER_BLACK_BOX_IMPLEMENTATION(RadioButton,bbtk::WxBlackBox);
+
+
+  void RadioButton::bbUserConstructor() 
+  { 
+    bbSetInputIn(0);
+    bbSetOutputOut( bbGetInputIn() );
+    bbSetInputIn0("");
+    bbSetInputIn1("");
+    bbSetInputIn2("");
+    bbSetInputIn3("");
+    bbSetInputIn4("");
+    bbSetInputIn5("");
+    bbSetInputIn6("");
+    bbSetInputIn7("");
+    bbSetInputIn8("");
+    bbSetInputIn9("");
+  }
+  
+
+  void RadioButton::Process() 
+  { 
+    bbtkDebugMessageInc("Core",9,"RadioButton::Process()"<<std::endl);
+    bbtkDebugDecTab("Core",9);
+  }
+
+  /**
+   * \brief  Create wxWidget . 
+   *
+   *
+   */ 
+ void RadioButton::CreateWidget()
+  {
+
+    std::vector<wxString> lstIn;
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
+
+    RadioButtonWidget *w = new RadioButtonWidget(
+                         this,
+                         bbGetWxParent(),
+                         bbGetInputIn() ,
+                         bbtk::std2wx(bbGetInputTitle()),
+                         lstIn );
+
+   bbSetOutputWidget( w );
+
+  }
+
+
+
+
+}//namespace bbtk
+
+#endif // _USE_WXWIDGETS_ 
+
diff --git a/packages/wx/src/bbwxRadioButton.h b/packages/wx/src/bbwxRadioButton.h
new file mode 100644 (file)
index 0000000..71a0d10
--- /dev/null
@@ -0,0 +1,136 @@
+/*=========================================================================
+                                                                                
+  Program:   bbtk
+  Module:    $RCSfile: bbwxRadioButton.h,v $
+  Language:  C++
+  Date:      $Date: 2008/02/11 14:47:12 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*//**
+ * \brief Short description in one line
+ * 
+ * Long description which 
+ * can span multiple lines
+ */
+/**
+ * \file 
+ * \brief Pattern for the definition of a new type of Node (header)
+ */
+/**
+ * \class bbtk::NodePatern 
+ * \brief Pattern for the definition of a new type of Node 
+ */
+
+
+#ifdef _USE_WXWIDGETS_
+
+// Prevents multiple inclusions : use symbols of the form
+// __FILENAME_INCLUDED__ 
+// where FILENAME must be replaced by the actual file name
+#ifndef __bbWxRadioButton_h__
+#define __bbWxRadioButton_h__
+
+#include "bbtkWxBlackBox.h"
+
+// Namespace of the package "wx" is "bbwx" 
+// Namespace associated to packages should be of the form :
+// bbPACKAGENAME
+namespace bbwx
+{
+  
+  
+  
+  
+  class RadioButton;
+  
+  //--------------------------------------------------------------------------
+  // The widget created by the box 
+  class RadioButtonWidget : public wxPanel
+  {
+  public:
+    RadioButtonWidget( RadioButton* box, wxWindow *parent, 
+                      int In, 
+                      wxString title, 
+                      std::vector<wxString> lstIn );
+
+    ~RadioButtonWidget();
+
+    int GetValue();
+    void OnRadioButton(wxEvent& event);
+
+  private:
+    RadioButton      *mBox;
+    int                     MAX_RADIOBUTTON;
+    wxRadioButton    *mwxRadioButton[10];
+  };
+  
+  //------------------------------------------------------------------------
+  //------------------------------------------------------------------------
+  //------------------------------------------------------------------------
+
+  class /*BBTK_EXPORT*/ RadioButton : public bbtk::WxBlackBox
+  {
+
+    BBTK_USER_BLACK_BOX_INTERFACE(RadioButton,bbtk::WxBlackBox);
+    BBTK_DECLARE_INPUT(In,int);
+    BBTK_DECLARE_INPUT(In0,std::string);
+    BBTK_DECLARE_INPUT(In1,std::string);
+    BBTK_DECLARE_INPUT(In2,std::string);
+    BBTK_DECLARE_INPUT(In3,std::string);
+    BBTK_DECLARE_INPUT(In4,std::string);
+    BBTK_DECLARE_INPUT(In5,std::string);
+    BBTK_DECLARE_INPUT(In6,std::string);
+    BBTK_DECLARE_INPUT(In7,std::string);
+    BBTK_DECLARE_INPUT(In8,std::string);
+    BBTK_DECLARE_INPUT(In9,std::string);
+    BBTK_DECLARE_INPUT(Title,std::string);
+    BBTK_DECLARE_OUTPUT(Out,int);
+    BBTK_CREATE_WIDGET(CreateWidget);
+    BBTK_PROCESS(Process);
+    void Process();
+    void CreateWidget();
+
+  protected:
+    virtual void bbUserConstructor();
+
+  };
+  //=================================================================
+  // UserBlackBox description
+  BBTK_BEGIN_DESCRIBE_BLACK_BOX(RadioButton,bbtk::WxBlackBox);
+  BBTK_NAME("RadioButton");
+  BBTK_AUTHOR("eduardo.davila@creatis.insa-lyon.fr");
+  BBTK_DESCRIPTION("RadioButton group widget 0-9 entries");
+  BBTK_INPUT(RadioButton,In,"Set initial item",int);
+
+  BBTK_INPUT(RadioButton,In0,"option 0",std::string);
+  BBTK_INPUT(RadioButton,In1,"option 1",std::string);
+  BBTK_INPUT(RadioButton,In2,"option 2",std::string);
+  BBTK_INPUT(RadioButton,In3,"option 3",std::string);
+  BBTK_INPUT(RadioButton,In4,"option 4",std::string);
+  BBTK_INPUT(RadioButton,In5,"option 5",std::string);
+  BBTK_INPUT(RadioButton,In6,"option 6",std::string);
+  BBTK_INPUT(RadioButton,In7,"option 7",std::string);
+  BBTK_INPUT(RadioButton,In8,"option 8",std::string);
+  BBTK_INPUT(RadioButton,In9,"option 9",std::string);
+
+  BBTK_INPUT(RadioButton,Title,"Title of the widget (default '') ",std::string);
+
+  BBTK_OUTPUT(RadioButton,Out,"Item selected",int);
+  BBTK_END_DESCRIBE_BLACK_BOX(RadioButton);
+  //=================================================================
+
+}
+
+//namespace bbtk
+#endif  //__bbWxRadioButton_h__
+
+#endif //_USE_WXWIDGETS_