X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkComplexBlackBox.cxx;h=f47e401248fdf3c0c5bd7fec30479eec353721a1;hb=e6b2de923e0e69c303c7d18fb8a5c1970541bb3a;hp=be9fec2b348034fd5492eb11817b8b3ca8cf4eec;hpb=efd5498c468f0151a9f8e67ff28c4e54ba57af50;p=bbtk.git diff --git a/kernel/src/bbtkComplexBlackBox.cxx b/kernel/src/bbtkComplexBlackBox.cxx index be9fec2..f47e401 100644 --- a/kernel/src/bbtkComplexBlackBox.cxx +++ b/kernel/src/bbtkComplexBlackBox.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkComplexBlackBox.cxx,v $ Language: C++ -Date: $Date: 2008/02/19 18:40:10 $ -Version: $Revision: 1.6 $ +Date: $Date: 2008/07/24 14:37:05 $ +Version: $Revision: 1.20 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -22,6 +22,7 @@ PURPOSE. See the above copyright notices for more information. * \brief class bbtk::ComplexBlackBox : user defined complex black boxes */ #include "bbtkComplexBlackBox.h" +#include "bbtkWx.h" #include "bbtkBlackBoxDescriptor.h" #include "bbtkFactory.h" #include "bbtkConfigurationFile.h" @@ -29,19 +30,37 @@ PURPOSE. See the above copyright notices for more information. namespace bbtk { + //========================================================================== + /// Creates a new complex black box + ComplexBlackBox::Pointer ComplexBlackBox::New(const std::string& name, + ComplexBlackBoxDescriptor::Pointer desc) + { + bbtkDebugMessage("object",1,"##> ComplexBlackBox::New('"<GetTypeName()<<"')" <GetTypeName()<<"')" < ComplexBlackBox::ComplexBlackBox(\"" + < ComplexBlackBox::ComplexBlackBox(\"" <first<<"\""<second->bbClone(i->second->bbGetName()); + bbtkDebugMessageInc("object",5," * Cloning \""<first<<"\""<second->bbClone(i->second->bbGetName()); bbUnsafeAddBlackBox(B); - - bbtkDebugDecTab("Kernel",9); } - bbtkDebugDecTab("Kernel",9); - bbtkDebugMessageInc("Kernel",9,"* Cloning Connections"<GetFullName()<<"\""<GetFullName()<<"\""<GetBlackBoxFrom()->bbGetName() ); - BlackBox* bbto = bbGetBlackBox( (*j)->GetBlackBoxTo()->bbGetName() ); - Connection* c = /*mDescriptor->GetFactory()->Create*/ + BlackBox::Pointer bbfrom = bbGetBlackBox( (*j)->GetOriginalBlackBoxFrom()->bbGetName() ); + BlackBox::Pointer bbto = bbGetBlackBox( (*j)->GetOriginalBlackBoxTo()->bbGetName() ); + + Connection::Pointer c = mDescriptor.lock()->GetFactory()-> NewConnection( bbfrom, - (*j)->GetBlackBoxFromOutput(), + (*j)->GetOriginalBlackBoxFromOutput(), bbto, - (*j)->GetBlackBoxToInput() ); + (*j)->GetOriginalBlackBoxToInput() ); + //c->Check(); bbAddConnection(c); - bbtkDebugDecTab("Kernel",9); } - bbtkDebugDecTab("Kernel",9); bbAllocateConnectors(); - bbtkDebugDecTab("Kernel",9); + bbtkDebugMessage("object",3, + "<## ComplexBlackBox::ComplexBlackBox(\"" + <GetFullName()<<"\""<first<<"\""<second->bbDelete(); - bbtkDebugDecTab("Kernel",9); - } - bbtkDebugDecTab("Kernel",9); - // bbtkDebugMessage("Kernel",9,"EO ComplexBlackBox::~ComplexBlackBox [" - // < ComplexBlackBox::~ComplexBlackBox() [" + < Releasing connections"< Releasing boxes"<bbDesallocateConnectors(); - bbtkDebugDecTab("Kernel",9); + + bbtkDebugMessage("object",3, + "<== ComplexBlackBox::~ComplexBlackBox() [" + <GetInputDescriptorMap(); @@ -160,7 +173,6 @@ namespace bbtk ->bbGetInputConnectorMap()[ d->GetInput() ]; bbGetInputConnectorMap()[i->second->GetName()] = c; -//new BlackBoxInputConnector(); } // Output connectors @@ -180,8 +192,8 @@ namespace bbtk ->bbGetOutputConnectorMap()[ d->GetOutput() ]; bbGetOutputConnectorMap()[o->second->GetName()] = c; - //new BlackBoxOutputConnector(); } + bbtkDebugDecTab("Kernel",8); } //========================================================================= @@ -208,17 +220,14 @@ namespace bbtk //========================================================================= //======================================================================= - BlackBox* ComplexBlackBox::bbClone(const std::string& name) + BlackBox::Pointer ComplexBlackBox::bbClone(const std::string& name) { bbtkDebugMessageInc("Kernel",9, "ComplexBlackBox::bbClone(\""< ComplexBlackBox::bbExecute() [" < Executing '"<<*i<<"'"< Executing '"<<*i<<"'"<bbExecute(force); } } else { - std::map::iterator i; + std::map::iterator i; for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i) { i->second->bbExecute(force); } } - Wx::EndBusyCursor(); - - bbtkDebugDecTab("Process",1); - } //================================================================== //================================================================== void ComplexBlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c) { - bbtkDebugMessage("Process",3, - "ComplexBlackBox::bbSetModifiedStatus(" + bbtkDebugMessage("modified",1, + "==> ComplexBlackBox::bbSetModifiedStatus(" <GetBlackBox()->bbSetModifiedStatus(c); - bbtkDebugMessage("Process",3, - "EO ComplexBlackBox::bbSetModifiedStatus(" + /* + bbtkDebugMessage("modified",1, + "<== ComplexBlackBox::bbSetModifiedStatus(" <GetFullName()<<") [" + bbtkDebugMessageInc("process",3, + "==> ComplexBlackBox::bbBackwardUpdate(" + <<(caller?caller->GetFullName():"0")<<") [" <GetBlackBoxFrom()->bbGetFullName() + <<"."<GetBlackBoxFromOutput()<<"----" + <GetOriginalBlackBoxFrom()->bbGetFullName() + <<"."<GetOriginalBlackBoxFromOutput()<second; // Get the internal box - BlackBox* b = bbUnsafeGetBlackBox ( d->GetTarget() ); + BlackBox::Pointer b = bbUnsafeGetBlackBox ( d->GetTarget() ); // Calls BackwardUpdate on it - bbtkDebugMessageInc("Process",2,"Internal box connected to output : "<GetTarget()<GetTarget()<GetBlackBoxFromOutput(); + // std::cout << "oldout = "<GetFullName()<<"' does not point to a valid output of the complex box !"); } - bbtkDebugDecTab("Process",1); - return s; - } - //================================================================== - - /* - //================================================================== - void ComplexBlackBox::bbForwardUpdate(Connection* caller) - { - bbtkDebugMessageInc("Process",1, - "ComplexBlackBox::bbForwardUpdate("<GetFullName()<<") [" - <GetInputDescriptorMap(); - BlackBoxDescriptor::InputDescriptorMapType::const_iterator i - = imap.find(caller->GetBlackBoxToInput()); - if (i!=imap.end()) - { - // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor - ComplexBlackBoxInputDescriptor* d = - (ComplexBlackBoxInputDescriptor*)i->second; - // Get the internal box - BlackBox* b = bbUnsafeGetBlackBox ( d->GetTarget() ); - // Calls ForwardUpdate on it - bbtkDebugMessage("Process",2,"-> Internal box connected to input : "<GetTarget()<bbForwardUpdate(caller); - } - else - { - bbtkError("Connection '"<GetFullName()<<"' does not point to a valid input of the complex box !"); - } - bbtkDebugDecTab("Process",1); + return s; + } //================================================================== - */ //================================================================== @@ -457,9 +465,73 @@ namespace bbtk } //================================================================== + //========================================================================= + /// Connects the input to the connection c + void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c) + { + bbtkDebugMessage("connection",2, + "==> ComplexBlackBox::bbConnectInput(\"" + <GetFullName()<<") [" + <GetInputDescriptor(name); + + + BlackBox::Pointer t = bbGetBlackBox(d->GetTarget()); + + bbtkDebugMessage("connection",2," - Target = "<GetTarget()<<" = "<bbGetFullName()<SetBlackBoxTo(t); + c->SetBlackBoxToInput(d->GetInput()); + + bbtkDebugMessage("connection",2," - New conn = "<GetFullName()<bbConnectInput(d->GetInput(),c); + + bbtkDebugMessage("connection",2, + "<== ComplexBlackBox::bbConnectInput(\"" + <GetFullName()<<") [" + < to the connection c + void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c) + { + bbtkDebugMessage("connection",2, + "==> ComplexBlackBox::bbConnectOutput(\"" + <GetFullName()<<") [" + <GetOutputDescriptor(name); + + BlackBox::Pointer t = bbGetBlackBox(d->GetTarget()); + + bbtkDebugMessage("connection",2," - Target = "<GetTarget()<<" = "<bbGetFullName()<SetBlackBoxFrom(t); + c->SetBlackBoxFromOutput(d->GetOutput()); + + bbtkDebugMessage("connection",2," - New conn = "<GetFullName()<bbConnectOutput(d->GetOutput(),c); + + bbtkDebugMessage("connection",2, + "<== ComplexBlackBox::bbConnectOutput(\"" + <GetFullName()<<") [" + <bbGetName() @@ -471,7 +543,7 @@ namespace bbtk bbtkError("a black box called \""<bbGetName() <<"\" already exists"); } - b->bbSetParent(this); + b->bbSetParent(GetThisPointer()); mBlackBoxMap[b->bbGetName()] = b; bbtkDebugDecTab("Kernel",7); @@ -480,14 +552,14 @@ namespace bbtk //================================================================== /// Adds the black box to the complex box (unsafe) - void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox* b) + void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox::Pointer b) { bbtkDebugMessageInc("Kernel",7, "ComplexBlackBox::UnsafeAddBlackBox(\""<bbGetName() <<"\") [" <bbSetParent(this); + b->bbSetParent(GetThisPointer()); mBlackBoxMap[b->bbGetName()] = b; bbtkDebugDecTab("Kernel",7); @@ -496,13 +568,39 @@ namespace bbtk //================================================================== /// Removes the black box from the complex box - void ComplexBlackBox::bbRemoveBlackBox( const std::string& name ) + void ComplexBlackBox::bbRemoveBlackBox( const std::string& name, + bool remove_connections ) { bbtkDebugMessageInc("Kernel",7, "ComplexBlackBox::RemoveBlackBox(\""<second; + + if (remove_connections) + { + ConnectionListType::const_iterator j; + for ( j = mConnectionList.begin(); + j != mConnectionList.end(); ++j ) + { + (*j)->Check(); + } + } + if (p.use_count()!=1) + { + bbtkError("the black box \""< - BlackBox* ComplexBlackBox::bbGetBlackBox( const std::string& name ) + BlackBox::Pointer ComplexBlackBox::bbGetBlackBox( const std::string& name ) { bbtkDebugMessageInc("Kernel",9, "ComplexBlackBox::GetBlackBox(\""< : does not throw an exception /// if it does not exist but return a null pointer - BlackBox* ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name ) + BlackBox::Pointer ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name ) { bbtkDebugMessageInc("Kernel",9, "ComplexBlackBox::UnsafeGetBlackBox(\""<"); @@ -621,11 +719,7 @@ namespace bbtk } BlackBoxMapType::iterator i = mBlackBoxMap.find(subname); - if ( i == mBlackBoxMap.end() ) - { - blackbox = NULL; - } - else + if ( i != mBlackBoxMap.end() ) { blackbox = i->second; if (restname!="") @@ -679,7 +773,9 @@ namespace bbtk fprintf(ff,"rankdir=LR%s\n",";"); fprintf(ff,"node [shape=record]%s\n",";"); - this->bbWriteDotFileBlackBox(ff,this,detail,level, + this->bbWriteDotFileBlackBox(ff, + GetThisPointer(), + detail,level, instanceOrtype, relative_link ); @@ -720,14 +816,14 @@ namespace bbtk //========================================================================= /// Write Graphviz-dot description in file void ComplexBlackBox::bbWriteDotFileBlackBox(FILE *ff, - BlackBox *parentblackbox, + BlackBox::Pointer parentblackbox, int detail, int level, bool instanceOrtype, bool relative_link ) { std::string tmp1; std::string valueStr(""); - Package *package = this->bbGetDescriptor()->GetPackage(); + Package::Pointer package = this->bbGetDescriptor()->GetPackage(); if (package!=NULL) { @@ -751,7 +847,7 @@ namespace bbtk } std::string boxname="["+bbGetTypeName()+"]"; - if (this!=parentblackbox) + if (GetThisPointer()!=parentblackbox) { if (detail==0) { @@ -858,7 +954,9 @@ namespace bbtk { if (level>-1) { - j->second->bbWriteDotFileBlackBox(ff,parentblackbox,detail, + j->second->bbWriteDotFileBlackBox(ff, + parentblackbox, + detail, level-1, instanceOrtype, relative_link); @@ -885,7 +983,7 @@ namespace bbtk fprintf(ff,":%s",cbbid->GetName().c_str() ); } fprintf(ff,"->" ); - BlackBox *bb = bbGetBlackBox( cbbid->GetTarget() ); + BlackBox::Pointer bb = bbGetBlackBox( cbbid->GetTarget() ); bb->bbWriteDotInputOutputName(ff,true,detail,level); if (detail==1) { @@ -906,7 +1004,7 @@ namespace bbtk { ComplexBlackBoxOutputDescriptor *cbbod = (ComplexBlackBoxOutputDescriptor*)yy->second; fprintf(ff," "); - BlackBox *bb = bbGetBlackBox( cbbod->GetTarget() ); + BlackBox::Pointer bb = bbGetBlackBox( cbbod->GetTarget() ); bb->bbWriteDotInputOutputName(ff,false,detail,level); if (detail==1) { @@ -926,7 +1024,7 @@ namespace bbtk // Relation from the out side of this ComplexBlackBox with its Inputs - if (this!=parentblackbox) { + if (GetThisPointer()!=parentblackbox) { for ( ii = bbGetInputConnectorMap().begin(); ii != bbGetInputConnectorMap().end(); ++ii ) { @@ -934,19 +1032,19 @@ namespace bbtk { Connection* con = ii->second->GetConnection(); if (con!=NULL){ - BlackBox *a=con->GetBlackBoxFrom(); - BlackBox *b=con->GetBlackBoxTo(); + BlackBox::Pointer a=con->GetOriginalBlackBoxFrom(); + BlackBox::Pointer b=con->GetOriginalBlackBoxTo(); fprintf(ff," "); a->bbWriteDotInputOutputName(ff,false,detail,level); if (detail==1) { - fprintf(ff,":%s",con->GetBlackBoxFromOutput().c_str()); + fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str()); } fprintf(ff,"->"); b->bbWriteDotInputOutputName(ff,true,detail,level); if (detail==1) { - fprintf(ff,":%s",con->GetBlackBoxToInput().c_str()); + fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str()); } fprintf(ff,"%s\n",";"); } // if con @@ -955,9 +1053,11 @@ namespace bbtk } // if parentblackbox } //========================================================================= + + - /* + /* //======================================================================= /// Generates the list of the packages of which its depends @@ -974,4 +1074,97 @@ namespace bbtk } //======================================================================= */ + + //======================================================================= + void ComplexBlackBox::Check(bool recursive) + { + bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this + <<" ["<second->Check(recursive); + } + ConnectionListType::const_iterator j; + for ( j = mConnectionList.begin(); + j != mConnectionList.end(); ++j ) + { + (*j)->Check(); + } + bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this + <<" ["<GetFullTypeName() + ":" + bbGetName(); + } + else + { + return std::string(":") + bbGetName(); + } + } + //========================================================================= + + //========================================================================== + std::string ComplexBlackBox::GetObjectName() const + { + return std::string("ComplexBlackBox '")+bbGetNameWithParent() + +std::string("'"); + } + //========================================================================== + + //========================================================================== + std::string ComplexBlackBox::GetObjectInfo() const + { + std::stringstream i; + i << " - "<second->GetObjectRecursiveSize(); + } + ConnectionListType::const_iterator j; + for ( j = mConnectionList.begin(); + j != mConnectionList.end(); ++j ) + { + s += (*j)->GetObjectRecursiveSize(); + } + return s; + } + //========================================================================== + }