b311480e |
1 | // Created on: 2001-09-04 |
2 | // Created by: Julia DOROVSKIKH |
973c2be1 |
3 | // Copyright (c) 2001-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #include <XmlMXCAFDoc_GraphNodeDriver.ixx> |
17 | |
18 | #include <XmlObjMgt.hxx> |
19 | |
20 | #include <XCAFDoc_GraphNode.hxx> |
21 | #include <TDF_Tool.hxx> |
22 | #include <TDF_Label.hxx> |
23 | #include <Standard_PCharacter.hxx> |
24 | |
25 | IMPLEMENT_DOMSTRING (TreeIdString, "treeid") |
26 | IMPLEMENT_DOMSTRING (ChildrenString, "children") |
27 | IMPLEMENT_DOMSTRING (FathersString, "fathers") |
28 | |
29 | //======================================================================= |
30 | //function : XmlMXCAFDoc_GraphNodeDriver |
31 | //purpose : Constructor |
32 | //======================================================================= |
33 | XmlMXCAFDoc_GraphNodeDriver::XmlMXCAFDoc_GraphNodeDriver |
34 | (const Handle(CDM_MessageDriver)& theMsgDriver) |
35 | : XmlMDF_ADriver (theMsgDriver, "xcaf", "GraphNode") |
36 | {} |
37 | |
38 | //======================================================================= |
39 | //function : NewEmpty |
40 | //purpose : |
41 | //======================================================================= |
42 | Handle(TDF_Attribute) XmlMXCAFDoc_GraphNodeDriver::NewEmpty() const |
43 | { |
44 | return (new XCAFDoc_GraphNode()); |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : Paste |
49 | //purpose : persistent -> transient (retrieve) |
50 | //======================================================================= |
51 | Standard_Boolean XmlMXCAFDoc_GraphNodeDriver::Paste |
52 | (const XmlObjMgt_Persistent& theSource, |
53 | const Handle(TDF_Attribute)& theTarget, |
54 | XmlObjMgt_RRelocationTable& theRelocTable) const |
55 | { |
56 | Handle(XCAFDoc_GraphNode) aT = Handle(XCAFDoc_GraphNode)::DownCast(theTarget); |
57 | const XmlObjMgt_Element& anElement = theSource; |
58 | |
59 | // tree id |
60 | XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::TreeIdString()); |
61 | Standard_GUID aGUID (Standard_CString(aGUIDStr.GetString())); |
62 | aT->SetGraphID(aGUID); |
63 | |
64 | XmlObjMgt_DOMString aDOMStr; |
65 | Handle(XCAFDoc_GraphNode) aTChild; |
66 | |
67 | // fathers |
68 | aDOMStr = anElement.getAttribute(::FathersString()); |
69 | if (aDOMStr != NULL) // void list is allowed |
70 | { |
71 | Standard_CString aChildren = Standard_CString(aDOMStr.GetString()); |
72 | Standard_Integer aNb = 0; |
73 | if (!XmlObjMgt::GetInteger(aChildren, aNb)) return Standard_False; |
74 | |
75 | while (aNb > 0) |
76 | { |
77 | // Find or create GraphNode attribute with the given ID |
78 | if (theRelocTable.IsBound(aNb)) |
79 | { |
80 | aTChild = Handle(XCAFDoc_GraphNode)::DownCast(theRelocTable.Find(aNb)); |
81 | if (aTChild.IsNull()) |
82 | return Standard_False; |
83 | } |
84 | else |
85 | { |
86 | aTChild = new XCAFDoc_GraphNode; |
87 | theRelocTable.Bind(aNb, aTChild); |
88 | } |
89 | |
90 | // Add the child to the current tree |
91 | aTChild->SetGraphID(aGUID); |
92 | aT->SetFather(aTChild); |
93 | |
94 | // Get next child ID |
95 | if (!XmlObjMgt::GetInteger(aChildren, aNb)) aNb = 0; |
96 | } |
97 | } |
98 | |
99 | // children |
100 | aDOMStr = anElement.getAttribute(::ChildrenString()); |
101 | if (aDOMStr != NULL) // void list is allowed |
102 | { |
103 | Standard_CString aChildren = Standard_CString(aDOMStr.GetString()); |
104 | Standard_Integer aNb = 0; |
105 | if (!XmlObjMgt::GetInteger(aChildren, aNb)) return Standard_False; |
106 | |
107 | while (aNb > 0) |
108 | { |
109 | // Find or create GraphNode attribute with the given ID |
110 | if (theRelocTable.IsBound(aNb)) |
111 | { |
112 | aTChild = Handle(XCAFDoc_GraphNode)::DownCast(theRelocTable.Find(aNb)); |
113 | if (aTChild.IsNull()) |
114 | return Standard_False; |
115 | } |
116 | else |
117 | { |
118 | aTChild = new XCAFDoc_GraphNode; |
119 | theRelocTable.Bind(aNb, aTChild); |
120 | } |
121 | |
122 | // Add the child to the current tree |
123 | aTChild->SetGraphID(aGUID); |
124 | aT->SetChild(aTChild); |
125 | |
126 | // Get next child ID |
127 | if (!XmlObjMgt::GetInteger(aChildren, aNb)) aNb = 0; |
128 | } |
129 | } |
130 | |
131 | return Standard_True; |
132 | } |
133 | |
134 | //======================================================================= |
135 | //function : Paste |
136 | //purpose : transient -> persistent (store) |
137 | //======================================================================= |
138 | void XmlMXCAFDoc_GraphNodeDriver::Paste (const Handle(TDF_Attribute)& theSource, |
139 | XmlObjMgt_Persistent& theTarget, |
140 | XmlObjMgt_SRelocationTable& theRelocTable) const |
141 | { |
142 | Handle(XCAFDoc_GraphNode) aS = Handle(XCAFDoc_GraphNode)::DownCast(theSource); |
143 | if (aS.IsNull()) return; |
144 | |
145 | // graph id |
146 | Standard_Character aGuidStr [40]; |
147 | Standard_PCharacter pGuidStr; |
148 | // |
149 | pGuidStr=(Standard_PCharacter)aGuidStr; |
150 | aS->ID().ToCString (pGuidStr); |
151 | theTarget.Element().setAttribute(::TreeIdString(), aGuidStr); |
152 | |
153 | Standard_Integer aNb; |
154 | TCollection_AsciiString aStr; |
155 | Handle(XCAFDoc_GraphNode) aF; |
156 | Standard_Integer i; |
157 | |
158 | // fathers |
159 | for (i = 1; i <= aS->NbFathers(); i++) |
160 | { |
161 | aF = aS->GetFather(i); |
162 | if (!aF.IsNull()) |
163 | { |
164 | aNb = theRelocTable.FindIndex(aF); |
165 | if (aNb == 0) |
166 | { |
167 | aNb = theRelocTable.Add(aF); |
168 | } |
169 | TCollection_AsciiString aNbStr (aNb); |
170 | aStr += aNbStr + " "; |
171 | } |
172 | } |
173 | if (aStr.Length() > 0) |
174 | theTarget.Element().setAttribute(::FathersString(), aStr.ToCString()); |
175 | |
176 | // children |
177 | aStr.Clear(); |
178 | for (i = 1; i <= aS->NbChildren(); i++) |
179 | { |
180 | aF = aS->GetChild(i); |
181 | if (!aF.IsNull()) |
182 | { |
183 | aNb = theRelocTable.FindIndex(aF); |
184 | if (aNb == 0) |
185 | { |
186 | aNb = theRelocTable.Add(aF); |
187 | } |
188 | TCollection_AsciiString aNbStr (aNb); |
189 | aStr += aNbStr + " "; |
190 | } |
191 | } |
192 | if (aStr.Length() > 0) |
193 | theTarget.Element().setAttribute(::ChildrenString(), aStr.ToCString()); |
194 | } |