1 // File: XmlMNaming_Shape1.cxx
2 // Created: 01.08.01 18:26:53
3 // Author: Alexander GRIGORIEV
4 // Copyright: Open Cascade 2001
7 #include <XmlMNaming_Shape1.ixx>
9 #include <XmlObjMgt.hxx>
10 #include <TCollection_AsciiString.hxx>
11 #include <TopoDS_Vertex.hxx>
14 #include <BRep_Tool.hxx>
18 IMPLEMENT_DOMSTRING (TShapeString, "tshape")
19 IMPLEMENT_DOMSTRING (LocationString, "location")
21 IMPLEMENT_DOMSTRING (XCoordString, "x")
22 IMPLEMENT_DOMSTRING (YCoordString, "y")
23 IMPLEMENT_DOMSTRING (ZCoordString, "z")
25 //=======================================================================
26 //function : XmlMNaming_Shape1
28 //=======================================================================
29 XmlMNaming_Shape1::XmlMNaming_Shape1 (XmlObjMgt_Document& theDoc)
32 myOrientation (TopAbs_FORWARD)
34 myElement = theDoc.createElement(XmlObjMgt_DOMString("shape"));
37 //=======================================================================
38 //function : XmlMNaming_Shape1
40 //=======================================================================
41 XmlMNaming_Shape1::XmlMNaming_Shape1 (const XmlObjMgt_Element& theEl)
45 myOrientation (TopAbs_FORWARD)
47 if (myElement != NULL)
49 myElement.getAttribute(::LocationString()).GetInteger (myLocID);
50 XmlObjMgt_DOMString aString = myElement.getAttribute(::TShapeString());
51 const char * aPtr = aString.GetString();
53 case '+' : myOrientation = TopAbs_FORWARD; break;
54 case '-' : myOrientation = TopAbs_REVERSED; break;
55 case 'i' : myOrientation = TopAbs_INTERNAL; break;
56 case 'e' : myOrientation = TopAbs_EXTERNAL; break;
57 default: Standard_DomainError::Raise
58 ("XmlMNaming_Shape1; orientation value without enum term equivalence");
60 Standard_CString anIntPtr = (Standard_CString) &aPtr[1];
61 if (XmlObjMgt::GetInteger (anIntPtr, myTShapeID) == Standard_False)
62 Standard_DomainError::Raise
63 ("XmlMNaming_Shape1; tshape value cannot be initialised by integer");
67 //=======================================================================
70 //=======================================================================
71 const XmlObjMgt_Element& XmlMNaming_Shape1::Element() const
76 //=======================================================================
79 //=======================================================================
80 XmlObjMgt_Element& XmlMNaming_Shape1::Element()
85 //=======================================================================
88 //=======================================================================
89 Standard_Integer XmlMNaming_Shape1::TShapeId() const
94 //=======================================================================
97 //=======================================================================
98 Standard_Integer XmlMNaming_Shape1::LocId() const
103 //=======================================================================
104 //function : Orientation
106 //=======================================================================
107 TopAbs_Orientation XmlMNaming_Shape1::Orientation() const
109 return myOrientation;
112 //=======================================================================
113 //function : SetShape
115 //=======================================================================
116 void XmlMNaming_Shape1::SetShape (const Standard_Integer theID,
117 const Standard_Integer theLocID,
118 const TopAbs_Orientation theOrient)
122 myOrientation = theOrient;
124 char aBuffer[16], anOr;
127 case TopAbs_FORWARD : anOr = '+'; break;
128 case TopAbs_REVERSED : anOr = '-'; break;
129 case TopAbs_INTERNAL : anOr = 'i'; break;
130 case TopAbs_EXTERNAL : anOr = 'e'; break;
131 default : anOr = '\0';
133 sprintf (aBuffer, "%c%i", anOr, theID);
134 Element().setAttribute (::TShapeString(), aBuffer);
136 Element().setAttribute (::LocationString(), theLocID);
139 //=======================================================================
140 //function : SetVertex
142 //=======================================================================
143 void XmlMNaming_Shape1::SetVertex (const TopoDS_Shape& theVertex)
145 TopoDS_Vertex aV = TopoDS::Vertex(theVertex);
146 gp_Pnt aPos = BRep_Tool::Pnt(aV);
149 sprintf (buf, "%.8g", aPos.X());
150 Element().setAttribute (::XCoordString(), buf);
152 sprintf (buf, "%.8g", aPos.Y());
153 Element().setAttribute (::YCoordString(), buf);
155 sprintf (buf, "%.8g", aPos.Z());
156 Element().setAttribute (::ZCoordString(), buf);