Salome HOME
Copyright update 2022
[modules/geom.git] / src / XAO / XAO_Group.hxx
1 // Copyright (C) 2013-2022  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), Frederic Pons (OpenCascade)
20
21 #ifndef __XAO_GROUP_HXX__
22 #define __XAO_GROUP_HXX__
23
24 #include <string>
25 #include <set>
26
27 #include "XAO.hxx"
28 #include "XAO_XaoUtils.hxx"
29 #ifdef WIN32
30 #pragma warning(disable:4251) // Warning dll-interface ...
31 #endif
32 namespace XAO
33 {
34     /**
35      * \class Group
36      * Class to represent a Geometrical Group.
37      */
38     class XAO_EXPORT Group
39     {
40     public:
41         /**
42          * Constructor.
43          * @param dim the dimension of the group.
44          * @param nbElements the number of geometrical elements for the dimension in the geometry.
45          * @param name the name of the group.
46          */
47         Group(XAO::Dimension dim, int nbElements, const std::string& name = std::string(""));
48
49         /**
50          * Destructor.
51          */
52         virtual ~Group();
53
54         /**
55         * Gets the name of the group.
56         * \return the name of the group.
57         */
58        const std::string getName()
59        {
60            return m_name;
61        }
62         /**
63          * Sets the name of the group.
64          * \param name the name to set.
65          */
66         void setName(const std::string& name)
67         {
68             m_name = name;
69         }
70
71         /**
72          * Gets the dimension of the group.
73          * \return the dimension of the group.
74          */
75         XAO::Dimension getDimension()
76         {
77             return m_dimension;
78         }
79
80         /**
81          * Gets the numbers of elements in the geometry of the same type than the group.
82          * \return the number of elements in the associated geometry.
83          */
84         int getNbElements()
85         {
86             return m_nbElements;
87         }
88
89         /**
90          * Gets the number of elements in the group.
91          * \return the number of elements.
92          */
93         int count() const
94         {
95             return m_elements.size();
96         }
97
98         /**
99          * Gets the reference of an element.
100          * \param index the index of the element.
101          * \return the reference of the element.
102          * \note use begin() and end() if you need to iterate.
103          */
104         int get(int index)
105         {
106             checkIndex(index);
107             std::set<int>::iterator it = m_elements.begin();
108             std::advance(it, index);
109             return (*it);
110         }
111
112         /**
113          * Adds an element to the group.
114          * \param value the index of the element to add.
115          */
116         void add(int value);
117
118         /**
119          * Removes an element from the group.
120          * \param value the index of the element to remove.
121          */
122         void remove(int value);
123
124         /**
125          * Gets an iterator on the first element in the group.
126          * @return an iterator on the first element.
127          */
128         std::set<int>::iterator begin() { return m_elements.begin(); }
129
130         /**
131          * Gets an iterator on the last element in the group.
132          * @return an iterator on the last element.
133          */
134         std::set<int>::iterator end() { return m_elements.end(); }
135
136     private:
137         /**
138          * Ensures that the given element is valid.
139          * @param element
140          * @throw XAO_Exception if element is bigger than the number of elements.
141          */
142         void checkIndex(int element);
143
144     private:
145         /** The name of the group. */
146         std::string m_name;
147         /** The number of elements in the associated geometry. */
148         int m_nbElements;
149         /** The dimension of the group. */
150         XAO::Dimension m_dimension;
151         /** The number of elements in the group. */
152         int m_count;
153         /** The elements of the group. */
154         std::set<int> m_elements;
155     };
156 }
157
158 #endif