From e746553dde41260204aae07b809f484544de10b9 Mon Sep 17 00:00:00 2001 From: guigues Date: Wed, 10 Dec 2008 09:33:16 +0000 Subject: [PATCH] *** empty log message *** --- CMakeLists.txt | 16 +-- kernel/src/bbtkBlackBox.cxx | 42 +++--- kernel/src/bbtkBlackBox.h | 23 +-- kernel/src/bbtkBlackBoxOutputConnector.cxx | 22 +-- kernel/src/bbtkBlackBoxOutputConnector.h | 9 +- samples/CMakeLists.txt | 19 ++- samples/SampleOutputObserver/CMakeLists.txt | 19 +++ .../bbtkSampleOutputObserver.cxx | 131 ++++++++++++++++++ samples/SampleWidgetsBase/CMakeLists.txt | 19 +++ .../bbtkSampleWidgetsBase.cxx | 105 ++++++++++++++ 10 files changed, 354 insertions(+), 51 deletions(-) create mode 100644 samples/SampleOutputObserver/CMakeLists.txt create mode 100644 samples/SampleOutputObserver/bbtkSampleOutputObserver.cxx create mode 100644 samples/SampleWidgetsBase/CMakeLists.txt create mode 100644 samples/SampleWidgetsBase/bbtkSampleWidgetsBase.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 57d53a3..895eb29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) +#----------------------------------------------------------------------------- + diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index 1ff72d1..2e5716e 100644 --- a/kernel/src/bbtkBlackBox.cxx +++ b/kernel/src/bbtkBlackBox.cxx @@ -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 = " + //<second->GetStatus()) + // <second->GetStatus()==UPTODATE) + // { i->second->SignalChange(GetThisPointer(),i->first); - } + // } } if (reaction) bbGlobalProcessExecutionList(); @@ -649,8 +656,8 @@ namespace bbtk bbtkError("BlackBox["<second->GetStatus()==UPTODATE) - { + // if (i->second->GetStatus()==UPTODATE) + // { i->second->SignalChange(GetThisPointer(),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["<second->GetStatus()==UPTODATE) - { + + // if (i->second->GetStatus()==UPTODATE) + // { i->second->SignalChange(GetThisPointer(),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(),i->first); if (reaction) bbGlobalProcessExecutionList(); - } + // } } bbtkDebugMessageDec("change",5, diff --git a/kernel/src/bbtkBlackBox.h b/kernel/src/bbtkBlackBox.h index 93c51ef..53e286d 100644 --- a/kernel/src/bbtkBlackBox.h +++ b/kernel/src/bbtkBlackBox.h @@ -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 diff --git a/kernel/src/bbtkBlackBoxOutputConnector.cxx b/kernel/src/bbtkBlackBoxOutputConnector.cxx index c6813f2..789cda4 100644 --- a/kernel/src/bbtkBlackBoxOutputConnector.cxx +++ b/kernel/src/bbtkBlackBoxOutputConnector.cxx @@ -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(" <bbGetFullName()<<",'" <bbGetFullName()<<",'" + // <bbGetFullName()<<",'" @@ -198,6 +201,7 @@ namespace bbtk //====================================================================== void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f) { + // std::cout << "BlackBoxOutputConnector::AddChangeObserver" << std::endl; mChangeSignal.connect(f); } //====================================================================== diff --git a/kernel/src/bbtkBlackBoxOutputConnector.h b/kernel/src/bbtkBlackBoxOutputConnector.h index fdfb5eb..58d1c21 100644 --- a/kernel/src/bbtkBlackBoxOutputConnector.h +++ b/kernel/src/bbtkBlackBoxOutputConnector.h @@ -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 diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 785c0df..3f409c0 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -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 index 0000000..ca18517 --- /dev/null +++ b/samples/SampleOutputObserver/CMakeLists.txt @@ -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 index 0000000..67c4075 --- /dev/null +++ b/samples/SampleOutputObserver/bbtkSampleOutputObserver.cxx @@ -0,0 +1,131 @@ +#include +#include + +//========================================================================= +// 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="<bbGetName() + <<" o="<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="<bbGetName() + <<" o="< +#include + +//========================================================================= +// 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 +#include +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); +} +//========================================================================= -- 2.45.1