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