2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 #include <bbwxSlider.h>
29 #include <bbwxLayoutLine.h>
31 //=========================================================================
32 // Illustrates the Output Observer mechanism
33 //=========================================================================
35 //=========================================================================
36 // FIRST EXAMPLE USING A FUNCTION AS CALLBACK
37 void CallbackFunction ( bbtk::BlackBox::Pointer p, // The black box which changed
38 const std::string& o, // The output which changed
39 bbtk::IOStatus s) // The new status of the output
41 std::cout << "== Callback function called with p="<<p->bbGetName()
42 <<" o="<<o<<" s="<<s/*bbtk::GetIOStatusString(s)*/<<std::endl;
44 // Cast the black box pointer into Slider pointer
45 bbwx::Slider::Pointer slider = boost::dynamic_pointer_cast<bbwx::Slider>(p);
48 std::cout << "* Current slider value = "<<slider->bbGetOutputOut()
52 //=========================================================================
54 //=========================================================================
57 std::cout << "============== Callback function called when slider is released"
61 bbwx::Slider::Pointer slider = bbwx::Slider::New("slider");
62 slider->bbSetInputWinDialog(true); // mandatory
64 slider->bbAddOutputObserver( "Out", &CallbackFunction );
67 catch (bbtk::Exception e)
72 //=========================================================================
75 //=========================================================================
76 // SECOND EXAMPLE : MEMBER METHOD CALLED WHEN SLIDER IS RELEASED
77 class ClassWithTwoSliders
81 ClassWithTwoSliders();
83 void OnSlider( bbtk::BlackBox::Pointer p,
87 bbwx::Slider::Pointer mSlider1;
88 bbwx::Slider::Pointer mSlider2;
89 bbwx::LayoutLine::Pointer mLayout;
91 //=========================================================================
93 //=========================================================================
94 ClassWithTwoSliders::ClassWithTwoSliders()
96 std::cout << "============== Callback member called when first slider is released or second slider moves"
100 mSlider1 = bbwx::Slider::New("slider1");
101 // Add the observer method
102 // As it is not a FREEHAND function we must use the macro
103 // BBTK_MAKE_OUTPUT_OBSERVER which takes the object and the method to call
104 mSlider1->bbAddOutputObserver("Out",
105 BBTK_MAKE_OUTPUT_OBSERVER
107 &ClassWithTwoSliders::OnSlider ));
109 mSlider2 = bbwx::Slider::New("slider2");
110 mSlider2->bbSetInputReactiveOnTrack(true);
111 mSlider2->bbAddOutputObserver("Out",
112 BBTK_MAKE_OUTPUT_OBSERVER
114 &ClassWithTwoSliders::OnSlider ));
116 mLayout = bbwx::LayoutLine::New("layout");
117 mLayout->bbSetInputWinDialog(true); // mandatory
119 bbtk::Connection::Pointer c1 = bbtk::Connection::New( mSlider1,
123 bbtk::Connection::Pointer c2 = bbtk::Connection::New( mSlider2,
128 mLayout->bbExecute();
130 catch (bbtk::Exception e)
135 //=========================================================================
137 //=========================================================================
138 void ClassWithTwoSliders::OnSlider( bbtk::BlackBox::Pointer p,
139 const std::string& o,
142 std::cout << "== 'OnSlider' called with p="<<p->bbGetName()
143 <<" o="<<o<<" s="<<s/*bbtk::GetIOStatusString(s)*/<<std::endl;
145 if ((p==mSlider1) && (o=="Out"))
147 std::cout << "* First slider released. New value = "
148 <<mSlider1->bbGetOutputOut()<<std::endl;
150 else if ((p==mSlider2) && (o=="Out"))
152 std::cout << "* Second slider moved. New value = "
153 <<mSlider2->bbGetOutputOut()<<std::endl;
156 //=========================================================================
158 //=========================================================================
159 int main(int argv, char* argc[])
162 bbtk::MessageManager::SetMessageLevel("all",9);
164 ClassWithTwoSliders C;
166 //=========================================================================