]> Creatis software - bbtk.git/blob - kernel/src/bbtkAtomicBlackBox.cxx
New widget pipeline : progressing ...
[bbtk.git] / kernel / src / bbtkAtomicBlackBox.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkAtomicBlackBox.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/11/25 11:17:13 $
6   Version:   $Revision: 1.10 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
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.
20 *
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
25 *  liability. 
26 *
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 * ------------------------------------------------------------------------ */                                                                         
30
31
32 /**
33  *  \file 
34  *  \brief class bbtk::AtomicBlackBox : abstract user defined black boxes
35  */
36 #include "bbtkAtomicBlackBox.h"
37
38 namespace bbtk
39 {
40   
41   //=========================================================================
42   AtomicBlackBox::AtomicBlackBox(const std::string &name, bool alloc)
43     : BlackBox(name)
44   {
45     bbtkDebugMessage("object",3,
46                      "==> AtomicBlackBox::AtomicBlackBox(\""
47                      <<name<<"\")"<<std::endl);
48     bbtkDebugMessage("object",3,
49                      "<== AtomicBlackBox::AtomicBlackBox(\""
50                      <<name<<"\")"<<std::endl);
51   }
52   //========================================================================= 
53   
54   //=========================================================================
55   /// Constructor from an existing box (copy) with a new name 
56   AtomicBlackBox::AtomicBlackBox(AtomicBlackBox& from, 
57                 const std::string &name, 
58                 bool alloc)
59     : BlackBox(from,name)
60   {
61     bbtkDebugMessage("object",3,
62                      "==>AtomicBlackBox::AtomicBlackBox("
63                      <<from.bbGetFullName()<<",\""
64                      <<name<<"\")"<<std::endl);
65     bbtkDebugMessage("object",3,
66                      "<==AtomicBlackBox::AtomicBlackBox("
67                      <<from.bbGetFullName()<<",\""
68                      <<name<<"\")"<<std::endl);
69     
70   }
71   //=========================================================================
72   
73   
74   //=========================================================================
75   ///  Destructor
76   AtomicBlackBox::~AtomicBlackBox()
77   {
78     bbtkDebugMessage("object",3,"==> AtomicBlackBox::~AtomicBlackBox()"
79                      <<std::endl);
80     bbtkDebugMessage("object",3,"<== AtomicBlackBox::~AtomicBlackBox()"
81                      <<std::endl);
82   } 
83   //=========================================================================
84   
85
86
87   //=========================================================================
88   /// Main processing method of the box.
89   IOStatus AtomicBlackBox::bbBackwardUpdate( Connection::Pointer caller )
90   {
91     bbtkDebugMessageInc("process",3,
92                         "=> AtomicBlackBox::bbBackwardUpdate("
93                         <<(caller?caller->GetFullName():"0")<<") ["
94                         <<bbGetFullName()<<"]"<<std::endl);
95
96     // If already executing : return
97     if (bbGetExecuting()) 
98       {
99         bbtkDebugMessage("process",3,
100                          " -> already executing : bailing out"<<std::endl);
101         return bbGetStatus();
102       }
103     bbSetExecuting(true);
104     bool wasExecuting = bbGlobalGetSomeBoxExecuting();
105     bbGlobalSetSomeBoxExecuting(true);
106
107     bbtkDebugMessage("process",5,"Initial Status  = "<<bbGetStatus()
108                     <<std::endl);
109     bbtkDebugMessage("process",5,"BoxProcessMode  = "
110                     <<bbGetInputBoxProcessMode()<<std::endl);
111    
112
113     if ( ( bbGetStatus() == MODIFIED ) ||
114         ( bbBoxProcessModeIsAlways() ) )
115       {
116
117         //      bbSetStatus(UPDATING);
118
119         // Updates its inputs
120         IOStatus s = bbUpdateInputs();
121     
122         bbtkDebugMessage("process",6,"=> AtomicBlackBox::bbBackwardUpdate("
123                         <<(caller?caller->GetFullName():"0")<<") ["
124                         <<bbGetFullName()<<"] : Inputs post-update status = "<<s<<std::endl);
125         // If all inputs are in UPTODATE post-update status 
126         // and mProcessMode is not "Always"
127         // then the box is now UPTODATE
128         IOStatus new_status;
129         if ( ( s == UPTODATE ) && 
130             ( ! bbBoxProcessModeIsAlways() ) ) 
131             {
132                 new_status = UPTODATE;
133             }
134         else 
135             {
136                 // else it remains MODIFIED
137                  new_status = MODIFIED;
138             }
139         bbSetStatus(new_status);
140
141         // User process
142         bbProcess();
143
144         // Displays the window (WxBlackbox)
145         bbShowWindow(caller);
146
147
148       }
149     else 
150       {
151         bbtkDebugMessage("process",5,"Up-to-date : nothing to do"<<std::endl);
152       }
153
154     bbtkDebugMessage("process",5,"=> AtomicBlackBox::bbBackwardUpdate("
155                      <<(caller?caller->GetFullName():"0")<<") ["
156                      <<bbGetFullName()<<"] : Final Status    = "
157                      <<bbGetStatus()<<std::endl);
158     bbtkDebugMessage("process",3,
159             "<= AtomicBlackBox::bbBackwardUpdate() ["
160             <<bbGetFullName()<<"]"<<std::endl);
161
162     bbSetExecuting(false);
163     bbGlobalSetSomeBoxExecuting(wasExecuting);
164
165     return bbGetStatus();
166
167   }
168   //=========================================================================
169   
170     
171   //=========================================================================
172   Data AtomicBlackBox::bbGetOutput( const std::string &name )
173   {
174     bbtkDebugMessageInc("Data",7,
175             "AtomicBlackBox::bbGetOutput(\""<<name<<"\") ["
176             <<bbGetFullName()<<"]"
177             <<std::endl);
178     
179     Data p = ((AtomicBlackBoxOutputDescriptor*)bbGetDescriptor()
180                 ->GetOutputDescriptor(name))->GetGetFunctor()->Get(this);
181     
182     bbtkDebugDecTab("Data",7);
183     return p;
184   }
185   //=========================================================================
186   
187   
188   //=========================================================================
189   ///  Gets the input Data of a given name
190   Data AtomicBlackBox::bbGetInput( const std::string &name ) 
191   {
192     bbtkDebugMessageInc("Data",7,
193             "AtomicBlackBox::bbGetInput(\""<<name<<"\") ["
194             <<bbGetFullName()<<"]"
195             <<std::endl);  
196     
197     Data p = ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()
198                 ->GetInputDescriptor(name))->GetGetFunctor()->Get(this);
199     
200     bbtkDebugDecTab("Data",7);
201     return p;
202   }
203   //=========================================================================
204   
205   
206   //=========================================================================
207   ///  Sets the data of the output called <name>
208   void AtomicBlackBox::bbSetOutput( const std::string &name, Data data)
209   {
210     bbtkDebugMessageInc("Data",7,
211             "AtomicBlackBox::bbSetOutput(\""<<name<<"\",data) ["
212             <<bbGetFullName()<<"]"
213             <<std::endl); 
214     
215     ((AtomicBlackBoxOutputDescriptor*)bbGetDescriptor()
216         ->GetOutputDescriptor(name))->GetSetFunctor()->Set(this,data);
217     
218     bbtkDebugDecTab("Data",7);
219   }  
220   //=========================================================================
221   
222   
223   //=========================================================================
224   ///  Sets the data of the input called <name>
225   void AtomicBlackBox::bbSetInput(
226                 const std::string &name,
227                 Data data, 
228                 bool setModified )
229   {
230     bbtkDebugMessageInc("data",7,
231             "AtomicBlackBox::bbSetInput(\""<<name<<"\",data) ["
232             <<bbGetFullName()<<"]"
233             <<std::endl);  
234     ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()->GetInputDescriptor(name))->GetSetFunctor()->Set(this,data);
235     
236     if (setModified) 
237         {
238             bbSetModifiedStatus();
239         }
240     
241     bbtkDebugDecTab("data",7);
242   }
243   //=========================================================================
244   
245     //=========================================================================
246   ///  Sets the data of the input called <name>
247   void AtomicBlackBox::bbBruteForceSetInputPointer
248     (
249                     const std::string &name, 
250                     void* data, 
251                     bool setModified
252     )
253   {
254     bbtkDebugMessageInc("data",7,
255             "AtomicBlackBox::bbBruteForceSetInputPointer(\""
256             <<name<<"\",data) ["
257             <<bbGetFullName()<<"]"
258             <<std::endl);  
259     ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()
260         ->GetInputDescriptor(name))->GetSetFunctor()
261             ->BruteForceSetPointer(this,data);
262     
263     if (setModified) 
264       {
265         bbSetModifiedStatus();
266       }
267     
268     bbtkDebugDecTab("data",7);
269   }
270   //=========================================================================
271  
272
273
274   //==========================================================================
275   std::string AtomicBlackBox::GetObjectInfo() const 
276   {
277     std::stringstream i;
278     return i.str();
279   }
280   //==========================================================================
281
282   //==========================================================================
283   size_t AtomicBlackBox::GetObjectSize() const 
284   {
285     return sizeof(*this);
286   }
287   //==========================================================================
288   
289   //==========================================================================
290   size_t AtomicBlackBox::GetObjectRecursiveSize() const 
291   {
292     size_t s = GetObjectSize();
293     return s;
294   }
295   //==========================================================================
296
297  
298 }
299 // EO namespace bbtk