1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0026005: Problem with transient TFunction_Logbook

This commit is contained in:
vro
2015-11-24 08:56:17 +03:00
committed by bugmaster
parent 8156ddddc7
commit f486f64d86
44 changed files with 438 additions and 257 deletions

View File

@@ -47,14 +47,15 @@ void TFunction_Driver::Init(const TDF_Label& L)
//purpose : Validates labels of a function
//=======================================================================
void TFunction_Driver::Validate(TFunction_Logbook& log) const
void TFunction_Driver::Validate(Handle(TFunction_Logbook)& log) const
{
TDF_LabelList res;
Results(res);
TDF_ListIteratorOfLabelList itr(res);
for (; itr.More(); itr.Next())
{
log.SetValid(itr.Value(), Standard_True);
log->SetValid(itr.Value(), Standard_True);
}
}
@@ -64,15 +65,16 @@ void TFunction_Driver::Validate(TFunction_Logbook& log) const
//purpose : Analyzes the labels in the logbook
//=======================================================================
Standard_Boolean TFunction_Driver::MustExecute(const TFunction_Logbook& log) const
Standard_Boolean TFunction_Driver::MustExecute(const Handle(TFunction_Logbook)& log) const
{
// Check modification of arguments.
TDF_LabelList args;
Arguments(args);
TDF_ListIteratorOfLabelList itr(args);
for (; itr.More(); itr.Next())
{
if (log.IsModified(itr.Value()))
if (log->IsModified(itr.Value()))
return Standard_True;
}
return Standard_False;

View File

@@ -62,18 +62,18 @@ public:
//! method even if the function is not executed.
//! execution of function
//! =====================
Standard_EXPORT virtual void Validate (TFunction_Logbook& log) const;
Standard_EXPORT virtual void Validate (Handle(TFunction_Logbook)& log) const;
//! Analyzes the labels in the logbook log.
//! Returns true if attributes have been modified.
//! If the function label itself has been modified, the function must be executed.
Standard_EXPORT virtual Standard_Boolean MustExecute (const TFunction_Logbook& log) const;
Standard_EXPORT virtual Standard_Boolean MustExecute (const Handle(TFunction_Logbook)& log) const;
//! Executes the function in this function driver and
//! puts the impacted labels in the logbook log.
//! arguments & results of functions
//! ================================
Standard_EXPORT virtual Standard_Integer Execute (TFunction_Logbook& log) const = 0;
Standard_EXPORT virtual Standard_Integer Execute (Handle(TFunction_Logbook)& log) const = 0;
//! The method fills-in the list by labels,
//! where the arguments of the function are located.

View File

@@ -406,7 +406,7 @@ const TFunction_DoubleMapOfIntegerLabel& TFunction_IFunction::GetAllFunctions()
//purpose : Returns the Logbook.
//=======================================================================
TFunction_Logbook& TFunction_IFunction::GetLogbook() const
Handle(TFunction_Logbook) TFunction_IFunction::GetLogbook() const
{
return TFunction_Scope::Set(myLabel)->GetLogbook();
}

View File

@@ -97,7 +97,7 @@ public:
Standard_EXPORT const TFunction_DoubleMapOfIntegerLabel& GetAllFunctions() const;
//! Returns the Logbook - keeper of modifications.
Standard_EXPORT TFunction_Logbook& GetLogbook() const;
Standard_EXPORT Handle(TFunction_Logbook) GetLogbook() const;
//! Returns a driver of the function.
Standard_EXPORT Handle(TFunction_Driver) GetDriver (const Standard_Integer thread = 0) const;

View File

@@ -21,8 +21,46 @@
#include <TDF_Label.hxx>
#include <TDF_LabelMap.hxx>
#include <TDF_MapIteratorOfLabelMap.hxx>
#include <TDF_RelocationTable.hxx>
#include <TDF_Tool.hxx>
#include <TFunction_Logbook.hxx>
#include <Standard_GUID.hxx>
//=======================================================================
//function : GetID
//purpose : Static method to get an ID
//=======================================================================
const Standard_GUID& TFunction_Logbook::GetID()
{
static Standard_GUID TFunction_LogbookID("CF519724-5CA4-4B90-835F-8919BE1DDE4B");
return TFunction_LogbookID;
}
//=======================================================================
//function : Set
//purpose : Finds or creates a Scope attribute
//=======================================================================
Handle(TFunction_Logbook) TFunction_Logbook::Set(const TDF_Label& Access)
{
Handle(TFunction_Logbook) S;
if (!Access.Root().FindAttribute(TFunction_Logbook::GetID(), S))
{
S = new TFunction_Logbook();
Access.Root().AddAttribute(S);
}
return S;
}
//=======================================================================
//function : ID
//purpose : Returns GUID of the function
//=======================================================================
const Standard_GUID& TFunction_Logbook::ID() const
{
return GetID();
}
//=======================================================================
//function : TFunction_Logbook
@@ -38,9 +76,13 @@ TFunction_Logbook::TFunction_Logbook():isDone(Standard_False)
void TFunction_Logbook::Clear()
{
myTouched.Clear();
myImpacted.Clear();
myValid.Clear();
if (!IsEmpty())
{
Backup();
myTouched.Clear();
myImpacted.Clear();
myValid.Clear();
}
}
//=======================================================================
@@ -59,15 +101,22 @@ Standard_Boolean TFunction_Logbook::IsEmpty () const
//=======================================================================
Standard_Boolean TFunction_Logbook::IsModified(const TDF_Label& L,
const Standard_Boolean WithChildren) const
const Standard_Boolean WithChildren) const
{
if (myTouched.Contains(L)) return Standard_True;
if (myImpacted.Contains(L)) return Standard_True;
if (WithChildren) {
if (myTouched.Contains(L))
return Standard_True;
if (myImpacted.Contains(L))
return Standard_True;
if (WithChildren)
{
TDF_ChildIterator itr(L);
for (; itr.More(); itr.Next())
{
if (IsModified(itr.Value(), Standard_True))
return Standard_True;
{
return Standard_True;
}
}
}
return Standard_False;
}
@@ -78,34 +127,169 @@ Standard_Boolean TFunction_Logbook::IsModified(const TDF_Label& L,
//=======================================================================
void TFunction_Logbook::SetValid(const TDF_Label& L,
const Standard_Boolean WithChildren)
const Standard_Boolean WithChildren)
{
Backup();
myValid.Add(L);
if (WithChildren) {
if (WithChildren)
{
TDF_ChildIterator itr(L, Standard_True);
for (; itr.More(); itr.Next()) {
for (; itr.More(); itr.Next())
{
myValid.Add(itr.Value());
}
}
}
void TFunction_Logbook::SetValid(const TDF_LabelMap& Ls)
{
Backup();
TDF_MapIteratorOfLabelMap itrm(Ls);
for (; itrm.More(); itrm.Next())
{
const TDF_Label& L = itrm.Key();
myValid.Add(L);
}
}
//=======================================================================
//function : SetImpacted
//purpose :
//=======================================================================
void TFunction_Logbook::SetImpacted(const TDF_Label& L,
const Standard_Boolean WithChildren)
const Standard_Boolean WithChildren)
{
Backup();
myImpacted.Add(L);
if (WithChildren) {
if (WithChildren)
{
TDF_ChildIterator itr(L, Standard_True);
for (; itr.More(); itr.Next()) {
for (; itr.More(); itr.Next())
{
myImpacted.Add(itr.Value());
}
}
}
//=======================================================================
//function : GetValid
//purpose : Returns valid labels.
//=======================================================================
void TFunction_Logbook::GetValid(TDF_LabelMap& Ls) const
{
// Copy valid labels.
TDF_MapIteratorOfLabelMap itrm(myValid);
for (; itrm.More(); itrm.Next())
{
const TDF_Label& L = itrm.Key();
Ls.Add(L);
}
}
//=======================================================================
//function : Restore
//purpose : Undos (and redos) the attribute.
//=======================================================================
void TFunction_Logbook::Restore(const Handle(TDF_Attribute)& other)
{
Handle(TFunction_Logbook) logbook = Handle(TFunction_Logbook)::DownCast(other);
// Status.
isDone = logbook->isDone;
// Valid labels
TDF_MapIteratorOfLabelMap itrm;
for (itrm.Initialize(logbook->myValid); itrm.More(); itrm.Next())
{
myValid.Add(itrm.Key());
}
// Touched labels
for (itrm.Initialize(logbook->myTouched); itrm.More(); itrm.Next())
{
myTouched.Add(itrm.Key());
}
// Impacted labels
for (itrm.Initialize(logbook->myImpacted); itrm.More(); itrm.Next())
{
myImpacted.Add(itrm.Key());
}
}
//=======================================================================
//function : Paste
//purpose : Method for Copy mechanism
//=======================================================================
void TFunction_Logbook::Paste(const Handle(TDF_Attribute)& into,
const Handle(TDF_RelocationTable)& RT) const
{
Handle(TFunction_Logbook) logbook = Handle(TFunction_Logbook)::DownCast(into);
// Status.
logbook->isDone = isDone;
// Touched.
logbook->myTouched.Clear();
TDF_MapIteratorOfLabelMap itr(myTouched);
for (; itr.More(); itr.Next())
{
const TDF_Label& L = itr.Value();
if (!L.IsNull())
{
TDF_Label relocL;
if (RT->HasRelocation(L, relocL))
logbook->myTouched.Add(relocL);
else
logbook->myTouched.Add(L);
}
}
// Impacted.
logbook->myImpacted.Clear();
itr.Initialize(myImpacted);
for (; itr.More(); itr.Next())
{
const TDF_Label& L = itr.Value();
if (!L.IsNull())
{
TDF_Label relocL;
if (RT->HasRelocation(L, relocL))
logbook->myImpacted.Add(relocL);
else
logbook->myImpacted.Add(L);
}
}
// Valid.
logbook->myValid.Clear();
itr.Initialize(myValid);
for (; itr.More(); itr.Next())
{
const TDF_Label& L = itr.Value();
if (!L.IsNull())
{
TDF_Label relocL;
if (RT->HasRelocation(L, relocL))
logbook->myValid.Add(relocL);
else
logbook->myValid.Add(L);
}
}
}
//=======================================================================
//function : NewEmpty
//purpose : Returns new empty graph node attribute
//=======================================================================
Handle(TDF_Attribute) TFunction_Logbook::NewEmpty() const
{
return new TFunction_Logbook();
}
//=======================================================================
//function : Dump
//purpose : Dump of modifications
@@ -118,17 +302,20 @@ Standard_OStream& TFunction_Logbook::Dump(Standard_OStream& stream) const
stream<<"Done = "<<isDone<<endl;
stream<<"Touched labels: "<<endl;
for (itr.Initialize(myTouched); itr.More(); itr.Next()) {
for (itr.Initialize(myTouched); itr.More(); itr.Next())
{
TDF_Tool::Entry(itr.Key(), as);
stream<<as<<endl;
}
stream<<"Impacted labels: "<<endl;
for (itr.Initialize(myImpacted); itr.More(); itr.Next()) {
for (itr.Initialize(myImpacted); itr.More(); itr.Next())
{
TDF_Tool::Entry(itr.Key(), as);
stream<<as<<endl;
}
stream<<"Valid labels: "<<endl;
for (itr.Initialize(myValid); itr.More(); itr.Next()) {
for (itr.Initialize(myValid); itr.More(); itr.Next())
{
TDF_Tool::Entry(itr.Key(), as);
stream<<as<<endl;
}

View File

@@ -22,10 +22,17 @@
#include <Standard_Handle.hxx>
#include <TDF_LabelMap.hxx>
#include <TDF_Attribute.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_OStream.hxx>
class TDF_Label;
class Standard_GUID;
class TFunction_Logbook;
class TDF_Attribute;
class TDF_RelocationTable;
class TFunction_Logbook;
DEFINE_STANDARD_HANDLE(TFunction_Logbook, TDF_Attribute)
//! This class contains information which is written and
//! read during the solving process. Information is divided
@@ -34,25 +41,32 @@ class TDF_Label;
//! * Touched Labels (modified by the end user),
//! * Impacted Labels (modified during execution of the function),
//! * Valid Labels (within the valid label scope).
class TFunction_Logbook
class TFunction_Logbook : public TDF_Attribute
{
public:
DEFINE_STANDARD_ALLOC
//! next methods are solving declaration
//! ===================================
//! Finds or Creates a TFunction_Logbook attribute at the root label accessed by <Access>.
//! Returns the attribute.
Standard_EXPORT static Handle(TFunction_Logbook) Set(const TDF_Label& Access);
//! Returns the GUID for logbook attribute.
Standard_EXPORT static const Standard_GUID& GetID();
//! The methods manipulating the data
//! (touched, impacted and valid labels)
// ====================================
//! Constructor (empty).
Standard_EXPORT TFunction_Logbook();
//! Clears this logbook to its default, empty state.
Standard_EXPORT void Clear();
Standard_EXPORT Standard_Boolean IsEmpty() const;
//! Sets the label L as a touched label in this logbook.
//! In other words, L is understood to have been modified by the end user.
void SetTouched (const TDF_Label& L);
Standard_EXPORT void SetTouched (const TDF_Label& L);
//! Sets the label L as an impacted label in this logbook.
//! This method is called by execution of the function driver.
@@ -60,62 +74,59 @@ public:
//! Sets the label L as a valid label in this logbook.
Standard_EXPORT void SetValid (const TDF_Label& L, const Standard_Boolean WithChildren = Standard_False);
TDF_LabelMap& ChangeValid();
Standard_EXPORT void SetValid (const TDF_LabelMap& Ls);
//! Returns True if the label L is touched or impacted. This method
//! is called by <TFunction_FunctionDriver::MustExecute>.
//! If <WithChildren> is set to true, the method checks
//! all the sublabels of <L> too.
//! next method to consult solving result
//! =====================================
Standard_EXPORT Standard_Boolean IsModified (const TDF_Label& L, const Standard_Boolean WithChildren = Standard_False) const;
//! Returns the map of touched labels in this logbook.
//! A touched label is the one modified by the end user.
const TDF_LabelMap& GetTouched() const;
Standard_EXPORT const TDF_LabelMap& GetTouched() const;
//! Returns the map of impacted labels contained in this logbook.
const TDF_LabelMap& GetImpacted() const;
Standard_EXPORT const TDF_LabelMap& GetImpacted() const;
//! Returns the map of valid labels in this logbook.
const TDF_LabelMap& GetValid() const;
Standard_EXPORT const TDF_LabelMap& GetValid() const;
Standard_EXPORT void GetValid(TDF_LabelMap& Ls) const;
//! Sets if the execution failed
void Done (const Standard_Boolean status);
//! Sets status of execution.
Standard_EXPORT void Done (const Standard_Boolean status);
Standard_Boolean IsDone() const;
//! Returns status of execution.
Standard_EXPORT Standard_Boolean IsDone() const;
//! The methods inherited from TDF_Attribute
// ========================================
//! Returns the ID of the attribute.
Standard_EXPORT const Standard_GUID& ID() const;
Standard_EXPORT Standard_OStream& Dump (Standard_OStream& stream) const;
protected:
//! Undos (and redos) the attribute.
Standard_EXPORT virtual void Restore (const Handle(TDF_Attribute)& with);
//! Pastes the attribute to another label.
Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const;
//! Returns a new empty instance of the attribute.
Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
//! Prints th data of the attributes (touched, impacted and valid labels).
Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& anOS) const Standard_OVERRIDE;
private:
TDF_LabelMap myTouched;
TDF_LabelMap myImpacted;
TDF_LabelMap myValid;
Standard_Boolean isDone;
};
#include <TFunction_Logbook.lxx>
#endif // _TFunction_Logbook_HeaderFile

View File

@@ -16,7 +16,11 @@
inline void TFunction_Logbook::SetTouched(const TDF_Label& L)
{
myTouched.Add(L);
if (!myTouched.Contains(L))
{
Backup();
myTouched.Add(L);
}
}
inline const TDF_LabelMap& TFunction_Logbook::GetTouched() const
@@ -29,11 +33,6 @@ inline const TDF_LabelMap& TFunction_Logbook::GetImpacted() const
return myImpacted;
}
inline TDF_LabelMap& TFunction_Logbook::ChangeValid()
{
return myValid;
}
inline const TDF_LabelMap& TFunction_Logbook::GetValid() const
{
return myValid;
@@ -41,7 +40,11 @@ inline const TDF_LabelMap& TFunction_Logbook::GetValid() const
inline void TFunction_Logbook::Done(const Standard_Boolean status)
{
isDone = status;
if (isDone != status)
{
Backup();
isDone = status;
}
}
inline Standard_Boolean TFunction_Logbook::IsDone() const

View File

@@ -20,7 +20,6 @@
#include <TDF_Label.hxx>
#include <TDF_MapIteratorOfLabelMap.hxx>
#include <TDF_RelocationTable.hxx>
#include <TFunction_Logbook.hxx>
#include <TFunction_Scope.hxx>
//=======================================================================
@@ -175,9 +174,11 @@ const TDF_Label& TFunction_Scope::GetFunction(const Standard_Integer ID) const
//purpose : Returns the Logbook.
//=======================================================================
TFunction_Logbook& TFunction_Scope::GetLogbook()
Handle(TFunction_Logbook) TFunction_Scope::GetLogbook() const
{
return myLogbook;
Handle(TFunction_Logbook) logbook;
FindAttribute(TFunction_Logbook::GetID(), logbook);
return logbook;
}
//=======================================================================
@@ -192,26 +193,6 @@ void TFunction_Scope::Restore(const Handle(TDF_Attribute)& other)
// Functions
myFunctions = S->myFunctions; // copying...
myFreeID = S->myFreeID;
// Logbook
myLogbook.Clear();
TDF_MapIteratorOfLabelMap itrm;
// Valid labels
for (itrm.Initialize(S->myLogbook.GetValid()); itrm.More(); itrm.Next())
{
myLogbook.SetValid(itrm.Key(), Standard_False);
}
// Touched labels
for (itrm.Initialize(S->myLogbook.GetTouched()); itrm.More(); itrm.Next())
{
myLogbook.SetTouched(itrm.Key());
}
// Impacted labels
for (itrm.Initialize(S->myLogbook.GetImpacted()); itrm.More(); itrm.Next())
{
myLogbook.SetImpacted(itrm.Key(), Standard_False);
}
myLogbook.Done(S->myLogbook.IsDone());
}
//=======================================================================

View File

@@ -83,7 +83,7 @@ public:
//! Returns the Logbook used in TFunction_Driver methods.
//! Implementation of Attribute methods
//! ===================================
Standard_EXPORT TFunction_Logbook& GetLogbook();
Standard_EXPORT Handle(TFunction_Logbook) GetLogbook() const;
Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
@@ -120,7 +120,6 @@ private:
TFunction_DoubleMapOfIntegerLabel myFunctions;
TFunction_Logbook myLogbook;
Standard_Integer myFreeID;