1 // Created on: 2001-08-24
2 // Created by: Alexnder GRIGORIEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <XmlMDataStd_TreeNodeDriver.ixx>
22 #include <TDataStd_TreeNode.hxx>
23 #include <XmlObjMgt.hxx>
25 IMPLEMENT_DOMSTRING (TreeIdString, "treeid")
26 IMPLEMENT_DOMSTRING (ChildrenString, "children")
28 //=======================================================================
29 //function : XmlMDataStd_TreeNodeDriver
30 //purpose : Constructor
31 //=======================================================================
33 XmlMDataStd_TreeNodeDriver::XmlMDataStd_TreeNodeDriver
34 (const Handle(CDM_MessageDriver)& theMsgDriver)
35 : XmlMDF_ADriver (theMsgDriver, NULL)
38 //=======================================================================
41 //=======================================================================
42 Handle(TDF_Attribute) XmlMDataStd_TreeNodeDriver::NewEmpty() const
44 return (new TDataStd_TreeNode());
47 //=======================================================================
50 //=======================================================================
51 Standard_Boolean XmlMDataStd_TreeNodeDriver::Paste
52 (const XmlObjMgt_Persistent& theSource,
53 const Handle(TDF_Attribute)& theTarget,
54 XmlObjMgt_RRelocationTable& theRelocTable) const
56 Handle(TDataStd_TreeNode) aT = Handle(TDataStd_TreeNode)::DownCast(theTarget);
57 const XmlObjMgt_Element& anElement = theSource;
60 XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::TreeIdString());
61 Standard_GUID aGUID (Standard_CString(aGUIDStr.GetString()));
65 Handle(TDataStd_TreeNode) aTChild;
67 XmlObjMgt_DOMString aChildrenStr = anElement.getAttribute(::ChildrenString());
68 if (aChildrenStr != NULL) // void list is allowed
70 Standard_CString aChildren = Standard_CString(aChildrenStr.GetString());
71 Standard_Integer aNb = 0;
72 if (!XmlObjMgt::GetInteger(aChildren, aNb)) return Standard_False;
76 // Find or create TreeNode attribute with the given ID
77 if (theRelocTable.IsBound(aNb))
79 aTChild = Handle(TDataStd_TreeNode)::DownCast(theRelocTable.Find(aNb));
81 return Standard_False;
85 aTChild = new TDataStd_TreeNode;
86 theRelocTable.Bind(aNb, aTChild);
89 // Add the child to the current tree
90 aTChild->SetTreeID(aGUID);
94 if (!XmlObjMgt::GetInteger(aChildren, aNb)) aNb = 0;
100 //=======================================================================
103 //=======================================================================
104 void XmlMDataStd_TreeNodeDriver::Paste
105 (const Handle(TDF_Attribute)& theSource,
106 XmlObjMgt_Persistent& theTarget,
107 XmlObjMgt_SRelocationTable& theRelocTable) const
109 Handle(TDataStd_TreeNode) aS = Handle(TDataStd_TreeNode)::DownCast(theSource);
111 Standard_Integer aNb;
113 TCollection_AsciiString aChildrenStr;
116 Standard_Character aGuidStr [40];
117 Standard_PCharacter pGuidStr=aGuidStr;
118 aS->ID().ToCString (pGuidStr);
119 theTarget.Element().setAttribute(::TreeIdString(), aGuidStr);
122 Handle(TDataStd_TreeNode) aF = aS->First();
124 // form the string of numbers for the list of children
127 aNb = theRelocTable.FindIndex(aF);
130 aNb = theRelocTable.Add(aF);
132 TCollection_AsciiString aNbStr (aNb);
133 aChildrenStr += aNbStr + " ";
139 if (aChildrenStr.Length() > 0)
140 theTarget.Element().setAttribute(::ChildrenString(),
141 aChildrenStr.ToCString());