0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / XmlMNaming / XmlMNaming_Shape1.cxx
1 // Created on: 2001-08-01
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
17 #include <BRep_Tool.hxx>
18 #include <gp_Pnt.hxx>
19 #include <TCollection_AsciiString.hxx>
20 #include <TopoDS.hxx>
21 #include <TopoDS_Shape.hxx>
22 #include <TopoDS_Vertex.hxx>
23 #include <XmlMNaming_Shape1.hxx>
24 #include <XmlObjMgt.hxx>
25
26 #include <stdio.h>
27 IMPLEMENT_DOMSTRING (TShapeString,   "tshape")
28 IMPLEMENT_DOMSTRING (LocationString, "location")
29
30 IMPLEMENT_DOMSTRING (XCoordString, "x")
31 IMPLEMENT_DOMSTRING (YCoordString, "y")
32 IMPLEMENT_DOMSTRING (ZCoordString, "z")
33
34 //=======================================================================
35 //function : XmlMNaming_Shape1
36 //purpose  : 
37 //=======================================================================
38 XmlMNaming_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 //=======================================================================
50 XmlMNaming_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:   throw Standard_DomainError("XmlMNaming_Shape1; orientation value without enum term equivalence");
67     }
68     Standard_CString anIntPtr = (Standard_CString) &aPtr[1];
69     if (XmlObjMgt::GetInteger (anIntPtr, myTShapeID) == Standard_False)
70       throw Standard_DomainError("XmlMNaming_Shape1; tshape value cannot be initialised by integer");
71   }
72 }
73
74 //=======================================================================
75 //function : Element
76 //purpose  : 
77 //=======================================================================
78 const XmlObjMgt_Element& XmlMNaming_Shape1::Element() const
79 {
80   return myElement;
81 }
82
83 //=======================================================================
84 //function : Element
85 //purpose  : 
86 //=======================================================================
87 XmlObjMgt_Element& XmlMNaming_Shape1::Element()
88 {
89   return myElement;
90 }
91
92 //=======================================================================
93 //function : TShapeId
94 //purpose  : 
95 //=======================================================================
96 Standard_Integer XmlMNaming_Shape1::TShapeId() const 
97 {
98   return myTShapeID;
99 }
100
101 //=======================================================================
102 //function : LocId
103 //purpose  : 
104 //=======================================================================
105 Standard_Integer XmlMNaming_Shape1::LocId() const 
106 {
107   return myLocID;
108 }
109
110 //=======================================================================
111 //function : Orientation
112 //purpose  : 
113 //=======================================================================
114 TopAbs_Orientation  XmlMNaming_Shape1::Orientation() const 
115 {
116   return myOrientation;
117 }
118
119 //=======================================================================
120 //function : SetShape
121 //purpose  : 
122 //=======================================================================
123 void  XmlMNaming_Shape1::SetShape (const Standard_Integer       theID,
124                                    const Standard_Integer       theLocID,
125                                    const TopAbs_Orientation     theOrient)
126 {
127   myTShapeID    = theID;
128   myLocID       = theLocID;
129   myOrientation = theOrient;
130
131   char aBuffer[16], anOr;
132   
133   switch (theOrient) {
134   case TopAbs_FORWARD   : anOr = '+'; break;
135   case TopAbs_REVERSED  : anOr = '-'; break;
136   case TopAbs_INTERNAL  : anOr = 'i'; break;
137   case TopAbs_EXTERNAL  : anOr = 'e'; break;
138   default               : anOr = '\0';
139   }
140   Sprintf (aBuffer, "%c%i", anOr, theID);
141   Element().setAttribute (::TShapeString(), aBuffer);
142   if (theLocID > 0)
143     Element().setAttribute (::LocationString(), theLocID);
144 }
145
146 //=======================================================================
147 //function : SetVertex
148 //purpose  : 
149 //=======================================================================
150 void XmlMNaming_Shape1::SetVertex (const TopoDS_Shape& theVertex)
151 {
152   TopoDS_Vertex aV = TopoDS::Vertex(theVertex);
153   gp_Pnt aPos = BRep_Tool::Pnt(aV);
154
155   char buf [16];
156   Sprintf (buf, "%.8g", aPos.X());
157   Element().setAttribute (::XCoordString(), buf);
158
159   Sprintf (buf, "%.8g", aPos.Y());
160   Element().setAttribute (::YCoordString(), buf);
161
162   Sprintf (buf, "%.8g", aPos.Z());
163   Element().setAttribute (::ZCoordString(), buf);
164 }