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