]> Creatis software - bbtk.git/blob - kernel/src/bbtkKWBlackBox.h
dec705f1c0f887c832d1ff2f9e3739a792e410da
[bbtk.git] / kernel / src / bbtkKWBlackBox.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkKWBlackBox.h,v $
4   Language:  C++
5   Date:      $Date: 2008/11/29 21:41:34 $
6   Version:   $Revision: 1.1 $
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 #include "vtkKWWidget.h"
56 #include "vtkKWWindowBase.h"
57 #include "vtkKWFrame.h"
58 #include "vtkKWDialog.h"
59
60 namespace bbtk
61 {
62
63
64
65
66   //==================================================================
67   // Forward declaration of the class of window associated to a KWBlackBox
68   class vtkKWBlackBoxWindow;
69   //==================================================================
70
71   //==================================================================
72   // Forward declaration of the widget event handler class
73   //  class KWBlackBoxWidgetEventHandler;
74   //==================================================================
75
76
77   //==================================================================
78   /// Widget black boxes
79   class BBTK_EXPORT KWBlackBox : public bbtk::AtomicBlackBox  
80   { 
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*);
89
90   public:
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);
93
94
95     typedef vtkKWBlackBoxWindow Window;
96     
97     /// Returns the **OWN** window associated to the box
98     /// If 0 returned = no window
99     Window* bbGetWindow() { return bbmWindow; }
100
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.
104     /// More precisely :
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'
108     /// Else returns 0;
109     Window* bbGetContainingWindow();
110
111     /// Returns the parent wxWindow that must be used to create the widget 
112           //
113           // LG 24/11/08 : New widget pipeline
114           //    wxWindow* bbGetKWParent();
115
116     /// Returns true iff the 'containing window' exists and is shown 
117     /// (see bbGetContainingWindow).
118     bool bbIsShown();
119
120     //==================================================================    
121     /// User callback invoked when the containing window is shown
122     virtual void bbUserOnShow() {}
123     //==================================================================    
124  
125     //==================================================================    
126     /// User callback invoked when the containing window is hidden
127     virtual void bbUserOnHide() {}
128     //==================================================================    
129
130     // LG 24/11/08 : New widget pipeline
131     //    void bbCreateWidgetAndEventHandler(vtkKWWidget* parent); 
132
133           
134   protected:
135     
136   
137     //==================================================================
138     /// User callback called in the box contructor
139     virtual void bbUserConstructor();
140     /// User callback called in the box copy constructor
141     virtual void bbUserCopyConstructor(bbtk::BlackBox::Pointer);
142     /// User callback called in the box destructor
143     virtual void bbUserDestructor();
144     //==================================================================    
145
146     //==================================================================    
147     /// User callback for creating the widget associated to the box
148     /// ** Must be defined **
149     // LG 24/11/08 : New widget pipeline
150     virtual void bbUserCreateWidget(vtkKWWidget* parent) 
151     {
152       bbtkError(bbGetTypeName()<<" is a KWBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
153     }
154     //==================================================================    
155
156
157     vtkKWWidget* bbCreateWidgetOfInput(const std::string& in, 
158                                        vtkKWWidget* parent);
159
160
161     //==================================================================
162     /// Main processing method of the box.
163     virtual IOStatus bbBackwardUpdate( Connection::Pointer caller );
164     //==================================================================
165
166
167
168     //==================================================================
169     /// Overloaded processing method for KWBlackBoxes
170     virtual void bbProcess();
171     //==================================================================
172
173     //==================================================================
174     /// If necessary creates the KWBlackBoxWindow associated to the box
175     /// and shows it 
176     /// (does nothing if the box output 'Widget' is connected which 
177     /// means that the box does not have its own window but is contained 
178     /// into another window)
179     void bbShowWindow();
180     /// Hides the KWBlackBoxWindow associated to the box (if exists)
181     void bbHideWindow();
182     /// Closes (destroys) the KWBlackBoxWindow associated to the box (if exists)
183     void bbCloseWindow();
184     //==================================================================
185
186   private:
187     /// friendship
188     friend class vtkKWBlackBoxWindow;
189     //    friend class KWBlackBoxWidgetEventHandler;
190
191     /// Sets the window
192     inline void bbSetWindow(Window* w) { bbmWindow=w; }
193
194     /*
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; }
201     */
202
203     /// The KWBlackBoxWindow associated to the box
204     Window* bbmWindow;
205     /// The KWBlackBoxWidgetEventHandler associated to the box
206     //    KWBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
207
208
209     void bbInitAttributes();
210
211   protected :
212
213
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;
219
220     bool bbGetUpdateTransferedToParent() const { return bbmUpdateTransferedToParent; }
221     void bbSetUpdateTransferedToParent(bool b) 
222     { bbmUpdateTransferedToParent = b; }
223
224   };
225   //=================================================================
226  
227
228   //======================================================================
229   /// Defines the bbUserCreateWidget method
230 #define BBTK_CREATE_KWWIDGET(CALLBACK)                                  \
231   public:                                                               \
232   inline void bbUserCreateWidget(vtkKWWidget* parent)                   \
233   {                                                                     \
234     bbtkDebugMessageInc("kw",1,"**> Creating widget for ["              \
235                         <<bbGetFullName()<<"]"<<std::endl);             \
236     CALLBACK(parent);                                                   \
237     bbtkDebugMessageInc("kw",1,"<** Creating widget for ["              \
238                         <<bbGetFullName()<<"]"<<std::endl);             \
239   }
240   
241   //======================================================================
242
243   //======================================================================
244   /// Defines the bbUserOnShow method
245 #define BBTK_ON_SHOW_WIDGET(CALLBACK)                                   \
246   public:                                                               \
247   inline void bbUserOnShow()                                    \
248   {                                                                     \
249     bbtkDebugMessageInc("wx",1,"**> Showing ["          \
250                         <<bbGetFullName()<<"]"<<std::endl);             \
251     CALLBACK();                                                         \
252     bbtkDebugMessageInc("wx",1,"<** Showing ["          \
253                         <<bbGetFullName()<<"]"<<std::endl);             \
254   }
255   
256   //======================================================================
257
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 (*)",
266              std::string,"");
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   //=================================================================
280
281
282
283
284
285
286
287
288
289   //==================================================================
290   // The base of the hierarchy of windows associated to a KWBlackBox
291   class BBTK_EXPORT vtkKWBlackBoxWindow 
292   {
293   public:
294     vtkKWBlackBoxWindow();
295     virtual ~vtkKWBlackBoxWindow();
296     virtual void bbShow();
297     virtual void bbHide();
298     virtual void bbClose();
299     bool bbIsShown() { return mShown; }
300     void bbSetBlackBox(KWBlackBox::Pointer box) 
301     { 
302       mBox = box; 
303       mBox.lock()->bbSetWindow(this);
304     }
305     virtual KWBlackBox::Pointer bbGetBlackBox() { return mBox.lock(); }
306   private:
307     KWBlackBox::WeakPointer mBox;
308     bool mShown;
309   };
310   //==================================================================
311
312
313   //==================================================================
314   // Dialog window which is modal
315   // Name of window must not begin with uppercase letter 
316   class BBTK_EXPORT  vtkKWBlackBoxDialog : public vtkKWDialog, 
317                                         public vtkKWBlackBoxWindow
318   {
319   public:
320     static vtkKWBlackBoxDialog* New();
321     vtkTypeRevisionMacro(vtkKWBlackBoxDialog,vtkKWDialog);
322     void bbShow();  
323     void bbHide();
324     void bbClose();
325     void Cancel();
326   protected:
327     vtkKWBlackBoxDialog();
328     ~vtkKWBlackBoxDialog();
329   private:
330     vtkKWBlackBoxDialog(const vtkKWBlackBoxDialog&);   // Not implemented.
331     void operator=(const vtkKWBlackBoxDialog&);  // Not implemented.
332   };
333   //==================================================================
334
335   //==================================================================
336   // Frame window which is not modal
337   class BBTK_EXPORT  vtkKWBlackBoxFrame : public vtkKWWindowBase,
338                                        public vtkKWBlackBoxWindow
339   {
340   public:
341     static vtkKWBlackBoxFrame* New();
342     vtkTypeRevisionMacro(vtkKWBlackBoxFrame,vtkKWWindowBase);
343     void bbShow();  
344     void bbHide();
345     void bbClose();
346   protected:
347     vtkKWBlackBoxFrame();
348     ~vtkKWBlackBoxFrame();
349   private:
350     vtkKWBlackBoxFrame(const vtkKWBlackBoxFrame&);   // Not implemented.
351     void operator=(const vtkKWBlackBoxFrame&);  // Not implemented.
352   };
353   //==================================================================
354
355
356   /*
357   //=================================================================
358   // Handles the destroy events of a widget associated to a KWBlackBox 
359   // in order to signal the widget death to its associated box
360   class BBTK_EXPORT KWBlackBoxWidgetEventHandler : public wxEvtHandler
361   {
362   public:
363     /// Ctor with the box and widget 
364     KWBlackBoxWidgetEventHandler( KWBlackBox::Pointer box, wxWindow *widget );
365     /// Dtor
366     ~KWBlackBoxWidgetEventHandler();
367     /// Returns true iff is the handler for that window  
368     bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
369     // wxWindow* GetKWWindow() { return mWindow; }
370     /// Method processing the destroy event of the widget
371     void OnWindowDestroy(wxWindowDestroyEvent&);
372     //
373     //bool IsDead() { return mDead; }
374
375   private:
376     KWBlackBox::WeakPointer mBox;
377     wxWindow* mWindow;
378     //bool mDead;
379   };  
380   //=================================================================
381   */
382
383
384 } //namespace bbtk
385
386
387
388 #endif  // USE_KWWIDGETS
389 #endif  //__bbtkKWBlackBox_h__