1 /*=========================================================================
3 Module: $RCSfile: bbtkKWBlackBox.cxx,v $
5 Date: $Date: 2008/12/18 11:54:44 $
6 Version: $Revision: 1.8 $
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());
158 KW::GetApplication()->Script
159 ("pack %s -expand yes -fill both",
160 bbGetOutputWidget()->GetWidgetName());
163 KW::GetApplication()->Script("place %s -x 0 -y 0 -width %d -height %d",
164 bbGetOutputWidget()->GetWidgetName(),
165 bbGetInputWinWidth(),
166 bbGetInputWinHeight());
173 bbGetOutputWidget()->SetParent(win);
174 bbGetOutputWidget()->Create();
175 KW::GetApplication()->Script("pack %s -side left -anchor c -expand y",
177 //"pack %s -side top -anchor nw -expand y -fill none -padx 2 -pady 2",
178 bbGetOutputWidget()->GetWidgetName());
183 // Input WinDialog set to false : creating a Frame
186 bbtkDebugMessage("process",2,
187 " Input WinDialog set to false : creating a Frame"
189 vtkKWBlackBoxFrame* win = vtkKWBlackBoxFrame::New();
190 show = (Window*) win;
191 win->bbSetBlackBox( GetThisPointer<KWBlackBox>());
192 // win->SetName( bbGetInputWinTitle() + " - bbtk (c) CREATIS LRMN" );
193 // win->SetWidth( bbGetInputWinWidth() );
194 // win->SetHeight( bbGetInputWinHeight() );
195 KW::GetApplication()->AddWindow((vtkKWWindowBase*)win);
198 bbGetOutputWidget()->SetParent(win);
199 bbGetOutputWidget()->Create();
200 KW::GetApplication()->Script("pack %s -side top -anchor nw -expand y -fill none -padx 2 -pady 2",
201 bbGetOutputWidget()->GetWidgetName()); }
210 // std::cout << "KW::GetApplication()->Start();"<<std::endl;
211 // KW::GetApplication()->Start();
212 // std::cout << "AFTER KW::GetApplication()->Start();"<<std::endl;
218 //=========================================================================
221 //==================================================================
222 vtkKWWidget* KWBlackBox::bbCreateWidgetOfInput(const std::string& in, vtkKWFrame* parent)
225 // If input is connected
226 BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
227 if ( c->IsConnected() )
229 // Get black box from
230 BlackBox::Pointer from =
231 c->GetConnection()->GetBlackBoxFrom();
232 // Cast it into a KWBlackBox
233 KWBlackBox::Pointer wfrom = boost::dynamic_pointer_cast<KWBlackBox>(from);
234 // Call bbCreateWidget
235 wfrom->bbUserCreateWidget(parent);
236 // Get the widget created
237 w = wfrom->bbGetOutputWidget();
241 //==================================================================
244 //==================================================================
245 void KWBlackBox::bbHideWindow()
247 bbtkDebugMessageInc("kw",1,"=> KWBlackBox::bbHideWindow() ["
248 <<bbGetFullName()<<"]"<<std::endl);
250 if (bbGetWindow()!=0) bbGetWindow()->bbHide();
252 bbtkDebugMessageDec("kw",2,"<= KWBlackBox::bbHideWindow() ["
253 <<bbGetFullName()<<"]"<<std::endl);
255 //==================================================================
258 //==================================================================
259 void KWBlackBox::bbCloseWindow()
261 bbtkDebugMessageInc("kw",1,"=> KWBlackBox::bbCloseWindow() ["
262 <<bbGetFullName()<<"]"<<std::endl);
264 if (bbGetWindow()!=0) bbGetWindow()->bbClose();
266 bbtkDebugMessageDec("kw",2,"<= KWBlackBox::bbCloseWindow() ["
267 <<bbGetFullName()<<"]"<<std::endl);
269 //==================================================================
271 //==================================================================
272 KWBlackBox::Window* KWBlackBox::bbGetContainingWindow()
274 if (bbGetWindow()!=0) return bbGetWindow();
275 BlackBox::OutputConnectorMapType::const_iterator i
276 = bbGetOutputConnectorMap().find("Widget");
277 if ( i->second->GetConnectionVector().size() != 0 )
279 return boost::static_pointer_cast<KWBlackBox>
280 (i->second->GetConnectionVector().front() //.lock()
281 ->GetBlackBoxTo())->bbGetContainingWindow();
285 //==================================================================
288 //==================================================================
289 bool KWBlackBox::bbIsShown()
291 if (bbGetContainingWindow()!=0)
292 return bbGetContainingWindow()->bbIsShown();
295 //==================================================================