]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBoxOutputConnector.cxx
#2696 BBTK Bug New Normal - BoxChange BoxExecute not responding at the second actio...
[bbtk.git] / kernel / src / bbtkBlackBoxOutputConnector.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkBlackBoxOutputConnector.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.14 $
34 =========================================================================*/
35
36
37 /**
38  *  \file 
39  *  \brief Class bbtk::BlackBoxOutputConnector : 
40  */
41
42 #include "bbtkBlackBoxOutputConnector.h"
43 #include "bbtkMessageManager.h"
44 #include "bbtkBlackBox.h"
45 //#include <algorithm>
46
47 namespace bbtk
48 {
49
50   //========================================================================
51   /// The Pimpl
52   class BlackBoxOutputConnector::Pimpl
53   {
54   public:
55     Pimpl() : mStatus(OUTOFDATE) {}
56     Pimpl(const Pimpl&) {}
57    /// 
58     BlackBoxWeakPointer mBox;
59     /// The vector of output connections
60     ConnectionVector mConnection;
61     /// The status of the output 
62     IOStatus mStatus;
63     /// The output changed signal 
64     BlackBox::OutputChangeSignalType mChangeSignal;
65   };
66   //========================================================================
67
68   //========================================================================
69   BBTK_IMPL_PIMPL(BlackBoxOutputConnector)
70   //========================================================================
71
72
73   //======================================================================
74   BlackBoxOutputConnector::BlackBoxOutputConnector(BlackBox::Pointer b) 
75   {
76     bbtkDebugMessage("kernel",9,
77                      "["<<b->bbGetName()
78                      <<"] BlackBoxOutputConnector()"<<std::endl);
79     PimplConstruct();
80     p->mBox = b;
81   }
82   //======================================================================
83
84
85   //======================================================================
86   BlackBoxOutputConnector::~BlackBoxOutputConnector() 
87   {
88     bbtkDebugMessage("kernel",9,
89                      "[DEAD BOX] ==> ~BlackBoxOutputConnector()"
90                      <<std::endl);
91     /*
92     ConnectionVector::iterator i;
93     for (i=mConnection.begin();
94          i!=mConnection.end();
95          ++i)
96       (*i) = Connection::WeakPointer();
97     */
98     p->mConnection.clear();
99     PimplDestruct();
100   
101     bbtkDebugMessage("kernel",9,
102                      "[DEAD BOX] <== ~BlackBoxOutputConnector()"
103                      <<std::endl);
104   }
105   //======================================================================
106
107   //======================================================================
108   ///
109   void BlackBoxOutputConnector::SetConnection(Connection* c)
110   {
111     bbtkDebugMessage("kernel",9,
112                      "["<<p->mBox.lock()->bbGetName()
113                      <<"] BlackBoxOutputConnector::SetConnection("
114                      <<c<<")"<<std::endl);
115     p->mConnection.push_back(c);
116     //    AddChangeObserver(boost::bind(&Connection::SignalChange,c));
117   }
118   //======================================================================
119
120
121   //======================================================================
122   void BlackBoxOutputConnector::UnsetConnection(Connection* c)
123   {
124     bbtkDebugMessage("kernel",9,"["<<p->mBox.lock()->bbGetName()
125                      <<"] BlackBoxOutputConnector::UnsetConnection("
126                      <<c<<")"<<std::endl);
127
128     if (!c) 
129       {
130         bbtkInternalError(p->mBox.lock()->bbGetFullName()
131                           <<": BlackBoxOutputConnector::UnsetConnection("
132                           <<c<<") : invalid connection");
133
134       }
135     //    c->Check();
136     //Connection::WeakPointer w(c);
137     ConnectionVector::iterator i;
138     //  = find(mConnection.begin(),mConnection.end(),c);
139     for (i=p->mConnection.begin();
140          i!=p->mConnection.end();
141          ++i)
142       {
143         if (*i==c) break;
144       }
145     if (i==p->mConnection.end())
146       {
147         bbtkInternalError(p->mBox.lock()->bbGetFullName()
148                           <<": BlackBoxOutputConnector::UnsetConnection("
149                           <<c
150                           <<") : connection is absent from connections list");
151       }
152     p->mConnection.erase(i);
153     //    RemoveChangeObserver(boost::bind(&Connection::SignalChange,c));
154
155
156   }
157   //======================================================================
158   
159   //======================================================================
160   const BlackBoxOutputConnector::ConnectionVector& 
161   BlackBoxOutputConnector::GetConnectionVector() const
162   { 
163     return p->mConnection; 
164   }
165   //======================================================================
166   
167   //======================================================================
168   /// Returns the status of the input 
169   IOStatus BlackBoxOutputConnector::GetStatus() const 
170   { 
171     return p->mStatus; 
172   }
173   //======================================================================
174
175   //======================================================================
176   /// Sets the status of the input 
177   void BlackBoxOutputConnector::SetStatus( IOStatus s ) 
178   {
179     p->mStatus = s; 
180   }
181   //======================================================================
182   
183   //======================================================================
184   void BlackBoxOutputConnector::SignalChange( BlackBox::Pointer box,
185                                               const std::string& output )
186   {
187     IOStatus s = OUTOFDATE; //mStatus;
188     //if (s==UPTODATE) s=MODIFIED;
189     
190     bbtkDebugMessage("change",2,
191                      "["<<box->bbGetName()
192                      <<"] ==> BlackBoxOutputConnector::SignalChange('"
193                      <<output<<"','"<<GetIOStatusString(s)<<"') ["
194                      <<this<<"]"
195                      <<std::endl);
196     
197     //    std::cout<<"BlackBoxOutputConnector::SignalChange("
198     //       <<box->bbGetName()<<",'"
199     //       <<output<<"')"<<std::endl;
200     p->mChangeSignal(box,output,s);
201     
202     bbtkDebugMessage("change",2,
203                      "["<<box->bbGetName()
204                      <<"] <== BlackBoxOutputConnector::SignalChange('"
205                      <<output<<"','"<<GetIOStatusString(s)<<"') ["
206                      <<this<<"]"
207                      <<std::endl);
208   }
209   //======================================================================
210
211   //======================================================================
212   void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
213   { 
214     //    std::cout << "BlackBoxOutputConnector::AddChangeObserver" << std::endl;
215     p->mChangeSignal.connect(f); 
216   }
217   //======================================================================
218   
219   //======================================================================
220   /// Removes the function f from the list of functions to call when 
221   /// the output changes (TO WRITE)
222   void BlackBoxOutputConnector::RemoveChangeObserver(OutputChangeCallbackType f)
223   { 
224     bbtkError("BlackBoxOutputConnector::RemoveChangeObserver not implemented");
225     
226     //mChangeSignal.disconnect(f);
227   }
228   //======================================================================
229 }
230 // namespace bbtk
231