1 /*=========================================================================
3 Module: $RCSfile: bbtkWidgetBlackBox.txx,v $
5 Date: $Date: 2009/05/19 10:19:23 $
6 Version: $Revision: 1.4 $
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 bbtkDebugMessage("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()
75 //=========================================================================
77 //=========================================================================
79 void WidgetBlackBox<T>::bbUserFinalizeProcessing()
81 bbtkDebugMessage("widget",9,"==> WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
86 if (bbGetWindow()->bbIsShown()) DecNbWindowsShown();
89 bbGetWindow()->bbDestroy();
92 bbtkDebugMessage("widget",9,"<== WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
94 //=========================================================================
100 //=========================================================================
102 void WidgetBlackBox<T>::bbProcess()
104 // TODO : update the window size and title
105 this->bbUserProcess();
107 //=========================================================================
109 //=========================================================================
111 void WidgetBlackBox<T>::bbCreateWindow()
115 // If output 'Widget' not connected then
116 // it is a top level Widget have to create and show the Window
117 if ( ! bbIsOutputWidgetConnected() )
119 // create the Window if does not exist
120 if ( bbGetWindow() == 0)
122 bbtkDebugMessage("widget",2,
123 "-> Creating the window"
125 // this->InitWindowManagerIfNeeded();
126 // If is a Dialog requested
127 if ( bbGetInputWinDialog() )
129 bbtkDebugMessage("process",2,
130 " Input WinDialog set to true : creating a Dialog"
132 this->bbCreateDialogWindow();
134 // Input WinDialog set to false : creating a Frame
137 bbtkDebugMessage("process",2,
138 " Input WinDialog set to false : creating a Frame"
140 this->bbCreateFrameWindow();
144 if ( !bbGetWindow() )
146 bbtkInternalError("Need to show the Window of widget "<<bbGetName()
147 <<" however was not created by apropriate cb");
149 bbtkDebugMessage("widget",2,
150 "-> Showing the window"
152 bbGetWindow()->bbShow();
156 //=========================================================================
159 //==================================================================
161 typename WidgetBlackBox<T>::WidgetPointer
162 WidgetBlackBox<T>::bbCreateWidgetOfInput
163 (const std::string& in, typename WidgetBlackBox<T>::WidgetPointer parent)
166 // If input is connected
167 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
168 if ( c->IsConnected() )
170 // Get black box from
171 BlackBox::Pointer from =
172 c->GetConnection()->GetBlackBoxFrom();
173 // Cast it into a WidgetBlackBox
174 typename WidgetBlackBox<T>::Pointer wfrom
175 = boost::dynamic_pointer_cast<WidgetBlackBox<T> >(from);
176 // If the black box from construction is not done yet : do it
177 // If not constructed do it
178 wfrom->bbInitializeProcessing();
179 // Call bbUserCreateWidget
180 wfrom->bbUserCreateWidget(parent);
181 // Get the widget created
182 w = wfrom->bbGetOutputWidget();
186 //==================================================================
188 //=========================================================================
190 bool WidgetBlackBox<T>::bbIsOutputWidgetConnected()
192 return ((*bbGetOutputConnectorMap().find("Widget")).second->GetConnectionVector().size() != 0 );
194 //==================================================================
196 //==================================================================
198 void WidgetBlackBox<T>::bbShowWindow()
200 bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbShowWindow() ["
201 <<bbGetFullName()<<"]"<<std::endl);
203 if (bbGetWindow()!=0) bbGetWindow()->bbShow();
205 bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbShowWindow() ["
206 <<bbGetFullName()<<"]"<<std::endl);
208 //==================================================================
210 //==================================================================
212 void WidgetBlackBox<T>::bbHideWindow()
214 bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbHideWindow() ["
215 <<bbGetFullName()<<"]"<<std::endl);
217 if (bbGetWindow()!=0) bbGetWindow()->bbHide();
219 bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbHideWindow() ["
220 <<bbGetFullName()<<"]"<<std::endl);
222 //==================================================================
225 //==================================================================
227 void WidgetBlackBox<T>::bbCloseWindow()
229 bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbCloseWindow() ["
230 <<bbGetFullName()<<"]"<<std::endl);
232 if (bbGetWindow()!=0) bbGetWindow()->bbDestroy();
234 bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbCloseWindow() ["
235 <<bbGetFullName()<<"]"<<std::endl);
237 //==================================================================
239 //==================================================================
241 typename WidgetBlackBox<T>::Window*
242 WidgetBlackBox<T>::bbGetContainingWindow()
244 if (bbGetWindow()!=0) return bbGetWindow();
245 BlackBox::OutputConnectorMapType::const_iterator i
246 = bbGetOutputConnectorMap().find("Widget");
247 if ( i->second->GetConnectionVector().size() != 0 )
249 return boost::static_pointer_cast<WidgetBlackBox>
250 (i->second->GetConnectionVector().front() //.lock()
251 ->GetBlackBoxTo())->bbGetContainingWindow();
255 //==================================================================
258 //==================================================================
260 bool WidgetBlackBox<T>::bbIsShown()
262 if (bbGetContainingWindow()!=0)
263 return bbGetContainingWindow()->bbIsShown();
266 //==================================================================