0027232: Configuration - fix mblen missing building issue on Android
[occt.git] / src / XmlObjMgt / XmlObjMgt_GP.cxx
1 // Created on: 2001-08-02
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
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>
24 static const char * Translate (const char * theStr, gp_Mat& M);
25 static const char * Translate (const char * theStr, gp_XYZ& P);
26
27 // STORE
28
29 //=======================================================================
30 //function : Translate
31 //purpose  : 
32 //=======================================================================
33 XmlObjMgt_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()));
38   Sprintf (buf, "%.17g %d %s %s", aTrsf.ScaleFactor(), aTrsf.Form(),
39            S1.GetString(), S2.GetString());
40
41   return XmlObjMgt_DOMString (buf);
42 }
43
44 //=======================================================================
45 //function : Translate
46 //purpose  : 
47 //=======================================================================
48 XmlObjMgt_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)));
54   Sprintf (buf, "%s %s %s", S1.GetString(), S2.GetString(), S3.GetString());
55   return XmlObjMgt_DOMString (buf);
56 }
57
58 //=======================================================================
59 //function : Translate
60 //purpose  : 
61 //=======================================================================
62 XmlObjMgt_DOMString XmlObjMgt_GP::Translate (const gp_XYZ& anXYZ)
63 {
64   char buf [64];
65   Sprintf (buf, "%.17g %.17g %.17g", anXYZ.X(), anXYZ.Y(), anXYZ.Z());
66   return XmlObjMgt_DOMString (buf);
67 }
68
69 // RETRIEVE
70
71 //=======================================================================
72 //function : Translate
73 //purpose  : 
74 //=======================================================================
75 Standard_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;
82   Standard_Real aScaleFactor = Standard_Real(Strtod (aStr, &ptr));
83   if (ptr != aStr && errno != ERANGE && errno != EINVAL)
84   {
85     T.SetScaleFactor(aScaleFactor);
86     aStr = ptr;
87     Standard_Integer aForm = Standard_Integer(strtol(aStr, &ptr, 10));
88     if (ptr != aStr && errno != ERANGE && errno != EINVAL) {
89       T.SetForm((gp_TrsfForm)aForm);
90       aStr = ptr;
91
92 //  gp_Mat aMatr;
93       aStr = ::Translate(aStr, (gp_Mat&)T.HVectorialPart());
94       if (aStr) {
95
96 //  gp_XYZ aTransl;
97         ::Translate(aStr, (gp_XYZ&)T.TranslationPart());
98         aResult = Standard_True;
99       }
100     }
101   }
102   return aResult;
103 }
104
105 //=======================================================================
106 //function : Translate
107 //purpose  : 
108 //=======================================================================
109 Standard_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 //=======================================================================
119 Standard_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 //=======================================================================
129 static 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 //=======================================================================
151 static const char * Translate (const char * theStr, gp_XYZ& P)
152 {
153   char * ptr;
154   if (theStr) {
155     errno = 0;
156     Standard_Real aC = Strtod (theStr, &ptr);
157     if (ptr != theStr && errno != ERANGE && errno != EINVAL) {
158       P.SetX(aC);
159       theStr = ptr;
160       aC = Strtod (theStr, &ptr);
161       if (ptr != theStr && errno != ERANGE && errno != EINVAL) {
162         P.SetY(aC);
163         theStr = ptr;
164         aC = Strtod (theStr, &ptr);
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 }