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 = c->GetConnection()->GetBlackBoxFrom();
201 // Cast it into a WidgetBlackBox
202 typename WidgetBlackBox<T>::Pointer wfrom = boost::dynamic_pointer_cast<WidgetBlackBox<T> >(from);
203 // If the black box from construction is not done yet : do it
204 // If not constructed do it
205 wfrom->bbInitializeProcessing();
206 // Call bbUserCreateWidget
207 wfrom->bbUserCreateWidget(parent);
208 // Get the widget created
209 w = wfrom->bbGetOutputWidget();
210 // Insert the box into the NestedWidgetBoxes list
211 bbmNestedWidgetBoxes.push_back(from);
215 //==================================================================
217 //=========================================================================
219 bool WidgetBlackBox<T>::bbIsOutputWidgetConnected()
221 return ((*bbGetOutputConnectorMap().find("Widget")).second->GetConnectionVector().size() != 0 );
223 //==================================================================
225 //==================================================================
227 void WidgetBlackBox<T>::bbSetShown(bool b)
229 if (b==bbmShown) return;
231 bbtkBlackBoxDebugMessage("widget",5,"WidgetBlackBox::bbSetShown("
238 this->bbUserOnShow();
240 // Have to propagate to nested widgets
241 std::vector<BlackBox::WeakPointer>::const_iterator i;
242 for (i =bbmNestedWidgetBoxes.begin();
243 i!=bbmNestedWidgetBoxes.end();
246 if (!i->expired()) i->lock()->bbSetShown(b);
250 //==================================================================
252 //==================================================================
254 bool WidgetBlackBox<T>::bbIsShown()
258 //==================================================================
261 //==================================================================
263 void WidgetBlackBox<T>::bbShowWindow()
265 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbShowWindow() ["
266 <<bbGetFullName()<<"]"<<std::endl);
268 if (bbGetWindow()!=0) bbGetWindow()->bbShow();
270 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbShowWindow() ["
271 <<bbGetFullName()<<"]"<<std::endl);
273 //==================================================================
275 //==================================================================
277 void WidgetBlackBox<T>::bbHideWindow()
279 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbHideWindow() ["
280 <<bbGetFullName()<<"]"<<std::endl);
282 if (bbGetWindow()!=0) bbGetWindow()->bbHide();
284 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbHideWindow() ["
285 <<bbGetFullName()<<"]"<<std::endl);
287 //==================================================================
290 //==================================================================
292 void WidgetBlackBox<T>::bbCloseWindow()
294 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbCloseWindow() ["
295 <<bbGetFullName()<<"]"<<std::endl);
297 printf("EED WidgetBlackBoxWindow<W>::bbDestroy\n");
300 if (bbGetWindow()!=0) bbGetWindow()->bbDestroy();
302 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbCloseWindow() ["
303 <<bbGetFullName()<<"]"<<std::endl);
305 //==================================================================
307 //==================================================================
309 typename WidgetBlackBox<T>::Window*
310 WidgetBlackBox<T>::bbGetContainingWindow()
312 if (bbGetWindow()!=0) return bbGetWindow();
313 BlackBox::OutputConnectorMapType::const_iterator i
314 = bbGetOutputConnectorMap().find("Widget");
315 if ( i->second->GetConnectionVector().size() != 0 )
317 return boost::static_pointer_cast<WidgetBlackBox>
318 (i->second->GetConnectionVector().front() //.lock()
319 ->GetBlackBoxTo())->bbGetContainingWindow();
323 //==================================================================
326 //==================================================================
328 bool WidgetBlackBox<T>::bbIsShown()
330 if (bbGetContainingWindow()!=0)
331 return bbGetContainingWindow()->bbIsShown();
334 //==================================================================