]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkConnection.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkConnection.cxx
index 2c99b6e2518a8a274b59357c1bfa45eadc2f6c54..29bab6cc40a63308c6c3fca425e676403cd1ce3a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkConnection.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/04/08 06:59:30 $
-  Version:   $Revision: 1.5 $
+  Date:      $Date: 2008/04/09 11:16:57 $
+  Version:   $Revision: 1.6 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See doc/license.txt or
@@ -44,10 +44,10 @@ namespace bbtk
                        <<to->bbGetName()<<"\",\""<<input<<"\")"
                        <<std::endl);    
 
-    mFrom = from;
-    mTo = to;
-    mInput = input;
-    mOutput = output;
+    mFrom = mOriginalFrom = from;
+    mTo = mOriginalTo = to;
+    mInput = mOriginalInput = input;
+    mOutput = mOriginalOutput = output;
     
 
     if (! from->bbHasOutput(output) )
@@ -124,8 +124,8 @@ namespace bbtk
   
   void Connection::Clear()
   {
-    mFrom = 0;
-    mTo = 0;
+    mFrom = mOriginalFrom = 0;
+    mTo = mOriginalTo = 0;
     mAdaptor = 0;
   }
 
@@ -136,10 +136,11 @@ namespace bbtk
     bbtkDebugMessageInc("Kernel",7,
                        "Connection::~Connection() ["
                        <<GetFullName()<<"]"<<std::endl);
+    std::cout << "~Connection() " << GetFullName() << std::endl;
 
-    if (mFrom) mFrom->bbDisconnectOutput(mOutput,this);
-    if (mTo) mTo->bbDisconnectInput(mInput,this);
-    if (mAdaptor) mAdaptor->bbDelete();
+    if (mFrom!=0) mFrom->bbDisconnectOutput(mOutput,this);
+    if (mTo!=0) mTo->bbDisconnectInput(mInput,this);
+    if (mAdaptor!=0) mAdaptor->bbDelete();
 
     bbtkDebugDecTab("Kernel",7);
   }
@@ -320,14 +321,108 @@ namespace bbtk
   
   //==================================================================
   std::string Connection::GetFullName() const {
-    if (mFrom && mTo)
-      return  mFrom->bbGetName()+"."+mOutput+"--"
-       +mTo->bbGetName()+"."+mInput;
+    if (mFrom && mTo) 
+      {
+       std::string res = mFrom->bbGetName()+"."+mOutput+"--"
+         +mTo->bbGetName()+"."+mInput;
+       if ((mFrom!=mOriginalFrom)||(mTo!=mOriginalTo))
+         {
+           res += "("+mOriginalFrom->bbGetName()+"."+mOriginalOutput+"--"
+             + mOriginalTo->bbGetName()+"."+mOriginalInput+")";
+         }
+       return res;
+      }
     return "***Invalid Connection***";
   }
   //==================================================================
 
+  //==================================================================
+  void Connection::Check() const
+  {
+    bbtkMessage("Debug",1,"** Checking Connection "<<(void*)this<<" ["<<GetFullName()<<"]"
+               <<std::endl);
+    if (mFrom==0) 
+      {
+       bbtkMessage("Debug",2," - From = 0"<<std::endl);
+      }
+    else
+      {
+       bbtkMessage("Debug",2," - From : "<<mFrom->bbGetFullName()<<std::endl);
+       if (!mFrom->bbHasOutput(mOutput))
+         {
+           bbtkError(mFrom->bbGetFullName()<<" does not have output '"
+                     <<mOutput<<"'");
+         }     
+       bbtkMessage("Debug",2," - From : Output '"<<mOutput<<"' exists"<<std::endl);
+       BlackBox::OutputConnectorMapType::const_iterator i 
+         = mFrom->bbGetOutputConnectorMap().find(mOutput);
+       if (i== mFrom->bbGetOutputConnectorMap().end())
+         {
+            bbtkError(mFrom->bbGetFullName()<<" output '"
+                      <<mOutput<<"' is not in OutputConnectorMap");
+         }
+       bbtkMessage("Debug",2," - From : Output '"<<mOutput
+                   <<"' is in OutputConnectorMap"<<std::endl);
+
+        std::vector< Connection * >::const_iterator j;
+       j = find(i->second->GetConnectionVector().begin(),
+                i->second->GetConnectionVector().end(),
+                this);
+       if (j==i->second->GetConnectionVector().end())
+         {
+           bbtkError("Connection ["<<GetFullName()<<"] : "
+                     <<" OutputConnector '"
+                     <<mOutput<<"' of "<<mFrom->bbGetFullName()
+                     <<" does not point to this connection");
+           
+         }
+       bbtkMessage("Debug",2," - From : This connection is in OutputConnector connection vector"<<std::endl);
+       bbtkMessage("Debug",1," * Box from : Check successfull"<<std::endl);
 
+      }
+
+    if (mTo==0) 
+      {
+       bbtkMessage("Debug",2," - To   = 0"<<std::endl);
+      }
+    else
+      {
+       bbtkMessage("Debug",2," - To   : "<<mTo->bbGetName()<<std::endl);
+       std::cout << mTo << std::endl;
+       std::cout << mTo->bbGetDescriptor() << std::endl;
+       std::cout << mTo->bbGetDescriptor()->GetTypeName() << std::endl;
+       mTo->bbGetFullName();
+       bbtkMessage("Debug",2," - To   : "<<mTo->bbGetFullName()<<std::endl);
+       if (!mTo->bbHasInput(mInput))
+         {
+           bbtkError(mTo->bbGetFullName()<<" does not have input '"
+                     <<mInput<<"'");
+         }     
+       bbtkMessage("Debug",2," - To   : Input '"<<mInput<<"' exists"<<std::endl);
+       BlackBox::InputConnectorMapType::const_iterator i 
+         = mTo->bbGetInputConnectorMap().find(mInput);
+       if (i== mTo->bbGetInputConnectorMap().end())
+         {
+            bbtkError(mTo->bbGetFullName()<<" input '"
+                      <<mInput<<"' is not in InputConnectorMap");
+         }
+       bbtkMessage("Debug",2," - To   : Input '"<<mInput
+                   <<"' is in InputConnectorMap"<<std::endl);
+
+       if (i->second->GetConnection()==0)
+         {
+           bbtkError("Connection "<<GetFullName()<<" : "
+                     <<" InputConnector '"
+                     <<mInput<<"' of "<<mTo->bbGetFullName()
+                     <<" does not point to this connection");
+    
+         }
+       bbtkMessage("Debug",2," - To   : This connection is in InputConnector connection vector"<<std::endl);
+       bbtkMessage("Debug",1," * Box to   : Check successfull"<<std::endl);
+
+      }
+  }
+  //==================================================================
 
 }// namespace bbtk