b311480e |
1 | // Created on: 1999-05-21 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 1999-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <Standard_DomainError.hxx> |
7fd59977 |
19 | #include <Standard_GUID.hxx> |
20 | #include <TCollection_AsciiString.hxx> |
42cf5bc1 |
21 | #include <TDataStd_TreeNode.hxx> |
7fd59977 |
22 | #include <TDF_ClosureMode.hxx> |
23 | #include <TDF_ClosureTool.hxx> |
7fd59977 |
24 | #include <TDF_ComparisonTool.hxx> |
42cf5bc1 |
25 | #include <TDF_CopyTool.hxx> |
26 | #include <TDF_DataSet.hxx> |
27 | #include <TDF_IDFilter.hxx> |
28 | #include <TDF_IDList.hxx> |
29 | #include <TDF_Label.hxx> |
30 | #include <TDF_LabelList.hxx> |
31 | #include <TDF_LabelMap.hxx> |
32 | #include <TDF_ListIteratorOfLabelList.hxx> |
33 | #include <TDF_MapIteratorOfLabelMap.hxx> |
7fd59977 |
34 | #include <TDF_Reference.hxx> |
42cf5bc1 |
35 | #include <TDF_RelocationTable.hxx> |
36 | #include <TDF_Tool.hxx> |
37 | #include <TDocStd_Document.hxx> |
38 | #include <TDocStd_XLink.hxx> |
39 | #include <TDocStd_XLinkTool.hxx> |
b311480e |
40 | |
42cf5bc1 |
41 | // standard copy |
7fd59977 |
42 | //======================================================================= |
43 | //function : TDocStd_XLinkTool |
44 | //purpose : |
45 | //======================================================================= |
7fd59977 |
46 | TDocStd_XLinkTool::TDocStd_XLinkTool () { |
47 | isDone = Standard_False; |
48 | myRT = new TDF_RelocationTable(); |
49 | } |
50 | |
51 | //======================================================================= |
52 | //function : Copy |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | void TDocStd_XLinkTool::Copy (const TDF_Label& target, |
57 | const TDF_Label& source) |
58 | { |
59 | Handle(TDocStd_Document) TARGET,SOURCE; |
60 | TARGET = TDocStd_Document::Get(target); |
61 | SOURCE = TDocStd_Document::Get(source); |
62 | if (TARGET != SOURCE) { |
63 | if (!TDF_Tool::IsSelfContained(source)) { |
9775fa61 |
64 | throw Standard_DomainError("TDocStd_XLinkTool::Copy : not self-contained"); |
7fd59977 |
65 | } |
66 | } |
67 | |
68 | |
69 | // Remove TreeNode, then resotre, if present |
70 | Handle(TDataStd_TreeNode) aFather, aPrev, aNext; |
71 | Handle(TDataStd_TreeNode) anOldFather, anOldPrev, anOldNext; |
72 | Handle(TDataStd_TreeNode) aNode, anOldNode; |
73 | if(TDataStd_TreeNode::Find(source, aNode)) { |
74 | aFather = aNode->Father(); |
75 | aPrev = aNode->Previous(); |
76 | aNext = aNode->Next(); |
77 | aNode->Remove(); |
78 | } |
79 | if(TDataStd_TreeNode::Find(target, anOldNode)) { |
80 | anOldFather = anOldNode->Father(); |
81 | anOldPrev = anOldNode->Previous(); |
82 | anOldNext = anOldNode->Next(); |
83 | anOldNode->Remove(); |
84 | } |
85 | |
86 | myRT = new TDF_RelocationTable(Standard_True); |
87 | myDS = new TDF_DataSet; |
88 | Handle(TDF_DataSet) DS = new TDF_DataSet(); |
89 | TDF_ClosureMode mode(Standard_True); // descendant plus reference |
90 | myDS->AddLabel(source); |
91 | myRT->SetRelocation(source,target); |
92 | TDF_IDFilter filter (Standard_False); // on prend tout |
93 | TDF_ClosureTool::Closure(myDS,filter,mode); |
94 | TDF_CopyTool::Copy(myDS,myRT); |
95 | //TopTools_DataMapOfShapeShape M; // removed to avoid dependence with TNaming |
96 | //TNaming::ChangeShapes(target,M);// should be used as postfix after Copy |
97 | |
98 | if(!aNode.IsNull()) { |
99 | if(!aPrev.IsNull()) |
100 | aPrev->InsertAfter(aNode); |
101 | else if(!aNext.IsNull()) { |
102 | aNext->InsertBefore(aNode); |
103 | } else if (!aFather.IsNull()) |
104 | aNode->SetFather(aFather); |
105 | } |
106 | |
107 | if(!anOldNode.IsNull()) { |
108 | if(TDataStd_TreeNode::Find(target, anOldNode)) { |
109 | if(!anOldPrev.IsNull()) |
110 | anOldPrev->InsertAfter(anOldNode); |
111 | else if(!anOldNext.IsNull()) { |
112 | anOldNext->InsertBefore(anOldNode); |
113 | } else if (!anOldFather.IsNull()) |
114 | anOldNode->SetFather(anOldFather); |
115 | } |
116 | } |
117 | |
118 | isDone = Standard_True; |
119 | } |
120 | |
121 | //======================================================================= |
122 | //function : CopyWithLink |
123 | //purpose : |
124 | //======================================================================= |
125 | |
126 | void TDocStd_XLinkTool::CopyWithLink (const TDF_Label& target, |
127 | const TDF_Label& source) |
128 | { |
129 | Handle(TDF_Reference) REF; |
130 | if (target.FindAttribute(TDF_Reference::GetID(),REF)) { |
9775fa61 |
131 | throw Standard_DomainError(" TDocStd_CopyWithLink : already a ref"); |
7fd59977 |
132 | } |
133 | Copy(target,source); |
134 | if (isDone) { |
135 | TCollection_AsciiString xlabelentry, xdocentry; |
136 | TDF_Tool::Entry(source,xlabelentry); |
137 | Handle(TDocStd_Document) aSourceD = TDocStd_Document::Get(source); |
138 | Handle(TDocStd_Document) aTargetD = TDocStd_Document::Get(target); |
139 | Standard_Integer aDocEntry = 0; |
140 | if(aSourceD != aTargetD) |
141 | aDocEntry = aTargetD->CreateReference(aSourceD); |
142 | xdocentry = aDocEntry; |
143 | |
144 | Handle(TDocStd_XLink) X = TDocStd_XLink::Set(target); |
145 | X->LabelEntry(xlabelentry); |
146 | X->DocumentEntry(xdocentry); |
147 | TDF_Reference::Set(target,source); |
148 | isDone = Standard_True; |
149 | } |
150 | } |
151 | |
152 | |
153 | //======================================================================= |
154 | //function : UpdateLink |
155 | //purpose : |
156 | //======================================================================= |
157 | |
158 | void TDocStd_XLinkTool::UpdateLink (const TDF_Label& label) |
159 | { |
160 | Handle(TDF_Reference) REF; |
161 | if (!label.FindAttribute(TDF_Reference::GetID(),REF)) { |
9775fa61 |
162 | throw Standard_DomainError(" TDocStd_XLinkTool::UpdateLink : not ref registred"); |
7fd59977 |
163 | } |
164 | TDocStd_XLinkTool XLinkTool; |
165 | Copy (label,REF->Get()); |
166 | } |
167 | |
168 | |
169 | //======================================================================= |
170 | //function : IsDone |
171 | //purpose : |
172 | //======================================================================= |
173 | |
174 | Standard_Boolean TDocStd_XLinkTool::IsDone () const |
175 | { |
176 | return isDone; |
177 | } |
178 | |
179 | //======================================================================= |
180 | //function : RelocationTable |
181 | //purpose : |
182 | //======================================================================= |
183 | |
184 | Handle(TDF_RelocationTable) TDocStd_XLinkTool::RelocationTable () const |
185 | { |
186 | return myRT; |
187 | } |
188 | |
189 | //======================================================================= |
190 | //function : DataSet |
191 | //purpose : |
192 | //======================================================================= |
193 | |
194 | Handle(TDF_DataSet) TDocStd_XLinkTool::DataSet () const |
195 | { |
196 | return myDS; |
197 | } |