]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBoxOutputConnector.cxx
Fixed Window deletion mechanism
[bbtk.git] / kernel / src / bbtkBlackBoxOutputConnector.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkBlackBoxOutputConnector.cxx,v $
4   Language:  C++
5   Date:      $Date: 2009/05/28 08:12:05 $
6   Version:   $Revision: 1.12 $
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::BlackBoxOutputConnector : 
35  */
36
37 #include "bbtkBlackBoxOutputConnector.h"
38 #include "bbtkMessageManager.h"
39 #include "bbtkBlackBox.h"
40 //#include <algorithm>
41
42 namespace bbtk
43 {
44
45   //======================================================================
46   BlackBoxOutputConnector::BlackBoxOutputConnector(BlackBox::Pointer b) 
47     : mBox(b),
48       mStatus(OUTOFDATE)
49   {
50     bbtkDebugMessage("kernel",9,
51                      "["<<b->bbGetName()
52                      <<"] BlackBoxOutputConnector()"<<std::endl);
53   }
54   //======================================================================
55
56
57   //======================================================================
58   BlackBoxOutputConnector::~BlackBoxOutputConnector() 
59   {
60     bbtkDebugMessage("kernel",9,
61                      "[NULL"//<<mBox.lock()->bbGetName()
62                      <<"] ==> ~BlackBoxOutputConnector()"
63                      <<std::endl);
64     /*
65     ConnectionVector::iterator i;
66     for (i=mConnection.begin();
67          i!=mConnection.end();
68          ++i)
69       (*i) = Connection::WeakPointer();
70     */
71     mConnection.clear();
72     bbtkDebugMessage("kernel",9,
73                      "[NULL"//<<mBox.lock()->bbGetName()
74                      <<"] <== ~BlackBoxOutputConnector()"
75                      <<std::endl);
76   }
77   //======================================================================
78
79   //======================================================================
80   ///
81   void BlackBoxOutputConnector::SetConnection(Connection* c)
82   {
83     bbtkDebugMessage("kernel",9,
84                      "["<<mBox.lock()->bbGetName()
85                      <<"] BlackBoxOutputConnector::SetConnection("
86                      <<c<<")"<<std::endl);
87     mConnection.push_back(c);
88     //    AddChangeObserver(boost::bind(&Connection::SignalChange,c));
89   }
90   //======================================================================
91
92
93   //======================================================================
94   void BlackBoxOutputConnector::UnsetConnection(Connection* c)
95   {
96     bbtkDebugMessage("kernel",9,"["<<mBox.lock()->bbGetName()
97                      <<"] BlackBoxOutputConnector::UnsetConnection("
98                      <<c<<")"<<std::endl);
99
100     if (!c) 
101       {
102         bbtkInternalError(mBox.lock()->bbGetFullName()
103                           <<": BlackBoxOutputConnector::UnsetConnection("
104                           <<c<<") : invalid connection");
105
106       }
107     //    c->Check();
108     //Connection::WeakPointer w(c);
109     ConnectionVector::iterator i;
110     //  = find(mConnection.begin(),mConnection.end(),c);
111     for (i=mConnection.begin();
112          i!=mConnection.end();
113          ++i)
114       {
115         if (*i==c) break;
116       }
117     if (i==mConnection.end())
118       {
119         bbtkInternalError(mBox.lock()->bbGetFullName()
120                           <<": BlackBoxOutputConnector::UnsetConnection("
121                           <<c
122                           <<") : connection is absent from connections list");
123       }
124     mConnection.erase(i);
125     //    RemoveChangeObserver(boost::bind(&Connection::SignalChange,c));
126
127
128   }
129   //======================================================================
130
131   
132    //======================================================================
133   void BlackBoxOutputConnector::SignalChange( BlackBox::Pointer box,
134                                               const std::string& output )
135   {
136     IOStatus s = OUTOFDATE; //mStatus;
137     //if (s==UPTODATE) s=MODIFIED;
138     
139     bbtkDebugMessage("change",2,
140                      "["<<box->bbGetName()
141                      <<"] ==> BlackBoxOutputConnector::SignalChange('"
142                      <<output<<"','"<<GetIOStatusString(s)<<"') ["
143                      <<this<<"]"
144                      <<std::endl);
145     
146     //    std::cout<<"BlackBoxOutputConnector::SignalChange("
147     //       <<box->bbGetName()<<",'"
148     //       <<output<<"')"<<std::endl;
149     mChangeSignal(box,output,s);
150     
151     bbtkDebugMessage("change",2,
152                      "["<<box->bbGetName()
153                      <<"] <== BlackBoxOutputConnector::SignalChange('"
154                      <<output<<"','"<<GetIOStatusString(s)<<"') ["
155                      <<this<<"]"
156                      <<std::endl);
157   }
158   //======================================================================
159  /*
160   void BlackBoxOutputConnector::SetModifiedStatus()
161   {
162     bbtkDebugMessage("modified",2,
163                      "==> BlackBoxOutputConnector::SetModifiedStatus() ["
164                      <<this<<"]"
165                      <<std::endl);
166     ConnectionVector::iterator i;
167     for (i=mConnection.begin();i!=mConnection.end();++i) 
168       {
169         (*i)->SetModifiedStatus();
170       }
171     
172     
173    }
174   */
175   /*
176   //======================================================================
177   void BlackBoxOutputConnector::SetChangeTime(const ChangeTime& t)
178   {
179     bbtkDebugMessage("change",2,
180                      "==> BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
181                      <<this<<"]"
182                      <<std::endl);
183     if (mChangeTime.Set(t))
184       {
185         mChangeSignal(this);
186       }
187     bbtkDebugMessage("change",2,
188                      "<== BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
189                      <<this<<"]"
190                      <<std::endl);
191   }
192   //======================================================================
193   */
194   /*
195  //======================================================================
196   void BlackBoxOutputConnector::SetChangeTimeToCurrentTime()
197   {
198     bbtkDebugMessage("change",2,
199                      "==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
200                      <<this<<"]"
201                      <<std::endl);
202     mChangeTime.Set(ChangeTime::GetCurrentTime());
203     mChangeSignal(this);
204     
205     bbtkDebugMessage("change",2,
206                      "<==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
207                      <<this<<"]"
208                      <<std::endl);
209   }
210   //======================================================================
211   */
212
213
214   //======================================================================
215   void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
216   { 
217     //    std::cout << "BlackBoxOutputConnector::AddChangeObserver" << std::endl;
218     mChangeSignal.connect(f); 
219   }
220   //======================================================================
221   
222   //======================================================================
223   /// Removes the function f from the list of functions to call when 
224   /// the output changes (TO WRITE)
225   void BlackBoxOutputConnector::RemoveChangeObserver(OutputChangeCallbackType f)
226   { 
227     bbtkError("BlackBoxOutputConnector::RemoveChangeObserver not implemented");
228     
229     //mChangeSignal.disconnect(f);
230   }
231   //======================================================================
232 }
233 // namespace bbtk
234