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

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

5
src/TDF/FILES Executable file
View File

@@ -0,0 +1,5 @@
TDF_LabelNode.hxx
TDF_LabelNode.cxx
TDF_AttributeIterator.hxx
TDF_AttributeIterator.cxx
TDF_HAllocator.hxx

292
src/TDF/TDF.cdl Executable file
View File

@@ -0,0 +1,292 @@
-- File: TDF.cdl
-- --------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Feb 5 1997 Creation
package TDF
---Purpose: This package provides data framework for binding
-- features and data structures.
--
-- The feature structure is a tree used to bind
-- semantic informations about each feature together.
--
-- The only one concrete attribute defined in this
-- package is the TagSource attribute.This attribute
-- is used for random creation of child labels under
-- a given label. Tags are randomly delivered.
---Category: GUID - AttributeID
-- 2a96b611-ec8b-11d0-bee7-080009dc3333 TDataStd_TagSource
uses
Standard,
MMgt,
TColStd,
TCollection
is
---Category: DF Structure Classes
-- ==============================================================
class Data;
---Purpose: The root class of this structure.
class Label;
---Purpose: A label is a feature in the structure.
imported HAllocator;
imported LabelNode;
pointer LabelNodePtr to LabelNode from TDF;
deferred class Attribute;
---Purpose: A class each application has to implement. It is
-- used to contain the application data.
class TagSource;
---Purpose: this attribute may be used for automatic delivery of
-- labels under a given label.
class Reference;
---Purpose: this attribute is used to store in the framework a
-- reference to an other label.
---Category: DF Copy algorithms
-- ==============================================================
class ClosureMode;
---Purpose: This class provides options closure management.
class ClosureTool;
---Purpose: This class gives services around the transitive
-- enclosure of a set of information, starting from a
-- list of label.
class CopyTool;
---Purpose: This class gives services around copy/paste actions.
class CopyLabel;
---Purpose: This class gives copy of source label hierarchy
class ComparisonTool;
---Purpose: This class gives services around the comparison
-- between two sets of information.
---Category: DF Transaction & Delta
-- ==============================================================
class Transaction;
---Purpose: This class offers services to open, commit or
-- abort a transaction in a more secure way than
-- using Data from TDF.
class Delta;
---Purpose: A set of AttributeDelta for a given transaction
-- number and reference time number.
deferred class AttributeDelta;
---Purpose: Delta for a given attribute.
class DeltaOnAddition;
---Purpose: Attribute delta on ADDITION action.
class DeltaOnForget;
---Purpose: Attribute delta on FORGET action.
class DeltaOnResume;
---Purpose: Attribute delta on RESUME action.
deferred class DeltaOnRemoval;
---Purpose: Attribute delta on REMOVAL action.
deferred class DeltaOnModification;
---Purpose: Attribute delta on MODIFICATION action.
class DefaultDeltaOnRemoval;
---Purpose: Default implementation of TDF_DeltaOnRemoval.
class DefaultDeltaOnModification;
---Purpose: Default implementation of TDF_DeltaOnModification.
---Category: DF Basic Tools
-- ==============================================================
class ChildIterator;
---Purpose: A tool to iterate on the children of a label.
class ChildIDIterator;
---Purpose: A tool to iterate on the children of a label to
-- find attributes with an ID.
imported AttributeIterator;
---Purpose: DO NOT USE THIS CLASS WITHOUT AUTHORIZATION!
---Category: DF Specific Tools
-- ==============================================================
class DataSet;
---Purpose: This class is used to build a set of DF
-- informations like labels or attributes.
class RelocationTable;
---Purpose: Builds a attribute relocation dictionnary useful
-- for copy or paste actions.
class Tool;
---Purpose: This class provides general services.
class LabelMapHasher;
---Purpose: A label hasher for label maps.
class IDFilter;
---Purpose: This class offers filtering services around an ID list.
---Category: DF Classes Instantiations
-- ==============================================================
-- Lists
-- -----
class IDList instantiates List from TCollection
(GUID from Standard);
class AttributeList instantiates List from TCollection
(Attribute from TDF);
class LabelList instantiates List from TCollection
(Label from TDF);
class AttributeDeltaList instantiates List from TCollection
(AttributeDelta from TDF);
class DeltaList instantiates List from TCollection
(Delta from TDF);
-- Sequences
-- ---------
class AttributeSequence instantiates Sequence from TCollection
(Attribute from TDF);
class LabelSequence instantiates Sequence from TCollection
(Label from TDF);
-- Arrays
-- ------
class AttributeArray1 instantiates Array1 from TCollection
(Attribute from TDF);
class HAttributeArray1 instantiates HArray1 from TCollection
(Attribute from TDF,
AttributeArray1 from TDF);
-- Maps
-- ----
class IDMap instantiates Map from TCollection
(GUID from Standard,
GUID from Standard);
class AttributeMap instantiates Map from TCollection
(Attribute from TDF,
MapTransientHasher from TColStd);
class AttributeDataMap instantiates DataMap from TCollection
(Attribute from TDF,
Attribute from TDF,
MapTransientHasher from TColStd);
class AttributeDoubleMap instantiates DoubleMap from TCollection
(Attribute from TDF,
Attribute from TDF,
MapTransientHasher from TColStd,
MapTransientHasher from TColStd);
class AttributeIndexedMap instantiates IndexedMap from TCollection
(Attribute from TDF,
MapTransientHasher from TColStd);
class LabelMap instantiates Map from TCollection
(Label from TDF,
LabelMapHasher from TDF);
class LabelDataMap instantiates DataMap from TCollection
(Label from TDF,
Label from TDF,
LabelMapHasher from TDF);
class LabelDoubleMap instantiates DoubleMap from TCollection
(Label from TDF,
Label from TDF,
LabelMapHasher from TDF,
LabelMapHasher from TDF);
class LabelIndexedMap instantiates IndexedMap from TCollection
(Label from TDF,
LabelMapHasher from TDF);
class LabelIntegerMap instantiates DataMap from TCollection
(Label from TDF,
Integer from Standard,
LabelMapHasher from TDF);
class LabelLabelMap instantiates DataMap from TCollection
(Label from TDF,
Label from TDF,
LabelMapHasher from TDF);
class GUIDProgIDMap instantiates DoubleMap from TCollection
(GUID from Standard,
ExtendedString from TCollection,
GUID from Standard,
ExtendedString from TCollection);
---Category: Package methods
-- ==============================================================
LowestID returns GUID from Standard;
---Purpose: Returns ID "00000000-0000-0000-0000-000000000000",
-- sometimes used as null ID.
--
---C++: return const &
UppestID returns GUID from Standard;
---Purpose: Returns ID "ffffffff-ffff-ffff-ffff-ffffffffffff".
--
---C++: return const &
AddLinkGUIDToProgID( ID : GUID from Standard; ProgID : ExtendedString from TCollection );
---Purpose: Sets link between GUID and ProgID in hidden DataMap
GUIDFromProgID( ProgID : ExtendedString from TCollection; ID : in out GUID from Standard )
returns Boolean from Standard;
---Purpose: Returns True if there is GUID for given <ProgID> then GUID is returned in <ID>
ProgIDFromGUID( ID : GUID from Standard; ProgID : in out ExtendedString from TCollection )
returns Boolean from Standard;
---Purpose: Returns True if there is ProgID for given <ID> then ProgID is returned in <ProgID>
end TDF;

78
src/TDF/TDF.cxx Executable file
View File

@@ -0,0 +1,78 @@
// File: TDF.cxx
// -------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Nov 14 1997 Creation
#include <TDF.ixx>
#include <TDF_GUIDProgIDMap.hxx>
static TDF_GUIDProgIDMap guidprogidmap;
//=======================================================================
//function : LowerID
//purpose :
//=======================================================================
const Standard_GUID& TDF::LowestID()
{
static Standard_GUID lowestID("00000000-0000-0000-0000-000000000000");
return lowestID;
}
//=======================================================================
//function : UpperID
//purpose :
//=======================================================================
const Standard_GUID& TDF::UppestID()
{
static Standard_GUID uppestID("ffffffff-ffff-ffff-ffff-ffffffffffff");
return uppestID;
}
//=======================================================================
//function : AddLinkGUIDToProgID
//purpose :
//=======================================================================
void TDF::AddLinkGUIDToProgID(const Standard_GUID& ID,const TCollection_ExtendedString& ProgID)
{
guidprogidmap.UnBind1( ID );
guidprogidmap.UnBind2( ProgID );
guidprogidmap.Bind(ID, ProgID);
}
//=======================================================================
//function : GUIDFromProgID
//purpose :
//=======================================================================
Standard_Boolean TDF::GUIDFromProgID(const TCollection_ExtendedString& ProgID,Standard_GUID& ID)
{
if( guidprogidmap.IsBound2(ProgID) ) {
ID = guidprogidmap.Find2( ProgID );
return Standard_True;
}
return Standard_False;
}
//=======================================================================
//function : ProgIDFromGUID
//purpose :
//=======================================================================
Standard_Boolean TDF::ProgIDFromGUID(const Standard_GUID& ID,TCollection_ExtendedString& ProgID)
{
if( guidprogidmap.IsBound1(ID) ) {
ProgID = guidprogidmap.Find1( ID );
return Standard_True;
}
return Standard_False;
}

512
src/TDF/TDF_Attribute.cdl Executable file
View File

@@ -0,0 +1,512 @@
-- File: TDF_Attribute.cdl
-- -----------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Feb 4 1997 Creation
deferred class Attribute from TDF
inherits TShared from MMgt
---Purpose: This abstract class, alongwith Label,
-- is one of the cornerstones of Model Editor.
-- The groundwork is to define the root of
-- information. This information is to be
-- attached to a Label, and could be of any of
-- the following types:
-- - a feature
-- - a constraint
-- - a comment
--
-- Contents:
-- ---------
--
-- Each software component who'd like to attach its
-- own information to a label has to inherit from
-- this class and has to add its own information as
-- fields of this new class.
--
-- Identification:
-- ---------------
--
-- An attribute can be identified by its ID. Every
-- attributes used with the same meaning (for
-- exemple: Integer, String, Topology...) have the
-- same worldwide unique ID.
--
-- Addition:
-- ---------
--
-- An attribute can be added to a label only if there
-- is no attribute yet with the same ID. Call-back
-- methods are offered, called automatically before
-- and after the addition action.
--
-- Removal:
-- --------
--
-- An attribute can be removed from a label only if
-- there is an attribute yet with the same
-- ID. Call-back methods are offered, called
-- automatically before and after the removal
-- action. A removed attribute cannot be found
-- again. After a removal, only an addition of an
-- attribute with the sane ID is possible (no
-- backup...).
--
-- Modification & Transaction:
-- ---------------------------
--
-- An attribute can be backuped before a
-- modification. Only one backup attribute by
-- transaction is possible. The modification can be
-- forgotten (abort transaction) or validated (commit
-- transaction).
--
-- BackupCopy and restore are methods used by the backup or
-- abort transaction actions. BackupCopy is called by
-- Backup to generate an attribute with the same
-- contents as the current one. Restore is called
-- when aborting a transaction to transfer the
-- backuped contents into the current
-- attribute. These methods must be implemented by
-- end use inheriting classes.
--
-- A standard implementation of BackupCopy is provided, but
-- it is not necessary a good one for any use.
--
-- Copy use methods:
-- -----------------
--
-- Paste and NewEmpty methods are used by the copy
-- algorithms. The goal of "Paste" is to transfer an
-- attribute new contents into another attribute. The
-- goal of "NewEmpty" is to create an attribute
-- whithout contents, to be further filled with the
-- new contents of another one. These 2 methods must
-- be implemented by end use inheriting classes.
--
-- AttributeDelta:
-- ---------------
--
-- An AttributeDelta is the difference between to
-- attribute values states. These methods must be
-- implemented by end use inheriting classes, to
-- profit from the delta services.
uses
GUID from Standard,
AttributeIndexedMap from TDF,
DataSet from TDF,
AttributeDelta from TDF,
DeltaOnModification from TDF,
DeltaOnRemoval from TDF,
DeltaOnResume from TDF,
DeltaOnAddition from TDF,
DeltaOnForget from TDF,
IDFilter from TDF,
Label from TDF,
LabelNode from TDF,
LabelNodePtr from TDF,
RelocationTable from TDF
raises DomainError from Standard
is
Initialize
returns mutable Attribute from TDF;
---Purpose: Initializes fields.
---Category: Information access.
-- ==============================================================
-- Implement such a method and use it to implement ID(me).
--
-- GetID (myclass)
-- -C++: return const &
-- returns GUID from Standard;
--
-- const Standard_GUID& MyClass::GetID() const
-- {
-- static Standard_GUID myID("12345678-1234-1234-1234-1234567890ab");
-- return myID;
-- }
ID(me)
returns GUID from Standard
is deferred;
---Purpose: Returns the ID of the attribute.
--
---C++: return const &
Label(me)
returns Label from TDF;
---Purpose: Returns the label to which the attribute is
-- attached. If the label is not included in a DF,
-- the label is null. See Label.
-- Warning
-- If the label is not included in a data
-- framework, it is null.
-- This function should not be redefined inline.
---C++: return const
Transaction(me)
returns Integer from Standard;
---Purpose: Returns the transaction index in which the
-- attribute has been created or modified.
--
---C++: inline
UntilTransaction(me)
returns Integer from Standard;
---Purpose: Returns the upper transaction index until which
-- the attribute is/was valid. This number may
-- vary. A removed attribute validity range is
-- reduced to its transaction index.
IsValid(me)
returns Boolean from Standard;
---Purpose: Returns true if the attribute is valid; i.e. not a
-- backuped or removed one.
--
---C++: inline
IsNew(me)
returns Boolean from Standard;
---Purpose: Returns true if the attribute has no backup
--
---C++: inline
IsForgotten(me)
returns Boolean from Standard;
---Purpose: Returns true if the attribute forgotten status is
-- set.
--
---C++: inline
---Purpose: ShortCut Methods concerning associated attributes
-- =================================================
IsAttribute (me; anID : GUID from Standard)
returns Boolean from Standard;
---Purpose: Returns true if it exists an associated attribute
-- of <me> with <anID> as ID.
FindAttribute (me; anID : GUID from Standard;
anAttribute : in out Attribute from TDF)
returns Boolean from Standard;
---Purpose: Finds an associated attribute of <me>, according
-- to <anID>. the returned <anAttribute> is a valid
-- one. The method returns True if found, False
-- otherwise. A removed attribute cannot be found using
-- this method.
AddAttribute (me; other : Attribute from TDF)
raises DomainError from Standard;
---Purpose: Adds an Attribute <other> to the label of
-- <me>.Raises if there is already one of the same
-- GUID fhan <other>.
ForgetAttribute (me; aguid : GUID from Standard)
returns Boolean from Standard;
---Purpose: Forgets the Attribute of GUID <aguid> associated
-- to the label of <me>. Be carefull that if <me> is
-- the attribute of <guid>, <me> will have a null label
-- after this call. If the attribute doesn't exist
-- returns False. Otherwise returns True.
ForgetAllAttributes (me; clearChildren : Boolean from Standard = Standard_True);
---Purpose: Forgets all the attributes attached to the label
-- of <me>. Does it on the sub-labels if
-- <clearChildren> is set to true. Of course, this
-- method is compatible with Transaction & Delta
-- mecanisms. Be carefull that if <me> will have a
-- null label after this call
---Category: Immediate callbacks
-- ==============================================================
AfterAddition(me: mutable)
is virtual;
---Purpose: Something to do after adding an Attribute to a label.
BeforeRemoval(me: mutable)
is virtual;
---Purpose: Something to do before removing an Attribute from
-- a label.
BeforeForget(me: mutable)
is virtual;
---Purpose: Something to do before forgetting an Attribute to a
-- label.
AfterResume(me: mutable)
is virtual;
---Purpose: Something to do after resuming an Attribute from
-- a label.
---Category: Retrieval callbacks
-- ==============================================================
-- The following method is called after a whole
-- Transient-Persistent translation.
AfterRetrieval(me: mutable;
forceIt : Boolean from Standard = Standard_False)
returns Boolean from Standard
is virtual;
---Purpose: Something to do AFTER creation of an attribute by
-- persistent-transient translation. The returned
-- status says if AfterUndo has been performed (true)
-- or if this callback must be called once again
-- further (false). If <forceIt> is set to true, the
-- method MUST perform and return true. Does nothing
-- by default and returns true.
---Category: Undo callbacks
-- ==============================================================
-- The following methods are called before/after a whole Delta is
-- applied. They are called for each concerned attribute.
BeforeUndo(me: mutable;
anAttDelta : AttributeDelta from TDF;
forceIt : Boolean from Standard = Standard_False)
returns Boolean from Standard
is virtual;
---Purpose: Something to do before applying <anAttDelta>. The
-- returned status says if AfterUndo has been
-- performed (true) or if this callback must be
-- called once again further (false). If <forceIt> is
-- set to true, the method MUST perform and return
-- true. Does nothing by default and returns true.
AfterUndo(me: mutable;
anAttDelta : AttributeDelta from TDF;
forceIt : Boolean from Standard = Standard_False)
returns Boolean from Standard
is virtual;
---Purpose: Something to do after applying <anAttDelta>. The
-- returned status says if AfterUndo has been
-- performed (true) or if this callback must be
-- called once again further (false). If <forceIt> is
-- set to true, the method MUST perform and return
-- true. Does nothing by default and returns true.
---Category: Modification & Transaction
-- ==============================================================
BeforeCommitTransaction(me : mutable)
---Purpose: A callback.
-- By default does nothing.
-- It is called by TDF_Data::CommitTransaction() method.
is virtual;
Backup(me : mutable);
---Purpose: Backups the attribute. The backuped attribute is
-- flagged "Backuped" and not "Valid".
--
-- The method does nothing:
--
-- 1) If the attribute transaction number is equal to
-- the current transaction number (the attribute has
-- already been backuped).
--
-- 2) If the attribute is not attached to a label.
IsBackuped(me)
returns Boolean from Standard;
---Purpose: Returns true if the attribute backup status is
-- set. This status is set/unset by the
-- Backup() method.
--
---C++: inline
BackupCopy(me) returns mutable Attribute from TDF
is virtual;
---Purpose: Copies the attribute contents into a new other
-- attribute. It is used by Backup().
Restore(me: mutable;
anAttribute : Attribute from TDF)
is deferred;
---Purpose: Restores the backuped contents from <anAttribute>
-- into this one. It is used when aborting a
-- transaction.
---Category: Delta generation
-- ==============================================================
DeltaOnAddition(me)
returns DeltaOnAddition from TDF
---Purpose : Makes an AttributeDelta because <me>
-- appeared. The only known use of a redefinition of
-- this method is to return a null handle (no delta).
is virtual;
DeltaOnForget(me)
returns DeltaOnForget from TDF
---Purpose : Makes an AttributeDelta because <me> has been
-- forgotten.
is virtual;
DeltaOnResume(me)
returns DeltaOnResume from TDF
---Purpose : Makes an AttributeDelta because <me> has been
-- resumed.
is virtual;
DeltaOnModification(me; anOldAttribute : Attribute from TDF)
returns DeltaOnModification from TDF
---Purpose : Makes a DeltaOnModification between <me> and
-- <anOldAttribute.
is virtual;
DeltaOnModification(me : mutable; aDelta : DeltaOnModification from TDF)
is virtual;
---Purpose: Applies a DeltaOnModification to <me>.
DeltaOnRemoval(me)
returns DeltaOnRemoval from TDF
---Purpose : Makes a DeltaOnRemoval on <me> because <me> has
-- disappeared from the DS.
is virtual;
---Category: Copy
-- ==============================================================
NewEmpty(me)
returns mutable Attribute from TDF
is deferred;
---Purpose: Returns an new empty attribute from the good end
-- type. It is used by the copy algorithm.
Paste(me;
intoAttribute : mutable Attribute from TDF;
aRelocationTable : mutable RelocationTable from TDF)
is deferred;
---Purpose: This method is different from the "Copy" one,
-- because it is used when copying an attribute from
-- a source structure into a target structure. This
-- method may paste the contents of <me> into
-- <intoAttribute>.
--
-- The given pasted attribute can be full or empty of
-- its contents. But don't make a NEW! Just set the
-- contents!
--
-- It is possible to use <aRelocationTable> to
-- get/set the relocation value of a source
-- attribute.
References(me; aDataSet : DataSet from TDF)
is virtual;
---Purpose: Adds the first level referenced attributes and labels
-- to <aDataSet>.
--
-- For this, use the AddLabel or AddAttribute of
-- DataSet.
--
-- If there is none, do not implement the method.
---Category: Dump
-- ==============================================================
Dump(me; anOS : in out OStream from Standard)
returns OStream from Standard
is virtual;
---Purpose: Dumps the minimum information about <me> on
-- <aStream>.
--
---C++: return &
---C++: alias operator<<
ExtendedDump(me;
anOS : in out OStream from Standard;
aFilter : IDFilter from TDF;
aMap : in out AttributeIndexedMap from TDF)
is virtual;
---Purpose: Dumps the attribute content on <aStream>, using
-- <aMap> like this: if an attribute is not in the
-- map, first put add it to the map and then dump it.
-- Use the map rank instead of dumping each attribute
-- field.
---Category: Miscelleaneous
-- ==============================================================
---Category: Private area...
-- ==============================================================
Validate(me: mutable; aStatus : Boolean from Standard)
is private;
---Purpose: Set the "Valid" status with <aStatus>.
--
---C++: inline
Forget(me: mutable; aTransaction : Integer from Standard);
---Purpose: Forgets the attribute. <aTransaction> is the
-- current transaction in which the forget is done. A
-- forgotten attribute is also flagged not "Valid".
--
-- A forgotten attribute is invisible. Set also the
-- "Valid" status to False. Obvioulsy, DF cannot
-- empty an attribute (this has a semantic
-- signification), but can remove it from the
-- structure. So, a forgotten attribute is NOT an empty
-- one, but a soon DEAD one.
--
-- Should be private.
Resume(me: mutable)
is private;
---Purpose: Resumes the attribute (undos Forget action).
Backup(me: mutable; aStatus : Boolean from Standard)
is private;
---Purpose: Set the "backuped" status with <aStatus>.
--
---C++: inline
RemoveBackup(me : mutable) is private;
---Purpose: Removes the last backup attribute, if it exists.
fields
myLabelNode : LabelNodePtr from TDF;
myTransaction : Integer from Standard;
mySavedTransaction : Integer from Standard;
myFlags : Integer from Standard;
myNext : Attribute from TDF;
myBackup : Attribute from TDF;
friends
class Data from TDF,
class Label from TDF,
class LabelNode from TDF,
class AttributeIterator from TDF,
class DeltaOnForget from TDF
end Attribute;

394
src/TDF/TDF_Attribute.cxx Executable file
View File

@@ -0,0 +1,394 @@
// File: TDF_Attribute.cxx
// ------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 7 1997 Creation
#include <TDF_Attribute.ixx>
#include <TCollection_AsciiString.hxx>
#include <TDF_DefaultDeltaOnModification.hxx>
#include <TDF_DefaultDeltaOnRemoval.hxx>
#include <TDF_DeltaOnForget.hxx>
#include <TDF_DeltaOnResume.hxx>
#include <TDF_DataSet.hxx>
#include <TDF_Label.hxx>
#include <TDF_LabelNode.hxx>
#include <TDF_Tool.hxx>
#include <Standard_DomainError.hxx>
#include <Standard_ImmutableObject.hxx>
#undef TDF_DATA_COMMIT_OPTIMIZED
#define BUC60879
//=======================================================================
//function : TDF_Attribute
//purpose : Initializes fields.
//=======================================================================
TDF_Attribute::TDF_Attribute() :
myLabelNode(NULL),
myTransaction(0),
mySavedTransaction(0),
myFlags(1)
{}
//=======================================================================
//function : Label
//purpose :
//=======================================================================
const TDF_Label TDF_Attribute::Label() const
{ return TDF_Label(myLabelNode); }
//=======================================================================
//function : Find
//purpose :
//=======================================================================
Standard_Boolean TDF_Attribute::FindAttribute (const Standard_GUID& anID,
Handle(TDF_Attribute)& anAttribute) const
{
return Label().FindAttribute(anID,anAttribute);
}
//=======================================================================
//function : IsAttribute
//purpose :
//=======================================================================
Standard_Boolean TDF_Attribute::IsAttribute (const Standard_GUID& anID) const
{
return Label().IsAttribute(anID);
}
//=======================================================================
//function : AddAttribute
//purpose :
//=======================================================================
void TDF_Attribute::AddAttribute (const Handle(TDF_Attribute)& otherAttribute) const
{ Label().AddAttribute (otherAttribute); }
//=======================================================================
//function : ForgetAttribute
//purpose :
//=======================================================================
Standard_Boolean TDF_Attribute::ForgetAttribute (const Standard_GUID& anID) const
{ return Label().ForgetAttribute (anID); }
//=======================================================================
//function : ForgetAllAttributes
//purpose :
//=======================================================================
void TDF_Attribute::ForgetAllAttributes (const Standard_Boolean clearChildren) const
{ Label().ForgetAllAttributes (clearChildren); }
//=======================================================================
//function : Forget
//purpose :
//=======================================================================
void TDF_Attribute::Forget (const Standard_Integer aTransaction)
{
mySavedTransaction = myTransaction;
myTransaction = aTransaction;
myFlags = (myFlags | TDF_AttributeForgottenMsk);
Validate(Standard_False);
}
//=======================================================================
//function : Resume
//purpose :
//=======================================================================
void TDF_Attribute::Resume()
{
myTransaction = mySavedTransaction;
mySavedTransaction = -1; // To say "just resumed"!
myFlags = (myFlags & ~TDF_AttributeForgottenMsk);
Validate(Standard_True);
}
//=======================================================================
//function : UntilTransaction
//purpose :
//=======================================================================
Standard_Integer TDF_Attribute::UntilTransaction() const
{
if (IsForgotten()) return myTransaction;
else if (IsBackuped()) return myNext->myTransaction - 1;
else if (IsValid()) return myLabelNode->Data()->Transaction();
Standard_DomainError::Raise("The attribute structure is wrong.");
return 0;
}
//=======================================================================
//function : AfterAddition
//purpose :
//=======================================================================
void TDF_Attribute::AfterAddition()
{}
//=======================================================================
//function : BeforeRemoval
//purpose :
//=======================================================================
void TDF_Attribute::BeforeRemoval()
{}
//=======================================================================
//function : BeforeForget
//purpose :
//=======================================================================
void TDF_Attribute::BeforeForget()
{}
//=======================================================================
//function : AfterResume
//purpose :
//=======================================================================
void TDF_Attribute::AfterResume()
{}
//=======================================================================
//function : BeforeUndo
//purpose : Before application of a TDF_Delta.
//=======================================================================
Standard_Boolean TDF_Attribute::BeforeUndo
(const Handle(TDF_AttributeDelta)& anAttDelta,
const Standard_Boolean forceIt)
{ return Standard_True; }
//=======================================================================
//function : AfterUndo
//purpose : After application of a TDF_Delta.
//=======================================================================
Standard_Boolean TDF_Attribute::AfterUndo
(const Handle(TDF_AttributeDelta)& anAttDelta,
const Standard_Boolean forceIt)
{ return Standard_True; }
//=======================================================================
//function : AfterRetrieval
//purpose :
//=======================================================================
Standard_Boolean TDF_Attribute::AfterRetrieval
(const Standard_Boolean forceIt)
{ return Standard_True; }
#ifdef BUC60879
//=======================================================================
//function : BeforeCommitTransaction
//purpose :
//=======================================================================
void TDF_Attribute::BeforeCommitTransaction() {}
#endif
//=======================================================================
//function : Backup
//purpose : Backups the attribute.
//=======================================================================
void TDF_Attribute::Backup()
{
// The attribute must be valid and attached to a label.
if (IsValid() && (myLabelNode != NULL)) {
Handle(TDF_Data) aData = myLabelNode->Data();
// check that modification is allowed
if ( !aData->IsModificationAllowed() ) {
TCollection_AsciiString aMess;
aMess = "Attribute \"";
aMess += DynamicType()->Name();
aMess += "\" is changed outside transaction";
Standard_ImmutableObject::Raise(aMess.ToCString());
}
const Standard_Integer currentTransaction =
aData->Transaction();
if (myTransaction < currentTransaction) {//"!=" is less secure.
Handle(TDF_Attribute) backup = BackupCopy();
#ifdef TDF_DATA_COMMIT_OPTIMIZED
myLabelNode->AttributesModified(Standard_True);
#endif
backup->myLabelNode = myLabelNode;
backup->myNext = this; // Back reference;
backup->myBackup = myBackup;
backup->myTransaction = myTransaction;
backup->Backup(Standard_True);
myBackup = backup;
myTransaction = currentTransaction;
}
}
}
//=======================================================================
//function : BackupCopy
//purpose : Standard implementation of BackupCopy.
//=======================================================================
Handle(TDF_Attribute) TDF_Attribute::BackupCopy() const
{
Handle(TDF_Attribute) copy = NewEmpty(); copy->Restore(this);
return copy;
}
//=======================================================================
//function : RemoveBackup
//purpose :
//=======================================================================
void TDF_Attribute::RemoveBackup()
{
#ifdef DEB
if (myBackup.IsNull())
Standard_DomainError::Raise("Impossible to remove a nonexistent backup.");
#endif
myBackup->BeforeRemoval();
myBackup->myLabelNode = NULL; // Absolutly necessary!
myBackup->myNext.Nullify(); // Absolutly necessary!
myBackup = myBackup->myBackup;
if (!myBackup.IsNull()) myBackup->myNext = this; // New back reference.
}
//=======================================================================
//function : References
//purpose : Adds the referenced attributes or labels.
//=======================================================================
void TDF_Attribute::References(const Handle(TDF_DataSet)& aDataSet) const
{}
//=======================================================================
//function : DeltaOnAddition
//purpose : Creates such a delta.
//=======================================================================
Handle(TDF_DeltaOnAddition) TDF_Attribute::DeltaOnAddition() const
{ return new TDF_DeltaOnAddition(this); }
//=======================================================================
//function : DeltaOnForget
//purpose : Creates such a delta.
//=======================================================================
Handle(TDF_DeltaOnForget) TDF_Attribute::DeltaOnForget() const
{ return new TDF_DeltaOnForget(this); }
//=======================================================================
//function : DeltaOnResume
//purpose : Creates such a delta.
//=======================================================================
Handle(TDF_DeltaOnResume) TDF_Attribute::DeltaOnResume() const
{ return new TDF_DeltaOnResume(this); }
//=======================================================================
//function : DeltaOnModification
//purpose : Creates such a delta.
//=======================================================================
Handle(TDF_DeltaOnModification) TDF_Attribute::DeltaOnModification
(const Handle(TDF_Attribute)& anOldAttribute) const
{ return new TDF_DefaultDeltaOnModification(anOldAttribute); }
//=======================================================================
//function : DeltaOnModification
//purpose : Applies such a delta.
//=======================================================================
void TDF_Attribute::DeltaOnModification
(const Handle(TDF_DeltaOnModification)& aDelta)
{
Backup();
Restore(aDelta->Attribute());
}
//=======================================================================
//function : DeltaOnRemoval
//purpose : Creates such a delta.
//=======================================================================
Handle(TDF_DeltaOnRemoval) TDF_Attribute::DeltaOnRemoval() const
{ return new TDF_DefaultDeltaOnRemoval(this); } // myBackup
//=======================================================================
//function : Dump
//purpose : This method is equivalent to operator <<
//=======================================================================
Standard_OStream& TDF_Attribute::Dump(Standard_OStream& anOS) const
{
anOS<<"\t"<<DynamicType()->Name()<<"\tTrans. "<<myTransaction<<";";
if (IsValid()) anOS<<" Valid";
if (IsBackuped()) anOS<<" Backuped";
if (IsForgotten()) anOS<<" Forgotten";
char toto[45];
Standard_PCharacter pStr;
//
pStr=toto;
ID().ToCString(pStr); anOS<<";\tID = "<<toto<<endl;
//ID().ShallowDump(anOS);anOS<<endl;
return anOS;
}
//=======================================================================
//function :ExtendedDump
//purpose :
//=======================================================================
void TDF_Attribute::ExtendedDump
(Standard_OStream& anOS,
const TDF_IDFilter& aFilter,
TDF_AttributeIndexedMap& aMap) const
{ Dump(anOS); }

