1 // Created on: 2008-03-07
2 // Created by: Vlad ROMASHKO
3 // Copyright (c) 2008-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 <CDM_MessageDriver.hxx>
18 #include <Standard_Type.hxx>
19 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
20 #include <TDF_Attribute.hxx>
21 #include <TFunction_GraphNode.hxx>
22 #include <XmlMFunction_GraphNodeDriver.hxx>
23 #include <XmlObjMgt.hxx>
24 #include <XmlObjMgt_Persistent.hxx>
26 IMPLEMENT_DOMSTRING (LastPreviousIndex, "lastprev")
27 IMPLEMENT_DOMSTRING (LastNextIndex, "lastnext")
28 IMPLEMENT_DOMSTRING (ExecutionStatus, "exec")
30 //=======================================================================
31 //function : XmlMFunction_GraphNodeDriver
32 //purpose : Constructor
33 //=======================================================================
34 XmlMFunction_GraphNodeDriver::XmlMFunction_GraphNodeDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
35 : XmlMDF_ADriver (theMsgDriver, NULL)
40 //=======================================================================
43 //=======================================================================
44 Handle(TDF_Attribute) XmlMFunction_GraphNodeDriver::NewEmpty() const
46 return (new TFunction_GraphNode());
49 //=======================================================================
51 //purpose : persistent -> transient (retrieve)
52 //=======================================================================
53 Standard_Boolean XmlMFunction_GraphNodeDriver::Paste(const XmlObjMgt_Persistent& theSource,
54 const Handle(TDF_Attribute)& theTarget,
55 XmlObjMgt_RRelocationTable& ) const
57 Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(theTarget);
59 Standard_Integer aFirstIndPrev, aLastIndPrev, aFirstIndNext, aLastIndNext, aValue, ind;
60 const XmlObjMgt_Element& anElement = theSource;
65 // Read the FirstIndex; if the attribute is absent initialize to 1
66 aFirstIndPrev = 1; // It is absent :-) because I didn't wrote it on the stage of writing the file.
68 // Read the LastIndex; the attribute should present
69 if (!anElement.getAttribute(::LastPreviousIndex()).GetInteger(aLastIndPrev))
71 TCollection_ExtendedString aMessageString =
72 TCollection_ExtendedString("Cannot retrieve the last index"
73 " for previous functions of GraphNode attribute");
74 WriteMessage (aMessageString);
75 return Standard_False;
78 if (aFirstIndPrev == aLastIndPrev)
80 Standard_Integer anInteger;
81 if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger))
83 TCollection_ExtendedString aMessageString =
84 TCollection_ExtendedString("Cannot retrieve integer member"
85 " for previous functions of GraphNode attribute");
86 WriteMessage (aMessageString);
87 return Standard_False;
89 G->AddPrevious(anInteger);
93 Standard_CString aValueStr =
94 Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
96 for (ind = aFirstIndPrev; ind <= aLastIndPrev; ind++)
98 if (!XmlObjMgt::GetInteger(aValueStr, aValue))
100 TCollection_ExtendedString aMessageString =
101 TCollection_ExtendedString("Cannot retrieve integer member"
102 " for previous functions of GraphNode attribute as \"")
104 WriteMessage (aMessageString);
105 return Standard_False;
107 G->AddPrevious(aValue);
115 // Read the FirstIndex; if the attribute is absent initialize to 1
116 aFirstIndNext = aLastIndPrev + 1; // It is absent :-) because I didn't wrote it on the stage of writing the file.
118 // Read the LastIndex; the attribute should present
119 if (!anElement.getAttribute(::LastNextIndex()).GetInteger(aLastIndNext))
121 TCollection_ExtendedString aMessageString =
122 TCollection_ExtendedString("Cannot retrieve the last index"
123 " for next functions of GraphNode attribute");
124 WriteMessage (aMessageString);
125 return Standard_False;
127 aLastIndNext += aLastIndPrev;
129 Standard_CString aValueStr =
130 Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
132 for (ind = 1; ind <= aLastIndNext; ind++)
134 if (!XmlObjMgt::GetInteger(aValueStr, aValue))
136 TCollection_ExtendedString aMessageString =
137 TCollection_ExtendedString("Cannot retrieve integer member"
138 " for next functions of GraphNode attribute as \"")
140 WriteMessage (aMessageString);
141 return Standard_False;
143 if (ind < aFirstIndNext)
149 Standard_Integer exec = 0;
150 if (!anElement.getAttribute(::ExecutionStatus()).GetInteger(exec))
152 TCollection_ExtendedString aMessageString =
153 TCollection_ExtendedString("Cannot retrieve the execution status"
154 " for GraphNode attribute");
155 WriteMessage (aMessageString);
156 return Standard_False;
158 G->SetStatus((TFunction_ExecutionStatus) exec);
160 return Standard_True;
163 //=======================================================================
165 //purpose : transient -> persistent (store)
166 //=======================================================================
167 void XmlMFunction_GraphNodeDriver::Paste (const Handle(TDF_Attribute)& theSource,
168 XmlObjMgt_Persistent& theTarget,
169 XmlObjMgt_SRelocationTable& ) const
171 Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(theSource);
176 theTarget.Element().setAttribute(::LastPreviousIndex(), G->GetPrevious().Extent());
178 TCollection_AsciiString aValueStr;
179 TColStd_MapIteratorOfMapOfInteger itrm(G->GetPrevious());
180 for (; itrm.More(); itrm.Next())
182 const Standard_Integer ID = itrm.Key();
183 aValueStr += TCollection_AsciiString(ID);
191 theTarget.Element().setAttribute(::LastNextIndex(), G->GetNext().Extent());
193 itrm.Initialize(G->GetNext());
194 for (; itrm.More(); itrm.Next())
196 const Standard_Integer ID = itrm.Key();
197 aValueStr += TCollection_AsciiString(ID);
201 XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);
204 theTarget.Element().setAttribute(::ExecutionStatus(), (Standard_Integer) G->GetStatus());