1 // Created on: 2001-08-02
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-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.
16 #include <XmlObjMgt_GP.ixx>
20 static const char * Translate (const char * theStr, gp_Mat& M);
21 static const char * Translate (const char * theStr, gp_XYZ& P);
25 //=======================================================================
26 //function : Translate
28 //=======================================================================
29 XmlObjMgt_DOMString XmlObjMgt_GP::Translate (const gp_Trsf& aTrsf)
32 XmlObjMgt_DOMString S1 (Translate(aTrsf.HVectorialPart())),
33 S2 (Translate(aTrsf.TranslationPart()));
34 Sprintf (buf, "%.17g %d %s %s", aTrsf.ScaleFactor(), aTrsf.Form(),
35 S1.GetString(), S2.GetString());
37 return XmlObjMgt_DOMString (buf);
40 //=======================================================================
41 //function : Translate
43 //=======================================================================
44 XmlObjMgt_DOMString XmlObjMgt_GP::Translate (const gp_Mat& aMat)
47 XmlObjMgt_DOMString S1 (Translate(aMat.Row(1))),
48 S2 (Translate(aMat.Row(2))),
49 S3 (Translate(aMat.Row(3)));
50 Sprintf (buf, "%s %s %s", S1.GetString(), S2.GetString(), S3.GetString());
51 return XmlObjMgt_DOMString (buf);
54 //=======================================================================
55 //function : Translate
57 //=======================================================================
58 XmlObjMgt_DOMString XmlObjMgt_GP::Translate (const gp_XYZ& anXYZ)
61 Sprintf (buf, "%.17g %.17g %.17g", anXYZ.X(), anXYZ.Y(), anXYZ.Z());
62 return XmlObjMgt_DOMString (buf);
67 //=======================================================================
68 //function : Translate
70 //=======================================================================
71 Standard_Boolean XmlObjMgt_GP::Translate
72 (const XmlObjMgt_DOMString& theStr, gp_Trsf& T)
74 Standard_Boolean aResult = Standard_False;
75 const char * aStr = theStr.GetString();
78 Standard_Real aScaleFactor = Standard_Real(Strtod (aStr, &ptr));
79 if (ptr != aStr && errno != ERANGE && errno != EINVAL)
81 T.SetScaleFactor(aScaleFactor);
83 Standard_Integer aForm = Standard_Integer(strtol(aStr, &ptr, 10));
84 if (ptr != aStr && errno != ERANGE && errno != EINVAL) {
85 T.SetForm((gp_TrsfForm)aForm);
89 aStr = ::Translate(aStr, (gp_Mat&)T.HVectorialPart());
93 ::Translate(aStr, (gp_XYZ&)T.TranslationPart());
94 aResult = Standard_True;
101 //=======================================================================
102 //function : Translate
104 //=======================================================================
105 Standard_Boolean XmlObjMgt_GP::Translate
106 (const XmlObjMgt_DOMString& theStr, gp_Mat& M)
108 return (::Translate (theStr.GetString(), M) != 0);
111 //=======================================================================
112 //function : Translate
114 //=======================================================================
115 Standard_Boolean XmlObjMgt_GP::Translate
116 (const XmlObjMgt_DOMString& theStr, gp_XYZ& P)
118 return (::Translate (theStr.GetString(), P) != 0);
121 //=======================================================================
122 //function : Translate
124 //=======================================================================
125 static const char * Translate (const char * theStr, gp_Mat& M)
129 theStr = Translate(theStr, aC);
132 theStr = Translate(theStr, aC);
135 theStr = Translate(theStr, aC);
143 //=======================================================================
144 //function : Translate
146 //=======================================================================
147 static const char * Translate (const char * theStr, gp_XYZ& P)
152 Standard_Real aC = Strtod (theStr, &ptr);
153 if (ptr != theStr && errno != ERANGE && errno != EINVAL) {
156 aC = Strtod (theStr, &ptr);
157 if (ptr != theStr && errno != ERANGE && errno != EINVAL) {
160 aC = Strtod (theStr, &ptr);
161 if (ptr != theStr && errno != ERANGE && errno != EINVAL) {