50
src/TDF/TDF_Attribute.lxx Executable file
View File

@@ -0,0 +1,50 @@
// File: TDF_Attribute.lxx
// -----------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 14 1997 Creation
enum {
TDF_AttributeValidMsk = 1,
TDF_AttributeBackupMsk = 2,
TDF_AttributeForgottenMsk = 4
};
inline Standard_Integer TDF_Attribute::Transaction() const
{ return myTransaction; }
// Validation
inline void TDF_Attribute::Validate(const Standard_Boolean aStatus)
{ myFlags = (aStatus) ?
(myFlags | TDF_AttributeValidMsk) : (myFlags & ~TDF_AttributeValidMsk); }
inline Standard_Boolean TDF_Attribute::IsValid() const
{ return (myFlags & TDF_AttributeValidMsk) != 0 ; }
// Backup
inline void TDF_Attribute::Backup(const Standard_Boolean aStatus)
{
myFlags = (aStatus) ?
(myFlags | TDF_AttributeBackupMsk) : (myFlags & ~ TDF_AttributeBackupMsk);
Validate(!aStatus);
}
inline Standard_Boolean TDF_Attribute::IsBackuped() const
{ return (myFlags & TDF_AttributeBackupMsk) != 0; }
// IsNew
inline Standard_Boolean TDF_Attribute::IsNew() const
{ return IsValid () && myBackup.IsNull(); }
// IsForgotten
inline Standard_Boolean TDF_Attribute::IsForgotten() const
{ return (myFlags & TDF_AttributeForgottenMsk) != 0; }
// operator <<
inline Standard_OStream& operator << (Standard_OStream& anOS,
const Handle(TDF_Attribute)& anAtt)
{ return anAtt->Dump(anOS); }

76
src/TDF/TDF_AttributeDelta.cdl Executable file
View File

@@ -0,0 +1,76 @@
-- File: TDF_AttributeDelta.cdl
-- ----------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Sep 8 1997 Creation
deferred class AttributeDelta from TDF inherits TShared from MMgt
---Purpose: This class discribes the services we need to
-- implement Delta and Undo/Redo services.
--
-- AttributeDeltas are applied in an unpredictable
-- order. But by the redefinition of the method
-- IsNowApplicable, a condition can be verified
-- before application. If the AttributeDelta is not
-- yet applicable, it is put at the end of the
-- AttributeDelta list, to be treated later. If a
-- dead lock if found on the list, the
-- AttributeDeltas are forced to be applied in an
-- unpredictable order.
uses
Label from TDF,
Attribute from TDF
is
Initialize(anAttribute: Attribute from TDF);
Apply(me : mutable)
is deferred;
---Purpose: Applies the delta to the attribute.
Label(me)
returns Label from TDF;
---Purpose: Returns the label concerned by <me>.
Attribute(me)
returns Attribute from TDF;
---Purpose: Returns the reference attribute.
ID(me)
returns GUID from Standard;
---Purpose: Returns the ID of the attribute concerned by <me>.
---Category: Miscelleaneous
-- --------------------------------------------------------------
Dump(me; OS : in out OStream from Standard)
returns OStream from Standard
is virtual;
---Purpose: Dumps the contents.
--
---C++: return &
---C++: alias operator<<
fields
myAttribute : Attribute from TDF;
myLabel : Label from TDF;
end AttributeDelta;

73
src/TDF/TDF_AttributeDelta.cxx Executable file
View File

@@ -0,0 +1,73 @@
// File: TDF_AttributeDelta.cxx
// ----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Sep 8 1997 Creation
#include <TDF_AttributeDelta.ixx>
#include <Standard_GUID.hxx>
#include <TDF_Label.hxx>
#include <TDF_Tool.hxx>
#include <TCollection_AsciiString.hxx>
//=======================================================================
//function : TDF_AttributeDelta
//purpose :
//=======================================================================
TDF_AttributeDelta::TDF_AttributeDelta
(const Handle(TDF_Attribute)& anAttribute)
: myAttribute(anAttribute),
myLabel(anAttribute->Label())
{}
//=======================================================================
//function : Label
//purpose :
//=======================================================================
TDF_Label TDF_AttributeDelta::Label() const
{ return myLabel; }
//=======================================================================
//function : Attribute
//purpose :
//=======================================================================
Handle(TDF_Attribute) TDF_AttributeDelta::Attribute() const
{ return myAttribute; }
//=======================================================================
//function : ID
//purpose :
//=======================================================================
Standard_GUID TDF_AttributeDelta::ID() const
{ return myAttribute->ID(); }
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
Standard_OStream& TDF_AttributeDelta::Dump(Standard_OStream& OS) const
{
static TCollection_AsciiString entry;
TDF_Tool::Entry(Label(),entry);
OS<<this->DynamicType()->Name()<<" at "<<entry;
OS<<" on "<<Attribute()->DynamicType()->Name();
return OS;
}

117
src/TDF/TDF_AttributeIterator.cxx Executable file
View File

@@ -0,0 +1,117 @@
// File: TDF_AttributeIterator.cxx
// --------------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 7 1997 Creation
#include <TDF_AttributeIterator.hxx>
//=======================================================================
//function : TDF_AttributeIterator
//purpose :
//=======================================================================
TDF_AttributeIterator::TDF_AttributeIterator()
: myValue (0L),
myWithoutForgotten (Standard_True)
{}
//=======================================================================
//function : TDF_AttributeIterator
//purpose :
//=======================================================================
TDF_AttributeIterator::TDF_AttributeIterator
(const TDF_Label& aLabel,
const Standard_Boolean withoutForgotten)
: myValue (0L),
myWithoutForgotten (withoutForgotten)
{
const Handle(TDF_Attribute)& aFirstAttribute =
aLabel.myLabelNode->FirstAttribute();
if (!aFirstAttribute.IsNull())
goToNext (aFirstAttribute);
}
//=======================================================================
//function : TDF_AttributeIterator
//purpose :
//=======================================================================
TDF_AttributeIterator::TDF_AttributeIterator
(const TDF_LabelNodePtr aLabelNode,
const Standard_Boolean withoutForgotten)
: myValue (0L),
myWithoutForgotten (withoutForgotten)
{
const Handle(TDF_Attribute)& aFirstAttribute = aLabelNode->FirstAttribute();
if (!aFirstAttribute.IsNull())
goToNext (aFirstAttribute);
}
//=======================================================================
//function : TDF_AttributeIterator
//purpose :
//=======================================================================
void TDF_AttributeIterator::Initialize
(const TDF_Label& aLabel,
const Standard_Boolean withoutForgotten)
{
myWithoutForgotten = withoutForgotten;
const Handle(TDF_Attribute)& aFirstAttribute =
aLabel.myLabelNode->FirstAttribute();
if (aFirstAttribute.IsNull())
myValue = 0L;
else
goToNext (aFirstAttribute);
}
//=======================================================================
//function : Next
//purpose :
//=======================================================================
void TDF_AttributeIterator::Next()
{
// A little bit complicated...
// but necessary if we want to find sometimes the Forgotten attributes.
if (myValue) {
const Handle(TDF_Attribute)& anAttribute = myValue->myNext;
if (anAttribute.IsNull())
myValue = 0L;
else
goToNext (anAttribute);
}
}
//=======================================================================
//function : goToNext
//purpose : private method, used by the above
//=======================================================================
void TDF_AttributeIterator::goToNext (const Handle(TDF_Attribute)& anAttr)
{
myValue = anAttr.operator->();
if (myWithoutForgotten) {
while (myValue->IsForgotten()) {
const Handle(TDF_Attribute)& anAttribute = myValue->myNext;
if (anAttribute.IsNull()) {
myValue = 0L;
break;
}
myValue = anAttribute.operator->();
}
}
}

102
src/TDF/TDF_AttributeIterator.hxx Executable file
View File

@@ -0,0 +1,102 @@
// File: TDF_AttributeIterator.hxx
// -------------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1998
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 16 1998 Creation
#ifndef _TDF_Attribute_HeaderFile
#include <TDF_Attribute.hxx>
#endif
#ifndef _TDF_Label_HeaderFile
#include <TDF_Label.hxx>
#endif
#ifndef TDF_AttributeIterator_HeaderFile
#define TDF_AttributeIterator_HeaderFile
#ifndef _Handle_TDF_Attribute_HeaderFile
#include <Handle_TDF_Attribute.hxx>
#endif
#ifndef _Standard_Boolean_HeaderFile
#include <Standard_Boolean.hxx>
#endif
#ifndef _TDF_LabelNodePtr_HeaderFile
#include <TDF_LabelNodePtr.hxx>
#endif
class TDF_Attribute;
class TDF_Label;
#ifndef _Standard_Macro_HeaderFile
#include <Standard_Macro.hxx>
#endif
// This class provides a way to iterates on the
// up-to-date (current) valid attributes of a label.
//
// Even a Forgotten attribute may be found if this
// option is set. To use this possibility, look at
// the constructor.
//
// Sorry: nobody needs this iterator but its friends!
class TDF_AttributeIterator {
public:
// Methods PUBLIC
//
Standard_EXPORT TDF_AttributeIterator();
Standard_EXPORT TDF_AttributeIterator
(const TDF_Label& aLabel,
const Standard_Boolean withoutForgotten = Standard_True);
Standard_EXPORT TDF_AttributeIterator
(const TDF_LabelNodePtr aLabelNode,
const Standard_Boolean withoutForgotten = Standard_True);
Standard_EXPORT void Initialize
(const TDF_Label& aLabel,
const Standard_Boolean withoutForgotten = Standard_True) ;
inline Standard_Boolean More() const;
Standard_EXPORT void Next() ;
inline TDF_Attribute * Value() const;
protected:
// Methods PROTECTED
//
// Fields PROTECTED
//
private:
// Methods PRIVATE
//
void goToNext (const Handle(TDF_Attribute)& anAttr);
// Fields PRIVATE
//
TDF_Attribute * myValue;
Standard_Boolean myWithoutForgotten;
};
// other inline functions and methods (like "C++: function call" methods)
//
inline Standard_Boolean TDF_AttributeIterator::More() const
{ return (myValue != 0L); }
inline TDF_Attribute * TDF_AttributeIterator::Value() const
{ return myValue; }
#endif

74
src/TDF/TDF_ChildIDIterator.cdl Executable file
View File

@@ -0,0 +1,74 @@
-- File: TDF_ChildIDIterator.cdl
-- -----------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Nov 20 1997 Creation
class ChildIDIterator from TDF
---Purpose: Iterates on the children of a label, to find
-- attributes having ID as Attribute ID.
--
-- Level option works as TDF_ChildIterator.
uses
Attribute from TDF,
Label from TDF,
LabelNodePtr from TDF,
ChildIterator from TDF
is
Create
returns ChildIDIterator from TDF;
---Purpose: Creates an empty iterator.
Create(aLabel : Label from TDF;
anID : GUID from Standard;
allLevels : Boolean from Standard = Standard_False)
returns ChildIDIterator from TDF;
---Purpose: Iterates on the children of the given label. If
-- <allLevels> option is set to true, it explores not
-- only the first, but all the sub label levels.
Initialize(me : in out;
aLabel : Label from TDF;
anID : GUID from Standard;
allLevels : Boolean from Standard = Standard_False);
---Purpose: Initializes the iteration on the children of the
-- given label. If <allLevels> option is set to true,
-- it explores not only the first, but all the sub
-- label levels.
More(me) returns Boolean;
---Purpose: Returns True if there is a current Item in the
-- iteration.
--
---C++: inline
Next(me : in out);
---Purpose: Move to the next Item
NextBrother(me : in out);
---Purpose: Move to the next Brother. If there is none, go up
-- etc. This method is interesting only with
-- "allLevels" behavior, because it avoids to explore
-- the current label children.
Value(me) returns Attribute from TDF;
---Purpose: Returns the current item; a null handle if there is none.
--
---C++: inline
fields
myID : GUID from Standard;
myItr : ChildIterator from TDF;
myAtt : Attribute from TDF;
end ChildIDIterator;

95
src/TDF/TDF_ChildIDIterator.cxx Executable file
View File

@@ -0,0 +1,95 @@
// File: TDF_ChildIDIterator.cxx
// -----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Nov 20 1997 Creation
#include <TDF_ChildIDIterator.ixx>
#include <TDF_ChildIterator.ixx>
#include <TDF_Label.hxx>
#include <TDF_LabelNode.hxx>
#include <TDF_LabelNodePtr.hxx>
#define ChildIDIterator_FindNext \
{ while( myItr.More() && !myItr.Value().FindAttribute(myID,myAtt)) myItr.Next(); }
//=======================================================================
//function : TDF_ChildIDIterator
//purpose :
//=======================================================================
TDF_ChildIDIterator::TDF_ChildIDIterator()
{}
//=======================================================================
//function : TDF_ChildIDIterator
//purpose :
//=======================================================================
TDF_ChildIDIterator::TDF_ChildIDIterator
(const TDF_Label& aLabel,
const Standard_GUID& anID,
const Standard_Boolean allLevels)
: myID(anID),
myItr(aLabel,allLevels)
{ ChildIDIterator_FindNext; }
//=======================================================================
//function : Initialize
//purpose :
//=======================================================================
void TDF_ChildIDIterator::Initialize
(const TDF_Label& aLabel,
const Standard_GUID& anID,
const Standard_Boolean allLevels)
{
myID = anID;
myItr.Initialize(aLabel,allLevels);
myAtt.Nullify();
ChildIDIterator_FindNext;
}
//=======================================================================
//function : Next
//purpose :
//=======================================================================
void TDF_ChildIDIterator::Next()
{
myAtt.Nullify();
if (myItr.More()) {
myItr.Next();
ChildIDIterator_FindNext;
}
}
//=======================================================================
//function : NextBrother
//purpose :
//=======================================================================
void TDF_ChildIDIterator::NextBrother()
{
myAtt.Nullify();
if (myItr.More()) {
myItr.NextBrother();
while (myItr.More() && !myItr.Value().FindAttribute(myID,myAtt))
myItr.NextBrother();
}
}

16
src/TDF/TDF_ChildIDIterator.lxx Executable file
View File

@@ -0,0 +1,16 @@
// File: TDF_ChildIDIterator.lxx
// -----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Dec 1 1997 Creation
inline Standard_Boolean TDF_ChildIDIterator::More() const
{ return !myAtt.IsNull(); }
inline Handle(TDF_Attribute) TDF_ChildIDIterator::Value() const
{ return myAtt; }

101
src/TDF/TDF_ChildIterator.cdl Executable file
View File

@@ -0,0 +1,101 @@
-- File: TDF_ChildIterator.cdl
-- ------------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Feb 4 1997 Creation
class ChildIterator from TDF
---Purpose: Iterates on the children of a label, at the first
-- level only. It is possible to ask the iterator to
-- explore all the sub label levels of the given one,
-- with the option "allLevels".
uses
Label from TDF,
LabelNodePtr from TDF
is
Create
returns ChildIterator from TDF;
---Purpose: Creates an empty iterator object to
-- explore the children of a label.
Create(aLabel : Label from TDF;
allLevels : Boolean from Standard = Standard_False)
returns ChildIterator from TDF;
---Purpose: Constructs the iterator object defined by
-- the label aLabel. Iterates on the children of the given label. If
-- <allLevels> option is set to true, it explores not
-- only the first, but all the sub label levels.
Initialize(me : in out;
aLabel : Label from TDF;
allLevels : Boolean from Standard = Standard_False);
---Purpose: Initializes the iteration on the children of the
-- given label.
-- If <allLevels> option is set to true,
-- it explores not only the first, but all the sub
-- label levels.
-- If allLevels is false, only the first level of
-- child labels is explored.
-- In the example below, the label is iterated
-- using Initialize, More and Next and its
-- child labels dumped using TDF_Tool::Entry.
-- Example
-- void DumpChildren(const
-- TDF_Label& aLabel)
-- {
-- TDF_ChildIterator it;
-- TCollection_AsciiString es;
-- for
-- (it.Initialize(aLabel,Standard_True);
-- it.More(); it.Next()){
-- TDF_Tool::Entry(it.Value(),es);
-- cout << as.ToCString() << endl;
-- }
-- }
More(me) returns Boolean;
---Purpose: Returns true if a current label is found in the
-- iteration process.
--
---C++: inline
Next(me : in out);
---Purpose: Move the current iteration to the next Item.
NextBrother(me : in out);
---Purpose: Moves this iteration to the next brother
-- label. A brother label is one with the same
-- father as an initial label.
-- Use this function when the non-empty
-- constructor or Initialize has allLevels set to
-- true. The result is that the iteration does not
-- explore the children of the current label.
-- This method is interesting only with
-- "allLevels" behavior, because it avoids to explore
-- the current label children.
Value(me) returns Label from TDF;
---Purpose: Returns the current label; or, if there is
-- none, a null label.
--
---C++: return const
---C++: inline
fields
myNode : LabelNodePtr from TDF;
myFirstLevel : Integer from Standard;
end ChildIterator;

94
src/TDF/TDF_ChildIterator.cxx Executable file
View File

@@ -0,0 +1,94 @@
// File: TDF_ChildIterator.cxx
// ----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 7 1997 Creation
#include <TDF_ChildIterator.ixx>
#include <TDF_Label.hxx>
#include <TDF_LabelNode.hxx>
#include <TDF_LabelNodePtr.hxx>
#define ChildIterator_UpToBrother \
{ \
while (myNode && (myNode->Depth() > myFirstLevel) && !myNode->Brother()) \
myNode = myNode->Father(); \
if (myNode && (myNode->Depth() > myFirstLevel) && myNode->Father()) \
myNode = myNode->Brother(); \
else \
myNode = NULL; \
}
//=======================================================================
//function : TDF_ChildIterator
//purpose :
//=======================================================================
TDF_ChildIterator::TDF_ChildIterator()
: myNode(NULL),
myFirstLevel(0)
{}
//=======================================================================
//function : TDF_ChildIterator
//purpose :
//=======================================================================
TDF_ChildIterator::TDF_ChildIterator
(const TDF_Label& aLabel,
const Standard_Boolean allLevels)
: myNode(aLabel.myLabelNode->FirstChild()),
myFirstLevel(allLevels ? aLabel.Depth() : -1)
{}
//=======================================================================
//function : Initialize
//purpose :
//=======================================================================
void TDF_ChildIterator::Initialize
(const TDF_Label& aLabel,
const Standard_Boolean allLevels)
{
myNode = aLabel.myLabelNode->FirstChild();
myFirstLevel = allLevels ? aLabel.Depth() : -1;
}
//=======================================================================
//function : Next
//purpose :
//=======================================================================
void TDF_ChildIterator::Next()
{
if (myFirstLevel == -1) {
myNode = myNode->Brother();
}
else {
if (myNode->FirstChild()) myNode = myNode->FirstChild();
else ChildIterator_UpToBrother;
}
}
//=======================================================================
//function : NextBrother
//purpose :
//=======================================================================
void TDF_ChildIterator::NextBrother()
{
if ((myFirstLevel == -1) || myNode->Brother()) myNode = myNode->Brother();
else ChildIterator_UpToBrother;
}

16
src/TDF/TDF_ChildIterator.lxx Executable file
View File

@@ -0,0 +1,16 @@
// File: TDF_ChildIterator.lxx
// ----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 7 1997 Creation
inline Standard_Boolean TDF_ChildIterator::More() const
{ return (myNode != NULL); }
inline const TDF_Label TDF_ChildIterator::Value() const
{ return TDF_Label(myNode); }

66
src/TDF/TDF_ClosureMode.cdl Executable file
View File

@@ -0,0 +1,66 @@
-- File: TDF_ClosureMode.cdl
-- -------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 May 26 1997 Creation
class ClosureMode from TDF
---Purpose: This class provides options closure management.
-- uses
-- raises
is
Create(aMode : Boolean from Standard = Standard_True)
returns ClosureMode from TDF;
---Purpose: Creates an objet with all modes set to <aMode>.
Descendants(me : in out; aStatus : Boolean from Standard);
---Purpose: Sets the mode "Descendants" to <aStatus>.
--
-- "Descendants" mode means we add to the data set
-- the children labels of each USER GIVEN label. We
-- do not do that with the labels found applying
-- UpToFirstLevel option.
--
---C++: inline
Descendants(me) returns Boolean from Standard;
---Purpose: Returns true if the mode "Descendants" is set.
--
---C++: inline
References(me : in out; aStatus : Boolean from Standard);
---Purpose: Sets the mode "References" to <aStatus>.
--
-- "References" mode means we add to the data set
-- the descendants of an attribute, by calling the
-- attribute method Descendants().
--
---C++: inline
References(me) returns Boolean from Standard;
---Purpose: Returns true if the mode "References" is set.
--
---C++: inline
fields
myFlags : Integer from Standard;
-- Bit Mask Use
-- 0 1 Descendants
-- 1 2 References
-- 2 4 Unused
end ClosureMode;

23
src/TDF/TDF_ClosureMode.cxx Executable file
View File

@@ -0,0 +1,23 @@
// File: TDF_ClosureMode.cxx
// -------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 May 26 1997 Creation
#include <TDF_ClosureMode.ixx>
//=======================================================================
//function : TDF_ClosureMode
//purpose :
//=======================================================================
TDF_ClosureMode::TDF_ClosureMode(const Standard_Boolean aMode) :
myFlags(aMode ? ~0 : 0)
{}

27
src/TDF/TDF_ClosureMode.lxx Executable file
View File

@@ -0,0 +1,27 @@
// File: TDF_ClosureMode.lxx
// -------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 May 26 1997 Creation
#define DescendantsFlag 1
#define ReferencesFlag 2
//#define DummyFlag 4
inline void TDF_ClosureMode::Descendants(const Standard_Boolean aStatus)
{ myFlags = (aStatus) ? (myFlags | DescendantsFlag) : (myFlags & ~DescendantsFlag);}
inline Standard_Boolean TDF_ClosureMode::Descendants() const
{ return (myFlags & DescendantsFlag) != 0 ; }
inline void TDF_ClosureMode::References(const Standard_Boolean aStatus)
{ myFlags = (aStatus) ? (myFlags | ReferencesFlag) : (myFlags & ~ReferencesFlag);}
inline Standard_Boolean TDF_ClosureMode::References() const
{ return (myFlags & ReferencesFlag) != 0 ; }

80
src/TDF/TDF_ClosureTool.cdl Executable file
View File

@@ -0,0 +1,80 @@
-- File: TDF_ClosureTool.cdl
-- -------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1998
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Sep 8 1998 Creation
class ClosureTool from TDF
---Purpose: This class provides services to build the closure
-- of an information set.
--
-- You can set closure options by using IDFilter
-- (to select or exclude specific attribute IDs) and
-- CopyOption objects and by giving to Closure
-- method.
--
uses
Boolean from Standard,
Label from TDF,
Attribute from TDF,
DataSet from TDF,
RelocationTable from TDF,
AttributeMap from TDF,
LabelMap from TDF,
IDFilter from TDF,
ClosureMode from TDF
-- raises
is
Closure(myclass;
aDataSet : mutable DataSet from TDF);
---Purpose: Builds the transitive closure of label and
-- attribute sets into <aDataSet>.
Closure(myclass;
aDataSet : mutable DataSet from TDF;
aFilter : IDFilter from TDF;
aMode : ClosureMode from TDF);
---Purpose: Builds the transitive closure of label and
-- attribute sets into <aDataSet>. Uses <aFilter> to
-- determine if an attribute has to be taken in
-- account or not. Uses <aMode> for various way of
-- closing.
-- ----------------------------------------------------------------------
--
-- Private methods
--
-- ----------------------------------------------------------------------
Closure(myclass;
aLabel : Label from TDF;
aLabMap : in out LabelMap from TDF;
anAttMap : in out AttributeMap from TDF;
aFilter : IDFilter from TDF;
aMode : ClosureMode from TDF);
---Purpose: Builds the transitive closure of <aLabel>.
LabelAttributes(myclass;
aLabel : Label from TDF;
aLabMap : in out LabelMap from TDF;
anAttMap : in out AttributeMap from TDF;
aFilter : IDFilter from TDF;
aMode : ClosureMode from TDF)
is private;
---Purpose: Adds label attributes and dependences.
end ClosureTool;

176
src/TDF/TDF_ClosureTool.cxx Executable file
View File

@@ -0,0 +1,176 @@
// File: TDF_ClosureTool.cxx
// -------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1998
// Version: 0.0
// History: Version Date Purpose
// 0.0 Sep 8 1998 Creation
#include <TDF_ClosureTool.ixx>
//#include <TDF_Reference.hxx>
#include <TDF_Attribute.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_AttributeMap.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_Label.hxx>
#include <TDF_LabelMap.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
#include <TDF_MapIteratorOfAttributeMap.hxx>
#include <TDF_MapIteratorOfLabelMap.hxx>
#include <Standard_TypeMismatch.hxx>
#define DeclareAndSpeedCast(V,T,Vdown) Handle(T) Vdown = *((Handle(T)*)& V)
#define DeclareConstAndSpeedCast(V,T,Vdown) const Handle(T)& Vdown = (Handle(T)&) V
#define SpeedCast(V,T,Vdown) Vdown = *((Handle(T)*)& V)
//=======================================================================
//function : Closure
//purpose : Builds the transitive closure whithout attribute filter.
//=======================================================================
void TDF_ClosureTool::Closure
(const Handle(TDF_DataSet)& aDataSet)
{
TDF_IDFilter Filter(Standard_False); // "Keep all"
TDF_ClosureMode Mode; // All modes are set to true.
TDF_ClosureTool::Closure(aDataSet, Filter, Mode);
}
//=======================================================================
//function : Closure
//purpose : Builds the transitive closure with an attribute filter.
//=======================================================================
void TDF_ClosureTool::Closure
(const Handle(TDF_DataSet)& aDataSet,
const TDF_IDFilter& aFilter,
const TDF_ClosureMode& aMode)
{
TDF_LabelMap& labMap = aDataSet->Labels();
TDF_AttributeMap& attMap = aDataSet->Attributes();
TDF_LabelList& rootLst = aDataSet->Roots();
// Memorizes the roots for future uses.
rootLst.Clear();
TDF_MapIteratorOfLabelMap labMItr(labMap);
for (; labMItr.More(); labMItr.Next()) rootLst.Append(labMItr.Key());
// Iterates on roots.
TDF_ListIteratorOfLabelList labLItr(rootLst);
for (; labLItr.More(); labLItr.Next()) {
const TDF_Label& lab = labLItr.Value();
if (lab.HasAttribute())
TDF_ClosureTool::LabelAttributes(lab,labMap,attMap,aFilter,aMode);
TDF_ClosureTool::Closure(lab,labMap,attMap,aFilter,aMode);
}
}
//=======================================================================
//function : Closure
//purpose : Internal closure method.
//=======================================================================
void TDF_ClosureTool::Closure
(const TDF_Label& aLabel,
TDF_LabelMap& aLabMap,
TDF_AttributeMap& anAttMap,
const TDF_IDFilter& aFilter,
const TDF_ClosureMode& aMode)
{
TDF_Label upLab;
for (TDF_ChildIterator childItr(aLabel,Standard_True);
childItr.More();childItr.Next()){
const TDF_Label& locLab = childItr.Value();
// On ne peut faire cette optimisation car il faudrait d'abord
// qu'aucun label donne comme Root ne soit fils d'un autre label root!
if (locLab.HasAttribute()) { // && aLabMap.Add(locLab)) {
aLabMap.Add(locLab);
upLab = locLab.Father();
while (aLabMap.Add(upLab)) upLab = upLab.Father();
TDF_ClosureTool::LabelAttributes(locLab,aLabMap,anAttMap,aFilter,aMode);
}
}
}
//=======================================================================
//function : LabelAttributes
//purpose : Internal method: adds the attributes to <aDataSet>.
//=======================================================================
void TDF_ClosureTool::LabelAttributes
(const TDF_Label& aLabel,
TDF_LabelMap& aLabMap,
TDF_AttributeMap& anAttMap,
const TDF_IDFilter& aFilter,
const TDF_ClosureMode& aMode)
{
Handle(TDF_DataSet) tmpDataSet;
Standard_Boolean BindLabel;
TDF_MapIteratorOfAttributeMap attMItr;
TDF_MapIteratorOfLabelMap labMItr;
// Attributes directly attached to the label.
for (TDF_AttributeIterator attItr(aLabel); attItr.More(); attItr.Next()) {
const Handle(TDF_Attribute) locAtt1 = attItr.Value();
if (aFilter.IsKept(locAtt1)) {
if (anAttMap.Add(locAtt1)) {
// locAtt1 not yet in the map.
// Labels & Attributes referenced by the attribute.
tmpDataSet = new TDF_DataSet();
if (aMode.References()) {
// 1 - The referenced attributes
// 1.1 - A referenced attribute has a label : adds the label;
// 1.2 - A referenced attribute has no label : adds the attribute;
// 2 - Adds the referenced labels.
locAtt1->References(tmpDataSet);
// 1 - The referenced attributes
const TDF_AttributeMap& tmpAttMap = tmpDataSet->Attributes();
for (attMItr.Initialize(tmpAttMap);
attMItr.More(); attMItr.Next()) {
const Handle(TDF_Attribute)& locAtt2 = attMItr.Key();
BindLabel = Standard_False;
if (!locAtt2.IsNull()) {
const TDF_Label& locLab2 = locAtt2->Label();
BindLabel = !locLab2.IsNull();
if (BindLabel) {
// 1.1 - A referenced attribute has a label.
if (aLabMap.Add(locLab2))
TDF_ClosureTool::Closure(locLab2,
aLabMap,anAttMap,aFilter,aMode);
}
else {
// 1.2 - A referenced attribute has no label.
// We suppose locAtt2 has no referenced attribute itself.
anAttMap.Add(locAtt2);
}
}
}
// 2 - Adds the referenced labels.
const TDF_LabelMap& tmpLabMap = tmpDataSet->Labels();
for (labMItr.Initialize(tmpLabMap);
labMItr.More(); labMItr.Next()) {
const TDF_Label& locLab1 = labMItr.Key();
if (aLabMap.Add(locLab1))
TDF_ClosureTool::Closure(locLab1,
aLabMap,anAttMap,aFilter,aMode);
}
}
}
}
}
}

