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
8 // under the terms of the GNU Lesser General Public 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.
16 #include <XmlMFunction_GraphNodeDriver.ixx>
17 #include <XmlObjMgt.hxx>
19 #include <TFunction_GraphNode.hxx>
20 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
22 IMPLEMENT_DOMSTRING (LastPreviousIndex, "lastprev")
23 IMPLEMENT_DOMSTRING (LastNextIndex, "lastnext")
24 IMPLEMENT_DOMSTRING (ExecutionStatus, "exec")
26 //=======================================================================
27 //function : XmlMFunction_GraphNodeDriver
28 //purpose : Constructor
29 //=======================================================================
30 XmlMFunction_GraphNodeDriver::XmlMFunction_GraphNodeDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
31 : XmlMDF_ADriver (theMsgDriver, NULL)
36 //=======================================================================
39 //=======================================================================
40 Handle(TDF_Attribute) XmlMFunction_GraphNodeDriver::NewEmpty() const
42 return (new TFunction_GraphNode());
45 //=======================================================================
47 //purpose : persistent -> transient (retrieve)
48 //=======================================================================
49 Standard_Boolean XmlMFunction_GraphNodeDriver::Paste(const XmlObjMgt_Persistent& theSource,
50 const Handle(TDF_Attribute)& theTarget,
51 XmlObjMgt_RRelocationTable& ) const
53 Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(theTarget);
55 Standard_Integer aFirstIndPrev, aLastIndPrev, aFirstIndNext, aLastIndNext, aValue, ind;
56 const XmlObjMgt_Element& anElement = theSource;
61 // Read the FirstIndex; if the attribute is absent initialize to 1
62 aFirstIndPrev = 1; // It is absent :-) because I didn't wrote it on the stage of writing the file.
64 // Read the LastIndex; the attribute should present
65 if (!anElement.getAttribute(::LastPreviousIndex()).GetInteger(aLastIndPrev))
67 TCollection_ExtendedString aMessageString =
68 TCollection_ExtendedString("Cannot retrieve the last index"
69 " for previous functions of GraphNode attribute");
70 WriteMessage (aMessageString);
71 return Standard_False;
74 if (aFirstIndPrev == aLastIndPrev)
76 Standard_Integer anInteger;
77 if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger))
79 TCollection_ExtendedString aMessageString =
80 TCollection_ExtendedString("Cannot retrieve integer member"
81 " for previous functions of GraphNode attribute");
82 WriteMessage (aMessageString);
83 return Standard_False;
85 G->AddPrevious(anInteger);
89 Standard_CString aValueStr =
90 Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
92 for (ind = aFirstIndPrev; ind <= aLastIndPrev; ind++)
94 if (!XmlObjMgt::GetInteger(aValueStr, aValue))
96 TCollection_ExtendedString aMessageString =
97 TCollection_ExtendedString("Cannot retrieve integer member"
98 " for previous functions of GraphNode attribute as \"")
100 WriteMessage (aMessageString);
101 return Standard_False;
103 G->AddPrevious(aValue);
111 // Read the FirstIndex; if the attribute is absent initialize to 1
112 aFirstIndNext = aLastIndPrev + 1; // It is absent :-) because I didn't wrote it on the stage of writing the file.
114 // Read the LastIndex; the attribute should present
115 if (!anElement.getAttribute(::LastNextIndex()).GetInteger(aLastIndNext))
117 TCollection_ExtendedString aMessageString =
118 TCollection_ExtendedString("Cannot retrieve the last index"
119 " for next functions of GraphNode attribute");
120 WriteMessage (aMessageString);
121 return Standard_False;
123 aLastIndNext += aLastIndPrev;
125 Standard_CString aValueStr =
126 Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
128 for (ind = 1; ind <= aLastIndNext; ind++)
130 if (!XmlObjMgt::GetInteger(aValueStr, aValue))
132 TCollection_ExtendedString aMessageString =
133 TCollection_ExtendedString("Cannot retrieve integer member"
134 " for next functions of GraphNode attribute as \"")
136 WriteMessage (aMessageString);
137 return Standard_False;
139 if (ind < aFirstIndNext)
145 Standard_Integer exec = 0;
146 if (!anElement.getAttribute(::ExecutionStatus()).GetInteger(exec))
148 TCollection_ExtendedString aMessageString =
149 TCollection_ExtendedString("Cannot retrieve the execution status"
150 " for GraphNode attribute");
151 WriteMessage (aMessageString);
152 return Standard_False;
154 G->SetStatus((TFunction_ExecutionStatus) exec);
156 return Standard_True;
159 //=======================================================================
161 //purpose : transient -> persistent (store)
162 //=======================================================================
163 void XmlMFunction_GraphNodeDriver::Paste (const Handle(TDF_Attribute)& theSource,
164 XmlObjMgt_Persistent& theTarget,
165 XmlObjMgt_SRelocationTable& ) const
167 Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(theSource);
172 theTarget.Element().setAttribute(::LastPreviousIndex(), G->GetPrevious().Extent());
174 TCollection_AsciiString aValueStr;
175 TColStd_MapIteratorOfMapOfInteger itrm(G->GetPrevious());
176 for (; itrm.More(); itrm.Next())
178 const Standard_Integer ID = itrm.Key();
179 aValueStr += TCollection_AsciiString(ID);
187 theTarget.Element().setAttribute(::LastNextIndex(), G->GetNext().Extent());
189 itrm.Initialize(G->GetNext());
190 for (; itrm.More(); itrm.Next())
192 const Standard_Integer ID = itrm.Key();
193 aValueStr += TCollection_AsciiString(ID);
197 XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);
200 theTarget.Element().setAttribute(::ExecutionStatus(), (Standard_Integer) G->GetStatus());