X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkBlackBox.cxx;h=8be7d01d0e3a283d659957fcf63f6284a8dbb7ba;hb=a35973b128a2f7130b619a2a11a35cfd418b21b6;hp=f8ad055c388726fdc01ea57d9618ccbff060c30b;hpb=dcd0daa8375b06efaf723f38ee9e074b5f9bb306;p=bbtk.git diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index f8ad055..8be7d01 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/12/03 13:35:22 $ - Version: $Revision: 1.31 $ + Date: $Date: 2009/03/30 14:42:16 $ + Version: $Revision: 1.41 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -36,6 +36,7 @@ #include "bbtkPackage.h" #include "bbtkMessageManager.h" #include "bbtkFactory.h" +#include "bbtkBlackBoxOutputConnector.h" #include "bbtkConfigurationFile.h" #include "bbtkWxBlackBox.h" @@ -53,6 +54,7 @@ namespace bbtk static std::set bbmgExecutionList; //========================================================================= + BlackBox::Deleter::Deleter() { } @@ -77,7 +79,7 @@ namespace bbtk b->bbDelete(); - bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""< BlackBox::Deleter(\""< BlackBox::bbExecute("<<(int)force<<") [" - < already executing : bailing out"< FreezeExecution global flag is 'true' : abort execution"< 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); + } + } } - if ( (c==bbGetInputConnectorMap().find("WinClose")->second) ) - // && (bbCanReact())) + } + //========================================================================= + + //========================================================================= + /// 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 ) { - bbtkDebugMessage("modified",2, - "-> Close triggered by WinClose input change" - <bbHideWindow(); - this->bbSetStatus(MODIFIED); - return; + mMaxInputChangeTime = t; + if ( mMinOutputChangeTime > mMaxInputChangeTime ) + { + + } } - if ( ( bbBoxProcessModeIsReactive() || - (c==bbGetInputConnectorMap().find("BoxExecute")->second)) - && (bbCanReact() ) ) + } + //========================================================================= + + //========================================================================= + void bbUpdateMinOutputChangeTime(const ChangeTime& t) + { + ChangeTime old = mMinOutputChangeTime; + mMinOutputChangeTime = MAXLONG; + OutputConnectorMapType::iterator i; + for (i = bbGetOutputConnectorMap.begin(); + i != bbGetOutputConnectorMap.end(); + ++i) { - bbtkDebugMessage("modified",2, - "-> Execution triggered by Reactive mode or BoxExecute input change"<bbSetStatus(MODIFIED); - bbGlobalAddToExecutionList( GetThisPointer() ); + if (i->second->GetChangeTime() < mMinOutputChangeTime) + mMinOutputChangeTime = i->second->GetChangeTime(); } - /* - 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::bbSetStatusAndPropagate(input," + <SetStatus(s); + + // Flash reaction + /* + if (bbGetBoxProcessModeValue() == Flash) + { + 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("change",2, + "-> Execution triggered by Reactive mode or BoxExecute input change"<() ); + } + bbtkDebugMessageInc("change",5, + "<= BlackBox::bbSetStatusAndPropagate(input) [" + < 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 @@ -583,28 +679,160 @@ 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"<bbCreateWidget(); + + // 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 [" + <first<<"' is Out-of-date ???"); + } + } + + bbtkDebugMessage("process",3," -> Up-to-date : nothing to do" + <bbShowWidget(); + + + bbtkDebugMessage("process",3, + "<= BlackBox::bbRecursiveExecute() [" + < BlackBox::bbUpdateInputs() [" @@ -617,28 +845,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) @@ -656,13 +941,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; @@ -1058,11 +1357,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); @@ -1082,6 +1383,7 @@ namespace bbtk ss.push_back(s); } // if con oconn.push_back(ss); + ostatus.push_back(GetIOStatusString(o->second->GetStatus())); } if (iname.size()) @@ -1089,10 +1391,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 += "'"; @@ -1101,9 +1403,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<<"]"<