137
src/TDF/TDF_ComparisonTool.cdl Executable file
View File

@@ -0,0 +1,137 @@
-- File: TDF_ComparisonTool.cdl
-- ----------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Sep 4 1997 Creation
class ComparisonTool from TDF
---Purpose: This class provides services to compare sets of
-- information. The use of this tool can works after
-- a copy, acted by a CopyTool.
--
-- * Compare(...) compares two DataSet and returns
-- the result.
--
-- * SourceUnbound(...) builds the difference between
-- a relocation dictionnary and a source set of
-- information.
--
-- * TargetUnbound(...) does the same between a
-- relocation dictionnary and a target set of
-- information.
--
-- * Cut(aDataSet, anLabel) removes a set of
-- attributes.
--
-- * IsSelfContained(...) returns true if all the
-- labels of the attributes of the given DataSet are
-- descendant of the given label.
uses
Boolean from Standard,
Label from TDF,
Attribute from TDF,
DataSet from TDF,
RelocationTable from TDF,
AttributeMap from TDF,
IDFilter from TDF
-- raises
is
Compare(myclass;
aSourceDataSet : DataSet from TDF;
aTargetDataSet : DataSet from TDF;
aFilter : IDFilter from TDF;
aRelocationTable : mutable RelocationTable from TDF);
---Purpose: Compares <aSourceDataSet> with <aTargetDataSet>,
-- updating <aRelocationTable> with labels and
-- attributes found in both sets.
SourceUnbound(myclass;
aRefDataSet : DataSet from TDF;
aRelocationTable : RelocationTable from TDF;
aFilter : IDFilter from TDF;
aDiffDataSet : mutable DataSet from TDF;
anOption : Integer from Standard = 2)
returns Boolean from Standard;
---Purpose: Finds from <aRefDataSet> all the keys not bound
-- into <aRelocationTable> and put them into
-- <aDiffDataSet>. Returns True if the difference
-- contains at least one key. (A key is a source
-- object).
--
-- <anOption> may take the following values:
-- 1 : labels treatment only;
-- 2 : attributes treatment only (default value);
-- 3 : both labels & attributes treatment.
TargetUnbound(myclass;
aRefDataSet : DataSet from TDF;
aRelocationTable : RelocationTable from TDF;
aFilter : IDFilter from TDF;
aDiffDataSet : mutable DataSet from TDF;
anOption : Integer from Standard = 2)
returns Boolean from Standard;
---Purpose: Substracts from <aRefDataSet> all the items bound
-- into <aRelocationTable>. The result is put into
-- <aDiffDataSet>. Returns True if the difference
-- contains at least one item. (An item is a target
-- object).
--
-- <anOption> may take the following values:
-- 1 : labels treatment only;
-- 2 : attributes treatment only(default value);
-- 3 : both labels & attributes treatment.
Cut(myclass;
aDataSet : DataSet from TDF);
---Purpose: Removes attributes from <aDataSet>.
IsSelfContained(myclass;
aLabel : Label from TDF;
aDataSet : DataSet from TDF)
returns Boolean from Standard;
---Purpose: Returns true if all the labels of <aDataSet> are
-- descendant of <aLabel>.
-- ----------------------------------------------------------------------
--
-- Private methods
--
-- ----------------------------------------------------------------------
Compare(myclass;
aSrcLabel : Label from TDF;
aTrgLabel : Label from TDF;
aSourceDataSet : DataSet from TDF;
aTargetDataSet : DataSet from TDF;
aFilter : IDFilter from TDF;
aRelocationTable : mutable RelocationTable from TDF)
is private;
---Purpose: Internal comparison method used by Compare(...).
Unbound(myclass;
aRefDataSet : DataSet from TDF;
aRelocationTable : RelocationTable from TDF;
aFilter : IDFilter from TDF;
aDiffDataSet : mutable DataSet from TDF;
anOption : Integer from Standard;
theSource : Boolean from Standard)
returns Boolean from Standard
is private;
---Purpose: Internal function used by SourceUnbound() and
-- TargetUnbound().
end ComparisonTool;

261
src/TDF/TDF_ComparisonTool.cxx Executable file
View File

@@ -0,0 +1,261 @@
// File: TDF_ComparisonTool.cxx
// ----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Sep 4 1997 Creation
#include <TDF_ComparisonTool.ixx>
#include <TDF_Attribute.hxx>
#include <TDF_AttributeDataMap.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_AttributeMap.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_DataMapIteratorOfAttributeDataMap.hxx>
#include <TDF_DataMapIteratorOfLabelDataMap.hxx>
#include <TDF_Label.hxx>
#include <TDF_LabelDataMap.hxx>
#include <TDF_LabelMap.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
#include <TDF_MapIteratorOfAttributeMap.hxx>
#include <TDF_MapIteratorOfLabelMap.hxx>
//=======================================================================
//function : Compare
//purpose : Comparison method between 2 DataSets.
//=======================================================================
void TDF_ComparisonTool::Compare
(const Handle(TDF_DataSet)& aSourceDataSet,
const Handle(TDF_DataSet)& aTargetDataSet,
const TDF_IDFilter& aFilter,
const Handle(TDF_RelocationTable)& aRelocationTable)
{
if (aSourceDataSet->IsEmpty() || aTargetDataSet->IsEmpty()) return;
const TDF_LabelList& srcRoots = aSourceDataSet->Roots();
TDF_ListIteratorOfLabelList srcRootItr(srcRoots);
const TDF_LabelList& trgRoots = aTargetDataSet->Roots();
TDF_ListIteratorOfLabelList trgRootItr;
TDF_LabelDataMap& the2LabMap = aRelocationTable->LabelTable();
// Try to match source and target roots by their tag.
for (; srcRootItr.More(); srcRootItr.Next()) {
const TDF_Label& srcLab = srcRootItr.Value();
for (trgRootItr.Initialize(trgRoots);trgRootItr.More();trgRootItr.Next()){
const TDF_Label& trgLab = trgRootItr.Value();
if (srcLab.Tag() == trgLab.Tag()) {
the2LabMap.Bind(srcLab, trgLab);
// Now, compare recursively!
TDF_ComparisonTool::Compare(srcLab,trgLab,
aSourceDataSet, aTargetDataSet, aFilter,
aRelocationTable);
break;
}
}
}
// The relocation attribute table is now ready,
// except for the label unattached attributes,
// because we cannot treat them.
}
//=======================================================================
//function : Compare
//purpose : Internal recursive comparison method.
//=======================================================================
void TDF_ComparisonTool::Compare
(const TDF_Label& aSrcLabel,
const TDF_Label& aTrgLabel,
const Handle(TDF_DataSet)& aSourceDataSet,
const Handle(TDF_DataSet)& aTargetDataSet,
const TDF_IDFilter& aFilter,
const Handle(TDF_RelocationTable)& aRelocationTable)
{
TDF_LabelDataMap& the2LabMap = aRelocationTable->LabelTable();
TDF_AttributeDataMap& the2AttMap = aRelocationTable->AttributeTable();
Handle(TDF_Attribute) tAtt;
// Compare source and target attributes.
for (TDF_AttributeIterator attItr(aSrcLabel); attItr.More(); attItr.Next()){
const Handle(TDF_Attribute) sAtt = attItr.Value();
if (aFilter.IsKept(sAtt) && aSourceDataSet->ContainsAttribute(sAtt)) {
if (aTrgLabel.FindAttribute(sAtt->ID(),tAtt)) {
if (aTargetDataSet->ContainsAttribute(tAtt))
the2AttMap.Bind(sAtt,tAtt);
}
}
}
// Do the same for the children.
TDF_ChildIterator childItr1, childItr2;
for (childItr1.Initialize(aSrcLabel); childItr1.More(); childItr1.Next()){
const TDF_Label& childSrcLab = childItr1.Value();
if (aSourceDataSet->ContainsLabel(childSrcLab)) {
for (childItr2.Initialize(aSrcLabel);childItr2.More();childItr2.Next()){
const TDF_Label& childTrgLab = childItr2.Value();
if (aTargetDataSet->ContainsLabel(childTrgLab)) {
if (childSrcLab.Tag() == childTrgLab.Tag()) {
the2LabMap.Bind(childSrcLab, childTrgLab);
TDF_ComparisonTool::Compare(childSrcLab,childTrgLab,
aSourceDataSet,aTargetDataSet,aFilter,
aRelocationTable);
break;
}
}
}
}
}
}
//=======================================================================
//function : SourceUnbound
//purpose :
//=======================================================================
Standard_Boolean TDF_ComparisonTool::SourceUnbound
(const Handle(TDF_DataSet)& aRefDataSet,
const Handle(TDF_RelocationTable)& aRelocationTable,
const TDF_IDFilter& aFilter,
const Handle(TDF_DataSet)& aDiffDataSet,
const Standard_Integer anOption)
{
if (aRefDataSet->IsEmpty()) return Standard_False;
else return Unbound(aRefDataSet, aRelocationTable, aFilter,
aDiffDataSet, anOption, Standard_True);
}
//=======================================================================
//function : TargetUnbound
//purpose :
//=======================================================================
Standard_Boolean TDF_ComparisonTool::TargetUnbound
(const Handle(TDF_DataSet)& aRefDataSet,
const Handle(TDF_RelocationTable)& aRelocationTable,
const TDF_IDFilter& aFilter,
const Handle(TDF_DataSet)& aDiffDataSet,
const Standard_Integer anOption)
{
if (aRefDataSet->IsEmpty()) return Standard_False;
else return Unbound(aRefDataSet, aRelocationTable, aFilter,
aDiffDataSet, anOption, Standard_False);
}
//=======================================================================
//function : Unbound
//purpose : Internal function used by SourceUnbound and TargetUnbound.
//=======================================================================
Standard_Boolean TDF_ComparisonTool::Unbound
(const Handle(TDF_DataSet)& aRefDataSet,
const Handle(TDF_RelocationTable)& aRelocationTable,
const TDF_IDFilter& aFilter,
const Handle(TDF_DataSet)& aDiffDataSet,
const Standard_Integer anOption,
const Standard_Boolean theSource)
{
Standard_Boolean hasDiff = Standard_False;
// Labels
if ((anOption & 1) != 0) {
const TDF_LabelMap& refLabs = aRefDataSet->Labels();
TDF_LabelMap& diffLabs = aDiffDataSet->Labels();
const TDF_LabelDataMap& the2LabMap = aRelocationTable->LabelTable();
TDF_LabelMap theTLabMap;
if (!theSource) aRelocationTable->TargetLabelMap(theTLabMap);
for (TDF_MapIteratorOfLabelMap refLabMItr(refLabs);
refLabMItr.More(); refLabMItr.Next()) {
const TDF_Label& refLab = refLabMItr.Key();
if (!(theSource ?
the2LabMap.IsBound(refLab)
: theTLabMap.Contains(refLab)))
diffLabs.Add(refLab);
}
hasDiff = (diffLabs.Extent()>0);
}
// Attributes
if ((anOption & 2) != 0) {
const TDF_AttributeMap& refAtts = aRefDataSet->Attributes();
TDF_AttributeMap& diffAtts = aDiffDataSet->Attributes();
const TDF_AttributeDataMap& the2AttMap =aRelocationTable->AttributeTable();
TDF_AttributeMap theTAttMap;
if (!theSource) aRelocationTable->TargetAttributeMap(theTAttMap);
for (TDF_MapIteratorOfAttributeMap refAttMItr(refAtts);
refAttMItr.More(); refAttMItr.Next()) {
const Handle(TDF_Attribute)& refAtt = refAttMItr.Key();
if (aFilter.IsKept(refAtt)) {
if (!(theSource ?
the2AttMap.IsBound(refAtt)
: theTAttMap.Contains(refAtt)))
diffAtts.Add(refAtt);
}
}
hasDiff = (hasDiff || diffAtts.Extent()>0);
}
return hasDiff;
}
//=======================================================================
//function : Cut
//purpose : Removes the attributes contained into <aDataSet>
//=======================================================================
void TDF_ComparisonTool::Cut
(const Handle(TDF_DataSet)& aDataSet)
{
if (aDataSet->IsEmpty()) return;
#ifdef DEB
TDF_LabelMap& refLabs =
#endif
aDataSet->Labels();
const TDF_AttributeMap& refAtts = aDataSet->Attributes();
// Removes the attributes.
TDF_MapIteratorOfAttributeMap refAttMItr(refAtts);
for (; refAttMItr.More(); refAttMItr.Next()) {
const Handle(TDF_Attribute)& locAtt = refAttMItr.Key();
locAtt->Label().ForgetAttribute(locAtt);
}
}
//=======================================================================
//function : IsSelfContained
//purpose : Returns true if all the labels of <aDataSet> are
// descendant of <aLabel>.
//=======================================================================
Standard_Boolean TDF_ComparisonTool::IsSelfContained
(const TDF_Label& aLabel,
const Handle(TDF_DataSet)& aDataSet)
{
if (!aDataSet->IsEmpty()) {
const TDF_LabelMap& refLabs = aDataSet->Labels();
for (TDF_MapIteratorOfLabelMap refLabMItr(refLabs);
refLabMItr.More();
refLabMItr.Next()) {
if (!refLabMItr.Key().IsDescendant(aLabel)) return Standard_False;
}
}
return Standard_True;
}

72
src/TDF/TDF_CopyLabel.cdl Executable file
View File

@@ -0,0 +1,72 @@
-- File: TDF_SelfContainedCopy.cdl
-- Created: Thu Jun 24 14:23:31 1999
-- Author: Sergey ZARITCHNY
-- <szy@philipox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class CopyLabel from TDF
---Purpose:
uses
Boolean from Standard,
Label from TDF,
Attribute from TDF,
DataSet from TDF,
RelocationTable from TDF,
AttributeMap from TDF,
LabelMap from TDF,
IDFilter from TDF
is
Create returns CopyLabel from TDF;
---Purpose: Empty constructor
Create(aSource, aTarget : Label from TDF)
returns CopyLabel from TDF;
---Purpose: CopyTool
Load(me : in out; aSource, aTarget : Label from TDF);
---Purpose: Loads src and tgt labels
UseFilter(me : in out; aFilter : IDFilter from TDF);
---Purpose: Sets filter
ExternalReferences(myclass; Lab : Label from TDF;
aExternals:in out AttributeMap from TDF;
aFilter : IDFilter from TDF)
returns Boolean from Standard;
---Purpose: Check external references and if exist fills the aExternals Map
ExternalReferences(myclass; aRefLab, Lab : Label from TDF;
aExternals : in out AttributeMap from TDF;
aFilter : IDFilter from TDF;
aDataSet : in out DataSet from TDF) ;
---Purpose: Check external references and if exist fills the aExternals Map
Perform(me:in out);
---Purpose: performs algorithm of selfcontained copy
IsDone(me)
returns Boolean from Standard;
---C++: inline
RelocationTable(me)
returns RelocationTable from TDF;
---Purpose: returns relocation table
---C++: return const&
fields
myRT : RelocationTable from TDF;
mySL : Label from TDF; -- source label
myTL : Label from TDF; -- target label
myFilter : IDFilter from TDF;
myMapOfExt : AttributeMap from TDF; -- map of attribute with external reference
myIsDone : Boolean from Standard;
end CopyLabel;

209
src/TDF/TDF_CopyLabel.cxx Executable file
View File

@@ -0,0 +1,209 @@
// File: TDF_CopyLabel.cxx
// Created: Thu Jun 24 14:23:46 1999
// Author: Sergey ZARITCHNY
// <szy@philipox.nnov.matra-dtv.fr>
#include <TDF_CopyLabel.ixx>
#include <TDF_Label.hxx>
#include <TDF_AttributeMap.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_IDFilter.hxx>
#include <TDF_DataSet.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_AttributeMap.hxx>
#include <TDF_MapIteratorOfAttributeMap.hxx>
#include <TDF_LabelMap.hxx>
#include <TDF_MapIteratorOfLabelMap.hxx>
#include <TDF_CopyTool.hxx>
#include <TDF_ClosureMode.hxx>
#include <TDF_ClosureTool.hxx>
#include <TDF_Tool.hxx>
#include <TDF_Data.hxx>
// The bug concerns the COPY operation of some attributes of a non-self-contained label.
// The attributes making the label non-self-contained are not involved by the operation.
// Therefore, these attributes shouldn't be considered by the COPY mechanism and
// the label should be considered as a self-contained.
// Correction of the bug consists of ignoring the attributes not involved by the COPY operation.
#define BUC60813
//=======================================================================
//function : TDF_CopyLabel
//purpose :
//=======================================================================
TDF_CopyLabel::TDF_CopyLabel()
:myFilter(Standard_False), myIsDone(Standard_False)
{
mySL.Nullify();
myTL.Nullify();
}
//=======================================================================
//function : TDF_CopyLabel
//purpose :
//=======================================================================
TDF_CopyLabel::TDF_CopyLabel(const TDF_Label& aSource,const TDF_Label& aTarget )
:myFilter(Standard_False), myIsDone(Standard_False)
{
mySL = aSource; myTL = aTarget;
}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
void TDF_CopyLabel::Load(const TDF_Label& aSource, const TDF_Label& aTarget)
{
mySL = aSource; myTL = aTarget;
}
//=======================================================================
//function : ExternalReferences
//purpose : internal
//=======================================================================
void TDF_CopyLabel::ExternalReferences(const TDF_Label& aRefLabel, const TDF_Label& aLabel,
TDF_AttributeMap& aExternals, const TDF_IDFilter& aFilter,
Handle(TDF_DataSet)& ds)
{
// TCollection_AsciiString entr1,entr2; //d
Standard_Boolean extRefFound = Standard_False;
for (TDF_AttributeIterator itr(aLabel); itr.More(); itr.Next()) {
itr.Value()->References(ds);
const TDF_AttributeMap& attMap = ds->Attributes(); //attMap
// TDF_Tool::Entry(itr.Value()->Label(), entr1); //d
// cout<<"\tSource Attribute dynamic type = "<<itr.Value()->DynamicType()<<" Label = "<<entr1 <<endl;
for (TDF_MapIteratorOfAttributeMap attMItr(attMap);attMItr.More(); attMItr.Next()) {
Handle(TDF_Attribute) att = attMItr.Key();
// TDF_Tool::Entry(att->Label(), entr1);
// cout<<"\t\tReferences attribute dynamic type = "<<att->DynamicType()<<" Label = "<<entr1 <<endl;
if (aFilter.IsKept(att) && att->Label().IsDifferent(aRefLabel) &&
!att->Label().IsDescendant(aRefLabel)) {
aExternals.Add(att);
extRefFound = Standard_True;
}
}
// const TDF_LabelMap& labMap = ds->Labels();
// for (TDF_MapIteratorOfLabelMap labMItr(labMap);labMItr.More(); labMItr.Next()) {
// TDF_Tool::Entry(labMItr.Key(), entr1);
// cout<<"\t\tLABELS from DS of Attr:: Lab = "<<entr1<<endl;
// if (!labMItr.Key().IsDescendant(aRefLabel) && labMItr.Key().IsDifferent(aRefLabel)) {
// // aExternals.Add(itr.Value()); // ??? LabelMap of Attribute has label which don't
// // belongs to source hierarchy. So, what we should do ?
// // Add this Attribute to the aExternals or add all attributes
// // from this label ?
// TCollection_AsciiString entr1, entr2;
// TDF_Tool::Entry(labMItr.Key(), entr1);
// TDF_Tool::Entry(aRefLabel, entr2);
// cout<<"\t\t\tNot descendant label:: Lab1 = "<<entr1<<" and RefLab = "<<entr2<<endl;
// }
// }
extRefFound = Standard_False;
ds->Clear();
}
}
//=======================================================================
//function : ExternalReferences
//purpose :
//=======================================================================
Standard_Boolean TDF_CopyLabel::ExternalReferences(const TDF_Label& L,
TDF_AttributeMap& aExternals,
const TDF_IDFilter& aFilter)
{
Handle(TDF_DataSet) ds = new TDF_DataSet();
ExternalReferences(L, L, aExternals, aFilter, ds);
for (TDF_ChildIterator itr(L, Standard_True);itr.More(); itr.Next()) {
ExternalReferences(L,itr.Value(),aExternals , aFilter, ds);
}
if(!aExternals.Extent())
return Standard_False;
else
return Standard_True;
}
//=======================================================================
#ifdef DEB
static void PrintEntry(const TDF_Label& label, const Standard_Boolean allLevels)
{
TCollection_AsciiString entry;
TDF_Tool::Entry(label, entry);
cout << "\tShareable attribute on the label = "<< entry << endl;
TDF_ChildIterator it (label, allLevels);
for (; it.More(); it.Next())
{
TDF_Tool::Entry(it.Value(), entry);
cout << "\tChildLabelEntry = "<< entry << endl;
}
}
#endif
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void TDF_CopyLabel::Perform()
{
myIsDone = Standard_False;
if(mySL.Data()->Root().IsDifferent(myTL.Data()->Root()) && //TDF_Data is not the same
#ifdef BUC60813
!TDF_Tool::IsSelfContained(mySL, myFilter)) return; //source label isn't self-contained
#else
!TDF_Tool::IsSelfContained(mySL)) return;
#endif
else {
#ifdef DEB
cout << "THE SAME Data" <<endl;
#endif
}
//TDF_Data of the source and target labels are the same
Standard_Boolean extReferers =
ExternalReferences(mySL, myMapOfExt, myFilter);
myRT = new TDF_RelocationTable(Standard_True);
Handle(TDF_DataSet) ds = new TDF_DataSet();
TDF_ClosureMode mode(Standard_True); // descendant plus reference
ds->AddLabel(mySL);
myRT->SetRelocation(mySL, myTL);
TDF_ClosureTool::Closure(ds, myFilter, mode);
if(extReferers) {
for (TDF_MapIteratorOfAttributeMap attMItr(myMapOfExt);attMItr.More(); attMItr.Next()) {
Handle(TDF_Attribute) att = attMItr.Key();
myRT->SetRelocation(att, att);
#ifdef DEB
PrintEntry(att->Label(), Standard_True);
#endif
}
}
TDF_CopyTool::Copy(ds,myRT);
myIsDone = Standard_True;
}
//=======================================================================
//function : RelocationTable
//purpose :
//=======================================================================
const Handle(TDF_RelocationTable)& TDF_CopyLabel::RelocationTable() const
{
return myRT;
}
//=======================================================================
//function : UseFilter
//purpose :
//=======================================================================
void TDF_CopyLabel::UseFilter(const TDF_IDFilter& aFilter)
{
myFilter = aFilter;
}

14
src/TDF/TDF_CopyLabel.lxx Executable file
View File

@@ -0,0 +1,14 @@
// File: TDF_CopyLabel.lxx
// Created: Tue Jun 29 16:16:18 1999
// Author: Sergey ZARITCHNY
// <szy@philipox.nnov.matra-dtv.fr>
//=======================================================================
//function : IsDone
//purpose :
//=======================================================================
inline Standard_Boolean TDF_CopyLabel::IsDone() const
{
return myIsDone;
}

135
src/TDF/TDF_CopyTool.cdl Executable file
View File

@@ -0,0 +1,135 @@
-- File: TDF_CopyTool.cdl
-- ----------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Mar 11 1997 Creation
class CopyTool from TDF
---Purpose: This class provides services to build, copy or
-- paste a set of information.
--
-- Copy methods:
-- -------------
--
-- * Copy(aSourceDataSet, aTargetLabel,
-- aRelocationTable) copies a source DataSet under
-- its target place (see below: IMPORTANT NOTICE 1).
--
-- * Copy(aSourceDataSet, anTargetLabel,
-- aRelocationTable, aFilter) does the same job as
-- the previous method. But <aFilter> gives a list of
-- IDs for which a target attribute prevails over a
-- source one. In this special case, the source
-- attribute will be copied only if there will be no
-- target attribute.
--
--
-- IMPORTANT NOTICE : Label pre-binding
-- ------------------
--
-- For it is possible to copy root labels in another
-- place in the same Data or in a different one with
-- other tags, it is necessary to inform the Copy
-- algorithm about the target place. To do so:
--
-- * first get or create new target root labels;
--
-- * then bind them with the source root labels using
-- the relocation table method:
-- SetRelocation(aSourceLabel, aTargetLabel);
--
-- * finally call Copy(...) with the relocation table
-- previously set. In this way, this method will take
-- these relocations in account.
uses
Boolean from Standard,
Label from TDF,
Attribute from TDF,
DataSet from TDF,
RelocationTable from TDF,
AttributeMap from TDF,
AttributeDataMap from TDF,
LabelDataMap from TDF,
LabelMap from TDF,
IDFilter from TDF,
ClosureMode from TDF
is
Copy(myclass;
aSourceDataSet : DataSet from TDF;
aRelocationTable : mutable RelocationTable from TDF);
---Purpose: Copy <aSourceDataSet> with using and updating
-- <aRelocationTable>. This method ignores target
-- attributes privilege over source ones.
Copy(myclass;
aSourceDataSet : DataSet from TDF;
aRelocationTable : mutable RelocationTable from TDF;
aPrivilegeFilter : IDFilter from TDF);
---Purpose: Copy <aSourceDataSet> using and updating
-- <aRelocationTable>. Use <aPrivilegeFilter> to give
-- a list of IDs for which the target attribute
-- prevails over the source one.
-- Copy method piloting self contained attitude.
-- ----------------------------------------------
Copy(myclass;
aSourceDataSet : DataSet from TDF;
aRelocationTable : mutable RelocationTable from TDF;
aPrivilegeFilter : IDFilter from TDF;
aRefFilter : IDFilter from TDF;
setSelfContained : Boolean from Standard);
---Purpose: Copy <aSourceDataSet> using and updating
-- <aRelocationTable>. Use <aPrivilegeFilter> to give
-- a list of IDs for which the target attribute
-- prevails over the source one. If
-- <setSelfContained> is set to true, every
-- TDF_Reference will be replaced by the referenced
-- structure according to <aRefFilter>.
--
-- NB: <aRefFilter> is used only if
-- <setSelfContained> is true.
-- ----------------------------------------------------------------------
--
-- Private methods
--
-- ----------------------------------------------------------------------
---Purpose: Internal root label copy recursive method.
CopyLabels(myclass;
aSLabel : Label from TDF;
aTargetLabel : in out Label from TDF;
aLabMap : in out LabelDataMap from TDF;
aAttMap : in out AttributeDataMap from TDF;
aSrcLabelMap : LabelMap from TDF;
aSrcAttributeMap : AttributeMap from TDF)
is private;
---Purpose: Internal root label copy recursive method.
CopyAttributes(myclass;
aSLabel : Label from TDF;
aTargetLabel : in out Label from TDF;
aAttMap : in out AttributeDataMap from TDF;
aSrcAttributeMap : AttributeMap from TDF)
is private;
---Purpose: Internal attribute copy method.
end CopyTool;

198
src/TDF/TDF_CopyTool.cxx Executable file
View File

@@ -0,0 +1,198 @@
// File: TDF_CopyTool.cxx
// ---------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Mar 11 1997 Creation
#include <TDF_CopyTool.ixx>
#include <TDF_ClosureTool.hxx>
#include <TDF_Attribute.hxx>
#include <TDF_AttributeDataMap.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_AttributeMap.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_DataMapIteratorOfAttributeDataMap.hxx>
#include <TDF_DataMapIteratorOfLabelDataMap.hxx>
#include <TDF_Label.hxx>
#include <TDF_LabelDataMap.hxx>
#include <TDF_LabelMap.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
#include <TDF_MapIteratorOfAttributeMap.hxx>
#include <TDF_MapIteratorOfLabelMap.hxx>
#include <Standard_TypeMismatch.hxx>
#define DeclareAndSpeedCast(V,T,Vdown) Handle(T) Vdown = *((Handle(T)*)& V)
#define DeclareConstAndSpeedCast(V,T,Vdown) const Handle(T)& Vdown = (Handle(T)&) V
#define SpeedCast(V,T,Vdown) Vdown = *((Handle(T)*)& V)
//=======================================================================
//function : Copy
//purpose :
//=======================================================================
void TDF_CopyTool::Copy
(const Handle(TDF_DataSet)& aSourceDataSet,
const Handle(TDF_RelocationTable)& aRelocationTable)
{
TDF_IDFilter privilegeFilter; // Ignore the target attribute's privilege!
TDF_IDFilter refFilter; // Will not be used.
TDF_CopyTool::Copy
(aSourceDataSet, aRelocationTable, privilegeFilter,
refFilter, Standard_False);
}
//=======================================================================
//function : Copy
//purpose :
//=======================================================================
void TDF_CopyTool::Copy
(const Handle(TDF_DataSet)& aSourceDataSet,
const Handle(TDF_RelocationTable)& aRelocationTable,
const TDF_IDFilter& aPrivilegeFilter)
{
TDF_IDFilter refFilter; // Will not be used.
TDF_CopyTool::Copy
(aSourceDataSet, aRelocationTable, aPrivilegeFilter,
refFilter, Standard_False);
}
//=======================================================================
//function : Copy
//purpose :
//=======================================================================
void TDF_CopyTool::Copy
(const Handle(TDF_DataSet)& aSourceDataSet,
const Handle(TDF_RelocationTable)& aRelocationTable,
const TDF_IDFilter& aPrivilegeFilter,
const TDF_IDFilter& /* aRefFilter */,
const Standard_Boolean /* setSelfContained */)
{
if (aSourceDataSet->IsEmpty()) return;
TDF_LabelMap& srcLabs = aSourceDataSet->Labels();
TDF_AttributeMap& srcAtts = aSourceDataSet->Attributes();
TDF_LabelList& rootLst = aSourceDataSet->Roots();
TDF_LabelDataMap& theLabMap = aRelocationTable->LabelTable();
TDF_AttributeDataMap& theAttMap = aRelocationTable->AttributeTable();
// Parallel exploration of the root label structures:
// * builds the target labels not found;
// * binds the source attributes with the target ones;
// * binds the source attributes with new target ones if there is none.
// Label pre-binding is tested before paste.
// For it is possible to copy the roots at another place with OTHER TAGS,
// we first ask <theLabMap> if each source root label is already bound.
for (TDF_ListIteratorOfLabelList labLItr(rootLst);
labLItr.More(); labLItr.Next()) {
const TDF_Label& sLab = labLItr.Value();
if (theLabMap.IsBound(sLab)) {
TDF_Label tIns(theLabMap.Find(sLab));
TDF_CopyTool::CopyLabels(sLab,tIns,
theLabMap,theAttMap,srcLabs,srcAtts);
}
// if not bound : do nothing!
}
// The relocation attribute table is now ready,
// except for the label unattached attributes,
// but everybody can update the relocation table...
// Now: the paste phasis!
TDF_DataMapIteratorOfAttributeDataMap attItr2(theAttMap);
for (;attItr2.More(); attItr2.Next()) {
const Handle(TDF_Attribute)& sAtt = attItr2.Key();
if (!sAtt.IsNull()) { // This condition looks superfluous; and below also.
const Handle(TDF_Attribute)& tAtt = attItr2.Value();
// 1 - No copy on itself.
// 2 - The target attribute is present BUT its privilege over the
// source one must be ignored. The source attribute can be copied.
if ((sAtt != tAtt) && aPrivilegeFilter.IsIgnored(tAtt->ID()))
sAtt->Paste(tAtt,aRelocationTable);
}
}
}
//=======================================================================
//function : CopyLabels
//purpose : Internal root label copy recursive method.
//=======================================================================
void TDF_CopyTool::CopyLabels
(const TDF_Label& aSLabel,
TDF_Label& aTargetLabel,
TDF_LabelDataMap& aLabMap,
TDF_AttributeDataMap& aAttMap,
const TDF_LabelMap& aSrcLabelMap,
const TDF_AttributeMap& aSrcAttributeMap)
{
TDF_CopyTool::CopyAttributes(aSLabel,aTargetLabel,
aAttMap,aSrcAttributeMap);
// Does the same for the children.
for (TDF_ChildIterator childItr(aSLabel); childItr.More(); childItr.Next()){
const TDF_Label& childSLab = childItr.Value();
if (aSrcLabelMap.Contains(childSLab)) {
TDF_Label childTIns = aTargetLabel.FindChild(childSLab.Tag());
aLabMap.Bind(childSLab,childTIns);
TDF_CopyTool::CopyLabels(childSLab,childTIns,
aLabMap,aAttMap,
aSrcLabelMap,aSrcAttributeMap);
}
}
}
//=======================================================================
//function : CopyAttributes
//purpose : Internal attribute copy method.
//=======================================================================
void TDF_CopyTool::CopyAttributes
(const TDF_Label& aSLabel,
TDF_Label& aTargetLabel,
TDF_AttributeDataMap& aAttMap,
const TDF_AttributeMap& aSrcAttributeMap)
{
Handle(TDF_Attribute) tAtt;
// Finds the target attributes or creates them empty.
for (TDF_AttributeIterator attItr(aSLabel);
attItr.More(); attItr.Next()) {
const Handle(TDF_Attribute) sAtt = attItr.Value();
if (aSrcAttributeMap.Contains(sAtt)) {
const Standard_GUID& id = sAtt->ID();
if (!aTargetLabel.FindAttribute(id,tAtt)) {
tAtt = sAtt->NewEmpty();
aTargetLabel.AddAttribute(tAtt);
aAttMap.Bind(sAtt,tAtt);
}
else {
// Some attributes have the same ID, but are different and
// exclusive. This obliged to test the dynamic type identity.
if (tAtt->IsInstance(sAtt->DynamicType()))
aAttMap.Bind(sAtt,tAtt);
else
Standard_TypeMismatch::Raise
("TDF_CopyTool: Cannot paste to a different type attribute.");
}
}
}
}

