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)
SUBDIRS(packages)
#-----------------------------------------------------------------------------
+#-----------------------------------------------------------------------------
+# The samples
+#OPTION(BUILD_BBTK_SAMPLES "Build bbtk samples" OFF)
+#IF(BUILD_BBTK_SAMPLES)
+# SUBDIRS(samples)
+#ENDIF(BUILD_BBTK_SAMPLES)
+#-----------------------------------------------------------------------------
+
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 $
=========================================================================*/
/* ---------------------------------------------------------------------
//=========================================================================
- 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");
}
//=========================================================================
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();
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")
}
}
if (reaction) bbGlobalProcessExecutionList();
- }
+ // }
bbtkDebugMessageDec("change",5,
"<= BlackBox::bbSignalOutputModification("
{
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,
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 $
=========================================================================*/
/* ---------------------------------------------------------------------
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
{
/// 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
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 $
=========================================================================*/
/* ---------------------------------------------------------------------
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()<<",'"
//======================================================================
void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
{
+ // std::cout << "BlackBoxOutputConnector::AddChangeObserver" << std::endl;
mChangeSignal.connect(f);
}
//======================================================================
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 $
=========================================================================*/
/* ---------------------------------------------------------------------
/// 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
-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)
--- /dev/null
+# 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})
--- /dev/null
+#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;
+}
+//=========================================================================
--- /dev/null
+# 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})
--- /dev/null
+#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);
+}
+//=========================================================================