1 /*=========================================================================
3 Module: $RCSfile: bbtkKWBlackBox.cxx,v $
5 Date: $Date: 2008/12/08 12:54:26 $
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 * ------------------------------------------------------------------------ */
41 #include "bbtkKWBlackBox.h"
42 #include "bbtkBlackBoxOutputConnector.h"
43 #include "vtkKWBlackBoxDialog.h"
49 //=========================================================================
51 //=========================================================================
53 //=========================================================================
54 //=========================================================================
55 //=========================================================================
56 //=========================================================================
57 BBTK_BLACK_BOX_IMPLEMENTATION(KWBlackBox,AtomicBlackBox);
58 //=========================================================================
60 //=========================================================================
61 void KWBlackBox::bbUserConstructor()
63 bbtkDebugMessage("Kernel",9,"KWBlackBox::bbUserConstructor()"<<std::endl);
66 //=========================================================================
68 //=========================================================================
69 void KWBlackBox::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
71 bbtkDebugMessage("Kernel",9,"KWBlackBox::bbUserCopyConstructor()"
75 //=========================================================================
78 //=========================================================================
79 void KWBlackBox::bbUserDestructor()
81 bbtkDebugMessage("kw",9,"==> KWBlackBox::bbUserDestructor() ["<<bbGetFullName()<<"]"<<std::endl);
83 bbGetWindow()->bbClose();
86 bbtkDebugMessage("kw",9,"<== KWBlackBox::bbUserDestructor() ["<<bbGetFullName()<<"]"<<std::endl);
88 //=========================================================================
92 //=========================================================================
94 * \brief Initialize the attributes of the class
97 void KWBlackBox::bbInitAttributes()
101 // bbSetInputWinParent(0);
102 bbSetInputWinTitle(bbGetName());
103 bbSetInputWinWidth(800);
104 bbSetInputWinHeight(800);
105 bbSetInputWinDialog(false);
106 bbSetOutputWidget(0);
108 // bbSetWidgetEventHandler(0);
109 // bbSetUpdateTransferedToParent(false);
111 //=========================================================================
113 //=========================================================================
114 /// Main processing method of the box.
115 void KWBlackBox::bbExecute(bool force)
117 bbtkDebugMessageInc("process",2,
118 "=> KWBlackBox::bbExecute("<<(int)force<<") ["
119 <<bbGetFullName()<<"]"<<std::endl);
121 // If the output 'Widget' is connected then
122 // we must execute the parent box
123 BlackBox::OutputConnectorMapType::const_iterator i
124 = bbGetOutputConnectorMap().find("Widget");
126 if ( i->second->GetConnectionVector().size() != 0 )
128 bbtkWarning("Execution called on '"<<bbGetFullName()
129 <<"' although its Output 'Widget' is connected: "
130 <<"if the widget is not created yet then it will not be! "
131 <<"Execute the top level Layout widget to create and "
132 <<"display the widget.");
135 AtomicBlackBox::bbExecute(force);
137 bbtkDebugMessageDec("process",2,
138 "<= KWBlackBox::bbExecute() ["
139 <<bbGetFullName()<<"]"<<std::endl);
141 //=========================================================================
144 //=========================================================================
145 void KWBlackBox::bbProcess()
148 if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
149 this->bbUserProcess();
151 // this->bbUserOnShow();
153 this->bbUserProcess();
155 // If output widget not connected create the window
156 if ( (*bbGetOutputConnectorMap().find("Widget")).second
157 ->GetConnectionVector().size() == 0 )
160 // If the window already exists : no need creating it
161 if (bbGetWindow()!=0)
163 bbtkDebugMessage("kw",2,
164 "-> Window already exists"
166 show = bbGetWindow();
168 // Else create window
171 bbtkDebugMessage("kw",2,
172 "-> Creating the window"
174 KW::GetApplication();
176 // Input WinDialog set to true : creating a Dialog
178 if (bbGetInputWinDialog())
180 bbtkDebugMessage("kw",2,
181 " Input WinDialog set to true : creating a Dialog"
184 vtkKWBlackBoxDialog* win = vtkKWBlackBoxDialog::New();
185 show = (Window*) win;
186 win->bbSetBlackBox( GetThisPointer<KWBlackBox>());
187 KW::GetApplication()->AddWindow((vtkKWWindowBase*)win);
189 win->SetResizable(0,0);
191 bbUserCreateWidget(win->GetFrame());
192 KW::GetApplication()->Script("place %s -x 0 -y 0 -width %d -height %d",
193 bbGetOutputWidget()->GetWidgetName(),
194 bbGetInputWinWidth(),
195 bbGetInputWinHeight());
202 bbGetOutputWidget()->SetParent(win);
203 bbGetOutputWidget()->Create();
204 KW::GetApplication()->Script("pack %s -side left -anchor c -expand y",
206 //"pack %s -side top -anchor nw -expand y -fill none -padx 2 -pady 2",
207 bbGetOutputWidget()->GetWidgetName());
212 // Input WinDialog set to false : creating a Frame
215 bbtkDebugMessage("process",2,
216 " Input WinDialog set to false : creating a Frame"
218 vtkKWBlackBoxFrame* win = vtkKWBlackBoxFrame::New();
219 show = (Window*) win;
220 win->bbSetBlackBox( GetThisPointer<KWBlackBox>());
221 // win->SetName( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN" );
222 // win->SetWidth( bbGetInputWinWidth() );
223 // win->SetHeight( bbGetInputWinHeight() );
224 KW::GetApplication()->AddWindow((vtkKWWindowBase*)win);
227 bbGetOutputWidget()->SetParent(win);
228 bbGetOutputWidget()->Create();
229 KW::GetApplication()->Script("pack %s -side top -anchor nw -expand y -fill none -padx 2 -pady 2",
230 bbGetOutputWidget()->GetWidgetName()); }
239 // std::cout << "KW::GetApplication()->Start();"<<std::endl;
240 // KW::GetApplication()->Start();
241 // std::cout << "AFTER KW::GetApplication()->Start();"<<std::endl;
247 //=========================================================================
250 //==================================================================
251 vtkKWWidget* KWBlackBox::bbCreateWidgetOfInput(const std::string& in, vtkKWFrame* parent)
254 // If input is connected
255 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
256 if ( c->IsConnected() )
258 // Get black box from
259 BlackBox::Pointer from =
260 c->GetConnection()->GetBlackBoxFrom();
261 // Cast it into a KWBlackBox
262 KWBlackBox::Pointer wfrom = boost::dynamic_pointer_cast<KWBlackBox>(from);
263 // Call bbCreateWidget
264 wfrom->bbUserCreateWidget(parent);
265 // Get the widget created
266 w = wfrom->bbGetOutputWidget();
270 //==================================================================
273 //==================================================================
274 void KWBlackBox::bbHideWindow()
276 bbtkDebugMessageInc("kw",1,"=> KWBlackBox::bbHideWindow() ["
277 <<bbGetFullName()<<"]"<<std::endl);
279 if (bbGetWindow()!=0) bbGetWindow()->bbHide();
281 bbtkDebugMessageDec("kw",2,"<= KWBlackBox::bbHideWindow() ["
282 <<bbGetFullName()<<"]"<<std::endl);
284 //==================================================================
287 //==================================================================
288 void KWBlackBox::bbCloseWindow()
290 bbtkDebugMessageInc("kw",1,"=> KWBlackBox::bbCloseWindow() ["
291 <<bbGetFullName()<<"]"<<std::endl);
293 if (bbGetWindow()!=0) bbGetWindow()->bbClose();
295 bbtkDebugMessageDec("kw",2,"<= KWBlackBox::bbCloseWindow() ["
296 <<bbGetFullName()<<"]"<<std::endl);
298 //==================================================================
300 //==================================================================
301 KWBlackBox::Window* KWBlackBox::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<KWBlackBox>
309 (i->second->GetConnectionVector().front() //.lock()
310 ->GetBlackBoxTo())->bbGetContainingWindow();
314 //==================================================================
317 //==================================================================
318 bool KWBlackBox::bbIsShown()
320 if (bbGetContainingWindow()!=0)
321 return bbGetContainingWindow()->bbIsShown();
324 //==================================================================