summaryrefslogtreecommitdiff
path: root/src/XmlMNaming/XmlMNaming_Shape1.cxx
blob: 3400862a7cbefa47371a59a4c40c141d263549b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// File:      XmlMNaming_Shape1.cxx
// Created:   01.08.01 18:26:53
// Author:    Alexander GRIGORIEV
// Copyright: Open Cascade 2001
// History:

#include <XmlMNaming_Shape1.ixx>

#include <XmlObjMgt.hxx>
#include <TCollection_AsciiString.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS.hxx>
#include <gp_Pnt.hxx>
#include <BRep_Tool.hxx>

#include <stdio.h>

IMPLEMENT_DOMSTRING (TShapeString,   "tshape")
IMPLEMENT_DOMSTRING (LocationString, "location")

IMPLEMENT_DOMSTRING (XCoordString, "x")
IMPLEMENT_DOMSTRING (YCoordString, "y")
IMPLEMENT_DOMSTRING (ZCoordString, "z")

//=======================================================================
//function : XmlMNaming_Shape1
//purpose  : 
//=======================================================================
XmlMNaming_Shape1::XmlMNaming_Shape1 (XmlObjMgt_Document& theDoc)
     : myTShapeID (0),
       myLocID    (0),
       myOrientation (TopAbs_FORWARD)
{
  myElement = theDoc.createElement(XmlObjMgt_DOMString("shape"));
}

//=======================================================================
//function : XmlMNaming_Shape1
//purpose  : 
//=======================================================================
XmlMNaming_Shape1::XmlMNaming_Shape1 (const XmlObjMgt_Element& theEl)
     : myElement(theEl),
       myTShapeID (0),
       myLocID    (0),
       myOrientation (TopAbs_FORWARD)
{
  if (myElement != NULL)
  {
    myElement.getAttribute(::LocationString()).GetInteger (myLocID);
    XmlObjMgt_DOMString aString = myElement.getAttribute(::TShapeString());
    const char * aPtr = aString.GetString();
    switch (* aPtr) {
    case '+' : myOrientation = TopAbs_FORWARD;  break;
    case '-' : myOrientation = TopAbs_REVERSED; break;
    case 'i' : myOrientation = TopAbs_INTERNAL; break;
    case 'e' : myOrientation = TopAbs_EXTERNAL; break;
    default:       Standard_DomainError::Raise
      ("XmlMNaming_Shape1; orientation value without enum term equivalence");
    }
    Standard_CString anIntPtr = (Standard_CString) &aPtr[1];
    if (XmlObjMgt::GetInteger (anIntPtr, myTShapeID) == Standard_False)
      Standard_DomainError::Raise
        ("XmlMNaming_Shape1; tshape value cannot be initialised by integer");
  }
}

//=======================================================================
//function : Element
//purpose  : 
//=======================================================================
const XmlObjMgt_Element& XmlMNaming_Shape1::Element() const
{
  return myElement;
}

//=======================================================================
//function : Element
//purpose  : 
//=======================================================================
XmlObjMgt_Element& XmlMNaming_Shape1::Element()
{
  return myElement;
}

//=======================================================================
//function : TShapeId
//purpose  : 
//=======================================================================
Standard_Integer XmlMNaming_Shape1::TShapeId() const 
{
  return myTShapeID;
}

//=======================================================================
//function : LocId
//purpose  : 
//=======================================================================
Standard_Integer XmlMNaming_Shape1::LocId() const 
{
  return myLocID;
}

//=======================================================================
//function : Orientation
//purpose  : 
//=======================================================================
TopAbs_Orientation  XmlMNaming_Shape1::Orientation() const 
{
  return myOrientation;
}

//=======================================================================
//function : SetShape
//purpose  : 
//=======================================================================
void  XmlMNaming_Shape1::SetShape (const Standard_Integer       theID,
                                   const Standard_Integer       theLocID,
                                   const TopAbs_Orientation     theOrient)
{
  myTShapeID    = theID;
  myLocID       = theLocID;
  myOrientation = theOrient;

  char aBuffer[16], anOr;
  
  switch (theOrient) {
  case TopAbs_FORWARD   : anOr = '+'; break;
  case TopAbs_REVERSED  : anOr = '-'; break;
  case TopAbs_INTERNAL  : anOr = 'i'; break;
  case TopAbs_EXTERNAL  : anOr = 'e'; break;
  default               : anOr = '\0';
  }
  sprintf (aBuffer, "%c%i", anOr, theID);
  Element().setAttribute (::TShapeString(), aBuffer);
  if (theLocID > 0)
    Element().setAttribute (::LocationString(), theLocID);
}

//=======================================================================
//function : SetVertex
//purpose  : 
//=======================================================================
void XmlMNaming_Shape1::SetVertex (const TopoDS_Shape& theVertex)
{
  TopoDS_Vertex aV = TopoDS::Vertex(theVertex);
  gp_Pnt aPos = BRep_Tool::Pnt(aV);

  char buf [16];
  sprintf (buf, "%.8g", aPos.X());
  Element().setAttribute (::XCoordString(), buf);

  sprintf (buf, "%.8g", aPos.Y());
  Element().setAttribute (::YCoordString(), buf);

  sprintf (buf, "%.8g", aPos.Z());
  Element().setAttribute (::ZCoordString(), buf);
}