X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkBlackBox.cxx;h=8be7d01d0e3a283d659957fcf63f6284a8dbb7ba;hb=a35973b128a2f7130b619a2a11a35cfd418b21b6;hp=c21285cd6b136b7e4a7a96aaf92675ed61b561fd;hpb=6575a389b71b1b85c79e4444885becb76ecf16e4;p=bbtk.git diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index c21285c..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/10/17 08:18:12 $ - Version: $Revision: 1.25 $ + 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" @@ -50,9 +51,10 @@ namespace bbtk static bool bbmgSomeBoxExecuting = false; static bool bbmgFreezeExecution = false; - static std::set bbmgExecutionList; + static std::set bbmgExecutionList; //========================================================================= + BlackBox::Deleter::Deleter() { } @@ -77,7 +79,7 @@ namespace bbtk b->bbDelete(); - bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""< BlackBox::Deleter(\""< BlackBox::bbExecute() [" - < 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 @@ -356,6 +332,7 @@ namespace bbtk { if (! o->second->GetCopyConstruct() ) continue; std::string output = o->second->GetName(); + bbtkDebugMessage("Kernel",2,"* Copying output "<bbSetOutput(output, from.bbGetOutput(output) ); } @@ -370,7 +347,7 @@ namespace bbtk bool BlackBox::bbCanReact() const { return ( bbGlobalGetSomeBoxExecuting() -#ifdef _USE_WXWIDGETS_ +#ifdef USE_WXWIDGETS || Wx::IsSomeWindowAlive() #endif ); @@ -406,11 +383,18 @@ namespace bbtk if ( (p == "2") || (p == "R") || (p == "r") || (p == "Reactive") || (p == "reactive") ) return Reactive; + /* + if ( (p == "3") || + (p == "F") || (p == "f") || + (p == "Flash") || (p == "flash") ) return Flash; + */ bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<

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 ) + { + + } + } + + } + //========================================================================= + + //========================================================================= + 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 ( (c==bbGetInputConnectorMap().find("WinClose")->second) ) - // && (bbCanReact())) + 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); + + // 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("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 @@ -571,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() [" @@ -605,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) @@ -644,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; @@ -1046,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); @@ -1070,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()) @@ -1077,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 += "'"; @@ -1089,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<<"]"< BlackBox::bbGlobalProcessExecutionList()" - <::iterator i; - for (i=bbmgExecutionList.begin(); - i!=bbmgExecutionList.end(); - ++i) + < 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()->bbGetFullName()<bbExecute(true); + } + else + { + bbtkGlobalError("Strange error in BlackBox::bbGlobalProcessExecutionList() : Weak bb pointer in bbmgExecutionList is no more valid..."); + } } bbmgExecutionList.clear(); @@ -1150,6 +1483,7 @@ namespace bbtk "<= BlackBox::bbGlobalProcessExecutionList()" <bbGetFullName()<<")"<