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.
18 #include <gp_Trsf.hxx>
20 #include <XmlObjMgt_GP.hxx>
24 static const char * Translate (const char * theStr, gp_Mat& M);
25 static const char * Translate (const char * theStr, gp_XYZ& P);
29 //=======================================================================
30 //function : Translate
32 //=======================================================================
33 XmlObjMgt_DOMString XmlObjMgt_GP::Translate (const gp_Trsf& aTrsf)
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());
41 return XmlObjMgt_DOMString (buf);
44 //=======================================================================
45 //function : Translate
47 //=======================================================================
48 XmlObjMgt_DOMString XmlObjMgt_GP::Translate (const gp_Mat& aMat)
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);
58 //=======================================================================
59 //function : Translate
61 //=======================================================================
62 XmlObjMgt_DOMString XmlObjMgt_GP::Translate (const gp_XYZ& anXYZ)
64 char buf [75]; // (24 + 1) * 3
65 Sprintf (buf, "%.17g %.17g %.17g", anXYZ.X(), anXYZ.Y(), anXYZ.Z());
66 return XmlObjMgt_DOMString (buf);
71 //=======================================================================
72 //function : Translate
74 //=======================================================================
75 Standard_Boolean XmlObjMgt_GP::Translate
76 (const XmlObjMgt_DOMString& theStr, gp_Trsf& T)
78 Standard_Boolean aResult = Standard_False;
79 const char * aStr = theStr.GetString();
82 Standard_Real aScaleFactor = Standard_Real(Strtod (aStr, &ptr));
83 if (ptr != aStr && errno != ERANGE && errno != EINVAL)
85 T.SetScaleFactor(aScaleFactor);
87 Standard_Integer aForm = Standard_Integer(strtol(aStr, &ptr, 10));
88 if (ptr != aStr && errno != ERANGE && errno != EINVAL) {
89 T.SetForm((gp_TrsfForm)aForm);
93 aStr = ::Translate(aStr, (gp_Mat&)T.HVectorialPart());
97 ::Translate(aStr, (gp_XYZ&)T.TranslationPart());
98 aResult = Standard_True;
105 //=======================================================================
106 //function : Translate
108 //=======================================================================
109 Standard_Boolean XmlObjMgt_GP::Translate
110 (const XmlObjMgt_DOMString& theStr, gp_Mat& M)
112 return (::Translate (theStr.GetString(), M) != 0);
115 //=======================================================================
116 //function : Translate
118 //=======================================================================
119 Standard_Boolean XmlObjMgt_GP::Translate
120 (const XmlObjMgt_DOMString& theStr, gp_XYZ& P)
122 return (::Translate (theStr.GetString(), P) != 0);
125 //=======================================================================
126 //function : Translate
128 //=======================================================================
129 static const char * Translate (const char * theStr, gp_Mat& M)
133 theStr = Translate(theStr, aC);
136 theStr = Translate(theStr, aC);
139 theStr = Translate(theStr, aC);
147 //=======================================================================
148 //function : Translate
150 //=======================================================================
151 static const char * Translate (const char * theStr, gp_XYZ& P)
156 Standard_Real 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) {
164 aC = Strtod (theStr, &ptr);
165 if (ptr != theStr && errno != ERANGE && errno != EINVAL) {