228
src/TDF/TDF_Data.cdl Executable file
View File

@@ -0,0 +1,228 @@
-- File: TDF_Data.cdl
-- ------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Feb 4 1997 Creation
class Data from TDF inherits TShared from MMgt
---Purpose: This class is used to manipulate a complete
-- independant, self sufficient data structure and
-- its services:
--
-- Access to the root label;
--
-- Opens, aborts, commits a transaction;
--
-- Generation and use of Delta, depending on the time.
-- This class uses a special allocator
-- (see LabelNodeAllocator() method)
-- for more efficient allocation of
-- objects in memory.
uses
Attribute from TDF,
Label from TDF,
LabelNodePtr from TDF,
Delta from TDF,
IDFilter from TDF,
StackOfInteger from TColStd,
HAllocator from TDF
raises
NoMoreObject from Standard
is
Create returns mutable Data from TDF;
---Purpose: A new and empty Data structure.
-- -----------------------------------------------------------------------
Root(me) returns Label from TDF;
---Purpose: Returns the root label of the Data structure.
--
---C++: inline
---C++: return const
-- -----------------------------------------------------------------------
-- Important notice: For a more secure use of Open/Commit/Abort
-- transactions, see class Transaction from TDF.
Transaction(me) returns Integer;
---Purpose: Returns the current transaction number.
OpenTransaction(me : mutable) returns Integer
is private;
---Purpose: Increments the transaction number and returns it.
CommitTransaction(me : mutable;
withDelta : Boolean from Standard = Standard_False)
returns Delta from TDF
raises NoMoreObject from Standard
is private;
---Purpose: Decrements the transaction number and commits the
-- modifications.
--
-- Raises if there is no current transaction.
--
-- Optionnal <withDelta> set to True indiquates a
-- Delta must be generated.
CommitUntilTransaction(me : mutable;
untilTransaction : Integer from Standard;
withDelta : Boolean from Standard = Standard_False)
returns Delta from TDF
is private;
---Purpose: Decrements the transaction number and commits the
-- modifications until AND including the transaction
-- <untilTransaction>.
AbortTransaction(me : mutable)
raises NoMoreObject from Standard
is private;
---Purpose: Decrements the transaction number and forgets the
-- modifications.
--
-- Raises if there is no current transaction.
AbortUntilTransaction(me : mutable;
untilTransaction : Integer from Standard)
is private;
---Purpose: Decrements the transaction number and forgets the
-- modifications until AND including the transaction
-- <untilTransaction>.
-- -----------------------------------------------------------------------
Time(me) returns Integer from Standard;
---Purpose: Returns the current tick. It is incremented each Commit.
--
---C++: inline
IsApplicable (me;
aDelta : Delta from TDF)
returns Boolean from Standard;
---Purpose: Returns true if <aDelta> is applicable HERE and NOW.
Undo(me : mutable;
aDelta : Delta from TDF;
withDelta : Boolean from Standard = Standard_False)
returns Delta from TDF;
---Purpose: Apply <aDelta> to undo a set of attribute
-- modifications.
--
-- Optionnal <withDelta> set to True indiquates a
-- Delta Set must be generated. (See above)
-- -----------------------------------------------------------------------
Destroy(me : mutable);
---C++: alias ~
-- Private internal use methods ------------------------------------------
CommitTransaction(me : mutable;
aLabel : Label from TDF;
aDelta : Delta from TDF;
withDelta : Boolean from Standard)
returns Integer from Standard
is private;
---Purpose: Decrements the transaction number and commits the
-- modifications. Used to implement the recursif
-- commit process. The returned boolean says how many
-- attributes (new, modified or deleted) has been
-- committed from the previous transaction into the
-- current one.
-- Miscelleaneous
-- --------------
NotUndoMode(me) returns Boolean from Standard;
---Purpose: Returns the undo mode status.
--
---C++: inline
Dump(me; anOS : in out OStream from Standard)
returns OStream from Standard;
---Purpose: Dumps the Data on <aStream>.
--
---C++: return &
---C++: alias operator<<
-- methods for check modifications outside the transaction -----------
AllowModification(me: mutable; isAllowed : Boolean from Standard );
---Purpose: Sets modification mode.
--
---C++: inline
IsModificationAllowed(me) returns Boolean from Standard;
---Purpose: returns modification mode.
--
---C++: inline
LabelNodeAllocator(me) returns HAllocator from TDF;
---Purpose: Returns TDF_HAllocator, which is an
-- incremental allocator used by
-- TDF_LabelNode.
-- This allocator is used to
-- manage TDF_LabelNode objects,
-- but it can also be used for
-- allocating memory to
-- application-specific data (be
-- careful because this
-- allocator does not release
-- the memory).
-- The benefits of this
-- allocation scheme are
-- noticeable when dealing with
-- large OCAF documents, due to:
-- 1. Very quick allocation of
-- objects (memory heap is not
-- used, the algorithm that
-- replaces it is very simple).
-- 2. Very quick destruction of
-- objects (memory is released not
-- by destructors of TDF_LabelNode,
-- but rather by the destructor of
-- TDF_Data).
-- 3. TDF_LabelNode objects do not
-- fragmentize the memory; they are
-- kept compactly in a number of
-- arrays of 16K each.
-- 4. Swapping is reduced on large
-- data, because each document now
-- occupies a smaller number of
-- memory pages.
---C++: inline
---C++: return const &
fields
myRoot : LabelNodePtr from TDF;
myTransaction : Integer from Standard;
myNbTouchedAtt : Integer from Standard;
myNotUndoMode : Boolean from Standard;
myTime : Integer from Standard;
myTimes : StackOfInteger from TColStd;
myLabelNodeAllocator: HAllocator from TDF;
myAllowModification : Boolean from Standard;
friends
class Transaction from TDF,
class LabelNode from TDF
end Data;

422
src/TDF/TDF_Data.cxx Executable file
View File

