1 /*=========================================================================
4 Module: $RCSfile: bbtkUserBlackBox.cxx,v $
6 Date: $Date: 2008/01/22 15:02:00 $
7 Version: $Revision: 1.1 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
22 * \brief class bbtk::UserBlackBox : abstract user defined black boxes
24 #include "bbtkUserBlackBox.h"
29 //=========================================================================
30 UserBlackBox::UserBlackBox(const std::string &name, bool alloc)
33 bbtkDebugMessageInc("Core",7,
34 "UserBlackBox::UserBlackBox(\""
35 <<name<<"\")"<<std::endl);
36 bbtkDebugDecTab("Core",7);
38 //=========================================================================
40 //=========================================================================
41 /// Constructor from an existing box (copy) with a new name
42 UserBlackBox::UserBlackBox(UserBlackBox& from,
43 const std::string &name,
47 bbtkDebugMessageInc("Core",7,
48 "UserBlackBox::UserBlackBox("
49 <<from.bbGetFullName()<<",\""
50 <<name<<"\")"<<std::endl);
51 bbtkDebugDecTab("Core",7);
54 //=========================================================================
57 //=========================================================================
59 UserBlackBox::~UserBlackBox()
61 bbtkDebugMessage("Core",7,"UserBlackBox::~UserBlackBox()"
64 //=========================================================================
68 //=========================================================================
69 /// Main processing method of the box.
70 IOStatus UserBlackBox::bbBackwardUpdate( Connection* caller )
72 bbtkDebugMessageInc("Process",1,
73 "=> UserBlackBox::bbBackwardUpdate() ["
74 <<bbGetFullName()<<"]"<<std::endl);
76 bbtkDebugMessage("Process",5,"Initial Status = "<<bbGetStatus()<<std::endl);
77 bbtkDebugMessage("Process",5,"BoxProcessMode = "<<bbGetInputBoxProcessMode()<<std::endl);
80 if ( bbGetStatus() == UPDATING )
82 bbtkMessage("Warning",1,"!! WARNING !! Cyclic pipeline execution (bbBackwardUpdate ["<<bbGetFullName()<<"] reentered). This may indicate an error in pipeline conception"<<std::endl);
84 bbSetStatus(MODIFIED);
88 if ( ( bbGetStatus() == MODIFIED ) ||
89 ( bbBoxProcessModeIsAlways() ) )
91 bool wasExecuting = bbGlobalGetSomeBoxExecuting();
92 bbGlobalSetSomeBoxExecuting(true);
94 // bbSetStatus(UPDATING);
97 IOStatus s = bbUpdateInputs();
99 bbtkDebugMessage("Process",6,"Inputs post-update status = "<<s<<std::endl);
100 // If all inputs are in UPTODATE post-update status
101 // and mProcessMode is not "Always"
102 // then the box is now UPTODATE
103 if ( ( s == UPTODATE ) &&
104 ( ! bbBoxProcessModeIsAlways() ) )
106 bbSetStatus(UPTODATE);
110 // else it remains MODIFIED
111 bbSetStatus(MODIFIED);
114 // Creates the window (WxBlackbox)
117 // Children update (WxContainerBlackBox)
118 // bbUpdateChildren(caller);
123 // Displays the window (WxBlackbox)
124 bbShowWindow(caller);
128 bbGlobalSetSomeBoxExecuting(wasExecuting);
134 bbtkDebugMessage("Process",5,"Up-to-date : nothing to do"<<std::endl);
137 bbtkDebugMessage("Process",5,"Final Status = "
138 <<bbGetStatus()<<std::endl);
139 bbtkDebugMessage("Process",1,
140 "<= UserBlackBox::bbBackwardUpdate() ["
141 <<bbGetFullName()<<"]"<<std::endl);
142 bbtkDebugDecTab("Process",1);
144 return bbGetStatus();
147 //=========================================================================
150 //=========================================================================
151 /// Main processing method of the box.
152 void UserBlackBox::bbForwardUpdate( Connection* caller )
154 bbtkDebugMessageInc("Process",1,
155 "=> UserBlackBox::bbForwardUpdate() ["
156 <<bbGetFullName()<<"]"<<std::endl);
158 bbtkDebugMessage("Process",5,"Initial Status = "<<bbGetStatus()<<std::endl);
159 bbtkDebugMessage("Process",5,"BoxProcessMode = "<<bbGetInputBoxProcessMode()<<std::endl);
161 if ( ( bbGetStatus() == MODIFIED ) ||
162 ( bbBoxProcessModeIsAlways() ) )
164 bool wasExecuting = bbGlobalGetSomeBoxExecuting();
165 bbGlobalSetSomeBoxExecuting(true);
167 // Updates its inputs ** EXCLUDING "Parent" **
168 IOStatus s = bbUpdateInputs(true);
170 // ??? Status management on ForwardUpdate ???
171 bbSetStatus(UPTODATE);
173 // Creates the window
176 // Children update (WxContainer)
177 bbUpdateChildren(caller);
182 bbGlobalSetSomeBoxExecuting(wasExecuting);
185 bbtkDebugMessage("Process",1,
186 "<= UserBlackBox::bbForwardUpdate() ["
187 <<bbGetFullName()<<"]"<<std::endl);
189 bbtkDebugDecTab("Process",1);
191 //=========================================================================
196 //=========================================================================
197 Data UserBlackBox::bbGetOutput( const std::string &name )
199 bbtkDebugMessageInc("Data",7,
200 "UserBlackBox::bbGetOutput(\""<<name<<"\") ["
201 <<bbGetFullName()<<"]"
204 Data p = ((UserBlackBoxOutputDescriptor*)bbGetDescriptor()->GetOutputDescriptor(name))->GetGetFunctor()->Get(this);
206 bbtkDebugDecTab("Data",7);
209 //=========================================================================
212 //=========================================================================
213 /// Gets the input Data of a given name
214 Data UserBlackBox::bbGetInput( const std::string &name )
216 bbtkDebugMessageInc("Data",7,
217 "UserBlackBox::bbGetInput(\""<<name<<"\") ["
218 <<bbGetFullName()<<"]"
221 Data p = ((UserBlackBoxInputDescriptor*)bbGetDescriptor()->GetInputDescriptor(name))->GetGetFunctor()->Get(this);
223 bbtkDebugDecTab("Data",7);
226 //=========================================================================
229 //=========================================================================
230 /// Sets the data of the output called <name>
231 void UserBlackBox::bbSetOutput( const std::string &name, Data data)
233 bbtkDebugMessageInc("Data",7,
234 "UserBlackBox::bbSetOutput(\""<<name<<"\",data) ["
235 <<bbGetFullName()<<"]"
238 ((UserBlackBoxOutputDescriptor*)bbGetDescriptor()->GetOutputDescriptor(name))->GetSetFunctor()->Set(this,data);
240 bbtkDebugDecTab("Data",7);
242 //=========================================================================
245 //=========================================================================
246 /// Sets the data of the input called <name>
247 void UserBlackBox::bbSetInput( const std::string &name, Data data,
250 bbtkDebugMessageInc("Data",7,
251 "UserBlackBox::bbSetInput(\""<<name<<"\",data) ["
252 <<bbGetFullName()<<"]"
254 ((UserBlackBoxInputDescriptor*)bbGetDescriptor()->GetInputDescriptor(name))->GetSetFunctor()->Set(this,data);
258 bbSetModifiedStatus();
261 bbtkDebugDecTab("Data",7);
263 //=========================================================================
265 //=========================================================================
266 /// Sets the data of the input called <name>
267 void UserBlackBox::bbBruteForceSetInputPointer( const std::string &name,
271 bbtkDebugMessageInc("Data",7,
272 "UserBlackBox::bbBruteForceSetInputPointer(\""
274 <<bbGetFullName()<<"]"
276 ((UserBlackBoxInputDescriptor*)bbGetDescriptor()->GetInputDescriptor(name))->GetSetFunctor()->BruteForceSetPointer(this,data);
280 bbSetModifiedStatus();
283 bbtkDebugDecTab("Data",7);
285 //=========================================================================