1 /*=========================================================================
3 Module: $RCSfile: bbtkWidgetBlackBox.txx,v $
5 Date: $Date: 2010/01/14 13:17:27 $
6 Version: $Revision: 1.6 $
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 * ------------------------------------------------------------------------ */
38 //#include "bbtkWidgetBlackBoxWindow.h"
39 #include "bbtkBlackBoxOutputConnector.h"
45 //=========================================================================
47 //=========================================================================
49 //=========================================================================
50 //=========================================================================
51 //=========================================================================
52 //=========================================================================
53 BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(WidgetBlackBox,AtomicBlackBox);
54 //=========================================================================
56 //=========================================================================
58 void WidgetBlackBox<T>::bbUserSetDefaultValues()
60 bbtkBlackBoxDebugMessage("widget",9,"WidgetBlackBox::bbUserSetDefaultValues()"<<std::endl);
62 bbSetInputWinTitle(bbGetName());
63 bbSetInputWinWidth(800);
64 bbSetInputWinHeight(800);
65 bbSetInputWinDialog(false);
68 //=========================================================================
71 //=========================================================================
73 void WidgetBlackBox<T>::bbUserInitializeProcessing()
77 //=========================================================================
79 //=========================================================================
81 void WidgetBlackBox<T>::bbUserFinalizeProcessing()
84 std::cout << "****** WidgetBlackBox<T>::bbUserFinalizeProcessing()"<<std::endl;
85 bbtkBlackBoxDebugMessage("widget",9,"==> WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
88 bool shown = bbGetWindow()->bbIsShown();
89 bbGetWindow()->bbDestroy();
94 bbtkBlackBoxDebugMessage("widget",9,"**** HERE use count == 0"<<std::endl);
95 if (shown) DecNbWindowsShown();
100 bbtkBlackBoxDebugMessage("widget",9,"<== WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
103 //=========================================================================
109 //=========================================================================
111 void WidgetBlackBox<T>::bbProcess()
113 // TODO : update the window size and title
114 this->bbUserProcess();
116 //=========================================================================
118 //=========================================================================
120 void WidgetBlackBox<T>::bbCreateWindow()
124 // If output 'Widget' not connected then
125 // it is a top level Widget have to create and show the Window
126 if ( ! bbIsOutputWidgetConnected() )
128 // create the Window if does not exist
129 if (!bbWindowIsCreated())
131 bbtkBlackBoxDebugMessage("widget",2,
132 "-> Creating the window"
136 bbmNestedWidgetBoxes.clear();
138 // this->InitWindowManagerIfNeeded();
139 // If is a Dialog requested
140 if ( bbGetInputWinDialog() )
142 bbtkBlackBoxDebugMessage("widget",2,
143 " Input WinDialog set to true : creating a Dialog"
145 this->bbCreateDialogWindow();
147 // Input WinDialog set to false : creating a Frame
150 bbtkBlackBoxDebugMessage("widget",2,
151 " Input WinDialog set to false : creating a Frame"
153 this->bbCreateFrameWindow();
158 if ( !bbGetWindow() )
160 bbtkInternalError("Need to show the Window of widget "<<bbGetName()
161 <<" however was not created by apropriate cb");
166 bbtkBlackBoxDebugMessage("widget",2,
167 "-> Showing the window"
169 // bbGetWindow()->bbShow();
170 this->bbShowWindow();
175 //=========================================================================
178 //==================================================================
180 typename WidgetBlackBox<T>::WidgetPointer
181 WidgetBlackBox<T>::bbCreateWidgetOfInput
182 (const std::string& in, typename WidgetBlackBox<T>::WidgetPointer parent)
184 bbtkBlackBoxDebugMessage("widget",2,"bbCreateWidgetOfInput("
185 <<in<<","<<parent<<")"
188 // If input is connected
189 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
190 if ( c->IsConnected() )
192 // Get black box from
193 BlackBox::Pointer from =
194 c->GetConnection()->GetBlackBoxFrom();
195 // Cast it into a WidgetBlackBox
196 typename WidgetBlackBox<T>::Pointer wfrom
197 = boost::dynamic_pointer_cast<WidgetBlackBox<T> >(from);
198 // If the black box from construction is not done yet : do it
199 // If not constructed do it
200 wfrom->bbInitializeProcessing();
201 // Call bbUserCreateWidget
202 wfrom->bbUserCreateWidget(parent);
203 // Get the widget created
204 w = wfrom->bbGetOutputWidget();
205 // Insert the box into the NestedWidgetBoxes list
206 bbmNestedWidgetBoxes.push_back(from);
210 //==================================================================
212 //=========================================================================
214 bool WidgetBlackBox<T>::bbIsOutputWidgetConnected()
216 return ((*bbGetOutputConnectorMap().find("Widget")).second->GetConnectionVector().size() != 0 );
218 //==================================================================
220 //==================================================================
222 void WidgetBlackBox<T>::bbSetShown(bool b)
224 if (b==bbmShown) return;
226 bbtkBlackBoxDebugMessage("widget",5,"WidgetBlackBox::bbSetShown("
233 this->bbUserOnShow();
235 // Have to propagate to nested widgets
236 std::vector<BlackBox::WeakPointer>::const_iterator i;
237 for (i =bbmNestedWidgetBoxes.begin();
238 i!=bbmNestedWidgetBoxes.end();
241 if (!i->expired()) i->lock()->bbSetShown(b);
245 //==================================================================
247 //==================================================================
249 bool WidgetBlackBox<T>::bbIsShown()
253 //==================================================================
256 //==================================================================
258 void WidgetBlackBox<T>::bbShowWindow()
260 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbShowWindow() ["
261 <<bbGetFullName()<<"]"<<std::endl);
263 if (bbGetWindow()!=0) bbGetWindow()->bbShow();
265 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbShowWindow() ["
266 <<bbGetFullName()<<"]"<<std::endl);
268 //==================================================================
270 //==================================================================
272 void WidgetBlackBox<T>::bbHideWindow()
274 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbHideWindow() ["
275 <<bbGetFullName()<<"]"<<std::endl);
277 if (bbGetWindow()!=0) bbGetWindow()->bbHide();
279 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbHideWindow() ["
280 <<bbGetFullName()<<"]"<<std::endl);
282 //==================================================================
285 //==================================================================
287 void WidgetBlackBox<T>::bbCloseWindow()
289 bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbCloseWindow() ["
290 <<bbGetFullName()<<"]"<<std::endl);
292 if (bbGetWindow()!=0) bbGetWindow()->bbDestroy();
294 bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbCloseWindow() ["
295 <<bbGetFullName()<<"]"<<std::endl);
297 //==================================================================
299 //==================================================================
301 typename WidgetBlackBox<T>::Window*
302 WidgetBlackBox<T>::bbGetContainingWindow()
304 if (bbGetWindow()!=0) return bbGetWindow();
305 BlackBox::OutputConnectorMapType::const_iterator i
306 = bbGetOutputConnectorMap().find("Widget");
307 if ( i->second->GetConnectionVector().size() != 0 )
309 return boost::static_pointer_cast<WidgetBlackBox>
310 (i->second->GetConnectionVector().front() //.lock()
311 ->GetBlackBoxTo())->bbGetContainingWindow();
315 //==================================================================
318 //==================================================================
320 bool WidgetBlackBox<T>::bbIsShown()
322 if (bbGetContainingWindow()!=0)
323 return bbGetContainingWindow()->bbIsShown();
326 //==================================================================