2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkWidgetBlackBox.txx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.7 $
34 =========================================================================*/
45 //#include "bbtkWidgetBlackBoxWindow.h"
46 #include "bbtkBlackBoxOutputConnector.h"
52 //=========================================================================
54 //=========================================================================
56 //=========================================================================
57 //=========================================================================
58 //=========================================================================
59 //=========================================================================
60 BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(WidgetBlackBox,AtomicBlackBox);
61 //=========================================================================
63 //=========================================================================
65 void WidgetBlackBox<T>::bbUserSetDefaultValues()
67 bbtkBlackBoxDebugMessage("widget",9,"WidgetBlackBox::bbUserSetDefaultValues()"<<std::endl);
69 bbSetInputWinTitle(bbGetName());
70 bbSetInputWinWidth(800);
71 bbSetInputWinHeight(800);
72 bbSetInputWinDialog(false);
75 //=========================================================================
78 //=========================================================================
80 void WidgetBlackBox<T>::bbUserInitializeProcessing()
84 //=========================================================================
86 //=========================================================================
88 void WidgetBlackBox<T>::bbUserFinalizeProcessing()
91 std::cout << "****** WidgetBlackBox<T>::bbUserFinalizeProcessing()"<<std::endl;
92 bbtkBlackBoxDebugMessage("widget",9,"==> WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
95 bool shown = bbGetWindow()->bbIsShown();
96 bbGetWindow()->bbDestroy();
101 bbtkBlackBoxDebugMessage("widget",9,"**** HERE use count == 0"<<std::endl);
102 if (shown) DecNbWindowsShown();
107 bbtkBlackBoxDebugMessage("widget",9,"<== WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
110 //=========================================================================
116 //=========================================================================
118 void WidgetBlackBox<T>::bbProcess()
120 // TODO : update the window size and title
121 this->bbUserProcess();
123 //=========================================================================
125 //=========================================================================
127 void WidgetBlackBox<T>::bbCreateWindow()
131 // If output 'Widget' not connected then
132 // it is a top level Widget have to create and show the Window
133 if ( ! bbIsOutputWidgetConnected() )
135 // create the Window if does not exist
136 if (!bbWindowIsCreated())
138 bbtkBlackBoxDebugMessage("widget",2,
139 "-> Creating the window"
143 bbmNestedWidgetBoxes.clear();
145 // this->InitWindowManagerIfNeeded();
146 // If is a Dialog requested
147 if ( bbGetInputWinDialog() )
149 bbtkBlackBoxDebugMessage("widget",2,
150 " Input WinDialog set to true : creating a Dialog"
152 this->bbCreateDialogWindow();
154 // Input WinDialog set to false : creating a Frame
157 bbtkBlackBoxDebugMessage("widget",2,
158 " Input WinDialog set to false : creating a Frame"
160 this->bbCreateFrameWindow();
165 if ( !bbGetWindow() )
167 bbtkInternalError("Need to show the Window of widget "<<bbGetName()
168 <<" however was not created by apropriate cb");
173 bbtkBlackBoxDebugMessage("widget",2,
174 "-> Showing the window"
176 // bbGetWindow()->bbShow();
177 this->bbShowWindow();
182 //=========================================================================
185 //==================================================================
187 typename WidgetBlackBox<T>::WidgetPointer
188 WidgetBlackBox<T>::bbCreateWidgetOfInput
189 (const std::string& in, typename WidgetBlackBox<T>::WidgetPointer parent)
191 bbtkBlackBoxDebugMessage("widget",2,"bbCreateWidgetOfInput("
192 <<in<<","<<parent<<")"
195 // If input is connected
196 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
197 if ( c->IsConnected() )
199 // Get black box from
200 BlackBox::Pointer from =
201 c->GetConnection()->GetBlackBoxFrom();
202 // Cast it into a WidgetBlackBox
203 typename WidgetBlackBox<T>::Pointer wfrom
204 = boost::dynamic_pointer_cast<WidgetBlackBox<T> >(from);
205 // If the black box from construction is not done yet : do it
206 // If not constructed do it
207 wfrom->bbInitializeProcessing();
208 // Call bbUserCreateWidget
209 wfrom->bbUserCreateWidget(parent);
210 // Get the widget created
211 w = wfrom->bbGetOutputWidget();
212 // Insert the box into the NestedWidgetBoxes list
213 bbmNestedWidgetBoxes.push_back(from);
217 //==================================================================
219 //=========================================================================
221 bool WidgetBlackBox<T>::bbIsOutputWidgetConnected()
223 return ((*bbGetOutputConnectorMap().find("Widget")).second->GetConnectionVector().size() != 0 );
225 //==================================================================
227 //==================================================================
229 void WidgetBlackBox<T>::bbSetShown(bool b)
231 if (b==bbmShown) return;
233 bbtkBlackBoxDebugMessage("widget",5,"WidgetBlackBox::bbSetShown("
240 this->bbUserOnShow();
242 // Have to propagate to nested widgets
243 std::vector<BlackBox::WeakPointer>::const_iterator i;
244 for (i =bbmNestedWidgetBoxes.begin();
245 i!=bbmNestedWidgetBoxes.end();
248 if (!i->expired()) i->lock()->bbSetShown(b);
252 //==================================================================
254 //==================================================================
256 bool WidgetBlackBox<T>::bbIsShown()
260 //==================================================================
263 //==================================================================
265 void WidgetBlackBox<T>::bbShowWindow()
267 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbShowWindow() ["
268 <<bbGetFullName()<<"]"<<std::endl);
270 if (bbGetWindow()!=0) bbGetWindow()->bbShow();
272 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbShowWindow() ["
273 <<bbGetFullName()<<"]"<<std::endl);
275 //==================================================================
277 //==================================================================
279 void WidgetBlackBox<T>::bbHideWindow()
281 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbHideWindow() ["
282 <<bbGetFullName()<<"]"<<std::endl);
284 if (bbGetWindow()!=0) bbGetWindow()->bbHide();
286 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbHideWindow() ["
287 <<bbGetFullName()<<"]"<<std::endl);
289 //==================================================================
292 //==================================================================
294 void WidgetBlackBox<T>::bbCloseWindow()
296 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbCloseWindow() ["
297 <<bbGetFullName()<<"]"<<std::endl);
299 if (bbGetWindow()!=0) bbGetWindow()->bbDestroy();
301 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbCloseWindow() ["
302 <<bbGetFullName()<<"]"<<std::endl);
304 //==================================================================
306 //==================================================================
308 typename WidgetBlackBox<T>::Window*
309 WidgetBlackBox<T>::bbGetContainingWindow()
311 if (bbGetWindow()!=0) return bbGetWindow();
312 BlackBox::OutputConnectorMapType::const_iterator i
313 = bbGetOutputConnectorMap().find("Widget");
314 if ( i->second->GetConnectionVector().size() != 0 )
316 return boost::static_pointer_cast<WidgetBlackBox>
317 (i->second->GetConnectionVector().front() //.lock()
318 ->GetBlackBoxTo())->bbGetContainingWindow();
322 //==================================================================
325 //==================================================================
327 bool WidgetBlackBox<T>::bbIsShown()
329 if (bbGetContainingWindow()!=0)
330 return bbGetContainingWindow()->bbIsShown();
333 //==================================================================