1 // Created on: 2001-09-04
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <Message_Messenger.hxx>
18 #include <Standard_PCharacter.hxx>
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>
28 IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_GraphNodeDriver,XmlMDF_ADriver)
29 IMPLEMENT_DOMSTRING (TreeIdString, "treeid")
30 IMPLEMENT_DOMSTRING (ChildrenString, "children")
31 IMPLEMENT_DOMSTRING (FathersString, "fathers")
33 //=======================================================================
34 //function : XmlMXCAFDoc_GraphNodeDriver
35 //purpose : Constructor
36 //=======================================================================
37 XmlMXCAFDoc_GraphNodeDriver::XmlMXCAFDoc_GraphNodeDriver
38 (const Handle(Message_Messenger)& theMsgDriver)
39 : XmlMDF_ADriver (theMsgDriver, "xcaf", "GraphNode")
42 //=======================================================================
45 //=======================================================================
46 Handle(TDF_Attribute) XmlMXCAFDoc_GraphNodeDriver::NewEmpty() const
48 return (new XCAFDoc_GraphNode());
51 //=======================================================================
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
60 Handle(XCAFDoc_GraphNode) aT = Handle(XCAFDoc_GraphNode)::DownCast(theTarget);
61 const XmlObjMgt_Element& anElement = theSource;
64 XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::TreeIdString());
65 Standard_GUID aGUID (Standard_CString(aGUIDStr.GetString()));
66 aT->SetGraphID(aGUID);
68 XmlObjMgt_DOMString aDOMStr;
69 Handle(XCAFDoc_GraphNode) aTChild;
72 aDOMStr = anElement.getAttribute(::FathersString());
73 if (aDOMStr != NULL) // void list is allowed
75 Standard_CString aChildren = Standard_CString(aDOMStr.GetString());
76 Standard_Integer aNb = 0;
77 if (!XmlObjMgt::GetInteger(aChildren, aNb)) return Standard_False;
81 // Find or create GraphNode attribute with the given ID
82 if (theRelocTable.IsBound(aNb))
84 aTChild = Handle(XCAFDoc_GraphNode)::DownCast(theRelocTable.Find(aNb));
86 return Standard_False;
90 aTChild = new XCAFDoc_GraphNode;
91 theRelocTable.Bind(aNb, aTChild);
94 // Add the child to the current tree
95 aTChild->SetGraphID(aGUID);
96 aT->SetFather(aTChild);
99 if (!XmlObjMgt::GetInteger(aChildren, aNb)) aNb = 0;
104 aDOMStr = anElement.getAttribute(::ChildrenString());
105 if (aDOMStr != NULL) // void list is allowed
107 Standard_CString aChildren = Standard_CString(aDOMStr.GetString());
108 Standard_Integer aNb = 0;
109 if (!XmlObjMgt::GetInteger(aChildren, aNb)) return Standard_False;
113 // Find or create GraphNode attribute with the given ID
114 if (theRelocTable.IsBound(aNb))
116 aTChild = Handle(XCAFDoc_GraphNode)::DownCast(theRelocTable.Find(aNb));
117 if (aTChild.IsNull())
118 return Standard_False;
122 aTChild = new XCAFDoc_GraphNode;
123 theRelocTable.Bind(aNb, aTChild);
126 // Add the child to the current tree
127 aTChild->SetGraphID(aGUID);
128 aT->SetChild(aTChild);
131 if (!XmlObjMgt::GetInteger(aChildren, aNb)) aNb = 0;
135 return Standard_True;
138 //=======================================================================
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
146 Handle(XCAFDoc_GraphNode) aS = Handle(XCAFDoc_GraphNode)::DownCast(theSource);
147 if (aS.IsNull()) return;
150 Standard_Character aGuidStr [40];
151 Standard_PCharacter pGuidStr;
153 pGuidStr=(Standard_PCharacter)aGuidStr;
154 aS->ID().ToCString (pGuidStr);
155 theTarget.Element().setAttribute(::TreeIdString(), aGuidStr);
157 Standard_Integer aNb;
158 TCollection_AsciiString aStr;
159 Handle(XCAFDoc_GraphNode) aF;
163 for (i = 1; i <= aS->NbFathers(); i++)
165 aF = aS->GetFather(i);
168 aNb = theRelocTable.FindIndex(aF);
171 aNb = theRelocTable.Add(aF);
173 TCollection_AsciiString aNbStr (aNb);
174 aStr += aNbStr + " ";
177 if (aStr.Length() > 0)
178 theTarget.Element().setAttribute(::FathersString(), aStr.ToCString());
182 for (i = 1; i <= aS->NbChildren(); i++)
184 aF = aS->GetChild(i);
187 aNb = theRelocTable.FindIndex(aF);
190 aNb = theRelocTable.Add(aF);
192 TCollection_AsciiString aNbStr (aNb);
193 aStr += aNbStr + " ";
196 if (aStr.Length() > 0)
197 theTarget.Element().setAttribute(::ChildrenString(), aStr.ToCString());