Salome HOME
68d9bd2f49e5ca13ba324a7bcd5c94049a4cfe6e
[modules/geom.git] / src / XAO / XAO_GeometricElement.cxx
1 // Copyright (C) 2013-2020  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 bool GeometricElement::hasName()
44 {
45     return !m_name.empty();
46 }
47
48 GeometricElementList::GeometricElementList()
49 {
50     setSize(0);
51 }
52
53 GeometricElementList::GeometricElementList(int count)
54 {
55     setSize(count);
56 }
57
58 void GeometricElementList::setSize(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(int index) const
69 {
70     if (m_count >= 0 && index < m_count)
71         return;
72
73     throw XAO_Exception(MsgBuilder() << "Index of element is out of range [0, "
74                                      << m_count-1 << "]: " << index);
75 }
76
77 void GeometricElementList::setElement(int index, const std::string& name, const std::string& reference)
78 {
79     checkElementIndex(index);
80     m_elements[index].setName(name);
81     m_elements[index].setReference(reference);
82 }
83
84 const std::string GeometricElementList::getName(int index)
85 {
86     checkElementIndex(index);
87     return m_elements[index].getName();
88 }
89
90 void GeometricElementList::setName(int index, const std::string& name)
91 {
92     checkElementIndex(index);
93     m_elements[index].setName(name);
94 }
95
96 bool GeometricElementList::hasName(int index)
97 {
98     checkElementIndex(index);
99     return m_elements[index].hasName();
100 }
101
102 const std::string GeometricElementList::getReference(int index)
103 {
104     checkElementIndex(index);
105     return m_elements[index].getReference();
106 }
107
108 void GeometricElementList::setReference(int index, const std::string& name)
109 {
110     checkElementIndex(index);
111     m_elements[index].setReference(name);
112 }
113
114 int GeometricElementList::getIndexByReference(const std::string& ref)
115 {
116     for (int index = 0; index < m_count; ++index)
117     {
118         if (ref == m_elements[index].getReference())
119             return index;
120     }
121
122     throw XAO_Exception(MsgBuilder() << "Reference not found: " << ref);
123 }