]> Creatis software - bbtk.git/commitdiff
#3462 SpinCtrl box
authorEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Thu, 3 Jun 2021 14:10:27 +0000 (16:10 +0200)
committerEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Thu, 3 Jun 2021 14:10:27 +0000 (16:10 +0200)
packages/wx/bbs/appli/example_SpinCtrl.bbg [new file with mode: 0644]
packages/wx/bbs/appli/example_SpinCtrl.bbs [new file with mode: 0644]
packages/wx/src/bbwxSpinCtrl.cxx [new file with mode: 0644]
packages/wx/src/bbwxSpinCtrl.h [new file with mode: 0644]

diff --git a/packages/wx/bbs/appli/example_SpinCtrl.bbg b/packages/wx/bbs/appli/example_SpinCtrl.bbg
new file mode 100644 (file)
index 0000000..b7bc80a
--- /dev/null
@@ -0,0 +1,48 @@
+# ----------------------------------
+# - BBTKGEditor v 1.4 BBG BlackBox Diagram file
+# - /home/davila/Creatis/C11/creatools_source/bbtk/packages/wx/bbs/appli/example_SpinCtrl.bbg
+# ----------------------------------
+
+APP_START
+CATEGORY:<VOID>
+DESCRIPTION:Description ??
+AUTHOR:Author ??
+COMPLEXBOX:FALSE
+COMPLEXINPUTS:0
+BOXES:3
+BOX
+wx:SpinCtrl:Box00
+ISEXEC:FALSE
+-63.378740:69.384705:-900.000000
+-24.298740:59.384705:-900.000000
+PORT
+Selected:"50"
+PORT
+Type:"1"
+FIN_BOX
+BOX
+wx:LayoutLine:Box01
+ISEXEC:TRUE
+-82.661050:20.704775:-900.000000
+-25.101050:10.704775:-900.000000
+FIN_BOX
+BOX
+wx:OutputText:Box02
+ISEXEC:FALSE
+-44.096430:49.470189:-900.000000
+-7.321430:39.470189:-900.000000
+FIN_BOX
+CONNECTIONS:4
+CONNECTION
+Box00:Widget:Box01:Widget1
+NumberOfControlPoints:0
+CONNECTION
+Box02:Widget:Box01:Widget5
+NumberOfControlPoints:0
+CONNECTION
+Box00:BoxChange:Box02:BoxExecute
+NumberOfControlPoints:0
+CONNECTION
+Box00:Out:Box02:In
+NumberOfControlPoints:0
+APP_END
diff --git a/packages/wx/bbs/appli/example_SpinCtrl.bbs b/packages/wx/bbs/appli/example_SpinCtrl.bbs
new file mode 100644 (file)
index 0000000..b3a26a0
--- /dev/null
@@ -0,0 +1,37 @@
+# ----------------------------------
+# - BBTKGEditor v 1.4 BBS BlackBox Script
+# - /home/davila/Creatis/C11/creatools_source/bbtk/packages/wx/bbs/appli/example_SpinCtrl.bbs
+# ----------------------------------
+
+# BBTK GEditor Script
+# ----------------------
+
+include std
+include itkvtk
+include wx
+
+author "Author ??"
+description "Description ??"
+category "<VOID>"
+
+new wx:SpinCtrl Box00
+  set Box00.Selected "50"
+  set Box00.Type "1"
+
+new wx:LayoutLine Box01
+
+new wx:OutputText Box02
+
+
+connect Box00.Widget Box01.Widget1
+
+connect Box02.Widget Box01.Widget5
+
+connect Box00.BoxChange Box02.BoxExecute
+
+connect Box00.Out Box02.In
+
+
+
+# Complex input ports
+exec Box01
diff --git a/packages/wx/src/bbwxSpinCtrl.cxx b/packages/wx/src/bbwxSpinCtrl.cxx
new file mode 100644 (file)
index 0000000..a30be49
--- /dev/null
@@ -0,0 +1,201 @@
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+#include "bbwxSpinCtrl.h"
+#include "bbwxPackage.h"
+
+#include <wx/spinbutt.h>
+#include <wx/spinctrl.h>
+
+namespace bbwx
+{
+
+
+
+  //--------------------------------------------------------------------------
+  // The widget created by the box 
+  class SpinCtrlWidget : public wxPanel 
+  {
+  public:
+    /// Ctor with the two first params the parent window and the creator box
+    /// which must be passed to the WxBlackBoxWidget constructor.
+    /// The other params initialize the widget 
+    SpinCtrlWidget(SpinCtrl* box, wxWindow *parent,
+                wxString title, int reactiveOnKeyStroke );
+    /// Dtor
+    ~SpinCtrlWidget();
+    /// Events callbacks
+    /// Called when the box is clicked
+    void OnSpinCtrlClick(wxCommandEvent& event);
+
+    // Accessors
+    bool GetValue() { return mwxSpinCtrl->GetValue(); }
+    void SetValue(int  min, int max, int selected);
+    // Update the texts which display the min/max/current values of the slider
+       
+  private:
+    SpinCtrl*       mBox;
+    wxSpinCtrl         *mwxSpinCtrl;
+    wxSpinButton       *mwxSpinButton;
+    int                _reactiveOnKeyStroke;
+    int                selected;
+  };
+  //------------------------------------------------------------------------
+  //------------------------------------------------------------------------
+  //------------------------------------------------------------------------
+
+  
+    
+  //-------------------------------------------------------------------------
+  SpinCtrlWidget::SpinCtrlWidget(SpinCtrl* box, wxWindow *parent,
+                            wxString title,
+                             int reactiveOnKeyStroke)
+    :  
+    wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
+    mBox(box),
+    _reactiveOnKeyStroke(reactiveOnKeyStroke)
+  {
+    wxPanel * panel = this;
+    //---------------------------------------------------------------------
+    // 1) Creation of the components of the widget
+    // Any top level sub-widget must have the panel returned by panel
+    // for parent
+
+
+    wxFlexGridSizer *sizer;
+    sizer      = new wxFlexGridSizer(1);
+
+    
+    mwxSpinCtrl                = NULL;
+    mwxSpinButton      = NULL;
+       if (mBox->bbGetInputType()==0)
+       {
+           mwxSpinCtrl = new wxSpinCtrl( panel, -1 );      
+               // Connecting events to callbacks
+               Connect( mwxSpinCtrl->GetId(), 
+                        wxEVT_COMMAND_SPINCTRL_UPDATED, 
+                        (wxObjectEventFunction) 
+                        (void (wxPanel::*)(wxScrollEvent&))
+                        &SpinCtrlWidget::OnSpinCtrlClick);
+               sizer->Add( mwxSpinCtrl );
+       } else {
+           mwxSpinButton = new wxSpinButton( panel, -1 );      
+               // Connecting events to callbacks
+               Connect( mwxSpinButton->GetId(), 
+                        wxEVT_SPIN, 
+                        (wxObjectEventFunction) 
+                        (void (wxPanel::*)(wxScrollEvent&))
+                        &SpinCtrlWidget::OnSpinCtrlClick);
+               sizer->Add( mwxSpinButton );
+       }// if Type
+             
+    //---------------------------------------------------------------------
+
+    //---------------------------------------------------------------------
+    // 2) Insertion of the components in the window
+    
+    // We use a FlexGridSizer
+    panel->SetSizer(sizer);
+  }
+  //-------------------------------------------------------------------------
+  
+
+  //-------------------------------------------------------------------------
+  SpinCtrlWidget::~SpinCtrlWidget()
+  {
+  }
+  //-------------------------------------------------------------------------
+
+
+  //-------------------------------------------------------------------------
+
+
+
+  //-------------------------------------------------------------------------
+  void SpinCtrlWidget::OnSpinCtrlClick(wxCommandEvent& event)
+  {
+         // When user clicks the box 
+         // we update the output of the box
+
+       if (mBox->bbGetInputType()==0)
+       {
+         mBox->bbSetOutputOut( mwxSpinCtrl->GetValue() );
+       } else {
+         mBox->bbSetOutputOut( mwxSpinButton->GetValue() );
+       }// if Type
+
+         // and signal that the output has changed
+         //if(_reactiveOnKeyStroke==1){
+         mBox->bbSignalOutputModification(std::string("Out"));
+         //}
+  }
+  //-------------------------------------------------------------------------
+
+  //-------------------------------------------------------------------------
+  
+
+  //-------------------------------------------------------------------------
+  void SpinCtrlWidget::SetValue(int min, int max, int selected)
+  {
+       if (mBox->bbGetInputType()==0)
+       {
+           mwxSpinCtrl->SetRange( min,max );
+           mwxSpinCtrl->SetValue( selected );
+       } else {
+           mwxSpinButton->SetRange( min,max );
+           mwxSpinButton->SetValue( selected );
+       }// if Type
+  }
+  //-------------------------------------------------------------------------
+
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,SpinCtrl)
+BBTK_BLACK_BOX_IMPLEMENTATION(SpinCtrl,bbtk::WxBlackBox);
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+void SpinCtrl::Process()
+{
+               // if with label
+               ((SpinCtrlWidget*)bbGetOutputWidget())->SetValue( bbGetInputMin() , bbGetInputMax(), bbGetInputSelected() );    
+               bbSetOutputOut( bbGetInputSelected() );
+}
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+void SpinCtrl::CreateWidget(wxWindow* parent)
+{
+
+               SpinCtrlWidget *spinctrlwidget=new  SpinCtrlWidget( this , parent, bbGetInputTitle() ,1);
+               bbSetOutputWidget( spinctrlwidget );
+               spinctrlwidget->SetValue( bbGetInputMin() , bbGetInputMax(), bbGetInputSelected() );    
+
+}
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+void SpinCtrl::bbUserSetDefaultValues()
+{
+       bbSetInputMin(0);
+       bbSetInputMax(100);
+       bbSetInputSelected(0);
+       bbSetInputType(0);
+       bbSetInputTitle("");    
+
+}
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+void SpinCtrl::bbUserInitializeProcessing()
+{
+}
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+void SpinCtrl::bbUserFinalizeProcessing()
+{
+}
+
+} // EO namespace bbwx
+
+
diff --git a/packages/wx/src/bbwxSpinCtrl.h b/packages/wx/src/bbwxSpinCtrl.h
new file mode 100644 (file)
index 0000000..f325cc2
--- /dev/null
@@ -0,0 +1,60 @@
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+#ifdef _USE_WXWIDGETS_
+#ifndef __bbwxSpinCtrl_h_INCLUDED__
+#define __bbwxSpinCtrl_h_INCLUDED__
+
+#include "bbwx_EXPORT.h"
+#include "bbtkWxBlackBox.h"
+
+namespace bbwx
+{
+
+class bbwx_EXPORT SpinCtrl
+ : 
+   public bbtk::WxBlackBox
+{
+  BBTK_BLACK_BOX_INTERFACE(SpinCtrl,bbtk::WxBlackBox);
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+  BBTK_DECLARE_INPUT(Title,std::string);
+  BBTK_DECLARE_INPUT(Min,int);
+  BBTK_DECLARE_INPUT(Max,int);
+  BBTK_DECLARE_INPUT(Selected,int);
+  BBTK_DECLARE_INPUT(Type,int);
+  BBTK_DECLARE_OUTPUT(Out,int);
+  BBTK_PROCESS(Process);
+  void Process();
+  BBTK_CREATE_WIDGET(CreateWidget);
+  void CreateWidget(wxWindow*);
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(SpinCtrl,bbtk::WxBlackBox);
+  BBTK_NAME("SpinCtrl");
+  BBTK_AUTHOR("InfoDev");
+  BBTK_DESCRIPTION("No Description.");
+  BBTK_CATEGORY("__CategoryBlackBox__");
+
+  BBTK_INPUT(SpinCtrl,Title,"Title",std::string,"");
+  BBTK_INPUT(SpinCtrl,Min,"(default 0) Min",int,"");
+  BBTK_INPUT(SpinCtrl,Max,"default 100) Max",int,"");
+  BBTK_INPUT(SpinCtrl,Selected,"default 0) Selected",int,"");
+  BBTK_INPUT(SpinCtrl,Type,"(default 0)  0:with Label    1:not Label",int,"");
+
+  BBTK_OUTPUT(SpinCtrl,Out,"Output value",int,"");
+
+BBTK_END_DESCRIBE_BLACK_BOX(SpinCtrl);
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+}
+// EO namespace bbwx
+
+#endif // __bbwxSpinCtrl_h_INCLUDED__
+#endif // _USE_WXWIDGETS_
+