1 /*=========================================================================
3 Module: $RCSfile: bbtkKWBlackBox.h,v $
5 Date: $Date: 2008/12/02 08:38:08 $
6 Version: $Revision: 1.2 $
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;
61 //==================================================================
70 //==================================================================
71 // Forward declaration of the widget event handler class
72 // class KWBlackBoxWidgetEventHandler;
73 //==================================================================
76 //==================================================================
77 /// Widget black boxes
78 class BBTK_EXPORT KWBlackBox : public bbtk::AtomicBlackBox
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*);
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);
94 typedef vtkKWBlackBoxDialog Window;
96 /// Returns the **OWN** window associated to the box
97 /// If 0 returned = no window
98 Window* bbGetWindow() { return bbmWindow; }
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.
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'
108 Window* bbGetContainingWindow();
110 /// Returns the parent wxWindow that must be used to create the widget
112 // LG 24/11/08 : New widget pipeline
113 // wxWindow* bbGetKWParent();
115 /// Returns true iff the 'containing window' exists and is shown
116 /// (see bbGetContainingWindow).
119 //==================================================================
120 /// User callback invoked when the containing window is shown
121 virtual void bbUserOnShow() {}
122 //==================================================================
124 //==================================================================
125 /// User callback invoked when the containing window is hidden
126 virtual void bbUserOnHide() {}
127 //==================================================================
129 // LG 24/11/08 : New widget pipeline
130 // void bbCreateWidgetAndEventHandler(vtkKWWidget* parent);
132 inline void bbSetWindow(Window* w) { bbmWindow=w; }
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 //==================================================================
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)
153 bbtkError(bbGetTypeName()<<" is a KWBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
155 //==================================================================
158 vtkKWWidget* bbCreateWidgetOfInput(const std::string& in,
159 vtkKWWidget* parent);
162 //==================================================================
163 /// Main processing method of the box.
164 virtual IOStatus bbBackwardUpdate( Connection::Pointer caller );
165 //==================================================================
169 //==================================================================
170 /// Overloaded processing method for KWBlackBoxes
171 virtual void bbProcess();
172 //==================================================================
174 //==================================================================
175 /// If necessary creates the KWBlackBoxWindow associated to the box
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)
181 /// Hides the KWBlackBoxWindow associated to the box (if exists)
183 /// Closes (destroys) the KWBlackBoxWindow associated to the box (if exists)
184 void bbCloseWindow();
185 //==================================================================
189 friend class vtkKWBlackBoxWindow;
190 // friend class KWBlackBoxWidgetEventHandler;
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; }
202 /// The KWBlackBoxWindow associated to the box
204 /// The KWBlackBoxWidgetEventHandler associated to the box
205 // KWBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
208 void bbInitAttributes();
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;
219 bool bbGetUpdateTransferedToParent() const { return bbmUpdateTransferedToParent; }
220 void bbSetUpdateTransferedToParent(bool b)
221 { bbmUpdateTransferedToParent = b; }
224 //=================================================================
227 //======================================================================
228 /// Defines the bbUserCreateWidget method
229 #define BBTK_CREATE_KWWIDGET(CALLBACK) \
231 inline void bbUserCreateWidget(vtkKWWidget* parent) \
233 bbtkDebugMessageInc("kw",1,"**> Creating widget for [" \
234 <<bbGetFullName()<<"]"<<std::endl); \
236 bbtkDebugMessageInc("kw",1,"<** Creating widget for [" \
237 <<bbGetFullName()<<"]"<<std::endl); \
240 //======================================================================
242 //======================================================================
243 /// Defines the bbUserOnShow method
244 #define BBTK_ON_SHOW_WIDGET(CALLBACK) \
246 inline void bbUserOnShow() \
248 bbtkDebugMessageInc("wx",1,"**> Showing [" \
249 <<bbGetFullName()<<"]"<<std::endl); \
251 bbtkDebugMessageInc("wx",1,"<** Showing [" \
252 <<bbGetFullName()<<"]"<<std::endl); \
255 //======================================================================
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 (*)",
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 //=================================================================
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
294 /// Ctor with the box and widget
295 KWBlackBoxWidgetEventHandler( KWBlackBox::Pointer box, wxWindow *widget );
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&);
304 //bool IsDead() { return mDead; }
307 KWBlackBox::WeakPointer mBox;
311 //=================================================================
319 #endif // USE_KWWIDGETS
320 #endif //__bbtkKWBlackBox_h__