Salome HOME
b774b31af9ceada68cf28e95adff8735f48d0518
[modules/geom.git] / src / XAO / XAO_Geometry.cxx
1 // Copyright (C) 2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Nathalie Gore (OpenCascade)
20
21 #include "XAO_XaoUtils.hxx"
22 #include "XAO_Geometry.hxx"
23 #include "XAO_BrepGeometry.hxx"
24
25 using namespace XAO;
26
27 Geometry::Geometry(const std::string& name)
28     : m_name(name)
29 {
30     m_readOnly = false;
31 }
32
33 Geometry* Geometry::createGeometry(const XAO::Format& format)
34 throw (XAO_Exception)
35 {
36     return createGeometry(format, "");
37 }
38
39 Geometry* Geometry::createGeometry(const XAO::Format& format, const std::string& name)
40 throw (XAO_Exception)
41 {
42     if (format == XAO::BREP)
43         return new BrepGeometry(name);
44
45     throw XAO_Exception(MsgBuilder() << "Geometry format not supported: " << format);
46 }
47
48 Geometry::~Geometry()
49 {
50 }
51
52 void Geometry::checkReadOnly()
53 throw (XAO_Exception)
54 {
55     if (m_readOnly)
56         throw XAO_Exception("Geometry is read only.");
57 }
58
59 const int Geometry::countElements(const XAO::Dimension& dim) const
60 throw (XAO_Exception)
61 {
62     if (dim == XAO::VERTEX)
63         return countVertices();
64     if (dim == XAO::EDGE)
65         return countEdges();
66     if (dim == XAO::FACE)
67         return countFaces();
68     if (dim == XAO::SOLID)
69         return countSolids();
70
71     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
72 }
73
74 const std::string Geometry::getElementReference(const XAO::Dimension& dim, const int& index)
75 throw (XAO_Exception)
76 {
77     if (dim == XAO::VERTEX)
78         return getVertexReference(index);
79     if (dim == XAO::EDGE)
80         return getEdgeReference(index);
81     if (dim == XAO::FACE)
82         return getFaceReference(index);
83     if (dim == XAO::SOLID)
84         return getSolidReference(index);
85
86     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
87 }
88
89 const int Geometry::getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference)
90 throw (XAO_Exception)
91 {
92     if (dim == XAO::VERTEX)
93         return getVertexIndexByReference(reference);
94     if (dim == XAO::EDGE)
95         return getEdgeIndexByReference(reference);
96     if (dim == XAO::FACE)
97         return getFaceIndexByReference(reference);
98     if (dim == XAO::SOLID)
99         return getSolidIndexByReference(reference);
100
101     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
102 }
103
104 GeometricElementList::iterator Geometry::begin(const XAO::Dimension& dim)
105 throw (XAO_Exception)
106 {
107     if (dim == XAO::VERTEX)
108         return m_vertices.begin();
109     if (dim == XAO::EDGE)
110         return m_edges.begin();
111     if (dim == XAO::FACE)
112         return m_faces.begin();
113     if (dim == XAO::SOLID)
114         return m_solids.begin();
115
116     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
117 }
118
119 GeometricElementList::iterator Geometry::end(const XAO::Dimension& dim)
120 throw (XAO_Exception)
121 {
122     if (dim == XAO::VERTEX)
123         return m_vertices.end();
124     if (dim == XAO::EDGE)
125         return m_edges.end();
126     if (dim == XAO::FACE)
127         return m_faces.end();
128     if (dim == XAO::SOLID)
129         return m_solids.end();
130
131     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
132 }
133
134 void Geometry::setCountVertices(const int& nb) throw (XAO_Exception)
135 {
136     checkReadOnly();
137     m_vertices.setSize(nb);
138 }
139 void Geometry::setCountEdges(const int& nb) throw (XAO_Exception)
140 {
141     checkReadOnly();
142     m_edges.setSize(nb);
143 }
144 void Geometry::setCountFaces(const int& nb) throw (XAO_Exception)
145 {
146     checkReadOnly();
147     m_faces.setSize(nb);
148 }
149 void Geometry::setCountSolids(const int& nb) throw (XAO_Exception)
150 {
151     checkReadOnly();
152     m_solids.setSize(nb);
153 }
154
155 void Geometry::setVertexReference(const int& index, const std::string& reference) throw (XAO_Exception)
156 {
157     checkReadOnly();
158     m_vertices.setReference(index, reference);
159 }
160 void Geometry::setEdgeReference(const int& index, const std::string& reference) throw (XAO_Exception)
161 {
162     checkReadOnly();
163     m_edges.setReference(index, reference);
164 }
165 void Geometry::setFaceReference(const int& index, const std::string& reference) throw (XAO_Exception)
166 {
167     checkReadOnly();
168     m_faces.setReference(index, reference);
169 }
170 void Geometry::setSolidReference(const int& index, const std::string& reference) throw (XAO_Exception)
171 {
172     checkReadOnly();
173     m_solids.setReference(index, reference);
174 }
175
176 void Geometry::setVertex(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
177 {
178     checkReadOnly();
179     m_vertices.setElement(index, name, reference);
180 }
181 void Geometry::setEdge(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
182 {
183     checkReadOnly();
184     m_edges.setElement(index, name, reference);
185 }
186 void Geometry::setFace(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
187 {
188     checkReadOnly();
189     m_faces.setElement(index, name, reference);
190 }
191 void Geometry::setSolid(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
192 {
193     checkReadOnly();
194     m_solids.setElement(index, name, reference);
195 }