]> Creatis software - bbtk.git/blob - kernel/src/bbtkKWBlackBox.h
KWWidgets support
[bbtk.git] / kernel / src / bbtkKWBlackBox.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkKWBlackBox.h,v $
4   Language:  C++
5   Date:      $Date: 2008/12/02 08:38:08 $
6   Version:   $Revision: 1.2 $
7 ========================================================================*/
8
9
10 /* ---------------------------------------------------------------------
11
12 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
13 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 *
15 *  This software is governed by the CeCILL-B license under French law and 
16 *  abiding by the rules of distribution of free software. You can  use, 
17 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
18 *  license as circulated by CEA, CNRS and INRIA at the following URL 
19 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
20 *  or in the file LICENSE.txt.
21 *
22 *  As a counterpart to the access to the source code and  rights to copy,
23 *  modify and redistribute granted by the license, users are provided only
24 *  with a limited warranty  and the software's author,  the holder of the
25 *  economic rights,  and the successive licensors  have only  limited
26 *  liability. 
27 *
28 *  The fact that you are presently reading this means that you have had
29 *  knowledge of the CeCILL-B license and that you accept its terms.
30 * ------------------------------------------------------------------------ */                                                                         
31 /**
32  * \brief Short description in one line
33  * 
34  * Long description which 
35  * can span multiple lines
36  */
37 /**
38  * \file 
39  * \brief 
40  */
41 /**
42  * \class bbtk::
43  * \brief 
44  */
45 #ifndef __bbtkKWBlackBox_h_INCLUDED__
46 #define __bbtkKWBlackBox_h_INCLUDED__
47
48
49 #ifdef USE_KWWIDGETS
50
51 #include "bbtkAtomicBlackBox.h"
52
53
54 #include "bbtkKW.h"
55
56
57   //==================================================================
58   // Forward declaration of the class of window associated to a KWBlackBox
59   class vtkKWBlackBoxWindow;
60   class vtkKWBlackBoxDialog;
61   //==================================================================
62
63
64 namespace bbtk
65 {
66
67
68
69
70   //==================================================================
71   // Forward declaration of the widget event handler class
72   //  class KWBlackBoxWidgetEventHandler;
73   //==================================================================
74
75
76   //==================================================================
77   /// Widget black boxes
78   class BBTK_EXPORT KWBlackBox : public bbtk::AtomicBlackBox  
79   { 
80     BBTK_BLACK_BOX_INTERFACE(KWBlackBox,bbtk::AtomicBlackBox);
81     BBTK_DECLARE_INPUT(WinTitle,std::string);
82     BBTK_DECLARE_INPUT(WinWidth,int);
83     BBTK_DECLARE_INPUT(WinHeight,int);
84     BBTK_DECLARE_INPUT(WinDialog,bool);
85     BBTK_DECLARE_INPUT(WinHide,Void);
86     BBTK_DECLARE_INPUT(WinClose,Void);
87     BBTK_DECLARE_OUTPUT(Widget, vtkKWWidget*);
88
89   public:
90     /// Main processing method of the box. Overloaded to handle windows inclusion : if the output Widget is connected then the execution is transfered to the box to which it is connected (as the container window must be created and displayed - this box will be executed by the normal pipeline recursion mechanism)
91     virtual void bbExecute(bool force = false);
92
93
94     typedef vtkKWBlackBoxDialog Window;
95     
96     /// Returns the **OWN** window associated to the box
97     /// If 0 returned = no window
98     Window* bbGetWindow() { return bbmWindow; }
99
100     /// Returns the window containing the widget associated to the box
101     /// Which can be the own window of **ANOTHER** box in case of 
102     /// a hierarchy of widgets.
103     /// More precisely :
104     /// If bbGetWindow() != 0 then returns bbGetWindow()
105     /// Else if the output 'Widget' is connected 
106     ///  then returns bbGetContainingWindow() of the box connected to 'Widget'
107     /// Else returns 0;
108     Window* bbGetContainingWindow();
109
110     /// Returns the parent wxWindow that must be used to create the widget 
111           //
112           // LG 24/11/08 : New widget pipeline
113           //    wxWindow* bbGetKWParent();
114
115     /// Returns true iff the 'containing window' exists and is shown 
116     /// (see bbGetContainingWindow).
117     bool bbIsShown();
118
119     //==================================================================    
120     /// User callback invoked when the containing window is shown
121     virtual void bbUserOnShow() {}
122     //==================================================================    
123  
124     //==================================================================    
125     /// User callback invoked when the containing window is hidden
126     virtual void bbUserOnHide() {}
127     //==================================================================    
128
129     // LG 24/11/08 : New widget pipeline
130     //    void bbCreateWidgetAndEventHandler(vtkKWWidget* parent); 
131   /// Sets the window
132     inline void bbSetWindow(Window* w) { bbmWindow=w; }
133
134           
135   protected:
136     
137   
138     //==================================================================
139     /// User callback called in the box contructor
140     virtual void bbUserConstructor();
141     /// User callback called in the box copy constructor
142     virtual void bbUserCopyConstructor(bbtk::BlackBox::Pointer);
143     /// User callback called in the box destructor
144     virtual void bbUserDestructor();
145     //==================================================================    
146
147     //==================================================================    
148     /// User callback for creating the widget associated to the box
149     /// ** Must be defined **
150     // LG 24/11/08 : New widget pipeline
151     virtual void bbUserCreateWidget(vtkKWWidget* parent) 
152     {
153       bbtkError(bbGetTypeName()<<" is a KWBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
154     }
155     //==================================================================    
156
157
158     vtkKWWidget* bbCreateWidgetOfInput(const std::string& in, 
159                                        vtkKWWidget* parent);
160
161
162     //==================================================================
163     /// Main processing method of the box.
164     virtual IOStatus bbBackwardUpdate( Connection::Pointer caller );
165     //==================================================================
166
167
168
169     //==================================================================
170     /// Overloaded processing method for KWBlackBoxes
171     virtual void bbProcess();
172     //==================================================================
173
174     //==================================================================
175     /// If necessary creates the KWBlackBoxWindow associated to the box
176     /// and shows it 
177     /// (does nothing if the box output 'Widget' is connected which 
178     /// means that the box does not have its own window but is contained 
179     /// into another window)
180     void bbShowWindow();
181     /// Hides the KWBlackBoxWindow associated to the box (if exists)
182     void bbHideWindow();
183     /// Closes (destroys) the KWBlackBoxWindow associated to the box (if exists)
184     void bbCloseWindow();
185     //==================================================================
186
187   private:
188     /// friendship
189     friend class vtkKWBlackBoxWindow;
190     //    friend class KWBlackBoxWidgetEventHandler;
191
192   
193     /*
194     /// Sets the Widget Event Handler
195     inline void bbSetWidgetEventHandler(KWBlackBoxWidgetEventHandler* w) 
196     { bbmWidgetEventHandler = w; }
197     /// Gets the Widget Event Handler
198     inline KWBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
199     { return bbmWidgetEventHandler; }
200     */
201
202     /// The KWBlackBoxWindow associated to the box
203     Window* bbmWindow;
204     /// The KWBlackBoxWidgetEventHandler associated to the box
205     //    KWBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
206
207
208     void bbInitAttributes();
209
210   protected :
211
212
213     /// For Forward update mechanism when execution is called 
214     /// on a contained window
215     /// Is set to true before transfering update to parent 
216     /// in order to not re-transfer a second time...
217     bool bbmUpdateTransferedToParent;
218
219     bool bbGetUpdateTransferedToParent() const { return bbmUpdateTransferedToParent; }
220     void bbSetUpdateTransferedToParent(bool b) 
221     { bbmUpdateTransferedToParent = b; }
222
223   };
224   //=================================================================
225  
226
227   //======================================================================
228   /// Defines the bbUserCreateWidget method
229 #define BBTK_CREATE_KWWIDGET(CALLBACK)                                  \
230   public:                                                               \
231   inline void bbUserCreateWidget(vtkKWWidget* parent)                   \
232   {                                                                     \
233     bbtkDebugMessageInc("kw",1,"**> Creating widget for ["              \
234                         <<bbGetFullName()<<"]"<<std::endl);             \
235     CALLBACK(parent);                                                   \
236     bbtkDebugMessageInc("kw",1,"<** Creating widget for ["              \
237                         <<bbGetFullName()<<"]"<<std::endl);             \
238   }
239   
240   //======================================================================
241
242   //======================================================================
243   /// Defines the bbUserOnShow method
244 #define BBTK_ON_SHOW_WIDGET(CALLBACK)                                   \
245   public:                                                               \
246   inline void bbUserOnShow()                                    \
247   {                                                                     \
248     bbtkDebugMessageInc("wx",1,"**> Showing ["          \
249                         <<bbGetFullName()<<"]"<<std::endl);             \
250     CALLBACK();                                                         \
251     bbtkDebugMessageInc("wx",1,"<** Showing ["          \
252                         <<bbGetFullName()<<"]"<<std::endl);             \
253   }
254   
255   //======================================================================
256
257   //=================================================================
258   // KWBlackBoxDescriptor declaration
259   BBTK_BEGIN_DESCRIBE_BLACK_BOX(KWBlackBox,bbtk::AtomicBlackBox);
260   BBTK_NAME("KWBlackBox");
261   // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
262   BBTK_CATEGORY("widget");
263   BBTK_INPUT(KWBlackBox,WinTitle,
264              "Title of the window (*)",
265              std::string,"");
266   BBTK_INPUT(KWBlackBox,WinWidth,
267              "Width of the window (* : only used if the widget is not connected to a Layout box)",int,"");
268   BBTK_INPUT(KWBlackBox,WinHeight,
269              "Height of the window (*)",int,"");
270   BBTK_INPUT(KWBlackBox,WinDialog,
271              "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool,"");
272   BBTK_INPUT(KWBlackBox,WinHide,
273              "Any signal received hides the window (*)",Void,"signal");
274   BBTK_INPUT(KWBlackBox,WinClose,
275              "Any signal received closes the window (*)",Void,"signal");
276   BBTK_OUTPUT(KWBlackBox,Widget,"Output widget",vtkKWWidget*,"");
277   BBTK_END_DESCRIBE_BLACK_BOX(KWBlackBox);
278   //=================================================================
279
280
281
282
283
284
285
286
287   /*
288   //=================================================================
289   // Handles the destroy events of a widget associated to a KWBlackBox 
290   // in order to signal the widget death to its associated box
291   class BBTK_EXPORT KWBlackBoxWidgetEventHandler : public wxEvtHandler
292   {
293   public:
294     /// Ctor with the box and widget 
295     KWBlackBoxWidgetEventHandler( KWBlackBox::Pointer box, wxWindow *widget );
296     /// Dtor
297     ~KWBlackBoxWidgetEventHandler();
298     /// Returns true iff is the handler for that window  
299     bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
300     // wxWindow* GetKWWindow() { return mWindow; }
301     /// Method processing the destroy event of the widget
302     void OnWindowDestroy(wxWindowDestroyEvent&);
303     //
304     //bool IsDead() { return mDead; }
305
306   private:
307     KWBlackBox::WeakPointer mBox;
308     wxWindow* mWindow;
309     //bool mDead;
310   };  
311   //=================================================================
312   */
313
314
315 } //namespace bbtk
316
317
318
319 #endif  // USE_KWWIDGETS
320 #endif  //__bbtkKWBlackBox_h__