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