X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkBlackBox.cxx;h=a4dea22c8624d2e0959d574c573799a54122dd72;hb=d7e710c3fe8bd9c8c5fb79073bd5667b24c048f8;hp=3b3955622d59b996fb88bcd0989b5b2923b99b4b;hpb=236a8e2fee9937c050e2d16c7222e1caa993f01c;p=bbtk.git diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index 3b39556..a4dea22 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/13 14:46:43 $ - Version: $Revision: 1.28 $ + Date: $Date: 2008/12/11 15:30:04 $ + Version: $Revision: 1.38 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -36,6 +36,7 @@ #include "bbtkPackage.h" #include "bbtkMessageManager.h" #include "bbtkFactory.h" +#include "bbtkBlackBoxOutputConnector.h" #include "bbtkConfigurationFile.h" #include "bbtkWxBlackBox.h" @@ -102,7 +103,7 @@ namespace bbtk //========================================================================= BlackBox::BlackBox(const std::string &name) : - bbmStatus(MODIFIED), + // bbmStatus(MODIFIED), bbmExecuting(false), bbmName(name), bbmBoxProcessMode("Pipeline"), @@ -123,7 +124,7 @@ namespace bbtk //========================================================================= BlackBox::BlackBox(BlackBox& from, const std::string &name) : - bbmStatus(from.bbmStatus), + // bbmStatus(from.bbmStatus), bbmExecuting(false), bbmName(name), bbmBoxProcessMode(from.bbmBoxProcessMode), @@ -152,42 +153,6 @@ namespace bbtk //========================================================================= - //========================================================================= - /// Main processing method of the box. - void BlackBox::bbExecute(bool force) - { - bbtkDebugMessageInc("process",2, - "=> BlackBox::bbExecute("<<(int)force<<") [" - < already executing : bailing out"< FreezeExecution global flag is 'true' : abort execution"<second->GetCopyConstruct() ) continue; std::string input = i->second->GetName(); + bbtkDebugMessage("Kernel",2,"* Copying input "<bbSetInput(input, from.bbGetInput(input) ); } // copies the output values @@ -365,6 +331,7 @@ namespace bbtk { if (! o->second->GetCopyConstruct() ) continue; std::string output = o->second->GetName(); + bbtkDebugMessage("Kernel",2,"* Copying output "<bbSetOutput(output, from.bbGetOutput(output) ); } @@ -379,7 +346,7 @@ namespace bbtk bool BlackBox::bbCanReact() const { return ( bbGlobalGetSomeBoxExecuting() -#ifdef _USE_WXWIDGETS_ +#ifdef USE_WXWIDGETS || Wx::IsSomeWindowAlive() #endif ); @@ -437,92 +404,199 @@ namespace bbtk } //========================================================================= + + + + //========================================================================= + void BlackBox::bbAddOutputObserver(const std::string& output, + OutputChangeCallbackType f) + { + bbGetOutputConnector(output).AddChangeObserver(f); + } + //========================================================================= + + //========================================================================= + void BlackBox::bbRemoveOutputObserver(const std::string& output_name, + OutputChangeCallbackType f) + { + bbtkError("BlackBox::RemoveChangeObserver NOT IMPLEMENTED"); + } + //========================================================================= + + + /* //========================================================================= - /// Signals that the BlackBox has been modified - void BlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c) + /// Sets the ChangeTime of input + void BlackBox::bbSetInputChangeTime(BlackBoxInputConnector* c, + const ChangeTime& t) { - bbtkDebugMessage("modified",1, - "==> BlackBox::bbSetModifiedStatus("< BlackBox::bbSetInputChangeTime("<second) ) - // && (bbCanReact())) + // If new time is greater than old one + if ( c->SetChangeTime(t) ) { - bbtkDebugMessage("modified",2, - "-> Hide triggered by WinHide input change" - <bbHideWindow(); - this->bbSetStatus(MODIFIED); - return; + bool was_up_to_date = bbIsUpToDate(); + // If new time is greater than the old max time of inputs + if ( mMaxInputChangeTime.Set(t) ) + { + // If the box turned out-of-date + if ( was_up_to_date && bbIsOutOfDate() ) + { + // + if ( ( bbBoxProcessModeIsReactive() || + (c==bbGetInputConnectorMap().find("BoxExecute")->second)) + && (bbCanReact() ) ) + { + bbtkDebugMessage("change",2, + "an input of " + <() ); + } + // Have to propagate the modification to aval boxes + OutputConnectorMapType::iterator i; + for (i = bbGetOutputConnectorMap().begin(); + i != bbGetOutputConnectorMap().end(); + ++i) + { + i->second->SetChangeTime(t); + } + // update the MinOutputChangeTime + mMinOutputChangeTime.Set(t); + } + } + } + } + //========================================================================= + + //========================================================================= + /// Sets the ChangeTime of output + void BlackBox::bbSetOutputChangeTime(BlackBoxOutputConnector* c, + const ChangeTime& t) + { + bbtkDebugMessage("change",1, + "==> BlackBox::bbSetOutputChangeTime("<SetChangeTime(t); + // c->GetChangeTime() = t; + // bbUpdateMinOutputChangeTime(t); + // propagate + + } + //========================================================================= + */ + + /* + //========================================================================= + void BlackBox::bbUpdateMaxInputChangeTime(const ChangeTime& t) + { + + + if ( t > mMaxInputChangeTime ) + { + mMaxInputChangeTime = t; + if ( mMinOutputChangeTime > mMaxInputChangeTime ) + { + + } } - if ( (c==bbGetInputConnectorMap().find("WinClose")->second) ) - // && (bbCanReact())) + + } + //========================================================================= + + //========================================================================= + void bbUpdateMinOutputChangeTime(const ChangeTime& t) + { + ChangeTime old = mMinOutputChangeTime; + mMinOutputChangeTime = MAXLONG; + OutputConnectorMapType::iterator i; + for (i = bbGetOutputConnectorMap.begin(); + i != bbGetOutputConnectorMap.end(); + ++i) + { + if (i->second->GetChangeTime() < mMinOutputChangeTime) + mMinOutputChangeTime = i->second->GetChangeTime(); + } + if ( mMinOutputChangeTime < old ) { - bbtkDebugMessage("modified",2, - "-> Close triggered by WinClose input change" - <bbHideWindow(); - this->bbSetStatus(MODIFIED); - return; } + + } + //========================================================================= + */ + + //========================================================================= + /// Signals that the BlackBox has been modified through + /// the input connector c + /// and propagates it downward + /// ** NOT USER INTENDED ** + void BlackBox::bbSetStatusAndPropagate(BlackBoxInputConnector* c, + IOStatus s) + { + bbtkDebugMessageInc("change",5, + "=> BlackBox::bbSetStatusAndPropagate(input," + <SetStatus(s); + 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, + bbtkDebugMessage("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() [" + bbtkDebugMessageInc("change",5, + "=> 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, + bbtkDebugMessageDec("change",5, "<= 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, + bbtkDebugMessageInc("change",5, "=> 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 @@ -580,28 +662,155 @@ 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) [" + bbtkDebugMessageDec("change",5, + "<= BlackBox::bbSignalOutputModification(vector of outputs) [" < BlackBox::bbExecute("<<(int)force<<") [" + < already executing : abort"< FreezeExecution global flag is 'true' : abort execution"< BlackBox::bbRecursiveExecute(" + <<(caller?caller->GetFullName():"0")<<") [" + < already executing : abort"<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 [" + <first<<"' is Out-of-date ???"); + } + } + + bbtkDebugMessage("process",3," -> Up-to-date : nothing to do" + < BlackBox::bbUpdateInputs() [" @@ -614,28 +823,85 @@ namespace bbtk for ( i = bbGetInputConnectorMap().begin(); i!= bbGetInputConnectorMap().end(); ++i) { - if (excludeParent && (i->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; + bbtkDebugMessageDec("change",2, + bbGetName()<<"."<first + <<" ["<second<<"] " + <<" status before update = '" + <second->GetStatus()) + <<"'"<second->RecursiveExecute(); + IOStatus t = i->second->GetStatus(); + if (t > s) s = t; + bbtkDebugMessageDec("change",2, + bbGetName()<<"."<first + <<" ["<second<<"] " + <<" 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); + bbtkDebugMessage("change",2, + bbGetName()<<"."<first<<" : " + << GetIOStatusString(t) << " -> " + << GetIOStatusString(i->second->GetStatus()) + << std::endl); + } + bbtkDebugMessage("change",2, + bbGetName()<<" new output status : " + << GetIOStatusString(new_output_status) + <second->SetStatus(new_output_status); + } + + bbtkDebugMessageInc("process",4, + "<= BlackBox::bbComputePostProcessStatus() [" + < to the connection c void BlackBox::bbConnectInput( const std::string& name, Connection* c) @@ -653,13 +919,14 @@ namespace bbtk bbtkError("no input called '"<second->SetConnection(c); + // The input *MUST* be set OUTOFDATE to update its input on next execution + bbSetStatusAndPropagate(i->second,OUTOFDATE); bbtkDebugMessage("connection",2, "<== BlackBox::bbConnectInput(\"" <GetFullName()<<") [" <bbGetDescriptor()->GetTypeName()<<">"< iname; std::vector ivalue; std::vector iconn; + std::vector istatus; InputConnectorMapType::iterator i; unsigned int namelmax = 0; @@ -1055,11 +1335,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); @@ -1079,6 +1361,7 @@ namespace bbtk ss.push_back(s); } // if con oconn.push_back(ss); + ostatus.push_back(GetIOStatusString(o->second->GetStatus())); } if (iname.size()) @@ -1086,10 +1369,10 @@ namespace bbtk else bbtkMessage("Help",1," * No 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 += "'"; @@ -1098,9 +1381,11 @@ namespace bbtk value += "'"; value.append(1+valuelmax-value.size(),' '); if (i3->size()) - bbtkMessage("Help",1," '"< '"<<*i3<<"'"); pref.replace(0,pref.size(),pref.size(),' '); } } + bbtkMessage("Help",1," ["<<*i4<<"]"<