Salome HOME
Update copyrights
[modules/shaper.git] / src / XAO / XAO_GeometricElement.cxx
1 // Copyright (C) 2013-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 : Frederic Pons (OpenCascade)
20
21 #include "XAO_GeometricElement.hxx"
22 #include "XAO_XaoUtils.hxx"
23
24 using namespace XAO;
25
26
27 GeometricElement::GeometricElement()
28 {
29     m_name = "";
30     m_reference = "";
31 }
32
33 GeometricElement::GeometricElement(const std::string& name, const std::string& reference)
34 {
35     m_name = name;
36     m_reference = reference;
37 }
38
39 GeometricElement::~GeometricElement()
40 {
41 }
42
43 const bool GeometricElement::hasName()
44 {
45     return !m_name.empty();
46 }
47
48 GeometricElementList::GeometricElementList()
49 {
50     setSize(0);
51 }
52
53 GeometricElementList::GeometricElementList(const int& count)
54 {
55     setSize(count);
56 }
57
58 void GeometricElementList::setSize(const int& nb)
59 {
60     m_count = nb;
61     m_elements.clear();
62     for (int i = 0; i < nb; ++i)
63     {
64         m_elements[i] = GeometricElement();
65     }
66 }
67
68 void GeometricElementList::checkElementIndex(const int& index) const
69 throw (XAO_Exception)
70 {
71     if (m_count >= 0 && index < m_count)
72         return;
73
74     throw XAO_Exception(MsgBuilder() << "Index of element is out of range [0, "
75                                      << m_count-1 << "]: " << index);
76 }
77
78 void GeometricElementList::setElement(const int& index, const std::string& name, const std::string& reference)
79 throw (XAO_Exception)
80 {
81     checkElementIndex(index);
82     m_elements[index].setName(name);
83     m_elements[index].setReference(reference);
84 }
85
86 const std::string GeometricElementList::getName(const int& index)
87 throw (XAO_Exception)
88 {
89     checkElementIndex(index);
90     return m_elements[index].getName();
91 }
92
93 void GeometricElementList::setName(const int& index, const std::string& name)
94 throw (XAO_Exception)
95 {
96     checkElementIndex(index);
97     m_elements[index].setName(name);
98 }
99
100 const bool GeometricElementList::hasName(const int& index)
101 throw (XAO_Exception)
102 {
103     checkElementIndex(index);
104     return m_elements[index].hasName();
105 }
106
107 const std::string GeometricElementList::getReference(const int& index)
108 throw (XAO_Exception)
109 {
110     checkElementIndex(index);
111     return m_elements[index].getReference();
112 }
113
114 void GeometricElementList::setReference(const int& index, const std::string& name)
115 throw (XAO_Exception)
116 {
117     checkElementIndex(index);
118     m_elements[index].setReference(name);
119 }
120
121 const int GeometricElementList::getIndexByReference(const std::string& ref)
122 throw (XAO_Exception)
123 {
124     for (int index = 0; index < m_count; ++index)
125     {
126         if (ref == m_elements[index].getReference())
127             return index;
128     }
129
130     throw XAO_Exception(MsgBuilder() << "Reference not found: " << ref);
131 }