1 // Copyright (C) 2013-2024 CEA, EDF, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Frederic Pons (OpenCascade)
21 #include "XAO_BooleanStep.hxx"
22 #include "XAO_XaoUtils.hxx"
26 BooleanStep::BooleanStep(int step, int stamp, int nbElements, int nbComponents)
28 m_nbElements = nbElements;
29 m_nbComponents = nbComponents;
33 m_values.reserve(m_nbElements);
34 for (int i = 0; i < m_nbElements; ++i)
36 std::vector<bool> row;
37 row.reserve(m_nbComponents);
38 for (int j = 0; j < m_nbComponents; ++j)
40 m_values.push_back(row);
44 std::vector<bool> BooleanStep::getValues()
46 std::vector<bool> result;
47 result.reserve(m_nbElements * m_nbComponents);
49 std::vector< std::vector<bool> >::iterator it;
50 for (it = m_values.begin(); it != m_values.end(); ++it)
52 std::vector<bool> eltValues = *it;
53 result.insert(result.end(), eltValues.begin(), eltValues.end());
59 std::vector<bool> BooleanStep::getElement(int element)
61 checkElementIndex(element);
63 std::vector<bool> result(m_values[element]);
67 std::vector<bool> BooleanStep::getComponent(int component)
69 checkComponentIndex(component);
71 std::vector<bool> result;
72 result.reserve(m_nbElements);
74 std::vector< std::vector<bool> >::iterator it;
75 for (it = m_values.begin(); it != m_values.end(); ++it)
77 std::vector<bool> eltValues = *it;
78 result.push_back(eltValues[component]);
84 bool BooleanStep::getValue(int element, int component)
86 checkElementIndex(element);
87 checkComponentIndex(component);
89 return m_values[element][component];
92 const std::string BooleanStep::getStringValue(int element, int component)
94 return XaoUtils::booleanToString(getValue(element, component));
97 void BooleanStep::setValues(const std::vector<bool>& values)
99 checkNbValues((int)values.size());
101 for (int i = 0; i < m_nbElements; ++i)
103 for (int j = 0; j < m_nbComponents; ++j)
105 m_values[i][j] = values[i * m_nbComponents + j];
110 void BooleanStep::setElement(int element, const std::vector<bool>& elements)
112 checkElementIndex(element);
113 checkNbComponents(elements.size());
115 for (int i = 0; i < m_nbComponents; ++i)
116 m_values[element][i] = elements[i];
119 void BooleanStep::setComponent(int component, const std::vector<bool>& components)
121 checkComponentIndex(component);
122 checkNbElements(components.size());
124 for (int i = 0; i < m_nbElements; ++i)
125 m_values[i][component] = components[i];
128 void BooleanStep::setValue(int element, int component, bool value)
130 checkElementIndex(element);
131 checkComponentIndex(component);
133 m_values[element][component] = value;
136 void BooleanStep::setStringValue(int element, int component, const std::string& value)
138 setValue(element, component, XaoUtils::stringToBoolean(value));