Warnings on vc14 were eliminated
[occt.git] / src / XmlObjMgt / XmlObjMgt_GP.cxx
CommitLineData
b311480e 1// Created on: 2001-08-02
2// Created by: Alexander GRIGORIEV
973c2be1 3// Copyright (c) 2001-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
42cf5bc1 17#include <gp_Mat.hxx>
18#include <gp_Trsf.hxx>
19#include <gp_XYZ.hxx>
20#include <XmlObjMgt_GP.hxx>
21
22#include <errno.h>
23#include <stdio.h>
7fd59977 24static const char * Translate (const char * theStr, gp_Mat& M);
25static const char * Translate (const char * theStr, gp_XYZ& P);
26
27// STORE
28
29//=======================================================================
30//function : Translate
31//purpose :
32//=======================================================================
33XmlObjMgt_DOMString XmlObjMgt_GP::Translate (const gp_Trsf& aTrsf)
34{
35 char buf [256];
36 XmlObjMgt_DOMString S1 (Translate(aTrsf.HVectorialPart())),
37 S2 (Translate(aTrsf.TranslationPart()));
91322f44 38 Sprintf (buf, "%.17g %d %s %s", aTrsf.ScaleFactor(), aTrsf.Form(),
7fd59977 39 S1.GetString(), S2.GetString());
40
41 return XmlObjMgt_DOMString (buf);
42}
43
44//=======================================================================
45//function : Translate
46//purpose :
47//=======================================================================
48XmlObjMgt_DOMString XmlObjMgt_GP::Translate (const gp_Mat& aMat)
49{
50 char buf[128];
51 XmlObjMgt_DOMString S1 (Translate(aMat.Row(1))),
52 S2 (Translate(aMat.Row(2))),
53 S3 (Translate(aMat.Row(3)));
91322f44 54 Sprintf (buf, "%s %s %s", S1.GetString(), S2.GetString(), S3.GetString());
7fd59977 55 return XmlObjMgt_DOMString (buf);
56}
57
58//=======================================================================
59//function : Translate
60//purpose :
61//=======================================================================
62XmlObjMgt_DOMString XmlObjMgt_GP::Translate (const gp_XYZ& anXYZ)
63{
64 char buf [64];
91322f44 65 Sprintf (buf, "%.17g %.17g %.17g", anXYZ.X(), anXYZ.Y(), anXYZ.Z());
7fd59977 66 return XmlObjMgt_DOMString (buf);
67}
68
69// RETRIEVE
70
71//=======================================================================
72//function : Translate
73//purpose :
74//=======================================================================
75Standard_Boolean XmlObjMgt_GP::Translate
76 (const XmlObjMgt_DOMString& theStr, gp_Trsf& T)
77{
78 Standard_Boolean aResult = Standard_False;
79 const char * aStr = theStr.GetString();
80 char * ptr;
81 errno = 0;
91322f44 82 Standard_Real aScaleFactor = Standard_Real(Strtod (aStr, &ptr));
7fd59977 83 if (ptr != aStr && errno != ERANGE && errno != EINVAL)
84 {
087da3bd 85 T.SetScaleFactor(aScaleFactor);
7fd59977 86 aStr = ptr;
87 Standard_Integer aForm = Standard_Integer(strtol(aStr, &ptr, 10));
88 if (ptr != aStr && errno != ERANGE && errno != EINVAL) {
087da3bd 89 T.SetForm((gp_TrsfForm)aForm);
7fd59977 90 aStr = ptr;
91
92// gp_Mat aMatr;
087da3bd 93 aStr = ::Translate(aStr, (gp_Mat&)T.HVectorialPart());
7fd59977 94 if (aStr) {
95
96// gp_XYZ aTransl;
087da3bd 97 ::Translate(aStr, (gp_XYZ&)T.TranslationPart());
7fd59977 98 aResult = Standard_True;
99 }
100 }
101 }
102 return aResult;
103}
104
105//=======================================================================
106//function : Translate
107//purpose :
108//=======================================================================
109Standard_Boolean XmlObjMgt_GP::Translate
110 (const XmlObjMgt_DOMString& theStr, gp_Mat& M)
111{
112 return (::Translate (theStr.GetString(), M) != 0);
113}
114
115//=======================================================================
116//function : Translate
117//purpose :
118//=======================================================================
119Standard_Boolean XmlObjMgt_GP::Translate
120 (const XmlObjMgt_DOMString& theStr, gp_XYZ& P)
121{
122 return (::Translate (theStr.GetString(), P) != 0);
123}
124
125//=======================================================================
126//function : Translate
127//purpose :
128//=======================================================================
129static const char * Translate (const char * theStr, gp_Mat& M)
130{
131 gp_XYZ aC;
132
133 theStr = Translate(theStr, aC);
134 if (theStr) {
135 M.SetRow(1, aC);
136 theStr = Translate(theStr, aC);
137 if (theStr) {
138 M.SetRow(2, aC);
139 theStr = Translate(theStr, aC);
140 if (theStr)
141 M.SetRow(3, aC);
142 }
143 }
144 return theStr;
145}
146
147//=======================================================================
148//function : Translate
149//purpose :
150//=======================================================================
151static const char * Translate (const char * theStr, gp_XYZ& P)
152{
153 char * ptr;
154 if (theStr) {
155 errno = 0;
91322f44 156 Standard_Real aC = Strtod (theStr, &ptr);
7fd59977 157 if (ptr != theStr && errno != ERANGE && errno != EINVAL) {
158 P.SetX(aC);
159 theStr = ptr;
91322f44 160 aC = Strtod (theStr, &ptr);
7fd59977 161 if (ptr != theStr && errno != ERANGE && errno != EINVAL) {
162 P.SetY(aC);
163 theStr = ptr;
91322f44 164 aC = Strtod (theStr, &ptr);
7fd59977 165 if (ptr != theStr && errno != ERANGE && errno != EINVAL) {
166 P.SetZ(aC);
167 theStr = ptr;
168 } else
169 theStr = 0;
170 } else
171 theStr = 0;
172 } else
173 theStr = 0;
174 }
175 return theStr;
176}