X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkBlackBox.cxx;h=8be7d01d0e3a283d659957fcf63f6284a8dbb7ba;hb=a35973b128a2f7130b619a2a11a35cfd418b21b6;hp=5cffb502dad9552a427eb085437c2bc9668c7f11;hpb=857e5e5bd003d20cb8bc4539b6fca4ca9d50929c;p=bbtk.git diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index 5cffb50..8be7d01 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/05/15 08:02:36 $ -Version: $Revision: 1.19 $ - -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: 2009/03/30 14:42:16 $ + Version: $Revision: 1.41 $ =========================================================================*/ +/* --------------------------------------------------------------------- + +* 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 @@ -25,6 +36,7 @@ PURPOSE. See the above copyright notices for more information. #include "bbtkPackage.h" #include "bbtkMessageManager.h" #include "bbtkFactory.h" +#include "bbtkBlackBoxOutputConnector.h" #include "bbtkConfigurationFile.h" #include "bbtkWxBlackBox.h" @@ -39,9 +51,10 @@ namespace bbtk static bool bbmgSomeBoxExecuting = false; static bool bbmgFreezeExecution = false; - static std::set bbmgExecutionList; + static std::set bbmgExecutionList; //========================================================================= + BlackBox::Deleter::Deleter() { } @@ -66,7 +79,7 @@ namespace bbtk b->bbDelete(); - bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""< BlackBox::Deleter(\""< BlackBox::BlackBox(\"" < 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 @@ -344,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) ); } @@ -358,7 +347,7 @@ namespace bbtk bool BlackBox::bbCanReact() const { return ( bbGlobalGetSomeBoxExecuting() -#ifdef _USE_WXWIDGETS_ +#ifdef USE_WXWIDGETS || Wx::IsSomeWindowAlive() #endif ); @@ -394,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 ) + { + + } } - 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) { - bbtkDebugMessage("modified",2, - "-> Close triggered by WinClose input change" - <bbHideWindow(); - this->bbSetStatus(MODIFIED); - return; + if (i->second->GetChangeTime() < mMinOutputChangeTime) + mMinOutputChangeTime = i->second->GetChangeTime(); + } + if ( mMinOutputChangeTime < old ) + { + } + + } + //========================================================================= + */ + + //========================================================================= + /// 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 @@ -557,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() [" @@ -591,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) @@ -630,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; 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); @@ -1032,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); @@ -1056,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()) @@ -1063,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 += "'"; @@ -1075,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) + <::iterator i; + while (bbmgExecutionList.size()>0) { - bbtkDebugMessage("process",4, - " -> 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(); @@ -1136,6 +1483,7 @@ namespace bbtk "<= BlackBox::bbGlobalProcessExecutionList()" <bbGetFullName()<<")"< BlackBox::bbmgExecutionList; -*/ //========================================================================= //========================================================================= @@ -1183,6 +1529,16 @@ namespace bbtk } //========================================================================= + void BlackBox::bbUserOnShowWidget(std::string nameInput) + { + bbtk::BlackBoxInputConnector *cc; + cc = this->bbGetInputConnectorMap().find( nameInput.c_str() )->second; + if (cc->GetConnection()!=NULL) + { + cc->GetConnection()->GetBlackBoxFrom()->bbUserOnShow(); + } + } + } // EO namespace bbtk