Salome HOME
86d62e3e4243564e878b37c854b1bf2403ddba22
[modules/geom.git] / src / XAO / XAO_Geometry.cxx
1 // Copyright (C) 2013-2023  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(XAO::Format format)
34 {
35     return createGeometry(format, "");
36 }
37
38 Geometry* Geometry::createGeometry(XAO::Format format, const std::string& name)
39 {
40     if (format == XAO::BREP)
41         return new BrepGeometry(name);
42
43     throw XAO_Exception(MsgBuilder() << "Geometry format not supported: " << format);
44 }
45
46 Geometry::~Geometry()
47 {
48 }
49
50 void Geometry::checkReadOnly()
51 {
52     if (m_readOnly)
53         throw XAO_Exception("Geometry is read only.");
54 }
55
56 int Geometry::countElements(XAO::Dimension dim) const
57 {
58     if (dim == XAO::VERTEX)
59         return countVertices();
60     if (dim == XAO::EDGE)
61         return countEdges();
62     if (dim == XAO::FACE)
63         return countFaces();
64     if (dim == XAO::SOLID)
65         return countSolids();
66     if (dim == XAO::WHOLE)
67         return 1;
68
69     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
70 }
71
72 const std::string Geometry::getElementReference(XAO::Dimension dim, int index)
73 {
74     if (dim == XAO::VERTEX)
75         return getVertexReference(index);
76     if (dim == XAO::EDGE)
77         return getEdgeReference(index);
78     if (dim == XAO::FACE)
79         return getFaceReference(index);
80     if (dim == XAO::SOLID)
81         return getSolidReference(index);
82
83     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
84 }
85
86 int Geometry::getElementIndexByReference(XAO::Dimension dim, const std::string& reference)
87 {
88     if (dim == XAO::VERTEX)
89         return getVertexIndexByReference(reference);
90     if (dim == XAO::EDGE)
91         return getEdgeIndexByReference(reference);
92     if (dim == XAO::FACE)
93         return getFaceIndexByReference(reference);
94     if (dim == XAO::SOLID)
95         return getSolidIndexByReference(reference);
96
97     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
98 }
99
100 GeometricElementList::iterator Geometry::begin(XAO::Dimension dim)
101 {
102     if (dim == XAO::VERTEX)
103         return m_vertices.begin();
104     if (dim == XAO::EDGE)
105         return m_edges.begin();
106     if (dim == XAO::FACE)
107         return m_faces.begin();
108     if (dim == XAO::SOLID)
109         return m_solids.begin();
110
111     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
112 }
113
114 GeometricElementList::iterator Geometry::end(XAO::Dimension dim)
115 {
116     if (dim == XAO::VERTEX)
117         return m_vertices.end();
118     if (dim == XAO::EDGE)
119         return m_edges.end();
120     if (dim == XAO::FACE)
121         return m_faces.end();
122     if (dim == XAO::SOLID)
123         return m_solids.end();
124
125     throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
126 }
127
128 void Geometry::setCountVertices(int nb) 
129 {
130     checkReadOnly();
131     m_vertices.setSize(nb);
132 }
133 void Geometry::setCountEdges(int nb) 
134 {
135     checkReadOnly();
136     m_edges.setSize(nb);
137 }
138 void Geometry::setCountFaces(int nb) 
139 {
140     checkReadOnly();
141     m_faces.setSize(nb);
142 }
143 void Geometry::setCountSolids(int nb) 
144 {
145     checkReadOnly();
146     m_solids.setSize(nb);
147 }
148
149 void Geometry::setVertexReference(int index, const std::string& reference) 
150 {
151     checkReadOnly();
152     m_vertices.setReference(index, reference);
153 }
154 void Geometry::setEdgeReference(int index, const std::string& reference) 
155 {
156     checkReadOnly();
157     m_edges.setReference(index, reference);
158 }
159 void Geometry::setFaceReference(int index, const std::string& reference) 
160 {
161     checkReadOnly();
162     m_faces.setReference(index, reference);
163 }
164 void Geometry::setSolidReference(int index, const std::string& reference) 
165 {
166     checkReadOnly();
167     m_solids.setReference(index, reference);
168 }
169
170 void Geometry::setVertex(int index, const std::string& name, const std::string& reference) 
171 {
172     checkReadOnly();
173     m_vertices.setElement(index, name, reference);
174 }
175 void Geometry::setEdge(int index, const std::string& name, const std::string& reference) 
176 {
177     checkReadOnly();
178     m_edges.setElement(index, name, reference);
179 }
180 void Geometry::setFace(int index, const std::string& name, const std::string& reference) 
181 {
182     checkReadOnly();
183     m_faces.setElement(index, name, reference);
184 }
185 void Geometry::setSolid(int index, const std::string& name, const std::string& reference) 
186 {
187     checkReadOnly();
188     m_solids.setElement(index, name, reference);
189 }