1 /*=========================================================================
3 Module: $RCSfile: bbtkKWBlackBox.cxx,v $
5 Date: $Date: 2008/12/11 09:50:35 $
6 Version: $Revision: 1.7 $
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 //=========================================================================
114 //=========================================================================
115 void KWBlackBox::bbProcess()
118 this->bbUserProcess();
120 // If output widget not connected create the window
121 if ( (*bbGetOutputConnectorMap().find("Widget")).second
122 ->GetConnectionVector().size() == 0 )
125 // If the window already exists : no need creating it
126 if (bbGetWindow()!=0)
128 bbtkDebugMessage("kw",2,
129 "-> Window already exists"
131 show = bbGetWindow();
133 // Else create window
136 bbtkDebugMessage("kw",2,
137 "-> Creating the window"
139 KW::GetApplication();
141 // Input WinDialog set to true : creating a Dialog
143 if (bbGetInputWinDialog())
145 bbtkDebugMessage("kw",2,
146 " Input WinDialog set to true : creating a Dialog"
149 vtkKWBlackBoxDialog* win = vtkKWBlackBoxDialog::New();
150 show = (Window*) win;
151 win->bbSetBlackBox( GetThisPointer<KWBlackBox>());
152 KW::GetApplication()->AddWindow((vtkKWWindowBase*)win);
154 win->SetResizable(0,0);
156 bbUserCreateWidget(win->GetFrame());
157 KW::GetApplication()->Script("place %s -x 0 -y 0 -width %d -height %d",
158 bbGetOutputWidget()->GetWidgetName(),
159 bbGetInputWinWidth(),
160 bbGetInputWinHeight());
167 bbGetOutputWidget()->SetParent(win);
168 bbGetOutputWidget()->Create();
169 KW::GetApplication()->Script("pack %s -side left -anchor c -expand y",
171 //"pack %s -side top -anchor nw -expand y -fill none -padx 2 -pady 2",
172 bbGetOutputWidget()->GetWidgetName());
177 // Input WinDialog set to false : creating a Frame
180 bbtkDebugMessage("process",2,
181 " Input WinDialog set to false : creating a Frame"
183 vtkKWBlackBoxFrame* win = vtkKWBlackBoxFrame::New();
184 show = (Window*) win;
185 win->bbSetBlackBox( GetThisPointer<KWBlackBox>());
186 // win->SetName( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN" );
187 // win->SetWidth( bbGetInputWinWidth() );
188 // win->SetHeight( bbGetInputWinHeight() );
189 KW::GetApplication()->AddWindow((vtkKWWindowBase*)win);
192 bbGetOutputWidget()->SetParent(win);
193 bbGetOutputWidget()->Create();
194 KW::GetApplication()->Script("pack %s -side top -anchor nw -expand y -fill none -padx 2 -pady 2",
195 bbGetOutputWidget()->GetWidgetName()); }
204 // std::cout << "KW::GetApplication()->Start();"<<std::endl;
205 // KW::GetApplication()->Start();
206 // std::cout << "AFTER KW::GetApplication()->Start();"<<std::endl;
212 //=========================================================================
215 //==================================================================
216 vtkKWWidget* KWBlackBox::bbCreateWidgetOfInput(const std::string& in, vtkKWFrame* parent)
219 // If input is connected
220 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
221 if ( c->IsConnected() )
223 // Get black box from
224 BlackBox::Pointer from =
225 c->GetConnection()->GetBlackBoxFrom();
226 // Cast it into a KWBlackBox
227 KWBlackBox::Pointer wfrom = boost::dynamic_pointer_cast<KWBlackBox>(from);
228 // Call bbCreateWidget
229 wfrom->bbUserCreateWidget(parent);
230 // Get the widget created
231 w = wfrom->bbGetOutputWidget();
235 //==================================================================
238 //==================================================================
239 void KWBlackBox::bbHideWindow()
241 bbtkDebugMessageInc("kw",1,"=> KWBlackBox::bbHideWindow() ["
242 <<bbGetFullName()<<"]"<<std::endl);
244 if (bbGetWindow()!=0) bbGetWindow()->bbHide();
246 bbtkDebugMessageDec("kw",2,"<= KWBlackBox::bbHideWindow() ["
247 <<bbGetFullName()<<"]"<<std::endl);
249 //==================================================================
252 //==================================================================
253 void KWBlackBox::bbCloseWindow()
255 bbtkDebugMessageInc("kw",1,"=> KWBlackBox::bbCloseWindow() ["
256 <<bbGetFullName()<<"]"<<std::endl);
258 if (bbGetWindow()!=0) bbGetWindow()->bbClose();
260 bbtkDebugMessageDec("kw",2,"<= KWBlackBox::bbCloseWindow() ["
261 <<bbGetFullName()<<"]"<<std::endl);
263 //==================================================================
265 //==================================================================
266 KWBlackBox::Window* KWBlackBox::bbGetContainingWindow()
268 if (bbGetWindow()!=0) return bbGetWindow();
269 BlackBox::OutputConnectorMapType::const_iterator i
270 = bbGetOutputConnectorMap().find("Widget");
271 if ( i->second->GetConnectionVector().size() != 0 )
273 return boost::static_pointer_cast<KWBlackBox>
274 (i->second->GetConnectionVector().front() //.lock()
275 ->GetBlackBoxTo())->bbGetContainingWindow();
279 //==================================================================
282 //==================================================================
283 bool KWBlackBox::bbIsShown()
285 if (bbGetContainingWindow()!=0)
286 return bbGetContainingWindow()->bbIsShown();
289 //==================================================================