Salome HOME
Update copyrights
[modules/shaper.git] / src / XAO / XAO_Geometry.hxx
1 // Copyright (C) 2007-2019  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 #ifndef __XAO_GEOMETRY_HXX__
22 #define __XAO_GEOMETRY_HXX__
23
24 #include <string>
25
26 #include "XAO.hxx"
27 #include "XAO_XaoUtils.hxx"
28 #include "XAO_Exception.hxx"
29 #include "XAO_GeometricElement.hxx"
30
31 #ifdef WIN32
32 #pragma warning(disable:4290) // Warning Exception ...
33 #endif
34
35
36 namespace XAO
37 {
38     /**
39      * @class Geometry
40      * Base class for geometries.
41      */
42     class XAO_EXPORT Geometry
43     {
44     protected:
45         /**
46          * Constructor.
47          * @param name the name of the Geometry.
48          */
49         Geometry(const std::string& name);
50
51     public:
52
53         /**
54          * Creates a geometry.
55          * @param format the format of the geometry.
56          * @return the created geometry.
57          */
58         static Geometry* createGeometry(const XAO::Format& format) throw (XAO_Exception);
59
60         /**
61          * Constructor.
62          * Creates a geometry.
63          * @name name the name of the geometry.
64          * @return the created geometry.
65          */
66         static Geometry* createGeometry(const XAO::Format& format, const std::string& name)
67         throw (XAO_Exception);
68
69         /** Destructor. */
70         virtual ~Geometry();
71
72         /**
73          * Gets the name of the geometry.
74          * @return the name of the geometry.
75          */
76         const std::string getName()
77         {
78             return m_name;
79         }
80         /**
81          * Sets the name of the geometry.
82          * @param name the name to set.
83          */
84         void setName(const std::string& name)
85         {
86             m_name = name;
87         }
88
89         /**
90          * Gets the format of the geometry.
91          * @return the format of the geometry.
92          */
93         virtual const XAO::Format getFormat() = 0;
94
95         virtual const std::string getShapeString() = 0;
96         virtual void setShapeString(const std::string& shape) = 0;
97         virtual void writeShapeFile(const std::string& fileName) = 0;
98         virtual void readShapeFile(const std::string& fileName) = 0;
99
100         const int countElements(const XAO::Dimension& dim) const throw (XAO_Exception);
101         const int countVertices() const { return m_vertices.getSize(); }
102         const int countEdges() const { return m_edges.getSize(); }
103         const int countFaces() const { return m_faces.getSize(); }
104         const int countSolids() const { return m_solids.getSize(); }
105
106         void setCountVertices(const int& nb) throw (XAO_Exception);
107         void setCountEdges(const int& nb) throw (XAO_Exception);
108         void setCountFaces(const int& nb) throw (XAO_Exception);
109         void setCountSolids(const int& nb) throw (XAO_Exception);
110
111         const std::string getVertexName(const int& index) throw (XAO_Exception) { return m_vertices.getName(index); }
112         const std::string getEdgeName(const int& index) throw (XAO_Exception) { return m_edges.getName(index); }
113         const std::string getFaceName(const int& index) throw (XAO_Exception) { return m_faces.getName(index); }
114         const std::string getSolidName(const int& index) throw (XAO_Exception) { return m_solids.getName(index); }
115
116         void setVertexName(const int& index, const std::string& name) throw (XAO_Exception) { m_vertices.setName(index, name); }
117         void setEdgeName(const int& index, const std::string& name) throw (XAO_Exception) { m_edges.setName(index, name); }
118         void setFaceName(const int& index, const std::string& name) throw (XAO_Exception) { m_faces.setName(index, name); }
119         void setSolidName(const int& index, const std::string& name) throw (XAO_Exception) { m_solids.setName(index, name); }
120
121         const bool hasVertexName(const int& index) throw (XAO_Exception) { return m_vertices.hasName(index); }
122         const bool hasEdgeName(const int& index) throw (XAO_Exception) { return m_edges.hasName(index); }
123         const bool hasFaceName(const int& index) throw (XAO_Exception) { return m_faces.hasName(index); }
124         const bool hasSolidName(const int& index) throw (XAO_Exception) { return m_solids.hasName(index); }
125
126         const std::string getVertexReference(const int& index) throw (XAO_Exception) { return m_vertices.getReference(index); }
127         const std::string getEdgeReference(const int& index) throw (XAO_Exception) { return m_edges.getReference(index); }
128         const std::string getFaceReference(const int& index) throw (XAO_Exception) { return m_faces.getReference(index); }
129         const std::string getSolidReference(const int& index) throw (XAO_Exception) { return m_solids.getReference(index); }
130         const std::string getElementReference(const XAO::Dimension& dim, const int& index) throw (XAO_Exception);
131
132         void setVertexReference(const int& index, const std::string& reference) throw (XAO_Exception);
133         void setEdgeReference(const int& index, const std::string& reference) throw (XAO_Exception);
134         void setFaceReference(const int& index, const std::string& reference) throw (XAO_Exception);
135         void setSolidReference(const int& index, const std::string& reference) throw (XAO_Exception);
136
137         void setVertex(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
138         void setEdge(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
139         void setFace(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
140         void setSolid(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
141
142         const int getVertexIndexByReference(const std::string& reference) { return m_vertices.getIndexByReference(reference); }
143         const int getEdgeIndexByReference(const std::string& reference) { return m_edges.getIndexByReference(reference); }
144         const int getFaceIndexByReference(const std::string& reference) { return m_faces.getIndexByReference(reference); }
145         const int getSolidIndexByReference(const std::string& reference) { return m_solids.getIndexByReference(reference); }
146         const int getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference) throw (XAO_Exception);
147
148         GeometricElementList::iterator begin(const XAO::Dimension& dim) throw (XAO_Exception);
149         GeometricElementList::iterator end(const XAO::Dimension& dim) throw (XAO_Exception);
150
151         /**
152          * Verifies if the geometry is read only.
153          * @return true if the geometry is read only.
154          */
155         bool isReadOnly() { return m_readOnly; }
156
157         /**
158          * Sets the geometry read only.
159          */
160         void setReadOnly() { m_readOnly = true; }
161
162     protected:
163         void checkReadOnly() throw (XAO_Exception);
164
165     protected:
166         std::string m_name;
167         GeometricElementList m_vertices;
168         GeometricElementList m_edges;
169         GeometricElementList m_faces;
170         GeometricElementList m_solids;
171         bool m_readOnly;
172
173     };
174 }
175
176 #endif