1 // Created on: 2001-08-01
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <XmlMNaming_Shape1.ixx>
18 #include <XmlObjMgt.hxx>
19 #include <TCollection_AsciiString.hxx>
20 #include <TopoDS_Vertex.hxx>
23 #include <BRep_Tool.hxx>
27 IMPLEMENT_DOMSTRING (TShapeString, "tshape")
28 IMPLEMENT_DOMSTRING (LocationString, "location")
30 IMPLEMENT_DOMSTRING (XCoordString, "x")
31 IMPLEMENT_DOMSTRING (YCoordString, "y")
32 IMPLEMENT_DOMSTRING (ZCoordString, "z")
34 //=======================================================================
35 //function : XmlMNaming_Shape1
37 //=======================================================================
38 XmlMNaming_Shape1::XmlMNaming_Shape1 (XmlObjMgt_Document& theDoc)
41 myOrientation (TopAbs_FORWARD)
43 myElement = theDoc.createElement(XmlObjMgt_DOMString("shape"));
46 //=======================================================================
47 //function : XmlMNaming_Shape1
49 //=======================================================================
50 XmlMNaming_Shape1::XmlMNaming_Shape1 (const XmlObjMgt_Element& theEl)
54 myOrientation (TopAbs_FORWARD)
56 if (myElement != NULL)
58 myElement.getAttribute(::LocationString()).GetInteger (myLocID);
59 XmlObjMgt_DOMString aString = myElement.getAttribute(::TShapeString());
60 const char * aPtr = aString.GetString();
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");
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");
76 //=======================================================================
79 //=======================================================================
80 const XmlObjMgt_Element& XmlMNaming_Shape1::Element() const
85 //=======================================================================
88 //=======================================================================
89 XmlObjMgt_Element& XmlMNaming_Shape1::Element()
94 //=======================================================================
97 //=======================================================================
98 Standard_Integer XmlMNaming_Shape1::TShapeId() const
103 //=======================================================================
106 //=======================================================================
107 Standard_Integer XmlMNaming_Shape1::LocId() const
112 //=======================================================================
113 //function : Orientation
115 //=======================================================================
116 TopAbs_Orientation XmlMNaming_Shape1::Orientation() const
118 return myOrientation;
121 //=======================================================================
122 //function : SetShape
124 //=======================================================================
125 void XmlMNaming_Shape1::SetShape (const Standard_Integer theID,
126 const Standard_Integer theLocID,
127 const TopAbs_Orientation theOrient)
131 myOrientation = theOrient;
133 char aBuffer[16], anOr;
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';
142 Sprintf (aBuffer, "%c%i", anOr, theID);
143 Element().setAttribute (::TShapeString(), aBuffer);
145 Element().setAttribute (::LocationString(), theLocID);
148 //=======================================================================
149 //function : SetVertex
151 //=======================================================================
152 void XmlMNaming_Shape1::SetVertex (const TopoDS_Shape& theVertex)
154 TopoDS_Vertex aV = TopoDS::Vertex(theVertex);
155 gp_Pnt aPos = BRep_Tool::Pnt(aV);
158 Sprintf (buf, "%.8g", aPos.X());
159 Element().setAttribute (::XCoordString(), buf);
161 Sprintf (buf, "%.8g", aPos.Y());
162 Element().setAttribute (::YCoordString(), buf);
164 Sprintf (buf, "%.8g", aPos.Z());
165 Element().setAttribute (::ZCoordString(), buf);