]> Creatis software - bbtk.git/blob - kernel/src/bbtkKWBlackBox.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkKWBlackBox.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkKWBlackBox.h,v $
4   Language:  C++
5   Date:      $Date: 2008/12/11 09:50:35 $
6   Version:   $Revision: 1.5 $
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 class vtkKWFrame;
62 //==================================================================
63
64
65 namespace bbtk
66 {
67
68
69
70
71
72   //==================================================================
73   /// Widget black boxes
74   class BBTK_EXPORT KWBlackBox : public bbtk::AtomicBlackBox  
75   { 
76     BBTK_BLACK_BOX_INTERFACE(KWBlackBox,bbtk::AtomicBlackBox);
77     BBTK_DECLARE_INPUT(WinTitle,std::string);
78     BBTK_DECLARE_INPUT(WinWidth,int);
79     BBTK_DECLARE_INPUT(WinHeight,int);
80     BBTK_DECLARE_INPUT(WinDialog,bool);
81     BBTK_DECLARE_INPUT(WinHide,Void);
82     BBTK_DECLARE_INPUT(WinClose,Void);
83     BBTK_DECLARE_OUTPUT(Widget, vtkKWWidget*);
84
85   public:
86     
87     typedef vtkKWBlackBoxDialog Window;
88     
89     /// Returns the **OWN** window associated to the box
90     /// If 0 returned = no window
91     Window* bbGetWindow() { return bbmWindow; }
92
93     /// Returns the window containing the widget associated to the box
94     /// Which can be the own window of **ANOTHER** box in case of 
95     /// a hierarchy of widgets.
96     /// More precisely :
97     /// If bbGetWindow() != 0 then returns bbGetWindow()
98     /// Else if the output 'Widget' is connected 
99     ///  then returns bbGetContainingWindow() of the box connected to 'Widget'
100     /// Else returns 0;
101     Window* bbGetContainingWindow();
102
103
104     /// Returns true iff the 'containing window' exists and is shown 
105     /// (see bbGetContainingWindow).
106     bool bbIsShown();
107
108     //==================================================================    
109     /// User callback invoked when the containing window is shown
110     virtual void bbUserOnShow() {}
111     //==================================================================    
112  
113     //==================================================================    
114     /// User callback invoked when the containing window is hidden
115     virtual void bbUserOnHide() {}
116     //==================================================================    
117
118     /// Sets the window
119     inline void bbSetWindow(Window* w) { bbmWindow=w; }
120
121           
122   protected:
123     
124   
125     //==================================================================
126     /// User callback called in the box contructor
127     virtual void bbUserConstructor();
128     /// User callback called in the box copy constructor
129     virtual void bbUserCopyConstructor(bbtk::BlackBox::Pointer);
130     /// User callback called in the box destructor
131     virtual void bbUserDestructor();
132     //==================================================================    
133
134     //==================================================================    
135     /// User callback for creating the widget associated to the box
136     /// ** Must be defined **
137     // LG 24/11/08 : New widget pipeline
138     virtual void bbUserCreateWidget(vtkKWFrame* parent) 
139     {
140       bbtkError(bbGetTypeName()<<" is a KWBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
141     }
142     //==================================================================    
143
144
145     //==================================================================
146     vtkKWWidget* bbCreateWidgetOfInput(const std::string& in, 
147                                        vtkKWFrame* parent);
148     //==================================================================
149
150
151     //==================================================================
152     /// Overloaded processing method for KWBlackBoxes
153     virtual void bbProcess();
154     //==================================================================
155
156     //==================================================================
157     /// If necessary creates the KWBlackBoxWindow associated to the box
158     /// and shows it 
159     /// (does nothing if the box output 'Widget' is connected which 
160     /// means that the box does not have its own window but is contained 
161     /// into another window)
162     void bbShowWindow();
163     /// Hides the KWBlackBoxWindow associated to the box (if exists)
164     void bbHideWindow();
165     /// Closes (destroys) the KWBlackBoxWindow associated to the box (if exists)
166     void bbCloseWindow();
167     //==================================================================
168
169   private:
170     /// friendship
171     friend class vtkKWBlackBoxWindow;
172     //    friend class KWBlackBoxWidgetEventHandler;
173
174     /// The KWBlackBoxWindow associated to the box
175     Window* bbmWindow;
176
177
178     void bbInitAttributes();
179
180   };
181   //=================================================================
182  
183
184   //======================================================================
185   /// Defines the bbUserCreateWidget method
186 #define BBTK_CREATE_KWWIDGET(CALLBACK)                                  \
187   public:                                                               \
188   inline void bbUserCreateWidget(vtkKWFrame* parent)                    \
189   {                                                                     \
190     bbtkDebugMessageInc("kw",1,"**> Creating widget for ["              \
191                         <<bbGetFullName()<<"]"<<std::endl);             \
192     CALLBACK(parent);                                                   \
193     bbtkDebugMessageInc("kw",1,"<** Creating widget for ["              \
194                         <<bbGetFullName()<<"]"<<std::endl);             \
195   }
196   
197   //======================================================================
198
199   //======================================================================
200   /// Defines the bbUserOnShow method
201 #define BBTK_ON_SHOW_WIDGET(CALLBACK)                                   \
202   public:                                                               \
203   inline void bbUserOnShow()                                    \
204   {                                                                     \
205     bbtkDebugMessageInc("wx",1,"**> Showing ["          \
206                         <<bbGetFullName()<<"]"<<std::endl);             \
207     CALLBACK();                                                         \
208     bbtkDebugMessageInc("wx",1,"<** Showing ["          \
209                         <<bbGetFullName()<<"]"<<std::endl);             \
210   }
211   
212   //======================================================================
213
214   //=================================================================
215   // KWBlackBoxDescriptor declaration
216   BBTK_BEGIN_DESCRIBE_BLACK_BOX(KWBlackBox,bbtk::AtomicBlackBox);
217   BBTK_NAME("KWBlackBox");
218   // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
219   BBTK_CATEGORY("widget");
220   BBTK_INPUT(KWBlackBox,WinTitle,
221              "Title of the window (*)",
222              std::string,"");
223   BBTK_INPUT(KWBlackBox,WinWidth,
224              "Width of the window (* : only used if the widget is not connected to a Layout box)",int,"");
225   BBTK_INPUT(KWBlackBox,WinHeight,
226              "Height of the window (*)",int,"");
227   BBTK_INPUT(KWBlackBox,WinDialog,
228              "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool,"");
229   BBTK_INPUT(KWBlackBox,WinHide,
230              "Any signal received hides the window (*)",Void,"signal");
231   BBTK_INPUT(KWBlackBox,WinClose,
232              "Any signal received closes the window (*)",Void,"signal");
233   BBTK_OUTPUT(KWBlackBox,Widget,"Output widget",vtkKWWidget*,"");
234   BBTK_END_DESCRIBE_BLACK_BOX(KWBlackBox);
235   //=================================================================
236
237
238
239
240
241
242
243
244   /*
245   //=================================================================
246   // Handles the destroy events of a widget associated to a KWBlackBox 
247   // in order to signal the widget death to its associated box
248   class BBTK_EXPORT KWBlackBoxWidgetEventHandler : public wxEvtHandler
249   {
250   public:
251     /// Ctor with the box and widget 
252     KWBlackBoxWidgetEventHandler( KWBlackBox::Pointer box, wxWindow *widget );
253     /// Dtor
254     ~KWBlackBoxWidgetEventHandler();
255     /// Returns true iff is the handler for that window  
256     bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
257     // wxWindow* GetKWWindow() { return mWindow; }
258     /// Method processing the destroy event of the widget
259     void OnWindowDestroy(wxWindowDestroyEvent&);
260     //
261     //bool IsDead() { return mDead; }
262
263   private:
264     KWBlackBox::WeakPointer mBox;
265     wxWindow* mWindow;
266     //bool mDead;
267   };  
268   //=================================================================
269   */
270
271
272 } //namespace bbtk
273
274
275
276 #endif  // USE_KWWIDGETS
277 #endif  //__bbtkKWBlackBox_h__