Salome HOME
Fix a bug that NbShapes() and ShapeInfo() return 2 solids for a box
[modules/geom.git] / src / XAO / XAO_GeometricElement.hxx
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 : Frederic Pons (OpenCascade)
20
21 #ifndef __XAO_GEOMETRICELEMENT_HXX__
22 #define __XAO_GEOMETRICELEMENT_HXX__
23
24 #include <string>
25 #include <map>
26 #include "XAO_Exception.hxx"
27
28 namespace XAO
29 {
30     /**
31      * \class GeometricElement
32      * Generic class to manipulate a topologic element (vertex, edge, face or solid).
33      */
34     class GeometricElement
35     {
36     public:
37         /**
38          * Default constructor.
39          */
40         GeometricElement();
41         /**
42          * Constructor with name and reference.
43          * \param name the name of the element.
44          * \param reference the reference of the element.
45          */
46         GeometricElement(const std::string& name, const std::string& reference);
47         /**
48          * Destructor.
49          */
50         virtual ~GeometricElement();
51
52         /**
53          * Gets the name of the element.
54          * \return the name.
55          */
56         const std::string getName()
57         {
58             return m_name;
59         }
60         /**
61          * Sets the name of the element
62          * \param name the name to set.
63          */
64         void setName(const std::string& name)
65         {
66             m_name = name;
67         }
68
69         /**
70          * Checks if the element has a name.
71          * @return true if the element has a name, false otherwise.
72          */
73         const bool hasName();
74
75         /**
76          * Gets the reference of the element.
77          * \return the reference.
78          */
79         const std::string getReference()
80         {
81             return m_reference;
82         }
83         /**
84          * Sets the reference of the element.
85          * \param reference the reference to set.
86          */
87         void setReference(const std::string& reference)
88         {
89             m_reference = reference;
90         }
91
92     private:
93         /** The name of the element. */
94         std::string m_name;
95         /** The reference of the element. */
96         std::string m_reference;
97     };
98
99     /**
100      * \class GeometricElementList
101      * Generic class to manipulate a list of topologic element.
102      */
103     class GeometricElementList
104     {
105     public:
106         /**
107          * Default constructor.
108          */
109         GeometricElementList();
110
111         /**
112          * Constructor with size.
113          * \param nb the size to set.
114          */
115         GeometricElementList(const int& nb);
116
117         /**
118          * Destructor.
119          */
120         virtual ~GeometricElementList() {}
121
122         /**
123          * Gets the size of the list.
124          * \return the size of the list.
125          */
126         const int getSize() const { return m_count; }
127
128         /**
129          * Sets the size of the list.
130          * \param nb the size to set.
131          * \warning the list will be cleared.
132          */
133         void setSize(const int& nb);
134
135         /**
136          * Sets the name and the reference of an element.
137          * \param index the index of the element to set.
138          * \param name the name to set.
139          * \param reference the reference to set.
140          * \throw XAO_Exception if index is bigger than the size of the list.
141          */
142         void setElement(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
143         /**
144          * Gets the name of an element.
145          * \param index the index of the element to set.
146          * \return the name of the element with the given index.
147          * \throw XAO_Exception if index is bigger than the size of the list.
148          */
149         const std::string getName(const int& index) throw (XAO_Exception);
150         /**
151          * Sets the name of an element.
152          * \param index the index of the element.
153          * \param name the name to set.
154          * \throw XAO_Exception if index is bigger than the size of the list.
155          */
156         void setName(const int& index, const std::string& name) throw (XAO_Exception);
157
158         /**
159          * Checks if an element has a name.
160          * @param index the index of the element.
161          * @return true if the element has a name, false otherwise.
162          */
163         const bool hasName(const int& index) throw (XAO_Exception);
164
165         /**
166          * Gets the reference of an element.
167          * \param index the index of the element.
168          * \return the reference of the element.
169          * \throw XAO_Exception if index is bigger than the size of the list.
170          */
171         const std::string getReference(const int& index) throw (XAO_Exception);
172         /**
173          * Sets the reference of an element.
174          * \param index the index of the element to set.
175          * \param reference the reference to set.
176          * \throw XAO_Exception if index is bigger than the size of the list.
177          */
178         void setReference(const int& index, const std::string& reference) throw (XAO_Exception);
179
180         /**
181          * Gets the index of an element using its reference.
182          * \param reference the searched reference.
183          * \return the index of the element or -1 if no element found.
184          */
185         const int getIndexByReference(const std::string& reference) throw (XAO_Exception);
186
187         /**
188          * Iterator on the element of the list.
189          */
190         typedef std::map<int, GeometricElement>::iterator iterator;
191
192         /**
193          * Gets an iterator on the first element.
194          * @return an iterator on the first element.
195          */
196         iterator begin() { return m_elements.begin(); }
197
198         /**
199          * Gets an iterator on the last element.
200          * @return an iterator on the last element.
201          */
202         iterator end() { return m_elements.end(); }
203
204     private:
205         void checkElementIndex(const int& index) const throw (XAO_Exception);
206
207     private:
208         int m_count;
209         std::map<int, GeometricElement> m_elements;
210     };
211 }
212
213 #endif /* __XAO_GEOMETRICELEMENT_HXX__ */