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)
24 #include "XAO_Xao.hxx"
25 #include "XAO_Field.hxx"
26 #include "XAO_BooleanField.hxx"
27 #include "XAO_IntegerField.hxx"
28 #include "XAO_DoubleField.hxx"
29 #include "XAO_StringField.hxx"
30 #include "XAO_XaoUtils.hxx"
34 // -------------------------------------------------------
36 Field::Field(XAO::Dimension dimension,
37 int nbElements, int nbComponents, const std::string& name)
38 : m_name(name), m_dimension(dimension),
39 m_nbComponents(nbComponents), m_components(nbComponents, ""),
40 m_nbElements(nbElements)
46 for (unsigned int i = 0; i < m_steps.size(); ++i)
50 Field* Field::createField(XAO::Type type, XAO::Dimension dimension,
51 int nbElements, int nbComponents, const std::string& name)
53 if (type == XAO::BOOLEAN)
54 return new BooleanField(dimension, nbElements, nbComponents, name);
55 if (type == XAO::INTEGER)
56 return new IntegerField(dimension, nbElements, nbComponents, name);
57 if (type == XAO::DOUBLE)
58 return new DoubleField(dimension, nbElements, nbComponents, name);
59 if (type == XAO::STRING)
60 return new StringField(dimension, nbElements, nbComponents, name);
62 throw XAO_Exception(MsgBuilder() << "Bad Type: " << type);
65 const std::string Field::getComponentName(int index)
67 checkComponent(index);
68 return m_components[index];
71 void Field::setComponentName(int index, const std::string& name)
73 checkComponent(index);
74 m_components[index] = name;
77 void Field::setComponentsNames(const std::vector<std::string>& names)
79 for (unsigned int i = 0; i < names.size(); ++i)
81 if ((int)i < m_nbComponents)
82 m_components[i] = names[i];
86 bool Field::removeStep(Step* step)
88 std::vector<Step*>::iterator it = m_steps.begin();
89 for (; it != m_steps.end(); ++it)
102 bool Field::hasStep(int step)
104 std::vector<Step*>::iterator it = m_steps.begin();
105 for (; it != m_steps.end(); ++it)
108 if (current->getStep() == step)
115 void Field::checkComponent(int component)
117 if (component < m_nbComponents && component >= 0)
120 throw XAO_Exception(MsgBuilder() << "Step index is out of range [0, "
121 << m_nbComponents-1 << "]: " << component);
124 void Field::checkStepIndex(int step)
126 if (step < (int)m_steps.size() && step >= 0)
129 throw XAO_Exception(MsgBuilder() << "Step index is out of range [0, "
130 << m_steps.size()-1 << "]: " << step);