0024057: Eliminate compiler warning C4100 in MSVC++ with warning level 4
[occt.git] / src / TDocStd / TDocStd_XLink.cxx
1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 //
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.
9 //
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.
12 //
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.
19
20 //              --------------
21
22 // Version:     0.0
23 //Version       Date            Purpose
24 //              0.0     Sep 15 1997     Creation
25
26
27
28 #include <TDocStd_XLink.ixx>
29
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>
38
39
40 //=======================================================================
41 //function : TDocStd_XLink
42 //purpose  : 
43 //=======================================================================
44
45 TDocStd_XLink::TDocStd_XLink()
46 : myNext(NULL)
47 {}
48
49
50 //=======================================================================
51 //function : Set
52 //purpose  : Class method.
53 //=======================================================================
54
55 Handle(TDocStd_XLink) TDocStd_XLink::Set (const TDF_Label& atLabel) 
56 {
57   Handle(TDocStd_XLink) xRef;
58   if (!atLabel.FindAttribute(TDocStd_XLink::GetID(),xRef)) {
59     xRef = new TDocStd_XLink;  
60     atLabel.AddAttribute(xRef);
61   }
62   return xRef;
63 }
64
65 //=======================================================================
66 //function : Update
67 //purpose  : 
68 //=======================================================================
69
70 Handle(TDF_Reference) TDocStd_XLink::Update ()
71 {
72   TDF_Label reflabel;  
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);
80 }
81
82
83 //=======================================================================
84 //function : ID
85 //purpose  : 
86 //=======================================================================
87
88 const Standard_GUID& TDocStd_XLink::ID() const
89 { return GetID(); }
90
91
92 //=======================================================================
93 //function : GetID
94 //purpose  : 
95 //======================================================================
96
97 const Standard_GUID& TDocStd_XLink::GetID() 
98 {
99   static Standard_GUID myID("5d587400-5690-11d1-8940-080009dc3333");
100   return myID;
101 }
102
103
104 //=======================================================================
105 //function : DocumentEntry
106 //purpose  : 
107 //=======================================================================
108
109 void TDocStd_XLink::DocumentEntry
110 (const TCollection_AsciiString& aDocEntry) 
111 { Backup(); myDocEntry = aDocEntry; }
112
113
114 //=======================================================================
115 //function : DocumentEntry
116 //purpose  : 
117 //=======================================================================
118
119 const TCollection_AsciiString& TDocStd_XLink::DocumentEntry() const
120 { return myDocEntry; }
121
122
123 //=======================================================================
124 //function : LabelEntry
125 //purpose  : 
126 //=======================================================================
127
128 void TDocStd_XLink::LabelEntry
129 (const TDF_Label& aLabel) 
130 {
131   Backup();
132   TDF_Tool::Entry(aLabel,myLabelEntry);
133 }
134
135
136 //=======================================================================
137 //function : LabelEntry
138 //purpose  : 
139 //=======================================================================
140
141 void TDocStd_XLink::LabelEntry
142 (const TCollection_AsciiString& aLabEntry) 
143 { Backup(); myLabelEntry = aLabEntry; }
144
145
146 //=======================================================================
147 //function : LabelEntry
148 //purpose  : 
149 //=======================================================================
150
151 const TCollection_AsciiString& TDocStd_XLink::LabelEntry() const
152 { return myLabelEntry; }
153
154
155 //=======================================================================
156 //function : AfterAddition
157 //purpose  : 
158 //=======================================================================
159
160 void TDocStd_XLink::AfterAddition() 
161 {
162   TDocStd_XLinkRoot::Insert(this);
163   Label().Imported(Standard_True);
164 }
165
166
167 //=======================================================================
168 //function : BeforeRemoval
169 //purpose  : 
170 //=======================================================================
171
172 void TDocStd_XLink::BeforeRemoval() 
173 {
174   if (!IsBackuped()) {
175     TDocStd_XLinkRoot::Remove(this);
176     Label().Imported(Standard_False);
177   }
178 }
179
180
181 //=======================================================================
182 //function : BeforeUndo
183 //purpose  : Before application of a TDF_Delta.
184 //=======================================================================
185
186 Standard_Boolean TDocStd_XLink::BeforeUndo
187 (const Handle(TDF_AttributeDelta)& anAttDelta,
188  const Standard_Boolean /*forceIt*/)
189 {
190   if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
191     anAttDelta->Attribute()->BeforeRemoval();
192   }
193   return Standard_True;
194 }
195
196
197 //=======================================================================
198 //function : AfterUndo
199 //purpose  : After application of a TDF_Delta.
200 //=======================================================================
201
202 Standard_Boolean TDocStd_XLink::AfterUndo
203 (const Handle(TDF_AttributeDelta)& anAttDelta,
204  const Standard_Boolean /*forceIt*/)
205 {
206   if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnRemoval))) {
207     anAttDelta->Attribute()->AfterAddition();
208   }
209   return Standard_True;
210 }
211
212
213 //=======================================================================
214 //function : BackupCopy
215 //purpose  : 
216 //=======================================================================
217
218 Handle(TDF_Attribute) TDocStd_XLink::BackupCopy() const
219 {
220   Handle(TDocStd_XLink) xRef = new TDocStd_XLink();
221   xRef->DocumentEntry(myDocEntry);
222   xRef->LabelEntry(myLabelEntry);
223   return xRef;
224 }
225
226
227 //=======================================================================
228 //function : Restore
229 //purpose  : 
230 //=======================================================================
231
232 void TDocStd_XLink::Restore(const Handle(TDF_Attribute)& anAttribute) 
233 {
234   const Handle(TDocStd_XLink)& xRef =
235     Handle(TDocStd_XLink)::DownCast(anAttribute);
236   if (!xRef.IsNull()) {
237     myDocEntry = xRef->DocumentEntry();
238     myLabelEntry = xRef->LabelEntry();
239   }
240 }
241
242
243 //=======================================================================
244 //function : NewEmpty
245 //purpose  : 
246 //=======================================================================
247
248 Handle(TDF_Attribute) TDocStd_XLink::NewEmpty() const
249 { return new TDocStd_XLink(); }
250
251
252 //=======================================================================
253 //function : Paste
254 //purpose  : 
255 //=======================================================================
256
257 void TDocStd_XLink::Paste
258 (const Handle(TDF_Attribute)& intoAttribute,
259  const Handle(TDF_RelocationTable)& /*aRelocationTable*/) const
260 {
261   const Handle(TDocStd_XLink)& xRef =
262     Handle(TDocStd_XLink)::DownCast(intoAttribute);
263   if (!xRef.IsNull()) {
264     xRef->DocumentEntry(myDocEntry);
265     xRef->LabelEntry(myLabelEntry);
266   }
267 }
268
269
270 //=======================================================================
271 //function : Dump
272 //purpose  : 
273 //=======================================================================
274
275 Standard_OStream& TDocStd_XLink::Dump(Standard_OStream& anOS) const
276 {
277   return anOS;
278 }
279