1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
23 //Version Date Purpose
24 // 0.0 Sep 15 1997 Creation
28 #include <TDocStd_XLink.ixx>
30 #include <Standard_NotImplemented.hxx>
31 #include <TDF_DeltaOnAddition.hxx>
32 #include <TDF_DeltaOnRemoval.hxx>
33 #include <TDF_Tool.hxx>
34 #include <TDF_Reference.hxx>
35 #include <TDocStd.hxx>
36 #include <TDocStd_Document.hxx>
37 #include <TDocStd_XLinkRoot.hxx>
40 //=======================================================================
41 //function : TDocStd_XLink
43 //=======================================================================
45 TDocStd_XLink::TDocStd_XLink()
50 //=======================================================================
52 //purpose : Class method.
53 //=======================================================================
55 Handle(TDocStd_XLink) TDocStd_XLink::Set (const TDF_Label& atLabel)
57 Handle(TDocStd_XLink) xRef;
58 if (!atLabel.FindAttribute(TDocStd_XLink::GetID(),xRef)) {
59 xRef = new TDocStd_XLink;
60 atLabel.AddAttribute(xRef);
65 //=======================================================================
68 //=======================================================================
70 Handle(TDF_Reference) TDocStd_XLink::Update ()
73 Handle(TDocStd_Document) refdoc;
74 Standard_Integer IEntry = myDocEntry.IntegerValue();
75 Handle(TDocStd_Document) mydoc = TDocStd_Document::Get(Label()); //mon document
76 refdoc = Handle(TDocStd_Document)::DownCast(mydoc->Document(IEntry));
77 TDF_Tool::Label(refdoc->GetData(),myLabelEntry,reflabel);
78 // return TXLink::Import(reflabel,Label());
79 return TDF_Reference::Set(Label(),reflabel);
83 //=======================================================================
86 //=======================================================================
88 const Standard_GUID& TDocStd_XLink::ID() const
92 //=======================================================================
95 //======================================================================
97 const Standard_GUID& TDocStd_XLink::GetID()
99 static Standard_GUID myID("5d587400-5690-11d1-8940-080009dc3333");
104 //=======================================================================
105 //function : DocumentEntry
107 //=======================================================================
109 void TDocStd_XLink::DocumentEntry
110 (const TCollection_AsciiString& aDocEntry)
111 { Backup(); myDocEntry = aDocEntry; }
114 //=======================================================================
115 //function : DocumentEntry
117 //=======================================================================
119 const TCollection_AsciiString& TDocStd_XLink::DocumentEntry() const
120 { return myDocEntry; }
123 //=======================================================================
124 //function : LabelEntry
126 //=======================================================================
128 void TDocStd_XLink::LabelEntry
129 (const TDF_Label& aLabel)
132 TDF_Tool::Entry(aLabel,myLabelEntry);
136 //=======================================================================
137 //function : LabelEntry
139 //=======================================================================
141 void TDocStd_XLink::LabelEntry
142 (const TCollection_AsciiString& aLabEntry)
143 { Backup(); myLabelEntry = aLabEntry; }
146 //=======================================================================
147 //function : LabelEntry
149 //=======================================================================
151 const TCollection_AsciiString& TDocStd_XLink::LabelEntry() const
152 { return myLabelEntry; }
155 //=======================================================================
156 //function : AfterAddition
158 //=======================================================================
160 void TDocStd_XLink::AfterAddition()
162 TDocStd_XLinkRoot::Insert(this);
163 Label().Imported(Standard_True);
167 //=======================================================================
168 //function : BeforeRemoval
170 //=======================================================================
172 void TDocStd_XLink::BeforeRemoval()
175 TDocStd_XLinkRoot::Remove(this);
176 Label().Imported(Standard_False);
181 //=======================================================================
182 //function : BeforeUndo
183 //purpose : Before application of a TDF_Delta.
184 //=======================================================================
186 Standard_Boolean TDocStd_XLink::BeforeUndo
187 (const Handle(TDF_AttributeDelta)& anAttDelta,
188 const Standard_Boolean /*forceIt*/)
190 if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
191 anAttDelta->Attribute()->BeforeRemoval();
193 return Standard_True;
197 //=======================================================================
198 //function : AfterUndo
199 //purpose : After application of a TDF_Delta.
200 //=======================================================================
202 Standard_Boolean TDocStd_XLink::AfterUndo
203 (const Handle(TDF_AttributeDelta)& anAttDelta,
204 const Standard_Boolean /*forceIt*/)
206 if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnRemoval))) {
207 anAttDelta->Attribute()->AfterAddition();
209 return Standard_True;
213 //=======================================================================
214 //function : BackupCopy
216 //=======================================================================
218 Handle(TDF_Attribute) TDocStd_XLink::BackupCopy() const
220 Handle(TDocStd_XLink) xRef = new TDocStd_XLink();
221 xRef->DocumentEntry(myDocEntry);
222 xRef->LabelEntry(myLabelEntry);
227 //=======================================================================
230 //=======================================================================
232 void TDocStd_XLink::Restore(const Handle(TDF_Attribute)& anAttribute)
234 const Handle(TDocStd_XLink)& xRef =
235 Handle(TDocStd_XLink)::DownCast(anAttribute);
236 if (!xRef.IsNull()) {
237 myDocEntry = xRef->DocumentEntry();
238 myLabelEntry = xRef->LabelEntry();
243 //=======================================================================
244 //function : NewEmpty
246 //=======================================================================
248 Handle(TDF_Attribute) TDocStd_XLink::NewEmpty() const
249 { return new TDocStd_XLink(); }
252 //=======================================================================
255 //=======================================================================
257 void TDocStd_XLink::Paste
258 (const Handle(TDF_Attribute)& intoAttribute,
259 const Handle(TDF_RelocationTable)& /*aRelocationTable*/) const
261 const Handle(TDocStd_XLink)& xRef =
262 Handle(TDocStd_XLink)::DownCast(intoAttribute);
263 if (!xRef.IsNull()) {
264 xRef->DocumentEntry(myDocEntry);
265 xRef->LabelEntry(myLabelEntry);
270 //=======================================================================
273 //=======================================================================
275 Standard_OStream& TDocStd_XLink::Dump(Standard_OStream& anOS) const