@@ -0,0 +1,422 @@
// File: TDF_Data.cxx
// -------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 6 1997 Creation
#include <TDF_Data.ixx>
#include <TCollection_AsciiString.hxx>
#include <TDF_Attribute.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_AttributeIndexedMap.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_Delta.hxx>
#include <TDF_AttributeDelta.hxx>
#include <TDF_DeltaOnAddition.hxx>
#include <TDF_DeltaOnForget.hxx>
#include <TDF_DeltaOnModification.hxx>
#include <TDF_DeltaOnRemoval.hxx>
#include <TDF_DeltaOnResume.hxx>
#include <TDF_Label.hxx>
#include <TDF_LabelNode.hxx>
#include <TDF_LabelNodePtr.hxx>
#include <TDF_Tool.hxx>
#include <Standard_NoMoreObject.hxx>
#include <Standard_NullObject.hxx>
#undef DEB_DELTA_CREATION
#undef TDF_DATA_COMMIT_OPTIMIZED
#define BUC60879
#ifdef DEB_DELTA
#define TDF_Data_DebugModified(ACTION) \
cout<<"After "<<ACTION<<" #"<<myTransaction+1<<", DF "<<this<<" had "<<myNbTouchedAtt<<" attribute(s) touched. Time = "<<myTime<<endl; \
if (!myTransaction) { \
TCollection_AsciiString entry; \
for (TDF_ChildIterator itr(Root(),Standard_True); itr.More(); itr.Next()) { \
const TDF_LabelNode* lnp = itr.Value().myLabelNode; \
if (lnp->AttributesModified() || lnp->MayBeModified()) { \
TDF_Tool::Entry(itr.Value(),entry); \
cout<<ACTION<<" on "<<entry<<" : flag(s) "; \
if (lnp->AttributesModified()) cout<<"AttributesModified "; \
if (lnp->MayBeModified()) cout<<"MayBeModified already set in transaction 0! Please contact TDF developer."; \
cout<<endl; \
cout<<itr.Value()<<endl; \
entry.Clear(); \
}}}
#else
#define TDF_Data_DebugModified(ACTION)
#endif
#ifdef DEB_DELTA_CREATION
#define TDF_DataDebugDeltaCreation(DELTATYPE) \
{ \
TCollection_AsciiString entry; \
TDF_Tool::Entry(currentAtt->Label(),entry); \
cout<<"Creation of a DeltaOn"<<DELTATYPE<<" \tat "<<entry<<" \ton "<<currentAtt->DynamicType()<<endl; \
}
#else
#define TDF_DataDebugDeltaCreation(DELTATYPE)
#endif
#define TDF_Data_DeltaCreation(DELTACOMMENT,DELTACREATION) \
if (withDelta) { \
TDF_DataDebugDeltaCreation(DELTACOMMENT); \
aDelta->AddAttributeDelta(DELTACREATION); \
}
#ifdef WNT
// Disable the warning: "operator new unmatched by delete"
#pragma warning (disable:4291)
#endif
//=======================================================================
//function : TDF_Data
//purpose : empty constructor
//=======================================================================
TDF_Data::TDF_Data() :
myTransaction (0),
myNbTouchedAtt (0),
myNotUndoMode (Standard_True),
myTime (0),
myAllowModification (Standard_True)
{
const Handle(NCollection_IncAllocator) anIncAllocator=
new NCollection_IncAllocator (16000);
myLabelNodeAllocator = anIncAllocator;
myRoot = new (anIncAllocator) TDF_LabelNode (this);
}
#ifdef WNT
#pragma warning (default:4291)
#endif
//=======================================================================
//function : Destroy
//purpose : Used to implement the destructor ~.
//=======================================================================
void TDF_Data::Destroy()
{
AbortUntilTransaction(1);
delete myRoot;
}
//=======================================================================
//function : OpenTransaction
//purpose :
//=======================================================================
Standard_Integer TDF_Data::OpenTransaction()
{
myTimes.Push(myTime);
return ++myTransaction;
}
//=======================================================================
//function : CommitTransaction
//purpose : Commits the current transaction.
//=======================================================================
Handle(TDF_Delta) TDF_Data::CommitTransaction
(const Standard_Boolean withDelta)
{
Handle(TDF_Delta) delta;
if (myTransaction>0) {
if (withDelta) delta = new TDF_Delta();
#ifdef DEB_DELTA
cout<<"TDF_Data::Begin Commit #"<<myTransaction<<endl;
#endif
#ifdef TDF_DATA_COMMIT_OPTIMIZED
myNbTouchedAtt = 0;
if (Root().myLabelNode->MayBeModified())
#endif
myNbTouchedAtt =
TDF_Data::CommitTransaction(Root(),delta,withDelta);
if (myNbTouchedAtt && !(withDelta && delta->IsEmpty())) ++myTime;
--myTransaction;
if (withDelta) {
if (!delta->IsEmpty()) {
delta->Validity(myTimes.Top(),myTime);
#ifdef DEB_DELTA
if (myTransaction == 0) {
cout<<"TDF_Data::Commit generated this delta in t=0:"<<endl;
delta->Dump(cout);
}
#endif
}
#ifdef DEB_DELTA
else {
if (myTransaction == 0)
cout<<"TDF_Data::Commit generated NO delta."<<endl;
}
#endif
}
myTimes.Pop();
}
TDF_Data_DebugModified("COMMIT");
return delta;
}
//=======================================================================
//function : CommitUntilTransaction
//purpose : Commits the transactions until AND including
// the given transaction index.
//=======================================================================
Handle(TDF_Delta) TDF_Data::CommitUntilTransaction
(const Standard_Integer untilTransaction,
const Standard_Boolean withDelta)
{
Handle(TDF_Delta) delta;
if ((untilTransaction>0) && (myTransaction >= untilTransaction)) {
while (myTransaction > untilTransaction) {
delta = TDF_Data::CommitTransaction(Standard_False);
}
delta = TDF_Data::CommitTransaction(withDelta);
}
return delta;
}
//=======================================================================
//function : CommitTransaction
//purpose : Recursive method used to implement the commit action.
//=======================================================================
Standard_Integer TDF_Data::CommitTransaction
(const TDF_Label& aLabel,
const Handle(TDF_Delta)& aDelta,
const Standard_Boolean withDelta)
{
aLabel.myLabelNode->MayBeModified(Standard_False);
Standard_Integer nbTouchedAtt = 0;
#ifdef TDF_DATA_COMMIT_OPTIMIZED
Standard_Boolean attMod = aLabel.myLabelNode->AttributesModified();
#else
Standard_Boolean attMod = Standard_True;
#endif
if (attMod) {
Handle(TDF_Attribute) lastAtt;
Handle(TDF_Attribute) backupAtt;
Standard_Boolean currentIsRemoved = Standard_False;
attMod = Standard_False;
TDF_AttributeIterator itr1(aLabel, Standard_False);
while (itr1.More()) {
TDF_Attribute * aPtrCurrentAtt = itr1.Value();
itr1.Next();
// currentAtt = itr1.Value();
#ifdef BUC60879
// A callback:
aPtrCurrentAtt->BeforeCommitTransaction();
#endif
backupAtt = aPtrCurrentAtt->myBackup;
if (aPtrCurrentAtt->myTransaction == myTransaction) {
++nbTouchedAtt;
--(aPtrCurrentAtt->myTransaction);
// ------------------------------------------------------- Forgotten
if (aPtrCurrentAtt->IsForgotten()) {
if (aPtrCurrentAtt->mySavedTransaction >=
aPtrCurrentAtt->myTransaction)
{
const Handle(TDF_Attribute) currentAtt = aPtrCurrentAtt;
// Collision with a not forgotten version.
if (backupAtt.IsNull()) {
TDF_Data_DeltaCreation
("Removal(1)",
currentAtt->DeltaOnRemoval());
if (myNotUndoMode) currentAtt->BeforeRemoval();
aLabel.myLabelNode->RemoveAttribute(lastAtt,currentAtt);
currentIsRemoved = Standard_True;
attMod = Standard_True;
}
else {
// Modified then Forgotten...
// Forgotten flag spreading?
currentAtt->Resume();
currentAtt->Restore(backupAtt);
currentAtt->myTransaction = backupAtt->myTransaction;
currentAtt->RemoveBackup();
backupAtt = currentAtt->myBackup;
if (myTransaction == 1) {
TDF_Data_DeltaCreation
("Removal(2)",
currentAtt->DeltaOnRemoval());
if (myNotUndoMode) currentAtt->BeforeRemoval();
aLabel.myLabelNode->RemoveAttribute(lastAtt,currentAtt);
currentIsRemoved = Standard_True;
}
else {
// BeforeForget has already been called once.
// if (myNotUndoMode) currentAtt->BeforeForget();
currentAtt->Forget(myTransaction-1);
TDF_Data_DeltaCreation
("Forget(1)",
currentAtt->DeltaOnForget());
attMod = Standard_True;
}
}
}
else {
// Forgotten in lower transaction than the current one.
TDF_Data_DeltaCreation
("Forget(2)",
aPtrCurrentAtt->DeltaOnForget());
}
}
// ---------------------------------------------------------- Resumed.
else if (aPtrCurrentAtt->mySavedTransaction < 0) {
TDF_Data_DeltaCreation
("Resume",
aPtrCurrentAtt->DeltaOnResume());
aPtrCurrentAtt->mySavedTransaction = 0;
attMod = attMod || (aPtrCurrentAtt->myTransaction > 0);
}
// ------------------------------------------------------------ Added.
else if (backupAtt.IsNull()) {
TDF_Data_DeltaCreation
("Addition",
aPtrCurrentAtt->DeltaOnAddition());
attMod = attMod || (aPtrCurrentAtt->myTransaction > 0);
}
// --------------------------------------------------------- Modified.
else {
TDF_Data_DeltaCreation
("Modification",
aPtrCurrentAtt->DeltaOnModification(backupAtt));
if (aPtrCurrentAtt->myTransaction == backupAtt->myTransaction)
aPtrCurrentAtt->RemoveBackup();
attMod = attMod || (aPtrCurrentAtt->myTransaction > 0);
}
}
else attMod = attMod || (aPtrCurrentAtt->myTransaction > 0);
if (currentIsRemoved) currentIsRemoved = Standard_False;
else lastAtt = aPtrCurrentAtt;
}
aLabel.myLabelNode->AttributesModified(attMod);
}
// Iteration on the children to do the same!
//------------------------------------------
for (TDF_ChildIterator itr2(aLabel); itr2.More(); itr2.Next()) {
#ifdef TDF_DATA_COMMIT_OPTIMIZED
if (itr2.Value().myLabelNode->MayBeModified())
#endif
nbTouchedAtt +=
TDF_Data::CommitTransaction(itr2.Value(),aDelta,withDelta);
}
return nbTouchedAtt;
}
//=======================================================================
//function : AbortTransaction
//purpose : Aborts the current transaction.
//=======================================================================
void TDF_Data::AbortTransaction()
{
if (myTransaction>0)
Undo(TDF_Data::CommitTransaction(Standard_True),Standard_False);
TDF_Data_DebugModified("New ABORT");
}
//=======================================================================
//function : AbortUntilTransaction
//purpose : Aborts the transactions until AND including the given index.
//=======================================================================
void TDF_Data::AbortUntilTransaction(const Standard_Integer untilTransaction)
{
if (untilTransaction>0)
Undo(TDF_Data::CommitUntilTransaction(untilTransaction,Standard_True),Standard_False);
}
//=======================================================================
//function : IsApplicable
//purpose :
//=======================================================================
Standard_Boolean TDF_Data::IsApplicable
(const Handle(TDF_Delta)& aDelta) const
{
return !aDelta.IsNull() && aDelta->IsApplicable(myTime);
}
//=======================================================================
//function : Undo
//purpose : Applies a delta to undo actions.
//=======================================================================
Handle(TDF_Delta) TDF_Data::Undo
(const Handle(TDF_Delta)& aDelta,
const Standard_Boolean withDelta)
{
Handle(TDF_Delta) newDelta;
if (!aDelta.IsNull ()) {
if (aDelta->IsApplicable(myTime)) {
if (withDelta) OpenTransaction();
#ifdef DEB_DELTA
cout<<"TDF_Data::Undo applies this delta:"<<endl;
aDelta->Dump(cout);
#endif
aDelta->BeforeOrAfterApply(Standard_True);
myNotUndoMode = Standard_False;
aDelta->Apply ();
myNotUndoMode = Standard_True;
if (withDelta) {
newDelta = CommitTransaction(Standard_True);
newDelta->Validity(aDelta->EndTime(),aDelta->BeginTime());
#ifdef DEB_DELTA
cout<<"TDF_Data::Undo, after validity correction, Delta is now available from time \t#"<<newDelta->BeginTime()<<" to time \t#"<<newDelta->EndTime()<<endl;
#endif
}
myTime = aDelta->BeginTime();
aDelta->BeforeOrAfterApply(Standard_False);
}
}
return newDelta;
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
Standard_OStream& TDF_Data::Dump(Standard_OStream& anOS) const
{
anOS<<"Dump of a TDF_Data."<<endl;
anOS<<"Current transaction: "<<myTransaction;
anOS<<"; Current tick: "<<myTime<<";"<<endl;
return anOS;
}

41
src/TDF/TDF_Data.lxx Executable file
View File

@@ -0,0 +1,41 @@
// File: TDF_Data.lxx
// -------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 6 1997 Creation
inline Standard_Integer TDF_Data::Transaction() const
{ return myTransaction; }
inline const TDF_Label TDF_Data::Root() const
{ return TDF_Label(myRoot); }
inline Standard_Integer TDF_Data::Time() const
{ return myTime; }
inline Standard_Boolean TDF_Data::NotUndoMode() const
{ return myNotUndoMode; }
inline Standard_OStream& operator << (Standard_OStream& anOS, const Handle(TDF_Data)& aDF)
{ return aDF->Dump(anOS); }
inline void TDF_Data::AllowModification
(const Standard_Boolean theAllowModification)
{
myAllowModification = theAllowModification;
}
inline Standard_Boolean TDF_Data::IsModificationAllowed() const
{
return myAllowModification;
}
inline const Handle(NCollection_BaseAllocator)&
TDF_Data::LabelNodeAllocator() const
{ return myLabelNodeAllocator; }

114
src/TDF/TDF_DataSet.cdl Executable file
View File

@@ -0,0 +1,114 @@
-- File: TDF_DataSet.cdl
-- ---------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Mar 11 1997 Creation
class DataSet from TDF
inherits TShared from MMgt
---Purpose: This class is a set of TDF informations like
-- labels and attributes.
uses
OStream from Standard,
Label from TDF,
Attribute from TDF,
LabelList from TDF,
LabelMap from TDF,
AttributeMap from TDF
-- raises
is
Create
returns mutable DataSet from TDF;
---Purpose: Creates an empty DataSet object.
Clear(me : mutable);
---Purpose: Clears all information.
IsEmpty(me) returns Boolean from Standard;
---Purpose: Returns true if there is at least one label or one
-- attribute.
---C++: inline
-- Label set informations
AddLabel(me : mutable;
aLabel : Label from TDF);
---Purpose: Adds <aLabel> in the current data set.
---C++: inline
ContainsLabel(me; aLabel : Label from TDF)
returns Boolean from Standard;
---Purpose: Returns true if the label <alabel> is in the data set.
---C++: inline
Labels(me : mutable)
returns LabelMap from TDF;
---Purpose: Returns the map of labels in this data set.
-- This map can be used directly, or updated.
--
---C++: inline
---C++: return &
-- Attribute set informations
AddAttribute(me : mutable;
anAttribute : Attribute from TDF);
---Purpose: Adds <anAttribute> into the current data set.
---C++: inline
ContainsAttribute(me; anAttribute : Attribute from TDF)
returns Boolean from Standard;
---Purpose: Returns true if <anAttribute> is in the data set.
---C++: inline
Attributes(me : mutable)
returns AttributeMap from TDF;
---Purpose: Returns the map of attributes in the current data set.
-- This map can be used directly, or updated.
--
---C++: inline
---C++: return &
-- Root informations
AddRoot(me : mutable; aLabel : Label from TDF);
---Purpose: Adds a root label to <myRootLabels>.
--
---C++: inline
Roots(me : mutable)
returns LabelList from TDF;
---Purpose: Returns <myRootLabels> to be used or updated.
--
---C++: inline
---C++: return &
-- Miscellaneous
Dump(me; anOS : in out OStream from Standard)
returns OStream from Standard;
---Purpose: Dumps the minimum information about <me> on
-- <aStream>.
--
---C++: return &
---C++: alias operator<<
fields
myRootLabels : LabelList from TDF;
myLabelMap : LabelMap from TDF;
myAttributeMap : AttributeMap from TDF;
end DataSet;

72
src/TDF/TDF_DataSet.cxx Executable file
View File

@@ -0,0 +1,72 @@
// File: TDF_DataSet.cxx
// ---------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Mar 11 1997 Creation
#include <TDF_DataSet.ixx>
#include <TDF_MapIteratorOfAttributeMap.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
#include <TDF_MapIteratorOfLabelMap.hxx>
//=======================================================================
//function : TDF_DataSet
//purpose : Creates a DataSet.
//=======================================================================
TDF_DataSet::TDF_DataSet()
{}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void TDF_DataSet::Clear()
{
myRootLabels.Clear();
myLabelMap.Clear();
myAttributeMap.Clear();
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
Standard_OStream& TDF_DataSet::Dump(Standard_OStream& anOS) const
{
anOS<<"\t\t=====< TDF_DataSet dump >====="<<endl;
anOS<<"Root Labels :"<<endl<<"============="<<endl;
for (TDF_ListIteratorOfLabelList itr1(myRootLabels);
itr1.More(); itr1.Next()) {
itr1.Value().EntryDump(anOS);
anOS<<" | ";
}
anOS<<endl<<"Labels :"<<endl<<"========"<<endl;
for (TDF_MapIteratorOfLabelMap itr2(myLabelMap);
itr2.More(); itr2.Next()) {
itr2.Key().EntryDump(anOS);
anOS<<" | ";
}
anOS<<endl<<"Attributes :"<<endl<<"============"<<endl<<endl;
for (TDF_MapIteratorOfAttributeMap itr3(myAttributeMap);
itr3.More(); itr3.Next()) {
itr3.Key()->Label().EntryDump(anOS);
anOS<<" \t";
itr3.Key()->Dump(anOS);
anOS<<endl;
}
anOS<<endl;
return anOS;
}

51
src/TDF/TDF_DataSet.lxx Executable file
View File

@@ -0,0 +1,51 @@
// File: TDF_DataSet.lxx
// ---------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Mar 11 1997 Creation
#include <TDF_Label.hxx>
#include <TDF_Attribute.hxx>
// IsEmpty
//=========
inline Standard_Boolean TDF_DataSet::IsEmpty() const
{ return (myLabelMap.IsEmpty() && myAttributeMap.IsEmpty()); }
// Labels
//========
inline void TDF_DataSet::AddLabel(const TDF_Label& aLabel)
{ if (!aLabel.IsNull()) myLabelMap.Add(aLabel); }
inline Standard_Boolean TDF_DataSet::ContainsLabel
(const TDF_Label& aLabel) const
{ return myLabelMap.Contains(aLabel); }
inline TDF_LabelMap& TDF_DataSet::Labels()
{ return myLabelMap; }
// Attributes
//============
inline void TDF_DataSet::AddAttribute(const Handle(TDF_Attribute)& anAttribute)
{ if (!anAttribute.IsNull()) myAttributeMap.Add(anAttribute); }
inline Standard_Boolean TDF_DataSet::ContainsAttribute
(const Handle(TDF_Attribute)& anAttribute) const
{ return myAttributeMap.Contains(anAttribute); }
inline TDF_AttributeMap& TDF_DataSet::Attributes()
{ return myAttributeMap; }
// Root labels
//=============
inline void TDF_DataSet::AddRoot(const TDF_Label& aLabel)
{ if (ContainsLabel(aLabel)) myRootLabels.Append(aLabel); }
inline TDF_LabelList& TDF_DataSet::Roots()
{ return myRootLabels; }

View File

@@ -0,0 +1,35 @@
-- File: TDF_DefaultDeltaOnModification.cdl
-- ----------------------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Oct 10 1997 Creation
class DefaultDeltaOnModification from TDF
inherits DeltaOnModification from TDF
---Purpose: This class provides a default implementation of a
-- TDF_DeltaOnModification.
uses
Label from TDF,
Attribute from TDF
-- raises
is
Create(anAttribute : Attribute from TDF);
---Purpose: Creates a TDF_DefaultDeltaOnModification.
-- <anAttribute> must be the backup copy.
Apply (me : mutable)
is redefined virtual;
---Purpose: Applies the delta to the attribute.
end DefaultDeltaOnModification;

View File

@@ -0,0 +1,42 @@
// File: TDF_DefaultDeltaOnModification.cxx
// ----------------------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Oct 10 1997 Creation
#include <TDF_DefaultDeltaOnModification.ixx>
#include <TDF_Label.hxx>
#include <Standard_GUID.hxx>
//=======================================================================
//function : TDF_DefaultDeltaOnModification
//purpose :
//=======================================================================
TDF_DefaultDeltaOnModification::TDF_DefaultDeltaOnModification
(const Handle(TDF_Attribute)& anAttribute)
: TDF_DeltaOnModification(anAttribute)
{}
//=======================================================================
//function : Apply
//purpose :
//=======================================================================
void TDF_DefaultDeltaOnModification::Apply()
{
const Handle(TDF_Attribute)& savAtt = Attribute();
Handle(TDF_Attribute) refAtt;
if (Label().FindAttribute(savAtt->ID(),refAtt))
refAtt->DeltaOnModification(this);
}

View File

@@ -0,0 +1,34 @@
-- File: TDF_DefaultDeltaOnRemoval.cdl
-- -----------------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Oct 10 1997 Creation
class DefaultDeltaOnRemoval from TDF
inherits DeltaOnRemoval from TDF
---Purpose: This class provides a default implementation of a
-- TDF_DeltaOnRemoval.
uses
Label from TDF,
Attribute from TDF
-- raises
is
Create(anAttribute : Attribute from TDF);
---Purpose: Creates a TDF_DefaultDeltaOnRemoval.
Apply (me : mutable)
is redefined virtual;
---Purpose: Applies the delta to the attribute.
end DefaultDeltaOnRemoval;

View File

@@ -0,0 +1,36 @@
// File: TDF_DefaultDeltaOnRemoval.cxx
// -----------------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Oct 10 1997 Creation
#include <TDF_DefaultDeltaOnRemoval.ixx>
#include <TDF_Label.hxx>
//=======================================================================
//function : TDF_DefaultDeltaOnRemoval
//purpose :
//=======================================================================
TDF_DefaultDeltaOnRemoval::TDF_DefaultDeltaOnRemoval
(const Handle(TDF_Attribute)& anAttribute)
: TDF_DeltaOnRemoval(anAttribute)
{}
//=======================================================================
//function : Apply
//purpose :
//=======================================================================
void TDF_DefaultDeltaOnRemoval::Apply()
{
Label().AddAttribute(Attribute());
}

107
src/TDF/TDF_Delta.cdl Executable file
View File

@@ -0,0 +1,107 @@
-- File: TDF_Delta.cdl
-- -------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Sep 8 1997 Creation
class Delta from TDF inherits TShared from MMgt
---Purpose: A delta set is available at <aSourceTime>. If
-- applied, it restores the TDF_Data in the state it
-- was at <aTargetTime>.
uses
OStream from Standard,
ExtendedString from TCollection,
LabelList from TDF,
AttributeDelta from TDF,
AttributeDeltaList from TDF
raises
OutOfRange from Standard
is
Create;
---Purpose: Creates a delta.
Validity(me : mutable;
aBeginTime : Integer from Standard;
anEndTime : Integer from Standard)
is protected;
---Purpose: Validates <me> at <aBeginTime>. If applied, it
-- restores the TDF_Data in the state it was at
-- <anEndTime>. Reserved to TDF_Data.
AddAttributeDelta (me : mutable;
anAttributeDelta : AttributeDelta from TDF)
is protected;
---Purpose: Adds an AttributeDelta to the list. Reserved to
-- TDF_Data.
IsEmpty (me) returns Boolean from Standard;
---Purpose: Returns true if there is nothing to undo.
--
---C++: inline
BeforeOrAfterApply(me; before : Boolean from Standard) is private;
Apply (me : mutable) is private;
IsApplicable (me; aCurrentTime : Integer from Standard)
returns Boolean from Standard;
---Purpose: Returns true if the Undo action of <me> is
-- applicable at <aCurrentTime>.
--
---C++: inline
BeginTime (me) returns Integer;
---Purpose: Returns the field <myBeginTime>.
---C++: inline
EndTime (me) returns Integer;
---Purpose: Returns the field <myEndTime>.
---C++: inline
Labels(me; aLabelList : in out LabelList from TDF);
---Purpose: Adds in <aLabelList> the labels of the attribute deltas.
-- Caution: <aLabelList> is not cleared before use.
AttributeDeltas (me) returns AttributeDeltaList from TDF;
---Purpose: Returns the field <myAttDeltaList>.
---C++: inline
---C++: return const &
Name(me) returns ExtendedString from TCollection;
---Purpose: Returns a name associated with this delta.
---C++: inline
SetName(me : mutable; theName : ExtendedString from TCollection);
---Purpose: Associates a name <theName> with this delta
---C++: inline
Dump(me; OS : in out OStream from Standard);
fields
myBeginTime : Integer from Standard;
myEndTime : Integer from Standard;
myAttDeltaList : AttributeDeltaList from TDF;
myName : ExtendedString from TCollection;
friends
class Data from TDF
end Delta;

210
src/TDF/TDF_Delta.cxx Executable file
View File

@@ -0,0 +1,210 @@
// File: TDF_Delta.cxx
// -------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Sep 8 1997 Creation
#include <TDF_Delta.ixx>
#include <TDF_LabelMap.hxx>
#include <TDF_ListIteratorOfAttributeDeltaList.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
#include <TDF_MapIteratorOfLabelMap.hxx>
#ifdef DEB
#include <Standard_ConstructionError.hxx>
#endif
#undef DEB_DELTA
//=======================================================================
//function : TDF_Delta
//purpose :
//=======================================================================
TDF_Delta::TDF_Delta()
: myBeginTime(0),
myEndTime(0)
{}
//=======================================================================
//function : Validity
//purpose :
//=======================================================================
void TDF_Delta::Validity
(const Standard_Integer aBeginTime,
const Standard_Integer anEndTime)
{
myBeginTime = aBeginTime;
myEndTime = anEndTime;
}
//=======================================================================
//function : AddAttributeDelta
//purpose :
//=======================================================================
void TDF_Delta::AddAttributeDelta
(const Handle(TDF_AttributeDelta)& anAttributeDelta)
{ if (!anAttributeDelta.IsNull()) myAttDeltaList.Append(anAttributeDelta); }
//=======================================================================
//function : BeforeOrAfterApply
//purpose :
//=======================================================================
void TDF_Delta::BeforeOrAfterApply(const Standard_Boolean before) const
{
TDF_AttributeDeltaList ADlist;
// for (TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList);
TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList) ;
for ( ; itr.More(); itr.Next()) ADlist.Append(itr.Value());
Handle(TDF_AttributeDelta) attDelta;
Handle(TDF_Attribute) att;
Standard_Boolean noDeadLock = Standard_True;
Standard_Integer nbAD = ADlist.Extent();
Standard_Boolean next;
while (noDeadLock && (nbAD != 0)) {
itr.Initialize(ADlist);
while (itr.More()) {
next = Standard_True;
attDelta = itr.Value();
att = attDelta->Attribute();
if (before)
next = !att->BeforeUndo(attDelta);
else
next = !att->AfterUndo(attDelta);
if (next)
itr.Next();
else
ADlist.Remove(itr);
}
noDeadLock = (nbAD > ADlist.Extent());
nbAD = ADlist.Extent();
}
if (!noDeadLock) {
#ifdef DEB
if (before) cout<<"Before"; else cout<<"After";
cout<<"Undo(): dead lock between these attributes:"<<endl;
for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
cout<<"AttributeDelta type = "<<itr.Value()->DynamicType()->Name();
cout<<" Attribute type = "<<itr.Value()->Attribute()->DynamicType()->Name()<<endl;;
if (before)
Standard_ConstructionError::Raise("BeforeUndo(): dead lock.");
else
Standard_ConstructionError::Raise("AfterUndo(): dead lock.");
}
#endif
for (itr.Initialize(ADlist); itr.More(); itr.Next()) {
attDelta = itr.Value();
att = attDelta->Attribute();
if (before)
att->BeforeUndo(attDelta,Standard_True);
else
att->AfterUndo(attDelta,Standard_True);
}
}
}
//=======================================================================
//function : Apply
//purpose :
//=======================================================================
void TDF_Delta::Apply()
{
TDF_ListIteratorOfAttributeDeltaList itr;
for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
attDelta->Apply();
}
}
//=======================================================================
//function : Labels
//purpose :
//=======================================================================
void TDF_Delta::Labels(TDF_LabelList& aLabelList) const
{
Standard_Boolean inList;
TDF_LabelMap labMap;
// If <aLabelList> is not empty...
#ifdef DEB_DELTA
if (aLabelList.Extent() > 0) cout<<"Previously added as modified label(s) ";
#endif
for (TDF_ListIteratorOfLabelList it1(aLabelList);
it1.More(); it1.Next()) {
const TDF_Label& lab1 = it1.Value();
inList = labMap.Add(lab1);
#ifdef DEB_DELTA
if (!inList) {
lab1.EntryDump(cout);cout<<" | ";
}
#endif
}
#ifdef DEB_DELTA
cout<<endl;
#endif
// New labels to add.
#ifdef DEB_DELTA
if (myAttDeltaList.Extent() > 0) cout<<"New added as modified label(s) ";
#endif
for (TDF_ListIteratorOfAttributeDeltaList it2(myAttDeltaList);
it2.More();
it2.Next()) {
const TDF_Label& lab1 = it2.Value()->Label();
inList = labMap.Add(lab1);
#ifdef DEB_DELTA
if (!inList) {
lab1.EntryDump(cout);cout<<" | ";
}
#endif
}
#ifdef DEB_DELTA
cout<<endl;
#endif
// Now put labels into <aLabelList>.
aLabelList.Clear();
for (TDF_MapIteratorOfLabelMap it3(labMap);
it3.More(); it3.Next()) {
aLabelList.Append(it3.Key());
}
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void TDF_Delta::Dump(Standard_OStream& OS) const
{
OS<<"DELTA available from time \t#"<<myBeginTime<<" to time \t#"<<myEndTime<<endl;
Standard_Integer n = 0;
// for (TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList);
TDF_ListIteratorOfAttributeDeltaList itr(myAttDeltaList) ;
for ( ; itr.More(); itr.Next()) ++n;
OS<<"Nb Attribute Delta(s): "<<n<<endl;
for (itr.Initialize(myAttDeltaList); itr.More(); itr.Next()) {
const Handle(TDF_AttributeDelta)& attDelta = itr.Value();
OS<<"| "; attDelta->Dump(OS); OS<<endl;
}
}

32
src/TDF/TDF_Delta.lxx Executable file
View File

@@ -0,0 +1,32 @@
// File: TDF_Delta.lxx
// -------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Sep 8 1997 Creation
inline Standard_Boolean TDF_Delta::IsEmpty() const
{ return myAttDeltaList.IsEmpty(); }
inline Standard_Boolean TDF_Delta::IsApplicable
(const Standard_Integer aCurrentTime) const
{ return (myEndTime == aCurrentTime); }
inline Standard_Integer TDF_Delta::BeginTime () const
{ return myBeginTime; }
inline Standard_Integer TDF_Delta::EndTime () const
{ return myEndTime; }
inline const TDF_AttributeDeltaList& TDF_Delta::AttributeDeltas () const
{ return myAttDeltaList; }
inline void TDF_Delta::SetName (const TCollection_ExtendedString& theName)
{ myName = theName; }
inline TCollection_ExtendedString TDF_Delta::Name () const
{ return myName; }

36
src/TDF/TDF_DeltaOnAddition.cdl Executable file
View File

@@ -0,0 +1,36 @@
-- File: TDF_DeltaOnAddition.cdl
-- -----------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Oct 10 1997 Creation
class DeltaOnAddition from TDF inherits AttributeDelta from TDF
---Purpose: This class provides default services for an
-- AttributeDelta on an ADDITION action.
--
-- Applying this AttributeDelta means REMOVING its
-- attribute.
uses
Attribute from TDF
-- raises
is
Create(anAtt : Attribute from TDF)
returns mutable DeltaOnAddition from TDF;
---Purpose: Creates a TDF_DeltaOnAddition.
Apply (me : mutable)
is redefined static;
---Purpose: Applies the delta to the attribute.
end DeltaOnAddition;

41
src/TDF/TDF_DeltaOnAddition.cxx Executable file
View File

@@ -0,0 +1,41 @@
// File: TDF_DeltaOnAddition.cxx
// -----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Oct 10 1997 Creation
#include <TDF_DeltaOnAddition.ixx>
#include <Standard_GUID.hxx>
#include <TDF_Label.hxx>
//=======================================================================
//function : TDF_DeltaOnAddition
//purpose :
//=======================================================================
TDF_DeltaOnAddition::TDF_DeltaOnAddition
(const Handle(TDF_Attribute)& anAtt)
: TDF_AttributeDelta(anAtt)
{}
//=======================================================================
//function : Apply
//purpose :
//=======================================================================
void TDF_DeltaOnAddition::Apply()
{
Handle(TDF_Attribute) currentAtt;
if (Label().FindAttribute(ID(),currentAtt)) {
Label().ForgetAttribute (currentAtt);
}
}

34
src/TDF/TDF_DeltaOnForget.cdl Executable file
View File

@@ -0,0 +1,34 @@
-- File: TDF_DeltaOnForget.cdl
-- ---------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Nov 3 1997 Creation
-- 1.0 Jul 6 1998 Separation Forget/Resume
class DeltaOnForget from TDF inherits AttributeDelta from TDF
---Purpose: This class provides default services for an
-- AttributeDelta on an Forget action.
--
-- Applying this AttributeDelta means RESUMING its
-- attribute.
uses
Attribute from TDF
is
Create(anAtt : Attribute from TDF)
returns mutable DeltaOnForget from TDF;
---Purpose: Creates a TDF_DeltaOnForget.
Apply (me : mutable)
is redefined static;
---Purpose: Applies the delta to the attribute.
end DeltaOnForget;

41
src/TDF/TDF_DeltaOnForget.cxx Executable file
View File

@@ -0,0 +1,41 @@
// File: TDF_DeltaOnForget.cxx
// ---------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Nov 3 1997 Creation
#include <TDF_DeltaOnForget.ixx>
#include <TDF_Label.hxx>
//=======================================================================
//function : TDF_DeltaOnForget
//purpose :
//=======================================================================
TDF_DeltaOnForget::TDF_DeltaOnForget
(const Handle(TDF_Attribute)& anAtt)
: TDF_AttributeDelta(anAtt)
{}
//=======================================================================
//function : Apply
//purpose :
//=======================================================================
void TDF_DeltaOnForget::Apply()
{
// Undo = Resume.
Label().ResumeAttribute(Attribute());
Attribute()->mySavedTransaction = 0;
#ifdef DEB
cout<<"Resume attribute"<<endl;
#endif
}

View File

@@ -0,0 +1,37 @@
-- File: TDF_DeltaOnModification.cdl
-- ---------------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Oct 10 1997 Creation
deferred class DeltaOnModification from TDF
inherits AttributeDelta from TDF
---Purpose: This class provides default services for an
-- AttributeDelta on a MODIFICATION action.
--
-- Applying this AttributeDelta means GOING BACK to
-- the attribute previously registered state.
uses
Attribute from TDF
-- raises
is
Initialize(anAttribute: Attribute from TDF)
returns mutable DeltaOnModification from TDF;
---Purpose: Initializes a TDF_DeltaOnModification.
Apply (me : mutable)
is redefined virtual;
---Purpose: Applies the delta to the attribute.
end DeltaOnModification;

View File

@@ -0,0 +1,33 @@
// File: TDF_DeltaOnModification.cxx
// ---------------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Oct 10 1997 Creation
#include <TDF_DeltaOnModification.ixx>
//=======================================================================
//function : TDF_DeltaOnModification
//purpose :
//=======================================================================
TDF_DeltaOnModification::TDF_DeltaOnModification
(const Handle(TDF_Attribute)& anAttribute)
: TDF_AttributeDelta(anAttribute)
{}
//=======================================================================
//function : Apply
//purpose :
//=======================================================================
void TDF_DeltaOnModification::Apply()
{ Attribute()->DeltaOnModification(this); }

32
src/TDF/TDF_DeltaOnRemoval.cdl Executable file
View File

@@ -0,0 +1,32 @@
-- File: TDF_RemovalDelta.cdl
-- --------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Oct 10 1997 Creation
deferred class DeltaOnRemoval from TDF
inherits AttributeDelta from TDF
---Purpose: This class provides default services for an
-- AttributeDelta on a REMOVAL action.
--
-- Applying this AttributeDelta means ADDING its
-- attribute.
uses
Attribute from TDF
-- raises
is
Initialize(anAtt : Attribute from TDF);
---Purpose: Initializes a TDF_DeltaOnRemoval.
end DeltaOnRemoval;

23
src/TDF/TDF_DeltaOnRemoval.cxx Executable file
View File

@@ -0,0 +1,23 @@
// File: TDF_DeltaOnRemoval.cxx
// ----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Oct 10 1997 Creation
#include <TDF_DeltaOnRemoval.ixx>
//=======================================================================
//function : TDF_DeltaOnRemoval
//purpose :
//=======================================================================
TDF_DeltaOnRemoval::TDF_DeltaOnRemoval(const Handle(TDF_Attribute)& anAtt)
: TDF_AttributeDelta(anAtt)
{}

34
src/TDF/TDF_DeltaOnResume.cdl Executable file
View File

@@ -0,0 +1,34 @@
-- File: TDF_DeltaOnResume.cdl
-- ---------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1998
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Jul 6 1998 Creation
-- 1.0 Jul 6 1998 Separation Forget/Resume
class DeltaOnResume from TDF inherits AttributeDelta from TDF
---Purpose: This class provides default services for an
-- AttributeDelta on an Resume action.
--
-- Applying this AttributeDelta means FORGETTING its
-- attribute.
uses
Attribute from TDF
is
Create(anAtt : Attribute from TDF)
returns mutable DeltaOnResume from TDF;
---Purpose: Creates a TDF_DeltaOnResume.
Apply (me : mutable)
is redefined static;
---Purpose: Applies the delta to the attribute.
end DeltaOnResume;

40
src/TDF/TDF_DeltaOnResume.cxx Executable file
View File

@@ -0,0 +1,40 @@
// File: TDF_DeltaOnResume.cxx
// ---------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1998
// Version: 0.0
// History: Version Date Purpose
// 0.0 Jul 6 1998 Creation
#include <TDF_DeltaOnResume.ixx>
#include <TDF_Label.hxx>
//=======================================================================
//function : TDF_DeltaOnResume
//purpose :
//=======================================================================
TDF_DeltaOnResume::TDF_DeltaOnResume
(const Handle(TDF_Attribute)& anAtt)
: TDF_AttributeDelta(anAtt)
{}
//=======================================================================
//function : Apply
//purpose :
//=======================================================================
void TDF_DeltaOnResume::Apply()
{
// Undo = Forget.
Label().ForgetAttribute (Attribute());
#ifdef DEB
cout<<"Forget attribute"<<endl;
#endif
}

14
src/TDF/TDF_HAllocator.hxx Executable file
View File

@@ -0,0 +1,14 @@
// File: TDF_HAllocator.hxx
// Created: 16.06.03 15:10:12
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2002
#ifndef TDF_HAllocator_HeaderFile
#define TDF_HAllocator_HeaderFile
#include <NCollection_BaseAllocator.hxx>
typedef Handle_NCollection_BaseAllocator TDF_HAllocator;
#endif

129
src/TDF/TDF_IDFilter.cdl Executable file
View File

@@ -0,0 +1,129 @@
-- File: TDF_IDFilter.cdl
-- ----------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 May 26 1997 Creation
class IDFilter from TDF
---Purpose: This class offers filtering services around an ID list.
uses
GUID from Standard,
IDList from TDF,
IDMap from TDF,
Attribute from TDF
-- raises
is
Create(ignoreMode : Boolean from Standard = Standard_True)
returns IDFilter from TDF;
---Purpose: Creates an ID/attribute filter based on an ID
-- list. The default mode is "ignore all but...".
--
-- This filter has 2 working mode: keep and ignore.
--
-- Ignore/Exclusive mode: all IDs are ignored except
-- these set to be kept, using Keep(). Of course, it
-- is possible set an kept ID to be ignored using
-- Ignore().
--
-- Keep/Inclusive mode: all IDs are kept except these
-- set to be ignored, using Ignore(). Of course, it
-- is possible set an ignored ID to be kept using
-- Keep().
Create(aFilter : IDFilter from TDF)
returns IDFilter from TDF
is private;
---Purpose: Private, to forbid implicit or hidden accesses to
-- the copy constructor.
-- Mode methods.
IgnoreAll(me : in out; ignore : Boolean from Standard);
---Purpose: The list of ID is cleared and the filter mode is
-- set to ignore mode if <keep> is true; false
-- otherwise.
IgnoreAll(me) returns Boolean from Standard;
---Purpose: Returns true is the mode is set to "ignore all
-- but...".
--
---C++: inline
-- Keep/Ignore methods.
Keep(me : in out; anID : GUID from Standard);
---Purpose: An attribute with <anID> as ID is to be kept and
-- the filter will answer true to the question
-- IsKept(<anID>).
Keep(me : in out; anIDList : IDList from TDF);
---Purpose: Attributes with ID owned by <anIDList> are to be kept and
-- the filter will answer true to the question
-- IsKept(<anID>) with ID from <anIDList>.
Ignore(me : in out; anID : GUID from Standard);
---Purpose: An attribute with <anID> as ID is to be ignored and
-- the filter will answer false to the question
-- IsKept(<anID>).
Ignore(me : in out; anIDList : IDList from TDF);
---Purpose: Attributes with ID owned by <anIDList> are to be
-- ignored and the filter will answer false to the
-- question IsKept(<anID>) with ID from <anIDList>.
-- Question methods.
IsKept(me; anID : GUID from Standard) returns Boolean from Standard;
---Purpose: Returns true if the ID is to be kept.
--
---C++: inline
IsKept(me; anAtt : Attribute from TDF) returns Boolean from Standard;
---Purpose: Returns true if the attribute is to be kept.
--
---C++: inline
IsIgnored(me; anID : GUID from Standard) returns Boolean from Standard;
---Purpose: Returns true if the ID is to be ignored.
--
---C++: inline
IsIgnored(me; anAtt : Attribute from TDF) returns Boolean from Standard;
---Purpose: Returns true if the attribute is to be ignored.
--
---C++: inline
-- Miscelleaneous
IDList(me; anIDList : in out IDList from TDF);
---Purpose: Copies the list of ID to be kept or ignored in
-- <anIDList>. <anIDList> is cleared before use.
Copy(me : in out; fromFilter : IDFilter from TDF);
---Purpose: Copies into <me> the contents of
-- <fromFilter>. <me> is cleared before copy.
Dump(me; anOS : in out OStream from Standard);
---Purpose: Writes the contents of <me> to <OS>.
fields
myIgnore : Boolean from Standard;
myIDMap : IDMap from TDF;
end IDFilter;

166
src/TDF/TDF_IDFilter.cxx Executable file
View File

@@ -0,0 +1,166 @@
// File: TDF_IDFilter.cxx
// ---------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 May 26 1997 Creation
#include <TDF_IDFilter.ixx>
#include <TDF_IDList.hxx>
#include <TDF_ListIteratorOfIDList.hxx>
#include <TDF_MapIteratorOfIDMap.hxx>
// To avoid too much resizing actions, et 23 est un nombre premier.
#define TDF_IDFilterMapSize 23
//=======================================================================
//function : TDF_IDFilter
//purpose :
//=======================================================================
TDF_IDFilter::TDF_IDFilter(const Standard_Boolean ignoreMode) :
myIgnore(ignoreMode)
{}
//=======================================================================
//function : TDF_IDFilter
//purpose : Private, to forbid implicit or hidden accesses to
// the copy constructor.
//=======================================================================
TDF_IDFilter::TDF_IDFilter(const TDF_IDFilter& aFilter)
{}
//=======================================================================
//function : IgnoreAll
//purpose :
//=======================================================================
void TDF_IDFilter::IgnoreAll(const Standard_Boolean ignore)
{
myIgnore = ignore;
myIDMap.Clear(); myIDMap.ReSize(TDF_IDFilterMapSize);
}
//=======================================================================
//function : Keep
//purpose : Keeps an ID.
//=======================================================================
void TDF_IDFilter::Keep(const Standard_GUID& anID)
{
if (myIgnore) myIDMap.Add(anID);
else myIDMap.Remove(anID);
}
//=======================================================================
//function : Keep
//purpose : Keeps a list of ID.
//=======================================================================
void TDF_IDFilter::Keep(const TDF_IDList& anIDList)
{
if (!anIDList.IsEmpty()) {
TDF_ListIteratorOfIDList itr(anIDList);
if (myIgnore) {
Standard_Integer n = anIDList.Extent() + myIDMap.NbBuckets() + 1;
myIDMap.ReSize(n);
for (; itr.More(); itr.Next()) myIDMap.Add(itr.Value());
}
else {
for (; itr.More(); itr.Next()) myIDMap.Remove(itr.Value());
}
}
}
//=======================================================================
//function : Ignore
//purpose : Ignores an ID.
//=======================================================================
void TDF_IDFilter::Ignore(const Standard_GUID& anID)
{
if (myIgnore) myIDMap.Remove(anID);
else myIDMap.Add(anID);
}
//=======================================================================
//function : Ignore
//purpose : Ignores a list of ID.
//=======================================================================
void TDF_IDFilter::Ignore(const TDF_IDList& anIDList)
{
if (!anIDList.IsEmpty()) {
TDF_ListIteratorOfIDList itr(anIDList);
if (myIgnore) {
for (; itr.More(); itr.Next()) myIDMap.Remove(itr.Value());
}
else {
Standard_Integer n = anIDList.Extent() + myIDMap.NbBuckets() + 1;
myIDMap.ReSize(n);
for (; itr.More(); itr.Next()) myIDMap.Add(itr.Value());
}
}
}
//=======================================================================
//function : IDList
//purpose :
//=======================================================================
void TDF_IDFilter::IDList(TDF_IDList& anIDList) const
{
anIDList.Clear();
for (TDF_MapIteratorOfIDMap itr(myIDMap); itr.More(); itr.Next())
anIDList.Append(itr.Key());
}
//=======================================================================
//function : Copy
//purpose :
//=======================================================================
void TDF_IDFilter::Copy(const TDF_IDFilter& fromFilter)
{
myIgnore = fromFilter.IgnoreAll();
TDF_IDList idl;
fromFilter.IDList(idl);
if (myIgnore) Keep(idl);
else Ignore(idl);
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void TDF_IDFilter::Dump(Standard_OStream& anOS) const
{
if (myIgnore) anOS<<"EX"; else anOS<<"IN"; anOS<<"CLUSIVE filter: ";
if (myIgnore) anOS<<"ignores"; else anOS<<"keeps "; anOS<<" all IDs";
TDF_MapIteratorOfIDMap itr(myIDMap);
if (itr.More()) {
anOS<<" BUT:"<<endl;
for (; itr.More(); itr.Next()) {
const Standard_GUID& guid = itr.Key();
guid.ShallowDump(anOS);
anOS<<endl;
}
}
}

33
src/TDF/TDF_IDFilter.lxx Executable file
View File

@@ -0,0 +1,33 @@
// File: TDF_IDFilter.lxx
// ---------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Jun 10 1997 Creation
#include <TDF_Attribute.hxx>
inline Standard_Boolean TDF_IDFilter::IgnoreAll() const
{ return myIgnore; }
inline Standard_Boolean TDF_IDFilter::IsKept
(const Standard_GUID& anID) const
{ return (myIgnore == myIDMap.Contains(anID)); }
// Ce qui est plus compacte et rapide que:
//Standard_Boolean IsBound = myIDMap.Contains(anID);
// return myIgnore ? IsBound : !IsBound;
inline Standard_Boolean TDF_IDFilter::IsKept
(const Handle(TDF_Attribute)& anAtt) const
{ return IsKept(anAtt->ID()); }
inline Standard_Boolean TDF_IDFilter::IsIgnored
(const Standard_GUID& anID) const
{ return (myIgnore != myIDMap.Contains(anID)); }
inline Standard_Boolean TDF_IDFilter::IsIgnored
(const Handle(TDF_Attribute)& anAtt) const
{ return IsIgnored(anAtt->ID()); }

368
src/TDF/TDF_Label.cdl Executable file
View File

@@ -0,0 +1,368 @@
-- File: TDF_Label.cdl
-- Created: Tue Feb 4 10:59:33 1997
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Feb 4 1997 Creation
class Label from TDF
---Purpose: This class provides basic operations to define
-- a label in a data structure.
-- A label is a feature in the feature hierarchy. A
-- label is always connected to a Data from TDF.
-- To a label is attached attributes containing the
-- software components information.
--
-- Label information:
--
-- It is possible to know the tag, the father, the
-- depth in the tree of the label, if the label is
-- root, null or equal to another label.
--
-- Comfort methods:
-- Some methods useful on a label.
--
-- Attributes:
--
-- It is possible to get an attribute in accordance
-- to an ID, or the yougest previous version of a
-- current attribute.
uses
GUID from Standard,
LabelNodePtr from TDF,
Data from TDF,
Attribute from TDF,
IDFilter from TDF,
AttributeIndexedMap from TDF
raises
DomainError from Standard,
OutOfRange from Standard,
NullObject from Standard
is
Create returns Label from TDF;
---Purpose: Constructs an empty label object.
Create(aNode : LabelNodePtr from TDF) returns Label from TDF
is private;
---Purpose: Reserved to the friends.
Nullify(me : in out);
---Purpose: Nullifies the label.
--
---C++: inline
---Category:Label information
-- ==========================
Data(me) returns Data from TDF;
---Purpose: Returns the Data owning <me>.
--
---C++: inline
Tag(me) returns Integer;
---Purpose: Returns the tag of the label.
-- This is the integer assigned randomly to a label
-- in a data framework. This integer is used to
-- identify this label in an entry.
--
---C++: inline
Father(me) returns Label from TDF;
---Purpose: Returns the label father. This label may be null
-- if the label is root.
--
---C++: inline
---C++: return const
IsNull(me) returns Boolean from Standard;
---Purpose: Returns True if the <aLabel> is null, i.e. it has
-- not been included in the data framework.
--
---C++: inline
Imported(me; aStatus : Boolean from Standard);
---Purpose: Sets or unsets <me> and all its descendants as
-- imported label, according to <aStatus>.
IsImported(me) returns Boolean from Standard;
---Purpose: Returns True if the <aLabel> is imported.
--
---C++: inline
IsEqual(me; aLabel : Label from TDF) returns Boolean from Standard;
---Purpose: Returns True if the <aLabel> is equal to me (same
-- LabelNode*).
---C++: inline
---C++: alias operator ==
IsDifferent(me; aLabel : Label from TDF) returns Boolean from Standard;
---Puprpose: Returns True if the <aLabel> is different than me
-- (not same LabelNode*).
--
---C++: inline
---C++: alias operator !=
IsRoot(me) returns Boolean from Standard;
---Puprpose: Returns True if the label is root.
---C++: inline
---Category: Attribute methods
-- ===========================
---Warning: : becomes obsolete week 10
-- IsA (me; anID : GUID from Standard) returns Boolean from Standard;
-- Resume (me; anAttribute : Attribute from TDF) raises DomainError from Standard;
-- Add (me; anAttribute : Attribute from TDF) raises DomainError from Standard;
-- Forget (me; anAttribute : Attribute from TDF) raises DomainError from Standard;
-- Forget (me; aguid : GUID from Standard) returns Boolean from Standard;
-- ForgetAll (me; clearChildren : Boolean from Standard = Standard_True);
IsAttribute (me; anID : GUID from Standard) returns Boolean from Standard;
---Purpose: Returns true if <me> owns an attribute with <anID> as ID.
AddAttribute (me; anAttribute : Attribute from TDF)
---Purpose: Adds an Attribute to the current label. Raises if
-- there is already one.
raises DomainError from Standard;
ForgetAttribute (me; anAttribute : Attribute from TDF)
---Purpose: Forgets an Attribute from the current label,
-- setting its forgotten status true and its valid
-- status false. Raises if the attribute is not in
-- the structure.
raises DomainError from Standard;
ForgetAttribute (me; aguid : GUID from Standard)
---Purpose: Forgets the Attribute of GUID <aguid> from the
-- current label . If the attribute doesn't exist
-- returns False. Otherwise returns True.
returns Boolean from Standard;
ForgetAllAttributes (me; clearChildren : Boolean from Standard = Standard_True);
---Purpose: Forgets all the attributes. Does it on also on the
-- sub-labels if <clearChildren> is set to true. Of
-- course, this method is compatible with Transaction
-- & Delta mecanisms.
ResumeAttribute (me; anAttribute : Attribute from TDF)
---Purpose: Undo Forget action, setting its forgotten status
-- false and its valid status true. Raises if the
-- attribute is not in the structure.
raises DomainError from Standard;
FindAttribute (me;
anID : GUID from Standard;
anAttribute : in out Attribute from TDF)
returns Boolean from Standard;
---Purpose: Finds an attribute of the current label, according
-- to <anID>.
-- If anAttribute is not a valid one, false is returned.
--
-- The method returns True if found, False otherwise.
--
-- A removed attribute cannot be found.
FindAttribute (me;
anID : GUID from Standard;
aTransaction : Integer from Standard;
anAttribute : in out Attribute from TDF)
returns Boolean from Standard;
---Purpose: Finds an attribute of the current label, according
-- to <anID> and <aTransaction>. This attribute
-- has/had to be a valid one for the given
-- transaction index . So, this attribute is not
-- necessary a valid one.
--
-- The method returns True if found, False otherwise.
--
-- A removed attribute cannot be found nor a backuped
-- attribute of a removed one.
MayBeModified(me)
returns Boolean from Standard;
---Purpose: Returns true if <me> or a DESCENDANT of <me> owns
-- attributes not yet available in transaction 0. It
-- means at least one of their attributes is new,
-- modified or deleted.
--
---C++: inline
AttributesModified(me)
returns Boolean from Standard;
---Purpose: Returns true if <me> owns attributes not yet
-- available in transaction 0. It means at least one
-- attribute is new, modified or deleted.
--
---C++: inline
HasAttribute(me) returns Boolean from Standard;
---Purpose: Returns true if this label has at least one attribute.
NbAttributes(me) returns Integer;
---Purpose: Returns the number of attributes.
---Category: Label comfort methods
--================================
Depth(me) returns Integer from Standard;
---Purpose: Returns the depth of the label in the data framework.
-- This corresponds to the number of fathers which
-- this label has, and is used in determining
-- whether a label is root, null or equivalent to another label.
-- Exceptions:
-- Standard_NullObject if this label is null. This is
-- because a null object can have no depth.
IsDescendant(me; aLabel : Label from TDF) returns Boolean from Standard;
---Purpose: Returns True if <me> is a descendant of
-- <aLabel>. Attention: every label is its own
-- descendant.
Root(me) returns Label from TDF;
---Purpose: Returns the root label Root of the data structure.
-- This has a depth of 0.
-- Exceptions:
-- Standard_NullObject if this label is null. This is
-- because a null object can have no depth.
---C++: return const
HasChild(me) returns Boolean from Standard;
---Purpose: Returns true if this label has at least one child.
---C++: inline
NbChildren(me) returns Integer;
---Purpose: Returns the number of children.
FindChild(me; aTag : Integer from Standard;
create : Boolean from Standard = Standard_True)
returns Label from TDF
raises NullObject, DomainError, OutOfRange from Standard;
---Purpose: Finds a child label having <aTag> as tag. Creates
-- The tag aTag identifies the label which will be the parent.
-- If create is true and no child label is found, a new one is created.
-- Example:
-- //creating a label with tag 10 at Root
-- TDF_Label lab1 = aDF->Root().FindChild(10);
-- //creating labels 7 and 2 on label 10
-- TDF_Label lab2 = lab1.FindChild(7);
-- TDF_Label lab3 = lab1.FindChild(2);
NewChild (me)
returns Label from TDF
raises NullObject, DomainError, OutOfRange from Standard;
---Purpose: Create a new child label of me using autoamtic
-- delivery tags provided by TagSource.
---C++: inline
---Category: Miscelleaneous
-- ========================
Transaction(me) returns Integer from Standard;
---Purpose: Returns the current transaction index.
HasLowerNode(me; otherLabel : Label from TDF)
returns Boolean from Standard;
---Purpose: Returns true if node address of <me> is lower than
-- <otherLabel> one. Used to quickly sort labels (not
-- on entry criterion).
--
-- -C++: inline
HasGreaterNode(me; otherLabel : Label from TDF)
returns Boolean from Standard;
---Purpose: Returns true if node address of <me> is greater
-- than <otherLabel> one. Used to quickly sort labels
-- (not on entry criterion).
--
-- -C++: inline
Dump(me; anOS : in out OStream from Standard)
returns OStream from Standard;
---Purpose: Dumps the minimum information about <me> on
-- <aStream>.
--
---C++: return &
---C++: alias operator<<
ExtendedDump(me;
anOS : in out OStream from Standard;
aFilter : IDFilter from TDF;
aMap : in out AttributeIndexedMap from TDF);
---Purpose: Dumps the label on <aStream> and its attributes
-- rank in <aMap> if their IDs are kept by <IDFilter>.
EntryDump(me; anOS : in out OStream from Standard);
---Purpose: Dumps the label entry.
---Category: Private methods
-- =========================
AddToNode(me; toNode : LabelNodePtr from TDF;
anAttribute : Attribute from TDF)
raises DomainError from Standard
is private;
---Purpose: Adds an Attribute to <toNode>. Raises if there is
-- already one.
ForgetFromNode(me; fromNode : LabelNodePtr from TDF;
anAttribute : Attribute from TDF)
raises DomainError from Standard
is private;
---Purpose: Forgets an Attribute from <fromNode>. Raises if
-- the attribute is not in the structure.
ResumeToNode (me; fromNode : LabelNodePtr from TDF;
anAttribute : Attribute from TDF)
raises DomainError, NullObject from Standard
is private;
---Purpose: Resumes a forgotten Attribute to <toNode>. Raises
-- if the attribute is not in the structure.
FindOrAddChild(me; aTag : Integer from Standard;
create : Boolean from Standard)
returns LabelNodePtr from TDF
is private;
InternalDump(me; anOS : in out OStream from Standard;
aFilter : IDFilter from TDF;
aMap : in out AttributeIndexedMap from TDF;
extended : Boolean from Standard)
is private;
fields
myLabelNode : LabelNodePtr from TDF;
friends
class ChildIterator from TDF,
class Attribute from TDF,
class AttributeIterator from TDF,
class Data from TDF,
class LabelMapHasher from TDF
end Label;

668
src/TDF/TDF_Label.cxx Executable file
View File

@@ -0,0 +1,668 @@
// File: TDF_Label.cxx
// --------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 6 1997 Creation
#include <TDF_Label.ixx>
#include <TDF_Attribute.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_Data.hxx>
#include <TDF_LabelNode.hxx>
#include <TDF_LabelNodePtr.hxx>
#include <TDF_Tool.hxx>
#include <TCollection_AsciiString.hxx>
#include <Standard_ImmutableObject.hxx>
//=======================================================================
//function : TDF_Label
//purpose :
//=======================================================================
TDF_Label::TDF_Label()
:myLabelNode(NULL)
{}
//=======================================================================
//function : TDF_Label
//purpose :
//=======================================================================
TDF_Label::TDF_Label(const TDF_LabelNodePtr& aNode)
:myLabelNode(aNode)
{}
// Attribute methods ++++++++++++++++++++++++++++++++++++++++++++++++++++
//=======================================================================
//function : Imported
//purpose : Sets imported and all its descendants.
//=======================================================================
void TDF_Label::Imported(const Standard_Boolean aStatus) const
{
if (IsNull()) Standard_NullObject::Raise("A null Label has no status.");
if (myLabelNode->IsImported() != aStatus) {
myLabelNode->Imported(aStatus);
for (TDF_ChildIterator itr(*this, Standard_True);
itr.More(); itr.Next())
itr.Value().myLabelNode->Imported(aStatus);
}
}
//=======================================================================
//function : FindAttribute
//purpose : Finds an attributes according to an ID.
//=======================================================================
Standard_Boolean TDF_Label::FindAttribute
(const Standard_GUID& anID,
Handle(TDF_Attribute)& anAttribute) const
{
if (IsNull()) Standard_NullObject::Raise("A null Label has no attribute.");
TDF_AttributeIterator itr (myLabelNode); // Without removed attributes.
for ( ; itr.More(); itr.Next()) {
if (itr.Value()->ID() == anID) {
anAttribute = itr.Value();
return Standard_True;
}
}
return Standard_False;
}
//=======================================================================
//function : FindAttribute
//purpose : Finds an attributes according to an ID and a Transaction.
//=======================================================================
Standard_Boolean TDF_Label::FindAttribute
(const Standard_GUID& anID,
const Standard_Integer aTransaction,
Handle(TDF_Attribute)& anAttribute) const
{
Handle(TDF_Attribute) locAtt;
if (FindAttribute(anID, locAtt)) {
while ((!locAtt.IsNull()) && (locAtt->myTransaction > aTransaction))
locAtt = locAtt->myBackup;
if (!locAtt.IsNull()) {
anAttribute = locAtt;
return Standard_True;
}
}
return Standard_False;
}
// Label comfort methods ++++++++++++++++++++++++++++++++++++++++++++++++
//=======================================================================
//function : Depth
//purpose : Returns the depth of the label in the tree.
// Root has depth 0. So the depth is the number of fathers.
//=======================================================================
Standard_Integer TDF_Label::Depth() const
{
if (IsNull()) Standard_NullObject::Raise("A null Label has no depth.");
return myLabelNode->Depth();
}
//=======================================================================
//function : IsDescendant
//purpose : Returns True if <me> is a descendant of <aLabel>.
//=======================================================================
Standard_Boolean TDF_Label::IsDescendant(const TDF_Label& aLabel) const
{
// Cet algorithme remonte jusqu'a la racine. On peut s'arreter
// si la profondeur atteinte est inferieure a celle de <aLabel>.
const TDF_LabelNode* lp1 = aLabel.myLabelNode;
TDF_LabelNode* lp2 = myLabelNode;
#ifdef DEB
if ((lp1 == NULL) || (lp2 == NULL))
Standard_NullObject::Raise("A null label has no ancestor nor descendant.");
#endif
if ((lp1 != NULL) && (lp2 != NULL)) {
const Standard_Integer d1 = lp1->Depth();
Standard_Integer d2 = lp2->Depth();
// Tester (d1 > d2) optimise la recherche ET dispense du test (lp2 != NULL)
while ((d2 > d1) && (lp2 != lp1)) {
lp2 = lp2->Father();
d2 = lp2->Depth();
}
return (lp1 == lp2);
}
return Standard_False;
}
//=======================================================================
//function : Root
//purpose :
//=======================================================================
const TDF_Label TDF_Label::Root() const
{
if (IsNull()) Standard_NullObject::Raise("A null Label has no root.");
return myLabelNode->RootNode();
}
//=======================================================================
//function : NbChildren
//purpose : Returns the number of children.
//=======================================================================
Standard_Integer TDF_Label::NbChildren() const
{
if (IsNull()) Standard_NullObject::Raise("A null Label has no children.");
Standard_Integer n = 0;
if (myLabelNode->FirstChild() != NULL)
for (TDF_ChildIterator itr(*this); itr.More(); itr.Next()) ++n;
return n;
}
//=======================================================================
//function : FindChild
//purpose :
//=======================================================================
TDF_Label TDF_Label::FindChild
(const Standard_Integer aTag,
const Standard_Boolean create) const
{
if (IsNull())
Standard_NullObject::Raise("A null Label has no child.");
if (create && ((Depth()+1) & TDF_LabelNodeFlagsMsk))
Standard_OutOfRange::Raise("Depth value out of range");
return FindOrAddChild(aTag,create);
}
// Attribute comfort methods ++++++++++++++++++++++++++++++++++++++++++++
//=======================================================================
//function : IsA
//purpose : Returns true if owns an attribute with <anID> as ID.
//=======================================================================
// Standard_Boolean TDF_Label::IsA(const Standard_GUID& anID) const
// {
// Handle(TDF_Attribute) att;
// return FindAttribute(anID,att);
// }
//=======================================================================
//function : IsAttribute
//purpose : Returns true if owns an attribute with <anID> as ID.
//=======================================================================
Standard_Boolean TDF_Label::IsAttribute(const Standard_GUID& anID) const
{
Handle(TDF_Attribute) att;
return FindAttribute(anID,att);
}
//=======================================================================
//function : HasAttribute
//purpose : Returns true if the label has at least one unremoved attribute.
//=======================================================================
Standard_Boolean TDF_Label::HasAttribute() const
{
if (IsNull()) Standard_NullObject::Raise("A null Label has no attribute.");
if (!myLabelNode->FirstAttribute().IsNull()) {
TDF_AttributeIterator itr (myLabelNode); // Without removed attributes.
return itr.More();
}
return Standard_False;
}
//=======================================================================
//function : NbAttributes
//purpose : Returns the number of attributes.
//=======================================================================
Standard_Integer TDF_Label::NbAttributes() const
{
if (IsNull()) Standard_NullObject::Raise("A null Label has no attribute.");
Standard_Integer n = 0;
if (!myLabelNode->FirstAttribute().IsNull())
for (TDF_AttributeIterator itr (myLabelNode); itr.More(); itr.Next()) ++n;
return n;
}
// Miscelleaneous +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//=======================================================================
//function : Transaction
//purpose :
//=======================================================================
Standard_Integer TDF_Label::Transaction() const
{
if (IsNull()) Standard_NullObject::Raise("A null Label has no transaction.");
return myLabelNode->Data()->Transaction();
}
//=======================================================================
//function : Dump
//purpose : This method is equivalent to operator <<
//=======================================================================
Standard_OStream& TDF_Label::Dump
(Standard_OStream& anOS) const
{
TDF_IDFilter f; TDF_AttributeIndexedMap m;
TDF_Label::InternalDump(anOS,f,m,Standard_False);
return anOS;
}
//=======================================================================
//function : ExtendedDump
//purpose :
//=======================================================================
void TDF_Label::ExtendedDump
(Standard_OStream& anOS,
const TDF_IDFilter& aFilter,
TDF_AttributeIndexedMap& aMap) const
{ TDF_Label::InternalDump(anOS,aFilter,aMap,Standard_True); }
//=======================================================================
//function : EntryDump
//purpose :
//=======================================================================
void TDF_Label::EntryDump(Standard_OStream& anOS) const
{
if (IsNull ()) {
anOS<<"This label is null.";
}
else {
TCollection_AsciiString entry;
TDF_Tool::Entry(*this,entry);
anOS<<entry;
}
}
#ifdef WNT
// Disable the warning: "operator new unmatched by delete"
#pragma warning (disable:4291)
#endif
//=======================================================================
//function : FindOrAddChild
//purpose : Finds or adds a label child having <aTag> as tag.
//=======================================================================
TDF_LabelNode* TDF_Label::FindOrAddChild
(const Standard_Integer aTag,
const Standard_Boolean create) const
{
TDF_LabelNode* currentLnp = myLabelNode->FirstChild();
TDF_LabelNode* lastLnp = NULL;
TDF_LabelNode* lastFoundLnp = myLabelNode->myLastFoundChild; //jfa 10.01.2003
TDF_LabelNode* childLabelNode = NULL;
// Finds the right place.
//jfa 10.01.2003
// 1. Check, if we access to a child, which is after last touched upon
if (lastFoundLnp != NULL) {
if (lastFoundLnp->Tag() == aTag) {
return lastFoundLnp;
}
else if (lastFoundLnp->Tag() < aTag) {
lastLnp = lastFoundLnp;
currentLnp = lastFoundLnp->Brother();
}
}
//jfa 10.01.2003 end
// To facilitate many tools, label brethren are stored in increasing order.
while ((currentLnp != NULL) && (currentLnp->Tag() < aTag) ) {
lastLnp = currentLnp;
currentLnp = currentLnp->Brother();
}
if ( (currentLnp != NULL) && (currentLnp->Tag() == aTag) ) {
// The label exists.
childLabelNode = currentLnp;
}
else if (create) {
// Creates the label to be inserted always before currentLnp.
const Handle(NCollection_IncAllocator)& anIncAllocator =
(const Handle(NCollection_IncAllocator)&)
myLabelNode ->Data() -> LabelNodeAllocator();
childLabelNode = new (anIncAllocator) TDF_LabelNode (aTag, myLabelNode);
childLabelNode->myBrother = currentLnp; // May be NULL.
childLabelNode->Imported(IsImported());
//Inserts the label:
if (lastLnp == NULL) // ... at beginning.
myLabelNode->myFirstChild = childLabelNode;
else // ... somewhere.
lastLnp->myBrother = childLabelNode;
}
if (lastLnp) //agv 14.07.2010
myLabelNode->myLastFoundChild = lastLnp; //jfa 10.01.2003
return childLabelNode;
}
#ifdef WNT
#pragma warning (default:4291)
#endif
//=======================================================================
//function : InternalDump
//purpose : Private method.
//=======================================================================
void TDF_Label::InternalDump
(Standard_OStream& anOS,
const TDF_IDFilter& aFilter,
TDF_AttributeIndexedMap& aMap,
const Standard_Boolean extended) const
{
if (IsNull ()) {
anOS<<"This label is null.";
}
else {
TCollection_AsciiString entry; TDF_Tool::Entry(*this,entry);
anOS<<entry<<"\t";
if (IsImported()) anOS<<"IS "; else anOS<<"NOT"; anOS<<" imported; ";
if (MayBeModified()) anOS<<"MAYBE"; else anOS<<"NOT"; anOS<<" modified; ";
if (AttributesModified()) anOS<<"HAS attributes"; else anOS<<"NO attribute"; anOS<<" modified; ";
if (HasAttribute()) {
Standard_Integer nba = NbAttributes();
anOS<<"has "<<nba<<" attribute"; if (nba > 1) anOS<<"s"; anOS<<"."<<endl;
for (TDF_AttributeIterator itr(myLabelNode); itr.More(); itr.Next()) {
// CLE
// const Handle(TDF_Attribute)& att = itr.Value();
Handle(TDF_Attribute) att = itr.Value();
// ENDCLE
if (extended && aFilter.IsKept(att)) anOS<<"\t# "<<aMap.Add(att);
att->TDF_Attribute::Dump(anOS);
}
}
else {
anOS<<" has no attribute"<<endl;
}
}
}
Standard_Boolean TDF_Label::HasLowerNode(const TDF_Label& aLabel) const
{ return (myLabelNode < aLabel.myLabelNode); }
Standard_Boolean TDF_Label::HasGreaterNode(const TDF_Label& aLabel) const
{ return (myLabelNode > aLabel.myLabelNode); }
// from insertor ////////////////////////////////////////////////////////
//=======================================================================
//function : Add
//purpose :
//=======================================================================
// void TDF_Label::Add(const Handle(TDF_Attribute)& anAttribute) const
// { AddToNode(myLabelNode,anAttribute); }
//=======================================================================
//function : AddAttribute
//purpose :
//=======================================================================
void TDF_Label::AddAttribute (const Handle(TDF_Attribute)& anAttribute) const
{ AddToNode(myLabelNode,anAttribute); }
//=======================================================================
//function : Forget
//purpose :
//=======================================================================
// void TDF_Label::Forget(const Handle(TDF_Attribute)& anAttribute) const
// { ForgetFromNode(myLabelNode,anAttribute); }
//=======================================================================
//function : ForgetAttribute
//purpose :
//=======================================================================
void TDF_Label::ForgetAttribute (const Handle(TDF_Attribute)& anAttribute) const
{ ForgetFromNode(myLabelNode,anAttribute); }
//=======================================================================
//function : Forget
//purpose :
//=======================================================================
// Standard_Boolean TDF_Label::Forget (const Standard_GUID& anID) const
// {
// Handle(TDF_Attribute) anAttribute;
// //if (Label().FindAttribute(anID,anAttribute)) {
// if (FindAttribute(anID,anAttribute)) {
// Forget(anAttribute);
// return Standard_True;
// }
// return Standard_False;
// }
//=======================================================================
//function : ForgetAttribute
//purpose :
//=======================================================================
Standard_Boolean TDF_Label::ForgetAttribute (const Standard_GUID& anID) const
{
Handle(TDF_Attribute) anAttribute;
//if (Label().FindAttribute(anID,anAttribute)) {
if (FindAttribute(anID,anAttribute)) {
ForgetAttribute (anAttribute);
return Standard_True;
}
return Standard_False;
}
//=======================================================================
//function : ForgetAll
//purpose :
//=======================================================================
// void TDF_Label::ForgetAll (const Standard_Boolean clearChildren) const
// {
// for (TDF_AttributeIterator itr1(myLabelNode); itr1.More(); itr1.Next())
// ForgetFromNode(myLabelNode,itr1.Value());
// if (clearChildren)
// for (TDF_ChildIterator itr2(myLabelNode); itr2.More(); itr2.Next()) {
// itr2.Value().ForgetAll(clearChildren);
// }
// }
//=======================================================================
//function : ForgetAllAttributes
//purpose :
//=======================================================================
void TDF_Label::ForgetAllAttributes (const Standard_Boolean clearChildren) const
{
TDF_AttributeIterator itr1 (myLabelNode);
// AGV-OCC5031: iterator must be incremented before removal of the attribute
while (itr1.More()) {
const Handle(TDF_Attribute) anAttr = itr1.Value();
itr1.Next();
ForgetFromNode (myLabelNode, anAttr);
}
// while (itr1.More()) {
// ForgetFromNode(myLabelNode,itr1.Value());
// itr1.Next();
// }
if (clearChildren)
for (TDF_ChildIterator itr2(myLabelNode); itr2.More(); itr2.Next()) {
itr2.Value().ForgetAllAttributes (clearChildren);
}
}
//=======================================================================
//function : Resume
//purpose :
//=======================================================================
// void TDF_Label::Resume (const Handle(TDF_Attribute)& anAttribute) const
// { ResumeToNode(myLabelNode,anAttribute); }
//=======================================================================
//function : ResumeAttribute
//purpose :
//=======================================================================
void TDF_Label::ResumeAttribute (const Handle(TDF_Attribute)& anAttribute) const
{ ResumeToNode(myLabelNode,anAttribute); }
//=======================================================================
//function : AddToNode
//purpose : Private method used by Add
//=======================================================================
void TDF_Label::AddToNode (const TDF_LabelNodePtr& toNode,
const Handle(TDF_Attribute)& anAttribute) const
{
// check that modification is allowed
if ( !toNode->Data()->IsModificationAllowed() ) {
TCollection_AsciiString aMess;
aMess = "Attribute \"";
aMess += anAttribute->DynamicType()->Name();
aMess += "\" is added to label outside transaction";
Standard_ImmutableObject::Raise(aMess.ToCString());
}
if (!anAttribute->Label().IsNull())
Standard_DomainError::Raise("Attribute to add is already attached to a label.");
Handle(TDF_Attribute) dummyAtt;
//if (Find(anAttribute->ID(),dummyAtt))
if (FindAttribute(anAttribute->ID(),dummyAtt))
Standard_DomainError::Raise("This label has already such an attribute.");
anAttribute->myTransaction = toNode->Data()->Transaction(); /// myData->Transaction();
anAttribute->mySavedTransaction = 0;
dummyAtt.Nullify();
toNode->AddAttribute(dummyAtt,anAttribute);
toNode->AttributesModified(anAttribute->myTransaction != 0);
//if (myData->NotUndoMode()) anAttribute->AfterAddition();
if (toNode->Data()->NotUndoMode()) anAttribute->AfterAddition();
}
//=======================================================================
//function : ForgetFromNode
//purpose : Private method used by Forget
//=======================================================================
void TDF_Label::ForgetFromNode (const TDF_LabelNodePtr& fromNode,
const Handle(TDF_Attribute)& anAttribute) const
{
// check that modification is allowed
if ( !fromNode->Data()->IsModificationAllowed() ) {
TCollection_AsciiString aMess;
aMess = "Attribute \"";
aMess += anAttribute->DynamicType()->Name();
aMess += "\" is removed from label outside transaction";
Standard_ImmutableObject::Raise(aMess.ToCString());
}
if (fromNode != anAttribute->Label().myLabelNode)
Standard_DomainError::Raise
("Attribute to forget not attached to my label.");
Standard_Integer curTrans = fromNode->Data()->Transaction();
if (!anAttribute->IsForgotten()) {
if ( (curTrans == 0) ||
( (anAttribute->myTransaction == curTrans) &&
anAttribute->myBackup.IsNull())) {
// 1- No transaction is open;
// OR
// 2- The attribute has been created in the current transaction;
// ==> Complete disparition of the attribute.
Handle(TDF_Attribute) lastAtt;
for (TDF_AttributeIterator itr(fromNode, Standard_False);
itr.More();
itr.Next()) {
if (itr.Value() == anAttribute) {
//if (myData->NotUndoMode()) {
if (fromNode->Data()->NotUndoMode()) {
anAttribute->BeforeForget();
anAttribute->BeforeRemoval();
}
fromNode->RemoveAttribute(lastAtt,anAttribute);
anAttribute->Forget(fromNode->Data()->Transaction()); // vro
break;
}
lastAtt = itr.Value();
}
}
else {
// One case is here ignored:
// The attribute has been modified in the current transaction.
// (It has at least one backup.) We don't restore the previous
// version before forgetting. It may generated a strange behaviour
// in case of forgetting, commiting, aborting...
if (fromNode->Data()->NotUndoMode()) anAttribute->BeforeForget();
anAttribute->Forget(fromNode->Data()->Transaction());
}
}
}
//=======================================================================
//function : ResumeToNode
//purpose : Private method used by Resume
//=======================================================================
void TDF_Label::ResumeToNode (const TDF_LabelNodePtr& toNode,
const Handle(TDF_Attribute)& anAttribute) const
{
if (anAttribute.IsNull())
Standard_NullObject::Raise("The attribute is a null handle.");
if (!anAttribute->Label().IsNull())
Standard_NullObject::Raise
("Cannot resume an attribute already attached to a label.");
if (!anAttribute->IsForgotten())
Standard_DomainError::Raise
("Cannot resume an unforgotten attribute.");
AddToNode(toNode, anAttribute); // vro
anAttribute->Resume();
if (toNode->Data()->NotUndoMode()) anAttribute->AfterResume();
}
//////////////////end from insertor ///////////////////////////////////////////////////

55
src/TDF/TDF_Label.lxx Executable file
View File

@@ -0,0 +1,55 @@
// File: TDF_Label.lxx
// --------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 7 1997 Creation
#include <TDF_LabelNode.hxx>
#include <TDF_TagSource.hxx>
inline void TDF_Label::Nullify()
{ myLabelNode = NULL; }
inline Standard_Boolean TDF_Label::IsRoot() const
{ return myLabelNode->IsRoot(); }
inline Standard_Boolean TDF_Label::IsNull() const
{ return (myLabelNode == NULL); }
inline Standard_Boolean TDF_Label::IsImported() const
{ return myLabelNode->IsImported(); }
inline Standard_Boolean TDF_Label::IsEqual(const TDF_Label& aLabel) const
{ return (myLabelNode == aLabel.myLabelNode); }
inline Standard_Boolean TDF_Label::IsDifferent(const TDF_Label& aLabel) const
{ return (myLabelNode != aLabel.myLabelNode); }
inline Standard_Integer TDF_Label::Tag() const
{ return myLabelNode->Tag(); }
inline const TDF_Label TDF_Label::Father() const
{ return TDF_Label(myLabelNode->Father()); }
inline Standard_Boolean TDF_Label::HasChild() const
{ return (myLabelNode->FirstChild() != NULL); }
inline Standard_Boolean TDF_Label::AttributesModified() const
{ return myLabelNode->AttributesModified(); }
inline Standard_Boolean TDF_Label::MayBeModified() const
{ return myLabelNode->MayBeModified(); }
inline Handle(TDF_Data) TDF_Label::Data() const
{ return myLabelNode->Data(); }
inline Standard_OStream& operator << (Standard_OStream& anOS,
const TDF_Label& aLab)
{ aLab.Dump(anOS); return anOS; }
inline TDF_Label TDF_Label::NewChild () const
{ return TDF_TagSource::NewChild(*this); }

33
src/TDF/TDF_LabelMapHasher.cdl Executable file
View File

@@ -0,0 +1,33 @@
-- File: TDF_LabelMapHasher.cdl
-- ----------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Feb 13 1997 Creation
class LabelMapHasher from TDF
uses
Label from TDF
is
HashCode(myclass; aLab : Label from TDF; Upper : Integer) returns Integer;
---Purpose: Returns a HasCode value for the Key <K> in the
-- range 0..Upper.
--
---C++: inline
IsEqual(myclass; aLab1, aLab2 : Label from TDF) returns Boolean;
---Purpose: Returns True when the two keys are the same. Two
-- same keys must have the same hashcode, the
-- contrary is not necessary.
--
---C++: inline
end LabelMapHasher;

13
src/TDF/TDF_LabelMapHasher.cxx Executable file
View File

@@ -0,0 +1,13 @@
// File: TDF_LabelMapHasher.cxx
// ----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 13 1997 Creation
#include <TDF_LabelMapHasher.ixx>

37
src/TDF/TDF_LabelMapHasher.lxx Executable file
View File

@@ -0,0 +1,37 @@
// File: TDF_LabelMapHasher.lxx
// ----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 13 1997 Creation
//=======================================================================
//function : HashCode
//purpose :
//=======================================================================
//#ifndef WNT
//inline static Standard_Integer TDF_LabelMapHasher::HashCode
//#else
inline Standard_Integer TDF_LabelMapHasher::HashCode
//#endif
(const TDF_Label& aLab, const Standard_Integer Upper)
{ return 1 + ( (int) (labs((long int) aLab.myLabelNode) % Upper) ); }
//=======================================================================
//function : IsEqual
//purpose :
//=======================================================================
//#ifndef WNT
//inline static Standard_Boolean TDF_LabelMapHasher::IsEqual
//#else
inline Standard_Boolean TDF_LabelMapHasher::IsEqual
//#endif
(const TDF_Label& aLab1,const TDF_Label& aLab2)
{ return aLab1.IsEqual(aLab2); }

196
src/TDF/TDF_LabelNode.cxx Executable file
View File

@@ -0,0 +1,196 @@
// File: TDF_LabelNode.cxx
// ------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 6 1997 Creation
// MSV 21.03.2003: protect against stack overflow in destructor
#include <TDF_LabelNode.hxx>
#include <TDF_Data.hxx>
#include <TDF_Label.hxx>
//=======================================================================
//function : TDF_LabelNode
//purpose : Constructor with TDF_Data*, only used for root node.
//=======================================================================
TDF_LabelNode::TDF_LabelNode
(TDF_Data* aDataPtr)
: myFather (NULL), // The sign it is the root.
#ifdef KEEP_LOCAL_ROOT
myBrother (NULL),
#else
myBrother ((TDF_LabelNode *)aDataPtr),
#endif
myFirstChild (NULL),
myLastFoundChild (NULL), //jfa 10.01.2003
myTag (0), // Always 0 for root.
myFlags (0),
#ifdef KEEP_LOCAL_ROOT
myData (aDataPtr)
#endif
{
#ifdef DEB
myDebugEntry = '0';
#endif
}
//=======================================================================
//function : TDF_LabelNode
//purpose : Constructor
//=======================================================================
TDF_LabelNode::TDF_LabelNode
(const Standard_Integer aTag, TDF_LabelNode* aFather)
: myFather (aFather),
myBrother (NULL),
myFirstChild (NULL),
myLastFoundChild (NULL), //jfa 10.01.2003
myTag (aTag),
myFlags (0),
#ifdef KEEP_LOCAL_ROOT
myData (NULL)
#endif
{
if (aFather != NULL) {
Depth(aFather->Depth() + 1);
#ifdef KEEP_LOCAL_ROOT
myData = aFather -> Data();
#endif
}
#ifdef DEB
myDebugEntry = myFather->myDebugEntry;
myDebugEntry += ':';
myDebugEntry += aTag;
#endif
}
//=======================================================================
//function : ~TDF_LabelNode
//purpose :
//=======================================================================
TDF_LabelNode::~TDF_LabelNode()
{
// MSV 21.03.2003: do not delete brother, rather delete all children in a loop
// to avoid stack overflow
while (myFirstChild != NULL) {
TDF_LabelNode* aSecondChild = myFirstChild->Brother();
delete myFirstChild;
myFirstChild = aSecondChild;
}
myFirstAttribute.Nullify();
myLastFoundChild = NULL; //jfa 10.01.2003
}
//=======================================================================
//function : AddAttribute
//purpose : Adds an attribute at the first or the specified position.
//=======================================================================
void TDF_LabelNode::AddAttribute
(const Handle(TDF_Attribute)& afterAtt,
const Handle(TDF_Attribute)& newAtt)
{
newAtt->myFlags = 1; // Valid.
newAtt->myLabelNode = this;
if (afterAtt.IsNull()) { // Inserts at beginning.
newAtt->myNext = myFirstAttribute;
myFirstAttribute = newAtt;
}
else { // Inserts at specified place.
newAtt->myNext = afterAtt->myNext;
afterAtt->myNext = newAtt;
}
}
//=======================================================================
//function : RemoveAttribute
//purpose : Removes an attribute from the first or the specified position.
//=======================================================================
void TDF_LabelNode::RemoveAttribute
(const Handle(TDF_Attribute)& afterAtt,
const Handle(TDF_Attribute)& oldAtt)
{
oldAtt->myFlags = 0; // Unvalid.
oldAtt->myLabelNode = NULL;
if (afterAtt.IsNull()) { // Removes from beginning.
myFirstAttribute = oldAtt->myNext;
}
else { // Removes from specified place.
afterAtt->myNext = oldAtt->myNext;
}
// Nullifier le next induit l'iterateur d'attribut en erreur.
//oldAtt->myNext.Nullify();
}
//=======================================================================
//function : RootNode
//purpose : used for non const object.
//=======================================================================
TDF_LabelNode* TDF_LabelNode::RootNode ()
{
#ifdef KEEP_LOCAL_ROOT
return myData? myData -> myRoot: 0L;
#else
TDF_LabelNode* lp = this;
while (lp->myFather != NULL) lp = lp->myFather;
return lp;
#endif
}
//=======================================================================
//function : RootNode
//purpose : used for const object.
//=======================================================================
const TDF_LabelNode* TDF_LabelNode::RootNode () const
{
#ifdef KEEP_LOCAL_ROOT
return myData? myData -> myRoot: 0L;
#else
const TDF_LabelNode* lp = this;
while (lp->myFather != NULL) lp = lp->myFather;
return lp;
#endif
}
//=======================================================================
//function : Data
//purpose :
//=======================================================================
TDF_Data * TDF_LabelNode::Data () const
{
#ifdef KEEP_LOCAL_ROOT
return myData;
#else
const TDF_LabelNode* ln = RootNode()->myBrother;
return ((TDF_Data*) ln);
#endif
}
//=======================================================================
//function : AllMayBeModified
//purpose :
//=======================================================================
void TDF_LabelNode::AllMayBeModified()
{
MayBeModified(Standard_True);
if (myFather && !myFather->MayBeModified()) myFather->AllMayBeModified();
}

178
src/TDF/TDF_LabelNode.hxx Executable file
View File

@@ -0,0 +1,178 @@
// File: TDF_LabelNode.hxx
// ------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Feb 6 1997 Creation
//#include <TDF_Data.hxx>
#ifndef TDF_LabelNode_HeaderFile
#define TDF_LabelNode_HeaderFile
#include <TCollection_AsciiString.hxx>
#include <TDF_Attribute.hxx>
#include <TDF_LabelNodePtr.hxx>
#include <NCollection_IncAllocator.hxx>
class TDF_Attribute;
class TDF_AttributeIterator;
class TDF_ChildIterator;
class TDF_Data;
class Handle_TDF_Data;
class TDF_Label;
#define KEEP_LOCAL_ROOT
enum {
TDF_LabelNodeImportMsk = (int) 0x80000000, // Because the sign bit (HP).
TDF_LabelNodeAttModMsk = 0x40000000,
TDF_LabelNodeMayModMsk = 0x20000000,
TDF_LabelNodeFlagsMsk = (TDF_LabelNodeImportMsk \
| TDF_LabelNodeAttModMsk \
| TDF_LabelNodeMayModMsk)
};
//=======================================================================
//class: TDF_LabelNode
//=======================================================================
class TDF_LabelNode {
public :
// Public Methods
// --------------------------------------------------------------------------
// Father access
inline TDF_LabelNode* Father() const
{ return myFather; };
// Brother access
inline TDF_LabelNode* Brother() const
{ return myBrother; };
// Child access
inline TDF_LabelNode* FirstChild() const
{ return myFirstChild; };
// Attribute access
inline const Handle(TDF_Attribute)& FirstAttribute() const
{ return myFirstAttribute; };
// Tag access
inline Standard_Integer Tag() const
{ return myTag; };
// Depth access
inline Standard_Integer Depth() const
{ return (myFlags & ~TDF_LabelNodeFlagsMsk); };
// IsRoot
inline Standard_Boolean IsRoot() const
{ return myFather == NULL; };
// Data
Standard_EXPORT TDF_Data * Data() const;
// Flag AttributesModified access
inline void AttributesModified(const Standard_Boolean aStatus)
{
myFlags = (aStatus) ?
(myFlags | TDF_LabelNodeAttModMsk) :
(myFlags & ~TDF_LabelNodeAttModMsk);
if (aStatus) AllMayBeModified();
};
inline Standard_Boolean AttributesModified() const
{ return ((myFlags & TDF_LabelNodeAttModMsk) != 0); };
// Flag MayBeModified access
inline void MayBeModified(const Standard_Boolean aStatus)
{ myFlags = (aStatus) ?
(myFlags | TDF_LabelNodeMayModMsk) :
(myFlags & ~TDF_LabelNodeMayModMsk); };
inline Standard_Boolean MayBeModified() const
{ return ((myFlags & TDF_LabelNodeMayModMsk) != 0); };
// Constructor
TDF_LabelNode(TDF_Data* Data); // Useful for root node.
// Destructor
~TDF_LabelNode();
// Memory management
void * operator new (size_t aSize,
const Handle(NCollection_IncAllocator)& anAlloc)
{ return anAlloc -> Allocate (aSize); }
void operator delete(void *) { }
// nothing to do in operator delete since IncAllocator does not need it
// Public Friends
// --------------------------------------------------------------------------
friend class TDF_Data;
friend class TDF_Label;
private :
void* operator new(size_t);
// Private Methods
// --------------------------------------------------------------------------
// Constructor
TDF_LabelNode(const Standard_Integer Tag, TDF_LabelNode* Father);
// Others
void AddAttribute(const Handle(TDF_Attribute)& afterAtt,
const Handle(TDF_Attribute)& newAtt);
void RemoveAttribute(const Handle(TDF_Attribute)& afterAtt,
const Handle(TDF_Attribute)& oldAtt);
TDF_LabelNode* RootNode ();
const TDF_LabelNode* RootNode () const;
Standard_EXPORT void AllMayBeModified();
// Tag modification
inline void Tag(const Standard_Integer aTag)
{ myTag = aTag; };
// Depth modification
inline void Depth(const Standard_Integer aDepth)
{ myFlags = ((myFlags & TDF_LabelNodeFlagsMsk) | aDepth); };
// Flag Imported access
inline void Imported(const Standard_Boolean aStatus)
{ myFlags = (aStatus) ?
(myFlags | TDF_LabelNodeImportMsk) :
(myFlags & ~TDF_LabelNodeImportMsk); };
inline Standard_Boolean IsImported() const
{ return ((myFlags & TDF_LabelNodeImportMsk) != 0); };
// Private Fields
// --------------------------------------------------------------------------
TDF_LabelNodePtr myFather;
TDF_LabelNodePtr myBrother;
TDF_LabelNodePtr myFirstChild;
TDF_LabelNodePtr myLastFoundChild; //jfa 10.01.2003
Standard_Integer myTag;
Standard_Integer myFlags; // Flags & Depth
Handle(TDF_Attribute) myFirstAttribute;
#ifdef KEEP_LOCAL_ROOT
TDF_Data * myData;
#endif
#ifdef DEB
TCollection_AsciiString myDebugEntry;
#endif
};
#endif

67
src/TDF/TDF_Reference.cdl Executable file
View File

@@ -0,0 +1,67 @@
-- File: TDF_Reference.cdl
-- Created: Wed Mar 1 14:30:40 2000
-- Author: Denis PASCAL
-- <dp@dingox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 2000
class Reference from TDF inherits Attribute from TDF
---Purpose:
uses Attribute from TDF,
Label from TDF,
GUID from Standard,
DataSet from TDF,
RelocationTable from TDF
is
GetID (myclass)
---C++: return const &
returns GUID from Standard;
Set (myclass; I : Label from TDF; Origin : Label from TDF)
returns Reference from TDF;
Set (me : mutable; Origin : Label from TDF);
Get (me)
returns Label from TDF;
---Category: TDF_Attribute methods
-- =====================
ID (me)
---C++: return const &
returns GUID from Standard;
Restore (me: mutable; With : Attribute from TDF);
NewEmpty (me)
returns mutable Attribute from TDF;
Paste (me; Into : mutable Attribute from TDF;
RT : mutable RelocationTable from TDF);
References (me; DS : DataSet from TDF) is redefined;
Dump(me; anOS : in out OStream from Standard)
returns OStream from Standard
is redefined;
---C++: return &
Create
returns mutable Reference from TDF;
fields
myOrigin : Label from TDF;
end Reference;

135
src/TDF/TDF_Reference.cxx Executable file
View File

@@ -0,0 +1,135 @@
// File: TDF_Reference.cxx
// Created: Wed Mar 1 14:31:14 2000
// Author: Denis PASCAL
// <dp@dingox.paris1.matra-dtv.fr>
#include <TDF_Reference.ixx>
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& TDF_Reference::GetID ()
{
static Standard_GUID TDF_ReferenceID("2a96b610-ec8b-11d0-bee7-080009dc3333");
return TDF_ReferenceID;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
Handle(TDF_Reference) TDF_Reference::Set (const TDF_Label& L,
const TDF_Label& Origin)
{
Handle(TDF_Reference) A;
if (!L.FindAttribute (TDF_Reference::GetID (),A)) {
A = new TDF_Reference ();
L.AddAttribute (A);
}
A->Set (Origin);
return A;
}
//=======================================================================
//function : TDF_Reference
//purpose : Empty Constructor
//=======================================================================
TDF_Reference::TDF_Reference () { }
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void TDF_Reference::Set(const TDF_Label& Origin)
{
// OCC2932 correction
if(myOrigin == Origin) return;
Backup();
myOrigin = Origin;
}
//=======================================================================
//function : Get
//purpose :
//=======================================================================
TDF_Label TDF_Reference::Get() const
{
return myOrigin;
}
//=======================================================================
//function : ID
//purpose :
//=======================================================================
const Standard_GUID& TDF_Reference::ID() const { return GetID(); }
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) TDF_Reference::NewEmpty () const
{
return new TDF_Reference();
}
//=======================================================================
//function : Restore
//purpose :
//=======================================================================
void TDF_Reference::Restore(const Handle(TDF_Attribute)& With)
{
myOrigin = Handle(TDF_Reference)::DownCast (With)->Get ();
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void TDF_Reference::Paste (const Handle(TDF_Attribute)& Into,
const Handle(TDF_RelocationTable)& RT) const
{
TDF_Label tLab;
if (!myOrigin.IsNull()) {
if (!RT->HasRelocation(myOrigin,tLab)) tLab = myOrigin;
}
Handle(TDF_Reference)::DownCast(Into)->Set(tLab);
}
//=======================================================================
//function : References
//purpose : Adds the referenced attributes or labels.
//=======================================================================
void TDF_Reference::References(const Handle(TDF_DataSet)& aDataSet) const
{
if (!Label().IsImported()) aDataSet->AddLabel( myOrigin); //pour real et entier mais surtout pas les parts ...
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
Standard_OStream& TDF_Reference::Dump (Standard_OStream& anOS) const
{
anOS << "Reference";
return anOS;
}

195
src/TDF/TDF_RelocationTable.cdl Executable file
View File

@@ -0,0 +1,195 @@
-- File: TDF_RelocationTable.cdl
-- -----------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Mar 6 1997 Creation
-- 1.0 Sep 23 1998 DoubleMaps->DataMap
class RelocationTable from TDF
inherits TShared from MMgt
---Purpose: This is a relocation dictionnary between source
-- and target labels, attributes or any
-- transient. Note that one target value may be the
-- relocation value of more than one source object.
--
-- Common behaviour: it returns true and the found
-- relocation value as target object; false
-- otherwise.
--
-- Look at SelfRelocate method for more explanation
-- about self relocation behavior of this class.
uses
Attribute from TDF,
Data from TDF,
Label from TDF,
LabelMap from TDF,
LabelDataMap from TDF,
AttributeMap from TDF,
AttributeDataMap from TDF,
IndexedDataMapOfTransientTransient from TColStd
-- raises
is
Create(selfRelocate : Boolean from Standard = Standard_False)
-- Create(selfRelocate : Boolean from Standard = Standard_False;afterRelocate :Boolean from Standard = Standard_False)
returns mutable RelocationTable from TDF;
---Purpose: Creates an relocation table. <selfRelocate> says
-- if a value without explicit relocation is its own
-- relocation.
---Category: Self relocation methods.
-- -------------------------
SelfRelocate(me : mutable; selfRelocate : Boolean from Standard);
---Purpose: Sets <mySelfRelocate> to <selfRelocate>.
--
-- This flag affects the HasRelocation method
-- behavior like this:
--
-- <mySelfRelocate> == False:
--
-- If no relocation object is found in the map, a
-- null object is returned
--
-- <mySelfRelocate> == True:
--
-- If no relocation object is found in the map, the
-- method assumes the source object is relocation
-- value; so the source object is returned as target
-- object.
SelfRelocate(me) returns Boolean from Standard;
---Purpose: Returns <mySelfRelocate>.
AfterRelocate(me : mutable; afterRelocate : Boolean from Standard);
AfterRelocate(me) returns Boolean from Standard;
---Purpose: Returns <myAfterRelocate>.
---Category: Label relocation methods.
-- -------------------------
SetRelocation(me : mutable;
aSourceLabel : Label from TDF;
aTargetLabel : Label from TDF);
---Purpose: Sets the relocation value of <aSourceLabel> to
-- <aTargetLabel>.
HasRelocation(me;
aSourceLabel : Label from TDF;
aTargetLabel : in out Label from TDF)
returns Boolean from Standard;
---Purpose: Finds the relocation value of <aSourceLabel>
-- and returns it into <aTargetLabel>.
--
-- (See above SelfRelocate method for more
-- explanation about the method behavior)
---Category: Attribute relocation methods.
-- -----------------------------
SetRelocation(me : mutable;
aSourceAttribute : Attribute from TDF;
aTargetAttribute : Attribute from TDF);
---Purpose: Sets the relocation value of <aSourceAttribute> to
-- <aTargetAttribute>.
HasRelocation(me;
aSourceAttribute : Attribute from TDF;
aTargetAttribute : in out mutable Attribute from TDF)
returns Boolean from Standard;
---Purpose: Finds the relocation value of <aSourceAttribute>
-- and returns it into <aTargetAttribute>.
--
-- (See above SelfRelocate method for more
-- explanation about the method behavior)
---Category: Transient other types object relocation methods.
-- ------------------------------------------------
SetTransientRelocation(me : mutable;
aSourceTransient : Transient from Standard;
aTargetTransient : Transient from Standard);
---Purpose: Sets the relocation value of <aSourceTransient> to
-- <aTargetTransient>.
HasTransientRelocation
(me;
aSourceTransient : Transient from Standard;
aTargetTransient : in out mutable Transient from Standard)
returns Boolean from Standard;
---Purpose: Finds the relocation value of <aSourceTransient>
-- and returns it into <aTargetTransient>.
--
-- (See above SelfRelocate method for more
-- explanation about the method behavior)
---Category: Miscelleaneous
-- --------------
Clear(me : mutable);
---Purpose: Clears the relocation dictionnary, but lets the
-- self relocation flag to its current value.
TargetLabelMap(me; aLabelMap : in out LabelMap from TDF);
---Purpose: Fills <aLabelMap> with target relocation
-- labels. <aLabelMap> is not cleared before use.
TargetAttributeMap(me; anAttributeMap : in out AttributeMap from TDF);
---Purpose: Fills <anAttributeMap> with target relocation
-- attributes. <anAttributeMap> is not cleared before
-- use.
-- Try not to use the following methods, for they are very
-- implementation dependent.
LabelTable(me : mutable)
returns LabelDataMap from TDF;
---Purpose: Returns <myLabelTable> to be used or updated.
--
---C++: return &
AttributeTable(me : mutable)
returns AttributeDataMap from TDF;
---Purpose: Returns <myAttributeTable> to be used or updated.
--
---C++: return &
TransientTable(me : mutable)
returns IndexedDataMapOfTransientTransient from TColStd;
---Purpose: Returns <myTransientTable> to be used or updated.
--
---C++: return &
Dump(me;
dumpLabels, dumpAttributes, dumpTransients : Boolean from Standard;
anOS : in out OStream from Standard)
returns OStream from Standard;
---Purpose: Dumps the relocation table.
--
---C++: return &
fields
mySelfRelocate : Boolean from Standard;
myAfterRelocate : Boolean from Standard;
myLabelTable : LabelDataMap from TDF;
myAttributeTable : AttributeDataMap from TDF;
myTransientTable : IndexedDataMapOfTransientTransient from TColStd;
-- Indexed... because there is no other type available in TColStd.
end RelocationTable from TDF;

299
src/TDF/TDF_RelocationTable.cxx Executable file
View File

@@ -0,0 +1,299 @@
// File: TDF_RelocationTable.cxx
// -----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Mar 7 1997 Creation
#include <TDF_RelocationTable.ixx>
#include <TDF_DataMapIteratorOfAttributeDataMap.hxx>
#include <TDF_DataMapIteratorOfLabelDataMap.hxx>
//=======================================================================
//function : TDF_RelocationTable
//purpose :
//=======================================================================
TDF_RelocationTable::TDF_RelocationTable(const Standard_Boolean selfRelocate)
: mySelfRelocate(selfRelocate),myAfterRelocate(Standard_False)
{}
//=======================================================================
//function : SelfRelocate
//purpose :
//=======================================================================
void TDF_RelocationTable::SelfRelocate(const Standard_Boolean selfRelocate)
{ mySelfRelocate = selfRelocate; }
//=======================================================================
//function : SelfRelocate
//purpose :
//=======================================================================
Standard_Boolean TDF_RelocationTable::SelfRelocate() const
{ return mySelfRelocate; }
//=======================================================================
//function : SelfRelocate
//purpose :
//=======================================================================
void TDF_RelocationTable::AfterRelocate(const Standard_Boolean afterRelocate)
{ myAfterRelocate = afterRelocate; }
//=======================================================================
//function : SelfRelocate
//purpose :
//=======================================================================
Standard_Boolean TDF_RelocationTable::AfterRelocate() const
{ return myAfterRelocate; }
//=======================================================================
//function : SetRelocation
//purpose : Sets the relocation value of <aSourceLabel>
// to <aTargetLabel>.
//=======================================================================
void TDF_RelocationTable::SetRelocation
(const TDF_Label& aSourceLabel,
const TDF_Label& aTargetLabel)
{
if (!myLabelTable.IsBound(aSourceLabel))
myLabelTable.Bind(aSourceLabel,aTargetLabel);
}
//=======================================================================
//function : HasRelocation
//purpose : Finds the relocation value of <aSourceLabel>
// and returns it into <aTargetLabel>.
//=======================================================================
Standard_Boolean TDF_RelocationTable::HasRelocation
(const TDF_Label& aSourceLabel,
TDF_Label& aTargetLabel) const
{
aTargetLabel.Nullify();
if (myLabelTable.IsBound(aSourceLabel)) {
aTargetLabel = myLabelTable.Find(aSourceLabel);
return Standard_True;
}
if (mySelfRelocate) {
aTargetLabel = aSourceLabel;
return !myAfterRelocate;
}
return Standard_False;
}
//=======================================================================
//function : SetRelocation
//purpose : Sets the relocation value of <aSourceAttribute>
// to <aTargetAttribute>.
//=======================================================================
void TDF_RelocationTable::SetRelocation
(const Handle(TDF_Attribute)& aSourceAttribute,
const Handle(TDF_Attribute)& aTargetAttribute)
{
if (!myAttributeTable.IsBound(aSourceAttribute))
myAttributeTable.Bind(aSourceAttribute,aTargetAttribute);
}
//=======================================================================
//function : HasRelocation
//purpose : Finds the relocation value of <aSourceAttribute>
// and returns it into <aTargetAttribute>.
//=======================================================================
Standard_Boolean TDF_RelocationTable::HasRelocation
(const Handle(TDF_Attribute)& aSourceAttribute,
Handle(TDF_Attribute)& aTargetAttribute) const
{
aTargetAttribute.Nullify();
if (myAttributeTable.IsBound(aSourceAttribute)) {
aTargetAttribute = myAttributeTable.Find(aSourceAttribute);
return Standard_True;
}
if (mySelfRelocate) {
aTargetAttribute = aSourceAttribute;
return !myAfterRelocate;
}
return Standard_False;
}
//=======================================================================
//function : SetTransientRelocation
//purpose : Sets the relocation value of <aSourceTransient>
// to <aTargetTransient>.
//=======================================================================
void TDF_RelocationTable::SetTransientRelocation
(const Handle(Standard_Transient)& aSourceTransient,
const Handle(Standard_Transient)& aTargetTransient)
{
if (!myTransientTable.Contains(aSourceTransient))
myTransientTable.Add(aSourceTransient,aTargetTransient);
}
//=======================================================================
//function : HasTransientRelocation
//purpose : Finds the relocation value of <aSourceTransient>
// and returns it into <aTargetTransient>.
//=======================================================================
Standard_Boolean TDF_RelocationTable::HasTransientRelocation
(const Handle(Standard_Transient)& aSourceTransient,
Handle(Standard_Transient)& aTargetTransient) const
{
aTargetTransient.Nullify();
if (myTransientTable.Contains(aSourceTransient)) {
aTargetTransient = myTransientTable.FindFromKey(aSourceTransient);
return Standard_True;
}
if (mySelfRelocate) {
aTargetTransient = aSourceTransient;
return !myAfterRelocate;
}
return Standard_False;
}
//=======================================================================
//function : Clear
//purpose : Clears the relocation dictonnary.
//=======================================================================
void TDF_RelocationTable::Clear()
{
myLabelTable.Clear();
myAttributeTable.Clear();
myTransientTable.Clear();
}
//=======================================================================
//function : TargetLabelMap
//purpose :
//=======================================================================
void TDF_RelocationTable::TargetLabelMap(TDF_LabelMap& aLabelMap) const
{
for (TDF_DataMapIteratorOfLabelDataMap itr(myLabelTable);
itr.More(); itr.Next())
aLabelMap.Add(itr.Value());
}
//=======================================================================
//function : TargetAttributeMap
//purpose :
//=======================================================================
void TDF_RelocationTable::TargetAttributeMap(TDF_AttributeMap& anAttributeMap) const
{
for (TDF_DataMapIteratorOfAttributeDataMap itr(myAttributeTable);
itr.More(); itr.Next())
anAttributeMap.Add(itr.Value());
}
//=======================================================================
//function : LabelTable
//purpose :
//=======================================================================
TDF_LabelDataMap& TDF_RelocationTable::LabelTable()
{ return myLabelTable; }
//=======================================================================
//function : AttributeTable
//purpose :
//=======================================================================
TDF_AttributeDataMap& TDF_RelocationTable::AttributeTable()
{ return myAttributeTable; }
//=======================================================================
//function : TransientTable
//purpose :
//=======================================================================
TColStd_IndexedDataMapOfTransientTransient& TDF_RelocationTable::TransientTable()
{ return myTransientTable; }
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
Standard_OStream& TDF_RelocationTable::Dump
(const Standard_Boolean dumpLabels,
const Standard_Boolean dumpAttributes,
const Standard_Boolean dumpTransients,
Standard_OStream& anOS) const
{
anOS<<"Relocation Table ";
if (mySelfRelocate) anOS<<"IS"; else anOS<<"NOT";
anOS<<" self relocate ";
if (myAfterRelocate) anOS<<"WITH"; else anOS<<"WITHOUT";
anOS<<" after relocate"<<endl;
anOS<<"Nb labels="<<myLabelTable.Extent();
anOS<<" Nb attributes="<<myAttributeTable.Extent();
anOS<<" Nb transients="<<myTransientTable.Extent()<<endl;
Standard_Integer nb = 0;
if (dumpLabels) {
anOS<<"Label Table:"<<endl;
for (TDF_DataMapIteratorOfLabelDataMap itr(myLabelTable);
itr.More(); itr.Next()) {
++nb;
anOS<<nb<<" ";
itr.Key().EntryDump(anOS);
anOS<<"<=>";
itr.Value().EntryDump(anOS);
anOS<<"| ";
}
cout<<endl;
}
nb = 0;
if (dumpAttributes) {
anOS<<"Attribute Table:"<<endl;
for (TDF_DataMapIteratorOfAttributeDataMap itr(myAttributeTable);
itr.More(); itr.Next()) {
++nb;
anOS<<nb<<" ";
itr.Key()->Dump(anOS);
anOS<<"<=>";
itr.Value()->Dump(anOS);
anOS<<"| ";
anOS<<endl;
}
}
if (dumpTransients) {
anOS<<"Transient Table:"<<myTransientTable.Extent()<<" transient(s) in table."<<endl;
}
return anOS;
}

77
src/TDF/TDF_TagSource.cdl Executable file
View File

@@ -0,0 +1,77 @@
-- File: TDF_TagSource.cdl
-- Created: Mon Aug 4 15:32:05 1997
-- Author: VAUTHIER Jean-Claude
---Copyright: Matra Datavision 1997
class TagSource from TDF inherits Attribute from TDF
---Purpose: This attribute manage a tag provider to create
-- child labels of a given one.
uses GUID from Standard,
Attribute from TDF,
Label from TDF,
RelocationTable from TDF
is
---Purpose: class methods
-- =============
GetID (myclass)
---C++: return const &
returns GUID from Standard;
Set (myclass; label : Label from TDF)
---Purpose: Find, or create, a TagSource attribute. the TagSource
-- attribute is returned.
returns TagSource from TDF;
NewChild (myclass; L : Label from TDF)
---Purpose: Find (or create) a tagSource attribute located at <L>
-- and make a new child label.
returns Label from TDF;
---Purpose: TagSource methods
-- =================
Create
returns mutable TagSource from TDF;
NewTag (me : mutable)
returns Integer from Standard;
NewChild (me : mutable)
returns Label from TDF;
Get (me) returns Integer from Standard;
Set (me : mutable; T : Integer from Standard);
---Purpose: TDF_Attribute methods
-- =====================
ID (me)
---C++: return const &
returns GUID from Standard;
Restore (me: mutable; with : Attribute from TDF);
NewEmpty (me)
returns mutable Attribute from TDF;
Paste (me; Into : mutable Attribute from TDF;
RT : mutable RelocationTable from TDF);
fields
myTag : Integer from Standard;
end TagSource;

153
src/TDF/TDF_TagSource.cxx Executable file
View File

@@ -0,0 +1,153 @@
// File: TDF_TagSource.cxx
// Created: Mon Aug 4 16:26:55 1997
// Author: VAUTHIER Jean-Claude
#include <TDF_TagSource.ixx>
#include <Standard_GUID.hxx>
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& TDF_TagSource::GetID () {
static Standard_GUID TDF_TagSourceID("2a96b611-ec8b-11d0-bee7-080009dc3333");
return TDF_TagSourceID;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
Handle(TDF_TagSource) TDF_TagSource::Set (const TDF_Label& L) {
Handle(TDF_TagSource) T;
if (!L.FindAttribute (TDF_TagSource::GetID (), T)) {
T = new TDF_TagSource ();
L.AddAttribute (T);
}
return T;
}
//=======================================================================
//function : NewChild
//purpose :
//=======================================================================
TDF_Label TDF_TagSource::NewChild (const TDF_Label& L)
{
Handle(TDF_TagSource) T;
if (!L.FindAttribute(GetID(),T)) {
T = new TDF_TagSource();
L.AddAttribute(T);
}
return T->NewChild();
}
//=======================================================================
//function : TDF_TagSource
//purpose :
//=======================================================================
TDF_TagSource::TDF_TagSource () : myTag(0) { }
//=======================================================================
//function : NewTag
//purpose :
//=======================================================================
Standard_Integer TDF_TagSource::NewTag () {
Backup(); // FID 02/07/98
return ++myTag;
}
//=======================================================================
//function : NewChild
//purpose :
//=======================================================================
TDF_Label TDF_TagSource::NewChild () {
return Label().FindChild(NewTag(),Standard_True);
}
//=======================================================================
//function : Get
//purpose :
//=======================================================================
Standard_Integer TDF_TagSource::Get() const
{
return myTag;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void TDF_TagSource::Set (const Standard_Integer T) {
// OCC2932 correction
if(myTag == T) return;
Backup (); // FID 02/07/98
myTag = T;
}
//=======================================================================
//function : ID
//purpose :
//=======================================================================
const Standard_GUID& TDF_TagSource::ID() const { return GetID (); }
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) TDF_TagSource::NewEmpty () const
{
return new TDF_TagSource ();
}
//=======================================================================
//function : Restore
//purpose :
//=======================================================================
void TDF_TagSource::Restore(const Handle(TDF_Attribute)& With)
{
myTag = Handle(TDF_TagSource)::DownCast (With)->Get ();
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void TDF_TagSource::Paste (
const Handle(TDF_Attribute)& Into,
const Handle(TDF_RelocationTable)& RT) const
{
Handle(TDF_TagSource)::DownCast(Into)->Set (myTag);
}

226
src/TDF/TDF_Tool.cdl Executable file
View File

@@ -0,0 +1,226 @@
-- File: TDF_Tool.cdl
-- ------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Mar 13 1997 Creation
class Tool from TDF
---Purpose: This class provides general services for a data framework.
uses
Data from TDF,
Label from TDF,
LabelList from TDF,
LabelIntegerMap from TDF,
IDFilter from TDF,
AttributeList from TDF,
AttributeMap from TDF,
AttributeIndexedMap from TDF,
AsciiString from TCollection,
ListOfInteger from TColStd,
OStream from Standard
is
-- Objects counting ---------------------------------------------------
NbLabels(myclass;
aLabel : Label from TDF)
returns Integer from Standard;
---Purpose: Returns the number of labels of the tree,
-- including <aLabel>. aLabel is also included in this figure.
-- This information is useful in setting the size of an array.
NbAttributes(myclass;
aLabel : Label from TDF)
returns Integer from Standard;
---Purpose: Returns the total number of attributes attached
-- to the labels dependent on the label aLabel.
-- The attributes of aLabel are also included in this figure.
-- This information is useful in setting the size of an array.
NbAttributes(myclass;
aLabel : Label from TDF;
aFilter : IDFilter from TDF)
returns Integer from Standard;
---Purpose: Returns the number of attributes of the tree,
-- selected by a<Filter>, including those of
-- <aLabel>.
-- Self Contained Label -----------------------------------------------
IsSelfContained(myclass;
aLabel : Label from TDF)
returns Boolean from Standard;
---Purpose: Returns true if <aLabel> and its descendants
-- reference only attributes or labels attached to
-- themselves.
IsSelfContained(myclass;
aLabel : Label from TDF;
aFilter : IDFilter from TDF)
returns Boolean from Standard;
---Purpose: Returns true if <aLabel> and its descendants
-- reference only attributes or labels attached to
-- themselves and kept by <aFilter>.
OutReferers(myclass;
theLabel : Label from TDF;
theAtts : in out AttributeMap from TDF);
---Purpose: Returns in <theAtts> the attributes having out
-- references.
--
-- Caution: <theAtts> is not cleared before use!
OutReferers(myclass;
aLabel : Label from TDF;
aFilterForReferers : IDFilter from TDF;
aFilterForReferences : IDFilter from TDF;
atts : in out AttributeMap from TDF);
---Purpose: Returns in <atts> the attributes having out
-- references and kept by <aFilterForReferers>.
-- It considers only the references kept by <aFilterForReferences>.
-- Caution: <atts> is not cleared before use!
OutReferences(myclass;
aLabel : Label from TDF;
atts : in out AttributeMap from TDF);
---Purpose: Returns in <atts> the referenced attributes.
-- Caution: <atts> is not cleared before use!
OutReferences(myclass;
aLabel : Label from TDF;
aFilterForReferers : IDFilter from TDF;
aFilterForReferences : IDFilter from TDF;
atts : in out AttributeMap from TDF);
---Purpose: Returns in <atts> the referenced attributes and kept by <aFilterForReferences>.
-- It considers only the referers kept by <aFilterForReferers>.
-- Caution: <atts> is not cleared before use!
-- Label Relocation ---------------------------------------------------
RelocateLabel(myclass;
aSourceLabel, fromRoot, toRoot : Label from TDF;
aTargetLabel : in out Label from TDF;
create : Boolean from Standard = Standard_False);
---Purpose: Returns the label having the same sub-entry as
-- <aLabel> but located as descendant as <toRoot>
-- instead of <fromRoot>.
--
-- Exemple :
--
-- aLabel = 0:3:24:7:2:7
-- fromRoot = 0:3:24
-- toRoot = 0:5
-- returned label = 0:5:7:2:7
-- Label -> Entry -----------------------------------------------------
Entry(myclass;
aLabel : Label from TDF;
anEntry : in out AsciiString from TCollection);
---Purpose: Returns the entry for the label aLabel in the form
-- of the ASCII character string anEntry containing
-- the tag list for aLabel.
TagList(myclass;
aLabel : Label from TDF;
aTagList : in out ListOfInteger from TColStd);
---Purpose: Returns the entry of <aLabel> as list of integers
-- in <aTagList>.
TagList(myclass;
anEntry : AsciiString from TCollection;
aTagList : in out ListOfInteger from TColStd);
---Purpose: Returns the entry expressed by <anEntry> as list
-- of integers in <aTagList>.
-- Entry -> Label -----------------------------------------------------
Label(myclass;
aDF : Data from TDF;
anEntry : AsciiString from TCollection;
aLabel : in out Label from TDF;
create : Boolean from Standard = Standard_False);
---Purpose: Returns the label expressed by <anEntry>; creates
-- the label if it does not exist and if <create> is
-- true.
Label(myclass;
aDF : Data from TDF;
anEntry : CString from Standard;
aLabel : in out Label from TDF;
create : Boolean from Standard = Standard_False);
---Purpose: Returns the label expressed by <anEntry>; creates
-- the label if it does not exist and if <create> is
-- true.
Label(myclass;
aDF : Data from TDF;
aTagList : ListOfInteger from TColStd;
aLabel : in out Label from TDF;
create : Boolean from Standard = Standard_False);
---Purpose: Returns the label expressed by <anEntry>; creates
-- the label if it does not exist and if <create> is
-- true.
-- Label count --------------------------------------------------------
CountLabels(myclass;
aLabelList : in out LabelList from TDF;
aLabelMap : in out LabelIntegerMap from TDF);
---Purpose: Adds the labels of <aLabelList> to <aLabelMap> if
-- they are unbound, or increases their reference
-- counters. At the end of the process, <aLabelList>
-- contains only the ADDED labels.
DeductLabels(myclass;
aLabelList : in out LabelList from TDF;
aLabelMap : in out LabelIntegerMap from TDF);
---Purpose: Decreases the reference counters of the labels of
-- <aLabelList> to <aLabelMap>, and removes labels
-- with null counter. At the end of the process,
-- <aLabelList> contains only the SUPPRESSED labels.
-- Dump ---------------------------------------------------------------
DeepDump(myclass;
anOS : in out OStream from Standard;
aDF : Data from TDF);
---Purpose: Dumps <aDF> and its labels and their attributes.
ExtendedDeepDump(myclass;
anOS : in out OStream from Standard;
aDF : Data from TDF;
aFilter : IDFilter from TDF);
---Purpose: Dumps <aDF> and its labels and their attributes,
-- if their IDs are kept by <aFilter>. Dumps also the
-- attributes content.
DeepDump(myclass;
anOS : in out OStream from Standard;
aLabel : Label from TDF);
---Purpose: Dumps <aLabel>, its chilren and their attributes.
ExtendedDeepDump(myclass;
anOS : in out OStream from Standard;
aLabel : Label from TDF;
aFilter : IDFilter from TDF);
---Purpose: Dumps <aLabel>, its chilren and their attributes,
-- if their IDs are kept by <aFilter>. Dumps also the
-- attributes content.
end Tool;

652
src/TDF/TDF_Tool.cxx Executable file
View File

@@ -0,0 +1,652 @@
// File: TDF_Tool.cxx
// ------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Mar 13 1997 Creation
#include <TDF_Tool.ixx>
#include <TDF_MapIteratorOfLabelMap.hxx>
#include <TDF_MapIteratorOfAttributeMap.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_AttributeIndexedMap.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_DataSet.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
#include <TColStd_ListOfInteger.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#define TDF_TagSeparator ':'
static void TDF_Tool_ExtendedDeepDump(Standard_OStream& anOS,
const TDF_Label& aLabel,
const TDF_IDFilter& aFilter,
TDF_AttributeIndexedMap& aMap);
static Standard_Boolean TDF_Tool_DescendantRef(const TDF_Label& aRefLabel,
const TDF_Label& aLabel,
const TDF_IDFilter& aFilter,
const Handle(TDF_DataSet)& ds);
static void TDF_Tool_OutReferers(const TDF_Label& aRefLabel,
const TDF_Label& aLabel,
TDF_AttributeMap& atts,
const TDF_IDFilter& aFilterForReferers,
const TDF_IDFilter& aFilterForReferences,
const Handle(TDF_DataSet)& ds);
static void TDF_Tool_OutReferences(const TDF_Label& aRefLabel,
const TDF_Label& aLabel,
TDF_AttributeMap& atts,
const TDF_IDFilter& aFilterForReferers,
const TDF_IDFilter& aFilterForReferences,
const Handle(TDF_DataSet)& ds);
//=======================================================================
//function : NbLabels
//purpose : Returns the numbers of labels of the tree.
//=======================================================================
Standard_Integer TDF_Tool::NbLabels(const TDF_Label& aLabel)
{
Standard_Integer n = 1;
for (TDF_ChildIterator itr(aLabel,Standard_True); itr.More(); itr.Next())
++n;
return n;
}
//=======================================================================
//function : NbAttributes
//purpose : Returns the number of attributes of the tree.
//=======================================================================
Standard_Integer TDF_Tool::NbAttributes(const TDF_Label& aLabel)
{
Standard_Integer n = aLabel.NbAttributes();
for (TDF_ChildIterator itr(aLabel,Standard_True); itr.More(); itr.Next())
n += itr.Value().NbAttributes();
return n;
}
//=======================================================================
//function : NbAttributes
//purpose : Returns the number of attributes of the tree,
// selected by an IDFilter.
//=======================================================================
Standard_Integer TDF_Tool::NbAttributes
(const TDF_Label& aLabel,
const TDF_IDFilter& aFilter)
{
Standard_Integer n = 0;
TDF_AttributeIterator it2;
for (it2.Initialize(aLabel,Standard_True);it2.More();it2.Next())
if (aFilter.IsKept(it2.Value())) ++n;
for (TDF_ChildIterator it1(aLabel,Standard_True); it1.More(); it1.Next())
for (it2.Initialize(it1.Value(),Standard_True);it2.More();it2.Next())
if (aFilter.IsKept(it2.Value())) ++n;
return n;
}
//=======================================================================
//function : IsSelfContained
//purpose :
//=======================================================================
Standard_Boolean TDF_Tool::IsSelfContained(const TDF_Label& aLabel)
{
TDF_IDFilter filter(Standard_False); // Keep all.
return IsSelfContained(aLabel,filter);
}
//=======================================================================
//function : IsSelfContained
//purpose :
//=======================================================================
Standard_Boolean TDF_Tool::IsSelfContained
(const TDF_Label& aLabel,
const TDF_IDFilter& aFilter)
{
Handle(TDF_DataSet) ds = new TDF_DataSet();
if (!TDF_Tool_DescendantRef(aLabel,aLabel,aFilter,ds))
return Standard_False;
for (TDF_ChildIterator itr(aLabel,Standard_True);
itr.More();
itr.Next()) {
if (!TDF_Tool_DescendantRef(aLabel,itr.Value(),aFilter,ds))
return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : TDF_Tool_DescendantRef
//purpose :
//=======================================================================
static Standard_Boolean TDF_Tool_DescendantRef
(const TDF_Label& aRefLabel,
const TDF_Label& aLabel,
const TDF_IDFilter& aFilter,
const Handle(TDF_DataSet)& ds)
{
for (TDF_AttributeIterator itr(aLabel); itr.More(); itr.Next()) {
// CLE
// const Handle(TDF_Attribute)& labAtt = itr.Value();
Handle(TDF_Attribute) labAtt = itr.Value();
// ENDCLE
if (aFilter.IsKept(labAtt)) {
labAtt->References(ds);
// First of all, the referenced labels.
const TDF_LabelMap& labMap = ds->Labels();
for (TDF_MapIteratorOfLabelMap labMItr(labMap);
labMItr.More(); labMItr.Next()) {
if (!labMItr.Key().IsDescendant(aRefLabel))
return Standard_False;
}
// Then the referenced attributes.
const TDF_AttributeMap& attMap = ds->Attributes();
for (TDF_MapIteratorOfAttributeMap attMItr(attMap);
attMItr.More(); attMItr.Next()) {
// CLE
// const Handle(TDF_Attribute)& att = attMItr.Key();
Handle(TDF_Attribute) att = attMItr.Key();
// ENDCLE
if (aFilter.IsKept(att) && !att->Label().IsDescendant(aRefLabel))
return Standard_False;
}
ds->Clear();
}
}
return Standard_True;
}
//=======================================================================
//function : OutReferers
//purpose :
//=======================================================================
void TDF_Tool::OutReferers(const TDF_Label& aLabel,
TDF_AttributeMap& atts)
{
TDF_IDFilter filter(Standard_False); // Keep all.
OutReferers(aLabel,filter,filter,atts);
}
//=======================================================================
//function : OutReferers
//purpose :
//=======================================================================
void TDF_Tool::OutReferers(const TDF_Label& aLabel,
const TDF_IDFilter& aFilterForReferers,
const TDF_IDFilter& aFilterForReferences,
TDF_AttributeMap& atts)
{
Handle(TDF_DataSet) ds = new TDF_DataSet();
TDF_Tool_OutReferers(aLabel,aLabel,atts,aFilterForReferers,aFilterForReferences,ds);
for (TDF_ChildIterator itr(aLabel,Standard_True);itr.More();itr.Next()) {
TDF_Tool_OutReferers(aLabel,itr.Value(),atts,aFilterForReferers,aFilterForReferences,ds);
}
}
//=======================================================================
//function : TDF_Tool_OutReferers
//purpose :
//=======================================================================
static void TDF_Tool_OutReferers(const TDF_Label& aRefLabel,
const TDF_Label& aLabel,
TDF_AttributeMap& atts,
const TDF_IDFilter& aFilterForReferers,
const TDF_IDFilter& aFilterForReferences,
const Handle(TDF_DataSet)& ds)
{
Standard_Boolean outRefFound = Standard_False;
for (TDF_AttributeIterator itr(aLabel); itr.More(); itr.Next()) {
if (!aFilterForReferers.IsKept(itr.Value())) continue;
itr.Value()->References(ds);
const TDF_AttributeMap& attMap = ds->Attributes();
for (TDF_MapIteratorOfAttributeMap attMItr(attMap);
attMItr.More(); attMItr.Next()) {
// CLE
// const Handle(TDF_Attribute)& att = attMItr.Key();
Handle(TDF_Attribute) att = attMItr.Key();
// ENDCLE
if (aFilterForReferences.IsKept(att) && !att->Label().IsDescendant(aRefLabel)) {
atts.Add(itr.Value());
outRefFound = Standard_True;
break;
}
}
if (!outRefFound) {
const TDF_LabelMap& labMap = ds->Labels();
for (TDF_MapIteratorOfLabelMap labMItr(labMap);
labMItr.More(); labMItr.Next()) {
if (!labMItr.Key().IsDescendant(aRefLabel)) {
atts.Add(itr.Value());
break;
}
}
}
outRefFound = Standard_False;
ds->Clear();
}
}
//=======================================================================
//function : OutReferences
//purpose :
//=======================================================================
void TDF_Tool::OutReferences(const TDF_Label& aLabel,
TDF_AttributeMap& atts)
{
TDF_IDFilter filter(Standard_False); // Keep all.
OutReferences(aLabel,filter,filter,atts);
}
//=======================================================================
//function : OutReferences
//purpose :
//=======================================================================
void TDF_Tool::OutReferences(const TDF_Label& aLabel,
const TDF_IDFilter& aFilterForReferers,
const TDF_IDFilter& aFilterForReferences,
TDF_AttributeMap& atts)
{
Handle(TDF_DataSet) ds = new TDF_DataSet();
TDF_Tool_OutReferences(aLabel,aLabel,atts,aFilterForReferers,aFilterForReferences,ds);
for (TDF_ChildIterator itr(aLabel,Standard_True);itr.More();itr.Next()) {
TDF_Tool_OutReferences(aLabel,itr.Value(),atts,aFilterForReferers,aFilterForReferences,ds);
}
}
//=======================================================================
//function : TDF_Tool_OutReferences
//purpose :
//=======================================================================
static void TDF_Tool_OutReferences(const TDF_Label& aRefLabel,
const TDF_Label& aLabel,
TDF_AttributeMap& atts,
const TDF_IDFilter& aFilterForReferers,
const TDF_IDFilter& aFilterForReferences,
const Handle(TDF_DataSet)& ds)
{
for (TDF_AttributeIterator itr(aLabel); itr.More(); itr.Next()) {
if (!aFilterForReferers.IsKept(itr.Value())) continue;
itr.Value()->References(ds);
const TDF_AttributeMap& attMap = ds->Attributes();
for (TDF_MapIteratorOfAttributeMap attMItr(attMap);attMItr.More();attMItr.Next()) {
Handle(TDF_Attribute) att = attMItr.Key();
if (aFilterForReferences.IsKept(att) && !att->Label().IsDescendant(aRefLabel)) {
atts.Add(att);
}
}
const TDF_LabelMap& labMap = ds->Labels();
for (TDF_MapIteratorOfLabelMap labMItr(labMap);labMItr.More();labMItr.Next()) {
if (!labMItr.Key().IsDescendant(aRefLabel)) {
TDF_AttributeIterator itra(labMItr.Key());
for (; itra.More(); itra.Next()) {
if (aFilterForReferences.IsKept(itra.Value())) {
atts.Add(itra.Value());
}
}
}
}
}
ds->Clear();
}
//=======================================================================
//function : RelocateLabel
//purpose :
//=======================================================================
void TDF_Tool::RelocateLabel
(const TDF_Label& aSourceLabel,
const TDF_Label& fromRoot,
const TDF_Label& toRoot,
TDF_Label& aTargetLabel,
const Standard_Boolean create)
{
if (!aSourceLabel.IsDescendant(fromRoot)) return;
aTargetLabel.Nullify();
TColStd_ListOfInteger labelTags;
TDF_Tool::TagList(aSourceLabel,labelTags);
TColStd_ListOfInteger toTags;
TDF_Tool::TagList(toRoot,toTags);
for (Standard_Integer i = fromRoot.Depth(); i >= 0; --i)
labelTags.RemoveFirst();
labelTags.Prepend(toTags);
TDF_Tool::Label(toRoot.Data(),labelTags,aTargetLabel,create);
}
//=======================================================================
//function : Entry
//purpose : Returns the entry as an ascii string.
//=======================================================================
void TDF_Tool::Entry
(const TDF_Label& aLabel,
TCollection_AsciiString& anEntry)
{
anEntry.Clear();
if (!aLabel.IsNull()) {
TColStd_ListOfInteger Tags;
TDF_Tool::TagList(aLabel, Tags);
anEntry += TCollection_AsciiString(Tags.First());
Tags.RemoveFirst();
if (Tags.IsEmpty()) {
anEntry += TDF_TagSeparator; // It must be the root label case.
}
else {
while (!Tags.IsEmpty()) {
anEntry += TDF_TagSeparator;
anEntry += TCollection_AsciiString(Tags.First());
Tags.RemoveFirst();
}
}
}
}
//=======================================================================
//function : TagList
//purpose : Returns the entry of a label as a list of integers.
//=======================================================================
void TDF_Tool::TagList
(const TDF_Label& aLabel,
TColStd_ListOfInteger& aTagList)
{
aTagList.Clear();
if (!aLabel.IsNull()) {
TDF_Label Label = aLabel;
for (;;) {
aTagList.Prepend(Label.Tag());
if (Label.IsRoot()) break;
Label = Label.Father();
}
}
}
//=======================================================================
//function : TagList
//purpose : Returns the entry expressed as a string as a list of integers.
//=======================================================================
void TDF_Tool::TagList
(const TCollection_AsciiString& anEntry,
TColStd_ListOfInteger& aTagList)
{
char* cc = (char *)anEntry.ToCString();
Standard_Integer n = 0;
aTagList.Clear();
while (*cc != '\0') {
while ( *cc >= '0' && *cc <= '9') {
n = 10*n + (*cc - '0');
++cc;
}
if (*cc == TDF_TagSeparator || *cc == '\0') {
aTagList.Append(n);
n = 0;
if (*cc != '\0') ++cc;
}
else { // Not an entry!
aTagList.Clear();
break;
}
}
}
//=======================================================================
//function : Label
//purpose : Returns the label expressed by <anEntry>.
//=======================================================================
void TDF_Tool::Label
(const Handle(TDF_Data)& aDF,
const TCollection_AsciiString& anEntry,
TDF_Label& aLabel,
const Standard_Boolean create)
{ TDF_Tool::Label(aDF,anEntry.ToCString(),aLabel,create); }
//=======================================================================
//function : Label
//purpose : Returns the label expressed by <anEntry>,
// and creates it if <create> is true.
//=======================================================================
void TDF_Tool::Label
(const Handle(TDF_Data)& aDF,
const Standard_CString anEntry,
TDF_Label& aLabel,
const Standard_Boolean create)
{
TColStd_ListOfInteger tagList;
TDF_Tool::TagList(anEntry,tagList);
TDF_Tool::Label(aDF,tagList,aLabel,create);
}
//=======================================================================
//function : Label
//purpose : Returns the label expressed by <anEntry>,
// and creates it if <create> is true.
//=======================================================================
void TDF_Tool::Label
(const Handle(TDF_Data)& aDF,
const TColStd_ListOfInteger& aTagList,
TDF_Label& aLabel,
const Standard_Boolean create)
{
if (aTagList.Extent() == 0) {
aLabel.Nullify();
}
else {
aLabel = aDF->Root();
if (aTagList.Extent() == 1 && aTagList.First() == 0) return;
else {
TColStd_ListIteratorOfListOfInteger tagItr (aTagList);
tagItr.Next(); // Suppresses root tag.
for (; !aLabel.IsNull() && tagItr.More(); tagItr.Next()) {
aLabel = aLabel.FindChild(tagItr.Value(),create);
}
}
}
}
//=======================================================================
//function : CountLabels
//purpose :
//=======================================================================
void TDF_Tool::CountLabels
(TDF_LabelList& aLabelList,
TDF_LabelIntegerMap& aLabelMap)
{
if (aLabelList.IsEmpty()) return;
Standard_Boolean next = Standard_True;
TDF_ListIteratorOfLabelList itr(aLabelList);
while (itr.More()) {
const TDF_Label& lab = itr.Value();
if (aLabelMap.IsBound(lab)) {
aLabelMap(lab) += 1;
aLabelList.Remove(itr);
next = Standard_False;
}
else {
aLabelMap.Bind(lab,1);
next = itr.More();
}
if (next && !aLabelList.IsEmpty()) itr.Next();
}
}
//=======================================================================
//function : DeductLabels
//purpose :
//=======================================================================
void TDF_Tool::DeductLabels
(TDF_LabelList& aLabelList,
TDF_LabelIntegerMap& aLabelMap)
{
if (aLabelList.IsEmpty()) return;
Standard_Boolean next = Standard_True;
TDF_ListIteratorOfLabelList itr(aLabelList);
while (itr.More()) {
const TDF_Label& lab = itr.Value();
if (aLabelMap.IsBound(lab)) {
aLabelMap(lab) -= 1;
if (aLabelMap(lab) == 0) {
aLabelMap.UnBind(lab);
aLabelList.Remove(itr);
next = Standard_False;
}
}
else next = itr.More();
if (next && !aLabelList.IsEmpty()) itr.Next();
}
}
//=======================================================================
//function : DeepDump
//purpose : Deep dump of a DF.
//=======================================================================
void TDF_Tool::DeepDump
(Standard_OStream& anOS,
const Handle(TDF_Data)& aDF)
{
anOS<<aDF;
TDF_Tool::DeepDump(anOS,aDF->Root());
}
//=======================================================================
//function : ExtendedDeepDump
//purpose : Extended deep dump of a DF.
//=======================================================================
void TDF_Tool::ExtendedDeepDump
(Standard_OStream& anOS,
const Handle(TDF_Data)& aDF,
const TDF_IDFilter& aFilter)
{
anOS<<aDF;
TDF_Tool::ExtendedDeepDump(anOS,aDF->Root(),aFilter);
}
//=======================================================================
//function : DeepDump
//purpose : Deep dump of a label.
//=======================================================================
void TDF_Tool::DeepDump
(Standard_OStream& anOS,
const TDF_Label& aLabel)
{
// Dumps the label.
anOS<<aLabel;
// Its children
for (TDF_ChildIterator ChildIt(aLabel); ChildIt.More (); ChildIt.Next ()) {
TDF_Tool::DeepDump(anOS,ChildIt.Value());
}
}
//=======================================================================
//function : ExtendedDeepDump
//purpose : Extended deep dump of a label.
//=======================================================================
void TDF_Tool::ExtendedDeepDump
(Standard_OStream& anOS,
const TDF_Label& aLabel,
const TDF_IDFilter& aFilter)
{
TDF_AttributeIndexedMap map;
TDF_Tool_ExtendedDeepDump(anOS,aLabel,aFilter,map);
anOS<<map.Extent()<<" attribute"; if (map.Extent()>1) anOS<<"s";
anOS<<" referenced by the label structure."<<endl;
anOS<<endl<<"Extended dump of filtered attribute(s):"<<endl;
Standard_Integer nba = 0;
TCollection_AsciiString entry;
Standard_Integer i ;
for ( i = 1; i<= map.Extent(); ++i) {
const Handle(TDF_Attribute)& att = map.FindKey(i);
if (aFilter.IsKept(att)) {
++nba;
anOS<<"# "<<i;
if (att->Label().IsNull()) {
anOS<<" (no label)"<<endl;
}
else {
TDF_Tool::Entry(att->Label(),entry);
anOS<<" (label: "<<entry<<")"<<endl;
}
att->ExtendedDump(anOS,aFilter,map); anOS<<endl;
}
}
anOS<<endl<<nba<<" attribute";
if (nba>1) anOS<<"s";
anOS<<" dumped between "<<--i<<endl;
}
//=======================================================================
//function : ExtendedDeepDump
//purpose : Internal method.
//=======================================================================
static void TDF_Tool_ExtendedDeepDump
(Standard_OStream& anOS,
const TDF_Label& aLabel,
const TDF_IDFilter& aFilter,
TDF_AttributeIndexedMap& aMap)
{
// Dumps the label.
aLabel.ExtendedDump(anOS,aFilter,aMap);
// Its children
for (TDF_ChildIterator ChildIt(aLabel); ChildIt.More (); ChildIt.Next ()) {
TDF_Tool_ExtendedDeepDump(anOS,ChildIt.Value(),aFilter,aMap);
}
}

109
src/TDF/TDF_Transaction.cdl Executable file
View File

@@ -0,0 +1,109 @@
-- File: TDF_Transaction.cdl
-- -------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Oct 1 1997 Creation
class Transaction from TDF
---Purpose: This class offers services to open, commit or
-- abort a transaction in a more secure way than
-- using Data from TDF. If you forget to close a
-- transaction, it will be automaticaly aborted at
-- the destruction of this object, at the closure of
-- its scope.
--
-- In case of catching errors, the effect will be the
-- same: aborting transactions until the good current
-- one.
uses
Data from TDF,
Delta from TDF,
AsciiString from TCollection
raises
DomainError, NullObject from Standard
is
Create(aName : AsciiString from TCollection = "")
returns Transaction from TDF;
---Purpose: Creates an empty transaction context, unable to be
-- opened.
Create(aTrans : Transaction from TDF)
returns Transaction from TDF
is private;
---Purpose: Private to avoid copy.
Create(aDF : Data from TDF;
aName : AsciiString from TCollection = "")
returns Transaction from TDF;
---Purpose: Creates a transaction context on <aDF>, ready to
-- be opened.
Initialize(me : in out; aDF : Data from TDF);
---Purpose: Aborts all the transactions on <myDF> and sets
-- <aDF> to build a transaction context on <aDF>,
-- ready to be opened.
Open(me : in out)
returns Integer from Standard
raises DomainError, NullObject from Standard;
---Purpose: If not yet done, opens a new transaction on
-- <myDF>. Returns the index of the just opened
-- transaction.
--
-- It raises DomainError if the transaction is
-- already open, and NullObject if there is no
-- current Data framework.
Commit(me : in out;
withDelta : Boolean from Standard = Standard_False)
returns Delta from TDF;
---Purpose: Commits the transactions until AND including the
-- current opened one.
Abort(me : in out);
---Purpose: Aborts the transactions until AND including the
-- current opened one.
--
---C++: alias ~
Data(me) returns Data from TDF;
---Purpose: Returns the Data from TDF.
--
---C++: inline
Transaction(me) returns Integer from Standard;
---Purpose: Returns the number of the transaction opened by <me>.
--
---C++: inline
Name(me) returns AsciiString from TCollection;
---Purpose: Returns the transaction name.
--
---C++: return const &
IsOpen(me)
returns Boolean from Standard;
---Purpose: Returns true if the transaction is open.
--
---C++: inline
fields
myDF : Data from TDF;
myUntilTransaction : Integer from Standard;
myName : AsciiString from TCollection;
end Transaction;

148
src/TDF/TDF_Transaction.cxx Executable file
View File

@@ -0,0 +1,148 @@
// File: TDF_Transaction.cxx
// -------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Oct 1 1997 Creation
#include <TDF_Transaction.ixx>
#undef DEB_TRANSACTION
#ifdef DEB
#define DEB_TRANSACTION
#endif
#undef DEB_TRANSACTION_DUMP
#include <TDF_Tool.hxx>
//=======================================================================
//function : TDF_Transaction
//purpose :
//=======================================================================
TDF_Transaction::TDF_Transaction
(const TCollection_AsciiString& aName)
: myUntilTransaction(0),
myName(aName)
{}
//=======================================================================
//function : TDF_Transaction
//purpose : Private copy constructor.
//=======================================================================
TDF_Transaction::TDF_Transaction(const TDF_Transaction& aTrans)
{}
//=======================================================================
//function : TDF_Transaction
//purpose :
//=======================================================================
TDF_Transaction::TDF_Transaction
(const Handle(TDF_Data)& aDF,
const TCollection_AsciiString& aName)
: myDF(aDF),
myUntilTransaction(0),
myName(aName)
{}
//=======================================================================
//function : Initialize
//purpose : Initializes a transaction ready to be opened.
//=======================================================================
void TDF_Transaction::Initialize(const Handle(TDF_Data)& aDF)
{
if (IsOpen()) myDF->AbortUntilTransaction(myUntilTransaction);
myDF = aDF;
myUntilTransaction = 0;
}
//=======================================================================
//function : Open
//purpose :
//=======================================================================
Standard_Integer TDF_Transaction::Open()
{
#ifdef DEB_TRANSACTION
cout<<"Transaction "<<myName<<" opens #"<<myDF->Transaction()+1<<endl;
#endif
if (IsOpen())
Standard_DomainError::Raise("This transaction is already open.");
if (myDF.IsNull())
Standard_NullObject::Raise("Null TDF_Data.");
return myUntilTransaction = myDF->OpenTransaction();
}
//=======================================================================
//function : Commit
//purpose :
//=======================================================================
Handle(TDF_Delta) TDF_Transaction::Commit(const Standard_Boolean withDelta)
{
#ifdef DEB_TRANSACTION
cout<<"Transaction "<<myName<<" commits ";
#endif
Handle(TDF_Delta) delta;
if (IsOpen()) {
#ifdef DEB_TRANSACTION
cout<<"from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<endl;
#endif
#ifdef DEB_TRANSACTION_DUMP
cout<<"DF before commit"<<endl;
TDF_Tool::DeepDump(cout,myDF);
#endif
Standard_Integer until = myUntilTransaction;
myUntilTransaction = 0;
delta = myDF->CommitUntilTransaction(until, withDelta);
#ifdef DEB_TRANSACTION_DUMP
cout<<"DF after commit"<<endl;
TDF_Tool::DeepDump(cout,myDF);
#endif
}
#ifdef DEB_TRANSACTION
else cout<<"but this transaction is not open!"<<endl;
#endif
return delta;
}
//=======================================================================
//function : Abort
//purpose : alias ~
//=======================================================================
void TDF_Transaction::Abort()
{
if (IsOpen()) {
#ifdef DEB_TRANSACTION
cout<<"Transaction "<<myName<<" aborts from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<endl;
#endif
#ifdef DEB_TRANSACTION_DUMP
cout<<"DF before abort"<<endl;
TDF_Tool::DeepDump(cout,myDF);
#endif
myDF->AbortUntilTransaction(myUntilTransaction);
myUntilTransaction = 0;
#ifdef DEB_TRANSACTION_DUMP
cout<<"DF after abort"<<endl;
TDF_Tool::DeepDump(cout,myDF);
#endif
}
}

23
src/TDF/TDF_Transaction.lxx Executable file
View File

@@ -0,0 +1,23 @@
// File: TDF_Transaction.lxx
// -------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Oct 1 1997 Creation
inline Handle(TDF_Data) TDF_Transaction::Data() const
{ return myDF; }
inline Standard_Integer TDF_Transaction::Transaction() const
{ return myUntilTransaction; }
inline const TCollection_AsciiString& TDF_Transaction::Name() const
{ return myName; }
inline Standard_Boolean TDF_Transaction::IsOpen() const
{ return myUntilTransaction > 0; }