]> Creatis software - bbtk.git/blob - kernel/src/bbtkUserBlackBox.cxx
Recreated the complete cvs tree because the project architecture deeply changed
[bbtk.git] / kernel / src / bbtkUserBlackBox.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkUserBlackBox.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/01/22 15:02:00 $
7   Version:   $Revision: 1.1.1.1 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19
20 /**
21  *  \file 
22  *  \brief class bbtk::UserBlackBox : abstract user defined black boxes
23  */
24 #include "bbtkUserBlackBox.h"
25
26 namespace bbtk
27 {
28   
29   //=========================================================================
30   UserBlackBox::UserBlackBox(const std::string &name, bool alloc)
31     : BlackBox(name)
32   {
33     bbtkDebugMessageInc("Core",7,
34                         "UserBlackBox::UserBlackBox(\""
35                         <<name<<"\")"<<std::endl);
36     bbtkDebugDecTab("Core",7);
37   }
38   //========================================================================= 
39   
40   //=========================================================================
41   /// Constructor from an existing box (copy) with a new name 
42   UserBlackBox::UserBlackBox(UserBlackBox& from, 
43                              const std::string &name, 
44                              bool alloc)
45     : BlackBox(from,name)
46   {
47     bbtkDebugMessageInc("Core",7,
48                         "UserBlackBox::UserBlackBox("
49                         <<from.bbGetFullName()<<",\""
50                         <<name<<"\")"<<std::endl);
51     bbtkDebugDecTab("Core",7);
52     
53   }
54   //=========================================================================
55   
56   
57   //=========================================================================
58   ///  Destructor
59   UserBlackBox::~UserBlackBox()
60   {
61     bbtkDebugMessage("Core",7,"UserBlackBox::~UserBlackBox()"
62                      <<std::endl);
63   } 
64   //=========================================================================
65   
66   
67
68   //=========================================================================
69   /// Main processing method of the box.
70   IOStatus UserBlackBox::bbBackwardUpdate( Connection* caller )
71   {
72     bbtkDebugMessageInc("Process",1,
73                         "=> UserBlackBox::bbBackwardUpdate() ["
74                         <<bbGetFullName()<<"]"<<std::endl);
75     
76     bbtkDebugMessage("Process",5,"Initial Status  = "<<bbGetStatus()<<std::endl);
77     bbtkDebugMessage("Process",5,"BoxProcessMode  = "<<bbGetInputBoxProcessMode()<<std::endl);
78    
79     /* 
80     if ( bbGetStatus() == UPDATING ) 
81       {
82         bbtkMessage("Warning",1,"!! WARNING !! Cyclic pipeline execution (bbBackwardUpdate ["<<bbGetFullName()<<"] reentered). This may indicate an error in pipeline conception"<<std::endl);
83         //      return UPTODATE;
84         bbSetStatus(MODIFIED);
85       }
86     */
87
88     if ( ( bbGetStatus() == MODIFIED ) ||
89          ( bbBoxProcessModeIsAlways() ) )
90       {
91         bool wasExecuting = bbGlobalGetSomeBoxExecuting();
92         bbGlobalSetSomeBoxExecuting(true);
93
94         //      bbSetStatus(UPDATING);
95
96         // Updates its inputs
97         IOStatus s = bbUpdateInputs();
98         
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() ) ) 
105           {
106             bbSetStatus(UPTODATE);
107           }
108         else 
109           {
110             // else it remains MODIFIED
111             bbSetStatus(MODIFIED);
112           }     
113
114         // Creates the window (WxBlackbox)
115         //      bbCreateWindow();
116
117         // Children update (WxContainerBlackBox)
118         //      bbUpdateChildren(caller);       
119
120         // User process
121         bbProcess();
122
123         // Displays the window (WxBlackbox)
124         bbShowWindow(caller);
125
126
127
128         bbGlobalSetSomeBoxExecuting(wasExecuting);
129
130
131       }
132     else 
133       {
134         bbtkDebugMessage("Process",5,"Up-to-date : nothing to do"<<std::endl);
135       }
136
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);
143
144     return bbGetStatus();
145
146   }
147   //=========================================================================
148   
149   /*
150   //=========================================================================
151   /// Main processing method of the box.
152   void UserBlackBox::bbForwardUpdate( Connection* caller )
153   {
154     bbtkDebugMessageInc("Process",1,
155                         "=> UserBlackBox::bbForwardUpdate() ["
156                         <<bbGetFullName()<<"]"<<std::endl);
157     
158     bbtkDebugMessage("Process",5,"Initial Status  = "<<bbGetStatus()<<std::endl);
159     bbtkDebugMessage("Process",5,"BoxProcessMode     = "<<bbGetInputBoxProcessMode()<<std::endl);
160     
161     if ( ( bbGetStatus() == MODIFIED ) ||
162          ( bbBoxProcessModeIsAlways() ) )
163       {
164         bool wasExecuting = bbGlobalGetSomeBoxExecuting();
165         bbGlobalSetSomeBoxExecuting(true);
166
167         // Updates its inputs ** EXCLUDING "Parent" **
168         IOStatus s = bbUpdateInputs(true);
169
170         // ??? Status management on ForwardUpdate ???
171         bbSetStatus(UPTODATE);
172
173         // Creates the window 
174         bbCreateWindow();
175
176         // Children update (WxContainer)
177         bbUpdateChildren(caller);       
178
179         // User process
180         bbProcess();
181
182         bbGlobalSetSomeBoxExecuting(wasExecuting);
183       }
184     
185     bbtkDebugMessage("Process",1,
186                      "<= UserBlackBox::bbForwardUpdate() ["
187                      <<bbGetFullName()<<"]"<<std::endl);
188
189     bbtkDebugDecTab("Process",1);
190   }
191   //=========================================================================
192   */
193   
194   
195    
196   //=========================================================================
197   Data UserBlackBox::bbGetOutput( const std::string &name )
198   {
199     bbtkDebugMessageInc("Data",7,
200                         "UserBlackBox::bbGetOutput(\""<<name<<"\") ["
201                         <<bbGetFullName()<<"]"
202                         <<std::endl);
203     
204     Data p = ((UserBlackBoxOutputDescriptor*)bbGetDescriptor()->GetOutputDescriptor(name))->GetGetFunctor()->Get(this);
205     
206     bbtkDebugDecTab("Data",7);
207     return p;
208   }
209   //=========================================================================
210   
211   
212   //=========================================================================
213   ///  Gets the input Data of a given name
214   Data UserBlackBox::bbGetInput( const std::string &name ) 
215   {
216     bbtkDebugMessageInc("Data",7,
217                         "UserBlackBox::bbGetInput(\""<<name<<"\") ["
218                         <<bbGetFullName()<<"]"
219                         <<std::endl);  
220     
221     Data p = ((UserBlackBoxInputDescriptor*)bbGetDescriptor()->GetInputDescriptor(name))->GetGetFunctor()->Get(this);
222     
223     bbtkDebugDecTab("Data",7);
224     return p;
225   }
226   //=========================================================================
227   
228   
229   //=========================================================================
230   ///  Sets the data of the output called <name>
231   void UserBlackBox::bbSetOutput( const std::string &name, Data data)
232   {
233     bbtkDebugMessageInc("Data",7,
234                         "UserBlackBox::bbSetOutput(\""<<name<<"\",data) ["
235                         <<bbGetFullName()<<"]"
236                         <<std::endl); 
237     
238     ((UserBlackBoxOutputDescriptor*)bbGetDescriptor()->GetOutputDescriptor(name))->GetSetFunctor()->Set(this,data);
239     
240     bbtkDebugDecTab("Data",7);
241   }  
242   //=========================================================================
243   
244   
245   //=========================================================================
246   ///  Sets the data of the input called <name>
247   void UserBlackBox::bbSetInput( const std::string &name, Data data, 
248                                  bool setModified )
249   {
250     bbtkDebugMessageInc("Data",7,
251                         "UserBlackBox::bbSetInput(\""<<name<<"\",data) ["
252                         <<bbGetFullName()<<"]"
253                         <<std::endl);  
254     ((UserBlackBoxInputDescriptor*)bbGetDescriptor()->GetInputDescriptor(name))->GetSetFunctor()->Set(this,data);
255     
256     if (setModified) 
257       {
258         bbSetModifiedStatus();
259       }
260     
261     bbtkDebugDecTab("Data",7);
262   }
263   //=========================================================================
264   
265     //=========================================================================
266   ///  Sets the data of the input called <name>
267   void UserBlackBox::bbBruteForceSetInputPointer( const std::string &name, 
268                                                   void* data, 
269                                                   bool setModified )
270   {
271     bbtkDebugMessageInc("Data",7,
272                         "UserBlackBox::bbBruteForceSetInputPointer(\""
273                         <<name<<"\",data) ["
274                         <<bbGetFullName()<<"]"
275                         <<std::endl);  
276     ((UserBlackBoxInputDescriptor*)bbGetDescriptor()->GetInputDescriptor(name))->GetSetFunctor()->BruteForceSetPointer(this,data);
277     
278     if (setModified) 
279       {
280         bbSetModifiedStatus();
281       }
282     
283     bbtkDebugDecTab("Data",7);
284   }
285   //=========================================================================
286   
287 }
288 // EO namespace bbtk