Salome HOME
Copyright update 2021
[modules/geom.git] / src / XAO / XAO_BooleanStep.cxx
1 // Copyright (C) 2013-2021  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_BooleanStep.hxx"
22 #include "XAO_XaoUtils.hxx"
23
24 using namespace XAO;
25
26 BooleanStep::BooleanStep(int step, int stamp, int nbElements, int nbComponents)
27 {
28     m_nbElements = nbElements;
29     m_nbComponents = nbComponents;
30     m_step = step;
31     m_stamp = stamp;
32
33     m_values.reserve(m_nbElements);
34     for (int i = 0; i < m_nbElements; ++i)
35     {
36         std::vector<bool> row;
37         row.reserve(m_nbComponents);
38         for (int j = 0; j < m_nbComponents; ++j)
39             row.push_back(false);
40         m_values.push_back(row);
41     }
42 }
43
44 std::vector<bool> BooleanStep::getValues()
45 {
46     std::vector<bool> result;
47     result.reserve(m_nbElements * m_nbComponents);
48
49     std::vector< std::vector<bool>  >::iterator it;
50     for (it = m_values.begin(); it != m_values.end(); ++it)
51     {
52         std::vector<bool> eltValues = *it;
53         result.insert(result.end(), eltValues.begin(), eltValues.end());
54     }
55
56     return result;
57 }
58
59 std::vector<bool> BooleanStep::getElement(int element)
60 {
61     checkElementIndex(element);
62
63     std::vector<bool> result(m_values[element]);
64     return result;
65 }
66
67 std::vector<bool> BooleanStep::getComponent(int component)
68 {
69     checkComponentIndex(component);
70
71     std::vector<bool> result;
72     result.reserve(m_nbElements);
73
74     std::vector< std::vector<bool>  >::iterator it;
75     for (it = m_values.begin(); it != m_values.end(); ++it)
76     {
77         std::vector<bool> eltValues = *it;
78         result.push_back(eltValues[component]);
79     }
80
81     return result;
82 }
83
84 bool BooleanStep::getValue(int element, int component)
85 {
86     checkElementIndex(element);
87     checkComponentIndex(component);
88
89     return m_values[element][component];
90 }
91
92 const std::string BooleanStep::getStringValue(int element, int component)
93 {
94     return XaoUtils::booleanToString(getValue(element, component));
95 }
96
97 void BooleanStep::setValues(const std::vector<bool>& values)
98 {
99     checkNbValues((int)values.size());
100
101     for (int i = 0; i < m_nbElements; ++i)
102     {
103         for (int j = 0; j < m_nbComponents; ++j)
104         {
105             m_values[i][j] = values[i * m_nbComponents + j];
106         }
107     }
108 }
109
110 void BooleanStep::setElement(int element, const std::vector<bool>& elements)
111 {
112     checkElementIndex(element);
113     checkNbComponents(elements.size());
114
115     for (int i = 0; i < m_nbComponents; ++i)
116         m_values[element][i] = elements[i];
117 }
118
119 void BooleanStep::setComponent(int component, const std::vector<bool>& components)
120 {
121     checkComponentIndex(component);
122     checkNbElements(components.size());
123
124     for (int i = 0; i < m_nbElements; ++i)
125         m_values[i][component] = components[i];
126 }
127
128 void BooleanStep::setValue(int element, int component, bool value)
129 {
130     checkElementIndex(element);
131     checkComponentIndex(component);
132
133     m_values[element][component] = value;
134 }
135
136 void BooleanStep::setStringValue(int element, int component, const std::string& value)
137 {
138     setValue(element, component, XaoUtils::stringToBoolean(value));
139 }