X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkComplexBlackBox.cxx;h=47b983717e5b27d0b34b0c68470ca041fb499862;hb=cc134f89048428aca99fa855a7e1e87c815a3413;hp=ec6f1c313ff1ab39642e347903fa14ec081b6f98;hpb=71376d8384d5d21b5c56d36ecc8cbf31315c039a;p=bbtk.git diff --git a/kernel/src/bbtkComplexBlackBox.cxx b/kernel/src/bbtkComplexBlackBox.cxx index ec6f1c3..47b9837 100644 --- a/kernel/src/bbtkComplexBlackBox.cxx +++ b/kernel/src/bbtkComplexBlackBox.cxx @@ -1,27 +1,40 @@ -/*========================================================================= - -Program: bbtk -Module: $RCSfile: bbtkComplexBlackBox.cxx,v $ -Language: C++ -Date: $Date: 2008/02/05 13:23:46 $ -Version: $Revision: 1.2 $ - -Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de -l'Image). All rights reserved. See Doc/License.txt or -http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notices for more information. - +/*========================================================================= + Program: bbtk + Module: $RCSfile: bbtkComplexBlackBox.cxx,v $ + Language: C++ + Date: $Date: 2008/12/12 12:11:21 $ + Version: $Revision: 1.24 $ =========================================================================*/ +/* --------------------------------------------------------------------- + +* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale) +* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux +* +* This software is governed by the CeCILL-B license under French law and +* abiding by the rules of distribution of free software. You can use, +* modify and/ or redistribute the software under the terms of the CeCILL-B +* license as circulated by CEA, CNRS and INRIA at the following URL +* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +* or in the file LICENSE.txt. +* +* As a counterpart to the access to the source code and rights to copy, +* modify and redistribute granted by the license, users are provided only +* with a limited warranty and the software's author, the holder of the +* economic rights, and the successive licensors have only limited +* liability. +* +* The fact that you are presently reading this means that you have had +* knowledge of the CeCILL-B license and that you accept its terms. +* ------------------------------------------------------------------------ */ + /** * \file * \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 +42,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()<<"\""<GetOriginalBlackBoxFrom()->bbGetName() ); + BlackBox::Pointer bbto = bbGetBlackBox( (*j)->GetOriginalBlackBoxTo()->bbGetName() ); - BlackBox* bbfrom = bbGetBlackBox( (*j)->GetBlackBoxFrom()->bbGetName() ); - BlackBox* bbto = bbGetBlackBox( (*j)->GetBlackBoxTo()->bbGetName() ); - Connection* c = /*mDescriptor->GetFactory()->Create*/ + 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(\"" + < ComplexBlackBox::~ComplexBlackBox() [" + <GetFullName()<<"\""<bbDesallocateConnectors(); - - bbtkDebugMessageInc("Kernel",9,"* Delete Black Boxes"<first<<"\""<second->bbDelete(); - bbtkDebugDecTab("Kernel",9); - } - bbtkDebugDecTab("Kernel",9); - // bbtkDebugMessage("Kernel",9,"EO ComplexBlackBox::~ComplexBlackBox [" - // <bbDesallocateConnectors(); - bbtkDebugDecTab("Kernel",9); + //======================================================================= + /// Clear + void ComplexBlackBox::Clear() + { + bbtkDebugMessage("object",3, + "==> ComplexBlackBox::Clear() [" + < Releasing connections"< Releasing boxes"<GetInputDescriptorMap(); @@ -160,7 +199,6 @@ namespace bbtk ->bbGetInputConnectorMap()[ d->GetInput() ]; bbGetInputConnectorMap()[i->second->GetName()] = c; -//new BlackBoxInputConnector(); } // Output connectors @@ -180,8 +218,8 @@ namespace bbtk ->bbGetOutputConnectorMap()[ d->GetOutput() ]; bbGetOutputConnectorMap()[o->second->GetName()] = c; - //new BlackBoxOutputConnector(); } + bbtkDebugDecTab("Kernel",8); } //========================================================================= @@ -208,17 +246,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(" - <GetBlackBox()->bbSetModifiedStatus(c); - - bbtkDebugMessage("Process",3, - "EO ComplexBlackBox::bbSetModifiedStatus(" - <GetFullName()<<") [" - <GetOutputDescriptorMap(); - BlackBoxDescriptor::OutputDescriptorMapType::const_iterator i - = omap.find(caller->GetBlackBoxFromOutput()); - if (i!=omap.end()) - { - // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor - ComplexBlackBoxOutputDescriptor* d = - (ComplexBlackBoxOutputDescriptor*)i->second; - // Get the internal box - BlackBox* b = bbUnsafeGetBlackBox ( d->GetTarget() ); - // Calls BackwardUpdate on it - bbtkDebugMessageInc("Process",2,"Internal box connected to output : "<GetTarget()<bbBackwardUpdate(caller); - // ??? STATUS OF CBBs ??? - // ??? Here it is only the final status of the boxes connected to the output - if (s1==MODIFIED) s=MODIFIED; - bbtkDebugDecTab("Process",2); - } - else - { - bbtkError("Connection '"<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); + + mExecutionList.push_back( name ); + + bbtkDebugDecTab("Kernel",9); + } //================================================================== - */ //================================================================== @@ -457,9 +406,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 +484,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 +493,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 +509,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(\""<"); @@ -616,20 +655,18 @@ namespace bbtk restname = blackboxname.substr(lastPos+pos - lastPos+1, 999); if (restname==subname) - { - restname=""; - } + { + restname=""; + } BlackBoxMapType::iterator i = mBlackBoxMap.find(subname); - if ( i == mBlackBoxMap.end() ) - { - blackbox = NULL; - } else { - blackbox = i->second; - if (restname!="") - { - blackbox = blackbox->bbFindBlackBox(restname); - } + if ( i != mBlackBoxMap.end() ) + { + blackbox = i->second; + if (restname!="") + { + blackbox = blackbox->bbFindBlackBox(restname); + } } return blackbox; } @@ -647,11 +684,11 @@ namespace bbtk std::string directory(output_dir); if (output_dir.length() == 0) - { - // Don't pollute the file store with "doc_tmp" directories ... - std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_doc_tmp(); - directory = default_doc_dir + "/" + "doc_tmp"; - } + { + // Don't pollute the file store with "temp_dir" directories ... + std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir(); + directory = default_temp_dir + "/" + "temp_dir"; + } std::string simplefilename (this->bbGetTypeName()+"_"+this->bbGetName()); std::string simplefilename_png (simplefilename+".png"); @@ -677,7 +714,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 ); @@ -701,13 +740,13 @@ namespace bbtk char c; ff2=fopen(filename_cmap.c_str(),"r"); while (!feof(ff2)) - { - c=fgetc(ff2); - if (c!=-1) - { - (s) << c; - } - } + { + c=fgetc(ff2); + if (c!=-1) + { + (s) << c; + } + } (s) << "\n\n"; // End @@ -718,48 +757,50 @@ 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) - { - if (relative_link) - tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL(); - else - tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocURL(); - } + { + if (relative_link) + tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL(); + else + tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocURL(); + } else - { - tmp1 = "Caspitas"; - } + { + tmp1 = "Caspitas"; + } std::string tmp2=bbGetTypeName(); std::string url(tmp1 + "#" + tmp2 ); fprintf( ff , "subgraph cluster_%s_%p {\n",bbGetName().c_str(),this); if (!( (bbGetTypeName()=="workspace") && (bbGetName()=="workspacePrototype")) ) - { - fprintf( ff , " URL = \"%s\" %s",url.c_str(),";"); - } + { + fprintf( ff , " URL = \"%s\" %s",url.c_str(),";"); + } std::string boxname="["+bbGetTypeName()+"]"; - if (this!=parentblackbox) - { - if (detail==0) - { - boxname=bbGetName(); - } else { - boxname = bbGetName(); - boxname = boxname + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]"; - } + if (GetThisPointer()!=parentblackbox) + { + if (detail==0) + { + boxname=bbGetName(); + } + else + { + boxname = bbGetName(); + boxname = boxname + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]"; + } - } + } fprintf( ff , " label = \"%s\"%s\n", boxname.c_str() ,";"); @@ -854,7 +895,9 @@ namespace bbtk { if (level>-1) { - j->second->bbWriteDotFileBlackBox(ff,parentblackbox,detail, + j->second->bbWriteDotFileBlackBox(ff, + parentblackbox, + detail, level-1, instanceOrtype, relative_link); @@ -881,7 +924,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) { @@ -902,7 +945,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) { @@ -922,7 +965,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 ) { @@ -930,32 +973,33 @@ 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 } // if second } // for } // if parentblackbox - } //========================================================================= + - /* + /* + //======================================================================= /// Generates the list of the packages of which its depends /// (cause an internal box belongs to it) @@ -971,4 +1015,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; + } + //========================================================================== + }