1 /*=========================================================================
3 Module: $RCSfile: bbtkKWBlackBox.h,v $
5 Date: $Date: 2008/12/08 12:54:26 $
6 Version: $Revision: 1.4 $
7 ========================================================================*/
10 /* ---------------------------------------------------------------------
12 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
13 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
32 * \brief Short description in one line
34 * Long description which
35 * can span multiple lines
45 #ifndef __bbtkKWBlackBox_h_INCLUDED__
46 #define __bbtkKWBlackBox_h_INCLUDED__
51 #include "bbtkAtomicBlackBox.h"
57 //==================================================================
58 // Forward declaration of the class of window associated to a KWBlackBox
59 class vtkKWBlackBoxWindow;
60 class vtkKWBlackBoxDialog;
62 //==================================================================
71 //==================================================================
72 // Forward declaration of the widget event handler class
73 // class KWBlackBoxWidgetEventHandler;
74 //==================================================================
77 //==================================================================
78 /// Widget black boxes
79 class BBTK_EXPORT KWBlackBox : public bbtk::AtomicBlackBox
81 BBTK_BLACK_BOX_INTERFACE(KWBlackBox,bbtk::AtomicBlackBox);
82 BBTK_DECLARE_INPUT(WinTitle,std::string);
83 BBTK_DECLARE_INPUT(WinWidth,int);
84 BBTK_DECLARE_INPUT(WinHeight,int);
85 BBTK_DECLARE_INPUT(WinDialog,bool);
86 BBTK_DECLARE_INPUT(WinHide,Void);
87 BBTK_DECLARE_INPUT(WinClose,Void);
88 BBTK_DECLARE_OUTPUT(Widget, vtkKWWidget*);
91 /// 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)
92 virtual void bbExecute(bool force = false);
95 typedef vtkKWBlackBoxDialog Window;
97 /// Returns the **OWN** window associated to the box
98 /// If 0 returned = no window
99 Window* bbGetWindow() { return bbmWindow; }
101 /// Returns the window containing the widget associated to the box
102 /// Which can be the own window of **ANOTHER** box in case of
103 /// a hierarchy of widgets.
105 /// If bbGetWindow() != 0 then returns bbGetWindow()
106 /// Else if the output 'Widget' is connected
107 /// then returns bbGetContainingWindow() of the box connected to 'Widget'
109 Window* bbGetContainingWindow();
111 /// Returns the parent wxWindow that must be used to create the widget
113 // LG 24/11/08 : New widget pipeline
114 // wxWindow* bbGetKWParent();
116 /// Returns true iff the 'containing window' exists and is shown
117 /// (see bbGetContainingWindow).
120 //==================================================================
121 /// User callback invoked when the containing window is shown
122 virtual void bbUserOnShow() {}
123 //==================================================================
125 //==================================================================
126 /// User callback invoked when the containing window is hidden
127 virtual void bbUserOnHide() {}
128 //==================================================================
130 // LG 24/11/08 : New widget pipeline
131 // void bbCreateWidgetAndEventHandler(vtkKWWidget* parent);
133 inline void bbSetWindow(Window* w) { bbmWindow=w; }
139 //==================================================================
140 /// User callback called in the box contructor
141 virtual void bbUserConstructor();
142 /// User callback called in the box copy constructor
143 virtual void bbUserCopyConstructor(bbtk::BlackBox::Pointer);
144 /// User callback called in the box destructor
145 virtual void bbUserDestructor();
146 //==================================================================
148 //==================================================================
149 /// User callback for creating the widget associated to the box
150 /// ** Must be defined **
151 // LG 24/11/08 : New widget pipeline
152 virtual void bbUserCreateWidget(vtkKWFrame* parent)
154 bbtkError(bbGetTypeName()<<" is a KWBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
156 //==================================================================
159 vtkKWWidget* bbCreateWidgetOfInput(const std::string& in,
163 //==================================================================
164 /// Main processing method of the box.
165 // virtual void bbBackwardUpdate( Connection::Pointer caller );
166 //==================================================================
170 //==================================================================
171 /// Overloaded processing method for KWBlackBoxes
172 virtual void bbProcess();
173 //==================================================================
175 //==================================================================
176 /// If necessary creates the KWBlackBoxWindow associated to the box
178 /// (does nothing if the box output 'Widget' is connected which
179 /// means that the box does not have its own window but is contained
180 /// into another window)
182 /// Hides the KWBlackBoxWindow associated to the box (if exists)
184 /// Closes (destroys) the KWBlackBoxWindow associated to the box (if exists)
185 void bbCloseWindow();
186 //==================================================================
190 friend class vtkKWBlackBoxWindow;
191 // friend class KWBlackBoxWidgetEventHandler;
195 /// Sets the Widget Event Handler
196 inline void bbSetWidgetEventHandler(KWBlackBoxWidgetEventHandler* w)
197 { bbmWidgetEventHandler = w; }
198 /// Gets the Widget Event Handler
199 inline KWBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
200 { return bbmWidgetEventHandler; }
203 /// The KWBlackBoxWindow associated to the box
205 /// The KWBlackBoxWidgetEventHandler associated to the box
206 // KWBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
209 void bbInitAttributes();
214 /// For Forward update mechanism when execution is called
215 /// on a contained window
216 /// Is set to true before transfering update to parent
217 /// in order to not re-transfer a second time...
218 bool bbmUpdateTransferedToParent;
220 bool bbGetUpdateTransferedToParent() const { return bbmUpdateTransferedToParent; }
221 void bbSetUpdateTransferedToParent(bool b)
222 { bbmUpdateTransferedToParent = b; }
225 //=================================================================
228 //======================================================================
229 /// Defines the bbUserCreateWidget method
230 #define BBTK_CREATE_KWWIDGET(CALLBACK) \
232 inline void bbUserCreateWidget(vtkKWFrame* parent) \
234 bbtkDebugMessageInc("kw",1,"**> Creating widget for [" \
235 <<bbGetFullName()<<"]"<<std::endl); \
237 bbtkDebugMessageInc("kw",1,"<** Creating widget for [" \
238 <<bbGetFullName()<<"]"<<std::endl); \
241 //======================================================================
243 //======================================================================
244 /// Defines the bbUserOnShow method
245 #define BBTK_ON_SHOW_WIDGET(CALLBACK) \
247 inline void bbUserOnShow() \
249 bbtkDebugMessageInc("wx",1,"**> Showing [" \
250 <<bbGetFullName()<<"]"<<std::endl); \
252 bbtkDebugMessageInc("wx",1,"<** Showing [" \
253 <<bbGetFullName()<<"]"<<std::endl); \
256 //======================================================================
258 //=================================================================
259 // KWBlackBoxDescriptor declaration
260 BBTK_BEGIN_DESCRIBE_BLACK_BOX(KWBlackBox,bbtk::AtomicBlackBox);
261 BBTK_NAME("KWBlackBox");
262 // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
263 BBTK_CATEGORY("widget");
264 BBTK_INPUT(KWBlackBox,WinTitle,
265 "Title of the window (*)",
267 BBTK_INPUT(KWBlackBox,WinWidth,
268 "Width of the window (* : only used if the widget is not connected to a Layout box)",int,"");
269 BBTK_INPUT(KWBlackBox,WinHeight,
270 "Height of the window (*)",int,"");
271 BBTK_INPUT(KWBlackBox,WinDialog,
272 "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool,"");
273 BBTK_INPUT(KWBlackBox,WinHide,
274 "Any signal received hides the window (*)",Void,"signal");
275 BBTK_INPUT(KWBlackBox,WinClose,
276 "Any signal received closes the window (*)",Void,"signal");
277 BBTK_OUTPUT(KWBlackBox,Widget,"Output widget",vtkKWWidget*,"");
278 BBTK_END_DESCRIBE_BLACK_BOX(KWBlackBox);
279 //=================================================================
289 //=================================================================
290 // Handles the destroy events of a widget associated to a KWBlackBox
291 // in order to signal the widget death to its associated box
292 class BBTK_EXPORT KWBlackBoxWidgetEventHandler : public wxEvtHandler
295 /// Ctor with the box and widget
296 KWBlackBoxWidgetEventHandler( KWBlackBox::Pointer box, wxWindow *widget );
298 ~KWBlackBoxWidgetEventHandler();
299 /// Returns true iff is the handler for that window
300 bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
301 // wxWindow* GetKWWindow() { return mWindow; }
302 /// Method processing the destroy event of the widget
303 void OnWindowDestroy(wxWindowDestroyEvent&);
305 //bool IsDead() { return mDead; }
308 KWBlackBox::WeakPointer mBox;
312 //=================================================================
320 #endif // USE_KWWIDGETS
321 #endif //__bbtkKWBlackBox_h__