]> Creatis software - bbtk.git/commitdiff
*** empty log message ***
authorguigues <guigues>
Wed, 10 Dec 2008 09:33:16 +0000 (09:33 +0000)
committerguigues <guigues>
Wed, 10 Dec 2008 09:33:16 +0000 (09:33 +0000)
CMakeLists.txt
kernel/src/bbtkBlackBox.cxx
kernel/src/bbtkBlackBox.h
kernel/src/bbtkBlackBoxOutputConnector.cxx
kernel/src/bbtkBlackBoxOutputConnector.h
samples/CMakeLists.txt
samples/SampleOutputObserver/CMakeLists.txt [new file with mode: 0644]
samples/SampleOutputObserver/bbtkSampleOutputObserver.cxx [new file with mode: 0644]
samples/SampleWidgetsBase/CMakeLists.txt [new file with mode: 0644]
samples/SampleWidgetsBase/bbtkSampleWidgetsBase.cxx [new file with mode: 0644]

index 57d53a3de11f554ca5109f1fd07bcc3fb3d09a62..895eb29a4aabc0ec343c9d4155ccd0a882faa2f8 100644 (file)
@@ -10,14 +10,6 @@ IF(COMMAND cmake_policy AND ${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VER
   CMAKE_POLICY(SET CMP0005 NEW)
 ENDIF(COMMAND cmake_policy AND ${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4)
 
-#if(COMMAND cmake_policy)
-  # UNCOMMENT the 3 lines 'cmake_policy(...
-  # If you are using cmake 2.6 
-  # We can test it automatically, no JP ?
-  #cmake_policy(SET CMP0000 OLD)
-  #cmake_policy(SET CMP0005 NEW)
-  #cmake_policy(SET CMP0003 NEW)
- #   endif(COMMAND cmake_policy)
 
 #-----------------------------------------------------------------------------
 PROJECT(BBTK) 
@@ -39,3 +31,11 @@ SUBDIRS(kernel)
 SUBDIRS(packages)
 #-----------------------------------------------------------------------------
 
+#-----------------------------------------------------------------------------
+# The samples
+#OPTION(BUILD_BBTK_SAMPLES "Build bbtk samples" OFF)
+#IF(BUILD_BBTK_SAMPLES)
+#  SUBDIRS(samples)
+#ENDIF(BUILD_BBTK_SAMPLES)
+#-----------------------------------------------------------------------------
+
index 1ff72d10bdb6f49542d099ca5faf82c2fe784240..2e5716e3f9ba87e897ae7f3a69d7b10568af3743 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBox.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/12/09 13:45:13 $
-  Version:   $Revision: 1.35 $
+  Date:      $Date: 2008/12/10 09:33:18 $
+  Version:   $Revision: 1.36 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -444,16 +444,18 @@ namespace bbtk
 
 
   //=========================================================================
-  void BlackBox::AddChangeObserver(const std::string& output_name
+  void BlackBox::bbAddOutputObserver(const std::string& output
                                   OutputChangeCallbackType f)
   {
+    bbGetOutputConnector(output).AddChangeObserver(f);
   }  
   //=========================================================================
 
   //=========================================================================
-  void BlackBox::RemoveChangeObserver(const std::string& output_name, 
+  void BlackBox::bbRemoveOutputObserver(const std::string& output_name, 
                                      OutputChangeCallbackType f)
   {
+    bbtkError("BlackBox::RemoveChangeObserver NOT IMPLEMENTED");
   }
   //=========================================================================
 
@@ -617,10 +619,15 @@ namespace bbtk
     for ( i  = bbGetOutputConnectorMap().begin(); 
          i != bbGetOutputConnectorMap().end(); ++i) 
       {
-       if (i->second->GetStatus()==UPTODATE) 
-         {
+       //      std::cout << "Stat = "
+       //<<GetIOStatusString(i->second->GetStatus())
+       //                <<std::endl;
+       // LG : CANNOT SIGNAL ONLY WHEN UPTODATE 
+       // See bbtkSampleOutputObserver
+       //      if (i->second->GetStatus()==UPTODATE) 
+       //        {
            i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
-         }
+           //    }
       } 
 
     if (reaction) bbGlobalProcessExecutionList();
@@ -649,8 +656,8 @@ namespace bbtk
          bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
        }
 
-    if (i->second->GetStatus()==UPTODATE) 
-      {
+    //    if (i->second->GetStatus()==UPTODATE) 
+    //      {
        i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
        // Has to notify the output "BoxChange" also
        if (output != "BoxChange") 
@@ -662,7 +669,7 @@ namespace bbtk
              }
          }
        if (reaction) bbGlobalProcessExecutionList();
-      }
+       //      }
 
     bbtkDebugMessageDec("change",5,
                        "<= BlackBox::bbSignalOutputModification("
@@ -691,23 +698,22 @@ namespace bbtk
          {
            bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
          }
-       // Already OUTOFDATE : noting to do
-       if (i->second->GetStatus()==UPTODATE)
-         {
+
+       //      if (i->second->GetStatus()==UPTODATE)
+       //        {
            i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
            changed = true;
-         }
+           //  }
       }
     // Has to notify the output "BoxChange" also
     i = bbGetOutputConnectorMap().find("BoxChange");
     if ( changed && (i != bbGetOutputConnectorMap().end())) 
       {
-       // Already OUTOFDATE : noting to do
-       if (i->second->GetStatus()==UPTODATE) 
-         {
+       // if (i->second->GetStatus()==UPTODATE) 
+       //        {
            i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
            if (reaction) bbGlobalProcessExecutionList();
-         }
+           //  }
       }
 
     bbtkDebugMessageDec("change",5,
index 93c51ef9d6f19a3f3ba9135774edacd007747174..53e286dfb4dce69f924e733c48e37e019cfc208c 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBox.h,v $
   Language:  C++
-  Date:      $Date: 2008/12/09 13:45:13 $
-  Version:   $Revision: 1.19 $
+  Date:      $Date: 2008/12/10 09:33:18 $
+  Version:   $Revision: 1.20 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -62,6 +62,10 @@ namespace bbtk
   class Factory;
   class Connection;
   class BlackBoxOutputConnector;
+
+#define BBTK_MAKE_OUTPUT_OBSERVER(OBJECT,METHOD) \
+    boost::bind( METHOD, OBJECT, _1, _2, _3)
 
   class BBTK_EXPORT BlackBox : public Object
   {
@@ -121,17 +125,20 @@ namespace bbtk
     /// Adds the function f to the list of functions to call when 
     /// the output changes.
     /// f is of type ChangeCallbackType which is basically:
-    /// void (*ChangeCallbackType)(BlackBoxOutputConnector*)
+    /// void (*ChangeCallbackType)(bbtk::BlackBox::Pointer, 
+    ///                            const std::string&,
+    ///                            bbtk::IOStatus)
     /// To pass a member function 'f' of an instance 'c' of a class 'C' 
     /// as callback you have to 'bind' it, i.e. call:
-    /// AddChangeObserver ( "Out", boost::bind( &C::f , c, _1 ) );
-    void AddChangeObserver(const std::string& output_name, 
-                          OutputChangeCallbackType f); 
+    /// bbAddOutputObserver ( "Out", boost::bind( &C::f , c, _1, _2, _3 ) );
+    /// The convenience macro BBTK_BIND_OUTPUT_OBSERVER ( c, C::f ) does it for you 
+    void bbAddOutputObserver(const std::string& output_name, 
+                            OutputChangeCallbackType f); 
 
     /// Removes the function f from the list of functions to call when 
     /// the output changes (TO WRITE)
-    void RemoveChangeObserver(const std::string& output_name, 
-                             OutputChangeCallbackType f); 
+    void bbRemoveOutputObserver(const std::string& output_name, 
+                               OutputChangeCallbackType f); 
     
 
     /// Signals that the BlackBox outputs have been modified 
index c6813f250564ae15afce0b14bdcac3044b57e3d4..789cda41ffe91f058e491db6f424ccfc8351f9e6 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBoxOutputConnector.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/12/08 14:02:15 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2008/12/10 09:33:18 $
+  Version:   $Revision: 1.11 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -120,18 +120,21 @@ namespace bbtk
   void BlackBoxOutputConnector::SignalChange( BlackBox::Pointer box,
                                              const std::string& output )
   {
-         IOStatus s = OUTOFDATE; //mStatus;
-         //if (s==UPTODATE) s=MODIFIED;
-         
-         bbtkDebugMessage("change",2,
+    IOStatus s = OUTOFDATE; //mStatus;
+    //if (s==UPTODATE) s=MODIFIED;
+    
+    bbtkDebugMessage("change",2,
                     "==> BlackBoxOutputConnector::SignalChange("
                     <<box->bbGetFullName()<<",'"
                     <<output<<"','"<<GetIOStatusString(s)<<"') ["
                     <<this<<"]"
                     <<std::endl);
-
-   mChangeSignal(box,output,s);
-
+    
+    //    std::cout<<"BlackBoxOutputConnector::SignalChange("
+    //      <<box->bbGetFullName()<<",'"
+    //      <<output<<"')"<<std::endl;
+    mChangeSignal(box,output,s);
+    
     bbtkDebugMessage("change",2,
                     "<== BlackBoxOutputConnector::SignalChange("
                     <<box->bbGetFullName()<<",'"
@@ -198,6 +201,7 @@ namespace bbtk
   //======================================================================
   void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
   { 
+    //    std::cout << "BlackBoxOutputConnector::AddChangeObserver" << std::endl;
     mChangeSignal.connect(f); 
   }
   //======================================================================
index fdfb5eb0bb32ad6dd079d3b84609f55a1d462e8d..58d1c21404ddabb4b507b5d3aa9d6522c44af550 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBoxOutputConnector.h,v $
   Language:  C++
-  Date:      $Date: 2008/12/08 13:05:59 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2008/12/10 09:33:18 $
+  Version:   $Revision: 1.7 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -115,11 +115,6 @@ namespace bbtk
 
     /// Adds the function f to the list of functions to call when 
     /// the output changes.
-    /// f is of type ChangeCallbackType which is basically:
-    /// void (*ChangeCallbackType)(BlackBoxOutputConnector*)
-    /// To pass a member function 'f' of an instance 'c' of a class 'C' 
-    /// as callback you have to 'bind' it, i.e. call:
-    /// AddChangeObserver ( boost::bind( &C::f , c, _1 ) );
     void AddChangeObserver(OutputChangeCallbackType f); 
 
     /// Removes the function f from the list of functions to call when 
index 785c0df3fb0e798a6238988973c9737837b52670..3f409c0946a1f5f587e6beda770a49311077d672 100644 (file)
@@ -1 +1,18 @@
-SUBDIRS(cxx_sample1)
+#
+# Test CMake version
+#
+CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
+#MARK_AS_ADVANCED( FORCE CMAKE_BACKWARDS_COMPATIBILITY )
+
+# for CMake 2.6 corrected behaviour (see "cmake --help-policy CMP0003")
+IF(COMMAND cmake_policy AND ${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4)
+  CMAKE_POLICY(SET CMP0003 NEW)
+  CMAKE_POLICY(SET CMP0005 NEW)
+ENDIF(COMMAND cmake_policy AND ${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4)
+
+PROJECT(BBTK_SAMPLES)
+
+SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
+
+SUBDIRS(SampleWidgetsBase)
+SUBDIRS(SampleOutputObserver)
diff --git a/samples/SampleOutputObserver/CMakeLists.txt b/samples/SampleOutputObserver/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ca18517
--- /dev/null
@@ -0,0 +1,19 @@
+# Find the bbtk package wx 
+# The package is called 'bbwx'
+# It itself finds bbtk and automatically exports its dependency on it
+
+# Set 'FIND_PACKAGE_VERBOSE' to have information on the packages found
+SET(FIND_PACKAGE_VERBOSE 1)
+# Find 
+FIND_PACKAGE(bbwx)
+# Use if found
+IF(bbwx_FOUND)
+INCLUDE(${bbwx_USE_FILE})
+ENDIF(bbwx_FOUND)
+
+SET(SAMPLE bbtkSampleOutputObserver)
+
+# main 
+ADD_EXECUTABLE(${SAMPLE} ${SAMPLE})
+# Link against bbwx
+TARGET_LINK_LIBRARIES(${SAMPLE} ${bbwx_LIBRARIES})
diff --git a/samples/SampleOutputObserver/bbtkSampleOutputObserver.cxx b/samples/SampleOutputObserver/bbtkSampleOutputObserver.cxx
new file mode 100644 (file)
index 0000000..67c4075
--- /dev/null
@@ -0,0 +1,131 @@
+#include <bbwxSlider.h>
+#include <bbwxLayoutLine.h>
+
+//=========================================================================
+// Illustrates the Output Observer mechanism
+//=========================================================================
+
+//=========================================================================
+void CallbackFunction ( bbtk::BlackBox::Pointer p, 
+                       const std::string& o, 
+                       bbtk::IOStatus s)
+{
+  std::cout << "== Callback function called with p="<<p->bbGetName()
+           <<" o="<<o<<" s="<<bbtk::GetIOStatusString(s)<<std::endl;
+  bbwx::Slider::Pointer slider = boost::dynamic_pointer_cast<bbwx::Slider>(p);
+  if (slider)
+    {
+      std::cout << "* Current slider value = "<<slider->bbGetOutputOut()
+               <<std::endl;
+    }
+}
+//=========================================================================
+
+//=========================================================================
+void SliderCallback()
+{
+  std::cout << "============== Callback function called when slider is released" 
+           << std::endl;
+   try
+    {
+      bbwx::Slider::Pointer slider = bbwx::Slider::New("slider");
+      slider->bbSetInputWinDialog(true);  // mandatory
+      slider->bbAddOutputObserver( "Out", &CallbackFunction );
+      slider->bbExecute();
+    }
+  catch (bbtk::Exception e)
+    {
+      e.Print();
+    } 
+}
+//=========================================================================
+
+
+//=========================================================================
+class ClassWithTwoSliders
+{
+public:
+  // Ctor
+  ClassWithTwoSliders();
+  // Callback
+  void OnSlider( bbtk::BlackBox::Pointer p, 
+                const std::string& o, 
+                bbtk::IOStatus s );
+private:
+  bbwx::Slider::Pointer mSlider1;
+  bbwx::Slider::Pointer mSlider2;
+bbwx::LayoutLine::Pointer mLayout;
+};
+//=========================================================================
+
+//=========================================================================
+ClassWithTwoSliders::ClassWithTwoSliders()
+{
+  std::cout << "============== Callback member called when first slider is released or second slider moves" 
+           << std::endl;
+  try
+    {
+      mSlider1 = bbwx::Slider::New("slider1");
+      mSlider1->bbAddOutputObserver("Out", 
+                                   BBTK_MAKE_OUTPUT_OBSERVER
+                                   (this,
+                                    &ClassWithTwoSliders::OnSlider ));
+      
+      mSlider2 = bbwx::Slider::New("slider2");
+      mSlider2->bbSetInputReactiveOnTrack(true);
+      mSlider2->bbAddOutputObserver("Out", 
+                                   BBTK_MAKE_OUTPUT_OBSERVER
+                                   (this,
+                                    &ClassWithTwoSliders::OnSlider ));
+      
+      mLayout = bbwx::LayoutLine::New("layout");
+      mLayout->bbSetInputWinDialog(true);  // mandatory
+      
+      bbtk::Connection::Pointer c1 = bbtk::Connection::New( mSlider1, 
+                                                           "Widget", 
+                                                           mLayout, 
+                                                           "Widget1");
+      bbtk::Connection::Pointer c2 = bbtk::Connection::New( mSlider2, 
+                                                           "Widget", 
+                                                           mLayout, 
+                                                           "Widget2");
+      
+      mLayout->bbExecute();
+    }
+  catch (bbtk::Exception e)
+    {
+      e.Print();
+    }   
+}
+//=========================================================================
+
+//=========================================================================
+void ClassWithTwoSliders::OnSlider( bbtk::BlackBox::Pointer p, 
+                                   const std::string& o, 
+                                   bbtk::IOStatus s )
+{
+  std::cout << "== 'OnSlider' called with p="<<p->bbGetName()
+           <<" o="<<o<<" s="<<bbtk::GetIOStatusString(s)<<std::endl;
+  
+  if ((p==mSlider1) && (o=="Out"))
+    {
+      std::cout << "* First slider released. New value = "
+               <<mSlider1->bbGetOutputOut()<<std::endl;
+    }                                                 
+  else if ((p==mSlider2) && (o=="Out"))
+    {
+      std::cout << "* Second slider moved. New value = "
+               <<mSlider2->bbGetOutputOut()<<std::endl;
+    }
+}
+//=========================================================================
+
+//=========================================================================
+int main(int argv, char* argc[])
+{
+ // To track all ...
+  //  bbtk::MessageManager::SetMessageLevel("all",9);
+  SliderCallback();
+  ClassWithTwoSliders C;
+}
+//=========================================================================
diff --git a/samples/SampleWidgetsBase/CMakeLists.txt b/samples/SampleWidgetsBase/CMakeLists.txt
new file mode 100644 (file)
index 0000000..84abf5e
--- /dev/null
@@ -0,0 +1,19 @@
+# Find the bbtk package wx 
+# The package is called 'bbwx'
+# It itself finds bbtk and automatically exports its dependency on it
+
+# Set 'FIND_PACKAGE_VERBOSE' to have information on the packages found
+SET(FIND_PACKAGE_VERBOSE 1)
+# Find 
+FIND_PACKAGE(bbwx)
+# Use if found
+IF(bbwx_FOUND)
+INCLUDE(${bbwx_USE_FILE})
+ENDIF(bbwx_FOUND)
+
+SET(SAMPLE bbtkSampleWidgetsBase)
+
+# main 
+ADD_EXECUTABLE(${SAMPLE} ${SAMPLE})
+# Link against bbwx
+TARGET_LINK_LIBRARIES(${SAMPLE} ${bbwx_LIBRARIES})
diff --git a/samples/SampleWidgetsBase/bbtkSampleWidgetsBase.cxx b/samples/SampleWidgetsBase/bbtkSampleWidgetsBase.cxx
new file mode 100644 (file)
index 0000000..481c828
--- /dev/null
@@ -0,0 +1,105 @@
+#include <bbwxSlider.h>
+#include <bbwxOutputText.h>
+
+//=========================================================================
+// Different examples of using black boxes in C++
+// Here we do not use wxWidgets however WxBlackBox es work in **Dialog** mode 
+//=========================================================================
+
+//=========================================================================
+void SimpleSliderDialog()
+{
+  std::cout << "============== Simple Slider dialog" 
+           << std::endl;
+   try
+    {
+      bbwx::Slider::Pointer slider = bbwx::Slider::New("slider");
+      //      slider->bbGetHelp();
+      slider->bbSetInputWinDialog(true);  // mandatory
+      slider->bbExecute();
+      std::cout << "Slider Output = "<< slider->bbGetOutputOut() << std::endl;
+    }
+  catch (bbtk::Exception e)
+    {
+      e.Print();
+    } 
+}
+//=========================================================================
+
+//=========================================================================
+void SliderOutputTextWithoutFactory()
+{
+  std::cout << "============== Slider->OutputText without Factory" 
+           << std::endl;
+  try
+    {
+      bbwx::Slider::Pointer slider = bbwx::Slider::New("slider");
+      bbwx::OutputText::Pointer text = bbwx::OutputText::New("text");
+      bbtk::Connection::Pointer s2t = bbtk::Connection::New(slider,"Out",
+                                                           text,"In");
+      text->bbExecute();
+    }
+  catch (bbtk::Exception e)
+    {
+      bbtk::MessageManager::SetMessageLevel("Error",1);
+      e.Print();
+    }
+}
+//=========================================================================
+
+
+//=========================================================================
+#include <bbtkFactory.h>
+#include <bbwxLayoutLine.h>
+void SliderOutputTextWithFactory()
+{
+  std::cout << "============== Slider->OutputText **WITH** Factory" 
+           << std::endl;
+  try
+    {
+      bbtk::Factory::Pointer factory = bbtk::Factory::New();
+  
+      factory->LoadPackage("std");
+
+      bbwx::Slider::Pointer     slider   = bbwx::Slider::New("slider");
+      bbwx::OutputText::Pointer text     = bbwx::OutputText::New("text");
+      bbtk::Connection::Pointer s2t      = bbtk::Connection::New(slider,"Out",
+                                                           text,"In",
+                                                           factory);
+      bbwx::LayoutLine::Pointer layout   = bbwx::LayoutLine::New("layout");
+      bbtk::Connection::Pointer c1       = bbtk::Connection::New(slider,"Widget",
+                                                          layout,"Widget1");
+      bbtk::Connection::Pointer c2       = bbtk::Connection::New(text,"Widget",
+                                                          layout,"Widget2");
+                                                          
+      bbtk::Connection::Pointer c3       = bbtk::Connection::New(slider,"BoxChange",
+                                                          text,"BoxExecute");
+      // OR 
+      //      text->bbSetInputBoxProcessMode("Reactive");
+      
+      layout->bbSetInputWinDialog(true);
+      layout->bbExecute();
+    }
+  catch (bbtk::Exception e)
+    {
+      bbtk::MessageManager::SetMessageLevel("Error",1);
+      e.Print();
+    }
+}
+//=========================================================================
+
+//=========================================================================
+int main(int argv, char* argc[])
+{
+  // To track all ...
+  //  bbtk::MessageManager::SetMessageLevel("all",9);
+  
+  SimpleSliderDialog();
+  SliderOutputTextWithoutFactory();
+  SliderOutputTextWithFactory();
+
+  // To get the list of bbtk object still allocated after main ends
+  // bbtk::StaticInitTime::PrintObjectListInfo = true;
+  // bbtk::MessageManager::SetMessageLevel("object",1);
+}
+//=========================================================================