1 /*=========================================================================
3 Module: $RCSfile: bbtkWidgetBlackBox.txx,v $
5 Date: $Date: 2009/05/14 14:43:34 $
6 Version: $Revision: 1.3 $
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);
83 bbGetWindow()->bbClose();
86 bbtkDebugMessage("widget",9,"<== WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
88 //=========================================================================
94 //=========================================================================
96 void WidgetBlackBox<T>::bbProcess()
98 // TODO : update the window size and title
99 this->bbUserProcess();
101 //=========================================================================
103 //=========================================================================
105 void WidgetBlackBox<T>::bbCreateWindow()
109 // If output 'Widget' not connected then
110 // it is a top level Widget have to create and show the Window
111 if ( ! bbIsOutputWidgetConnected() )
113 // create the Window if does not exist
114 if ( bbGetWindow() == 0)
116 bbtkDebugMessage("widget",2,
117 "-> Creating the window"
119 // this->InitWindowManagerIfNeeded();
120 // If is a Dialog requested
121 if ( bbGetInputWinDialog() )
123 bbtkDebugMessage("process",2,
124 " Input WinDialog set to true : creating a Dialog"
126 this->bbCreateDialogWindow();
128 // Input WinDialog set to false : creating a Frame
131 bbtkDebugMessage("process",2,
132 " Input WinDialog set to false : creating a Frame"
134 this->bbCreateFrameWindow();
138 if ( !bbGetWindow() )
140 bbtkInternalError("Need to show the Window of widget "<<bbGetName()
141 <<" however was not created by apropriate cb");
143 bbtkDebugMessage("widget",2,
144 "-> Showing the window"
146 bbGetWindow()->bbShow();
150 //=========================================================================
153 //==================================================================
155 typename WidgetBlackBox<T>::WidgetPointer
156 WidgetBlackBox<T>::bbCreateWidgetOfInput
157 (const std::string& in, typename WidgetBlackBox<T>::WidgetPointer parent)
160 // If input is connected
161 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
162 if ( c->IsConnected() )
164 // Get black box from
165 BlackBox::Pointer from =
166 c->GetConnection()->GetBlackBoxFrom();
167 // Cast it into a WidgetBlackBox
168 typename WidgetBlackBox<T>::Pointer wfrom
169 = boost::dynamic_pointer_cast<WidgetBlackBox<T> >(from);
170 // If the black box from construction is not done yet : do it
171 // If not constructed do it
172 wfrom->bbInitializeProcessing();
173 // Call bbUserCreateWidget
174 wfrom->bbUserCreateWidget(parent);
175 // Get the widget created
176 w = wfrom->bbGetOutputWidget();
180 //==================================================================
182 //=========================================================================
184 bool WidgetBlackBox<T>::bbIsOutputWidgetConnected()
186 return ((*bbGetOutputConnectorMap().find("Widget")).second->GetConnectionVector().size() != 0 );
188 //==================================================================
190 //==================================================================
192 void WidgetBlackBox<T>::bbShowWindow()
194 bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbShowWindow() ["
195 <<bbGetFullName()<<"]"<<std::endl);
197 if (bbGetWindow()!=0) bbGetWindow()->bbShow();
199 bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbShowWindow() ["
200 <<bbGetFullName()<<"]"<<std::endl);
202 //==================================================================
204 //==================================================================
206 void WidgetBlackBox<T>::bbHideWindow()
208 bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbHideWindow() ["
209 <<bbGetFullName()<<"]"<<std::endl);
211 if (bbGetWindow()!=0) bbGetWindow()->bbHide();
213 bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbHideWindow() ["
214 <<bbGetFullName()<<"]"<<std::endl);
216 //==================================================================
219 //==================================================================
221 void WidgetBlackBox<T>::bbCloseWindow()
223 bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbCloseWindow() ["
224 <<bbGetFullName()<<"]"<<std::endl);
226 if (bbGetWindow()!=0) bbGetWindow()->bbClose();
228 bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbCloseWindow() ["
229 <<bbGetFullName()<<"]"<<std::endl);
231 //==================================================================
233 //==================================================================
235 typename WidgetBlackBox<T>::Window*
236 WidgetBlackBox<T>::bbGetContainingWindow()
238 if (bbGetWindow()!=0) return bbGetWindow();
239 BlackBox::OutputConnectorMapType::const_iterator i
240 = bbGetOutputConnectorMap().find("Widget");
241 if ( i->second->GetConnectionVector().size() != 0 )
243 return boost::static_pointer_cast<WidgetBlackBox>
244 (i->second->GetConnectionVector().front() //.lock()
245 ->GetBlackBoxTo())->bbGetContainingWindow();
249 //==================================================================
252 //==================================================================
254 bool WidgetBlackBox<T>::bbIsShown()
256 if (bbGetContainingWindow()!=0)
257 return bbGetContainingWindow()->bbIsShown();
260 //==================================================================