0027232: Configuration - fix mblen missing building issue on Android
[occt.git] / src / XmlMNaming / XmlMNaming_Shape1.cxx
CommitLineData
b311480e 1// Created on: 2001-08-01
2// Created by: Alexander GRIGORIEV
973c2be1 3// Copyright (c) 2001-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
42cf5bc1 17#include <BRep_Tool.hxx>
18#include <gp_Pnt.hxx>
7fd59977 19#include <TCollection_AsciiString.hxx>
7fd59977 20#include <TopoDS.hxx>
42cf5bc1 21#include <TopoDS_Shape.hxx>
22#include <TopoDS_Vertex.hxx>
23#include <XmlMNaming_Shape1.hxx>
24#include <XmlObjMgt.hxx>
7fd59977 25
26#include <stdio.h>
7fd59977 27IMPLEMENT_DOMSTRING (TShapeString, "tshape")
28IMPLEMENT_DOMSTRING (LocationString, "location")
29
30IMPLEMENT_DOMSTRING (XCoordString, "x")
31IMPLEMENT_DOMSTRING (YCoordString, "y")
32IMPLEMENT_DOMSTRING (ZCoordString, "z")
33
34//=======================================================================
35//function : XmlMNaming_Shape1
36//purpose :
37//=======================================================================
38XmlMNaming_Shape1::XmlMNaming_Shape1 (XmlObjMgt_Document& theDoc)
39 : myTShapeID (0),
40 myLocID (0),
41 myOrientation (TopAbs_FORWARD)
42{
43 myElement = theDoc.createElement(XmlObjMgt_DOMString("shape"));
44}
45
46//=======================================================================
47//function : XmlMNaming_Shape1
48//purpose :
49//=======================================================================
50XmlMNaming_Shape1::XmlMNaming_Shape1 (const XmlObjMgt_Element& theEl)
51 : myElement(theEl),
52 myTShapeID (0),
53 myLocID (0),
54 myOrientation (TopAbs_FORWARD)
55{
56 if (myElement != NULL)
57 {
58 myElement.getAttribute(::LocationString()).GetInteger (myLocID);
59 XmlObjMgt_DOMString aString = myElement.getAttribute(::TShapeString());
60 const char * aPtr = aString.GetString();
61 switch (* aPtr) {
62 case '+' : myOrientation = TopAbs_FORWARD; break;
63 case '-' : myOrientation = TopAbs_REVERSED; break;
64 case 'i' : myOrientation = TopAbs_INTERNAL; break;
65 case 'e' : myOrientation = TopAbs_EXTERNAL; break;
66 default: Standard_DomainError::Raise
67 ("XmlMNaming_Shape1; orientation value without enum term equivalence");
68 }
69 Standard_CString anIntPtr = (Standard_CString) &aPtr[1];
70 if (XmlObjMgt::GetInteger (anIntPtr, myTShapeID) == Standard_False)
71 Standard_DomainError::Raise
72 ("XmlMNaming_Shape1; tshape value cannot be initialised by integer");
73 }
74}
75
76//=======================================================================
77//function : Element
78//purpose :
79//=======================================================================
80const XmlObjMgt_Element& XmlMNaming_Shape1::Element() const
81{
82 return myElement;
83}
84
85//=======================================================================
86//function : Element
87//purpose :
88//=======================================================================
89XmlObjMgt_Element& XmlMNaming_Shape1::Element()
90{
91 return myElement;
92}
93
94//=======================================================================
95//function : TShapeId
96//purpose :
97//=======================================================================
98Standard_Integer XmlMNaming_Shape1::TShapeId() const
99{
100 return myTShapeID;
101}
102
103//=======================================================================
104//function : LocId
105//purpose :
106//=======================================================================
107Standard_Integer XmlMNaming_Shape1::LocId() const
108{
109 return myLocID;
110}
111
112//=======================================================================
113//function : Orientation
114//purpose :
115//=======================================================================
116TopAbs_Orientation XmlMNaming_Shape1::Orientation() const
117{
118 return myOrientation;
119}
120
121//=======================================================================
122//function : SetShape
123//purpose :
124//=======================================================================
125void XmlMNaming_Shape1::SetShape (const Standard_Integer theID,
126 const Standard_Integer theLocID,
127 const TopAbs_Orientation theOrient)
128{
129 myTShapeID = theID;
130 myLocID = theLocID;
131 myOrientation = theOrient;
132
133 char aBuffer[16], anOr;
134
135 switch (theOrient) {
136 case TopAbs_FORWARD : anOr = '+'; break;
137 case TopAbs_REVERSED : anOr = '-'; break;
138 case TopAbs_INTERNAL : anOr = 'i'; break;
139 case TopAbs_EXTERNAL : anOr = 'e'; break;
140 default : anOr = '\0';
141 }
91322f44 142 Sprintf (aBuffer, "%c%i", anOr, theID);
7fd59977 143 Element().setAttribute (::TShapeString(), aBuffer);
144 if (theLocID > 0)
145 Element().setAttribute (::LocationString(), theLocID);
146}
147
148//=======================================================================
149//function : SetVertex
150//purpose :
151//=======================================================================
152void XmlMNaming_Shape1::SetVertex (const TopoDS_Shape& theVertex)
153{
154 TopoDS_Vertex aV = TopoDS::Vertex(theVertex);
155 gp_Pnt aPos = BRep_Tool::Pnt(aV);
156
157 char buf [16];
91322f44 158 Sprintf (buf, "%.8g", aPos.X());
7fd59977 159 Element().setAttribute (::XCoordString(), buf);
160
91322f44 161 Sprintf (buf, "%.8g", aPos.Y());
7fd59977 162 Element().setAttribute (::YCoordString(), buf);
163
91322f44 164 Sprintf (buf, "%.8g", aPos.Z());
7fd59977 165 Element().setAttribute (::ZCoordString(), buf);
166}