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.
20 //AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
22 #define OCC6010 // vro 01.06.2004
25 #include <XmlMDataStd_RealArrayDriver.ixx>
26 #include <TDataStd_RealArray.hxx>
27 #include <XmlObjMgt.hxx>
28 #include <XmlMDataStd.hxx>
30 IMPLEMENT_DOMSTRING (FirstIndexString, "first")
31 IMPLEMENT_DOMSTRING (LastIndexString, "last")
32 IMPLEMENT_DOMSTRING (IsDeltaOn, "delta")
34 //=======================================================================
35 //function : XmlMDataStd_RealArrayDriver
36 //purpose : Constructor
37 //=======================================================================
39 XmlMDataStd_RealArrayDriver::XmlMDataStd_RealArrayDriver
40 (const Handle(CDM_MessageDriver)& theMsgDriver)
41 : XmlMDF_ADriver (theMsgDriver, NULL)
44 //=======================================================================
47 //=======================================================================
48 Handle(TDF_Attribute) XmlMDataStd_RealArrayDriver::NewEmpty() const
50 return (new TDataStd_RealArray());
53 //=======================================================================
55 //purpose : persistent -> transient (retrieve)
56 //=======================================================================
57 Standard_Boolean XmlMDataStd_RealArrayDriver::Paste
58 (const XmlObjMgt_Persistent& theSource,
59 const Handle(TDF_Attribute)& theTarget,
60 XmlObjMgt_RRelocationTable& ) const
62 Standard_Integer aFirstInd, aLastInd, ind;
64 const XmlObjMgt_Element& anElement = theSource;
66 // Read the FirstIndex; if the attribute is absent initialize to 1
67 XmlObjMgt_DOMString aFirstIndex= anElement.getAttribute(::FirstIndexString());
68 if (aFirstIndex == NULL)
70 else if (!aFirstIndex.GetInteger(aFirstInd)) {
71 TCollection_ExtendedString aMessageString =
72 TCollection_ExtendedString("Cannot retrieve the first index"
73 " for RealArray attribute as \"")
75 WriteMessage (aMessageString);
76 return Standard_False;
79 // Read LastIndex; the attribute should be present
80 if (!anElement.getAttribute(::LastIndexString()).GetInteger(aLastInd)) {
81 TCollection_ExtendedString aMessageString =
82 TCollection_ExtendedString("Cannot retrieve the last index"
83 " for RealArray attribute as \"")
85 WriteMessage (aMessageString);
86 return Standard_False;
89 Handle(TDataStd_RealArray) aRealArray =
90 Handle(TDataStd_RealArray)::DownCast(theTarget);
91 aRealArray->Init(aFirstInd, aLastInd);
93 // Check the type of LDOMString
94 const XmlObjMgt_DOMString& aString = XmlObjMgt::GetStringValue(anElement);
95 if (aString.Type() == LDOMBasicString::LDOM_Integer) {
96 if (aFirstInd == aLastInd) {
97 Standard_Integer anIntValue;
98 if (aString.GetInteger(anIntValue))
99 aRealArray -> SetValue (aFirstInd, Standard_Real(anIntValue));
101 TCollection_ExtendedString aMessageString =
102 TCollection_ExtendedString("Cannot retrieve array of real members"
103 " for RealArray attribute from Integer \"")
105 WriteMessage (aMessageString);
106 return Standard_False;
109 Standard_CString aValueStr = Standard_CString(aString.GetString());
110 for (ind = aFirstInd; ind <= aLastInd; ind++)
112 if (!XmlObjMgt::GetReal(aValueStr, aValue)) {
113 TCollection_ExtendedString aMessageString =
114 TCollection_ExtendedString("Cannot retrieve real member"
115 " for RealArray attribute as \"")
117 WriteMessage (aMessageString);
118 return Standard_False;
120 aRealArray->SetValue(ind, aValue);
124 //cout << "CurDocVersion = " << XmlMDataStd::DocumentVersion() <<endl;
126 Standard_Boolean aDelta(Standard_False);
128 if(XmlMDataStd::DocumentVersion() > 2) {
129 Standard_Integer aDeltaValue;
130 if (!anElement.getAttribute(::IsDeltaOn()).GetInteger(aDeltaValue))
132 TCollection_ExtendedString aMessageString =
133 TCollection_ExtendedString("Cannot retrieve the isDelta value"
134 " for RealArray attribute as \"")
135 + aDeltaValue + "\"";
136 WriteMessage (aMessageString);
137 return Standard_False;
140 aDelta = (Standard_Boolean)aDeltaValue;
143 else if(XmlMDataStd::DocumentVersion() == -1)
144 cout << "Current DocVersion field is not initialized. " <<endl;
146 aRealArray->SetDelta(aDelta);
148 return Standard_True;
151 //=======================================================================
153 //purpose : transient -> persistent (store)
154 //=======================================================================
155 void XmlMDataStd_RealArrayDriver::Paste (const Handle(TDF_Attribute)& theSource,
156 XmlObjMgt_Persistent& theTarget,
157 XmlObjMgt_SRelocationTable& ) const
159 Handle(TDataStd_RealArray) aRealArray =
160 Handle(TDataStd_RealArray)::DownCast(theSource);
162 Standard_Integer aL = aRealArray->Lower(), anU = aRealArray->Upper();
163 TCollection_AsciiString aValueStr;
165 if (aL != 1) theTarget.Element().setAttribute(::FirstIndexString(), aL);
166 theTarget.Element().setAttribute(::LastIndexString(), anU);
167 theTarget.Element().setAttribute(::IsDeltaOn(), aRealArray->GetDelta());
169 Standard_Integer i = aL;
172 aValueStr += TCollection_AsciiString(aRealArray->Value(i));
175 Sprintf(aValueChar, "%.15g", aRealArray->Value(i));
176 aValueStr += aValueChar;
182 // No occurrence of '&', '<' and other irregular XML characters
183 XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);