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