X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkBlackBox.cxx;h=6fb1fb83a9c749dfce3cc545269c3f0773ad71bf;hb=3dcc408acd2264664ca6431a501378ea64233dd6;hp=3aa696ab482be13d0e63864a488278ebcd596192;hpb=a26195c366a89795288009cf7e20f11afa494970;p=bbtk.git diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index 3aa696a..6fb1fb8 100644 --- a/kernel/src/bbtkBlackBox.cxx +++ b/kernel/src/bbtkBlackBox.cxx @@ -1,22 +1,40 @@ +/* + # --------------------------------------------------------------------- + # + # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image + # pour la SantÈ) + # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton + # Previous Authors : Laurent Guigues, Jean-Pierre Roux + # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil + # + # 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. + # ------------------------------------------------------------------------ */ + + /*========================================================================= - -Program: bbtk -Module: $RCSfile: bbtkBlackBox.cxx,v $ -Language: C++ -Date: $Date: 2008/01/22 15:02:00 $ -Version: $Revision: 1.1 $ - -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: bbtkBlackBox.cxx,v $ + Language: C++ + Date: $Date: 2012/11/16 08:49:01 $ + Version: $Revision: 1.56 $ =========================================================================*/ + /** * \file * \brief Class bbtk::BlackBox : abstract black-box interface. @@ -25,9 +43,11 @@ PURPOSE. See the above copyright notices for more information. #include "bbtkPackage.h" #include "bbtkMessageManager.h" #include "bbtkFactory.h" +#include "bbtkBlackBoxOutputConnector.h" #include "bbtkConfigurationFile.h" #include "bbtkWxBlackBox.h" +#include "bbtkWx.h" #include //#include @@ -35,24 +55,106 @@ 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() + { + } + //========================================================================= + + //========================================================================= + int 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); + bbtkBlackBoxDebugMessage("object",4,"<== BlackBox::~BlackBox() ["<bbUserDelete(); - } - //========================================================================= - //========================================================================= - /// Main processing method of the box. - void BlackBox::bbExecute(bool force) - { - bbtkDebugMessageInc("Process",1, - "=> BlackBox::bbExecute() [" - < FreezeExecution global flag is 'true' : abort execution"<bbGetDescriptor()->GetTypeName()+">"; + return this->bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">"; } //========================================================================= //========================================================================= - /// 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 { @@ -137,7 +198,6 @@ namespace bbtk //========================================================================= //========================================================================= - /// Prints the Help on the BlackBox type void BlackBox::bbGetHelp(bool full) const { bbGetDescriptor()->GetHelp(full); @@ -146,98 +206,96 @@ namespace bbtk //========================================================================= - /// Returns true if the UserBlackBox has an input of name name bool BlackBox::bbHasInput(const std::string& name) const { - bbtkDebugMessageInc("Core",8, + bbtkBlackBoxDebugMessage("kernel",8, "BlackBox::bbHasInput(\"" - <GetInputDescriptorMap().find(name) != bbGetDescriptor()->GetInputDescriptorMap().end()); - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("kernel",8); return r; } //========================================================================= //========================================================================= - /// Returns true if the UserBlackBox has an output of name name bool BlackBox::bbHasOutput(const std::string& name) const { - bbtkDebugMessageInc("Core",8,"BlackBox::bbHasOutput(\"" - <GetOutputDescriptorMap().find(name) != bbGetDescriptor()->GetOutputDescriptorMap().end()); - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("kernel",8); return r; } //========================================================================= //========================================================================= - /// Gets the output type of a given name TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const { - bbtkDebugMessageInc("Core",8, - "BlackBox::bbGetOutputType(\"" - <GetOutputDescriptor(name)->GetTypeInfo(); - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("kernel",8); return r; } //========================================================================= //========================================================================= - /// Gets the input type of a given name TypeInfo BlackBox::bbGetInputType( const std::string &name ) const { - bbtkDebugMessageInc("Core",8, - "BlackBox::bbGetInputType(\"" - <GetInputDescriptor(name)->GetTypeInfo(); - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("kernel",8); return r; } //========================================================================= //========================================================================= - /// Allocates the i/o connectors of the black box void BlackBox::bbAllocateConnectors() { - bbtkDebugMessageInc("Core",8, - "BlackBox::bbAllocateConnectors() [" - <GetInputDescriptorMap(); BlackBoxDescriptor::InputDescriptorMapType::const_iterator i; for ( i = imap.begin(); i != imap.end(); ++i ) { - bbtkDebugMessage("Core",8,"* Allocate \""<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(); + = new BlackBoxOutputConnector(GetThisPointer()); } - bbtkDebugDecTab("Core",8); } //========================================================================= //========================================================================= - /// Desallocates the i/o connectors of the black box void BlackBox::bbDesallocateConnectors() { - bbtkDebugMessageInc("Core",8, + bbtkBlackBoxDebugMessage("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); } //========================================================================= //========================================================================= - /// Copies the input / output values from another box void BlackBox::bbCopyIOValues(BlackBox& from) { - bbtkDebugMessageInc("Core",9, - "BlackBox::bbCopyIOValues(" - <GetInputDescriptorMap(); @@ -278,6 +334,7 @@ namespace bbtk { if (! i->second->GetCopyConstruct() ) continue; std::string input = i->second->GetName(); + bbtkBlackBoxDebugMessage("kernel",2,"* Copying input "<bbSetInput(input, from.bbGetInput(input) ); } // copies the output values @@ -288,11 +345,11 @@ namespace bbtk { if (! o->second->GetCopyConstruct() ) continue; std::string output = o->second->GetName(); + bbtkBlackBoxDebugMessage("kernel",2,"* Copying output "<bbSetOutput(output, from.bbGetOutput(output) ); } - bbtkDebugDecTab("Core",9); - + bbtkDebugDecTab("kernel",9); } //========================================================================= @@ -302,185 +359,232 @@ namespace bbtk bool BlackBox::bbCanReact() const { return ( bbGlobalGetSomeBoxExecuting() -#ifdef _USE_WXWIDGETS_ - || WxBlackBox::bbGlobalIsSomeWindowAlive() +#ifdef USE_WXWIDGETS + || Wx::IsSomeWindowAlive() #endif - ); + ); } //========================================================================= - //========================================================================= - /// User overloadable destruction method of a black box - void BlackBox::bbUserDelete() - { - bbtkDebugMessage("Process",5, - "=> BlackBox::bbUserDelete() [" - < BlackBox::bbSetModifiedStatus("<second) ) - // && (bbCanReact())) - { - bbtkDebugMessage("Process",9, - "-> Hide triggered by WinHide input change" - <bbHideWindow(); - this->bbSetStatus(MODIFIED); - return; - } - - if ( ( bbBoxProcessModeIsReactive() || - (c==bbGetInputConnectorMap().find("BoxExecute")->second)) - && (bbCanReact() ) ) + bbtkBlackBoxDebugMessage("change",5, + "=> BlackBox::bbSetStatusAndPropagate(input," + <SetStatus(s); + + // Flash reaction + /* + if (bbGetBoxProcessModeValue() == Flash) { - bbtkDebugMessage("Process",9, - "-> Execution triggered by Reactive mode or BoxExecute input change"<bbSetStatus(MODIFIED); - bbGlobalAddToExecutionList( this ); + this->bbExecute(); } - else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate()) - { - bbtkDebugMessage("Process",5,"-> Already modified"< Status set to modified"<bbSetStatus(MODIFIED); - } - - this->bbSignalOutputModification(false); - bbtkDebugMessageDec("Process",5, - "<= BlackBox::bbSetModifiedStatus("<first=="BoxChange") + { + o->second->SetStatus(UPTODATE); + } + + + +//EED 24/08/2015 +// EED CASPITAS 2 + if (o->second->GetStatus()==UPTODATE) +// if ((o->second->GetStatus()==UPTODATE) || (o->second->GetStatus()==OUTOFDATE)) +// if ((o->second->GetStatus()==UPTODATE) || (o->second->GetStatus()==MODIFIED)) + { + o->second->SetStatus(OUTOFDATE); + o->second->SignalChange(GetThisPointer(),o->first); + } // if + } // for + + + if ( ( bbBoxProcessModeIsReactive() + || (c==bbGetInputConnectorMap().find("BoxExecute")->second)) + && (bbCanReact() ) ) + { + bbtkBlackBoxDebugMessage("change",2, + "-> Execution triggered by Reactive mode or BoxExecute input change"<() ); + } // if + bbtkBlackBoxDebugMessage("change",5, + "<= BlackBox::bbSetStatusAndPropagate(input)" + < BlackBox::bbSignalOutputModification() [" - < BlackBox::bbSignalOutputModification(" + <first == "BoxChange" ) - { - change = i; - continue; - } - */ - i->second->SetModifiedStatus(); - } - // if (change != bbGetOutputConnectorMap().end()) - // change->second->SetModifiedStatus(); + i != bbGetOutputConnectorMap().end(); ++i) + { + // std::cout << "Stat = " + //<second->GetStatus()) + // <second->GetStatus()==UPTODATE) + // { + i->second->SignalChange(GetThisPointer(),i->first); + // } + } // for if (reaction) bbGlobalProcessExecutionList(); - bbtkDebugMessageDec("Process",5, - "<= BlackBox::bbSignalOutputModification() [" - < BlackBox::bbSignalOutputModification(" - < BlackBox::bbSignalOutputModification(" + <second->SetModifiedStatus(); - // Has to notify the output "BoxChange" also - if (output != "BoxChange") - { - i = bbGetOutputConnectorMap().find("BoxChange"); - if ( i != bbGetOutputConnectorMap().end() ) + + // if (i->second->GetStatus()==UPTODATE) + // { + i->second->SignalChange(GetThisPointer(),i->first); + // Has to notify the output "BoxChange" also + if (output != "BoxChange") { - i->second->SetModifiedStatus(); + i = bbGetOutputConnectorMap().find("BoxChange"); + if ( i != bbGetOutputConnectorMap().end() ) + { + i->second->SignalChange(GetThisPointer(),i->first); + } } - } - if (reaction) bbGlobalProcessExecutionList(); - - bbtkDebugMessageDec("Process",5, - "<= BlackBox::bbSignalOutputModification(" - <& output, bool reaction) { - bbtkDebugMessageInc("Process",5, - "=> BlackBox::bbSignalOutputModification(vector of outputs) [" - < BlackBox::bbSignalOutputModification(vector of outputs)" +<::const_iterator o; + bool changed = false; for (o=output.begin();o!=output.end();++o) { // the output "BoxChange" must be signaled **AFTER** all others @@ -491,91 +595,344 @@ namespace bbtk { bbtkError("BlackBox["<second->SetModifiedStatus(); + + // if (i->second->GetStatus()==UPTODATE) + // { + i->second->SignalChange(GetThisPointer(),i->first); + changed = true; + // } } // Has to notify the output "BoxChange" also i = bbGetOutputConnectorMap().find("BoxChange"); - if ( i != bbGetOutputConnectorMap().end() ) + if ( changed && (i != bbGetOutputConnectorMap().end())) { - i->second->SetModifiedStatus(); + // if (i->second->GetStatus()==UPTODATE) + // { + i->second->SignalChange(GetThisPointer(),i->first); + if (reaction) bbGlobalProcessExecutionList(); + // } } - if (reaction) bbGlobalProcessExecutionList(); - - bbtkDebugMessageDec("Process",5, - "<= BlackBox::bbSignalOutputModification(vector of outputs) [" - < BlackBox::bbExecute("<<(int)force<<")" + < already executing : abort"< FreezeExecution global flag is 'true' : abort execution"<bbRecursiveInitializeProcessing(); + bbmInitialized = true; + } + } + //========================================================================= + + //========================================================================= + void BlackBox::bbFinalizeProcessing() + { + if (bbmInitialized) + { + bbtkBlackBoxDebugMessage("process",2,"** Finalize processing" + <bbRecursiveFinalizeProcessing(); + bbmInitialized = false; + } + } + //========================================================================= + + //========================================================================= - /// Updates the BlackBox inputs - /// \returns UPTODATE if all inputs are in UPTODATE status after update - /// else MODIFIED - IOStatus BlackBox::bbUpdateInputs(bool excludeParent) + void BlackBox::bbRecursiveExecute( Connection::Pointer caller ) { - bbtkDebugMessageInc("Process",4, - "=> BlackBox::bbUpdateInputs() [" - < BlackBox::bbRecursiveExecute(" + <<(caller?caller->GetFullName():"0")<<")" + < already executing : abort"<bbCreateWindow(); + + // Updates its inputs + +// IOStatus s; + IOStatus s=UPTODATE; +// IOStatus s=OUTOFDATE; +// IOStatus s=MODIFIED; + + + if ( ( bbBoxProcessModeIsManual()==false ) || + ( (bbBoxProcessModeIsManual()==true) && (bbLetRecursiveExecuteManualMode==true) ) ) + { + s = bbUpdateInputs(); + } + + if ( (s != UPTODATE) || bbBoxProcessModeIsAlways() ) + { + // Displays the window (WxBlackbox) + // bbShowWindow(caller); + + // Actual processing (virtual) + if ( ( bbBoxProcessModeIsManual()==false ) || + ( (bbBoxProcessModeIsManual()==true)&&(bbLetRecursiveExecuteManualMode==true) ) + ) + { + this->bbProcess(); + } // Manual analysis + +//EED ups if ((bbBoxProcessModeIsManual()==true) && (bbLetRecursiveExecuteManualMode==false)) +//EED ups { +//EED ups bbSignalOutputModification(true); +//EED ups } + + + // Update the I/O statuses + bbComputePostProcessStatus(); + } + else + { + // Test output status... + OutputConnectorMapType::iterator o; + for ( o = bbGetOutputConnectorMap().begin(); + o!= bbGetOutputConnectorMap().end(); ++o) + { + if (o->second->GetStatus() != UPTODATE) + { + bbtkWarning("BlackBox::bbRecursiveExecute: " + <<"all inputs are Up-to-date but output '" + <first<<"' is Out-of-date ???"); + } + } + + bbtkBlackBoxDebugMessage("process",3," -> Up-to-date : nothing to do" + <bbShowWindow(); + + + bbtkBlackBoxDebugMessage("process",3, + "<= BlackBox::bbRecursiveExecute()" + < BlackBox::bbUpdateInputs()" <first=="WinParent")) continue; - if (i->first=="WinHide") continue; + // if (i->first=="WinHide") continue; // If input type is Void : no recurse //if ( bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo() // == typeid(Void) ) // continue; - - IOStatus t = i->second->BackwardUpdate(); - if (t==MODIFIED) s = MODIFIED; + bbtkBlackBoxDebugMessage("change",2, + "Input '"<first + <<"': status before update = '" + <second->GetStatus()) + <<"'"<second->RecursiveExecute(); + IOStatus t = i->second->GetStatus(); + if (t > s) s = t; + bbtkBlackBoxDebugMessage("change",2, + "Input '"<first + <<"': status before process = '" + <second->GetStatus()) + <<"'"< BlackBox::bbComputePostProcessStatus()" <second->GetStatus(); + if (t == OUTOFDATE) new_output_status = OUTOFDATE; + // A previously MODIFIED status turns to UPTODATE + if (t==MODIFIED) i->second->SetStatus(UPTODATE); + bbtkBlackBoxDebugMessage("change",2, + "Input '"<first<<"' : " + << GetIOStatusString(t) << " -> " + << GetIOStatusString(i->second->GetStatus()) + << std::endl); + } + bbtkBlackBoxDebugMessage("change",2, + "New output status : " + << GetIOStatusString(new_output_status) + <second->SetStatus(new_output_status); +//EED } else { +//EED if (( (bbBoxProcessModeIsManual()==true) && (bbLetRecursiveExecuteManualMode==false) ) ) +//EED { +//EED o->second->SetStatus(UPTODATE); +//EED } +//EED } // Manual analysis + + } + + bbtkBlackBoxDebugMessage("process",4, + "<= BlackBox::bbComputePostProcessStatus()" + < to the connection c void BlackBox::bbConnectInput( const std::string& name, Connection* c) { - bbtkDebugMessageInc("Core",7, - "BlackBox::bbConnectInput(\""< BlackBox::bbConnectInput(\"" + <GetFullName()<<")" <second->SetConnection(c); - - // bbSetModifiedStatus(); + // The input *MUST* be set OUTOFDATE to update its input on next execution + bbSetStatusAndPropagate(i->second,OUTOFDATE); - bbtkDebugDecTab("Core",7); + bbtkBlackBoxDebugMessage("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); + bbtkBlackBoxDebugMessage("connection",2, + "<== BlackBox::bbConnectOutput(\""<GetFullName()<<")" + < from the connection c - void BlackBox::bbDisconnectInput( const std::string& name, 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); + bbtkBlackBoxDebugMessage("connection",2, + "<== BlackBox::bbDisconnectInput(\""<GetFullName()<<")" + < from the connection c - void BlackBox::bbDisconnectOutput( const std::string& name, 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); + bbtkBlackBoxDebugMessage("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 +1090,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() ; @@ -720,11 +1138,11 @@ namespace bbtk std::string ss("<"); std::string::size_type pos = 0; pos = s.find(ss,0); - char* cr = "["; + std::string cr("["); while ( pos != std::string::npos ) { // std::cout << "*** find one "<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); @@ -813,8 +1233,8 @@ namespace bbtk const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first); tempStrTypeName=id->GetTypeName(); SubsBrackets(tempStrTypeName); - std::string Name(ii->first); - SubsBrackets(Name); + std::string Name(ii->first); + SubsBrackets(Name); labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + " ["+tempStrTypeName+"]"; } labelStr = labelStr+ " } }" ; @@ -834,26 +1254,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,160 +1287,252 @@ namespace bbtk //========================================================================= - void BlackBox::bbShowRelations(BlackBox *parentblackbox, + void BlackBox::bbPrintHelp(BlackBox::Pointer parentblackbox, int detail, int level /*,Factory *factory*/ ) { if (this->bbGetDescriptor()->GetPackage()) { - bbtkMessage("Help",1,"Black Box '"<bbGetDescriptor()->GetPackage()->GetName() <<"::"<bbGetDescriptor()->GetTypeName()<<">"<bbGetDescriptor()->GetTypeName()<<">"<bbGetDescriptor()->GetTypeName()<<">"< iname; std::vector ivalue; std::vector iconn; + std::vector istatus; InputConnectorMapType::iterator i; unsigned int namelmax = 0; unsigned int valuelmax = 0; - unsigned int connlmax = 0; + // unsigned int connlmax = 0; for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) - { - iname.push_back(i->first); - if (iname.back().size()>namelmax) namelmax = iname.back().size(); - ivalue.push_back(bbGetInputAsString(i->first)); - if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size(); - std::string s(""); - Connection* con = i->second->GetConnection(); - if (con!=0){ - s = con->GetBlackBoxFrom()->bbGetName(); - s += "."; - s += con->GetBlackBoxFromOutput(); - } // if con - iconn.push_back(s); - } + { + iname.push_back(i->first); + if (iname.back().size()>namelmax) namelmax = iname.back().size(); + ivalue.push_back(bbGetInputAsString(i->first)); + if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size(); + std::string s(""); + Connection* con = i->second->GetConnection(); + if (con!=0){ + s = con->GetOriginalBlackBoxFrom()->bbGetName(); + s += "."; + s += con->GetOriginalBlackBoxFromOutput(); + } // if con + iconn.push_back(s); + istatus.push_back(GetIOStatusString(i->second->GetStatus())); + } OutputConnectorMapType::iterator o; std::vector oname; std::vector ovalue; std::vector > oconn; + std::vector ostatus; for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o ) - { - oname.push_back(o->first); - if (oname.back().size()>namelmax) namelmax = oname.back().size(); - 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(); - std::vector::const_iterator c; - for (c=con.begin();c!=con.end();++c) - { - std::string s; - s = (*c)->GetBlackBoxTo()->bbGetName(); - s += "."; - s += (*c)->GetBlackBoxToInput(); - ss.push_back(s); - } // if con - oconn.push_back(ss); - } + { + oname.push_back(o->first); + if (oname.back().size()>namelmax) + namelmax = oname.back().size(); + 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(); + std::vector::const_iterator c; + for (c=con.begin();c!=con.end();++c) + { + std::string s; + s = (*c)->GetOriginalBlackBoxTo()->bbGetName(); + s += "."; + s += (*c)->GetOriginalBlackBoxToInput(); + ss.push_back(s); + } // if con + oconn.push_back(ss); + ostatus.push_back(GetIOStatusString(o->second->GetStatus())); + } if (iname.size()) - bbtkMessage("Help",1," * Inputs : "<::iterator i1,i2,i3; - for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin(); - i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end(); - ++i1,++i2,++i3) - { - std::string name(*i1); - name += "'"; - name.append(1+namelmax-name.size(),' '); - std::string value(*i2); - value += "'"; - value.append(1+valuelmax-value.size(),' '); - if (i3->size()) - bbtkMessage("Help",1," '"<size()) + bbtkBlackBoxMessage("help",1," '"< >::iterator i5; + + for (i1=oname.begin(),i2=ovalue.begin(),i5=oconn.begin(),i4=ostatus.begin(); + i1!=oname.end(),i2!=ovalue.end(),i5!=oconn.end(),i4!=ostatus.end(); + ++i1,++i2,++i4,++i5) + { + std::string name(*i1); + name += "'"; + name.append(1+namelmax-name.size(),' '); + std::string value(*i2); + value += "'"; + value.append(1+valuelmax-value.size(),' '); + if (!(*i5).size()) + bbtkBlackBoxMessage("help",1," '"< BlackBox::bbGlobalProcessExecutionList()" - <::iterator i; - for (i=bbmgExecutionList.begin(); - i!=bbmgExecutionList.end(); - ++i) + bbtkDebugMessage("process",3, + "=> BlackBox::bbGlobalProcessExecutionList()" + < Executing "<<(*i)->bbGetFullName()<bbExecute(true); + bbtkDebugMessage("process",3,"BlackBox::bbGlobalProcessExecutionList() reentered !"); + return; + } + bbmgGlobalProcessingExecutionList = true; + + std::set::iterator i; + while (bbmgExecutionList.size()>0) + { + i = bbmgExecutionList.begin(); + BlackBox::WeakPointer p = *i; + bbmgExecutionList.erase(i); + if (p.lock()) + { + bbtkDebugMessage("process",4, + " -> Executing '"<< + p.lock()->bbGetName()<<"'"<bbExecute(true); + } + else + { + bbtkGlobalError("Strange error in BlackBox::bbGlobalProcessExecutionList() : Weak bb pointer in bbmgExecutionList is no more valid..."); + } } bbmgExecutionList.clear(); - bbtkDebugMessageDec("Process",1, + bbtkDebugMessage("process",3, "<= BlackBox::bbGlobalProcessExecutionList()" < BlackBox::bbmgExecutionList; + bool BlackBox::bbGlobalGetSomeBoxExecuting() + { + return bbmgSomeBoxExecuting; + } + + void BlackBox::bbGlobalSetSomeBoxExecuting(bool b) + { + bbmgSomeBoxExecuting = b; + } + + void BlackBox::bbGlobalSetFreezeExecution(bool b) + { + bbmgFreezeExecution = b; + } + + bool BlackBox::bbGlobalGetFreezeExecution() + { + return bbmgFreezeExecution; + } + + void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b ) + { + bbtkDebugMessage("process",3,"* bbGlobalAddToExecutionList("<bbGetName()<<")"<