1 /*=========================================================================
3 Module: $RCSfile: bbtkWidgetBlackBox.txx,v $
5 Date: $Date: 2009/04/08 07:56:11 $
6 Version: $Revision: 1.1 $
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>::bbUserConstructor()
59 bbtkDebugMessage("widget",9,"WidgetBlackBox::bbUserConstructor()"<<std::endl);
62 //=========================================================================
64 //=========================================================================
66 void WidgetBlackBox<T>::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
68 bbtkDebugMessage("widget",9,"WidgetBlackBox::bbUserCopyConstructor()"
72 //=========================================================================
75 //=========================================================================
77 void WidgetBlackBox<T>::bbUserDestructor()
79 bbtkDebugMessage("widget",9,"==> WidgetBlackBox::bbUserDestructor() ["<<bbGetFullName()<<"]"<<std::endl);
81 bbGetWindow()->bbClose();
84 bbtkDebugMessage("widget",9,"<== WidgetBlackBox::bbUserDestructor() ["<<bbGetFullName()<<"]"<<std::endl);
86 //=========================================================================
90 //=========================================================================
92 * \brief Initialize the attributes of the class
96 void WidgetBlackBox<T>::bbInitAttributes()
99 bbSetInputWinTitle(bbGetName());
100 bbSetInputWinWidth(800);
101 bbSetInputWinHeight(800);
102 bbSetInputWinDialog(false);
103 bbSetOutputWidget(0);
105 //=========================================================================
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 ( bbGetWindow() == 0)
130 bbtkDebugMessage("widget",2,
131 "-> Creating the window"
133 // this->InitWindowManagerIfNeeded();
134 // If is a Dialog requested
135 if ( bbGetInputWinDialog() )
137 bbtkDebugMessage("process",2,
138 " Input WinDialog set to true : creating a Dialog"
140 this->bbCreateDialogWindow();
142 // Input WinDialog set to false : creating a Frame
145 bbtkDebugMessage("process",2,
146 " Input WinDialog set to false : creating a Frame"
148 this->bbCreateFrameWindow();
152 if ( !bbGetWindow() )
154 bbtkInternalError("Need to show the Window of widget "<<bbGetName()
155 <<" however was not created by apropriate cb");
157 bbtkDebugMessage("widget",2,
158 "-> Showing the window"
160 bbGetWindow()->bbShow();
164 //=========================================================================
167 //==================================================================
169 typename WidgetBlackBox<T>::WidgetPointer
170 WidgetBlackBox<T>::bbCreateWidgetOfInput
171 (const std::string& in, WidgetBlackBox<T>::WidgetPointer parent)
174 // If input is connected
175 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
176 if ( c->IsConnected() )
178 // Get black box from
179 BlackBox::Pointer from =
180 c->GetConnection()->GetBlackBoxFrom();
181 // Cast it into a WidgetBlackBox
182 typename WidgetBlackBox<T>::Pointer wfrom
183 = boost::dynamic_pointer_cast<WidgetBlackBox<T> >(from);
184 // Call bbCreateWidget
185 wfrom->bbUserCreateWidget(parent);
186 // Get the widget created
187 w = wfrom->bbGetOutputWidget();
191 //==================================================================
193 //=========================================================================
195 bool WidgetBlackBox<T>::bbIsOutputWidgetConnected()
197 return ((*bbGetOutputConnectorMap().find("Widget")).second->GetConnectionVector().size() != 0 );
199 //==================================================================
201 //==================================================================
203 void WidgetBlackBox<T>::bbShowWindow()
205 bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbShowWindow() ["
206 <<bbGetFullName()<<"]"<<std::endl);
208 if (bbGetWindow()!=0) bbGetWindow()->bbShow();
210 bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbShowWindow() ["
211 <<bbGetFullName()<<"]"<<std::endl);
213 //==================================================================
215 //==================================================================
217 void WidgetBlackBox<T>::bbHideWindow()
219 bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbHideWindow() ["
220 <<bbGetFullName()<<"]"<<std::endl);
222 if (bbGetWindow()!=0) bbGetWindow()->bbHide();
224 bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbHideWindow() ["
225 <<bbGetFullName()<<"]"<<std::endl);
227 //==================================================================
230 //==================================================================
232 void WidgetBlackBox<T>::bbCloseWindow()
234 bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbCloseWindow() ["
235 <<bbGetFullName()<<"]"<<std::endl);
237 if (bbGetWindow()!=0) bbGetWindow()->bbClose();
239 bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbCloseWindow() ["
240 <<bbGetFullName()<<"]"<<std::endl);
242 //==================================================================
244 //==================================================================
246 typename WidgetBlackBox<T>::Window*
247 WidgetBlackBox<T>::bbGetContainingWindow()
249 if (bbGetWindow()!=0) return bbGetWindow();
250 BlackBox::OutputConnectorMapType::const_iterator i
251 = bbGetOutputConnectorMap().find("Widget");
252 if ( i->second->GetConnectionVector().size() != 0 )
254 return boost::static_pointer_cast<WidgetBlackBox>
255 (i->second->GetConnectionVector().front() //.lock()
256 ->GetBlackBoxTo())->bbGetContainingWindow();
260 //==================================================================
263 //==================================================================
265 bool WidgetBlackBox<T>::bbIsShown()
267 if (bbGetContainingWindow()!=0)
268 return bbGetContainingWindow()->bbIsShown();
271 //==================================================================