X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkBlackBox.cxx;h=5fc7d01babe0b9224cb59e7b194a34e24e9aafe7;hb=ae4497a19b957df306e688ce3f69c3687323668e;hp=7955ccfc4ab4a0b1b77f13ae4246c6675c870d3c;hpb=3fb0c5f4f00f86519c93413ab2386c47c5224345;p=bbtk.git diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index 7955ccf..5fc7d01 100644 --- a/kernel/src/bbtkBlackBox.cxx +++ b/kernel/src/bbtkBlackBox.cxx @@ -1,21 +1,32 @@ -/*========================================================================= - -Program: bbtk -Module: $RCSfile: bbtkBlackBox.cxx,v $ -Language: C++ -Date: $Date: 2008/02/20 16:05:38 $ -Version: $Revision: 1.5 $ - -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: 2008/12/03 09:34:37 $ + Version: $Revision: 1.30 $ =========================================================================*/ +/* --------------------------------------------------------------------- + +* 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 @@ -35,24 +46,94 @@ 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("Kernel",7); - } - //========================================================================= - - //========================================================================= - /// Destruction method of a black box - void BlackBox::bbDelete() - { - bbtkDebugMessage("Kernel",5,"BlackBox::bbDelete() [" - <bbUserDelete(); + bbtkDebugMessage("object",4,"<== BlackBox::~BlackBox() ["< BlackBox::bbExecute() [" + bbtkDebugMessageInc("process",2, + "=> BlackBox::bbExecute("<<(int)force<<") [" < already executing : bailing out"< FreezeExecution global flag is 'true' : abort execution"<bbGetDescriptor()->GetTypeName()+">"; + return this->bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">"; } //========================================================================= @@ -125,9 +202,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 { @@ -217,7 +294,7 @@ namespace bbtk { bbtkDebugMessage("Kernel",8,"* Allocate \""<first<<"\""<second->GetName()] - = new BlackBoxInputConnector(this); + = new BlackBoxInputConnector(GetThisPointer()); } const BlackBoxDescriptor::OutputDescriptorMapType& omap = bbGetDescriptor()->GetOutputDescriptorMap(); @@ -266,7 +343,7 @@ namespace bbtk /// Copies the input / output values from another box void BlackBox::bbCopyIOValues(BlackBox& from) { - bbtkDebugMessageInc("Kernel",9, + bbtkDebugMessageInc("Kernel",1, "BlackBox::bbCopyIOValues(" <second->GetCopyConstruct() ) continue; std::string input = i->second->GetName(); + bbtkDebugMessage("Kernel",2,"* Copying input "<bbSetInput(input, from.bbGetInput(input) ); } // copies the output values @@ -288,6 +366,7 @@ namespace bbtk { if (! o->second->GetCopyConstruct() ) continue; std::string output = o->second->GetName(); + bbtkDebugMessage("Kernel",2,"* Copying output "<bbSetOutput(output, from.bbGetOutput(output) ); } @@ -315,7 +394,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 ( (c==bbGetInputConnectorMap().find("WinClose")->second) ) + // && (bbCanReact())) + { + bbtkDebugMessage("modified",2, + "-> Close triggered by WinClose 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); + std::cout << "Status set to modified" <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("Kernel",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("Kernel",7, - "BlackBox::bbConnectOutput(\""< BlackBox::bbConnectOutput(\""<GetFullName()<<") [" + <second->SetConnection(c); - bbtkDebugDecTab("Kernel",7); + bbtkDebugMessage("connection",2, + "<== BlackBox::bbConnectOutput(\""<GetFullName()<<") [" + < from the connection c void BlackBox::bbDisconnectInput( const std::string& name, Connection* c) { - bbtkDebugMessageInc("Kernel",7, - "BlackBox::bbDisconnectInput(\""< BlackBox::bbDisconnectInput(\""<GetFullName()<<") [" + <second->UnsetConnection(c); - bbtkDebugDecTab("Kernel",7); + bbtkDebugMessage("connection",2, + "<== BlackBox::bbDisconnectInput(\""<GetFullName()<<") [" + < from the connection c void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c) { - bbtkDebugMessageInc("Kernel",7, - "BlackBox::bbDisconnectOutput(\""< BlackBox::bbDisconnectOutput(\""<GetFullName()<<") [" + <second->UnsetConnection(c); - bbtkDebugDecTab("Kernel",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 +821,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,7 +902,7 @@ 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 ) @@ -836,26 +985,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 @@ -869,7 +1018,7 @@ namespace bbtk //========================================================================= - void BlackBox::bbShowRelations(BlackBox *parentblackbox, + void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox, int detail, int level /*,Factory *factory*/ ) { @@ -894,7 +1043,7 @@ namespace bbtk 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); @@ -904,9 +1053,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); } @@ -921,14 +1070,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); @@ -989,40 +1139,102 @@ namespace bbtk } //========================================================================= + static bool bbmgGlobalProcessingExecutionList = false; //========================================================================= void BlackBox::bbGlobalProcessExecutionList() { - bbtkDebugMessageInc("Process",1, + bbtkDebugMessageInc("process",3, "=> BlackBox::bbGlobalProcessExecutionList()" - <::iterator i; - for (i=bbmgExecutionList.begin(); - i!=bbmgExecutionList.end(); - ++i) + <::iterator i; + while (bbmgExecutionList.size()>0) { - bbtkDebugMessage("Process",2, - " -> Executing "<<(*i)->bbGetFullName()<bbExecute(true); + i = bbmgExecutionList.begin(); + BlackBox::WeakPointer p = *i; + bbmgExecutionList.erase(i); + if (p.lock()) + { + bbtkDebugMessage("process",4, + " -> Executing "<< + p.lock()->bbGetFullName()<bbExecute(true); + } + else + { + bbtkGlobalError("Strange error in BlackBox::bbGlobalProcessExecutionList() : Weak bb pointer in bbmgExecutionList is no more valid..."); + } } bbmgExecutionList.clear(); - bbtkDebugMessageDec("Process",1, + bbtkDebugMessageDec("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("<bbGetFullName()<<")"<bbGetInputConnectorMap().find( nameInput.c_str() )->second; + if (cc->GetConnection()!=NULL) + { + cc->GetConnection()->GetBlackBoxFrom()->bbUserOnShow(); + } + } + + } // EO namespace bbtk