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