b311480e |
1 | // Created on: 2001-08-01 |
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 <XmlMNaming_Shape1.ixx> |
22 | |
23 | #include <XmlObjMgt.hxx> |
24 | #include <TCollection_AsciiString.hxx> |
25 | #include <TopoDS_Vertex.hxx> |
26 | #include <TopoDS.hxx> |
27 | #include <gp_Pnt.hxx> |
28 | #include <BRep_Tool.hxx> |
29 | |
30 | #include <stdio.h> |
31 | |
32 | IMPLEMENT_DOMSTRING (TShapeString, "tshape") |
33 | IMPLEMENT_DOMSTRING (LocationString, "location") |
34 | |
35 | IMPLEMENT_DOMSTRING (XCoordString, "x") |
36 | IMPLEMENT_DOMSTRING (YCoordString, "y") |
37 | IMPLEMENT_DOMSTRING (ZCoordString, "z") |
38 | |
39 | //======================================================================= |
40 | //function : XmlMNaming_Shape1 |
41 | //purpose : |
42 | //======================================================================= |
43 | XmlMNaming_Shape1::XmlMNaming_Shape1 (XmlObjMgt_Document& theDoc) |
44 | : myTShapeID (0), |
45 | myLocID (0), |
46 | myOrientation (TopAbs_FORWARD) |
47 | { |
48 | myElement = theDoc.createElement(XmlObjMgt_DOMString("shape")); |
49 | } |
50 | |
51 | //======================================================================= |
52 | //function : XmlMNaming_Shape1 |
53 | //purpose : |
54 | //======================================================================= |
55 | XmlMNaming_Shape1::XmlMNaming_Shape1 (const XmlObjMgt_Element& theEl) |
56 | : myElement(theEl), |
57 | myTShapeID (0), |
58 | myLocID (0), |
59 | myOrientation (TopAbs_FORWARD) |
60 | { |
61 | if (myElement != NULL) |
62 | { |
63 | myElement.getAttribute(::LocationString()).GetInteger (myLocID); |
64 | XmlObjMgt_DOMString aString = myElement.getAttribute(::TShapeString()); |
65 | const char * aPtr = aString.GetString(); |
66 | switch (* aPtr) { |
67 | case '+' : myOrientation = TopAbs_FORWARD; break; |
68 | case '-' : myOrientation = TopAbs_REVERSED; break; |
69 | case 'i' : myOrientation = TopAbs_INTERNAL; break; |
70 | case 'e' : myOrientation = TopAbs_EXTERNAL; break; |
71 | default: Standard_DomainError::Raise |
72 | ("XmlMNaming_Shape1; orientation value without enum term equivalence"); |
73 | } |
74 | Standard_CString anIntPtr = (Standard_CString) &aPtr[1]; |
75 | if (XmlObjMgt::GetInteger (anIntPtr, myTShapeID) == Standard_False) |
76 | Standard_DomainError::Raise |
77 | ("XmlMNaming_Shape1; tshape value cannot be initialised by integer"); |
78 | } |
79 | } |
80 | |
81 | //======================================================================= |
82 | //function : Element |
83 | //purpose : |
84 | //======================================================================= |
85 | const XmlObjMgt_Element& XmlMNaming_Shape1::Element() const |
86 | { |
87 | return myElement; |
88 | } |
89 | |
90 | //======================================================================= |
91 | //function : Element |
92 | //purpose : |
93 | //======================================================================= |
94 | XmlObjMgt_Element& XmlMNaming_Shape1::Element() |
95 | { |
96 | return myElement; |
97 | } |
98 | |
99 | //======================================================================= |
100 | //function : TShapeId |
101 | //purpose : |
102 | //======================================================================= |
103 | Standard_Integer XmlMNaming_Shape1::TShapeId() const |
104 | { |
105 | return myTShapeID; |
106 | } |
107 | |
108 | //======================================================================= |
109 | //function : LocId |
110 | //purpose : |
111 | //======================================================================= |
112 | Standard_Integer XmlMNaming_Shape1::LocId() const |
113 | { |
114 | return myLocID; |
115 | } |
116 | |
117 | //======================================================================= |
118 | //function : Orientation |
119 | //purpose : |
120 | //======================================================================= |
121 | TopAbs_Orientation XmlMNaming_Shape1::Orientation() const |
122 | { |
123 | return myOrientation; |
124 | } |
125 | |
126 | //======================================================================= |
127 | //function : SetShape |
128 | //purpose : |
129 | //======================================================================= |
130 | void XmlMNaming_Shape1::SetShape (const Standard_Integer theID, |
131 | const Standard_Integer theLocID, |
132 | const TopAbs_Orientation theOrient) |
133 | { |
134 | myTShapeID = theID; |
135 | myLocID = theLocID; |
136 | myOrientation = theOrient; |
137 | |
138 | char aBuffer[16], anOr; |
139 | |
140 | switch (theOrient) { |
141 | case TopAbs_FORWARD : anOr = '+'; break; |
142 | case TopAbs_REVERSED : anOr = '-'; break; |
143 | case TopAbs_INTERNAL : anOr = 'i'; break; |
144 | case TopAbs_EXTERNAL : anOr = 'e'; break; |
145 | default : anOr = '\0'; |
146 | } |
147 | sprintf (aBuffer, "%c%i", anOr, theID); |
148 | Element().setAttribute (::TShapeString(), aBuffer); |
149 | if (theLocID > 0) |
150 | Element().setAttribute (::LocationString(), theLocID); |
151 | } |
152 | |
153 | //======================================================================= |
154 | //function : SetVertex |
155 | //purpose : |
156 | //======================================================================= |
157 | void XmlMNaming_Shape1::SetVertex (const TopoDS_Shape& theVertex) |
158 | { |
159 | TopoDS_Vertex aV = TopoDS::Vertex(theVertex); |
160 | gp_Pnt aPos = BRep_Tool::Pnt(aV); |
161 | |
162 | char buf [16]; |
163 | sprintf (buf, "%.8g", aPos.X()); |
164 | Element().setAttribute (::XCoordString(), buf); |
165 | |
166 | sprintf (buf, "%.8g", aPos.Y()); |
167 | Element().setAttribute (::YCoordString(), buf); |
168 | |
169 | sprintf (buf, "%.8g", aPos.Z()); |
170 | Element().setAttribute (::ZCoordString(), buf); |
171 | } |