1 // Created on: 2004-11-23
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // The original implementation Copyright: (C) RINA S.p.A
18 #ifndef TObj_TReference_HeaderFile
19 #define TObj_TReference_HeaderFile
21 #include <TObj_Common.hxx>
22 #include <TDF_Attribute.hxx>
23 #include <TDF_Label.hxx>
29 * Attribute for storing references to the objects which implement
30 * TObj_Object interface in the OCAF tree.
31 * Its persistency mechanism provides transparent method for storing
32 * cross-model references.
33 * Each reference, when created, registers itself in the referred object,
34 * to support back references
37 class TObj_TReference : public TDF_Attribute
40 //! Standard methods of OCAF attribute
43 Standard_EXPORT TObj_TReference();
45 //! This method is used in implementation of ID()
46 static Standard_EXPORT const Standard_GUID& GetID();
48 //! Returns the ID of TObj_TReference attribute.
49 Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
52 //! Method for create TObj_TReference object
54 //! Creates reference on TDF_Label <theLabel> to the object <theObject> and
55 //! creates backreference from the object <theObject> to <theMaster> one.
56 static Standard_EXPORT Handle(TObj_TReference) Set
57 (const TDF_Label& theLabel,
58 const Handle(TObj_Object)& theObject,
59 const Handle(TObj_Object)& theMaster);
62 //! Methods for setting and obtaining referenced object
64 //! Sets the reference to the theObject
65 Standard_EXPORT void Set(const Handle(TObj_Object)& theObject,
66 const TDF_Label& theMasterLabel);
68 //! Sets the reference to the theObject at indicated Label.
69 //! It is method for persistent only. Don`t use anywhere else.
70 Standard_EXPORT void Set(const TDF_Label& theLabel,
71 const TDF_Label& theMasterLabel);
73 //! Returns the referenced theObject
74 Standard_EXPORT Handle(TObj_Object) Get() const;
76 //! Returns the Label of master object.
77 TDF_Label GetMasterLabel() const {return myMasterLabel;}
79 //! Returns the referred label.
80 TDF_Label GetLabel() const {return myLabel;}
83 //! Redefined OCAF abstract methods
85 //! Returns an new empty TObj_TReference attribute. It is used by the
87 Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
89 //! Restores the backuped contents from <theWith> into this one. It is used
90 //! when aborting a transaction.
91 Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theWith) Standard_OVERRIDE;
93 //! This method is used when copying an attribute from a source structure
94 //! into a target structure.
95 Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theInto,
96 const Handle(TDF_RelocationTable)& theRT) const Standard_OVERRIDE;
98 //! Remove back references of it reference if it is in other document.
99 virtual Standard_EXPORT void BeforeForget() Standard_OVERRIDE;
101 //! It is necessary for tranzaction mechanism (Undo/Redo).
102 virtual Standard_EXPORT Standard_Boolean BeforeUndo
103 (const Handle(TDF_AttributeDelta)& theDelta,
104 const Standard_Boolean isForced = Standard_False) Standard_OVERRIDE;
106 //! It is necessary for tranzaction mechanism (Undo/Redo).
107 virtual Standard_EXPORT Standard_Boolean AfterUndo
108 (const Handle(TDF_AttributeDelta)& theDelta,
109 const Standard_Boolean isForced = Standard_False) Standard_OVERRIDE;
111 //! Check if back reference exists for reference.
112 virtual Standard_EXPORT void AfterResume() Standard_OVERRIDE;
114 //! Called after retrieval reference from file.
115 virtual Standard_EXPORT Standard_Boolean AfterRetrieval
116 (const Standard_Boolean forceIt = Standard_False) Standard_OVERRIDE;
120 TDF_Label myLabel; //!< Label that indicate referenced object
121 TDF_Label myMasterLabel; //!< Label of object that have this reference.
125 DEFINE_STANDARD_RTTIEXT(TObj_TReference,TDF_Attribute)
128 //! Define handle class for TObj_TReference
129 DEFINE_STANDARD_HANDLE(TObj_TReference,TDF_Attribute)