Salome HOME
Copyrights update 2015.
[modules/geom.git] / src / XAO / XAO_Geometry.cxx
1 // Copyright (C) 2013-2015  CEA/DEN, EDF R&D, OPEN CASCADE
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, or (at your option) any later version.
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     if (dim == XAO::WHOLE)
71         return 1;
72
73     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
74 }
75
76 const std::string Geometry::getElementReference(const XAO::Dimension& dim, const int& index)
77 throw (XAO_Exception)
78 {
79     if (dim == XAO::VERTEX)
80         return getVertexReference(index);
81     if (dim == XAO::EDGE)
82         return getEdgeReference(index);
83     if (dim == XAO::FACE)
84         return getFaceReference(index);
85     if (dim == XAO::SOLID)
86         return getSolidReference(index);
87
88     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
89 }
90
91 const int Geometry::getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference)
92 throw (XAO_Exception)
93 {
94     if (dim == XAO::VERTEX)
95         return getVertexIndexByReference(reference);
96     if (dim == XAO::EDGE)
97         return getEdgeIndexByReference(reference);
98     if (dim == XAO::FACE)
99         return getFaceIndexByReference(reference);
100     if (dim == XAO::SOLID)
101         return getSolidIndexByReference(reference);
102
103     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
104 }
105
106 GeometricElementList::iterator Geometry::begin(const XAO::Dimension& dim)
107 throw (XAO_Exception)
108 {
109     if (dim == XAO::VERTEX)
110         return m_vertices.begin();
111     if (dim == XAO::EDGE)
112         return m_edges.begin();
113     if (dim == XAO::FACE)
114         return m_faces.begin();
115     if (dim == XAO::SOLID)
116         return m_solids.begin();
117
118     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
119 }
120
121 GeometricElementList::iterator Geometry::end(const XAO::Dimension& dim)
122 throw (XAO_Exception)
123 {
124     if (dim == XAO::VERTEX)
125         return m_vertices.end();
126     if (dim == XAO::EDGE)
127         return m_edges.end();
128     if (dim == XAO::FACE)
129         return m_faces.end();
130     if (dim == XAO::SOLID)
131         return m_solids.end();
132
133     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
134 }
135
136 void Geometry::setCountVertices(const int& nb) throw (XAO_Exception)
137 {
138     checkReadOnly();
139     m_vertices.setSize(nb);
140 }
141 void Geometry::setCountEdges(const int& nb) throw (XAO_Exception)
142 {
143     checkReadOnly();
144     m_edges.setSize(nb);
145 }
146 void Geometry::setCountFaces(const int& nb) throw (XAO_Exception)
147 {
148     checkReadOnly();
149     m_faces.setSize(nb);
150 }
151 void Geometry::setCountSolids(const int& nb) throw (XAO_Exception)
152 {
153     checkReadOnly();
154     m_solids.setSize(nb);
155 }
156
157 void Geometry::setVertexReference(const int& index, const std::string& reference) throw (XAO_Exception)
158 {
159     checkReadOnly();
160     m_vertices.setReference(index, reference);
161 }
162 void Geometry::setEdgeReference(const int& index, const std::string& reference) throw (XAO_Exception)
163 {
164     checkReadOnly();
165     m_edges.setReference(index, reference);
166 }
167 void Geometry::setFaceReference(const int& index, const std::string& reference) throw (XAO_Exception)
168 {
169     checkReadOnly();
170     m_faces.setReference(index, reference);
171 }
172 void Geometry::setSolidReference(const int& index, const std::string& reference) throw (XAO_Exception)
173 {
174     checkReadOnly();
175     m_solids.setReference(index, reference);
176 }
177
178 void Geometry::setVertex(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
179 {
180     checkReadOnly();
181     m_vertices.setElement(index, name, reference);
182 }
183 void Geometry::setEdge(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
184 {
185     checkReadOnly();
186     m_edges.setElement(index, name, reference);
187 }
188 void Geometry::setFace(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
189 {
190     checkReadOnly();
191     m_faces.setElement(index, name, reference);
192 }
193 void Geometry::setSolid(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
194 {
195     checkReadOnly();
196     m_solids.setElement(index, name, reference);
197 }