]> Creatis software - bbtk.git/commitdiff
*** empty log message ***
authorguigues <guigues>
Wed, 11 Feb 2009 12:23:12 +0000 (12:23 +0000)
committerguigues <guigues>
Wed, 11 Feb 2009 12:23:12 +0000 (12:23 +0000)
samples/SampleInterpreter/bbtkSampleInterpreter.cxx
samples/SampleOutputObserver/bbtkSampleOutputObserver.cxx
samples/SampleWidgetsBase/bbtkSampleWidgetsBase.cxx

index 91f4ff02eec9b55e07218f2e94babed58f62c73c..6100d5ec6b4148e4345d674d94becde75a43367c 100644 (file)
@@ -31,7 +31,8 @@ int main(int argv, char* argc[])
       std::cout << "Enter a number : ";
       double num = 0;
       std::cin >> num;
-      // Set its input 'In' to 1
+
+      // Set its input 'In' to num
       p->bbSetInput("In",num);
 
       // Execute it
@@ -46,7 +47,22 @@ int main(int argv, char* argc[])
       
       std::cout << num << "+1 = "<<v<<std::endl;
        
-    }
+      //============================================================
+      // Second example : imagine the bbProcessing.bbs script has created
+      // the box "a" of type Processing
+      // Here we simulate it using:
+      I->InterpretLine("new Processing a");
+      // We get a the black box "a" in the workspace:
+      bbtk::BlackBox::Pointer a 
+       = I->GetExecuter()->GetWorkspace()->GetPrototype()->bbGetBlackBox("a");
+      // Then the same as previously...
+      a->bbSetInput("In",num);
+      a->bbExecute();
+      double w = p->bbGetOutput("Out").get<double>();
+      std::cout << "In case you did not understand:"<<std::endl<<num << "+1 = "<<w<<std::endl;
+
+      // That's all !
+   }
   catch (bbtk::Exception e)
     {
       std::cout << "* ERROR : "<<e.GetErrorMessage()<<std::endl;
index 67c40751fd24d000d21ef9be7e7214bcefa1a51c..71ccbd8975b216473a18b3be332ae95993edfb84 100644 (file)
@@ -6,12 +6,15 @@
 //=========================================================================
 
 //=========================================================================
-void CallbackFunction ( bbtk::BlackBox::Pointer p, 
-                       const std::string& o, 
-                       bbtk::IOStatus s)
+// FIRST EXAMPLE USING A FUNCTION AS CALLBACK
+void CallbackFunction ( bbtk::BlackBox::Pointer p,  // The black box which changed 
+                       const std::string& o, // The output which changed
+                       bbtk::IOStatus s) // The new status of the output
 {
   std::cout << "== Callback function called with p="<<p->bbGetName()
            <<" o="<<o<<" s="<<bbtk::GetIOStatusString(s)<<std::endl;
+
+  // Cast the black box pointer into Slider pointer
   bbwx::Slider::Pointer slider = boost::dynamic_pointer_cast<bbwx::Slider>(p);
   if (slider)
     {
@@ -30,6 +33,7 @@ void SliderCallback()
     {
       bbwx::Slider::Pointer slider = bbwx::Slider::New("slider");
       slider->bbSetInputWinDialog(true);  // mandatory
+      // Add the observer 
       slider->bbAddOutputObserver( "Out", &CallbackFunction );
       slider->bbExecute();
     }
@@ -42,6 +46,7 @@ void SliderCallback()
 
 
 //=========================================================================
+// SECOND EXAMPLE : MEMBER METHOD CALLED WHEN SLIDER IS RELEASED
 class ClassWithTwoSliders
 {
 public:
@@ -66,6 +71,9 @@ ClassWithTwoSliders::ClassWithTwoSliders()
   try
     {
       mSlider1 = bbwx::Slider::New("slider1");
+      // Add the observer method
+      // As it is not a FREEHAND function we must use the macro 
+      // BBTK_MAKE_OUTPUT_OBSERVER which takes the object and the method to call
       mSlider1->bbAddOutputObserver("Out", 
                                    BBTK_MAKE_OUTPUT_OBSERVER
                                    (this,
index 481c8281ba14a530b8bc40883b4f6b498381f8e0..6163c94f299dd00b008608adfb857e6f14fe578c 100644 (file)
@@ -3,7 +3,7 @@
 
 //=========================================================================
 // Different examples of using black boxes in C++
-// Here we do not use wxWidgets however WxBlackBox es work in **Dialog** mode 
+// Here we do not use wxWidgets however WxBlackBox work in **Dialog** mode 
 //=========================================================================
 
 //=========================================================================