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