]> Creatis software - bbtk.git/blob - kernel/src/bbtkWidgetBlackBox.txx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWidgetBlackBox.txx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWidgetBlackBox.txx,v $
4   Language:  C++
5   Date:      $Date: 2009/04/08 07:56:11 $
6   Version:   $Revision: 1.1 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30 /**
31  *  \file 
32  *  \brief 
33  */
34
35
36  
37 #include "bbtkWidgetBlackBoxWindow.h"
38 #include "bbtkBlackBoxOutputConnector.h"
39
40
41 namespace bbtk
42 {
43
44   //=========================================================================
45   // WidgetBlackBox
46   //=========================================================================
47
48   //=========================================================================
49   //=========================================================================
50   //=========================================================================
51   //=========================================================================
52   BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(WidgetBlackBox,AtomicBlackBox);
53   //=========================================================================
54   
55 //=========================================================================
56   template <class T>  
57   void WidgetBlackBox<T>::bbUserConstructor()
58   {
59     bbtkDebugMessage("widget",9,"WidgetBlackBox::bbUserConstructor()"<<std::endl);
60     bbInitAttributes();
61   }
62   //=========================================================================
63
64   //=========================================================================
65   template <class T>  
66   void WidgetBlackBox<T>::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
67   {
68     bbtkDebugMessage("widget",9,"WidgetBlackBox::bbUserCopyConstructor()"
69                      <<std::endl);
70     bbInitAttributes();
71   }
72   //=========================================================================
73
74
75   //=========================================================================
76   template <class T>  
77   void WidgetBlackBox<T>::bbUserDestructor()
78   {
79     bbtkDebugMessage("widget",9,"==> WidgetBlackBox::bbUserDestructor() ["<<bbGetFullName()<<"]"<<std::endl);
80     if (bbGetWindow()) {
81       bbGetWindow()->bbClose();
82       bbSetWindow(0);
83     }
84     bbtkDebugMessage("widget",9,"<== WidgetBlackBox::bbUserDestructor() ["<<bbGetFullName()<<"]"<<std::endl);
85   }
86   //=========================================================================
87   
88
89
90   //=========================================================================
91   /**
92    * \brief Initialize the attributes of the class
93    *
94    */
95   template <class T>  
96   void WidgetBlackBox<T>::bbInitAttributes()
97   {
98     bbmWindow = 0;
99     bbSetInputWinTitle(bbGetName());
100     bbSetInputWinWidth(800);
101     bbSetInputWinHeight(800);
102     bbSetInputWinDialog(false);
103     bbSetOutputWidget(0);
104   }
105   //=========================================================================
106
107
108   //=========================================================================
109   template <class T>  
110   void WidgetBlackBox<T>::bbProcess()
111   { 
112     // TODO : update the window size and title 
113     this->bbUserProcess(); 
114   }
115   //=========================================================================
116
117   //=========================================================================
118   template <class T>  
119   void WidgetBlackBox<T>::bbCreateWindow()
120   { 
121
122
123     // If output 'Widget' not connected then
124     // it is a top level Widget have to create and show the Window
125     if ( ! bbIsOutputWidgetConnected() )
126       {
127         // create the Window if does not exist
128         if ( bbGetWindow() == 0)
129           {
130             bbtkDebugMessage("widget",2,
131                              "-> Creating the window"
132                              <<std::endl);
133             //      this->InitWindowManagerIfNeeded();
134             // If is a Dialog requested
135             if ( bbGetInputWinDialog() )
136               {
137                 bbtkDebugMessage("process",2,
138                                  "   Input WinDialog set to true : creating a Dialog"
139                                  <<std::endl);
140                 this->bbCreateDialogWindow();
141               }
142             // Input WinDialog set to false : creating a Frame
143             else 
144               {
145                 bbtkDebugMessage("process",2,
146                                  "   Input WinDialog set to false : creating a Frame"
147                                  <<std::endl);
148                 this->bbCreateFrameWindow();
149               }
150           }
151         // Show the window
152         if ( !bbGetWindow() )
153           {
154             bbtkInternalError("Need to show the Window of widget "<<bbGetName()
155                               <<" however was not created by apropriate cb");
156           }
157         bbtkDebugMessage("widget",2,
158                          "-> Showing the window"
159                          <<std::endl);
160         bbGetWindow()->bbShow(); 
161       }           
162     //   
163   }
164   //=========================================================================
165   
166
167   //==================================================================
168   template <class T>  
169   typename WidgetBlackBox<T>::WidgetPointer  
170   WidgetBlackBox<T>::bbCreateWidgetOfInput
171   (const std::string& in, WidgetBlackBox<T>::WidgetPointer parent)
172   {
173     Widget* w = 0;
174     // If input is connected 
175     BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
176     if ( c->IsConnected() )                     
177       {
178         // Get black box from 
179         BlackBox::Pointer from = 
180           c->GetConnection()->GetBlackBoxFrom();
181         // Cast it into a WidgetBlackBox
182         typename WidgetBlackBox<T>::Pointer wfrom 
183           = boost::dynamic_pointer_cast<WidgetBlackBox<T> >(from);
184         // Call bbCreateWidget
185         wfrom->bbUserCreateWidget(parent);
186         // Get the widget created
187         w = wfrom->bbGetOutputWidget();
188       }
189     return w;
190   }
191   //==================================================================
192
193   //=========================================================================
194   template <class T>  
195   bool WidgetBlackBox<T>::bbIsOutputWidgetConnected()
196   {
197     return ((*bbGetOutputConnectorMap().find("Widget")).second->GetConnectionVector().size() != 0 );
198   }
199   //==================================================================
200
201  //==================================================================
202   template <class T>  
203    void WidgetBlackBox<T>::bbShowWindow()
204   {
205     bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbShowWindow() ["
206                         <<bbGetFullName()<<"]"<<std::endl);
207
208     if (bbGetWindow()!=0) bbGetWindow()->bbShow();
209
210     bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbShowWindow() ["
211                         <<bbGetFullName()<<"]"<<std::endl);
212   }
213   //==================================================================
214
215   //==================================================================
216   template <class T>  
217    void WidgetBlackBox<T>::bbHideWindow()
218   {
219     bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbHideWindow() ["
220                         <<bbGetFullName()<<"]"<<std::endl);
221
222     if (bbGetWindow()!=0) bbGetWindow()->bbHide();
223
224     bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbHideWindow() ["
225                         <<bbGetFullName()<<"]"<<std::endl);
226   }
227   //==================================================================
228
229
230   //==================================================================
231   template <class T>  
232   void WidgetBlackBox<T>::bbCloseWindow()
233   {
234     bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbCloseWindow() ["
235                         <<bbGetFullName()<<"]"<<std::endl);
236
237     if (bbGetWindow()!=0) bbGetWindow()->bbClose();
238
239     bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbCloseWindow() ["
240                         <<bbGetFullName()<<"]"<<std::endl);
241   }
242   //==================================================================
243
244   //==================================================================
245   template <class T>  
246   typename WidgetBlackBox<T>::Window* 
247   WidgetBlackBox<T>::bbGetContainingWindow()
248   {
249     if (bbGetWindow()!=0) return bbGetWindow();
250     BlackBox::OutputConnectorMapType::const_iterator i 
251       = bbGetOutputConnectorMap().find("Widget");
252     if ( i->second->GetConnectionVector().size() != 0 ) 
253       {
254         return boost::static_pointer_cast<WidgetBlackBox>
255           (i->second->GetConnectionVector().front() //.lock()
256            ->GetBlackBoxTo())->bbGetContainingWindow();
257       }
258     return 0;
259   }
260   //==================================================================
261
262
263   //==================================================================
264   template <class T>  
265   bool WidgetBlackBox<T>::bbIsShown()
266   {
267     if (bbGetContainingWindow()!=0)
268       return bbGetContainingWindow()->bbIsShown();
269     return false;
270   }
271   //==================================================================
272
273
274 }//namespace bbtk
275
276
277
278