1 // Created on: 1999-05-21
2 // Created by: Denis PASCAL
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <TDocStd_XLinkTool.hxx>
19 #include <Standard_DomainError.hxx>
20 #include <Standard_GUID.hxx>
21 #include <TCollection_AsciiString.hxx>
22 #include <TDataStd_TreeNode.hxx>
23 #include <TDF_ClosureMode.hxx>
24 #include <TDF_ClosureTool.hxx>
25 #include <TDF_ComparisonTool.hxx>
26 #include <TDF_CopyTool.hxx>
27 #include <TDF_DataSet.hxx>
28 #include <TDF_IDFilter.hxx>
29 #include <TDF_IDList.hxx>
30 #include <TDF_Label.hxx>
31 #include <TDF_LabelList.hxx>
32 #include <TDF_LabelMap.hxx>
33 #include <TDF_ListIteratorOfLabelList.hxx>
34 #include <TDF_MapIteratorOfLabelMap.hxx>
35 #include <TDF_Reference.hxx>
36 #include <TDF_RelocationTable.hxx>
37 #include <TDF_Tool.hxx>
38 #include <TDocStd_Document.hxx>
39 #include <TDocStd_XLink.hxx>
42 //=======================================================================
43 //function : TDocStd_XLinkTool
45 //=======================================================================
46 TDocStd_XLinkTool::TDocStd_XLinkTool () {
47 isDone = Standard_False;
48 myRT = new TDF_RelocationTable();
51 //=======================================================================
54 //=======================================================================
56 void TDocStd_XLinkTool::Copy (const TDF_Label& target,
57 const TDF_Label& source)
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)) {
64 throw Standard_DomainError("TDocStd_XLinkTool::Copy : not self-contained");
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();
79 if(TDataStd_TreeNode::Find(target, anOldNode)) {
80 anOldFather = anOldNode->Father();
81 anOldPrev = anOldNode->Previous();
82 anOldNext = anOldNode->Next();
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
100 aPrev->InsertAfter(aNode);
101 else if(!aNext.IsNull()) {
102 aNext->InsertBefore(aNode);
103 } else if (!aFather.IsNull())
104 aNode->SetFather(aFather);
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);
118 isDone = Standard_True;
121 //=======================================================================
122 //function : CopyWithLink
124 //=======================================================================
126 void TDocStd_XLinkTool::CopyWithLink (const TDF_Label& target,
127 const TDF_Label& source)
129 Handle(TDF_Reference) REF;
130 if (target.FindAttribute(TDF_Reference::GetID(),REF)) {
131 throw Standard_DomainError(" TDocStd_CopyWithLink : already a ref");
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;
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;
153 //=======================================================================
154 //function : UpdateLink
156 //=======================================================================
158 void TDocStd_XLinkTool::UpdateLink (const TDF_Label& label)
160 Handle(TDF_Reference) REF;
161 if (!label.FindAttribute(TDF_Reference::GetID(),REF)) {
162 throw Standard_DomainError(" TDocStd_XLinkTool::UpdateLink : not ref registred");
164 TDocStd_XLinkTool XLinkTool;
165 Copy (label,REF->Get());
169 //=======================================================================
172 //=======================================================================
174 Standard_Boolean TDocStd_XLinkTool::IsDone () const
179 //=======================================================================
180 //function : RelocationTable
182 //=======================================================================
184 Handle(TDF_RelocationTable) TDocStd_XLinkTool::RelocationTable () const
189 //=======================================================================
192 //=======================================================================
194 Handle(TDF_DataSet) TDocStd_XLinkTool::DataSet () const