X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkBlackBox.cxx;h=51a9ab7cfe824b790f5cd30cdc780c67003412c4;hb=e64f1a51510b44580500fd9ec30b4c937255bf75;hp=3aa696ab482be13d0e63864a488278ebcd596192;hpb=a26195c366a89795288009cf7e20f11afa494970;p=bbtk.git diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index 3aa696a..51a9ab7 100644 --- a/kernel/src/bbtkBlackBox.cxx +++ b/kernel/src/bbtkBlackBox.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkBlackBox.cxx,v $ Language: C++ -Date: $Date: 2008/01/22 15:02:00 $ -Version: $Revision: 1.1 $ +Date: $Date: 2008/05/06 13:45:12 $ +Version: $Revision: 1.17 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See doc/license.txt or @@ -35,24 +35,90 @@ PURPOSE. See the above copyright notices for more information. namespace bbtk { + + + static bool bbmgSomeBoxExecuting = false; + static bool bbmgFreezeExecution = false; + static std::set bbmgExecutionList; + + //========================================================================= + BlackBox::Deleter::Deleter() + { + } + //========================================================================= + + //========================================================================= + void BlackBox::Deleter::Delete(Object* p) + { + BlackBox* b = dynamic_cast(p); + if (!b) + { + bbtkInternalError("BlackBox::Deleter::Delete("<GetObjectName() + <<"["<GetObjectName();//b->bbGetNameWithParent(); + bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<bbGetDescriptor(); + bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<bbDelete(); + + bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<GetPackage(); + if (!pack.expired()) + { + Package::ReleaseBlackBoxDescriptor(pack,desc); + } + else + { + bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""< BlackBox::Deleter(\""< BlackBox::BlackBox(\"" + < BlackBox::BlackBox(" + < BlackBox::~BlackBox() ["<bbDesallocateConnectors(); - //printf("EED BlackBox::~BlackBox 02 \n"); - bbtkDebugDecTab("Core",7); - } - //========================================================================= - - //========================================================================= - /// Destruction method of a black box - void BlackBox::bbDelete() - { - bbtkDebugMessage("Core",5,"BlackBox::bbDelete() [" - <bbUserDelete(); + bbtkDebugMessage("object",4,"<== BlackBox::~BlackBox() ["< BlackBox::bbExecute() [" < FreezeExecution global flag is 'true' : abort execution"<bbGetDescriptor()->GetTypeName()+">"; + return this->bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">"; } //========================================================================= @@ -125,9 +181,9 @@ namespace bbtk /// Returns the name with the name of the parent prepended if any std::string BlackBox::bbGetNameWithParent() const { - if (bbmParent) + if (bbmParent.lock()) { - return bbmParent->bbGetNameWithParent() + ":" + bbmName; + return bbmParent.lock()->bbGetNameWithParent() + ":" + bbmName; } else { @@ -149,13 +205,13 @@ namespace bbtk /// Returns true if the UserBlackBox has an input of name name bool BlackBox::bbHasInput(const std::string& name) const { - bbtkDebugMessageInc("Core",8, + bbtkDebugMessageInc("Kernel",8, "BlackBox::bbHasInput(\"" <GetInputDescriptorMap().find(name) != bbGetDescriptor()->GetInputDescriptorMap().end()); - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("Kernel",8); return r; } //========================================================================= @@ -165,11 +221,11 @@ namespace bbtk /// Returns true if the UserBlackBox has an output of name name bool BlackBox::bbHasOutput(const std::string& name) const { - bbtkDebugMessageInc("Core",8,"BlackBox::bbHasOutput(\"" + bbtkDebugMessageInc("Kernel",8,"BlackBox::bbHasOutput(\"" <GetOutputDescriptorMap().find(name) != bbGetDescriptor()->GetOutputDescriptorMap().end()); - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("Kernel",8); return r; } //========================================================================= @@ -179,11 +235,11 @@ namespace bbtk /// Gets the output type of a given name TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const { - bbtkDebugMessageInc("Core",8, + bbtkDebugMessageInc("Kernel",8, "BlackBox::bbGetOutputType(\"" <GetOutputDescriptor(name)->GetTypeInfo(); - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("Kernel",8); return r; } //========================================================================= @@ -192,11 +248,11 @@ namespace bbtk /// Gets the input type of a given name TypeInfo BlackBox::bbGetInputType( const std::string &name ) const { - bbtkDebugMessageInc("Core",8, + bbtkDebugMessageInc("Kernel",8, "BlackBox::bbGetInputType(\"" <GetInputDescriptor(name)->GetTypeInfo(); - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("Kernel",8); return r; } //========================================================================= @@ -206,7 +262,7 @@ namespace bbtk /// Allocates the i/o connectors of the black box void BlackBox::bbAllocateConnectors() { - bbtkDebugMessageInc("Core",8, + bbtkDebugMessageInc("Kernel",8, "BlackBox::bbAllocateConnectors() [" <first<<"\""<first<<"\""<second->GetName()] - = new BlackBoxInputConnector(this); + = new BlackBoxInputConnector(GetThisPointer()); } const BlackBoxDescriptor::OutputDescriptorMapType& omap = bbGetDescriptor()->GetOutputDescriptorMap(); BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o; for ( o = omap.begin(); o != omap.end(); ++o ) { - bbtkDebugMessage("Core",8,"* Allocate \""<first<<"\""<first<<"\""<second->GetName()] = new BlackBoxOutputConnector(); } - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("Kernel",8); } //========================================================================= @@ -237,7 +293,7 @@ namespace bbtk /// Desallocates the i/o connectors of the black box void BlackBox::bbDesallocateConnectors() { - bbtkDebugMessageInc("Core",8, + bbtkDebugMessageInc("Kernel",8, "BlackBox::bbDesallocateConnectors()" <first<<"\""<first<<"\""<second); } OutputConnectorMapType::const_iterator o; for ( o = bbGetOutputConnectorMap().begin(); o != bbGetOutputConnectorMap().end(); ++o ) { - bbtkDebugMessage("Core",8,"* Delete \""<first<<"\""<first<<"\""<second); } - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("Kernel",8); } //========================================================================= @@ -266,7 +322,7 @@ namespace bbtk /// Copies the input / output values from another box void BlackBox::bbCopyIOValues(BlackBox& from) { - bbtkDebugMessageInc("Core",9, + bbtkDebugMessageInc("Kernel",9, "BlackBox::bbCopyIOValues(" <bbSetOutput(output, from.bbGetOutput(output) ); } - bbtkDebugDecTab("Core",9); + bbtkDebugDecTab("Kernel",9); } //========================================================================= @@ -303,7 +359,7 @@ namespace bbtk { return ( bbGlobalGetSomeBoxExecuting() #ifdef _USE_WXWIDGETS_ - || WxBlackBox::bbGlobalIsSomeWindowAlive() + || Wx::IsSomeWindowAlive() #endif ); } @@ -315,7 +371,7 @@ namespace bbtk /// User overloadable destruction method of a black box void BlackBox::bbUserDelete() { - bbtkDebugMessage("Process",5, + bbtkDebugMessage("process",5, "=> BlackBox::bbUserDelete() [" < BlackBox::bbSetModifiedStatus("< BlackBox::bbSetModifiedStatus("<second) ) - // && (bbCanReact())) + // && (bbCanReact())) { - bbtkDebugMessage("Process",9, + bbtkDebugMessage("modified",2, "-> Hide triggered by WinHide input change" <bbHideWindow(); this->bbSetStatus(MODIFIED); return; } - + if ( ( bbBoxProcessModeIsReactive() || (c==bbGetInputConnectorMap().find("BoxExecute")->second)) && (bbCanReact() ) ) { - bbtkDebugMessage("Process",9, + bbtkDebugMessage("modified",2, "-> Execution triggered by Reactive mode or BoxExecute input change"<bbSetStatus(MODIFIED); - bbGlobalAddToExecutionList( this ); + bbGlobalAddToExecutionList( GetThisPointer() ); } else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate()) { - bbtkDebugMessage("Process",5,"-> Already modified"< Already modified"< Status set to modified"< Status set to modified"<bbSetStatus(MODIFIED); } this->bbSignalOutputModification(false); - bbtkDebugMessageDec("Process",5, + /* + bbtkDebugMessageDec("process",5, "<= BlackBox::bbSetModifiedStatus("< BlackBox::bbSignalOutputModification() [" < BlackBox::bbSignalOutputModification(" <& output, bool reaction) { - bbtkDebugMessageInc("Process",5, + bbtkDebugMessageInc("process",5, "=> BlackBox::bbSignalOutputModification(vector of outputs) [" < BlackBox::bbUpdateInputs() [" < to the connection c void BlackBox::bbConnectInput( const std::string& name, Connection* c) { - bbtkDebugMessageInc("Core",7, - "BlackBox::bbConnectInput(\""< BlackBox::bbConnectInput(\"" + <GetFullName()<<") [" <second->SetConnection(c); + bbtkDebugMessage("connection",2, + "<== BlackBox::bbConnectInput(\"" + <GetFullName()<<") [" + < to the connection c void BlackBox::bbConnectOutput( const std::string& name, Connection* c) { - bbtkDebugMessageInc("Core",7, - "BlackBox::bbConnectOutput(\""< BlackBox::bbConnectOutput(\""<GetFullName()<<") [" + <second->SetConnection(c); - bbtkDebugDecTab("Core",7); + bbtkDebugMessage("connection",2, + "<== BlackBox::bbConnectOutput(\""<GetFullName()<<") [" + < from the connection c void BlackBox::bbDisconnectInput( const std::string& name, Connection* c) { - bbtkDebugMessageInc("Core",7, - "BlackBox::bbDisconnectInput(\""< BlackBox::bbDisconnectInput(\""<GetFullName()<<") [" + <second->UnsetConnection(c); - bbtkDebugDecTab("Core",7); + bbtkDebugMessage("connection",2, + "<== BlackBox::bbDisconnectInput(\""<GetFullName()<<") [" + < from the connection c void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c) { - bbtkDebugMessageInc("Core",7, - "BlackBox::bbDisconnectOutput(\""< BlackBox::bbDisconnectOutput(\""<GetFullName()<<") [" + <second->UnsetConnection(c); - bbtkDebugDecTab("Core",7); + bbtkDebugMessage("connection",2, + "<== BlackBox::bbDisconnectOutput(\""<GetFullName()<<") [" + <GetPackage(); + if ((p != 0) && ( ! p->GetFactorySet().empty() ) ) { - a = NewAdaptor( - bbGetOutputType(output), - typeid(std::string), - ""); - } catch (bbtk::Exception e) + Factory::Pointer f = p->GetFactorySet().begin()->lock(); + BlackBox::Pointer a; + try + { + a = f->NewAdaptor( + bbGetOutputType(output), + typeid(std::string), + ""); + } catch (bbtk::Exception e) + { + } + if (a){ + // bbUpdate(); + a->bbSetInput("In",bbGetOutput(output)); + a->bbExecute(); + v = a->bbGetOutput("Out").unsafe_get() ; + } else { + v="? (no adaptor found)"; + } + } + else { + v="? (no factory found)"; } - if (a!=NULL){ - // bbUpdate(); - a->bbSetInput("In",bbGetOutput(output)); - a->bbExecute(); - v = a->bbGetOutput("Out").unsafe_get() ; - } else { - v="? (no adaptor found)"; - } - } else { - // bbUpdate(); - v = bbGetOutput(output).unsafe_get() ; - } + } + else + { + // bbUpdate(); + v = bbGetOutput(output).unsafe_get() ; + } return v; } //========================================================================= @@ -682,28 +785,38 @@ namespace bbtk // Looks for the adaptor if (bbGetInputType(input) != typeid(std::string)) { - BlackBox* a = 0; - try - { - a = NewAdaptor( - bbGetInputType(input), - typeid(std::string), - ""); - }catch (bbtk::Exception e) - { - } - if (a!=NULL) + // Look for factory + Package::Pointer p = bbGetDescriptor()->GetPackage(); + if ((p != 0) && ( ! p->GetFactorySet().empty() ) ) { - // bbUpdate(); - a->bbSetInput("In",bbGetInput(input)); - a->bbExecute(); - v = a->bbGetOutput("Out").unsafe_get() ; + Factory::Pointer f = p->GetFactorySet().begin()->lock(); + BlackBox::Pointer a; + try + { + a = f->NewAdaptor( + bbGetInputType(input), + typeid(std::string), + ""); + }catch (bbtk::Exception e) + { + } + if (a) + { + // bbUpdate(); + a->bbSetInput("In",bbGetInput(input)); + a->bbExecute(); + v = a->bbGetOutput("Out").unsafe_get() ; + } + else + { + v="? (no adaptor found)"; + } } else { - v="? (no adaptor found)"; + v="? (no factory found)"; } - } + } else { v = bbGetInput(input).unsafe_get() ; @@ -753,22 +866,24 @@ namespace bbtk //========================================================================= /// Write Graphviz-dot description in file void BlackBox::bbWriteDotFileBlackBox(FILE *ff, - BlackBox *parentblackbox, + BlackBox::Pointer parentblackbox, int detail, int level, bool instanceOrtype, bool relative_link ) - { + { InputConnectorMapType::iterator i; // label std::string labelStr; std::string valueStr(""); - if (detail==0) - { - labelStr = bbGetName() ; - } else { - labelStr = bbGetName(); - labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] "; + + if (detail==0) { + labelStr = bbGetName() ; +//EED 18 Fev 2008 + labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]"; + } else { + labelStr = bbGetName(); + labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] "; } SubsBrackets(labelStr); @@ -834,26 +949,26 @@ namespace bbtk // std::cout << labelStr << std::endl; // Relation Input - if (this!=parentblackbox){ + if (GetThisPointer()!=parentblackbox){ for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) { if (i->second) { Connection* con = i->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 @@ -867,7 +982,7 @@ namespace bbtk //========================================================================= - void BlackBox::bbShowRelations(BlackBox *parentblackbox, + void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox, int detail, int level /*,Factory *factory*/ ) { @@ -902,9 +1017,9 @@ namespace bbtk std::string s(""); Connection* con = i->second->GetConnection(); if (con!=0){ - s = con->GetBlackBoxFrom()->bbGetName(); + s = con->GetOriginalBlackBoxFrom()->bbGetName(); s += "."; - s += con->GetBlackBoxFromOutput(); + s += con->GetOriginalBlackBoxFromOutput(); } // if con iconn.push_back(s); } @@ -919,14 +1034,15 @@ namespace bbtk ovalue.push_back(bbGetOutputAsString(o->first)); if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size(); std::vector ss; - const std::vector& con = o->second->GetConnectionVector(); + const std::vector& con + = o->second->GetConnectionVector(); std::vector::const_iterator c; for (c=con.begin();c!=con.end();++c) { std::string s; - s = (*c)->GetBlackBoxTo()->bbGetName(); + s = (*c)->GetOriginalBlackBoxTo()->bbGetName(); s += "."; - s += (*c)->GetBlackBoxToInput(); + s += (*c)->GetOriginalBlackBoxToInput(); ss.push_back(s); } // if con oconn.push_back(ss); @@ -991,22 +1107,22 @@ namespace bbtk //========================================================================= void BlackBox::bbGlobalProcessExecutionList() { - bbtkDebugMessageInc("Process",1, + bbtkDebugMessageInc("process",3, "=> BlackBox::bbGlobalProcessExecutionList()" <::iterator i; + std::set::iterator i; for (i=bbmgExecutionList.begin(); i!=bbmgExecutionList.end(); ++i) { - bbtkDebugMessage("Process",2, + bbtkDebugMessage("process",4, " -> Executing "<<(*i)->bbGetFullName()<bbExecute(true); } bbmgExecutionList.clear(); - bbtkDebugMessageDec("Process",1, + bbtkDebugMessageDec("process",3, "<= BlackBox::bbGlobalProcessExecutionList()" < BlackBox::bbmgExecutionList; +*/ //========================================================================= + //========================================================================= + void BlackBox::Check(bool recursive) + { + bbtkMessage("debug",1,"*** Checking Black Box "<<(void*)this<<" ["<