X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkBlackBox.cxx;h=35bda120cdf1aebc80a2d43cdc83e8dcecc1e9cf;hb=e542f5cdbfc165e80003d21b2fbf0e6a69344bb0;hp=ddfc3ed9576598ad5b150716c67dbec7ccafe65e;hpb=1e2df7fb6ae571ce1cf72e6af1715f0e34675cbf;p=bbtk.git diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index ddfc3ed..35bda12 100644 --- a/kernel/src/bbtkBlackBox.cxx +++ b/kernel/src/bbtkBlackBox.cxx @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbtkBlackBox.cxx,v $ Language: C++ - Date: $Date: 2008/11/25 11:17:13 $ - Version: $Revision: 1.29 $ + Date: $Date: 2011/03/03 14:33:13 $ + Version: $Revision: 1.51 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -36,9 +36,11 @@ #include "bbtkPackage.h" #include "bbtkMessageManager.h" #include "bbtkFactory.h" +#include "bbtkBlackBoxOutputConnector.h" #include "bbtkConfigurationFile.h" #include "bbtkWxBlackBox.h" +#include "bbtkWx.h" #include //#include @@ -46,20 +48,19 @@ namespace bbtk { - - static bool bbmgSomeBoxExecuting = false; static bool bbmgFreezeExecution = false; static std::set bbmgExecutionList; //========================================================================= + BlackBox::Deleter::Deleter() { } //========================================================================= //========================================================================= - void BlackBox::Deleter::Delete(Object* p) + int BlackBox::Deleter::Delete(Object* p) { BlackBox* b = dynamic_cast(p); if (!b) @@ -75,9 +76,9 @@ namespace bbtk BlackBoxDescriptor::WeakPointer desc = b->bbGetDescriptor(); bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<bbDelete(); + int refs = b->bbDelete(); - bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""< BlackBox::Deleter(\""< BlackBox::Deleter(\""< BlackBox::BlackBox(\"" + //JCP 02-11-09 + // bbmBoxProcessMode = "Pipeline"; +//std::cout<<"JCP BlackBox::BlackBox(const std::string &name) name=" < BlackBox::BlackBox(\"" < BlackBox::BlackBox(" + //JCP 02-11-09 + //bbmBoxProcessMode = from.bbmBoxProcessMode; + //std::cout<<"JCP BlackBox::BlackBox(const std::string &name) name=" < BlackBox::BlackBox(" < BlackBox::~BlackBox() ["< BlackBox::~BlackBox() ["<bbDesallocateConnectors(); - bbtkDebugMessage("object",4,"<== BlackBox::~BlackBox() ["< BlackBox::bbExecute("<<(int)force<<") [" - < already executing : bailing out"< FreezeExecution global flag is 'true' : abort execution"<GetHelp(full); @@ -223,76 +197,76 @@ namespace bbtk //========================================================================= - /// Returns true if the UserBlackBox has an input of name name bool BlackBox::bbHasInput(const std::string& name) const { - bbtkDebugMessageInc("Kernel",8, + bbtkBlackBoxDebugMessage("kernel",8, "BlackBox::bbHasInput(\"" - <GetInputDescriptorMap().find(name) != bbGetDescriptor()->GetInputDescriptorMap().end()); - bbtkDebugDecTab("Kernel",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("Kernel",8,"BlackBox::bbHasOutput(\"" - <GetOutputDescriptorMap().find(name) != bbGetDescriptor()->GetOutputDescriptorMap().end()); - bbtkDebugDecTab("Kernel",8); + bbtkDebugDecTab("kernel",8); return r; } //========================================================================= //========================================================================= - /// Gets the output type of a given name TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const { - bbtkDebugMessageInc("Kernel",8, - "BlackBox::bbGetOutputType(\"" - <GetOutputDescriptor(name)->GetTypeInfo(); - bbtkDebugDecTab("Kernel",8); + bbtkDebugDecTab("kernel",8); return r; } //========================================================================= //========================================================================= - /// Gets the input type of a given name TypeInfo BlackBox::bbGetInputType( const std::string &name ) const { - bbtkDebugMessageInc("Kernel",8, - "BlackBox::bbGetInputType(\"" - <GetInputDescriptor(name)->GetTypeInfo(); - bbtkDebugDecTab("Kernel",8); + bbtkDebugDecTab("kernel",8); return r; } //========================================================================= //========================================================================= - /// Allocates the i/o connectors of the black box void BlackBox::bbAllocateConnectors() { - bbtkDebugMessageInc("Kernel",8, - "BlackBox::bbAllocateConnectors() [" - <GetInputDescriptorMap(); BlackBoxDescriptor::InputDescriptorMapType::const_iterator i; for ( i = imap.begin(); i != imap.end(); ++i ) { - bbtkDebugMessage("Kernel",8,"* Allocate \""<first<<"\""<first<<"\""<second->GetName()] = new BlackBoxInputConnector(GetThisPointer()); } @@ -301,20 +275,18 @@ namespace bbtk BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o; for ( o = omap.begin(); o != omap.end(); ++o ) { - bbtkDebugMessage("Kernel",8,"* Allocate \""<first<<"\""<first<<"\""<second->GetName()] - = new BlackBoxOutputConnector(); + = new BlackBoxOutputConnector(GetThisPointer()); } - bbtkDebugDecTab("Kernel",8); } //========================================================================= //========================================================================= - /// Desallocates the i/o connectors of the black box void BlackBox::bbDesallocateConnectors() { - bbtkDebugMessageInc("Kernel",8, + bbtkBlackBoxDebugMessage("kernel",8, "BlackBox::bbDesallocateConnectors()" <first<<"\""<first<<"\""<second); } OutputConnectorMapType::const_iterator o; for ( o = bbGetOutputConnectorMap().begin(); o != bbGetOutputConnectorMap().end(); ++o ) { - bbtkDebugMessage("Kernel",8,"* Delete \""<first<<"\""<first<<"\""<second); } - bbtkDebugDecTab("Kernel",8); - + bbtkDebugDecTab("kernel",8); } //========================================================================= //========================================================================= - /// Copies the input / output values from another box void BlackBox::bbCopyIOValues(BlackBox& from) { - bbtkDebugMessageInc("Kernel",1, - "BlackBox::bbCopyIOValues(" - <GetInputDescriptorMap(); @@ -355,7 +325,7 @@ namespace bbtk { if (! i->second->GetCopyConstruct() ) continue; std::string input = i->second->GetName(); - bbtkDebugMessage("Kernel",2,"* Copying input "<bbSetInput(input, from.bbGetInput(input) ); } // copies the output values @@ -366,12 +336,11 @@ namespace bbtk { if (! o->second->GetCopyConstruct() ) continue; std::string output = o->second->GetName(); - bbtkDebugMessage("Kernel",2,"* Copying output "<bbSetOutput(output, from.bbGetOutput(output) ); } - bbtkDebugDecTab("Kernel",9); - + bbtkDebugDecTab("kernel",9); } //========================================================================= @@ -381,197 +350,203 @@ namespace bbtk bool BlackBox::bbCanReact() const { return ( bbGlobalGetSomeBoxExecuting() -#ifdef _USE_WXWIDGETS_ +#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("modified",2, - "-> Hide triggered by WinHide input change" - <bbHideWindow(); - this->bbSetStatus(MODIFIED); - return; - } - if ( (c==bbGetInputConnectorMap().find("WinClose")->second) ) - // && (bbCanReact())) + bbGetOutputConnector(output).AddChangeObserver(f); + } + //========================================================================= + + //========================================================================= + void BlackBox::bbRemoveOutputObserver(const std::string& output_name, + OutputChangeCallbackType f) + { + bbtkError("BlackBox::RemoveChangeObserver NOT IMPLEMENTED"); + } + //========================================================================= + + + //========================================================================= + void BlackBox::bbSetStatusAndPropagate(BlackBoxInputConnector* c, + IOStatus s) + { + bbtkBlackBoxDebugMessage("change",5, + "=> BlackBox::bbSetStatusAndPropagate(input," + <SetStatus(s); + + // Flash reaction + /* + if (bbGetBoxProcessModeValue() == Flash) { - bbtkDebugMessage("modified",2, - "-> Close triggered by WinClose input change" - <bbHideWindow(); - this->bbSetStatus(MODIFIED); - return; + this->bbExecute(); } + */ + + OutputConnectorMapType::const_iterator o; + for ( o = bbGetOutputConnectorMap().begin(); + o != bbGetOutputConnectorMap().end(); ++o ) + { + if (o->second->GetStatus()==UPTODATE) + { + o->second->SetStatus(OUTOFDATE); + o->second->SignalChange(GetThisPointer(),o->first); + } + } if ( ( bbBoxProcessModeIsReactive() || (c==bbGetInputConnectorMap().find("BoxExecute")->second)) && (bbCanReact() ) ) { - bbtkDebugMessage("modified",2, + bbtkBlackBoxDebugMessage("change",2, "-> Execution triggered by Reactive mode or BoxExecute input change"<bbSetStatus(MODIFIED); bbGlobalAddToExecutionList( GetThisPointer() ); - } - /* - else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate()) - { - bbtkDebugMessage("modified",2,"-> Already modified"< Status set to modified"<bbSetStatus(MODIFIED); - } - - this->bbSignalOutputModification(false); - - /* - bbtkDebugMessageDec("process",5, - "<= BlackBox::bbSetModifiedStatus("< 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); + // } + } 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 @@ -582,32 +557,187 @@ 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; + } + } + //========================================================================= + + + //========================================================================= + void BlackBox::bbRecursiveExecute( Connection::Pointer caller ) + { + bbtkBlackBoxDebugMessage("process",3, + "=> BlackBox::bbRecursiveExecute(" + <<(caller?caller->GetFullName():"0")<<")" + < already executing : abort"<bbCreateWindow(); + + // Updates its inputs + IOStatus s = bbUpdateInputs(); + + if ( (s != UPTODATE) || + bbBoxProcessModeIsAlways() ) + { + // Displays the window (WxBlackbox) + // bbShowWindow(caller); + + // Actual processing (virtual) + this->bbProcess(); + + + // 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() [" - < 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); + } + + bbtkBlackBoxDebugMessage("process",4, + "<= BlackBox::bbComputePostProcessStatus()" + < to the connection c void BlackBox::bbConnectInput( const std::string& name, Connection* c) { - bbtkDebugMessage("connection",2, + bbtkBlackBoxDebugMessage("connection",2, "==> BlackBox::bbConnectInput(\"" - <GetFullName()<<") [" - <GetFullName()<<")" <second->SetConnection(c); - - bbtkDebugMessage("connection",2, - "<== BlackBox::bbConnectInput(\"" - <GetFullName()<<") [" - <second,OUTOFDATE); + bbtkBlackBoxDebugMessage("connection",2, + "<== BlackBox::bbConnectInput(\"" + <GetFullName()<<")" + < to the connection c void BlackBox::bbConnectOutput( const std::string& name, Connection* c) { - bbtkDebugMessage("connection",2, - "==> BlackBox::bbConnectOutput(\""<GetFullName()<<") [" - < BlackBox::bbConnectOutput(\""<GetFullName()<<")" + <second->SetConnection(c); - bbtkDebugMessage("connection",2, - "<== BlackBox::bbConnectOutput(\""<GetFullName()<<") [" - <GetFullName()<<")" + < from the connection c - void BlackBox::bbDisconnectInput( const std::string& name, Connection* c) + void BlackBox::bbDisconnectInput( const std::string& name, Connection* c) { - bbtkDebugMessage("connection",2, + bbtkBlackBoxDebugMessage("connection",2, "==> BlackBox::bbDisconnectInput(\""<GetFullName()<<") [" - <GetFullName()<<")" + <second->UnsetConnection(c); - bbtkDebugMessage("connection",2, + bbtkBlackBoxDebugMessage("connection",2, "<== BlackBox::bbDisconnectInput(\""<GetFullName()<<") [" - <GetFullName()<<")" < from the connection c - void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c) + void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c) { - bbtkDebugMessage("connection",2, + bbtkBlackBoxDebugMessage("connection",2, "==> BlackBox::bbDisconnectOutput(\""<GetFullName()<<") [" - <GetFullName()<<")" <second->UnsetConnection(c); - bbtkDebugMessage("connection",2, + bbtkBlackBoxDebugMessage("connection",2, "<== BlackBox::bbDisconnectOutput(\""<GetFullName()<<") [" - <GetFullName()<<")" <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; @@ -1057,11 +1255,13 @@ namespace bbtk 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); @@ -1081,17 +1281,18 @@ namespace bbtk 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::vector::iterator i1,i2,i3,i4; + for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin(),i4=istatus.begin(); + i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end(),i4!=istatus.end(); + ++i1,++i2,++i3,++i4) { std::string name(*i1); name += "'"; @@ -1100,21 +1301,23 @@ namespace bbtk value += "'"; value.append(1+valuelmax-value.size(),' '); if (i3->size()) - bbtkMessage("Help",1," '"< '"<<*i3<<"'"); pref.replace(0,pref.size(),pref.size(),' '); } } + bbtkBlackBoxMessage("help",1," ["<<*i4<<"]"< BlackBox::bbGlobalProcessExecutionList()" - < BlackBox::bbGlobalProcessExecutionList()" + < Executing "<< - p.lock()->bbGetFullName()< Executing '"<< + p.lock()->bbGetName()<<"'"<bbExecute(true); } else @@ -1173,7 +1394,7 @@ namespace bbtk } bbmgExecutionList.clear(); - bbtkDebugMessageDec("process",3, + bbtkDebugMessage("process",3, "<= BlackBox::bbGlobalProcessExecutionList()" <bbGetFullName()<<")"<bbGetName()<<")"<bbGetInputConnectorMap().find( nameInput.c_str() )->second; - if (cc->GetConnection()!=NULL) - { - cc->GetConnection()->GetBlackBoxFrom()->bbUserOnShow(); - } - }