1 /*=========================================================================
3 Module: $RCSfile: bbtkWidgetBlackBox.txx,v $
5 Date: $Date: 2009/05/28 08:12:06 $
6 Version: $Revision: 1.5 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
37 //#include "bbtkWidgetBlackBoxWindow.h"
38 #include "bbtkBlackBoxOutputConnector.h"
44 //=========================================================================
46 //=========================================================================
48 //=========================================================================
49 //=========================================================================
50 //=========================================================================
51 //=========================================================================
52 BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(WidgetBlackBox,AtomicBlackBox);
53 //=========================================================================
55 //=========================================================================
57 void WidgetBlackBox<T>::bbUserSetDefaultValues()
59 bbtkBlackBoxDebugMessage("widget",9,"WidgetBlackBox::bbUserSetDefaultValues()"<<std::endl);
61 bbSetInputWinTitle(bbGetName());
62 bbSetInputWinWidth(800);
63 bbSetInputWinHeight(800);
64 bbSetInputWinDialog(false);
67 //=========================================================================
70 //=========================================================================
72 void WidgetBlackBox<T>::bbUserInitializeProcessing()
76 //=========================================================================
78 //=========================================================================
80 void WidgetBlackBox<T>::bbUserFinalizeProcessing()
83 std::cout << "****** WidgetBlackBox<T>::bbUserFinalizeProcessing()"<<std::endl;
84 bbtkBlackBoxDebugMessage("widget",9,"==> WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
87 bool shown = bbGetWindow()->bbIsShown();
88 bbGetWindow()->bbDestroy();
93 bbtkBlackBoxDebugMessage("widget",9,"**** HERE use count == 0"<<std::endl);
94 if (shown) DecNbWindowsShown();
99 bbtkBlackBoxDebugMessage("widget",9,"<== WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
102 //=========================================================================
108 //=========================================================================
110 void WidgetBlackBox<T>::bbProcess()
112 // TODO : update the window size and title
113 this->bbUserProcess();
115 //=========================================================================
117 //=========================================================================
119 void WidgetBlackBox<T>::bbCreateWindow()
123 // If output 'Widget' not connected then
124 // it is a top level Widget have to create and show the Window
125 if ( ! bbIsOutputWidgetConnected() )
127 // create the Window if does not exist
128 if (!bbWindowIsCreated())
130 bbtkBlackBoxDebugMessage("widget",2,
131 "-> Creating the window"
135 bbmNestedWidgetBoxes.clear();
137 // this->InitWindowManagerIfNeeded();
138 // If is a Dialog requested
139 if ( bbGetInputWinDialog() )
141 bbtkBlackBoxDebugMessage("widget",2,
142 " Input WinDialog set to true : creating a Dialog"
144 this->bbCreateDialogWindow();
146 // Input WinDialog set to false : creating a Frame
149 bbtkBlackBoxDebugMessage("widget",2,
150 " Input WinDialog set to false : creating a Frame"
152 this->bbCreateFrameWindow();
157 if ( !bbGetWindow() )
159 bbtkInternalError("Need to show the Window of widget "<<bbGetName()
160 <<" however was not created by apropriate cb");
165 bbtkBlackBoxDebugMessage("widget",2,
166 "-> Showing the window"
168 // bbGetWindow()->bbShow();
169 this->bbShowWindow();
174 //=========================================================================
177 //==================================================================
179 typename WidgetBlackBox<T>::WidgetPointer
180 WidgetBlackBox<T>::bbCreateWidgetOfInput
181 (const std::string& in, typename WidgetBlackBox<T>::WidgetPointer parent)
183 bbtkBlackBoxDebugMessage("widget",2,"bbCreateWidgetOfInput("
184 <<in<<","<<parent<<")"
187 // If input is connected
188 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
189 if ( c->IsConnected() )
191 // Get black box from
192 BlackBox::Pointer from =
193 c->GetConnection()->GetBlackBoxFrom();
194 // Cast it into a WidgetBlackBox
195 typename WidgetBlackBox<T>::Pointer wfrom
196 = boost::dynamic_pointer_cast<WidgetBlackBox<T> >(from);
197 // If the black box from construction is not done yet : do it
198 // If not constructed do it
199 wfrom->bbInitializeProcessing();
200 // Call bbUserCreateWidget
201 wfrom->bbUserCreateWidget(parent);
202 // Get the widget created
203 w = wfrom->bbGetOutputWidget();
204 // Insert the box into the NestedWidgetBoxes list
205 bbmNestedWidgetBoxes.push_back(from);
209 //==================================================================
211 //=========================================================================
213 bool WidgetBlackBox<T>::bbIsOutputWidgetConnected()
215 return ((*bbGetOutputConnectorMap().find("Widget")).second->GetConnectionVector().size() != 0 );
217 //==================================================================
219 //==================================================================
221 void WidgetBlackBox<T>::bbSetShown(bool b)
223 if (b==bbmShown) return;
225 bbtkBlackBoxDebugMessage("widget",5,"WidgetBlackBox::bbSetShown("
232 this->bbUserOnShow();
234 // Have to propagate to nested widgets
235 std::vector<BlackBox::WeakPointer>::const_iterator i;
236 for (i =bbmNestedWidgetBoxes.begin();
237 i!=bbmNestedWidgetBoxes.end();
240 if (!i->expired()) i->lock()->bbSetShown(b);
244 //==================================================================
246 //==================================================================
248 bool WidgetBlackBox<T>::bbIsShown()
252 //==================================================================
255 //==================================================================
257 void WidgetBlackBox<T>::bbShowWindow()
259 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbShowWindow() ["
260 <<bbGetFullName()<<"]"<<std::endl);
262 if (bbGetWindow()!=0) bbGetWindow()->bbShow();
264 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbShowWindow() ["
265 <<bbGetFullName()<<"]"<<std::endl);
267 //==================================================================
269 //==================================================================
271 void WidgetBlackBox<T>::bbHideWindow()
273 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbHideWindow() ["
274 <<bbGetFullName()<<"]"<<std::endl);
276 if (bbGetWindow()!=0) bbGetWindow()->bbHide();
278 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbHideWindow() ["
279 <<bbGetFullName()<<"]"<<std::endl);
281 //==================================================================
284 //==================================================================
286 void WidgetBlackBox<T>::bbCloseWindow()
288 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbCloseWindow() ["
289 <<bbGetFullName()<<"]"<<std::endl);
291 if (bbGetWindow()!=0) bbGetWindow()->bbDestroy();
293 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbCloseWindow() ["
294 <<bbGetFullName()<<"]"<<std::endl);
296 //==================================================================
298 //==================================================================
300 typename WidgetBlackBox<T>::Window*
301 WidgetBlackBox<T>::bbGetContainingWindow()
303 if (bbGetWindow()!=0) return bbGetWindow();
304 BlackBox::OutputConnectorMapType::const_iterator i
305 = bbGetOutputConnectorMap().find("Widget");
306 if ( i->second->GetConnectionVector().size() != 0 )
308 return boost::static_pointer_cast<WidgetBlackBox>
309 (i->second->GetConnectionVector().front() //.lock()
310 ->GetBlackBoxTo())->bbGetContainingWindow();
314 //==================================================================
317 //==================================================================
319 bool WidgetBlackBox<T>::bbIsShown()
321 if (bbGetContainingWindow()!=0)
322 return bbGetContainingWindow()->bbIsShown();
325 //==================================================================