+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include "BooleanField.hxx"
-#include "BooleanStep.hxx"
-#include "XaoUtils.hxx"
-
-#include <Utils_SALOME_Exception.hxx>
-
-using namespace XAO;
-
-BooleanField::BooleanField(const std::string& name, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents)
- : Field(name, dimension, nbElements, nbComponents)
-{
-}
-
-Step* BooleanField::addNewStep(const int& step)
-{
- return addStep(step, 0);
-}
-
-BooleanStep* BooleanField::addStep(const int& step)
-{
- return addStep(step, 0);
-}
-
-BooleanStep* BooleanField::addStep(const int& step, const int& stamp)
-{
- if (hasStep(step))
- throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
-
- BooleanStep* bstep = new BooleanStep(step, stamp, m_nbElements, m_nbComponents);
- m_steps.push_back(bstep);
- return bstep;
-}
-
-BooleanStep* BooleanField::getStep(const int& index)
-{
- checkStepIndex(index);
- return (BooleanStep*)m_steps[index];
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#ifndef __XAO_BOOLEANFIELD_HXX__
-#define __XAO_BOOLEANFIELD_HXX__
-
-#include <iostream>
-#include <string>
-#include <vector>
-
-#include "Xao.hxx"
-#include "Field.hxx"
-#include "BooleanStep.hxx"
-
-namespace XAO
-{
- class BooleanField : public Field
- {
- public:
- BooleanField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
-
- virtual const XAO::Type getType() { return XAO::BOOLEAN; }
-
- virtual Step* addNewStep(const int& step);
- BooleanStep* addStep(const int& step);
- BooleanStep* addStep(const int& step, const int& stamp);
- BooleanStep* getStep(const int& index);
- };
-}
-
-#endif /* __XAO_BOOLEANFIELD_HXX__ */
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include <Utils_SALOME_Exception.hxx>
-#include "BooleanStep.hxx"
-#include "XaoUtils.hxx"
-
-using namespace XAO;
-
-BooleanStep::BooleanStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
-{
- m_nbElements = nbElements;
- m_nbComponents = nbComponents;
- m_step = step;
- m_stamp = stamp;
-
- m_values.reserve(m_nbElements);
- for (int i = 0; i < m_nbElements; ++i)
- {
- std::vector<bool> row;
- row.reserve(m_nbComponents);
- for (int j = 0; j < m_nbComponents; ++j)
- row.push_back(false);
- m_values.push_back(row);
- }
-}
-
-std::vector<bool> BooleanStep::getValues()
-{
- std::vector<bool> result;
- result.reserve(m_nbElements * m_nbComponents);
-
- std::vector< std::vector<bool> >::iterator it;
- for (it = m_values.begin(); it != m_values.end(); ++it)
- {
- std::vector<bool> eltValues = *it;
- result.insert(result.end(), eltValues.begin(), eltValues.end());
- }
-
- return result;
-}
-
-std::vector<bool> BooleanStep::getElement(const int& element)
-{
- checkElementIndex(element);
-
- std::vector<bool> result(m_values[element]);
- return result;
-}
-
-std::vector<bool> BooleanStep::getComponent(const int& component)
-{
- checkComponentIndex(component);
-
- std::vector<bool> result;
- result.reserve(m_nbElements);
-
- std::vector< std::vector<bool> >::iterator it;
- for (it = m_values.begin(); it != m_values.end(); ++it)
- {
- std::vector<bool> eltValues = *it;
- result.push_back(eltValues[component]);
- }
-
- return result;
-}
-
-const bool BooleanStep::getValue(const int& element, const int& component)
-{
- checkElementIndex(element);
- checkComponentIndex(component);
-
- return m_values[element][component];
-}
-
-const std::string BooleanStep::getStringValue(const int& element, const int& component)
-{
- return XaoUtils::booleanToString(getValue(element, component));
-}
-
-void BooleanStep::setValues(const std::vector<bool>& values)
-{
- checkNbValues((int)values.size());
-
- for (int i = 0; i < m_nbElements; ++i)
- {
- for (int j = 0; j < m_nbComponents; ++j)
- {
- m_values[i][j] = values[i * m_nbComponents + j];
- }
- }
-}
-
-void BooleanStep::setElements(const int& element, const std::vector<bool>& elements)
-{
- checkElementIndex(element);
- checkNbComponents(elements.size());
-
- for (int i = 0; i < m_nbComponents; ++i)
- m_values[element][i] = elements[i];
-}
-
-void BooleanStep::setComponents(const int& component, const std::vector<bool>& components)
-{
- checkComponentIndex(component);
- checkNbElements(components.size());
-
- for (int i = 0; i < m_nbElements; ++i)
- m_values[i][component] = components[i];
-}
-
-void BooleanStep::setValue(const int& element, const int& component, const bool& value)
-{
- checkElementIndex(element);
- checkComponentIndex(component);
-
- m_values[element][component] = value;
-}
-
-void BooleanStep::setStringValue(const int& element, const int& component, const std::string& value)
-{
- setValue(element, component, XaoUtils::stringToBoolean(value));
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-
-#ifndef __XAO_BOOLEANSTEP_HXX__
-#define __XAO_BOOLEANSTEP_HXX__
-
-#include <map>
-#include <vector>
-
-#include "Xao.hxx"
-#include "Step.hxx"
-
-namespace XAO
-{
- class BooleanStep : public Step
- {
- public:
- BooleanStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
-
- virtual const XAO::Type getType() { return XAO::BOOLEAN; }
-
- /**
- * Gets all the values in a vector by elements and by components.
- * @return a vector containing all the values.
- */
- std::vector<bool> getValues();
-
- /**
- * Gets all the values for an element.
- * @param element the index of the element to get.
- * @return a vector containing all the values for the given element.
- */
- std::vector<bool> getElement(const int& element);
-
- /**
- * Gets all the values for a component.
- * @param component the index of the component to get.
- * @return a vector containing all the values for the given component.
- */
- std::vector<bool> getComponent(const int& component);
-
- /**
- * Gets a value for an element and a component.
- * @param element the index of the element.
- * @param component the index of the component.
- * @return the value.
- */
- const bool getValue(const int& element, const int& component);
-
- void setValues(const std::vector<bool>& values);
- void setElements(const int& element, const std::vector<bool>& elements);
- void setComponents(const int& component, const std::vector<bool>& components);
- void setValue(const int& element, const int& component, const bool& value);
-
- virtual const std::string getStringValue(const int& element, const int& component);
- virtual void setStringValue(const int& element, const int& component, const std::string& value);
-
- private:
- std::vector< std::vector<bool> > m_values;
- };
-}
-
-
-#endif /* __XAO_BOOLEANSTEP_HXX__ */
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include <cassert>
-
-#include <Standard_TypeMismatch.hxx>
-
-#include <BRepTools.hxx>
-#include <BRep_Builder.hxx>
-#include <TopAbs.hxx>
-#include <TopTools_MapOfShape.hxx>
-#include <TopTools_ListOfShape.hxx>
-#include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <TopTools_IndexedMapOfShape.hxx>
-#include <TopExp.hxx>
-#include <TopExp_Explorer.hxx>
-//#include <TColStd_ListIteratorOfListOfInteger.hxx>
-//#include <TColStd_HArray1OfInteger.hxx>
-//#include <TColStd_HSequenceOfInteger.hxx>
-#include <GProp_GProps.hxx>
-#include <BRepGProp.hxx>
-#include <TopoDS.hxx>
-#include <TopoDS_Vertex.hxx>
-
-#include <Utils_SALOME_Exception.hxx>
-
-#include "BrepGeometry.hxx"
-#include "XaoUtils.hxx"
-
-using namespace XAO;
-
-BrepGeometry::BrepGeometry() : Geometry("")
-{
-}
-
-BrepGeometry::BrepGeometry(const std::string& name) : Geometry(name)
-{
-}
-
-const std::string BrepGeometry::getShape()
-{
- std::ostringstream streamShape;
- BRepTools::Write(m_shape, streamShape);
- std::string data = streamShape.str();
- char* res = new char[data.size()];
- strcpy(res, data.c_str());
- return res;
-}
-
-void BrepGeometry::setShape(const std::string& shape)
-{
- std::istringstream streamBrep(shape.c_str());
- BRep_Builder builder;
- BRepTools::Read(m_shape, streamBrep, builder);
-
- initIds();
-}
-
-TopoDS_Shape BrepGeometry::getTopoDS_Shape()
-{
- return m_shape;
-}
-
-void BrepGeometry::setTopoDS_Shape(const TopoDS_Shape& shape)
-{
- m_shape = shape;
- initIds();
-}
-
-void BrepGeometry::initIds()
-{
- // intialization of Ids
- initListIds(TopAbs_VERTEX, m_vertices);
- initListIds(TopAbs_EDGE, m_edges);
- initListIds(TopAbs_FACE, m_faces);
- initListIds(TopAbs_SOLID, m_solids);
-}
-
-void BrepGeometry::initListIds(const TopAbs_ShapeEnum& shapeType, GeometricElementList& eltList)
-{
- TopTools_MapOfShape mapShape;
- TopTools_ListOfShape listShape;
-
- TopExp_Explorer exp(m_shape, shapeType);
- for (; exp.More(); exp.Next())
- {
- if (mapShape.Add(exp.Current()))
- listShape.Append(exp.Current());
- }
-
- if (listShape.IsEmpty())
- return;
-
- TopTools_IndexedMapOfShape indices;
- TopExp::MapShapes(m_shape, indices);
-
- std::list<int> indexList;
- TopTools_ListIteratorOfListOfShape itSub(listShape);
- for (int index = 1; itSub.More(); itSub.Next(), ++index)
- {
- TopoDS_Shape value = itSub.Value();
- indexList.push_back(indices.FindIndex(value));
- }
-
- std::list<int>::iterator it = indexList.begin();
-
- eltList.setSize(indexList.size());
- for (int i = 0; it != indexList.end(); it++, i++)
- eltList.setReference(i, XaoUtils::intToString((*it)));
-}
-
-TopoDS_Shape BrepGeometry::getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex)
-{
- TopTools_MapOfShape mapShape;
- TopTools_ListOfShape listShape;
-
- TopExp_Explorer exp(mainShape, shapeType);
- for (; exp.More(); exp.Next())
- {
- if (mapShape.Add(exp.Current()))
- listShape.Append(exp.Current());
- }
-
- if (!listShape.IsEmpty())
- {
- // use main shape indices
- TopTools_IndexedMapOfShape indices;
- TopExp::MapShapes(mainShape, indices);
-
- TopTools_ListIteratorOfListOfShape itSub(listShape);
- for (int index = 1; itSub.More(); itSub.Next(), ++index)
- {
- if (shapeIndex + 1 == index)
- {
- TopoDS_Shape value = itSub.Value();
- return value;
- }
- }
- }
-
- throw SALOME_Exception(MsgBuilder() << "Shape with reference [" << shapeIndex << "] not found.");
-}
-
-// -----------------------------
-const int BrepGeometry::countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType)
-{
- int res = 0;
- TopTools_MapOfShape mapShape;
- TopExp_Explorer exp(shape, shapeType);
- for (; exp.More(); exp.Next())
- {
-// if (mapShape.Add(exp.Current()))
- res++;
- }
-
- return res;
-}
-
-std::vector<int> BrepGeometry::getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim)
-{
- std::vector<int> indexList;
-
- TopTools_MapOfShape mapShape;
- TopTools_ListOfShape listShape;
-
- TopExp_Explorer exp(shape, shapeType);
- for (; exp.More(); exp.Next())
- {
- if (mapShape.Add(exp.Current()))
- listShape.Append(exp.Current());
- }
-
- if (!listShape.IsEmpty())
- {
- // use the shape of the geometry for the indices
- TopTools_IndexedMapOfShape indices;
- TopExp::MapShapes(m_shape, indices);
-
- TopTools_ListIteratorOfListOfShape itSub(listShape);
- for (int index = 1; itSub.More(); itSub.Next(), ++index)
- {
- TopoDS_Shape value = itSub.Value();
- int id = indices.FindIndex(value);
- indexList.push_back(findElement(dim, id));
- }
- }
-
- return indexList;
-}
-
-void BrepGeometry::getEdgeVertices(const int& edgeIndex, int& vertexA, int& vertexB)
-{
- TopoDS_Shape edge = getSubShape(m_shape, TopAbs_EDGE, edgeIndex);
- std::vector<int> vertices = getGeometricalElements(edge, TopAbs_VERTEX, XAO::VERTEX);
- assert(vertices.size() == 2);
-
- vertexA = vertices[0];
- vertexB = vertices[1];
-}
-
-const int BrepGeometry::countFaceWires(const int& faceIndex)
-{
- TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
- return countGeometricalElements(face, TopAbs_WIRE);
-}
-
-std::vector<int> BrepGeometry::getFaceEdges(const int& faceIndex, const int& wireIndex)
-{
- // get the face
- TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
- // get the wire
- TopoDS_Shape wire = getSubShape(face, TopAbs_WIRE, wireIndex);
- return getGeometricalElements(wire, TopAbs_EDGE, XAO::EDGE);
-}
-
-const int BrepGeometry::countSolidShells(const int& solidIndex)
-{
- TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
- return countGeometricalElements(solid, TopAbs_SHELL);
-}
-
-std::vector<int> BrepGeometry::getSolidFaces(const int& solidIndex, const int& shellIndex)
-{
- TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
- TopoDS_Shape shell = getSubShape(solid, TopAbs_SHELL, shellIndex);
- return getGeometricalElements(shell, TopAbs_FACE, XAO::FACE);
-}
-
-void BrepGeometry::getVertexXYZ(const int& vertexIndex, double& xCoord, double& yCoord, double& zCoord)
-{
- xCoord = 0.;
- yCoord = 0.;
- zCoord = 0.;
-
- TopoDS_Shape vertex = getSubShape(m_shape, TopAbs_VERTEX, vertexIndex);
- if (vertex.ShapeType() != TopAbs_VERTEX)
- throw SALOME_Exception(MsgBuilder() << "Shape " << vertexIndex<< " is not a point.");
-
- TopoDS_Vertex point = TopoDS::Vertex(vertex);
- if (!point.IsNull())
- {
- gp_Pnt aPnt = BRep_Tool::Pnt(point);
- xCoord = aPnt.X();
- yCoord = aPnt.Y();
- zCoord = aPnt.Z();
- }
-}
-
-// -----------------------------
-const double BrepGeometry::getEdgeLength(const int& edgeIndex)
-{
- TopoDS_Shape edge = getSubShape(m_shape, TopAbs_EDGE, edgeIndex);
- GProp_GProps system;
- BRepGProp::LinearProperties(edge, system);
- return system.Mass();
-}
-
-const double BrepGeometry::getFaceArea(const int& faceIndex)
-{
- TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
- GProp_GProps system;
- BRepGProp::SurfaceProperties(face, system);
- return system.Mass();
-}
-
-const double BrepGeometry::getSolidVolume(const int& solidIndex)
-{
- TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
- GProp_GProps system;
- BRepGProp::VolumeProperties(solid, system);
- return system.Mass();
-}
-
-// -----------------------------
-const int BrepGeometry::getVertexID(const int& index)
-{
- return XaoUtils::stringToInt(getVertexReference(index));
-}
-
-const int BrepGeometry::getEdgeID(const int& index)
-{
- return XaoUtils::stringToInt(getEdgeReference(index));
-}
-
-const int BrepGeometry::getFaceID(const int& index)
-{
- return XaoUtils::stringToInt(getFaceReference(index));
-}
-
-const int BrepGeometry::getSolidID(const int& index)
-{
- return XaoUtils::stringToInt(getSolidReference(index));
-}
-
-// -----------------------------
-void BrepGeometry::setVertexID(const int& index, const int& id)
-{
- setVertexReference(index, XaoUtils::intToString(id));
-}
-
-void BrepGeometry::setEdgeID(const int& index, const int& id)
-{
- setEdgeReference(index, XaoUtils::intToString(id));
-}
-
-void BrepGeometry::setFaceID(const int& index, const int& id)
-{
- setEdgeReference(index, XaoUtils::intToString(id));
-}
-
-void BrepGeometry::setSolidID(const int& index, const int& id)
-{
- setEdgeReference(index, XaoUtils::intToString(id));
-}
-
-// -----------------------------
-const int BrepGeometry::findElement(const XAO::Dimension& dim, const int& id)
-{
- if (dim == XAO::VERTEX)
- return findVertex(id);
- if (dim == XAO::EDGE)
- return findEdge(id);
- if (dim == XAO::FACE)
- return findFace(id);
- if (dim == XAO::SOLID)
- return findSolid(id);
- throw SALOME_Exception(MsgBuilder() << "Unknown Dimension: " << dim);
-}
-
-const int BrepGeometry::findVertex(const int& id)
-{
- return getVertexIndexByReference(XaoUtils::intToString(id));
-}
-
-const int BrepGeometry::findEdge(const int& id)
-{
- return getEdgeIndexByReference(XaoUtils::intToString(id));
-}
-
-const int BrepGeometry::findFace(const int& id)
-{
- return getFaceIndexByReference(XaoUtils::intToString(id));
-}
-
-const int BrepGeometry::findSolid(const int& id)
-{
- return getSolidIndexByReference(XaoUtils::intToString(id));
-}
-
-// -----------------------------
-const std::string BrepGeometry::findVertexName(const int& id)
-{
- return getVertexName(findVertex(id));
-}
-
-const std::string BrepGeometry::findEdgeName(const int& id)
-{
- return getEdgeName(findEdge(id));
-}
-
-const std::string BrepGeometry::findFaceName(const int& id)
-{
- return getFaceName(findFace(id));
-}
-
-const std::string BrepGeometry::findSolidName(const int& id)
-{
- return getSolidName(findSolid(id));
-}
-
-// -----------------------------
-void BrepGeometry::changeVertexName(const int& id, const std::string& name)
-{
- setVertexName(findVertex(id), name);
-}
-
-void BrepGeometry::changeEdgeName(const int& id, const std::string& name)
-{
- setEdgeName(findEdge(id), name);
-}
-
-void BrepGeometry::changeFaceName(const int& id, const std::string& name)
-{
- setFaceName(findFace(id), name);
-}
-
-void BrepGeometry::changeSolidName(const int& id, const std::string& name)
-{
- setSolidName(findSolid(id), name);
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#ifndef __XAO_BREPGEOMETRY_HXX__
-#define __XAO_BREPGEOMETRY_HXX__
-
-#include <string>
-#include <vector>
-
-#include <TopoDS_Shape.hxx>
-
-#include "Xao.hxx"
-#include "Geometry.hxx"
-
-namespace XAO
-{
- class BrepGeometry : public Geometry
- {
- public:
- BrepGeometry();
- BrepGeometry(const std::string& name);
-
- virtual const XAO::Format getFormat() { return XAO::BREP; }
-
- virtual const std::string getShape();
- virtual void setShape(const std::string& shape);
-
- TopoDS_Shape getTopoDS_Shape();
- void setTopoDS_Shape(const TopoDS_Shape& shape);
-
- /**
- * Gives the two extrimities of an edge.
- * @param edgeIndex the index of the edge.
- * @param vertexA
- * @param vertexB
- */
- void getEdgeVertices(const int& edgeIndex, int& vertexA, int& vertexB);
-
- /**
- * Gets the number of wires of a face (including holes).
- * @param faceIndex the index of the face.
- * @return the number of wires.
- */
- const int countFaceWires(const int& faceIndex);
-
- /**
- * Gets the indices of the wires of the face.
- * @param faceIndex the index of the face.
- * @param wireIndex the index of the wire.
- * @return the list of wires for the given face.
- */
- std::vector<int> getFaceEdges(const int& faceIndex, const int& wireIndex);
-
- /**
- * Gets the number of shells of a solid (including cavities).
- * @param solidIndex the index of the solid.
- * @return the number of shells.
- */
- const int countSolidShells(const int& solidIndex);
-
- /**
- * Gets the indices of the shells of the solids.
- * @param solidIndex the index of the solid.
- * @param shellIndex the index of the shell (for the given solid).
- * @return the list of shells for the given solid.
- */
- std::vector<int> getSolidFaces(const int& solidIndex, const int& shellIndex);
-
- /**
- * Gets the coordinates of a vertex.
- * @param vertexIndex the index of the vertex.
- * @param xCoord the X coordinate.
- * @param yCoord the Y coordinate.
- * @param zCoord the Z coordinate.
- */
- void getVertexXYZ(const int& vertexIndex, double& xCoord, double& yCoord, double& zCoord);
-
- /**
- * Gets the length of an edge.
- * @param edge the index of the edge.
- * @return the length of the edge.
- */
- const double getEdgeLength(const int& index);
-
- /**
- * Gets the are of a face.
- * @param face the index of a face.
- * @return the area of the face.
- */
- const double getFaceArea(const int& index);
-
- /**
- * Gets the volume of a solid.
- * @param solid the index of the solid.
- * @return the volume of the solid.
- */
- const double getSolidVolume(const int& index);
-
- /**
- * Gets the ID of a vertex.
- * @param vertex the index of the vertex.
- * @return the ID of the vertex.
- */
- const int getVertexID(const int& index);
-
- /**
- * Gets the ID of an edge.
- * @param edge the index of the edge.
- * @return the ID of the edge.
- */
- const int getEdgeID(const int& index);
-
- /**
- * Gets the ID of a face.
- * @param face the index of the face.
- * @return the ID of the face.
- */
- const int getFaceID(const int& index);
-
- /**
- * Gets the ID of a solid.
- * @param solid the index of the solid.
- * @return the ID of the solid.
- */
- const int getSolidID(const int& solid);
-
- void setVertexID(const int& index, const int& id);
- void setEdgeID(const int& index, const int& id);
- void setFaceID(const int& index, const int& id);
- void setSolidID(const int& index, const int& id);
-
- const int findElement(const XAO::Dimension& dim, const int& id);
-
- /**
- * Finds a vertex with its ID.
- * @param id the ID of the vertex.
- * @return the index of the vertex.
- */
- const int findVertex(const int& id);
-
- /**
- * Finds an edge with its ID.
- * @param id the ID of the edge.
- * @return the index of the edge.
- */
- const int findEdge(const int& id);
-
- /**
- * Finds a face with its ID.
- * @param id the ID of the face.
- * @return the index of the face.
- */
- const int findFace(const int& id);
-
- /**
- * Finds a solid with its ID.
- * @param id the ID of the solid.
- * @return th index of the solid.
- */
- const int findSolid(const int& id);
-
- /**
- * Finds the name of a vertex with its ID.
- * @param id the ID of the vertex.
- * @return the name of the vertex.
- */
- const std::string findVertexName(const int& id);
-
- /**
- * Finds the name of an edge with its ID.
- * @param id the ID of the edge.
- * @return the name of the edge.
- */
- const std::string findEdgeName(const int& id);
-
- /**
- * Finds the name of a face with its ID.
- * @param id the ID of the face.
- * @return the name of the face.
- */
- const std::string findFaceName(const int& id);
-
- /**
- * Finds the name of a solid with its ID.
- * @param id the ID of the solid.
- * @return the name of the solid.
- */
- const std::string findSolidName(const int& id);
-
- /**
- * Changes the name of a vertex.
- * @param id the ID of the vertex.
- * @param name the name to set.
- */
- void changeVertexName(const int& id, const std::string& name);
-
- /**
- * Changes the name of an edge.
- * @param id the ID of the edge
- * @param name the name to set.
- */
- void changeEdgeName(const int& id, const std::string& name);
-
- /**
- * Changes the name of a face.
- * @param id the ID of the face.
- * @param name the name to set.
- */
- void changeFaceName(const int& id, const std::string& name);
-
- /**
- * Changes the name of a solid.
- * @param id the ID of the solid.
- * @param name the name to set.
- */
- void changeSolidName(const int& id, const std::string& name);
-
- private:
- void initIds();
- void initListIds(const TopAbs_ShapeEnum& shapeType, GeometricElementList& eltList);
- TopoDS_Shape getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex);
- const int countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType);
- std::vector<int> getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim);
-
- private:
- TopoDS_Shape m_shape;
- };
-}
-
-#endif // __XAO_BREPGEOMETRY_HXX__
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include "DoubleField.hxx"
-#include "DoubleStep.hxx"
-#include "XaoUtils.hxx"
-
-#include <Utils_SALOME_Exception.hxx>
-
-using namespace XAO;
-
-DoubleField::DoubleField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents)
- : Field(name, dimension, nbElements, nbComponents)
-{
-}
-
-Step* DoubleField::addNewStep(const int& step)
-{
- return addStep(step, 0);
-}
-
-DoubleStep* DoubleField::addStep(const int& step)
-{
- return addStep(step, 0);
-}
-
-DoubleStep* DoubleField::addStep(const int& step, const int& stamp)
-{
- if (hasStep(step))
- throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
-
- DoubleStep* bstep = new DoubleStep(step, stamp, m_nbElements, m_nbComponents);
- m_steps.push_back(bstep);
- return bstep;
-}
-
-DoubleStep* DoubleField::getStep(const int& index)
-{
- checkStepIndex(index);
- return (DoubleStep*)m_steps[index];
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#ifndef __XAO_DOUBLEFIELD_HXX__
-#define __XAO_DOUBLEFIELD_HXX__
-
-#include <iostream>
-#include <string>
-#include <vector>
-#include <map>
-
-#include "Xao.hxx"
-#include "Field.hxx"
-#include "DoubleStep.hxx"
-
-namespace XAO
-{
- class DoubleField : public Field
- {
- public:
- DoubleField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
-
- virtual const XAO::Type getType() { return XAO::DOUBLE; }
-
- virtual Step* addNewStep(const int& step);
- DoubleStep* addStep(const int& step);
- DoubleStep* addStep(const int& step, const int& stamp);
- DoubleStep* getStep(const int& index);
- };
-}
-
-#endif /* __XAO_DOUBLEFIELD_HXX__ */
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include "DoubleStep.hxx"
-#include <Utils_SALOME_Exception.hxx>
-#include "XaoUtils.hxx"
-
-using namespace XAO;
-
-DoubleStep::DoubleStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
-{
- m_nbElements = nbElements;
- m_nbComponents = nbComponents;
- m_step = step;
- m_stamp = stamp;
-
- m_values.reserve(m_nbElements);
- for (int i = 0; i < m_nbElements; ++i)
- {
- std::vector<double> row;
- row.reserve(m_nbComponents);
- for (int j = 0; j < m_nbComponents; ++j)
- row.push_back(0);
- m_values.push_back(row);
- }
-}
-
-std::vector<double> DoubleStep::getValues()
-{
- std::vector<double> result;
- result.reserve(m_nbElements * m_nbComponents);
-
- std::vector< std::vector<double> >::iterator it;
- for (it = m_values.begin(); it != m_values.end(); ++it)
- {
- std::vector<double> eltValues = *it;
- result.insert(result.end(), eltValues.begin(), eltValues.end());
- }
-
- return result;
-}
-
-std::vector<double> DoubleStep::getElement(const int& element)
-{
- checkElementIndex(element);
-
- std::vector<double> result(m_values[element]);
- return result;
-}
-
-std::vector<double> DoubleStep::getComponent(const int& component)
-{
- checkComponentIndex(component);
-
- std::vector<double> result;
- result.reserve(m_nbElements);
-
- std::vector< std::vector<double> >::iterator it;
- for (it = m_values.begin(); it != m_values.end(); ++it)
- {
- std::vector<double> eltValues = *it;
- result.push_back(eltValues[component]);
- }
-
- return result;
-}
-
-const double DoubleStep::getValue(const int& element, const int& component)
-{
- checkElementIndex(element);
- checkComponentIndex(component);
-
- return m_values[element][component];
-}
-
-const std::string DoubleStep::getStringValue(const int& element, const int& component)
-{
- return XaoUtils::doubleToString(getValue(element, component));
-}
-
-void DoubleStep::setValues(const std::vector<double>& values)
-{
- checkNbValues(values.size());
-
- for (int i = 0; i < m_nbElements; ++i)
- {
- for (int j = 0; j < m_nbComponents; ++j)
- {
- m_values[i][j] = values[i * m_nbComponents + j];
- }
- }
-}
-
-void DoubleStep::setElements(const int& element, const std::vector<double>& elements)
-{
- checkElementIndex(element);
- checkNbComponents(elements.size());
-
- for (int i = 0; i < m_nbComponents; ++i)
- m_values[element][i] = elements[i];
-}
-
-void DoubleStep::setComponents(const int& component, const std::vector<double>& components)
-{
- checkElementIndex(component);
- checkNbElements(components.size());
-
- for (int i = 0; i < m_nbElements; ++i)
- m_values[i][component] = components[i];
-}
-
-void DoubleStep::setValue(const int& element, const int& component, const double& value)
-{
- checkElementIndex(element);
- checkComponentIndex(component);
-
- m_values[element][component] = value;
-}
-
-void DoubleStep::setStringValue(const int& element, const int& component, const std::string& value)
-{
- setValue(element, component, XaoUtils::stringToDouble(value));
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-
-#ifndef __XAO_DOUBLESTEP_HXX__
-#define __XAO_DOUBLESTEP_HXX__
-
-#include <vector>
-
-#include "Xao.hxx"
-#include "Step.hxx"
-
-namespace XAO
-{
- class DoubleStep : public Step
- {
- public:
- DoubleStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
-
- virtual const XAO::Type getType() { return XAO::DOUBLE; }
-
- std::vector<double> getValues();
- std::vector<double> getElement(const int& element);
- std::vector<double> getComponent(const int& component);
-
- const double getValue(const int& element, const int& component);
-
- void setValues(const std::vector<double>& values);
- void setElements(const int& element, const std::vector<double>& elements);
- void setComponents(const int& component, const std::vector<double>& components);
- void setValue(const int& element, const int& component, const double& value);
-
- virtual const std::string getStringValue(const int& element, const int& component);
- virtual void setStringValue(const int& element, const int& component, const std::string& value);
-
- private:
- std::vector< std::vector<double> > m_values;
- };
-}
-
-
-#endif /* __XAO_DOUBLESTEP_HXX__ */
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include <string>
-#include <iostream>
-#include <Utils_SALOME_Exception.hxx>
-
-#include "Xao.hxx"
-#include "Field.hxx"
-#include "BooleanField.hxx"
-#include "IntegerField.hxx"
-#include "DoubleField.hxx"
-#include "StringField.hxx"
-#include "XaoUtils.hxx"
-
-using namespace XAO;
-
-// -------------------------------------------------------
-
-Field::Field(const std::string& name, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents)
- : m_name(name), m_dimension(dimension), m_nbElements(nbElements), m_nbComponents(nbComponents)
-{
- m_components.reserve(nbComponents);
- for (int i = 0; i < nbComponents; ++i)
- m_components.push_back("");
-}
-
-Field::~Field()
-{
- for (int i = 0; i < m_steps.size(); ++i)
- delete m_steps[i];
-}
-
-Field* Field::createField(const XAO::Type& type, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents)
-{
- return createField(type, "", dimension, nbElements, nbComponents);
-}
-
-Field* Field::createField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents)
-{
- if (type == XAO::BOOLEAN)
- return new BooleanField(name, dimension, nbElements, nbComponents);
- if (type == XAO::INTEGER)
- return new IntegerField(name, dimension, nbElements, nbComponents);
- if (type == XAO::DOUBLE)
- return new DoubleField(name, dimension, nbElements, nbComponents);
- if (type == XAO::STRING)
- return new StringField(name, dimension, nbElements, nbComponents);
-
- throw SALOME_Exception(MsgBuilder() << "Bad Type: " << type);
-}
-
-const std::string Field::getComponentName(const int& index)
-{
- checkComponent(index);
- return m_components[index];
-}
-
-void Field::setComponentName(const int& index, const std::string& name)
-{
- checkComponent(index);
- m_components[index] = name;
-}
-
-bool Field::removeStep(Step* step)
-{
- std::vector<Step*>::iterator it = m_steps.begin();
- for (; it != m_steps.end(); ++it)
- {
- Step* current = *it;
- if (step == current)
- {
- m_steps.erase(it);
- return true;
- }
- }
-
- return false;
-}
-
-bool Field::hasStep(const int& step)
-{
- std::vector<Step*>::iterator it = m_steps.begin();
- for (; it != m_steps.end(); ++it)
- {
- Step* current = *it;
- if (current->getStep() == step)
- return true;
- }
-
- return false;
-}
-
-void Field::checkComponent(const int& component)
-{
- if (component < m_nbComponents && component >= 0)
- return;
-
- throw SALOME_Exception(MsgBuilder() << "Step index is out of range [0, "
- << m_nbComponents << "]: " << component);
-}
-
-void Field::checkStepIndex(const int& step)
-{
- if (step < m_steps.size() && step >= 0)
- return;
-
- throw SALOME_Exception(MsgBuilder() << "Step index is out of range [0, "
- << m_steps.size() << "]: " << step);
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#ifndef __XAO_FIELD_HXX__
-#define __XAO_FIELD_HXX__
-
-#include <iostream>
-#include <string>
-#include <vector>
-#include <map>
-
-#include "Xao.hxx"
-#include "Step.hxx"
-
-namespace XAO
-{
- typedef std::vector<Step*>::iterator stepIterator;
-
- /**
- * @class Field
- * A geometrical Field.
- */
- class Field
- {
- protected:
- /**
- * Constructor.
- * @param name the name of the field.
- * @param dimension the dimension ot the field.
- * @param nbElements the number of elements.
- * @param nbComponents the number of components.
- */
- Field(const std::string& name, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents);
-
- public:
- /**
- * Creates a Field of the given type.
- * @param type the type of the field to create.
- * @param dimension the dimension.
- * @param nbElements the number of geometrical elements.
- * @param nbComponents the number of components.
- * @return the created field.
- */
- static Field* createField(const XAO::Type& type, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents);
-
- /**
- /**
- * Creates a Field of the given type.
- * @param type the type of the field to create.
- * @name the name of the field.
- * @param dimension the dimension.
- * @param nbElements the number of geometrical elements.
- * @param nbComponents the number of components.
- * @return the created field.
- */
- static Field* createField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents);
-
- /**
- * Destructor.
- */
- virtual ~Field();
-
- /**
- * Gets the Type of the field.
- * @return the Type of the field.
- */
- virtual const XAO::Type getType() = 0;
-
- /**
- * Gets the name of the Field.
- * @return the name of the Field.
- */
- const std::string getName() const
- {
- return m_name;
- }
-
- /**
- * Sets the name of the Field.
- * @param name the name to set.
- */
- void setName(const std::string& name)
- {
- m_name = name;
- }
-
- /**
- * Gets the Dimension of the Field.
- * @return the Dimension of the Field.
- */
- const XAO::Dimension getDimension() const
- {
- return m_dimension;
- }
-
- /**
- * Gets the number of elements of each step.
- * @return the number of elements of each step.
- */
- const int countElements() const
- {
- return m_nbElements;
- }
-
- /**
- * Gets the number of components.
- * @return the number of components.
- */
- const int countComponents() const
- {
- return m_nbComponents;
- }
-
- /**
- * Gets the number of values for each step.
- * @return the number of values for each step.
- */
- const int countValues() const
- {
- return m_nbElements * m_nbComponents;
- }
-
- /**
- * Gets the number of the steps.
- * @return the number of steps.
- */
- const int countSteps() const { return m_steps.size(); }
-
- /**
- * Gets the name of a component.
- * @param index the index of the component to get.
- * @return the name of the component for the given index.
- */
- const std::string getComponentName(const int& index);
-
- /**
- * Sets the name of a component.
- * @param componentIndex the index of the component to set.
- * @param name the name to set.
- */
- void setComponentName(const int& componentIndex, const std::string& name);
-
- /**
- * Adds a new step of the same type than the field.
- * @param number the numer of the step.
- * @return the new create step.
- */
- virtual Step* addNewStep(const int& number) = 0;
-
- /**
- * Remove a step.
- * @param step the step to remove.
- * @return true if the step has been removed, false otherwise.
- */
- bool removeStep(Step* step);
-
- /**
- * Verifies if the field has a step with the given step number.
- * @param step the step number.
- * @return true if the field has a step for the given number.
- */
- bool hasStep(const int& step);
-
- /**
- * Returns the first step.
- * @return an iterator on the first step.
- */
- stepIterator begin() { return m_steps.begin(); }
-
- /**
- * Returns the last step.
- * @return an iterator on the last step.
- */
- stepIterator end() { return m_steps.end(); }
-
- protected:
- /** Ensures that component is valid (< m_nbComponents). */
- void checkComponent(const int& component);
- void checkStepIndex(const int& step);
-
- protected:
- /** The name of the Field. */
- std::string m_name;
- /** The dimension of the Field. */
- XAO::Dimension m_dimension;
-
- /** The number of components. */
- int m_nbComponents;
- /** The components of the field. */
- std::vector<std::string> m_components;
- /** The number of elements. */
- int m_nbElements;
-
- /** The list of steps. */
- std::vector<Step*> m_steps;
- };
-}
-
-#endif
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include <Utils_SALOME_Exception.hxx>
-
-#include "GeometricElement.hxx"
-#include "XaoUtils.hxx"
-
-using namespace XAO;
-
-
-GeometricElement::GeometricElement()
-{
- m_name = "";
- m_reference = "";
-}
-
-GeometricElement::GeometricElement(const std::string& name, const std::string& reference)
-{
- m_name = name;
- m_reference = reference;
-}
-
-GeometricElement::~GeometricElement()
-{
-}
-
-const bool GeometricElement::hasName()
-{
- return !m_name.empty();
-}
-
-GeometricElementList::GeometricElementList()
-{
- setSize(0);
-}
-
-GeometricElementList::GeometricElementList(const int& count)
-{
- setSize(m_count);
-}
-
-void GeometricElementList::setSize(const int& nb)
-{
- m_count = nb;
- m_elements.clear();
- for (int i = 0; i < nb; ++i)
- {
- m_elements[i] = GeometricElement();
- }
-}
-
-void GeometricElementList::setElement(const int& index, const std::string& name, const std::string& reference)
-{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
-
- m_elements[index].setName(name);
- m_elements[index].setReference(reference);
-}
-
-const std::string GeometricElementList::getName(const int& index)
-{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
-
- return m_elements[index].getName();
-}
-
-void GeometricElementList::setName(const int& index, const std::string& name)
-{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
-
- m_elements[index].setName(name);
-}
-
-const bool GeometricElementList::hasName(const int& index)
-{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
-
- return m_elements[index].hasName();
-}
-
-const std::string GeometricElementList::getReference(const int& index)
-{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
-
- return m_elements[index].getReference();
-}
-
-void GeometricElementList::setReference(const int& index, const std::string& name)
-{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
-
- m_elements[index].setReference(name);
-}
-
-const int GeometricElementList::getIndexByReference(const std::string& ref)
-{
- for (int index = 0; index < m_count; ++index)
- {
- if (ref == m_elements[index].getReference())
- return index;
- }
-
- throw SALOME_Exception(MsgBuilder() << "Reference not found: " << ref);
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#ifndef __XAO_GEOMETRICELEMENT_HXX__
-#define __XAO_GEOMETRICELEMENT_HXX__
-
-#include <string>
-#include <map>
-
-namespace XAO
-{
- /**
- * \class GeometricElement
- * Generic class to manipulate a topologic element (vertex, edge, face or solid).
- */
- class GeometricElement
- {
- public:
- /**
- * Default constructor.
- */
- GeometricElement();
- /**
- * Constructor with name and reference.
- * \param name the name of the element.
- * \param reference the reference of the element.
- */
- GeometricElement(const std::string& name, const std::string& reference);
- /**
- * Destructor.
- */
- virtual ~GeometricElement();
-
- /**
- * Gets the name of the element.
- * \return the name.
- */
- const std::string getName()
- {
- return m_name;
- }
- /**
- * Sets the name of the element
- * \param name the name to set.
- */
- void setName(const std::string& name)
- {
- m_name = name;
- }
-
- /**
- * Checks if the element has a name.
- * @return true if the element has a name, false otherwise.
- */
- const bool hasName();
-
- /**
- * Gets the reference of the element.
- * \return the reference.
- */
- const std::string getReference()
- {
- return m_reference;
- }
- /**
- * Sets the reference of the element.
- * \param reference the reference to set.
- */
- void setReference(const std::string& reference)
- {
- m_reference = reference;
- }
-
- private:
- /** The name of the element. */
- std::string m_name;
- /** The reference of the element. */
- std::string m_reference;
- };
-
- /**
- * \class GeometricElementList
- * Generic class to manipulate a list of topologic element.
- */
- class GeometricElementList
- {
- public:
- /**
- * Default constructor.
- */
- GeometricElementList();
-
- /**
- * Constructor with size.
- * \param nb the size to set.
- */
- GeometricElementList(const int& nb);
-
- /**
- * Destructor.
- */
- virtual ~GeometricElementList() {}
-
- /**
- * Gets the size of the list.
- * \return the size of the list.
- */
- const int getSize() const { return m_count; }
-
- /**
- * Sets the size of the list.
- * \param nb the size to set.
- * \warning the list will be cleared.
- */
- void setSize(const int& nb);
-
- /**
- * Sets the name and the reference of an element.
- * \param index the index of the element to set.
- * \param name the name to set.
- * \param reference the reference to set.
- * \throw SALOME_Exception if index is bigger than the size of the list.
- */
- void setElement(const int& index, const std::string& name, const std::string& reference);
- /**
- * Gets the name of an element.
- * \param index the index of the element to set.
- * \return the name of the element with the given index.
- * \throw SALOME_Exception if index is bigger than the size of the list.
- */
- const std::string getName(const int& index);
- /**
- * Sets the name of an element.
- * \param index the index of the element.
- * \param name the name to set.
- * \throw SALOME_Exception if index is bigger than the size of the list.
- */
- void setName(const int& index, const std::string& name);
-
- /**
- * Checks if an element has a name.
- * @param index the index of the element.
- * @return true if the element has a name, false otherwise.
- */
- const bool hasName(const int& index);
-
- /**
- * Gets the reference of an element.
- * \param index the index of the element.
- * \return the reference of the element.
- * \throw SALOME_Exception if index is bigger than the size of the list.
- */
- const std::string getReference(const int& index);
- /**
- * Sets the reference of an element.
- * \param index the index of the element to set.
- * \param reference the reference to set.
- * \throw SALOME_Exception if index is bigger than the size of the list.
- */
- void setReference(const int& index, const std::string& reference);
-
- /**
- * Gets the index of an element using its reference.
- * \param reference the searched reference.
- * \return the index of the element or -1 if no element found.
- */
- const int getIndexByReference(const std::string& reference);
-
- /**
- * Iterator on the element of the list.
- */
- typedef std::map<int, GeometricElement>::iterator iterator;
-
- /**
- * Gets an iterator on the first element.
- * @return an iterator on the first element.
- */
- iterator begin() { return m_elements.begin(); }
-
- /**
- * Gets an iterator on the last element.
- * @return an iterator on the last element.
- */
- iterator end() { return m_elements.end(); }
-
- private:
- int m_count;
- std::map<int, GeometricElement> m_elements;
- };
-}
-
-#endif /* __XAO_GEOMETRICELEMENT_HXX__ */
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Nathalie Gore (OpenCascade)
-
-#include <Utils_SALOME_Exception.hxx>
-
-#include "XaoUtils.hxx"
-#include "Geometry.hxx"
-#include "BrepGeometry.hxx"
-
-using namespace XAO;
-
-Geometry::Geometry(const std::string& name)
- : m_name(name)
-{
-}
-
-Geometry* Geometry::createGeometry(const XAO::Format& format)
-{
- return createGeometry(format, "");
-}
-
-Geometry* Geometry::createGeometry(const XAO::Format& format, const std::string& name)
-{
- if (format == XAO::BREP)
- return new BrepGeometry(name);
-
- throw SALOME_Exception(MsgBuilder() << "Geometry format not supported: " << format);
-}
-
-Geometry::~Geometry()
-{
-}
-
-const int Geometry::countElements(const XAO::Dimension& dim)
-{
- if (dim == XAO::VERTEX)
- return countVertices();
- if (dim == XAO::EDGE)
- return countEdges();
- if (dim == XAO::FACE)
- return countFaces();
- if (dim == XAO::SOLID)
- return countSolids();
-
- throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
-}
-
-const std::string Geometry::getElementReference(const XAO::Dimension& dim, const int& index)
-{
- if (dim == XAO::VERTEX)
- return getVertexReference(index);
- if (dim == XAO::EDGE)
- return getEdgeReference(index);
- if (dim == XAO::FACE)
- return getFaceReference(index);
- if (dim == XAO::SOLID)
- return getSolidReference(index);
-
- throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
-}
-
-const int Geometry::getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference)
-{
- if (dim == XAO::VERTEX)
- return getVertexIndexByReference(reference);
- if (dim == XAO::EDGE)
- return getEdgeIndexByReference(reference);
- if (dim == XAO::FACE)
- return getFaceIndexByReference(reference);
- if (dim == XAO::SOLID)
- return getSolidIndexByReference(reference);
-
- throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
-}
-
-GeometricElementList::iterator Geometry::begin(const XAO::Dimension& dim)
-{
- if (dim == XAO::VERTEX)
- return m_vertices.begin();
- if (dim == XAO::EDGE)
- return m_edges.begin();
- if (dim == XAO::FACE)
- return m_faces.begin();
- if (dim == XAO::SOLID)
- return m_solids.begin();
-
- throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
-}
-
-GeometricElementList::iterator Geometry::end(const XAO::Dimension& dim)
-{
- if (dim == XAO::VERTEX)
- return m_vertices.end();
- if (dim == XAO::EDGE)
- return m_edges.end();
- if (dim == XAO::FACE)
- return m_faces.end();
- if (dim == XAO::SOLID)
- return m_solids.end();
-
- throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
-}
+++ /dev/null
-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Nathalie Gore (OpenCascade)
-
-#ifndef __XAO_GEOMETRY_HXX__
-#define __XAO_GEOMETRY_HXX__
-
-#include <string>
-
-#include "Xao.hxx"
-#include "GeometricElement.hxx"
-
-namespace XAO
-{
- class Geometry
- {
- protected:
- Geometry(const std::string& name);
-
- public:
- /**
- * Creates a geometry.
- * @param format the format of the geometry.
- * @return the created geometry.
- */
- static Geometry* createGeometry(const XAO::Format& format);
-
- /**
- * Constructor.
- * Creates a geometry.
- * @name name the name of the geometry.
- * @return the created geometry.
- */
- static Geometry* createGeometry(const XAO::Format& format, const std::string& name);
-
- /** Destructor. */
- ~Geometry();
-
- /**
- * Gets the name of the geometry.
- * @return the name of the geometry.
- */
- const std::string getName()
- {
- return m_name;
- }
- /**
- * Sets the name of the geometry.
- * @param name the name to set.
- */
- void setName(const std::string& name)
- {
- m_name = name;
- }
-
- /**
- * Gets the format of the geometry.
- * @return the format of the geometry.
- */
- virtual const XAO::Format getFormat() = 0;
-
- virtual const std::string getShape() = 0;
- virtual void setShape(const std::string& shape) = 0;
-
- const int countElements(const XAO::Dimension& dim);
- const int countVertices() { return m_vertices.getSize(); }
- const int countEdges() { return m_edges.getSize(); }
- const int countFaces() { return m_faces.getSize(); }
- const int countSolids() { return m_solids.getSize(); }
-
- void setCountVertices(const int& nb) { m_vertices.setSize(nb); }
- void setCountEdges(const int& nb) { m_edges.setSize(nb); }
- void setCountFaces(const int& nb) { m_faces.setSize(nb); }
- void setCountSolids(const int& nb) { m_solids.setSize(nb); }
-
- const std::string getVertexName(const int& index) { return m_vertices.getName(index); }
- const std::string getEdgeName(const int& index) { return m_edges.getName(index); }
- const std::string getFaceName(const int& index) { return m_faces.getName(index); }
- const std::string getSolidName(const int& index) { return m_solids.getName(index); }
-
- void setVertexName(const int& index, const std::string& name) { m_vertices.setName(index, name); }
- void setEdgeName(const int& index, const std::string& name) { m_edges.setName(index, name); }
- void setFaceName(const int& index, const std::string& name) { m_faces.setName(index, name); }
- void setSolidName(const int& index, const std::string& name) { m_solids.setName(index, name); }
-
- const bool hasVertexName(const int& index) { return m_vertices.hasName(index); }
- const bool hasEdgeName(const int& index) { return m_edges.hasName(index); }
- const bool hasFaceName(const int& index) { return m_faces.hasName(index); }
- const bool hasSolidName(const int& index) { return m_solids.hasName(index); }
-
- const std::string getVertexReference(const int& index) { return m_vertices.getReference(index); }
- const std::string getEdgeReference(const int& index) { return m_edges.getReference(index); }
- const std::string getFaceReference(const int& index) { return m_faces.getReference(index); }
- const std::string getSolidReference(const int& index) { return m_solids.getReference(index); }
- const std::string getElementReference(const XAO::Dimension& dim, const int& index);
-
- void setVertexReference(const int& index, const std::string& reference) { m_vertices.setReference(index, reference); }
- void setEdgeReference(const int& index, const std::string& reference) { m_edges.setReference(index, reference); }
- void setFaceReference(const int& index, const std::string& reference) { m_faces.setReference(index, reference); }
- void setSolidReference(const int& index, const std::string& reference) { m_solids.setReference(index, reference); }
-
- void setVertex(const int& index, const std::string& name, const std::string& reference) { m_vertices.setElement(index, name, reference); }
- void setEdge(const int& index, const std::string& name, const std::string& reference) { m_edges.setElement(index, name, reference); }
- void setFace(const int& index, const std::string& name, const std::string& reference) { m_faces.setElement(index, name, reference); }
- void setSolid(const int& index, const std::string& name, const std::string& reference) { m_solids.setElement(index, name, reference); }
-
- const int getVertexIndexByReference(const std::string& reference) { return m_vertices.getIndexByReference(reference); }
- const int getEdgeIndexByReference(const std::string& reference) { return m_edges.getIndexByReference(reference); }
- const int getFaceIndexByReference(const std::string& reference) { return m_faces.getIndexByReference(reference); }
- const int getSolidIndexByReference(const std::string& reference) { return m_solids.getIndexByReference(reference); }
- const int getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference);
-
- GeometricElementList::iterator begin(const XAO::Dimension& dim);
- GeometricElementList::iterator end(const XAO::Dimension& dim);
-
- protected:
- std::string m_name;
- GeometricElementList m_vertices;
- GeometricElementList m_edges;
- GeometricElementList m_faces;
- GeometricElementList m_solids;
-
- };
-}
-
-#endif
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
-
-#include <Utils_SALOME_Exception.hxx>
-
-#include "XaoUtils.hxx"
-#include "Group.hxx"
-
-using namespace XAO;
-
-
-Group::Group(const XAO::Dimension& dim, const int& nbElements)
-{
- initGroup("", dim, nbElements);
-}
-
-Group::Group(const std::string& name, const XAO::Dimension& dim, const int& nbElements)
-{
- initGroup(name, dim, nbElements);
-}
-
-void Group::initGroup(const std::string& name, const XAO::Dimension& dim, const int& nbElements)
-{
- if (dim == XAO::WHOLE)
- throw SALOME_Exception("Dimension WHOLE is not valid for group.");
-
- m_name = name;
- m_dimension = dim;
- m_count = 0;
- m_nbElements = nbElements;
-}
-
-Group::~Group()
-{
-}
-
-void Group::checkIndex(const int& element)
-{
- if (element < m_elements.size() && element >= 0)
- return;
-
- throw SALOME_Exception(MsgBuilder() << "Index of element is out of range [0, "
- << m_elements.size()-1 << "]: " << element);
-}
-
-void Group::add(const int& value)
-{
- m_elements.insert(value);
-}
-
-void Group::remove(const int& value)
-{
- m_elements.erase(value);
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
-
-#ifndef __XAO_GROUP_HXX__
-#define __XAO_GROUP_HXX__
-
-# include <iostream>
-#include <string>
-#include <set>
-
-#include "Xao.hxx"
-
-namespace XAO
-{
- /**
- * \class Group
- * Class to represent a Geometrical Group.
- */
- class Group
- {
- public:
- /**
- * Constructor.
- * @param dim the dimension of the group.
- * @param nbElements the number of geometrical elements for the dimension in the geometry.
- */
- Group(const XAO::Dimension& dim, const int& nbElements);
-
- /**
- * Constructor.
- * @name the name of the group.
- * @param dim the dimension of the group.
- * @param nbElements the number of geometrical elements for the dimension in the geometry.
- */
- Group(const std::string& name, const XAO::Dimension& dim, const int& nbelements);
-
- /**
- * Destructor.
- */
- virtual ~Group();
-
- /**
- * Gets the name of the group.
- * \return the name of the group.
- */
- const std::string getName()
- {
- return m_name;
- }
- /**
- * Sets the name of the group.
- * \param name the name to set.
- */
- void setName(const std::string& name)
- {
- m_name = name;
- }
-
- /**
- * Gets the dimension of the group.
- * \return the dimension of the group.
- */
- const XAO::Dimension getDimension()
- {
- return m_dimension;
- }
-
- /**
- * Gets the numbers of elements in the geometry of the same type than the group.
- * \return the number of elements in the associated geometry.
- */
- const int getNbElements()
- {
- return m_nbElements;
- }
-
- /**
- * Gets the number of elements in the group.
- * \return the number of elements.
- */
- const int count() const
- {
- return m_elements.size();
- }
-
- /**
- * Gets the reference of an element.
- * \param index the index of the element.
- * \return the reference of the element.
- * \note use begin() and end() if you need to iterate.
- */
- const int get(const int& index)
- {
- checkIndex(index);
- std::set<int>::iterator it = m_elements.begin();
- std::advance(it, index);
- return (*it);
- }
-
- /**
- * Adds an element to the group.
- * \param value the index of the element to add.
- */
- void add(const int& value);
-
- /**
- * Removes an element from the group.
- * \param value the index of the element to remove.
- */
- void remove(const int& value);
-
- /**
- * Gets an iterator on the first element in the group.
- * @return an iterator on the first element.
- */
- std::set<int>::iterator begin() { return m_elements.begin(); }
-
- /**
- * Gets an iterator on the last element in the group.
- * @return an iterator on the last element.
- */
- std::set<int>::iterator end() { return m_elements.end(); }
-
- private:
- /**
- * Initialize the groups.
- * @param name the name of the group.
- * @param dim the dimension of the group.
- * @param nbElements the number of elements in the geometry for the dimension.
- */
- void initGroup(const std::string& name, const XAO::Dimension& dim, const int& nbElements);
-
- /**
- * Ensures that the given element is valid.
- * @param element
- * @throw SALOME_Exception if element is bigger than the number of elements.
- */
- void checkIndex(const int& element);
-
- private:
- /** The name of the group. */
- std::string m_name;
- /** The number of elements in the associated geometry. */
- int m_nbElements;
- /** The dimension of the group. */
- XAO::Dimension m_dimension;
- /** The number of elements in the group. */
- int m_count;
- /** The elements of the group. */
- std::set<int> m_elements;
- };
-}
-
-#endif
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include "IntegerField.hxx"
-#include "IntegerStep.hxx"
-#include "XaoUtils.hxx"
-
-#include <Utils_SALOME_Exception.hxx>
-
-using namespace XAO;
-
-IntegerField::IntegerField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents)
- : Field(name, dimension, nbElements, nbComponents)
-{
-}
-
-Step* IntegerField::addNewStep(const int& step)
-{
- return addStep(step, 0);
-}
-
-IntegerStep* IntegerField::addStep(const int& step)
-{
- return addStep(step, 0);
-}
-
-IntegerStep* IntegerField::addStep(const int& step, const int& stamp)
-{
- if (hasStep(step))
- throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
-
- IntegerStep* bstep = new IntegerStep(step, stamp, m_nbElements, m_nbComponents);
- m_steps.push_back(bstep);
- return bstep;
-}
-
-IntegerStep* IntegerField::getStep(const int& index)
-{
- checkStepIndex(index);
- return (IntegerStep*)m_steps[index];
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#ifndef __XAO_INTEGERFIELD_HXX__
-#define __XAO_INTEGERFIELD_HXX__
-
-#include <iostream>
-#include <string>
-#include <vector>
-#include <map>
-
-#include "Xao.hxx"
-#include "Field.hxx"
-#include "IntegerStep.hxx"
-
-namespace XAO
-{
- class IntegerField : public Field
- {
- public:
- IntegerField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
-
- virtual const XAO::Type getType() { return XAO::INTEGER; }
-
- virtual Step* addNewStep(const int& step);
- IntegerStep* addStep(const int& step);
- IntegerStep* addStep(const int& step, const int& stamp);
- IntegerStep* getStep(const int& step);
- };
-}
-
-#endif /* __XAO_INTEGERFIELD_HXX__ */
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include "IntegerStep.hxx"
-#include <Utils_SALOME_Exception.hxx>
-#include "XaoUtils.hxx"
-
-using namespace XAO;
-
-IntegerStep::IntegerStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
-{
- m_nbElements = nbElements;
- m_nbComponents = nbComponents;
- m_step = step;
- m_stamp = stamp;
-
- m_values.reserve(m_nbElements);
- for (int i = 0; i < m_nbElements; ++i)
- {
- std::vector<int> row;
- row.reserve(m_nbComponents);
- for (int j = 0; j < m_nbComponents; ++j)
- row.push_back(0);
- m_values.push_back(row);
- }
-}
-
-std::vector<int> IntegerStep::getValues()
-{
- std::vector<int> result;
- result.reserve(m_nbElements * m_nbComponents);
-
- std::vector< std::vector<int> >::iterator it;
- for (it = m_values.begin(); it != m_values.end(); ++it)
- {
- std::vector<int> eltValues = *it;
- result.insert(result.end(), eltValues.begin(), eltValues.end());
- }
-
- return result;
-}
-
-std::vector<int> IntegerStep::getElement(const int& element)
-{
- checkElementIndex(element);
-
- std::vector<int> result(m_values[element]);
- return result;
-}
-
-std::vector<int> IntegerStep::getComponent(const int& component)
-{
- checkComponentIndex(component);
-
- std::vector<int> result;
- result.reserve(m_nbElements);
-
- std::vector< std::vector<int> >::iterator it;
- for (it = m_values.begin(); it != m_values.end(); ++it)
- {
- std::vector<int> eltValues = *it;
- result.push_back(eltValues[component]);
- }
-
- return result;
-}
-
-const int IntegerStep::getValue(const int& element, const int& component)
-{
- checkElementIndex(element);
- checkComponentIndex(component);
-
- return m_values[element][component];
-}
-
-const std::string IntegerStep::getStringValue(const int& element, const int& component)
-{
- return XaoUtils::intToString(getValue(element, component));
-}
-
-void IntegerStep::setValues(const std::vector<int>& values)
-{
- checkNbValues(values.size());
-
- for (int i = 0; i < m_nbElements; ++i)
- {
- for (int j = 0; j < m_nbComponents; ++j)
- {
- m_values[i][j] = values[i * m_nbComponents + j];
- }
- }
-}
-
-void IntegerStep::setElements(const int& element, const std::vector<int>& elements)
-{
- checkElementIndex(element);
- checkNbComponents(elements.size());
-
- for (int i = 0; i < m_nbComponents; ++i)
- m_values[element][i] = elements[i];
-}
-
-void IntegerStep::setComponents(const int& component, const std::vector<int>& components)
-{
- checkElementIndex(component);
- checkNbElements(components.size());
-
- for (int i = 0; i < m_nbElements; ++i)
- m_values[i][component] = components[i];
-}
-
-void IntegerStep::setValue(const int& element, const int& component, const int& value)
-{
- checkElementIndex(element);
- checkComponentIndex(component);
-
- m_values[element][component] = value;
-}
-
-void IntegerStep::setStringValue(const int& element, const int& component, const std::string& value)
-{
- setValue(element, component, XaoUtils::stringToInt(value));
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-
-#ifndef __XAO_INTEGERSTEP_HXX__
-#define __XAO_INTEGERSTEP_HXX__
-
-#include <vector>
-
-#include "Xao.hxx"
-#include "Step.hxx"
-
-namespace XAO
-{
- class IntegerStep : public Step
- {
- public:
- IntegerStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
-
- virtual const XAO::Type getType() { return XAO::INTEGER; }
-
- std::vector<int> getValues();
- std::vector<int> getElement(const int& element);
- std::vector<int> getComponent(const int& component);
-
- const int getValue(const int& element, const int& component);
-
- void setValues(const std::vector<int>& values);
- void setElements(const int& element, const std::vector<int>& elements);
- void setComponents(const int& element, const std::vector<int>& components);
- void setValue(const int& element, const int& component, const int& value);
-
- virtual const std::string getStringValue(const int& element, const int& component);
- virtual void setStringValue(const int& element, const int& component, const std::string& value);
-
- private:
- std::vector< std::vector<int> > m_values;
- };
-}
-
-
-#endif /* __XAO_INTEGERSTEP_HXX__ */
#
# header files
salomeinclude_HEADERS = \
- XaoUtils.hxx \
- GeometricElement.hxx \
- Xao.hxx \
- Geometry.hxx \
- BrepGeometry.hxx \
- Group.hxx \
- Field.hxx \
- BooleanField.hxx \
- IntegerField.hxx \
- DoubleField.hxx \
- StringField.hxx \
- Step.hxx \
- BooleanStep.hxx \
- IntegerStep.hxx \
- DoubleStep.hxx \
- StringStep.hxx \
- XaoExporter.hxx
+ XAO_XaoUtils.hxx \
+ XAO_GeometricElement.hxx \
+ XAO_Xao.hxx \
+ XAO_Geometry.hxx \
+ XAO_BrepGeometry.hxx \
+ XAO_Group.hxx \
+ XAO_Field.hxx \
+ XAO_BooleanField.hxx \
+ XAO_IntegerField.hxx \
+ XAO_DoubleField.hxx \
+ XAO_StringField.hxx \
+ XAO_Step.hxx \
+ XAO_BooleanStep.hxx \
+ XAO_IntegerStep.hxx \
+ XAO_DoubleStep.hxx \
+ XAO_StringStep.hxx \
+ XAO_XaoExporter.hxx
lib_LTLIBRARIES = libXAO.la
dist_libXAO_la_SOURCES = \
- XaoUtils.cxx \
- GeometricElement.cxx \
- Xao.cxx \
- Geometry.cxx \
- BrepGeometry.cxx \
- Group.cxx \
- Field.cxx \
- BooleanField.cxx \
- IntegerField.cxx \
- DoubleField.cxx \
- StringField.cxx \
- Step.cxx \
- BooleanStep.cxx \
- IntegerStep.cxx \
- DoubleStep.cxx \
- StringStep.cxx \
- XaoExporter.cxx
+ XAO_XaoUtils.cxx \
+ XAO_GeometricElement.cxx \
+ XAO_Xao.cxx \
+ XAO_Geometry.cxx \
+ XAO_BrepGeometry.cxx \
+ XAO_Group.cxx \
+ XAO_Field.cxx \
+ XAO_BooleanField.cxx \
+ XAO_IntegerField.cxx \
+ XAO_DoubleField.cxx \
+ XAO_StringField.cxx \
+ XAO_Step.cxx \
+ XAO_BooleanStep.cxx \
+ XAO_IntegerStep.cxx \
+ XAO_DoubleStep.cxx \
+ XAO_StringStep.cxx \
+ XAO_XaoExporter.cxx
libXAO_la_CPPFLAGS = \
$(GEOM_CXXFLAGS) \
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include <Utils_SALOME_Exception.hxx>
-
-#include "Xao.hxx"
-#include "XaoUtils.hxx"
-#include "Step.hxx"
-#include "BooleanStep.hxx"
-#include "IntegerStep.hxx"
-#include "DoubleStep.hxx"
-#include "StringStep.hxx"
-
-using namespace XAO;
-
-Step* Step::createStep(const XAO::Type& type, const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
-{
- if (type == XAO::BOOLEAN)
- return new BooleanStep(step, stamp, nbElements, nbComponents);
- if (type == XAO::INTEGER)
- return new IntegerStep(step, stamp, nbElements, nbComponents);
- if (type == XAO::DOUBLE)
- return new DoubleStep(step, stamp, nbElements, nbComponents);
- if (type == XAO::STRING)
- return new StringStep(step, stamp, nbElements, nbComponents);
-
- throw SALOME_Exception("Unknown Type");
-}
-
-void Step::checkElementIndex(const int& element)
-{
- if (element < m_nbElements && element >= 0)
- return;
-
- throw SALOME_Exception(MsgBuilder() << "Element index is out of range [0, "
- << m_nbElements-1 << "]: " << element);
-}
-
-void Step::checkComponentIndex(const int& component)
-{
- if (component < m_nbComponents && component >= 0)
- return;
-
- throw SALOME_Exception(MsgBuilder() << "Component index is out of range [0, "
- << m_nbComponents-1 << "]: " << component);
-}
-
-void Step::checkNbElements(const int& nbElements)
-{
- if (nbElements == m_nbElements)
- return;
-
- throw SALOME_Exception(MsgBuilder() << "Invalid number of elements: " << nbElements
- << ", expected " << m_nbElements);
-}
-
-void Step::checkNbComponents(const int& nbComponents)
-{
- if (nbComponents == m_nbComponents)
- return;
-
- throw SALOME_Exception(MsgBuilder() << "Invalid number of components: " << nbComponents
- << ", expected " << m_nbComponents);
-}
-
-void Step::checkNbValues(const int& nbValues)
-{
- if (nbValues == m_nbElements * m_nbComponents)
- return;
-
- throw SALOME_Exception(MsgBuilder() << "Invalid number of values:" << nbValues
- << ", expected " << m_nbElements * m_nbComponents);
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-
-#ifndef __XAO_STEP_HXX__
-#define __XAO_STEP_HXX__
-
-#include "Xao.hxx"
-
-namespace XAO
-{
- class Step
- {
- protected:
- /** Default constructor. */
- Step() {}
-
- public:
- /**
- * Creates a step.
- * @param type the type of the values for the step.
- * @param step the index of the step.
- * @param stamp the stamp of the step.
- * @param nbElements the number of elements in the step.
- * @param nbComponents the number of components in the step.
- * @return
- */
- static Step* createStep(const XAO::Type& type, const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
-
- /**
- * Destructor.
- */
- virtual ~Step() {}
-
- /**
- * Gets the type of the step.
- * @return
- */
- virtual const XAO::Type getType() = 0;
-
- /**
- * Gets the step index.
- * @return the index of the step.
- */
- const int getStep() { return m_step; }
-
- /**
- * Sets the number of the step.
- * @param step the index to set.
- */
- void setStep(const int& step) { m_step = step; }
-
- /**
- * Gets the stamp of the index.
- * @return the stamp of the index.
- */
- const int getStamp() { return m_stamp; }
-
- /**
- * Sets the stamp of the index.
- * @param stamp the stamp to set.
- */
- void setStamp(const int& stamp) { m_stamp = stamp; }
-
- /**
- * Gets the number of components of the step.
- * @return the number of components.
- */
- const int countComponents() { return m_nbComponents; }
-
- /**
- * Gets the number of elements for the step.
- * @return the number of elements.
- */
- const int countElements() { return m_nbElements; }
-
- /**
- * Gets the number of values for the step.
- * @return the number of values.
- */
- const int countValues() { return m_nbElements * m_nbComponents; }
-
- /**
- * Gets a value as a string.
- * @param element the index of the element.
- * @param component the index of the component.
- * @return the value as a string.
- */
- virtual const std::string getStringValue(const int& element, const int& component) = 0;
-
- /**
- * Sets a value as a string
- * @param element the index of the element.
- * @param component the index of the component.
- * @param value the string value.
- * @throw SALOME_Exception if the value is not valid.
- */
- virtual void setStringValue(const int& element, const int& component, const std::string& value) = 0;
-
- protected:
- void checkElementIndex(const int& element);
- void checkComponentIndex(const int& component);
-
- void checkNbElements(const int& nbElements);
- void checkNbComponents(const int& nbComponents);
- void checkNbValues(const int& nbValues);
-
- protected:
- /** the index of the step. */
- int m_step;
- /** The stamp of the step. */
- int m_stamp;
- /** The number of components. */
- int m_nbComponents;
- /** The number of elements. */
- int m_nbElements;
- };
-}
-
-
-#endif /* __XAO_STEP_HXX__ */
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include "StringField.hxx"
-#include "StringStep.hxx"
-#include "XaoUtils.hxx"
-
-#include <Utils_SALOME_Exception.hxx>
-
-using namespace XAO;
-
-StringField::StringField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents)
- : Field(name, dimension, nbElements, nbComponents)
-{
-}
-
-Step* StringField::addNewStep(const int& step)
-{
- return addStep(step, 0);
-}
-
-StringStep* StringField::addStep(const int& step)
-{
- return addStep(step, 0);
-}
-
-StringStep* StringField::addStep(const int& step, const int& stamp)
-{
- if (hasStep(step))
- throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
-
- StringStep* bstep = new StringStep(step, stamp, m_nbElements, m_nbComponents);
- m_steps.push_back(bstep);
- return bstep;
-}
-
-StringStep* StringField::getStep(const int& index)
-{
- checkStepIndex(index);
- return (StringStep*)m_steps[index];
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#ifndef __XAO_STRINGFIELD_HXX__
-#define __XAO_STRINGFIELD_HXX__
-
-#include <iostream>
-#include <string>
-#include <vector>
-#include <map>
-
-#include "Xao.hxx"
-#include "Field.hxx"
-#include "StringStep.hxx"
-
-namespace XAO
-{
- class StringField : public Field
- {
- public:
- StringField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
-
- virtual const XAO::Type getType() { return XAO::STRING; }
-
- virtual Step* addNewStep(const int& step);
- StringStep* addStep(const int& step);
- StringStep* addStep(const int& step, const int& stamp);
- StringStep* getStep(const int& index);
- };
-}
-
-#endif /* __XAO_STRINGFIELD_HXX__ */
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include "StringStep.hxx"
-#include <Utils_SALOME_Exception.hxx>
-
-using namespace XAO;
-
-StringStep::StringStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
-{
- m_nbElements = nbElements;
- m_nbComponents = nbComponents;
- m_step = step;
- m_stamp = stamp;
-
- m_values.reserve(m_nbElements);
- for (int i = 0; i < m_nbElements; ++i)
- {
- std::vector<std::string> row;
- row.reserve(m_nbComponents);
- for (int j = 0; j < m_nbComponents; ++j)
- row.push_back("");
- m_values.push_back(row);
- }
-}
-
-std::vector<std::string> StringStep::getValues()
-{
- std::vector<std::string> result;
- result.reserve(m_nbElements * m_nbComponents);
-
- std::vector< std::vector<std::string> >::iterator it;
- for (it = m_values.begin(); it != m_values.end(); ++it)
- {
- std::vector<std::string> eltValues = *it;
- result.insert(result.end(), eltValues.begin(), eltValues.end());
- }
-
- return result;
-}
-
-std::vector<std::string> StringStep::getElement(const int& element)
-{
- checkElementIndex(element);
-
- std::vector<std::string> result(m_values[element]);
- return result;
-}
-
-std::vector<std::string> StringStep::getComponent(const int& component)
-{
- checkComponentIndex(component);
-
- std::vector<std::string> result;
- result.reserve(m_nbElements);
-
- std::vector< std::vector<std::string> >::iterator it;
- for (it = m_values.begin(); it != m_values.end(); ++it)
- {
- std::vector<std::string> eltValues = *it;
- result.push_back(eltValues[component]);
- }
-
- return result;
-}
-
-const std::string StringStep::getValue(const int& element, const int& component)
-{
- checkElementIndex(element);
- checkComponentIndex(component);
-
- return m_values[element][component];
-}
-
-const std::string StringStep::getStringValue(const int& element, const int& component)
-{
- return getValue(element, component);
-}
-
-void StringStep::setValues(const std::vector<std::string>& values)
-{
- checkNbValues(values.size());
-
- for (int i = 0; i < m_nbElements; ++i)
- {
- for (int j = 0; j < m_nbComponents; ++j)
- {
- m_values[i][j] = values[i * m_nbComponents + j];
- }
- }
-}
-
-void StringStep::setElements(const int& element, const std::vector<std::string>& elements)
-{
- checkElementIndex(element);
- checkNbComponents(elements.size());
-
- for (int i = 0; i < m_nbComponents; ++i)
- m_values[element][i] = elements[i];
-}
-
-void StringStep::setComponents(const int& component, const std::vector<std::string>& components)
-{
- checkElementIndex(component);
- checkNbElements(components.size());
-
- for (int i = 0; i < m_nbElements; ++i)
- m_values[i][component] = components[i];
-}
-
-void StringStep::setValue(const int& element, const int& component, const std::string& value)
-{
- checkElementIndex(element);
- checkComponentIndex(component);
-
- m_values[element][component] = value;
-}
-
-void StringStep::setStringValue(const int& element, const int& component, const std::string& value)
-{
- setValue(element, component, value);
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-
-#ifndef __XAO_STRINGSTEP_HXX__
-#define __XAO_STRINGSTEP_HXX__
-
-#include <string>
-#include <vector>
-
-#include "Xao.hxx"
-#include "Step.hxx"
-
-namespace XAO
-{
- class StringStep : public Step
- {
- public:
- StringStep(const int& nbElements, const int& nbComponents);
- StringStep(const int& step, const int& nbElements, const int& nbComponents);
- StringStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
-
- virtual const XAO::Type getType() { return XAO::STRING; }
-
- std::vector<std::string> getValues();
- std::vector<std::string> getElement(const int& element);
- std::vector<std::string> getComponent(const int& component);
-
- const std::string getValue(const int& element, const int& component);
-
- void setValues(const std::vector<std::string>& values);
- void setElements(const int& element, const std::vector<std::string>& elements);
- void setComponents(const int& component, const std::vector<std::string>& components);
- void setValue(const int& element, const int& component, const std::string& value);
-
- virtual const std::string getStringValue(const int& element, const int& component);
- virtual void setStringValue(const int& element, const int& component, const std::string& value);
-
- private:
- std::vector< std::vector<std::string> > m_values;
- };
-}
-
-
-#endif /* __XAO_STRINGSTEP_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_BooleanField.hxx"
+#include "XAO_BooleanStep.hxx"
+#include "XAO_XaoUtils.hxx"
+
+using namespace XAO;
+
+BooleanField::BooleanField(const std::string& name, const XAO::Dimension& dimension,
+ const int& nbElements, const int& nbComponents)
+ : Field(name, dimension, nbElements, nbComponents)
+{
+}
+
+Step* BooleanField::addNewStep(const int& step)
+{
+ return addStep(step, 0);
+}
+
+BooleanStep* BooleanField::addStep(const int& step)
+{
+ return addStep(step, 0);
+}
+
+BooleanStep* BooleanField::addStep(const int& step, const int& stamp)
+{
+ if (hasStep(step))
+ throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
+
+ BooleanStep* bstep = new BooleanStep(step, stamp, m_nbElements, m_nbComponents);
+ m_steps.push_back(bstep);
+ return bstep;
+}
+
+BooleanStep* BooleanField::getStep(const int& index)
+{
+ checkStepIndex(index);
+ return (BooleanStep*)m_steps[index];
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#ifndef __XAO_BOOLEANFIELD_HXX__
+#define __XAO_BOOLEANFIELD_HXX__
+
+#include <string>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Field.hxx"
+#include "XAO_BooleanStep.hxx"
+
+namespace XAO
+{
+ class BooleanField : public Field
+ {
+ public:
+ BooleanField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
+
+ virtual const XAO::Type getType() { return XAO::BOOLEAN; }
+
+ virtual Step* addNewStep(const int& step);
+ BooleanStep* addStep(const int& step);
+ BooleanStep* addStep(const int& step, const int& stamp);
+ BooleanStep* getStep(const int& index);
+ };
+}
+
+#endif /* __XAO_BOOLEANFIELD_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_BooleanStep.hxx"
+#include "XAO_XaoUtils.hxx"
+
+using namespace XAO;
+
+BooleanStep::BooleanStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
+{
+ m_nbElements = nbElements;
+ m_nbComponents = nbComponents;
+ m_step = step;
+ m_stamp = stamp;
+
+ m_values.reserve(m_nbElements);
+ for (int i = 0; i < m_nbElements; ++i)
+ {
+ std::vector<bool> row;
+ row.reserve(m_nbComponents);
+ for (int j = 0; j < m_nbComponents; ++j)
+ row.push_back(false);
+ m_values.push_back(row);
+ }
+}
+
+std::vector<bool> BooleanStep::getValues()
+{
+ std::vector<bool> result;
+ result.reserve(m_nbElements * m_nbComponents);
+
+ std::vector< std::vector<bool> >::iterator it;
+ for (it = m_values.begin(); it != m_values.end(); ++it)
+ {
+ std::vector<bool> eltValues = *it;
+ result.insert(result.end(), eltValues.begin(), eltValues.end());
+ }
+
+ return result;
+}
+
+std::vector<bool> BooleanStep::getElement(const int& element)
+{
+ checkElementIndex(element);
+
+ std::vector<bool> result(m_values[element]);
+ return result;
+}
+
+std::vector<bool> BooleanStep::getComponent(const int& component)
+{
+ checkComponentIndex(component);
+
+ std::vector<bool> result;
+ result.reserve(m_nbElements);
+
+ std::vector< std::vector<bool> >::iterator it;
+ for (it = m_values.begin(); it != m_values.end(); ++it)
+ {
+ std::vector<bool> eltValues = *it;
+ result.push_back(eltValues[component]);
+ }
+
+ return result;
+}
+
+const bool BooleanStep::getValue(const int& element, const int& component)
+{
+ checkElementIndex(element);
+ checkComponentIndex(component);
+
+ return m_values[element][component];
+}
+
+const std::string BooleanStep::getStringValue(const int& element, const int& component)
+{
+ return XaoUtils::booleanToString(getValue(element, component));
+}
+
+void BooleanStep::setValues(const std::vector<bool>& values)
+{
+ checkNbValues((int)values.size());
+
+ for (int i = 0; i < m_nbElements; ++i)
+ {
+ for (int j = 0; j < m_nbComponents; ++j)
+ {
+ m_values[i][j] = values[i * m_nbComponents + j];
+ }
+ }
+}
+
+void BooleanStep::setElements(const int& element, const std::vector<bool>& elements)
+{
+ checkElementIndex(element);
+ checkNbComponents(elements.size());
+
+ for (int i = 0; i < m_nbComponents; ++i)
+ m_values[element][i] = elements[i];
+}
+
+void BooleanStep::setComponents(const int& component, const std::vector<bool>& components)
+{
+ checkComponentIndex(component);
+ checkNbElements(components.size());
+
+ for (int i = 0; i < m_nbElements; ++i)
+ m_values[i][component] = components[i];
+}
+
+void BooleanStep::setValue(const int& element, const int& component, const bool& value)
+{
+ checkElementIndex(element);
+ checkComponentIndex(component);
+
+ m_values[element][component] = value;
+}
+
+void BooleanStep::setStringValue(const int& element, const int& component, const std::string& value)
+{
+ setValue(element, component, XaoUtils::stringToBoolean(value));
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+
+#ifndef __XAO_BOOLEANSTEP_HXX__
+#define __XAO_BOOLEANSTEP_HXX__
+
+#include <vector>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Step.hxx"
+
+namespace XAO
+{
+ class BooleanStep : public Step
+ {
+ public:
+ BooleanStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
+
+ virtual const XAO::Type getType() { return XAO::BOOLEAN; }
+
+ /**
+ * Gets all the values in a vector by elements and by components.
+ * @return a vector containing all the values.
+ */
+ std::vector<bool> getValues();
+
+ /**
+ * Gets all the values for an element.
+ * @param element the index of the element to get.
+ * @return a vector containing all the values for the given element.
+ */
+ std::vector<bool> getElement(const int& element);
+
+ /**
+ * Gets all the values for a component.
+ * @param component the index of the component to get.
+ * @return a vector containing all the values for the given component.
+ */
+ std::vector<bool> getComponent(const int& component);
+
+ /**
+ * Gets a value for an element and a component.
+ * @param element the index of the element.
+ * @param component the index of the component.
+ * @return the value.
+ */
+ const bool getValue(const int& element, const int& component);
+
+ void setValues(const std::vector<bool>& values);
+ void setElements(const int& element, const std::vector<bool>& elements);
+ void setComponents(const int& component, const std::vector<bool>& components);
+ void setValue(const int& element, const int& component, const bool& value);
+
+ virtual const std::string getStringValue(const int& element, const int& component);
+ virtual void setStringValue(const int& element, const int& component, const std::string& value);
+
+ private:
+ std::vector< std::vector<bool> > m_values;
+ };
+}
+
+
+#endif /* __XAO_BOOLEANSTEP_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <cassert>
+
+#include <Standard_TypeMismatch.hxx>
+
+#include <BRepTools.hxx>
+#include <BRep_Builder.hxx>
+#include <TopAbs.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <GProp_GProps.hxx>
+#include <BRepGProp.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Vertex.hxx>
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_BrepGeometry.hxx"
+#include "XAO_XaoUtils.hxx"
+
+using namespace XAO;
+
+BrepGeometry::BrepGeometry() : Geometry("")
+{
+}
+
+BrepGeometry::BrepGeometry(const std::string& name) : Geometry(name)
+{
+}
+
+const std::string BrepGeometry::getShape()
+{
+ std::ostringstream streamShape;
+ BRepTools::Write(m_shape, streamShape);
+ std::string data = streamShape.str();
+ char* res = new char[data.size()];
+ strcpy(res, data.c_str());
+ return res;
+}
+
+void BrepGeometry::setShape(const std::string& shape)
+{
+ std::istringstream streamBrep(shape.c_str());
+ BRep_Builder builder;
+ BRepTools::Read(m_shape, streamBrep, builder);
+
+ initIds();
+}
+
+TopoDS_Shape BrepGeometry::getTopoDS_Shape()
+{
+ return m_shape;
+}
+
+void BrepGeometry::setTopoDS_Shape(const TopoDS_Shape& shape)
+{
+ m_shape = shape;
+ initIds();
+}
+
+void BrepGeometry::initIds()
+{
+ // intialization of Ids
+ initListIds(TopAbs_VERTEX, m_vertices);
+ initListIds(TopAbs_EDGE, m_edges);
+ initListIds(TopAbs_FACE, m_faces);
+ initListIds(TopAbs_SOLID, m_solids);
+}
+
+void BrepGeometry::initListIds(const TopAbs_ShapeEnum& shapeType, GeometricElementList& eltList)
+{
+ TopTools_MapOfShape mapShape;
+ TopTools_ListOfShape listShape;
+
+ TopExp_Explorer exp(m_shape, shapeType);
+ for (; exp.More(); exp.Next())
+ {
+ if (mapShape.Add(exp.Current()))
+ listShape.Append(exp.Current());
+ }
+
+ if (listShape.IsEmpty())
+ return;
+
+ TopTools_IndexedMapOfShape indices;
+ TopExp::MapShapes(m_shape, indices);
+
+ std::list<int> indexList;
+ TopTools_ListIteratorOfListOfShape itSub(listShape);
+ for (int index = 1; itSub.More(); itSub.Next(), ++index)
+ {
+ TopoDS_Shape value = itSub.Value();
+ indexList.push_back(indices.FindIndex(value));
+ }
+
+ std::list<int>::iterator it = indexList.begin();
+
+ eltList.setSize(indexList.size());
+ for (int i = 0; it != indexList.end(); it++, i++)
+ eltList.setReference(i, XaoUtils::intToString((*it)));
+}
+
+TopoDS_Shape BrepGeometry::getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex)
+{
+ TopTools_MapOfShape mapShape;
+ TopTools_ListOfShape listShape;
+
+ TopExp_Explorer exp(mainShape, shapeType);
+ for (; exp.More(); exp.Next())
+ {
+ if (mapShape.Add(exp.Current()))
+ listShape.Append(exp.Current());
+ }
+
+ if (!listShape.IsEmpty())
+ {
+ // use main shape indices
+ TopTools_IndexedMapOfShape indices;
+ TopExp::MapShapes(mainShape, indices);
+
+ TopTools_ListIteratorOfListOfShape itSub(listShape);
+ for (int index = 1; itSub.More(); itSub.Next(), ++index)
+ {
+ if (shapeIndex + 1 == index)
+ {
+ TopoDS_Shape value = itSub.Value();
+ return value;
+ }
+ }
+ }
+
+ throw SALOME_Exception(MsgBuilder() << "Shape with reference [" << shapeIndex << "] not found.");
+}
+
+// -----------------------------
+const int BrepGeometry::countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType)
+{
+ int res = 0;
+ TopTools_MapOfShape mapShape;
+ TopExp_Explorer exp(shape, shapeType);
+ for (; exp.More(); exp.Next())
+ {
+// if (mapShape.Add(exp.Current()))
+ res++;
+ }
+
+ return res;
+}
+
+std::vector<int> BrepGeometry::getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim)
+{
+ std::vector<int> indexList;
+
+ TopTools_MapOfShape mapShape;
+ TopTools_ListOfShape listShape;
+
+ TopExp_Explorer exp(shape, shapeType);
+ for (; exp.More(); exp.Next())
+ {
+ if (mapShape.Add(exp.Current()))
+ listShape.Append(exp.Current());
+ }
+
+ if (!listShape.IsEmpty())
+ {
+ // use the shape of the geometry for the indices
+ TopTools_IndexedMapOfShape indices;
+ TopExp::MapShapes(m_shape, indices);
+
+ TopTools_ListIteratorOfListOfShape itSub(listShape);
+ for (int index = 1; itSub.More(); itSub.Next(), ++index)
+ {
+ TopoDS_Shape value = itSub.Value();
+ int id = indices.FindIndex(value);
+ indexList.push_back(findElement(dim, id));
+ }
+ }
+
+ return indexList;
+}
+
+void BrepGeometry::getEdgeVertices(const int& edgeIndex, int& vertexA, int& vertexB)
+{
+ TopoDS_Shape edge = getSubShape(m_shape, TopAbs_EDGE, edgeIndex);
+ std::vector<int> vertices = getGeometricalElements(edge, TopAbs_VERTEX, XAO::VERTEX);
+ assert(vertices.size() == 2);
+
+ vertexA = vertices[0];
+ vertexB = vertices[1];
+}
+
+const int BrepGeometry::countFaceWires(const int& faceIndex)
+{
+ TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
+ return countGeometricalElements(face, TopAbs_WIRE);
+}
+
+std::vector<int> BrepGeometry::getFaceEdges(const int& faceIndex, const int& wireIndex)
+{
+ // get the face
+ TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
+ // get the wire
+ TopoDS_Shape wire = getSubShape(face, TopAbs_WIRE, wireIndex);
+ return getGeometricalElements(wire, TopAbs_EDGE, XAO::EDGE);
+}
+
+const int BrepGeometry::countSolidShells(const int& solidIndex)
+{
+ TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
+ return countGeometricalElements(solid, TopAbs_SHELL);
+}
+
+std::vector<int> BrepGeometry::getSolidFaces(const int& solidIndex, const int& shellIndex)
+{
+ TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
+ TopoDS_Shape shell = getSubShape(solid, TopAbs_SHELL, shellIndex);
+ return getGeometricalElements(shell, TopAbs_FACE, XAO::FACE);
+}
+
+void BrepGeometry::getVertexXYZ(const int& vertexIndex, double& xCoord, double& yCoord, double& zCoord)
+{
+ xCoord = 0.;
+ yCoord = 0.;
+ zCoord = 0.;
+
+ TopoDS_Shape vertex = getSubShape(m_shape, TopAbs_VERTEX, vertexIndex);
+ if (vertex.ShapeType() != TopAbs_VERTEX)
+ throw SALOME_Exception(MsgBuilder() << "Shape " << vertexIndex<< " is not a point.");
+
+ TopoDS_Vertex point = TopoDS::Vertex(vertex);
+ if (!point.IsNull())
+ {
+ gp_Pnt aPnt = BRep_Tool::Pnt(point);
+ xCoord = aPnt.X();
+ yCoord = aPnt.Y();
+ zCoord = aPnt.Z();
+ }
+}
+
+// -----------------------------
+const double BrepGeometry::getEdgeLength(const int& edgeIndex)
+{
+ TopoDS_Shape edge = getSubShape(m_shape, TopAbs_EDGE, edgeIndex);
+ GProp_GProps system;
+ BRepGProp::LinearProperties(edge, system);
+ return system.Mass();
+}
+
+const double BrepGeometry::getFaceArea(const int& faceIndex)
+{
+ TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
+ GProp_GProps system;
+ BRepGProp::SurfaceProperties(face, system);
+ return system.Mass();
+}
+
+const double BrepGeometry::getSolidVolume(const int& solidIndex)
+{
+ TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
+ GProp_GProps system;
+ BRepGProp::VolumeProperties(solid, system);
+ return system.Mass();
+}
+
+// -----------------------------
+const int BrepGeometry::getVertexID(const int& index)
+{
+ return XaoUtils::stringToInt(getVertexReference(index));
+}
+
+const int BrepGeometry::getEdgeID(const int& index)
+{
+ return XaoUtils::stringToInt(getEdgeReference(index));
+}
+
+const int BrepGeometry::getFaceID(const int& index)
+{
+ return XaoUtils::stringToInt(getFaceReference(index));
+}
+
+const int BrepGeometry::getSolidID(const int& index)
+{
+ return XaoUtils::stringToInt(getSolidReference(index));
+}
+
+// -----------------------------
+void BrepGeometry::setVertexID(const int& index, const int& id)
+{
+ setVertexReference(index, XaoUtils::intToString(id));
+}
+
+void BrepGeometry::setEdgeID(const int& index, const int& id)
+{
+ setEdgeReference(index, XaoUtils::intToString(id));
+}
+
+void BrepGeometry::setFaceID(const int& index, const int& id)
+{
+ setEdgeReference(index, XaoUtils::intToString(id));
+}
+
+void BrepGeometry::setSolidID(const int& index, const int& id)
+{
+ setEdgeReference(index, XaoUtils::intToString(id));
+}
+
+// -----------------------------
+const int BrepGeometry::findElement(const XAO::Dimension& dim, const int& id)
+{
+ if (dim == XAO::VERTEX)
+ return findVertex(id);
+ if (dim == XAO::EDGE)
+ return findEdge(id);
+ if (dim == XAO::FACE)
+ return findFace(id);
+ if (dim == XAO::SOLID)
+ return findSolid(id);
+ throw SALOME_Exception(MsgBuilder() << "Unknown Dimension: " << dim);
+}
+
+const int BrepGeometry::findVertex(const int& id)
+{
+ return getVertexIndexByReference(XaoUtils::intToString(id));
+}
+
+const int BrepGeometry::findEdge(const int& id)
+{
+ return getEdgeIndexByReference(XaoUtils::intToString(id));
+}
+
+const int BrepGeometry::findFace(const int& id)
+{
+ return getFaceIndexByReference(XaoUtils::intToString(id));
+}
+
+const int BrepGeometry::findSolid(const int& id)
+{
+ return getSolidIndexByReference(XaoUtils::intToString(id));
+}
+
+// -----------------------------
+const std::string BrepGeometry::findVertexName(const int& id)
+{
+ return getVertexName(findVertex(id));
+}
+
+const std::string BrepGeometry::findEdgeName(const int& id)
+{
+ return getEdgeName(findEdge(id));
+}
+
+const std::string BrepGeometry::findFaceName(const int& id)
+{
+ return getFaceName(findFace(id));
+}
+
+const std::string BrepGeometry::findSolidName(const int& id)
+{
+ return getSolidName(findSolid(id));
+}
+
+// -----------------------------
+void BrepGeometry::changeVertexName(const int& id, const std::string& name)
+{
+ setVertexName(findVertex(id), name);
+}
+
+void BrepGeometry::changeEdgeName(const int& id, const std::string& name)
+{
+ setEdgeName(findEdge(id), name);
+}
+
+void BrepGeometry::changeFaceName(const int& id, const std::string& name)
+{
+ setFaceName(findFace(id), name);
+}
+
+void BrepGeometry::changeSolidName(const int& id, const std::string& name)
+{
+ setSolidName(findSolid(id), name);
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#ifndef __XAO_BREPGEOMETRY_HXX__
+#define __XAO_BREPGEOMETRY_HXX__
+
+#include <string>
+#include <vector>
+
+#include <TopoDS_Shape.hxx>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Geometry.hxx"
+
+namespace XAO
+{
+ class BrepGeometry : public Geometry
+ {
+ public:
+ BrepGeometry();
+ BrepGeometry(const std::string& name);
+
+ virtual const XAO::Format getFormat() { return XAO::BREP; }
+
+ virtual const std::string getShape();
+ virtual void setShape(const std::string& shape);
+
+ TopoDS_Shape getTopoDS_Shape();
+ void setTopoDS_Shape(const TopoDS_Shape& shape);
+
+ /**
+ * Gives the two extrimities of an edge.
+ * @param edgeIndex the index of the edge.
+ * @param vertexA
+ * @param vertexB
+ */
+ void getEdgeVertices(const int& edgeIndex, int& vertexA, int& vertexB);
+
+ /**
+ * Gets the number of wires of a face (including holes).
+ * @param faceIndex the index of the face.
+ * @return the number of wires.
+ */
+ const int countFaceWires(const int& faceIndex);
+
+ /**
+ * Gets the indices of the wires of the face.
+ * @param faceIndex the index of the face.
+ * @param wireIndex the index of the wire.
+ * @return the list of wires for the given face.
+ */
+ std::vector<int> getFaceEdges(const int& faceIndex, const int& wireIndex);
+
+ /**
+ * Gets the number of shells of a solid (including cavities).
+ * @param solidIndex the index of the solid.
+ * @return the number of shells.
+ */
+ const int countSolidShells(const int& solidIndex);
+
+ /**
+ * Gets the indices of the shells of the solids.
+ * @param solidIndex the index of the solid.
+ * @param shellIndex the index of the shell (for the given solid).
+ * @return the list of shells for the given solid.
+ */
+ std::vector<int> getSolidFaces(const int& solidIndex, const int& shellIndex);
+
+ /**
+ * Gets the coordinates of a vertex.
+ * @param vertexIndex the index of the vertex.
+ * @param xCoord the X coordinate.
+ * @param yCoord the Y coordinate.
+ * @param zCoord the Z coordinate.
+ */
+ void getVertexXYZ(const int& vertexIndex, double& xCoord, double& yCoord, double& zCoord);
+
+ /**
+ * Gets the length of an edge.
+ * @param edge the index of the edge.
+ * @return the length of the edge.
+ */
+ const double getEdgeLength(const int& index);
+
+ /**
+ * Gets the are of a face.
+ * @param face the index of a face.
+ * @return the area of the face.
+ */
+ const double getFaceArea(const int& index);
+
+ /**
+ * Gets the volume of a solid.
+ * @param solid the index of the solid.
+ * @return the volume of the solid.
+ */
+ const double getSolidVolume(const int& index);
+
+ /**
+ * Gets the ID of a vertex.
+ * @param vertex the index of the vertex.
+ * @return the ID of the vertex.
+ */
+ const int getVertexID(const int& index);
+
+ /**
+ * Gets the ID of an edge.
+ * @param edge the index of the edge.
+ * @return the ID of the edge.
+ */
+ const int getEdgeID(const int& index);
+
+ /**
+ * Gets the ID of a face.
+ * @param face the index of the face.
+ * @return the ID of the face.
+ */
+ const int getFaceID(const int& index);
+
+ /**
+ * Gets the ID of a solid.
+ * @param solid the index of the solid.
+ * @return the ID of the solid.
+ */
+ const int getSolidID(const int& solid);
+
+ void setVertexID(const int& index, const int& id);
+ void setEdgeID(const int& index, const int& id);
+ void setFaceID(const int& index, const int& id);
+ void setSolidID(const int& index, const int& id);
+
+ const int findElement(const XAO::Dimension& dim, const int& id);
+
+ /**
+ * Finds a vertex with its ID.
+ * @param id the ID of the vertex.
+ * @return the index of the vertex.
+ */
+ const int findVertex(const int& id);
+
+ /**
+ * Finds an edge with its ID.
+ * @param id the ID of the edge.
+ * @return the index of the edge.
+ */
+ const int findEdge(const int& id);
+
+ /**
+ * Finds a face with its ID.
+ * @param id the ID of the face.
+ * @return the index of the face.
+ */
+ const int findFace(const int& id);
+
+ /**
+ * Finds a solid with its ID.
+ * @param id the ID of the solid.
+ * @return th index of the solid.
+ */
+ const int findSolid(const int& id);
+
+ /**
+ * Finds the name of a vertex with its ID.
+ * @param id the ID of the vertex.
+ * @return the name of the vertex.
+ */
+ const std::string findVertexName(const int& id);
+
+ /**
+ * Finds the name of an edge with its ID.
+ * @param id the ID of the edge.
+ * @return the name of the edge.
+ */
+ const std::string findEdgeName(const int& id);
+
+ /**
+ * Finds the name of a face with its ID.
+ * @param id the ID of the face.
+ * @return the name of the face.
+ */
+ const std::string findFaceName(const int& id);
+
+ /**
+ * Finds the name of a solid with its ID.
+ * @param id the ID of the solid.
+ * @return the name of the solid.
+ */
+ const std::string findSolidName(const int& id);
+
+ /**
+ * Changes the name of a vertex.
+ * @param id the ID of the vertex.
+ * @param name the name to set.
+ */
+ void changeVertexName(const int& id, const std::string& name);
+
+ /**
+ * Changes the name of an edge.
+ * @param id the ID of the edge
+ * @param name the name to set.
+ */
+ void changeEdgeName(const int& id, const std::string& name);
+
+ /**
+ * Changes the name of a face.
+ * @param id the ID of the face.
+ * @param name the name to set.
+ */
+ void changeFaceName(const int& id, const std::string& name);
+
+ /**
+ * Changes the name of a solid.
+ * @param id the ID of the solid.
+ * @param name the name to set.
+ */
+ void changeSolidName(const int& id, const std::string& name);
+
+ private:
+ void initIds();
+ void initListIds(const TopAbs_ShapeEnum& shapeType, GeometricElementList& eltList);
+ TopoDS_Shape getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex);
+ const int countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType);
+ std::vector<int> getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim);
+
+ private:
+ TopoDS_Shape m_shape;
+ };
+}
+
+#endif // __XAO_BREPGEOMETRY_HXX__
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_DoubleField.hxx"
+#include "XAO_DoubleStep.hxx"
+#include "XAO_XaoUtils.hxx"
+
+using namespace XAO;
+
+DoubleField::DoubleField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents)
+ : Field(name, dimension, nbElements, nbComponents)
+{
+}
+
+Step* DoubleField::addNewStep(const int& step)
+{
+ return addStep(step, 0);
+}
+
+DoubleStep* DoubleField::addStep(const int& step)
+{
+ return addStep(step, 0);
+}
+
+DoubleStep* DoubleField::addStep(const int& step, const int& stamp)
+{
+ if (hasStep(step))
+ throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
+
+ DoubleStep* bstep = new DoubleStep(step, stamp, m_nbElements, m_nbComponents);
+ m_steps.push_back(bstep);
+ return bstep;
+}
+
+DoubleStep* DoubleField::getStep(const int& index)
+{
+ checkStepIndex(index);
+ return (DoubleStep*)m_steps[index];
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#ifndef __XAO_DOUBLEFIELD_HXX__
+#define __XAO_DOUBLEFIELD_HXX__
+
+#include <string>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Field.hxx"
+#include "XAO_DoubleStep.hxx"
+
+namespace XAO
+{
+ class DoubleField : public Field
+ {
+ public:
+ DoubleField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
+
+ virtual const XAO::Type getType() { return XAO::DOUBLE; }
+
+ virtual Step* addNewStep(const int& step);
+ DoubleStep* addStep(const int& step);
+ DoubleStep* addStep(const int& step, const int& stamp);
+ DoubleStep* getStep(const int& index);
+ };
+}
+
+#endif /* __XAO_DOUBLEFIELD_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_DoubleStep.hxx"
+#include "XAO_XaoUtils.hxx"
+
+using namespace XAO;
+
+DoubleStep::DoubleStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
+{
+ m_nbElements = nbElements;
+ m_nbComponents = nbComponents;
+ m_step = step;
+ m_stamp = stamp;
+
+ m_values.reserve(m_nbElements);
+ for (int i = 0; i < m_nbElements; ++i)
+ {
+ std::vector<double> row;
+ row.reserve(m_nbComponents);
+ for (int j = 0; j < m_nbComponents; ++j)
+ row.push_back(0);
+ m_values.push_back(row);
+ }
+}
+
+std::vector<double> DoubleStep::getValues()
+{
+ std::vector<double> result;
+ result.reserve(m_nbElements * m_nbComponents);
+
+ std::vector< std::vector<double> >::iterator it;
+ for (it = m_values.begin(); it != m_values.end(); ++it)
+ {
+ std::vector<double> eltValues = *it;
+ result.insert(result.end(), eltValues.begin(), eltValues.end());
+ }
+
+ return result;
+}
+
+std::vector<double> DoubleStep::getElement(const int& element)
+{
+ checkElementIndex(element);
+
+ std::vector<double> result(m_values[element]);
+ return result;
+}
+
+std::vector<double> DoubleStep::getComponent(const int& component)
+{
+ checkComponentIndex(component);
+
+ std::vector<double> result;
+ result.reserve(m_nbElements);
+
+ std::vector< std::vector<double> >::iterator it;
+ for (it = m_values.begin(); it != m_values.end(); ++it)
+ {
+ std::vector<double> eltValues = *it;
+ result.push_back(eltValues[component]);
+ }
+
+ return result;
+}
+
+const double DoubleStep::getValue(const int& element, const int& component)
+{
+ checkElementIndex(element);
+ checkComponentIndex(component);
+
+ return m_values[element][component];
+}
+
+const std::string DoubleStep::getStringValue(const int& element, const int& component)
+{
+ return XaoUtils::doubleToString(getValue(element, component));
+}
+
+void DoubleStep::setValues(const std::vector<double>& values)
+{
+ checkNbValues(values.size());
+
+ for (int i = 0; i < m_nbElements; ++i)
+ {
+ for (int j = 0; j < m_nbComponents; ++j)
+ {
+ m_values[i][j] = values[i * m_nbComponents + j];
+ }
+ }
+}
+
+void DoubleStep::setElements(const int& element, const std::vector<double>& elements)
+{
+ checkElementIndex(element);
+ checkNbComponents(elements.size());
+
+ for (int i = 0; i < m_nbComponents; ++i)
+ m_values[element][i] = elements[i];
+}
+
+void DoubleStep::setComponents(const int& component, const std::vector<double>& components)
+{
+ checkElementIndex(component);
+ checkNbElements(components.size());
+
+ for (int i = 0; i < m_nbElements; ++i)
+ m_values[i][component] = components[i];
+}
+
+void DoubleStep::setValue(const int& element, const int& component, const double& value)
+{
+ checkElementIndex(element);
+ checkComponentIndex(component);
+
+ m_values[element][component] = value;
+}
+
+void DoubleStep::setStringValue(const int& element, const int& component, const std::string& value)
+{
+ setValue(element, component, XaoUtils::stringToDouble(value));
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+
+#ifndef __XAO_DOUBLESTEP_HXX__
+#define __XAO_DOUBLESTEP_HXX__
+
+#include <vector>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Step.hxx"
+
+namespace XAO
+{
+ class DoubleStep : public Step
+ {
+ public:
+ DoubleStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
+
+ virtual const XAO::Type getType() { return XAO::DOUBLE; }
+
+ std::vector<double> getValues();
+ std::vector<double> getElement(const int& element);
+ std::vector<double> getComponent(const int& component);
+
+ const double getValue(const int& element, const int& component);
+
+ void setValues(const std::vector<double>& values);
+ void setElements(const int& element, const std::vector<double>& elements);
+ void setComponents(const int& component, const std::vector<double>& components);
+ void setValue(const int& element, const int& component, const double& value);
+
+ virtual const std::string getStringValue(const int& element, const int& component);
+ virtual void setStringValue(const int& element, const int& component, const std::string& value);
+
+ private:
+ std::vector< std::vector<double> > m_values;
+ };
+}
+
+
+#endif /* __XAO_DOUBLESTEP_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <string>
+#include <iostream>
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Field.hxx"
+#include "XAO_BooleanField.hxx"
+#include "XAO_IntegerField.hxx"
+#include "XAO_DoubleField.hxx"
+#include "XAO_StringField.hxx"
+#include "XAO_XaoUtils.hxx"
+
+using namespace XAO;
+
+// -------------------------------------------------------
+
+Field::Field(const std::string& name, const XAO::Dimension& dimension,
+ const int& nbElements, const int& nbComponents)
+ : m_name(name), m_dimension(dimension), m_nbElements(nbElements), m_nbComponents(nbComponents)
+{
+ m_components.reserve(nbComponents);
+ for (int i = 0; i < nbComponents; ++i)
+ m_components.push_back("");
+}
+
+Field::~Field()
+{
+ for (int i = 0; i < m_steps.size(); ++i)
+ delete m_steps[i];
+}
+
+Field* Field::createField(const XAO::Type& type, const XAO::Dimension& dimension,
+ const int& nbElements, const int& nbComponents)
+{
+ return createField(type, "", dimension, nbElements, nbComponents);
+}
+
+Field* Field::createField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dimension,
+ const int& nbElements, const int& nbComponents)
+{
+ if (type == XAO::BOOLEAN)
+ return new BooleanField(name, dimension, nbElements, nbComponents);
+ if (type == XAO::INTEGER)
+ return new IntegerField(name, dimension, nbElements, nbComponents);
+ if (type == XAO::DOUBLE)
+ return new DoubleField(name, dimension, nbElements, nbComponents);
+ if (type == XAO::STRING)
+ return new StringField(name, dimension, nbElements, nbComponents);
+
+ throw SALOME_Exception(MsgBuilder() << "Bad Type: " << type);
+}
+
+const std::string Field::getComponentName(const int& index)
+{
+ checkComponent(index);
+ return m_components[index];
+}
+
+void Field::setComponentName(const int& index, const std::string& name)
+{
+ checkComponent(index);
+ m_components[index] = name;
+}
+
+bool Field::removeStep(Step* step)
+{
+ std::vector<Step*>::iterator it = m_steps.begin();
+ for (; it != m_steps.end(); ++it)
+ {
+ Step* current = *it;
+ if (step == current)
+ {
+ m_steps.erase(it);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool Field::hasStep(const int& step)
+{
+ std::vector<Step*>::iterator it = m_steps.begin();
+ for (; it != m_steps.end(); ++it)
+ {
+ Step* current = *it;
+ if (current->getStep() == step)
+ return true;
+ }
+
+ return false;
+}
+
+void Field::checkComponent(const int& component)
+{
+ if (component < m_nbComponents && component >= 0)
+ return;
+
+ throw SALOME_Exception(MsgBuilder() << "Step index is out of range [0, "
+ << m_nbComponents << "]: " << component);
+}
+
+void Field::checkStepIndex(const int& step)
+{
+ if (step < m_steps.size() && step >= 0)
+ return;
+
+ throw SALOME_Exception(MsgBuilder() << "Step index is out of range [0, "
+ << m_steps.size() << "]: " << step);
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#ifndef __XAO_FIELD_HXX__
+#define __XAO_FIELD_HXX__
+
+#include <string>
+#include <vector>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Step.hxx"
+
+namespace XAO
+{
+ typedef std::vector<Step*>::iterator stepIterator;
+
+ /**
+ * @class Field
+ * A geometrical Field.
+ */
+ class Field
+ {
+ protected:
+ /**
+ * Constructor.
+ * @param name the name of the field.
+ * @param dimension the dimension ot the field.
+ * @param nbElements the number of elements.
+ * @param nbComponents the number of components.
+ */
+ Field(const std::string& name, const XAO::Dimension& dimension,
+ const int& nbElements, const int& nbComponents);
+
+ public:
+ /**
+ * Creates a Field of the given type.
+ * @param type the type of the field to create.
+ * @param dimension the dimension.
+ * @param nbElements the number of geometrical elements.
+ * @param nbComponents the number of components.
+ * @return the created field.
+ */
+ static Field* createField(const XAO::Type& type, const XAO::Dimension& dimension,
+ const int& nbElements, const int& nbComponents);
+
+ /**
+ /**
+ * Creates a Field of the given type.
+ * @param type the type of the field to create.
+ * @name the name of the field.
+ * @param dimension the dimension.
+ * @param nbElements the number of geometrical elements.
+ * @param nbComponents the number of components.
+ * @return the created field.
+ */
+ static Field* createField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dimension,
+ const int& nbElements, const int& nbComponents);
+
+ /**
+ * Destructor.
+ */
+ virtual ~Field();
+
+ /**
+ * Gets the Type of the field.
+ * @return the Type of the field.
+ */
+ virtual const XAO::Type getType() = 0;
+
+ /**
+ * Gets the name of the Field.
+ * @return the name of the Field.
+ */
+ const std::string getName() const
+ {
+ return m_name;
+ }
+
+ /**
+ * Sets the name of the Field.
+ * @param name the name to set.
+ */
+ void setName(const std::string& name)
+ {
+ m_name = name;
+ }
+
+ /**
+ * Gets the Dimension of the Field.
+ * @return the Dimension of the Field.
+ */
+ const XAO::Dimension getDimension() const
+ {
+ return m_dimension;
+ }
+
+ /**
+ * Gets the number of elements of each step.
+ * @return the number of elements of each step.
+ */
+ const int countElements() const
+ {
+ return m_nbElements;
+ }
+
+ /**
+ * Gets the number of components.
+ * @return the number of components.
+ */
+ const int countComponents() const
+ {
+ return m_nbComponents;
+ }
+
+ /**
+ * Gets the number of values for each step.
+ * @return the number of values for each step.
+ */
+ const int countValues() const
+ {
+ return m_nbElements * m_nbComponents;
+ }
+
+ /**
+ * Gets the number of the steps.
+ * @return the number of steps.
+ */
+ const int countSteps() const { return m_steps.size(); }
+
+ /**
+ * Gets the name of a component.
+ * @param index the index of the component to get.
+ * @return the name of the component for the given index.
+ */
+ const std::string getComponentName(const int& index);
+
+ /**
+ * Sets the name of a component.
+ * @param componentIndex the index of the component to set.
+ * @param name the name to set.
+ */
+ void setComponentName(const int& componentIndex, const std::string& name);
+
+ /**
+ * Adds a new step of the same type than the field.
+ * @param number the numer of the step.
+ * @return the new create step.
+ */
+ virtual Step* addNewStep(const int& number) = 0;
+
+ /**
+ * Remove a step.
+ * @param step the step to remove.
+ * @return true if the step has been removed, false otherwise.
+ */
+ bool removeStep(Step* step);
+
+ /**
+ * Verifies if the field has a step with the given step number.
+ * @param step the step number.
+ * @return true if the field has a step for the given number.
+ */
+ bool hasStep(const int& step);
+
+ /**
+ * Returns the first step.
+ * @return an iterator on the first step.
+ */
+ stepIterator begin() { return m_steps.begin(); }
+
+ /**
+ * Returns the last step.
+ * @return an iterator on the last step.
+ */
+ stepIterator end() { return m_steps.end(); }
+
+ protected:
+ /** Ensures that component is valid (< m_nbComponents). */
+ void checkComponent(const int& component);
+ void checkStepIndex(const int& step);
+
+ protected:
+ /** The name of the Field. */
+ std::string m_name;
+ /** The dimension of the Field. */
+ XAO::Dimension m_dimension;
+
+ /** The number of components. */
+ int m_nbComponents;
+ /** The components of the field. */
+ std::vector<std::string> m_components;
+ /** The number of elements. */
+ int m_nbElements;
+
+ /** The list of steps. */
+ std::vector<Step*> m_steps;
+ };
+}
+
+#endif
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_GeometricElement.hxx"
+#include "XAO_XaoUtils.hxx"
+
+using namespace XAO;
+
+
+GeometricElement::GeometricElement()
+{
+ m_name = "";
+ m_reference = "";
+}
+
+GeometricElement::GeometricElement(const std::string& name, const std::string& reference)
+{
+ m_name = name;
+ m_reference = reference;
+}
+
+GeometricElement::~GeometricElement()
+{
+}
+
+const bool GeometricElement::hasName()
+{
+ return !m_name.empty();
+}
+
+GeometricElementList::GeometricElementList()
+{
+ setSize(0);
+}
+
+GeometricElementList::GeometricElementList(const int& count)
+{
+ setSize(m_count);
+}
+
+void GeometricElementList::setSize(const int& nb)
+{
+ m_count = nb;
+ m_elements.clear();
+ for (int i = 0; i < nb; ++i)
+ {
+ m_elements[i] = GeometricElement();
+ }
+}
+
+void GeometricElementList::setElement(const int& index, const std::string& name, const std::string& reference)
+{
+ if (m_count == 0 || index > m_count)
+ throw SALOME_Exception("Problem with number of elements");
+
+ m_elements[index].setName(name);
+ m_elements[index].setReference(reference);
+}
+
+const std::string GeometricElementList::getName(const int& index)
+{
+ if (m_count == 0 || index > m_count)
+ throw SALOME_Exception("Problem with number of elements");
+
+ return m_elements[index].getName();
+}
+
+void GeometricElementList::setName(const int& index, const std::string& name)
+{
+ if (m_count == 0 || index > m_count)
+ throw SALOME_Exception("Problem with number of elements");
+
+ m_elements[index].setName(name);
+}
+
+const bool GeometricElementList::hasName(const int& index)
+{
+ if (m_count == 0 || index > m_count)
+ throw SALOME_Exception("Problem with number of elements");
+
+ return m_elements[index].hasName();
+}
+
+const std::string GeometricElementList::getReference(const int& index)
+{
+ if (m_count == 0 || index > m_count)
+ throw SALOME_Exception("Problem with number of elements");
+
+ return m_elements[index].getReference();
+}
+
+void GeometricElementList::setReference(const int& index, const std::string& name)
+{
+ if (m_count == 0 || index > m_count)
+ throw SALOME_Exception("Problem with number of elements");
+
+ m_elements[index].setReference(name);
+}
+
+const int GeometricElementList::getIndexByReference(const std::string& ref)
+{
+ for (int index = 0; index < m_count; ++index)
+ {
+ if (ref == m_elements[index].getReference())
+ return index;
+ }
+
+ throw SALOME_Exception(MsgBuilder() << "Reference not found: " << ref);
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#ifndef __XAO_GEOMETRICELEMENT_HXX__
+#define __XAO_GEOMETRICELEMENT_HXX__
+
+#include <string>
+#include <map>
+
+namespace XAO
+{
+ /**
+ * \class GeometricElement
+ * Generic class to manipulate a topologic element (vertex, edge, face or solid).
+ */
+ class GeometricElement
+ {
+ public:
+ /**
+ * Default constructor.
+ */
+ GeometricElement();
+ /**
+ * Constructor with name and reference.
+ * \param name the name of the element.
+ * \param reference the reference of the element.
+ */
+ GeometricElement(const std::string& name, const std::string& reference);
+ /**
+ * Destructor.
+ */
+ virtual ~GeometricElement();
+
+ /**
+ * Gets the name of the element.
+ * \return the name.
+ */
+ const std::string getName()
+ {
+ return m_name;
+ }
+ /**
+ * Sets the name of the element
+ * \param name the name to set.
+ */
+ void setName(const std::string& name)
+ {
+ m_name = name;
+ }
+
+ /**
+ * Checks if the element has a name.
+ * @return true if the element has a name, false otherwise.
+ */
+ const bool hasName();
+
+ /**
+ * Gets the reference of the element.
+ * \return the reference.
+ */
+ const std::string getReference()
+ {
+ return m_reference;
+ }
+ /**
+ * Sets the reference of the element.
+ * \param reference the reference to set.
+ */
+ void setReference(const std::string& reference)
+ {
+ m_reference = reference;
+ }
+
+ private:
+ /** The name of the element. */
+ std::string m_name;
+ /** The reference of the element. */
+ std::string m_reference;
+ };
+
+ /**
+ * \class GeometricElementList
+ * Generic class to manipulate a list of topologic element.
+ */
+ class GeometricElementList
+ {
+ public:
+ /**
+ * Default constructor.
+ */
+ GeometricElementList();
+
+ /**
+ * Constructor with size.
+ * \param nb the size to set.
+ */
+ GeometricElementList(const int& nb);
+
+ /**
+ * Destructor.
+ */
+ virtual ~GeometricElementList() {}
+
+ /**
+ * Gets the size of the list.
+ * \return the size of the list.
+ */
+ const int getSize() const { return m_count; }
+
+ /**
+ * Sets the size of the list.
+ * \param nb the size to set.
+ * \warning the list will be cleared.
+ */
+ void setSize(const int& nb);
+
+ /**
+ * Sets the name and the reference of an element.
+ * \param index the index of the element to set.
+ * \param name the name to set.
+ * \param reference the reference to set.
+ * \throw SALOME_Exception if index is bigger than the size of the list.
+ */
+ void setElement(const int& index, const std::string& name, const std::string& reference);
+ /**
+ * Gets the name of an element.
+ * \param index the index of the element to set.
+ * \return the name of the element with the given index.
+ * \throw SALOME_Exception if index is bigger than the size of the list.
+ */
+ const std::string getName(const int& index);
+ /**
+ * Sets the name of an element.
+ * \param index the index of the element.
+ * \param name the name to set.
+ * \throw SALOME_Exception if index is bigger than the size of the list.
+ */
+ void setName(const int& index, const std::string& name);
+
+ /**
+ * Checks if an element has a name.
+ * @param index the index of the element.
+ * @return true if the element has a name, false otherwise.
+ */
+ const bool hasName(const int& index);
+
+ /**
+ * Gets the reference of an element.
+ * \param index the index of the element.
+ * \return the reference of the element.
+ * \throw SALOME_Exception if index is bigger than the size of the list.
+ */
+ const std::string getReference(const int& index);
+ /**
+ * Sets the reference of an element.
+ * \param index the index of the element to set.
+ * \param reference the reference to set.
+ * \throw SALOME_Exception if index is bigger than the size of the list.
+ */
+ void setReference(const int& index, const std::string& reference);
+
+ /**
+ * Gets the index of an element using its reference.
+ * \param reference the searched reference.
+ * \return the index of the element or -1 if no element found.
+ */
+ const int getIndexByReference(const std::string& reference);
+
+ /**
+ * Iterator on the element of the list.
+ */
+ typedef std::map<int, GeometricElement>::iterator iterator;
+
+ /**
+ * Gets an iterator on the first element.
+ * @return an iterator on the first element.
+ */
+ iterator begin() { return m_elements.begin(); }
+
+ /**
+ * Gets an iterator on the last element.
+ * @return an iterator on the last element.
+ */
+ iterator end() { return m_elements.end(); }
+
+ private:
+ int m_count;
+ std::map<int, GeometricElement> m_elements;
+ };
+}
+
+#endif /* __XAO_GEOMETRICELEMENT_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Nathalie Gore (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_XaoUtils.hxx"
+#include "XAO_Geometry.hxx"
+#include "XAO_BrepGeometry.hxx"
+
+using namespace XAO;
+
+Geometry::Geometry(const std::string& name)
+ : m_name(name)
+{
+}
+
+Geometry* Geometry::createGeometry(const XAO::Format& format)
+{
+ return createGeometry(format, "");
+}
+
+Geometry* Geometry::createGeometry(const XAO::Format& format, const std::string& name)
+{
+ if (format == XAO::BREP)
+ return new BrepGeometry(name);
+
+ throw SALOME_Exception(MsgBuilder() << "Geometry format not supported: " << format);
+}
+
+Geometry::~Geometry()
+{
+}
+
+const int Geometry::countElements(const XAO::Dimension& dim)
+{
+ if (dim == XAO::VERTEX)
+ return countVertices();
+ if (dim == XAO::EDGE)
+ return countEdges();
+ if (dim == XAO::FACE)
+ return countFaces();
+ if (dim == XAO::SOLID)
+ return countSolids();
+
+ throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
+}
+
+const std::string Geometry::getElementReference(const XAO::Dimension& dim, const int& index)
+{
+ if (dim == XAO::VERTEX)
+ return getVertexReference(index);
+ if (dim == XAO::EDGE)
+ return getEdgeReference(index);
+ if (dim == XAO::FACE)
+ return getFaceReference(index);
+ if (dim == XAO::SOLID)
+ return getSolidReference(index);
+
+ throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
+}
+
+const int Geometry::getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference)
+{
+ if (dim == XAO::VERTEX)
+ return getVertexIndexByReference(reference);
+ if (dim == XAO::EDGE)
+ return getEdgeIndexByReference(reference);
+ if (dim == XAO::FACE)
+ return getFaceIndexByReference(reference);
+ if (dim == XAO::SOLID)
+ return getSolidIndexByReference(reference);
+
+ throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
+}
+
+GeometricElementList::iterator Geometry::begin(const XAO::Dimension& dim)
+{
+ if (dim == XAO::VERTEX)
+ return m_vertices.begin();
+ if (dim == XAO::EDGE)
+ return m_edges.begin();
+ if (dim == XAO::FACE)
+ return m_faces.begin();
+ if (dim == XAO::SOLID)
+ return m_solids.begin();
+
+ throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
+}
+
+GeometricElementList::iterator Geometry::end(const XAO::Dimension& dim)
+{
+ if (dim == XAO::VERTEX)
+ return m_vertices.end();
+ if (dim == XAO::EDGE)
+ return m_edges.end();
+ if (dim == XAO::FACE)
+ return m_faces.end();
+ if (dim == XAO::SOLID)
+ return m_solids.end();
+
+ throw SALOME_Exception(MsgBuilder() << "Unknown dimension:" << dim);
+}
--- /dev/null
+// Copyright (C) 2007-2012 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Nathalie Gore (OpenCascade)
+
+#ifndef __XAO_GEOMETRY_HXX__
+#define __XAO_GEOMETRY_HXX__
+
+#include <string>
+
+#include "XAO_Xao.hxx"
+#include "XAO_GeometricElement.hxx"
+
+namespace XAO
+{
+ class Geometry
+ {
+ protected:
+ Geometry(const std::string& name);
+
+ public:
+ /**
+ * Creates a geometry.
+ * @param format the format of the geometry.
+ * @return the created geometry.
+ */
+ static Geometry* createGeometry(const XAO::Format& format);
+
+ /**
+ * Constructor.
+ * Creates a geometry.
+ * @name name the name of the geometry.
+ * @return the created geometry.
+ */
+ static Geometry* createGeometry(const XAO::Format& format, const std::string& name);
+
+ /** Destructor. */
+ ~Geometry();
+
+ /**
+ * Gets the name of the geometry.
+ * @return the name of the geometry.
+ */
+ const std::string getName()
+ {
+ return m_name;
+ }
+ /**
+ * Sets the name of the geometry.
+ * @param name the name to set.
+ */
+ void setName(const std::string& name)
+ {
+ m_name = name;
+ }
+
+ /**
+ * Gets the format of the geometry.
+ * @return the format of the geometry.
+ */
+ virtual const XAO::Format getFormat() = 0;
+
+ virtual const std::string getShape() = 0;
+ virtual void setShape(const std::string& shape) = 0;
+
+ const int countElements(const XAO::Dimension& dim);
+ const int countVertices() { return m_vertices.getSize(); }
+ const int countEdges() { return m_edges.getSize(); }
+ const int countFaces() { return m_faces.getSize(); }
+ const int countSolids() { return m_solids.getSize(); }
+
+ void setCountVertices(const int& nb) { m_vertices.setSize(nb); }
+ void setCountEdges(const int& nb) { m_edges.setSize(nb); }
+ void setCountFaces(const int& nb) { m_faces.setSize(nb); }
+ void setCountSolids(const int& nb) { m_solids.setSize(nb); }
+
+ const std::string getVertexName(const int& index) { return m_vertices.getName(index); }
+ const std::string getEdgeName(const int& index) { return m_edges.getName(index); }
+ const std::string getFaceName(const int& index) { return m_faces.getName(index); }
+ const std::string getSolidName(const int& index) { return m_solids.getName(index); }
+
+ void setVertexName(const int& index, const std::string& name) { m_vertices.setName(index, name); }
+ void setEdgeName(const int& index, const std::string& name) { m_edges.setName(index, name); }
+ void setFaceName(const int& index, const std::string& name) { m_faces.setName(index, name); }
+ void setSolidName(const int& index, const std::string& name) { m_solids.setName(index, name); }
+
+ const bool hasVertexName(const int& index) { return m_vertices.hasName(index); }
+ const bool hasEdgeName(const int& index) { return m_edges.hasName(index); }
+ const bool hasFaceName(const int& index) { return m_faces.hasName(index); }
+ const bool hasSolidName(const int& index) { return m_solids.hasName(index); }
+
+ const std::string getVertexReference(const int& index) { return m_vertices.getReference(index); }
+ const std::string getEdgeReference(const int& index) { return m_edges.getReference(index); }
+ const std::string getFaceReference(const int& index) { return m_faces.getReference(index); }
+ const std::string getSolidReference(const int& index) { return m_solids.getReference(index); }
+ const std::string getElementReference(const XAO::Dimension& dim, const int& index);
+
+ void setVertexReference(const int& index, const std::string& reference) { m_vertices.setReference(index, reference); }
+ void setEdgeReference(const int& index, const std::string& reference) { m_edges.setReference(index, reference); }
+ void setFaceReference(const int& index, const std::string& reference) { m_faces.setReference(index, reference); }
+ void setSolidReference(const int& index, const std::string& reference) { m_solids.setReference(index, reference); }
+
+ void setVertex(const int& index, const std::string& name, const std::string& reference) { m_vertices.setElement(index, name, reference); }
+ void setEdge(const int& index, const std::string& name, const std::string& reference) { m_edges.setElement(index, name, reference); }
+ void setFace(const int& index, const std::string& name, const std::string& reference) { m_faces.setElement(index, name, reference); }
+ void setSolid(const int& index, const std::string& name, const std::string& reference) { m_solids.setElement(index, name, reference); }
+
+ const int getVertexIndexByReference(const std::string& reference) { return m_vertices.getIndexByReference(reference); }
+ const int getEdgeIndexByReference(const std::string& reference) { return m_edges.getIndexByReference(reference); }
+ const int getFaceIndexByReference(const std::string& reference) { return m_faces.getIndexByReference(reference); }
+ const int getSolidIndexByReference(const std::string& reference) { return m_solids.getIndexByReference(reference); }
+ const int getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference);
+
+ GeometricElementList::iterator begin(const XAO::Dimension& dim);
+ GeometricElementList::iterator end(const XAO::Dimension& dim);
+
+ protected:
+ std::string m_name;
+ GeometricElementList m_vertices;
+ GeometricElementList m_edges;
+ GeometricElementList m_faces;
+ GeometricElementList m_solids;
+
+ };
+}
+
+#endif
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_XaoUtils.hxx"
+#include "XAO_Group.hxx"
+
+using namespace XAO;
+
+
+Group::Group(const XAO::Dimension& dim, const int& nbElements)
+{
+ initGroup("", dim, nbElements);
+}
+
+Group::Group(const std::string& name, const XAO::Dimension& dim, const int& nbElements)
+{
+ initGroup(name, dim, nbElements);
+}
+
+void Group::initGroup(const std::string& name, const XAO::Dimension& dim, const int& nbElements)
+{
+ if (dim == XAO::WHOLE)
+ throw SALOME_Exception("Dimension WHOLE is not valid for group.");
+
+ m_name = name;
+ m_dimension = dim;
+ m_count = 0;
+ m_nbElements = nbElements;
+}
+
+Group::~Group()
+{
+}
+
+void Group::checkIndex(const int& element)
+{
+ if (element < m_elements.size() && element >= 0)
+ return;
+
+ throw SALOME_Exception(MsgBuilder() << "Index of element is out of range [0, "
+ << m_elements.size()-1 << "]: " << element);
+}
+
+void Group::add(const int& value)
+{
+ m_elements.insert(value);
+}
+
+void Group::remove(const int& value)
+{
+ m_elements.erase(value);
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
+
+#ifndef __XAO_GROUP_HXX__
+#define __XAO_GROUP_HXX__
+
+#include <string>
+#include <set>
+
+#include "XAO_Xao.hxx"
+
+namespace XAO
+{
+ /**
+ * \class Group
+ * Class to represent a Geometrical Group.
+ */
+ class Group
+ {
+ public:
+ /**
+ * Constructor.
+ * @param dim the dimension of the group.
+ * @param nbElements the number of geometrical elements for the dimension in the geometry.
+ */
+ Group(const XAO::Dimension& dim, const int& nbElements);
+
+ /**
+ * Constructor.
+ * @name the name of the group.
+ * @param dim the dimension of the group.
+ * @param nbElements the number of geometrical elements for the dimension in the geometry.
+ */
+ Group(const std::string& name, const XAO::Dimension& dim, const int& nbelements);
+
+ /**
+ * Destructor.
+ */
+ virtual ~Group();
+
+ /**
+ * Gets the name of the group.
+ * \return the name of the group.
+ */
+ const std::string getName()
+ {
+ return m_name;
+ }
+ /**
+ * Sets the name of the group.
+ * \param name the name to set.
+ */
+ void setName(const std::string& name)
+ {
+ m_name = name;
+ }
+
+ /**
+ * Gets the dimension of the group.
+ * \return the dimension of the group.
+ */
+ const XAO::Dimension getDimension()
+ {
+ return m_dimension;
+ }
+
+ /**
+ * Gets the numbers of elements in the geometry of the same type than the group.
+ * \return the number of elements in the associated geometry.
+ */
+ const int getNbElements()
+ {
+ return m_nbElements;
+ }
+
+ /**
+ * Gets the number of elements in the group.
+ * \return the number of elements.
+ */
+ const int count() const
+ {
+ return m_elements.size();
+ }
+
+ /**
+ * Gets the reference of an element.
+ * \param index the index of the element.
+ * \return the reference of the element.
+ * \note use begin() and end() if you need to iterate.
+ */
+ const int get(const int& index)
+ {
+ checkIndex(index);
+ std::set<int>::iterator it = m_elements.begin();
+ std::advance(it, index);
+ return (*it);
+ }
+
+ /**
+ * Adds an element to the group.
+ * \param value the index of the element to add.
+ */
+ void add(const int& value);
+
+ /**
+ * Removes an element from the group.
+ * \param value the index of the element to remove.
+ */
+ void remove(const int& value);
+
+ /**
+ * Gets an iterator on the first element in the group.
+ * @return an iterator on the first element.
+ */
+ std::set<int>::iterator begin() { return m_elements.begin(); }
+
+ /**
+ * Gets an iterator on the last element in the group.
+ * @return an iterator on the last element.
+ */
+ std::set<int>::iterator end() { return m_elements.end(); }
+
+ private:
+ /**
+ * Initialize the groups.
+ * @param name the name of the group.
+ * @param dim the dimension of the group.
+ * @param nbElements the number of elements in the geometry for the dimension.
+ */
+ void initGroup(const std::string& name, const XAO::Dimension& dim, const int& nbElements);
+
+ /**
+ * Ensures that the given element is valid.
+ * @param element
+ * @throw SALOME_Exception if element is bigger than the number of elements.
+ */
+ void checkIndex(const int& element);
+
+ private:
+ /** The name of the group. */
+ std::string m_name;
+ /** The number of elements in the associated geometry. */
+ int m_nbElements;
+ /** The dimension of the group. */
+ XAO::Dimension m_dimension;
+ /** The number of elements in the group. */
+ int m_count;
+ /** The elements of the group. */
+ std::set<int> m_elements;
+ };
+}
+
+#endif
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_IntegerField.hxx"
+#include "XAO_IntegerStep.hxx"
+#include "XAO_XaoUtils.hxx"
+
+using namespace XAO;
+
+IntegerField::IntegerField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents)
+ : Field(name, dimension, nbElements, nbComponents)
+{
+}
+
+Step* IntegerField::addNewStep(const int& step)
+{
+ return addStep(step, 0);
+}
+
+IntegerStep* IntegerField::addStep(const int& step)
+{
+ return addStep(step, 0);
+}
+
+IntegerStep* IntegerField::addStep(const int& step, const int& stamp)
+{
+ if (hasStep(step))
+ throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
+
+ IntegerStep* bstep = new IntegerStep(step, stamp, m_nbElements, m_nbComponents);
+ m_steps.push_back(bstep);
+ return bstep;
+}
+
+IntegerStep* IntegerField::getStep(const int& index)
+{
+ checkStepIndex(index);
+ return (IntegerStep*)m_steps[index];
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#ifndef __XAO_INTEGERFIELD_HXX__
+#define __XAO_INTEGERFIELD_HXX__
+
+#include <string>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Field.hxx"
+#include "XAO_IntegerStep.hxx"
+
+namespace XAO
+{
+ class IntegerField : public Field
+ {
+ public:
+ IntegerField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
+
+ virtual const XAO::Type getType() { return XAO::INTEGER; }
+
+ virtual Step* addNewStep(const int& step);
+ IntegerStep* addStep(const int& step);
+ IntegerStep* addStep(const int& step, const int& stamp);
+ IntegerStep* getStep(const int& step);
+ };
+}
+
+#endif /* __XAO_INTEGERFIELD_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_IntegerStep.hxx"
+#include "XAO_XaoUtils.hxx"
+
+using namespace XAO;
+
+IntegerStep::IntegerStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
+{
+ m_nbElements = nbElements;
+ m_nbComponents = nbComponents;
+ m_step = step;
+ m_stamp = stamp;
+
+ m_values.reserve(m_nbElements);
+ for (int i = 0; i < m_nbElements; ++i)
+ {
+ std::vector<int> row;
+ row.reserve(m_nbComponents);
+ for (int j = 0; j < m_nbComponents; ++j)
+ row.push_back(0);
+ m_values.push_back(row);
+ }
+}
+
+std::vector<int> IntegerStep::getValues()
+{
+ std::vector<int> result;
+ result.reserve(m_nbElements * m_nbComponents);
+
+ std::vector< std::vector<int> >::iterator it;
+ for (it = m_values.begin(); it != m_values.end(); ++it)
+ {
+ std::vector<int> eltValues = *it;
+ result.insert(result.end(), eltValues.begin(), eltValues.end());
+ }
+
+ return result;
+}
+
+std::vector<int> IntegerStep::getElement(const int& element)
+{
+ checkElementIndex(element);
+
+ std::vector<int> result(m_values[element]);
+ return result;
+}
+
+std::vector<int> IntegerStep::getComponent(const int& component)
+{
+ checkComponentIndex(component);
+
+ std::vector<int> result;
+ result.reserve(m_nbElements);
+
+ std::vector< std::vector<int> >::iterator it;
+ for (it = m_values.begin(); it != m_values.end(); ++it)
+ {
+ std::vector<int> eltValues = *it;
+ result.push_back(eltValues[component]);
+ }
+
+ return result;
+}
+
+const int IntegerStep::getValue(const int& element, const int& component)
+{
+ checkElementIndex(element);
+ checkComponentIndex(component);
+
+ return m_values[element][component];
+}
+
+const std::string IntegerStep::getStringValue(const int& element, const int& component)
+{
+ return XaoUtils::intToString(getValue(element, component));
+}
+
+void IntegerStep::setValues(const std::vector<int>& values)
+{
+ checkNbValues(values.size());
+
+ for (int i = 0; i < m_nbElements; ++i)
+ {
+ for (int j = 0; j < m_nbComponents; ++j)
+ {
+ m_values[i][j] = values[i * m_nbComponents + j];
+ }
+ }
+}
+
+void IntegerStep::setElements(const int& element, const std::vector<int>& elements)
+{
+ checkElementIndex(element);
+ checkNbComponents(elements.size());
+
+ for (int i = 0; i < m_nbComponents; ++i)
+ m_values[element][i] = elements[i];
+}
+
+void IntegerStep::setComponents(const int& component, const std::vector<int>& components)
+{
+ checkElementIndex(component);
+ checkNbElements(components.size());
+
+ for (int i = 0; i < m_nbElements; ++i)
+ m_values[i][component] = components[i];
+}
+
+void IntegerStep::setValue(const int& element, const int& component, const int& value)
+{
+ checkElementIndex(element);
+ checkComponentIndex(component);
+
+ m_values[element][component] = value;
+}
+
+void IntegerStep::setStringValue(const int& element, const int& component, const std::string& value)
+{
+ setValue(element, component, XaoUtils::stringToInt(value));
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+
+#ifndef __XAO_INTEGERSTEP_HXX__
+#define __XAO_INTEGERSTEP_HXX__
+
+#include <vector>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Step.hxx"
+
+namespace XAO
+{
+ class IntegerStep : public Step
+ {
+ public:
+ IntegerStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
+
+ virtual const XAO::Type getType() { return XAO::INTEGER; }
+
+ std::vector<int> getValues();
+ std::vector<int> getElement(const int& element);
+ std::vector<int> getComponent(const int& component);
+
+ const int getValue(const int& element, const int& component);
+
+ void setValues(const std::vector<int>& values);
+ void setElements(const int& element, const std::vector<int>& elements);
+ void setComponents(const int& element, const std::vector<int>& components);
+ void setValue(const int& element, const int& component, const int& value);
+
+ virtual const std::string getStringValue(const int& element, const int& component);
+ virtual void setStringValue(const int& element, const int& component, const std::string& value);
+
+ private:
+ std::vector< std::vector<int> > m_values;
+ };
+}
+
+
+#endif /* __XAO_INTEGERSTEP_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_Xao.hxx"
+#include "XAO_XaoUtils.hxx"
+#include "XAO_Step.hxx"
+#include "XAO_BooleanStep.hxx"
+#include "XAO_IntegerStep.hxx"
+#include "XAO_DoubleStep.hxx"
+#include "XAO_StringStep.hxx"
+
+using namespace XAO;
+
+Step* Step::createStep(const XAO::Type& type, const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
+{
+ if (type == XAO::BOOLEAN)
+ return new BooleanStep(step, stamp, nbElements, nbComponents);
+ if (type == XAO::INTEGER)
+ return new IntegerStep(step, stamp, nbElements, nbComponents);
+ if (type == XAO::DOUBLE)
+ return new DoubleStep(step, stamp, nbElements, nbComponents);
+ if (type == XAO::STRING)
+ return new StringStep(step, stamp, nbElements, nbComponents);
+
+ throw SALOME_Exception("Unknown Type");
+}
+
+void Step::checkElementIndex(const int& element)
+{
+ if (element < m_nbElements && element >= 0)
+ return;
+
+ throw SALOME_Exception(MsgBuilder() << "Element index is out of range [0, "
+ << m_nbElements-1 << "]: " << element);
+}
+
+void Step::checkComponentIndex(const int& component)
+{
+ if (component < m_nbComponents && component >= 0)
+ return;
+
+ throw SALOME_Exception(MsgBuilder() << "Component index is out of range [0, "
+ << m_nbComponents-1 << "]: " << component);
+}
+
+void Step::checkNbElements(const int& nbElements)
+{
+ if (nbElements == m_nbElements)
+ return;
+
+ throw SALOME_Exception(MsgBuilder() << "Invalid number of elements: " << nbElements
+ << ", expected " << m_nbElements);
+}
+
+void Step::checkNbComponents(const int& nbComponents)
+{
+ if (nbComponents == m_nbComponents)
+ return;
+
+ throw SALOME_Exception(MsgBuilder() << "Invalid number of components: " << nbComponents
+ << ", expected " << m_nbComponents);
+}
+
+void Step::checkNbValues(const int& nbValues)
+{
+ if (nbValues == m_nbElements * m_nbComponents)
+ return;
+
+ throw SALOME_Exception(MsgBuilder() << "Invalid number of values:" << nbValues
+ << ", expected " << m_nbElements * m_nbComponents);
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+
+#ifndef __XAO_STEP_HXX__
+#define __XAO_STEP_HXX__
+
+#include "XAO_Xao.hxx"
+
+namespace XAO
+{
+ class Step
+ {
+ protected:
+ /** Default constructor. */
+ Step() {}
+
+ public:
+ /**
+ * Creates a step.
+ * @param type the type of the values for the step.
+ * @param step the index of the step.
+ * @param stamp the stamp of the step.
+ * @param nbElements the number of elements in the step.
+ * @param nbComponents the number of components in the step.
+ * @return
+ */
+ static Step* createStep(const XAO::Type& type, const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
+
+ /**
+ * Destructor.
+ */
+ virtual ~Step() {}
+
+ /**
+ * Gets the type of the step.
+ * @return
+ */
+ virtual const XAO::Type getType() = 0;
+
+ /**
+ * Gets the step index.
+ * @return the index of the step.
+ */
+ const int getStep() { return m_step; }
+
+ /**
+ * Sets the number of the step.
+ * @param step the index to set.
+ */
+ void setStep(const int& step) { m_step = step; }
+
+ /**
+ * Gets the stamp of the index.
+ * @return the stamp of the index.
+ */
+ const int getStamp() { return m_stamp; }
+
+ /**
+ * Sets the stamp of the index.
+ * @param stamp the stamp to set.
+ */
+ void setStamp(const int& stamp) { m_stamp = stamp; }
+
+ /**
+ * Gets the number of components of the step.
+ * @return the number of components.
+ */
+ const int countComponents() { return m_nbComponents; }
+
+ /**
+ * Gets the number of elements for the step.
+ * @return the number of elements.
+ */
+ const int countElements() { return m_nbElements; }
+
+ /**
+ * Gets the number of values for the step.
+ * @return the number of values.
+ */
+ const int countValues() { return m_nbElements * m_nbComponents; }
+
+ /**
+ * Gets a value as a string.
+ * @param element the index of the element.
+ * @param component the index of the component.
+ * @return the value as a string.
+ */
+ virtual const std::string getStringValue(const int& element, const int& component) = 0;
+
+ /**
+ * Sets a value as a string
+ * @param element the index of the element.
+ * @param component the index of the component.
+ * @param value the string value.
+ * @throw SALOME_Exception if the value is not valid.
+ */
+ virtual void setStringValue(const int& element, const int& component, const std::string& value) = 0;
+
+ protected:
+ void checkElementIndex(const int& element);
+ void checkComponentIndex(const int& component);
+
+ void checkNbElements(const int& nbElements);
+ void checkNbComponents(const int& nbComponents);
+ void checkNbValues(const int& nbValues);
+
+ protected:
+ /** the index of the step. */
+ int m_step;
+ /** The stamp of the step. */
+ int m_stamp;
+ /** The number of components. */
+ int m_nbComponents;
+ /** The number of elements. */
+ int m_nbElements;
+ };
+}
+
+
+#endif /* __XAO_STEP_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_StringField.hxx"
+#include "XAO_StringStep.hxx"
+#include "XAO_XaoUtils.hxx"
+
+using namespace XAO;
+
+StringField::StringField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents)
+ : Field(name, dimension, nbElements, nbComponents)
+{
+}
+
+Step* StringField::addNewStep(const int& step)
+{
+ return addStep(step, 0);
+}
+
+StringStep* StringField::addStep(const int& step)
+{
+ return addStep(step, 0);
+}
+
+StringStep* StringField::addStep(const int& step, const int& stamp)
+{
+ if (hasStep(step))
+ throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
+
+ StringStep* bstep = new StringStep(step, stamp, m_nbElements, m_nbComponents);
+ m_steps.push_back(bstep);
+ return bstep;
+}
+
+StringStep* StringField::getStep(const int& index)
+{
+ checkStepIndex(index);
+ return (StringStep*)m_steps[index];
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#ifndef __XAO_STRINGFIELD_HXX__
+#define __XAO_STRINGFIELD_HXX__
+
+#include <string>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Field.hxx"
+#include "XAO_StringStep.hxx"
+
+namespace XAO
+{
+ class StringField : public Field
+ {
+ public:
+ StringField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
+
+ virtual const XAO::Type getType() { return XAO::STRING; }
+
+ virtual Step* addNewStep(const int& step);
+ StringStep* addStep(const int& step);
+ StringStep* addStep(const int& step, const int& stamp);
+ StringStep* getStep(const int& index);
+ };
+}
+
+#endif /* __XAO_STRINGFIELD_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_StringStep.hxx"
+
+using namespace XAO;
+
+StringStep::StringStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
+{
+ m_nbElements = nbElements;
+ m_nbComponents = nbComponents;
+ m_step = step;
+ m_stamp = stamp;
+
+ m_values.reserve(m_nbElements);
+ for (int i = 0; i < m_nbElements; ++i)
+ {
+ std::vector<std::string> row;
+ row.reserve(m_nbComponents);
+ for (int j = 0; j < m_nbComponents; ++j)
+ row.push_back("");
+ m_values.push_back(row);
+ }
+}
+
+std::vector<std::string> StringStep::getValues()
+{
+ std::vector<std::string> result;
+ result.reserve(m_nbElements * m_nbComponents);
+
+ std::vector< std::vector<std::string> >::iterator it;
+ for (it = m_values.begin(); it != m_values.end(); ++it)
+ {
+ std::vector<std::string> eltValues = *it;
+ result.insert(result.end(), eltValues.begin(), eltValues.end());
+ }
+
+ return result;
+}
+
+std::vector<std::string> StringStep::getElement(const int& element)
+{
+ checkElementIndex(element);
+
+ std::vector<std::string> result(m_values[element]);
+ return result;
+}
+
+std::vector<std::string> StringStep::getComponent(const int& component)
+{
+ checkComponentIndex(component);
+
+ std::vector<std::string> result;
+ result.reserve(m_nbElements);
+
+ std::vector< std::vector<std::string> >::iterator it;
+ for (it = m_values.begin(); it != m_values.end(); ++it)
+ {
+ std::vector<std::string> eltValues = *it;
+ result.push_back(eltValues[component]);
+ }
+
+ return result;
+}
+
+const std::string StringStep::getValue(const int& element, const int& component)
+{
+ checkElementIndex(element);
+ checkComponentIndex(component);
+
+ return m_values[element][component];
+}
+
+const std::string StringStep::getStringValue(const int& element, const int& component)
+{
+ return getValue(element, component);
+}
+
+void StringStep::setValues(const std::vector<std::string>& values)
+{
+ checkNbValues(values.size());
+
+ for (int i = 0; i < m_nbElements; ++i)
+ {
+ for (int j = 0; j < m_nbComponents; ++j)
+ {
+ m_values[i][j] = values[i * m_nbComponents + j];
+ }
+ }
+}
+
+void StringStep::setElements(const int& element, const std::vector<std::string>& elements)
+{
+ checkElementIndex(element);
+ checkNbComponents(elements.size());
+
+ for (int i = 0; i < m_nbComponents; ++i)
+ m_values[element][i] = elements[i];
+}
+
+void StringStep::setComponents(const int& component, const std::vector<std::string>& components)
+{
+ checkElementIndex(component);
+ checkNbElements(components.size());
+
+ for (int i = 0; i < m_nbElements; ++i)
+ m_values[i][component] = components[i];
+}
+
+void StringStep::setValue(const int& element, const int& component, const std::string& value)
+{
+ checkElementIndex(element);
+ checkComponentIndex(component);
+
+ m_values[element][component] = value;
+}
+
+void StringStep::setStringValue(const int& element, const int& component, const std::string& value)
+{
+ setValue(element, component, value);
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+
+#ifndef __XAO_STRINGSTEP_HXX__
+#define __XAO_STRINGSTEP_HXX__
+
+#include <string>
+#include <vector>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Step.hxx"
+
+namespace XAO
+{
+ class StringStep : public Step
+ {
+ public:
+ StringStep(const int& nbElements, const int& nbComponents);
+ StringStep(const int& step, const int& nbElements, const int& nbComponents);
+ StringStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
+
+ virtual const XAO::Type getType() { return XAO::STRING; }
+
+ std::vector<std::string> getValues();
+ std::vector<std::string> getElement(const int& element);
+ std::vector<std::string> getComponent(const int& component);
+
+ const std::string getValue(const int& element, const int& component);
+
+ void setValues(const std::vector<std::string>& values);
+ void setElements(const int& element, const std::vector<std::string>& elements);
+ void setComponents(const int& component, const std::vector<std::string>& components);
+ void setValue(const int& element, const int& component, const std::string& value);
+
+ virtual const std::string getStringValue(const int& element, const int& component);
+ virtual void setStringValue(const int& element, const int& component, const std::string& value);
+
+ private:
+ std::vector< std::vector<std::string> > m_values;
+ };
+}
+
+
+#endif /* __XAO_STRINGSTEP_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
+
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_XaoUtils.hxx"
+#include "XAO_Xao.hxx"
+#include "XAO_Geometry.hxx"
+#include "XAO_Group.hxx"
+#include "XAO_Field.hxx"
+#include "XAO_XaoExporter.hxx"
+
+using namespace XAO;
+
+const xmlChar* C_XAO_VERSION = (xmlChar*)"1.0";
+
+Xao::Xao()
+{
+ m_author = "";
+ m_version = (char*)C_XAO_VERSION;
+ m_geometry = NULL;
+}
+
+Xao::Xao(const std::string& author, const std::string& version)
+{
+ m_author = author;
+ m_version = version;
+ m_geometry = NULL;
+}
+
+Xao::~Xao()
+{
+ if (m_geometry != NULL)
+ {
+ delete m_geometry;
+ m_geometry = NULL;
+ }
+
+ for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it)
+ {
+ delete (*it);
+ }
+
+ for (std::list<Field*>::iterator it = m_fields.begin(); it != m_fields.end(); ++it)
+ {
+ delete (*it);
+ }
+}
+
+const int Xao::countGroups() const
+{
+ return m_groups.size();
+}
+
+Group* Xao::getGroup(const int& index)
+{
+ int i = 0;
+ for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it, ++i)
+ {
+ if (i == index)
+ return (*it);
+ }
+
+ return NULL;
+}
+
+Group* Xao::addGroup(const XAO::Dimension& dim)
+{
+ return addGroup("", dim);
+}
+
+Group* Xao::addGroup(const std::string& name, const XAO::Dimension& dim)
+{
+ checkGeometry();
+ Group* group = new Group(name, dim, m_geometry->countElements(dim));
+ m_groups.push_back(group);
+ return group;
+}
+
+void Xao::removeGroup(Group* group)
+{
+ m_groups.remove(group);
+}
+
+const int Xao::countFields() const
+{
+ return m_fields.size();
+}
+
+Field* Xao::getField(const int& index)
+{
+ int i = 0;
+ for (std::list<Field*>::iterator it = m_fields.begin(); it != m_fields.end(); ++it, ++i)
+ {
+ if (i == index)
+ return (*it);
+ }
+
+ return NULL;
+}
+
+Field* Xao::addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents)
+{
+ return addField(type, "", dim, nbComponents);
+}
+
+Field* Xao::addField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dim, const int& nbComponents)
+{
+ checkGeometry();
+ int nbElts = m_geometry->countElements(dim);
+ Field* field = Field::createField(type, name, dim, nbElts, nbComponents);
+ m_fields.push_back(field);
+ return field;
+}
+
+void Xao::removeField(Field* field)
+{
+ m_fields.remove(field);
+}
+
+const bool Xao::exportXAO(const std::string& fileName)
+{
+ return XaoExporter::saveToFile(this, fileName);
+}
+
+const std::string Xao::getXML()
+{
+ return XaoExporter::saveToXml(this);
+}
+
+const bool Xao::importXAO(const std::string& fileName)
+{
+ return XaoExporter::readFromFile(fileName, this);
+}
+
+const bool Xao::setXML(const std::string& xml)
+{
+ return XaoExporter::setXML(xml, this);
+}
+
+void Xao::checkGeometry() const
+{
+ if (m_geometry == NULL)
+ throw SALOME_Exception("Geometry is null");
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
+
+#ifndef __XAO_XAO_HXX__
+#define __XAO_XAO_HXX__
+
+#include <string>
+#include <list>
+
+namespace XAO
+{
+ /**
+ * @enum CAD
+ */
+ enum Format
+ {
+ BREP,
+ STEP
+ };
+
+ /**
+ * @enum Dimension
+ */
+ enum Dimension
+ {
+ VERTEX = 0,//!< VERTEX
+ EDGE = 1, //!< EDGE
+ FACE = 2, //!< FACE
+ SOLID = 3, //!< SOLID
+ WHOLE = -1 //!< WHOLE
+ };
+
+ /**
+ * @enum Type
+ */
+ enum Type
+ {
+ BOOLEAN = 0,//!< BOOLEAN
+ INTEGER = 1,//!< INTEGER
+ DOUBLE = 2, //!< DOUBLE
+ STRING = 3 //!< STRING
+ };
+
+ class Geometry;
+ class Group;
+ class Field;
+
+ /**
+ * @class Xao
+ * The Xao class describes the XAO format.
+ */
+ class Xao
+ {
+ public:
+ /**
+ * Default constructor.
+ */
+ Xao();
+ /**
+ * Constructor with author and version.
+ * \param author the author of the file.
+ * \param version the version of the XAO format.
+ */
+ Xao(const std::string& author, const std::string& version);
+ /**
+ * Destructor.
+ */
+ virtual ~Xao();
+
+ /**
+ * Gets the author of the file.
+ * \return the author of the file.
+ */
+ const std::string getAuthor() const
+ {
+ return m_author;
+ }
+ /**
+ * Sets the author of the file.
+ * \param author the author to set.
+ */
+ void setAuthor(const std::string& author)
+ {
+ m_author = author;
+ }
+
+ /**
+ * Gets the version of the file.
+ * \return the version of the file.
+ */
+ const std::string getVersion() const
+ {
+ return m_version;
+ }
+ /**
+ * Sets the version of the file.
+ * \param version the version to set.
+ */
+ void setVersion(const std::string& version)
+ {
+ m_version = version;
+ }
+
+ //
+ // Geometry
+ //
+
+ /**
+ * Gets the geometry.
+ * \return the geometry.
+ */
+ Geometry* getGeometry() const
+ {
+ return m_geometry;
+ }
+ /**
+ * Sets the geometry.
+ * \param geometry the geometry to set.
+ */
+ void setGeometry(Geometry* geometry)
+ {
+ m_geometry = geometry;
+ }
+
+ //
+ // Groups
+ //
+
+ /**
+ * Gets the number of groups.
+ * \return the number of groups.
+ */
+ const int countGroups() const;
+ /**
+ * Gets a group.
+ * \param index the index of the wanted group.
+ * \return the group or NULL if index is bigger than the number of groups.
+ */
+ Group* getGroup(const int& index);
+ /**
+ * Adds a group.
+ * \param dim the dimension of the group.
+ * \return the created group.
+ */
+ Group* addGroup(const XAO::Dimension& dim);
+ /**
+ * Adds a group.
+ * \param name the name of the group.
+ * \param dim the dimension of the group.
+ * \return the created group.
+ */
+ Group* addGroup(const std::string& name, const XAO::Dimension& dim);
+ /**
+ * Removes a group.
+ * \param group the group to remove.
+ */
+ void removeGroup(Group* group);
+
+ //
+ // Fields
+ //
+
+ /**
+ * Gets the number of fields.
+ * \return the number of fields.
+ */
+ const int countFields() const;
+ /**
+ * Gets a field.
+ * \param index the index of the wanted field.
+ * \return the field or NULL if the index is bigger than the number of fields.
+ */
+ Field* getField(const int& index);
+ /**
+ * Adds a field.
+ * \param type the type of the field.
+ * \param dim the dimension of the field.
+ * \param nbComponents the number of components in the field.
+ * \return the created field.
+ */
+ Field* addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents);
+ /**
+ * Adds a field.
+ * \param type the type of the field.
+ * \param the name of the field.
+ * \param dim the dimension of the field.
+ * \param nbComponents the number of components in the field.
+ * \return the created field.
+ */
+ Field* addField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dim, const int& nbComponents);
+ /**
+ * Removes a field.
+ * \param field the field to remove.
+ */
+ void removeField(Field* field);
+
+ //
+ // Import / Export
+ //
+ /**
+ * Exports this XAO object to a file.
+ * \param fileName the name of the file to create.
+ * \return true is the export is successful.
+ */
+ const bool exportXAO(const std::string& fileName);
+ /**
+ * Gets the XML corresponding to this XAO.
+ * \return the XML as a string.
+ */
+ const std::string getXML();
+
+ /**
+ * Imports an XAO file into this object.
+ * \param fileName the name of the file to import.
+ * \return true if the import is successful.
+ */
+ const bool importXAO(const std::string& fileName);
+ /**
+ * Sets an XML describing an XAO format to this object.
+ * \param xml the XML to set.
+ * \return true if the import is successful.
+ */
+ const bool setXML(const std::string& xml);
+
+ private:
+ void checkGeometry() const;
+
+ private:
+ /** The author of the file. */
+ std::string m_author;
+ /** The version of the file. */
+ std::string m_version;
+ /** The geometry. */
+ Geometry* m_geometry;
+ /** The list of groups. */
+ std::list<Group*> m_groups;
+ /** The list of fields. */
+ std::list<Field*> m_fields;
+ };
+
+}
+
+#endif
--- /dev/null
+
+#include <libxml/parser.h>
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_XaoExporter.hxx"
+#include "XAO_Xao.hxx"
+#include "XAO_Geometry.hxx"
+#include "XAO_Group.hxx"
+#include "XAO_Field.hxx"
+#include "XAO_Step.hxx"
+#include "XAO_XaoUtils.hxx"
+
+namespace XAO
+{
+ const xmlChar* C_TAG_XAO = (xmlChar*)"XAO";
+ const xmlChar* C_ATTR_XAO_AUTHOR = (xmlChar*)"author";
+ const xmlChar* C_ATTR_XAO_VERSION = (xmlChar*)"version";
+
+ const xmlChar* C_TAG_GEOMETRY = (xmlChar*)"geometry";
+ const xmlChar* C_ATTR_GEOMETRY_NAME = (xmlChar*)"name";
+
+ const xmlChar* C_TAG_SHAPE = (xmlChar*)"shape";
+ const xmlChar* C_ATTR_SHAPE_FORMAT = (xmlChar*)"format";
+
+ const xmlChar* C_TAG_TOPOLOGY = (xmlChar*)"topology";
+ const xmlChar* C_TAG_VERTICES = (xmlChar*)"vertices";
+ const xmlChar* C_TAG_VERTEX = (xmlChar*)"vertex";
+ const xmlChar* C_TAG_EDGES = (xmlChar*)"edges";
+ const xmlChar* C_TAG_EDGE = (xmlChar*)"edge";
+ const xmlChar* C_TAG_FACES = (xmlChar*)"faces";
+ const xmlChar* C_TAG_FACE = (xmlChar*)"face";
+ const xmlChar* C_TAG_SOLIDS = (xmlChar*)"solids";
+ const xmlChar* C_TAG_SOLID = (xmlChar*)"solid";
+ const xmlChar* C_ATTR_COUNT = (xmlChar*)"count";
+ const xmlChar* C_ATTR_ELT_INDEX = (xmlChar*)"index";
+ const xmlChar* C_ATTR_ELT_NAME = (xmlChar*)"name";
+ const xmlChar* C_ATTR_ELT_REFERENCE = (xmlChar*)"reference";
+
+ const xmlChar* C_TAG_GROUPS = (xmlChar*)"groups";
+ const xmlChar* C_TAG_GROUP = (xmlChar*)"group";
+ const xmlChar* C_ATTR_GROUP_NAME = (xmlChar*)"name";
+ const xmlChar* C_ATTR_GROUP_DIM = (xmlChar*)"dimension";
+
+ const xmlChar* C_TAG_ELEMENT = (xmlChar*)"element";
+ const xmlChar* C_ATTR_ELEMENT_INDEX = (xmlChar*)"index";
+ const xmlChar* C_TAG_VALUE = (xmlChar*)"value";
+ const xmlChar* C_ATTR_VALUE_COMPONENT = (xmlChar*)"component";
+
+ const xmlChar* C_TAG_FIELDS = (xmlChar*)"fields";
+ const xmlChar* C_TAG_FIELD = (xmlChar*)"field";
+ const xmlChar* C_ATTR_FIELD_NAME = (xmlChar*)"name";
+ const xmlChar* C_ATTR_FIELD_TYPE = (xmlChar*)"type";
+ const xmlChar* C_ATTR_FIELD_DIMENSION = (xmlChar*)"dimension";
+ const xmlChar* C_TAG_COMPONENTS = (xmlChar*)"components";
+ const xmlChar* C_TAG_COMPONENT = (xmlChar*)"component";
+ const xmlChar* C_ATTR_COMPONENT_COLUMN = (xmlChar*)"column";
+ const xmlChar* C_ATTR_COMPONENT_NAME = (xmlChar*)"name";
+
+ const xmlChar* C_TAG_STEPS = (xmlChar*)"steps";
+ const xmlChar* C_TAG_STEP = (xmlChar*)"step";
+ const xmlChar* C_ATTR_STEP_NUMBER = (xmlChar*)"number";
+ const xmlChar* C_ATTR_STEP_STAMP = (xmlChar*)"stamp";
+}
+
+using namespace XAO;
+
+std::string XaoExporter::readStringProp(xmlNodePtr node, const xmlChar* attribute,
+ const bool& required, const std::string& defaultValue,
+ const std::string& exception /*= std::string() */)
+{
+ xmlChar* strAttr = xmlGetProp(node, attribute);
+ if (strAttr == NULL)
+ {
+ if (required)
+ {
+ if (exception.size() > 0)
+ throw SALOME_Exception(exception.c_str());
+
+ throw SALOME_Exception(MsgBuilder() << "Line " << node->line << ": "
+ << "Property " << (char*)attribute << " is required.");
+ }
+
+ return defaultValue;
+ }
+
+ std::string res = (char*)strAttr;
+ xmlFree(strAttr);
+ return res;
+}
+
+int XaoExporter::readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
+ const bool& required, const int& defaultValue,
+ const std::string& exception /*= std::string() */)
+{
+ xmlChar* strAttr = xmlGetProp(node, attribute);
+ if (strAttr == NULL)
+ {
+ if (required)
+ {
+ if (exception.size() > 0)
+ throw SALOME_Exception(exception.c_str());
+
+ throw SALOME_Exception(MsgBuilder() << "Line " << node->line << ": "
+ << "Property " << (char*)attribute << " is required.");
+ }
+
+ return defaultValue;
+ }
+
+ int res = XaoUtils::stringToInt((char*)strAttr);
+ xmlFree(strAttr);
+ return res;
+}
+
+const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName)
+{
+ xmlDocPtr doc = exportXMLDoc(xaoObject);
+ xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 2);
+ xmlFreeDoc(doc);
+
+ return true;
+}
+
+const std::string XaoExporter::saveToXml(Xao* xaoObject)
+{
+ xmlDocPtr doc = exportXMLDoc(xaoObject);
+
+ xmlChar *xmlbuff;
+ int buffersize;
+ xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
+ xmlFreeDoc(doc);
+ xmlCleanupGlobals();
+
+ return (char*)xmlbuff;
+}
+
+xmlDocPtr XaoExporter::exportXMLDoc(Xao* xaoObject)
+{
+ // Creating the Xml document
+ xmlDocPtr masterDocument = xmlNewDoc(BAD_CAST "1.0");
+ xmlNodePtr xao = xmlNewNode(0, C_TAG_XAO);
+ xmlDocSetRootElement(masterDocument, xao);
+
+ xmlNewProp(xao, C_ATTR_XAO_VERSION, BAD_CAST xaoObject->getVersion().c_str());
+ xmlNewProp(xao, C_ATTR_XAO_AUTHOR, BAD_CAST xaoObject->getAuthor().c_str());
+
+ if (xaoObject->getGeometry() != NULL)
+ {
+ exportGeometry(xaoObject->getGeometry(), masterDocument, xao);
+ }
+
+ exportGroups(xaoObject, xao);
+ exportFields(xaoObject, xao);
+
+ return masterDocument;
+}
+
+void XaoExporter::exportGeometricElements(Geometry* xaoGeometry,
+ xmlNodePtr topology, XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag)
+{
+ xmlNodePtr vertices = xmlNewChild(topology, 0, colTag, 0);
+ xmlNewProp(vertices, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoGeometry->countElements(dim)).c_str());
+ GeometricElementList::iterator it = xaoGeometry->begin(dim);
+ for (; it != xaoGeometry->end(dim); it++)
+ {
+ int index = it->first;
+ GeometricElement elt = it->second;
+ xmlNodePtr vertex = xmlNewChild(vertices, 0, eltTag, 0);
+ xmlNewProp(vertex, C_ATTR_ELT_INDEX, BAD_CAST XaoUtils::intToString(index).c_str());
+ xmlNewProp(vertex, C_ATTR_ELT_NAME, BAD_CAST elt.getName().c_str());
+ xmlNewProp(vertex, C_ATTR_ELT_REFERENCE, BAD_CAST elt.getReference().c_str());
+ }
+}
+
+void XaoExporter::exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao)
+{
+ // Geometric part
+ xmlNodePtr geometry = xmlNewChild(xao, 0, C_TAG_GEOMETRY, 0);
+ xmlNewProp(geometry, C_ATTR_GEOMETRY_NAME, BAD_CAST xaoGeometry->getName().c_str());
+
+ xmlNodePtr shape = xmlNewChild(geometry, 0, C_TAG_SHAPE, 0);
+ xmlNewProp(shape, C_ATTR_SHAPE_FORMAT, BAD_CAST XaoUtils::shapeFormatToString(xaoGeometry->getFormat()).c_str());
+ std::string txtShape = xaoGeometry->getShape();
+ xmlNodePtr cdata = xmlNewCDataBlock(doc, BAD_CAST txtShape.c_str(), txtShape.size());
+ xmlAddChild(shape, cdata);
+
+ xmlNodePtr topology = xmlNewChild(geometry, 0, C_TAG_TOPOLOGY, 0);
+
+ exportGeometricElements(xaoGeometry, topology, XAO::VERTEX, C_TAG_VERTICES, C_TAG_VERTEX);
+ exportGeometricElements(xaoGeometry, topology, XAO::EDGE, C_TAG_EDGES, C_TAG_EDGE);
+ exportGeometricElements(xaoGeometry, topology, XAO::FACE, C_TAG_FACES, C_TAG_FACE);
+ exportGeometricElements(xaoGeometry, topology, XAO::SOLID, C_TAG_SOLIDS, C_TAG_SOLID);
+}
+
+void XaoExporter::exportGroups(Xao* xaoObject, xmlNodePtr xao)
+{
+ xmlNodePtr groups = xmlNewChild(xao, 0, C_TAG_GROUPS, 0);
+ xmlNewProp(groups, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countGroups()).c_str());
+
+ for (int i = 0; i < xaoObject->countGroups(); i++)
+ {
+ //Group* grp = (*it);
+ Group* grp = xaoObject->getGroup(i);
+ xmlNodePtr group = xmlNewChild(groups, 0, C_TAG_GROUP, 0);
+ xmlNewProp(group, C_ATTR_GROUP_NAME, BAD_CAST grp->getName().c_str());
+ xmlNewProp(group, C_ATTR_GROUP_DIM, BAD_CAST XaoUtils::dimensionToString(grp->getDimension()).c_str());
+ xmlNewProp(group, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(grp->count()).c_str());
+
+ for (std::set<int>::iterator it = grp->begin(); it != grp->end(); ++it)
+ {
+ int grpElt = (*it);
+ xmlNodePtr elt = xmlNewChild(group, 0, C_TAG_ELEMENT, 0);
+ xmlNewProp(elt, C_ATTR_ELEMENT_INDEX, BAD_CAST XaoUtils::intToString(grpElt).c_str());
+ }
+ }
+}
+
+void XaoExporter::exportFields(Xao* xaoObject, xmlNodePtr xao)
+{
+ xmlNodePtr fields = xmlNewChild(xao, 0, C_TAG_FIELDS, 0);
+ xmlNewProp(fields, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countFields()).c_str());
+
+ for (int i = 0; i < xaoObject->countFields(); i++)
+ {
+ Field* field = xaoObject->getField(i);
+ xmlNodePtr nodeField = xmlNewChild(fields, 0, C_TAG_FIELD, 0);
+ xmlNewProp(nodeField, C_ATTR_FIELD_NAME, BAD_CAST field->getName().c_str());
+ xmlNewProp(nodeField, C_ATTR_FIELD_TYPE, BAD_CAST XaoUtils::fieldTypeToString(field->getType()).c_str());
+ xmlNewProp(nodeField, C_ATTR_FIELD_DIMENSION, BAD_CAST XaoUtils::dimensionToString(field->getDimension()).c_str());
+
+ int nbComponents = field->countComponents();
+ xmlNodePtr components = xmlNewChild(nodeField, 0, C_TAG_COMPONENTS, 0);
+ xmlNewProp(components, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(nbComponents).c_str());
+
+ for (int j = 0; j < nbComponents; j++)
+ {
+ xmlNodePtr nodeComponent = xmlNewChild(components, 0, C_TAG_COMPONENT, 0);
+ xmlNewProp(nodeComponent, C_ATTR_COMPONENT_COLUMN, BAD_CAST XaoUtils::intToString(j).c_str());
+ xmlNewProp(nodeComponent, C_ATTR_COMPONENT_NAME, BAD_CAST field->getComponentName(j).c_str());
+ }
+
+ int nbSteps = field->countSteps();
+ xmlNodePtr nodeSteps = xmlNewChild(nodeField, 0, C_TAG_STEPS, 0);
+ xmlNewProp(nodeSteps, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(nbSteps).c_str());
+ for (stepIterator itStep = field->begin(); itStep != field->end(); itStep++)
+ {
+ Step* step = *itStep;
+ exportStep(step, field, nodeSteps);
+ }
+ }
+}
+
+void XaoExporter::exportStep(Step* step, Field* field, xmlNodePtr nodeSteps)
+{
+ xmlNodePtr nodeStep = xmlNewChild(nodeSteps, 0, C_TAG_STEP, 0);
+ xmlNewProp(nodeStep, C_ATTR_STEP_NUMBER, BAD_CAST XaoUtils::intToString(step->getStep()).c_str());
+ if (step->getStamp() >= 0)
+ {
+ xmlNewProp(nodeStep, C_ATTR_STEP_STAMP, BAD_CAST XaoUtils::intToString(step->getStamp()).c_str());
+ }
+
+ for(int i = 0; i < step->countElements(); ++i)
+ {
+ xmlNodePtr nodeElt = xmlNewChild(nodeStep, 0, C_TAG_ELEMENT, 0);
+ xmlNewProp(nodeElt, C_ATTR_ELEMENT_INDEX, BAD_CAST XaoUtils::intToString(i).c_str());
+
+ for (int j = 0; j < step->countComponents(); ++j)
+ {
+ std::string content = step->getStringValue(i, j);
+ xmlNodePtr nodeValue= xmlNewTextChild(nodeElt, 0, C_TAG_VALUE, BAD_CAST content.c_str());
+ xmlNewProp(nodeValue, C_ATTR_VALUE_COMPONENT, BAD_CAST XaoUtils::intToString(j).c_str());
+ }
+ }
+}
+
+const bool XaoExporter::readFromFile(const std::string& fileName, Xao* xaoObject)
+{
+ // parse the file and get the DOM
+ int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
+ xmlDocPtr doc = xmlReadFile(fileName.c_str(), NULL, options);
+ if (doc == NULL)
+ {
+ throw SALOME_Exception("Cannot read XAO file");
+ }
+
+ parseXMLDoc(doc, xaoObject);
+ return true;
+}
+
+const bool XaoExporter::setXML(const std::string& xml, Xao* xaoObject)
+{
+ int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
+ xmlDocPtr doc = xmlReadDoc(BAD_CAST xml.c_str(), "", NULL, options);
+ if (doc == NULL)
+ {
+ throw SALOME_Exception("Cannot read XAO stream");
+ }
+
+ parseXMLDoc(doc, xaoObject);
+ return true;
+}
+
+void XaoExporter::parseXMLDoc(xmlDocPtr doc, Xao* xaoObject)
+{
+ // Get the root element node
+ xmlNodePtr root = xmlDocGetRootElement(doc);
+ if (xmlStrcmp(root->name , C_TAG_XAO) != 0)
+ throw SALOME_Exception("Cannot read XAO file: invalid format XAO node not found");
+
+ parseXaoNode(doc, root, xaoObject);
+
+ xmlFreeDoc(doc); // free document
+ xmlCleanupParser(); // free globals
+}
+
+void XaoExporter::parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject)
+{
+ std::string version = readStringProp(xaoNode, C_ATTR_XAO_VERSION, false, "");
+ if (version != "")
+ xaoObject->setAuthor(version);
+
+ std::string author = readStringProp(xaoNode, C_ATTR_XAO_AUTHOR, false, "");
+ xaoObject->setAuthor(author);
+
+ for (xmlNodePtr node = xaoNode->children; node; node = node->next)
+ {
+ if (xmlStrcmp(node->name, C_TAG_GEOMETRY) == 0)
+ parseGeometryNode(doc, node, xaoObject);
+ else if (xmlStrcmp(node->name, C_TAG_GROUPS) == 0)
+ parseGroupsNode(node, xaoObject);
+ else if (xmlStrcmp(node->name, C_TAG_FIELDS) == 0)
+ parseFieldsNode(node, xaoObject);
+ }
+}
+
+void XaoExporter::parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject)
+{
+ // get the shape and topo nodes
+ xmlNodePtr shapeNode = NULL;
+ xmlNodePtr topoNode = NULL;
+ for (xmlNodePtr node = geometryNode->children; node; node = node->next)
+ {
+ if (xmlStrcmp(node->name, C_TAG_SHAPE) == 0)
+ shapeNode = node;
+ else if (xmlStrcmp(node->name, C_TAG_TOPOLOGY) == 0)
+ topoNode = node;
+ }
+
+ std::string name = readStringProp(geometryNode, C_ATTR_GEOMETRY_NAME, false, "");
+ std::string strFormat = readStringProp(shapeNode, C_ATTR_SHAPE_FORMAT, true, "");
+ XAO::Format shapeFormat = XaoUtils::stringToShapeFormat(strFormat);
+ Geometry* geometry = Geometry::createGeometry(shapeFormat, name);
+
+ parseShapeNode(doc, shapeNode, geometry);
+ parseTopologyNode(topoNode, geometry);
+
+ xaoObject->setGeometry(geometry);
+}
+
+void XaoExporter::parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry)
+{
+ if (geometry->getFormat() == XAO::BREP)
+ {
+ xmlChar* data = xmlNodeGetContent(shapeNode->children);
+ if (data == NULL)
+ throw SALOME_Exception("Missing BREP");
+ geometry->setShape((char*)data);
+ xmlFree(data);
+ }
+ else
+ {
+ throw SALOME_Exception(MsgBuilder() << "Shape format not supported: "
+ << XaoUtils::shapeFormatToString(geometry->getFormat()));
+ }
+}
+
+void XaoExporter::parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry)
+{
+ for (xmlNodePtr node = topologyNode->children; node; node = node->next)
+ {
+ if (xmlStrcmp(node->name, C_TAG_VERTICES) == 0)
+ parseVerticesNode(node, geometry);
+ else if (xmlStrcmp(node->name, C_TAG_EDGES) == 0)
+ parseEdgesNode(node, geometry);
+ else if (xmlStrcmp(node->name, C_TAG_FACES) == 0)
+ parseFacesNode(node, geometry);
+ else if (xmlStrcmp(node->name, C_TAG_SOLIDS) == 0)
+ parseSolidsNode(node, geometry);
+ }
+}
+
+void XaoExporter::parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry)
+{
+ int count = readIntegerProp(verticesNode, C_ATTR_COUNT, true, -1);
+ geometry->setCountVertices(count);
+
+ for (xmlNodePtr node = verticesNode->children; node; node = node->next)
+ {
+ if (xmlStrcmp(node->name, C_TAG_VERTEX) == 0)
+ {
+ int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
+ std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
+ std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
+
+ geometry->setVertex(index, name, reference);
+ }
+ }
+}
+
+void XaoExporter::parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry)
+{
+ int count = readIntegerProp(edgesNode, C_ATTR_COUNT, true, -1);
+ geometry->setCountEdges(count);
+
+ for (xmlNodePtr node = edgesNode->children; node; node = node->next)
+ {
+ if (xmlStrcmp(node->name, C_TAG_EDGE) == 0)
+ {
+ int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
+ std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
+ std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
+
+ geometry->setEdge(index, name, reference);
+ }
+ }
+}
+
+void XaoExporter::parseFacesNode(xmlNodePtr facesNode, Geometry* geometry)
+{
+ int count = readIntegerProp(facesNode, C_ATTR_COUNT, true, -1);
+ geometry->setCountFaces(count);
+
+ for (xmlNodePtr node = facesNode->children; node; node = node->next)
+ {
+ if (xmlStrcmp(node->name, C_TAG_FACE) == 0)
+ {
+ int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
+ std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
+ std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
+
+ geometry->setFace(index, name, reference);
+ }
+ }
+}
+
+void XaoExporter::parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry)
+{
+ int count = readIntegerProp(solidsNode, C_ATTR_COUNT, true, -1);
+ geometry->setCountSolids(count);
+
+ for (xmlNodePtr node = solidsNode->children; node; node = node->next)
+ {
+ if (xmlStrcmp(node->name, C_TAG_SOLID) == 0)
+ {
+ int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
+ std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
+ std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
+
+ geometry->setSolid(index, name, reference);
+ }
+ }
+}
+
+void XaoExporter::parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject)
+{
+ for (xmlNodePtr node = groupsNode->children; node; node = node->next)
+ {
+ if (xmlStrcmp(node->name, C_TAG_GROUP) == 0)
+ {
+ parseGroupNode(node, xaoObject);
+ }
+ }
+}
+
+void XaoExporter::parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject)
+{
+ std::string strDimension = readStringProp(groupNode, C_ATTR_GROUP_DIM, true, "");
+ XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
+ Group* group = xaoObject->addGroup(dim);
+
+ std::string name = readStringProp(groupNode, C_ATTR_GROUP_NAME, false, "");
+ group->setName(name);
+
+ for (xmlNodePtr node = groupNode->children; node; node = node->next)
+ {
+ if (xmlStrcmp(node->name, C_TAG_ELEMENT) == 0)
+ {
+ int index = readIntegerProp(node, C_ATTR_ELEMENT_INDEX, true, -1);
+ group->add(index);
+ }
+ }
+}
+
+void XaoExporter::parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject)
+{
+ for (xmlNodePtr node = fieldsNode->children; node; node = node->next)
+ {
+ if (xmlStrcmp(node->name, C_TAG_FIELD) == 0)
+ {
+ parseFieldNode(node, xaoObject);
+ }
+ }
+}
+
+void XaoExporter::parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject)
+{
+ std::string strDimension = readStringProp(fieldNode, C_ATTR_FIELD_DIMENSION, true, "");
+ XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
+
+ std::string strType = readStringProp(fieldNode, C_ATTR_FIELD_TYPE, true, "");
+ XAO::Type type = XaoUtils::stringToFieldType(strType);
+
+ // we need to get the number of components first to create the field
+ xmlNodePtr componentsNode = NULL;
+ xmlNodePtr stepsNode = NULL;
+
+ for (xmlNodePtr node = fieldNode->children; node; node = node->next)
+ {
+ if (xmlStrcmp(node->name, C_TAG_COMPONENTS) == 0)
+ componentsNode = node;
+ else if (xmlStrcmp(node->name, C_TAG_STEPS) == 0)
+ stepsNode = node;
+ }
+
+ // ensure that the components node is defined
+ if (componentsNode == NULL)
+ {
+ throw SALOME_Exception(MsgBuilder() << "Line " << fieldNode->line << ": "
+ << "No components defined for field.");
+ }
+
+ // create the field
+ int nbComponents = readIntegerProp(componentsNode, C_ATTR_COUNT, true, -1);
+ Field* field = xaoObject->addField(type, dim, nbComponents);
+
+ // parse the components
+ for (xmlNodePtr compNode = componentsNode->children; compNode; compNode = compNode->next)
+ {
+ std::string compName= readStringProp(compNode, C_ATTR_COMPONENT_NAME, false, "");
+ if (compName.size() > 0)
+ {
+ int col = readIntegerProp(compNode, C_ATTR_COMPONENT_COLUMN, true, -1);
+ field->setComponentName(col, compName);
+ }
+ }
+
+ // set the name
+ std::string name = readStringProp(fieldNode, C_ATTR_FIELD_NAME, false, "");
+ if (name.size() > 0) field->setName(name);
+
+ // read the steps
+ if (stepsNode != 0)
+ {
+ for (xmlNodePtr stepNode = stepsNode->children; stepNode; stepNode = stepNode->next)
+ {
+ if (xmlStrcmp(stepNode->name, C_TAG_STEP) == 0)
+ {
+ parseStepNode(stepNode, field);
+ }
+ }
+ }
+}
+
+void XaoExporter::parseStepNode(xmlNodePtr stepNode, Field* field)
+{
+ int stepNumber = readIntegerProp(stepNode, C_ATTR_STEP_NUMBER, true, -1);
+ Step* step = field->addNewStep(stepNumber);
+
+ int stepStamp = readIntegerProp(stepNode, C_ATTR_STEP_STAMP, false, -1);
+ if (stepStamp != -1)
+ {
+ step->setStamp(stepStamp);
+ }
+
+ for (xmlNodePtr eltNode = stepNode->children; eltNode; eltNode = eltNode->next)
+ {
+ if (xmlStrcmp(eltNode->name, C_TAG_ELEMENT) == 0)
+ {
+ parseStepElementNode(eltNode, step);
+ }
+ }
+}
+
+void XaoExporter::parseStepElementNode(xmlNodePtr eltNode, Step* step)
+{
+ int index = readIntegerProp(eltNode, C_ATTR_ELT_INDEX, true, -1);
+
+ for (xmlNodePtr valNode = eltNode->children; valNode; valNode = valNode->next)
+ {
+ if (xmlStrcmp(valNode->name, C_TAG_VALUE) == 0)
+ {
+ int component = readIntegerProp(valNode, C_ATTR_VALUE_COMPONENT, true, -1);
+ xmlChar* data = xmlNodeGetContent(valNode->children);
+
+ if (data == NULL)
+ {
+ throw SALOME_Exception(MsgBuilder() << "Line " << valNode->line << ": no content for value.");
+ }
+
+ std::string value = (char*)data;
+ step->setStringValue(index, component, value);
+ }
+ }
+}
--- /dev/null
+
+#ifndef __XAO_XAOEXPORTER_HXX__
+#define __XAO_XAOEXPORTER_HXX__
+
+#include <libxml/parser.h>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Geometry.hxx"
+#include "XAO_Group.hxx"
+#include "XAO_Field.hxx"
+
+namespace XAO
+{
+ class XaoExporter
+ {
+ public:
+ static const bool saveToFile(Xao* xaoObject, const std::string& fileName);
+ static const std::string saveToXml(Xao* xaoObject);
+
+ static const bool readFromFile(const std::string& fileName, Xao* xaoObject);
+ static const bool setXML(const std::string& xml, Xao* xaoObject);
+
+ private:
+ static xmlDocPtr exportXMLDoc(Xao* xaoObject);
+ static void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao);
+ static void exportGeometricElements(Geometry* xaoGeometry, xmlNodePtr topology,
+ XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag);
+ static void exportGroups(Xao* xaoObject, xmlNodePtr xao);
+ static void exportFields(Xao* xaoObject, xmlNodePtr xao);
+ static void exportStep(Step* step, Field* field, xmlNodePtr nodeSteps);
+
+ static void parseXMLDoc(xmlDocPtr doc, Xao* xaoObject);
+ static void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject);
+ static void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject);
+ static void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry);
+ static void parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry);
+ static void parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry);
+ static void parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry);
+ static void parseFacesNode(xmlNodePtr facesNode, Geometry* geometry);
+ static void parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry);
+ static void parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject);
+ static void parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject);
+
+ static void parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject);
+ static void parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject);
+ static void parseStepNode(xmlNodePtr stepNode, Field* field);
+ static void parseStepElementNode(xmlNodePtr eltNode, Step* step);
+
+ static std::string readStringProp(xmlNodePtr node, const xmlChar* attribute,
+ const bool& required, const std::string& defaultValue, const std::string& exception = std::string(""));
+ static int readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
+ const bool& required, const int& defaultValue, const std::string& exception = std::string(""));
+ };
+}
+
+
+#endif /* __XAO_XAOEXPORTER_HXX__ */
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#include <cstring>
+#include <sstream>
+#include <iosfwd>
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XAO_Xao.hxx"
+#include "XAO_XaoUtils.hxx"
+
+using namespace XAO;
+
+
+const std::string XaoUtils::intToString(const int& value)
+{
+ std::ostringstream str;
+ str << value;
+ return str.str();
+}
+
+const int XaoUtils::stringToInt(const std::string& value)
+{
+ int res;
+ std::istringstream convert(value);
+ if ( !(convert >> res) )
+ throw SALOME_Exception(MsgBuilder() << "Cannot convert '" << value << "' to integer.");
+ return res;
+}
+
+const std::string XaoUtils::doubleToString(const double& value)
+{
+ std::ostringstream str;
+ str << value;
+ return str.str();
+}
+
+const double XaoUtils::stringToDouble(const std::string& value)
+{
+ double res;
+ std::istringstream convert(value);
+ if ( !(convert >> res) )
+ throw SALOME_Exception(MsgBuilder() << "Cannot convert '" << value << "' to double.");
+ return res;
+}
+
+const std::string XaoUtils::booleanToString(const bool& value)
+{
+ if (value)
+ return "true";
+ return "false";
+}
+
+const bool XaoUtils::stringToBoolean(const std::string& value)
+{
+ if (value == "true" || value == "1")
+ return true;
+ if (value == "false" || value == "0")
+ return false;
+
+ throw SALOME_Exception(MsgBuilder() << "Invalid boolean value: " << value);
+}
+
+const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
+{
+ if (dimension == XAO::VERTEX)
+ return "vertex";
+ if (dimension == XAO::EDGE)
+ return "edge";
+ if (dimension == XAO::FACE)
+ return "face";
+ if (dimension == XAO::SOLID)
+ return "solid";
+ if (dimension == XAO::WHOLE)
+ return "whole";
+
+ throw SALOME_Exception(MsgBuilder() << "Bad dimension: " << dimension);
+}
+
+const XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension)
+{
+ if (dimension == "vertex")
+ return XAO::VERTEX;
+ if (dimension == "edge")
+ return XAO::EDGE;
+ if (dimension == "face")
+ return XAO::FACE;
+ if (dimension == "solid")
+ return XAO::SOLID;
+ if (dimension == "whole")
+ return XAO::WHOLE;
+
+ throw SALOME_Exception(MsgBuilder() << "Bad dimension: " << dimension);
+}
+
+const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
+{
+ if (type ==XAO:: BOOLEAN)
+ return "boolean";
+ if (type == XAO::INTEGER)
+ return "integer";
+ if (type == XAO::DOUBLE)
+ return "double";
+ if (type == XAO::STRING)
+ return "string";
+
+ throw SALOME_Exception(MsgBuilder() << "Bad type: " << type);
+}
+
+const XAO::Type XaoUtils::stringToFieldType(const std::string& type)
+{
+ if (type == "boolean")
+ return XAO::BOOLEAN;
+ if (type == "integer")
+ return XAO::INTEGER;
+ if (type == "double")
+ return XAO::DOUBLE;
+ if (type == "string")
+ return XAO::STRING;
+
+ throw SALOME_Exception(MsgBuilder() << "Bad type: " << type);
+}
+
+const std::string XaoUtils::shapeFormatToString(const XAO::Format& format)
+{
+ if (format == XAO::BREP)
+ return "BREP";
+ if (format == XAO::STEP)
+ return "STEP";
+
+ throw SALOME_Exception(MsgBuilder() << "Bad format: " << format);
+}
+
+const XAO::Format XaoUtils::stringToShapeFormat(const std::string& format)
+{
+ if (format == "BREP")
+ return XAO::BREP;
+ if (format == "STEP")
+ return XAO::STEP;
+
+ throw SALOME_Exception(MsgBuilder() << "Bad format: " << format);
+}
--- /dev/null
+// Copyright (C) 2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Frederic Pons (OpenCascade)
+
+#ifndef __XAO_UTILS_HXX__
+#define __XAO_UTILS_HXX__
+
+#include <sstream>
+#include <string>
+
+#include "XAO_Xao.hxx"
+#include "XAO_Field.hxx"
+
+namespace XAO
+{
+ /**
+ * \class XaoUtils
+ * Utilities class to convert types.
+ */
+ class XaoUtils
+ {
+ public:
+ /**
+ * Converts an integer into a string.
+ * \param value the integer to convert.
+ * \return the string.
+ */
+ static const std::string intToString(const int& value);
+
+ /**
+ * Converts a string into an integer.
+ * \param value the string to convert.
+ * \return the integer value.
+ */
+ static const int stringToInt(const std::string& value);
+
+ /**
+ * Converts a double into a string.
+ * @param value the double to convert.
+ * @return the string.
+ */
+ static const std::string doubleToString(const double& value);
+ /**
+ * Converts a string into a double.
+ * @param value the string to convert.
+ * @return the double value.
+ */
+ static const double stringToDouble(const std::string& value);
+
+ /**
+ * Converts a boolean into a string.
+ * @param value the boolean to convert.
+ * @return the string.
+ */
+ static const std::string booleanToString(const bool& value);
+ /**
+ * Converts a string into a boolean.
+ * @param value the string to convert.
+ * @return the boolean value.
+ */
+ static const bool stringToBoolean(const std::string& value);
+
+ /**
+ * Converts a Dimension to string.
+ * \param dimension the Dimension to convert.
+ * \return the dimension as a string.
+ * \throw SALOME_Exception
+ */
+ static const std::string dimensionToString(const XAO::Dimension& dimension);
+
+ /**
+ * Converts a string into a Dimension.
+ * \param dimension the dimension as a string.
+ * \return the converted Dimension.
+ * \throw SALOME_Exception
+ */
+ static const XAO::Dimension stringToDimension(const std::string& dimension);
+
+ /**
+ * Converts a Type to string.
+ * \param type the Type to convert.
+ * \return the Type as a string.
+ * \throw SALOME_Exception
+ */
+ static const std::string fieldTypeToString(const XAO::Type& type);
+
+ /**
+ * Converts a string into a Type.
+ * \param type the Type as a string.
+ * \return the converted Type.
+ * \throw SALOME_Exception
+ */
+ static const XAO::Type stringToFieldType(const std::string& type);
+
+ /**
+ * Converts a Format to string.
+ * \param format the Format to convert.
+ * \return the Format as a string.
+ * \throw SALOME_Exception
+ */
+ static const std::string shapeFormatToString(const XAO::Format& format);
+
+ /**
+ * Converts a string into a Format.
+ * \param format the Format as a string.
+ * \return the converted Format.
+ * \throw SALOME_Exception
+ */
+ static const XAO::Format stringToShapeFormat(const std::string& format);
+ };
+
+ class MsgBuilder
+ {
+ public:
+ MsgBuilder() {};
+
+ template <typename T>
+ MsgBuilder& operator <<(const T& t)
+ {
+ m_stream << t;
+ return *this;
+ }
+
+ operator const char*() const { return m_stream.str().c_str(); }
+
+ private :
+ std::stringstream m_stream;
+ };
+
+}
+
+
+
+#endif /* __XAO_UTILS_HXX__ */
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
-
-#include <libxml/parser.h>
-
-#include "XaoUtils.hxx"
-#include "Xao.hxx"
-#include "Geometry.hxx"
-#include "Group.hxx"
-#include "Field.hxx"
-#include "XaoExporter.hxx"
-#include <Utils_SALOME_Exception.hxx>
-
-using namespace XAO;
-
-const xmlChar* C_XAO_VERSION = (xmlChar*)"1.0";
-
-Xao::Xao()
-{
- m_author = "";
- m_version = (char*)C_XAO_VERSION;
- m_geometry = NULL;
-}
-
-Xao::Xao(const std::string& author, const std::string& version)
-{
- m_author = author;
- m_version = version;
- m_geometry = NULL;
-}
-
-Xao::~Xao()
-{
- if (m_geometry != NULL)
- {
- delete m_geometry;
- m_geometry = NULL;
- }
-
- for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it)
- {
- delete (*it);
- }
-
- for (std::list<Field*>::iterator it = m_fields.begin(); it != m_fields.end(); ++it)
- {
- delete (*it);
- }
-}
-
-const int Xao::countGroups() const
-{
- return m_groups.size();
-}
-
-Group* Xao::getGroup(const int& index)
-{
- int i = 0;
- for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it, ++i)
- {
- if (i == index)
- return (*it);
- }
-
- return NULL;
-}
-
-Group* Xao::addGroup(const XAO::Dimension& dim)
-{
- return addGroup("", dim);
-}
-
-Group* Xao::addGroup(const std::string& name, const XAO::Dimension& dim)
-{
- checkGeometry();
- Group* group = new Group(name, dim, m_geometry->countElements(dim));
- m_groups.push_back(group);
- return group;
-}
-
-void Xao::removeGroup(Group* group)
-{
- m_groups.remove(group);
-}
-
-const int Xao::countFields() const
-{
- return m_fields.size();
-}
-
-Field* Xao::getField(const int& index)
-{
- int i = 0;
- for (std::list<Field*>::iterator it = m_fields.begin(); it != m_fields.end(); ++it, ++i)
- {
- if (i == index)
- return (*it);
- }
-
- return NULL;
-}
-
-Field* Xao::addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents)
-{
- return addField(type, "", dim, nbComponents);
-}
-
-Field* Xao::addField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dim, const int& nbComponents)
-{
- checkGeometry();
- int nbElts = m_geometry->countElements(dim);
- Field* field = Field::createField(type, name, dim, nbElts, nbComponents);
- m_fields.push_back(field);
- return field;
-}
-
-void Xao::removeField(Field* field)
-{
- m_fields.remove(field);
-}
-
-const bool Xao::exportXAO(const std::string& fileName)
-{
- return XaoExporter::saveToFile(this, fileName);
-}
-
-const std::string Xao::getXML()
-{
- return XaoExporter::saveToXml(this);
-}
-
-const bool Xao::importXAO(const std::string& fileName)
-{
- return XaoExporter::readFromFile(fileName, this);
-}
-
-const bool Xao::setXML(const std::string& xml)
-{
- return XaoExporter::setXML(xml, this);
-}
-
-void Xao::checkGeometry() const
-{
- if (m_geometry == NULL)
- throw SALOME_Exception("Geometry is null");
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
-
-#ifndef __XAO_XAO_HXX__
-#define __XAO_XAO_HXX__
-
-#include <string>
-#include <list>
-#include <libxml/parser.h>
-
-namespace XAO
-{
- /**
- * @enum CAD
- */
- enum Format
- {
- BREP,
- STEP
- };
-
- /**
- * @enum Dimension
- */
- enum Dimension
- {
- VERTEX = 0,//!< VERTEX
- EDGE = 1, //!< EDGE
- FACE = 2, //!< FACE
- SOLID = 3, //!< SOLID
- WHOLE = -1 //!< WHOLE
- };
-
- /**
- * @enum Type
- */
- enum Type
- {
- BOOLEAN = 0,//!< BOOLEAN
- INTEGER = 1,//!< INTEGER
- DOUBLE = 2, //!< DOUBLE
- STRING = 3 //!< STRING
- };
-
- class Geometry;
- class Group;
- class Field;
-
- /**
- * @class Xao
- * The Xao class describes the XAO format.
- */
- class Xao
- {
- public:
- /**
- * Default constructor.
- */
- Xao();
- /**
- * Constructor with author and version.
- * \param author the author of the file.
- * \param version the version of the XAO format.
- */
- Xao(const std::string& author, const std::string& version);
- /**
- * Destructor.
- */
- virtual ~Xao();
-
- /**
- * Gets the author of the file.
- * \return the author of the file.
- */
- const std::string getAuthor() const
- {
- return m_author;
- }
- /**
- * Sets the author of the file.
- * \param author the author to set.
- */
- void setAuthor(const std::string& author)
- {
- m_author = author;
- }
-
- /**
- * Gets the version of the file.
- * \return the version of the file.
- */
- const std::string getVersion() const
- {
- return m_version;
- }
- /**
- * Sets the version of the file.
- * \param version the version to set.
- */
- void setVersion(const std::string& version)
- {
- m_version = version;
- }
-
- //
- // Geometry
- //
-
- /**
- * Gets the geometry.
- * \return the geometry.
- */
- Geometry* getGeometry() const
- {
- return m_geometry;
- }
- /**
- * Sets the geometry.
- * \param geometry the geometry to set.
- */
- void setGeometry(Geometry* geometry)
- {
- m_geometry = geometry;
- }
-
- //
- // Groups
- //
-
- /**
- * Gets the number of groups.
- * \return the number of groups.
- */
- const int countGroups() const;
- /**
- * Gets a group.
- * \param index the index of the wanted group.
- * \return the group or NULL if index is bigger than the number of groups.
- */
- Group* getGroup(const int& index);
- /**
- * Adds a group.
- * \param dim the dimension of the group.
- * \return the created group.
- */
- Group* addGroup(const XAO::Dimension& dim);
- /**
- * Adds a group.
- * \param name the name of the group.
- * \param dim the dimension of the group.
- * \return the created group.
- */
- Group* addGroup(const std::string& name, const XAO::Dimension& dim);
- /**
- * Removes a group.
- * \param group the group to remove.
- */
- void removeGroup(Group* group);
-
- //
- // Fields
- //
-
- /**
- * Gets the number of fields.
- * \return the number of fields.
- */
- const int countFields() const;
- /**
- * Gets a field.
- * \param index the index of the wanted field.
- * \return the field or NULL if the index is bigger than the number of fields.
- */
- Field* getField(const int& index);
- /**
- * Adds a field.
- * \param type the type of the field.
- * \param dim the dimension of the field.
- * \param nbComponents the number of components in the field.
- * \return the created field.
- */
- Field* addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents);
- /**
- * Adds a field.
- * \param type the type of the field.
- * \param the name of the field.
- * \param dim the dimension of the field.
- * \param nbComponents the number of components in the field.
- * \return the created field.
- */
- Field* addField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dim, const int& nbComponents);
- /**
- * Removes a field.
- * \param field the field to remove.
- */
- void removeField(Field* field);
-
- //
- // Import / Export
- //
- /**
- * Exports this XAO object to a file.
- * \param fileName the name of the file to create.
- * \return true is the export is successful.
- */
- const bool exportXAO(const std::string& fileName);
- /**
- * Gets the XML corresponding to this XAO.
- * \return the XML as a string.
- */
- const std::string getXML();
-
- /**
- * Imports an XAO file into this object.
- * \param fileName the name of the file to import.
- * \return true if the import is successful.
- */
- const bool importXAO(const std::string& fileName);
- /**
- * Sets an XML describing an XAO format to this object.
- * \param xml the XML to set.
- * \return true if the import is successful.
- */
- const bool setXML(const std::string& xml);
-
- private:
- void checkGeometry() const;
-
- private:
- /** The author of the file. */
- std::string m_author;
- /** The version of the file. */
- std::string m_version;
- /** The geometry. */
- Geometry* m_geometry;
- /** The list of groups. */
- std::list<Group*> m_groups;
- /** The list of fields. */
- std::list<Field*> m_fields;
- };
-
-}
-
-#endif
+++ /dev/null
-
-#include <libxml/parser.h>
-#include <Utils_SALOME_Exception.hxx>
-
-#include "XaoExporter.hxx"
-#include "Xao.hxx"
-#include "Geometry.hxx"
-#include "Group.hxx"
-#include "Field.hxx"
-#include "Step.hxx"
-#include "BooleanStep.hxx"
-#include "IntegerStep.hxx"
-#include "DoubleStep.hxx"
-#include "StringStep.hxx"
-#include "XaoUtils.hxx"
-
-namespace XAO
-{
- const xmlChar* C_TAG_XAO = (xmlChar*)"XAO";
- const xmlChar* C_ATTR_XAO_AUTHOR = (xmlChar*)"author";
- const xmlChar* C_ATTR_XAO_VERSION = (xmlChar*)"version";
-
- const xmlChar* C_TAG_GEOMETRY = (xmlChar*)"geometry";
- const xmlChar* C_ATTR_GEOMETRY_NAME = (xmlChar*)"name";
-
- const xmlChar* C_TAG_SHAPE = (xmlChar*)"shape";
- const xmlChar* C_ATTR_SHAPE_FORMAT = (xmlChar*)"format";
-
- const xmlChar* C_TAG_TOPOLOGY = (xmlChar*)"topology";
- const xmlChar* C_TAG_VERTICES = (xmlChar*)"vertices";
- const xmlChar* C_TAG_VERTEX = (xmlChar*)"vertex";
- const xmlChar* C_TAG_EDGES = (xmlChar*)"edges";
- const xmlChar* C_TAG_EDGE = (xmlChar*)"edge";
- const xmlChar* C_TAG_FACES = (xmlChar*)"faces";
- const xmlChar* C_TAG_FACE = (xmlChar*)"face";
- const xmlChar* C_TAG_SOLIDS = (xmlChar*)"solids";
- const xmlChar* C_TAG_SOLID = (xmlChar*)"solid";
- const xmlChar* C_ATTR_COUNT = (xmlChar*)"count";
- const xmlChar* C_ATTR_ELT_INDEX = (xmlChar*)"index";
- const xmlChar* C_ATTR_ELT_NAME = (xmlChar*)"name";
- const xmlChar* C_ATTR_ELT_REFERENCE = (xmlChar*)"reference";
-
- const xmlChar* C_TAG_GROUPS = (xmlChar*)"groups";
- const xmlChar* C_TAG_GROUP = (xmlChar*)"group";
- const xmlChar* C_ATTR_GROUP_NAME = (xmlChar*)"name";
- const xmlChar* C_ATTR_GROUP_DIM = (xmlChar*)"dimension";
-
- const xmlChar* C_TAG_ELEMENT = (xmlChar*)"element";
- const xmlChar* C_ATTR_ELEMENT_INDEX = (xmlChar*)"index";
- const xmlChar* C_TAG_VALUE = (xmlChar*)"value";
- const xmlChar* C_ATTR_VALUE_COMPONENT = (xmlChar*)"component";
-
- const xmlChar* C_TAG_FIELDS = (xmlChar*)"fields";
- const xmlChar* C_TAG_FIELD = (xmlChar*)"field";
- const xmlChar* C_ATTR_FIELD_NAME = (xmlChar*)"name";
- const xmlChar* C_ATTR_FIELD_TYPE = (xmlChar*)"type";
- const xmlChar* C_ATTR_FIELD_DIMENSION = (xmlChar*)"dimension";
- const xmlChar* C_TAG_COMPONENTS = (xmlChar*)"components";
- const xmlChar* C_TAG_COMPONENT = (xmlChar*)"component";
- const xmlChar* C_ATTR_COMPONENT_COLUMN = (xmlChar*)"column";
- const xmlChar* C_ATTR_COMPONENT_NAME = (xmlChar*)"name";
-
- const xmlChar* C_TAG_STEPS = (xmlChar*)"steps";
- const xmlChar* C_TAG_STEP = (xmlChar*)"step";
- const xmlChar* C_ATTR_STEP_NUMBER = (xmlChar*)"number";
- const xmlChar* C_ATTR_STEP_STAMP = (xmlChar*)"stamp";
-}
-
-using namespace XAO;
-
-std::string XaoExporter::readStringProp(xmlNodePtr node, const xmlChar* attribute,
- const bool& required, const std::string& defaultValue,
- const std::string& exception /*= std::string() */)
-{
- xmlChar* strAttr = xmlGetProp(node, attribute);
- if (strAttr == NULL)
- {
- if (required)
- {
- if (exception.size() > 0)
- throw SALOME_Exception(exception.c_str());
-
- throw SALOME_Exception(MsgBuilder() << "Line " << node->line << ": "
- << "Property " << (char*)attribute << " is required.");
- }
-
- return defaultValue;
- }
-
- std::string res = (char*)strAttr;
- xmlFree(strAttr);
- return res;
-}
-
-int XaoExporter::readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
- const bool& required, const int& defaultValue,
- const std::string& exception /*= std::string() */)
-{
- xmlChar* strAttr = xmlGetProp(node, attribute);
- if (strAttr == NULL)
- {
- if (required)
- {
- if (exception.size() > 0)
- throw SALOME_Exception(exception.c_str());
-
- throw SALOME_Exception(MsgBuilder() << "Line " << node->line << ": "
- << "Property " << (char*)attribute << " is required.");
- }
-
- return defaultValue;
- }
-
- int res = XaoUtils::stringToInt((char*)strAttr);
- xmlFree(strAttr);
- return res;
-}
-
-const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName)
-{
- xmlDocPtr doc = exportXMLDoc(xaoObject);
- xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 2);
- xmlFreeDoc(doc);
-
- return true;
-}
-
-const std::string XaoExporter::saveToXml(Xao* xaoObject)
-{
- xmlDocPtr doc = exportXMLDoc(xaoObject);
-
- xmlChar *xmlbuff;
- int buffersize;
- xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
- xmlFreeDoc(doc);
- xmlCleanupGlobals();
-
- return (char*)xmlbuff;
-}
-
-xmlDocPtr XaoExporter::exportXMLDoc(Xao* xaoObject)
-{
- // Creating the Xml document
- xmlDocPtr masterDocument = xmlNewDoc(BAD_CAST "1.0");
- xmlNodePtr xao = xmlNewNode(0, C_TAG_XAO);
- xmlDocSetRootElement(masterDocument, xao);
-
- xmlNewProp(xao, C_ATTR_XAO_VERSION, BAD_CAST xaoObject->getVersion().c_str());
- xmlNewProp(xao, C_ATTR_XAO_AUTHOR, BAD_CAST xaoObject->getAuthor().c_str());
-
- if (xaoObject->getGeometry() != NULL)
- {
- exportGeometry(xaoObject->getGeometry(), masterDocument, xao);
- }
-
- exportGroups(xaoObject, xao);
- exportFields(xaoObject, xao);
-
- return masterDocument;
-}
-
-void XaoExporter::exportGeometricElements(Geometry* xaoGeometry,
- xmlNodePtr topology, XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag)
-{
- xmlNodePtr vertices = xmlNewChild(topology, 0, colTag, 0);
- xmlNewProp(vertices, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoGeometry->countElements(dim)).c_str());
- GeometricElementList::iterator it = xaoGeometry->begin(dim);
- for (; it != xaoGeometry->end(dim); it++)
- {
- int index = it->first;
- GeometricElement elt = it->second;
- xmlNodePtr vertex = xmlNewChild(vertices, 0, eltTag, 0);
- xmlNewProp(vertex, C_ATTR_ELT_INDEX, BAD_CAST XaoUtils::intToString(index).c_str());
- xmlNewProp(vertex, C_ATTR_ELT_NAME, BAD_CAST elt.getName().c_str());
- xmlNewProp(vertex, C_ATTR_ELT_REFERENCE, BAD_CAST elt.getReference().c_str());
- }
-}
-
-void XaoExporter::exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao)
-{
- // Geometric part
- xmlNodePtr geometry = xmlNewChild(xao, 0, C_TAG_GEOMETRY, 0);
- xmlNewProp(geometry, C_ATTR_GEOMETRY_NAME, BAD_CAST xaoGeometry->getName().c_str());
-
- xmlNodePtr shape = xmlNewChild(geometry, 0, C_TAG_SHAPE, 0);
- xmlNewProp(shape, C_ATTR_SHAPE_FORMAT, BAD_CAST XaoUtils::shapeFormatToString(xaoGeometry->getFormat()).c_str());
- std::string txtShape = xaoGeometry->getShape();
- xmlNodePtr cdata = xmlNewCDataBlock(doc, BAD_CAST txtShape.c_str(), txtShape.size());
- xmlAddChild(shape, cdata);
-
- xmlNodePtr topology = xmlNewChild(geometry, 0, C_TAG_TOPOLOGY, 0);
-
- exportGeometricElements(xaoGeometry, topology, XAO::VERTEX, C_TAG_VERTICES, C_TAG_VERTEX);
- exportGeometricElements(xaoGeometry, topology, XAO::EDGE, C_TAG_EDGES, C_TAG_EDGE);
- exportGeometricElements(xaoGeometry, topology, XAO::FACE, C_TAG_FACES, C_TAG_FACE);
- exportGeometricElements(xaoGeometry, topology, XAO::SOLID, C_TAG_SOLIDS, C_TAG_SOLID);
-}
-
-void XaoExporter::exportGroups(Xao* xaoObject, xmlNodePtr xao)
-{
- xmlNodePtr groups = xmlNewChild(xao, 0, C_TAG_GROUPS, 0);
- xmlNewProp(groups, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countGroups()).c_str());
-
- for (int i = 0; i < xaoObject->countGroups(); i++)
- {
- //Group* grp = (*it);
- Group* grp = xaoObject->getGroup(i);
- xmlNodePtr group = xmlNewChild(groups, 0, C_TAG_GROUP, 0);
- xmlNewProp(group, C_ATTR_GROUP_NAME, BAD_CAST grp->getName().c_str());
- xmlNewProp(group, C_ATTR_GROUP_DIM, BAD_CAST XaoUtils::dimensionToString(grp->getDimension()).c_str());
- xmlNewProp(group, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(grp->count()).c_str());
-
- for (std::set<int>::iterator it = grp->begin(); it != grp->end(); ++it)
- {
- int grpElt = (*it);
- xmlNodePtr elt = xmlNewChild(group, 0, C_TAG_ELEMENT, 0);
- xmlNewProp(elt, C_ATTR_ELEMENT_INDEX, BAD_CAST XaoUtils::intToString(grpElt).c_str());
- }
- }
-}
-
-void XaoExporter::exportFields(Xao* xaoObject, xmlNodePtr xao)
-{
- xmlNodePtr fields = xmlNewChild(xao, 0, C_TAG_FIELDS, 0);
- xmlNewProp(fields, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countFields()).c_str());
-
- for (int i = 0; i < xaoObject->countFields(); i++)
- {
- Field* field = xaoObject->getField(i);
- xmlNodePtr nodeField = xmlNewChild(fields, 0, C_TAG_FIELD, 0);
- xmlNewProp(nodeField, C_ATTR_FIELD_NAME, BAD_CAST field->getName().c_str());
- xmlNewProp(nodeField, C_ATTR_FIELD_TYPE, BAD_CAST XaoUtils::fieldTypeToString(field->getType()).c_str());
- xmlNewProp(nodeField, C_ATTR_FIELD_DIMENSION, BAD_CAST XaoUtils::dimensionToString(field->getDimension()).c_str());
-
- int nbComponents = field->countComponents();
- xmlNodePtr components = xmlNewChild(nodeField, 0, C_TAG_COMPONENTS, 0);
- xmlNewProp(components, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(nbComponents).c_str());
-
- for (int j = 0; j < nbComponents; j++)
- {
- xmlNodePtr nodeComponent = xmlNewChild(components, 0, C_TAG_COMPONENT, 0);
- xmlNewProp(nodeComponent, C_ATTR_COMPONENT_COLUMN, BAD_CAST XaoUtils::intToString(j).c_str());
- xmlNewProp(nodeComponent, C_ATTR_COMPONENT_NAME, BAD_CAST field->getComponentName(j).c_str());
- }
-
- int nbSteps = field->countSteps();
- xmlNodePtr nodeSteps = xmlNewChild(nodeField, 0, C_TAG_STEPS, 0);
- xmlNewProp(nodeSteps, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(nbSteps).c_str());
- for (stepIterator itStep = field->begin(); itStep != field->end(); itStep++)
- {
- Step* step = *itStep;
- exportStep(step, field, nodeSteps);
- }
- }
-}
-
-void XaoExporter::exportStep(Step* step, Field* field, xmlNodePtr nodeSteps)
-{
- xmlNodePtr nodeStep = xmlNewChild(nodeSteps, 0, C_TAG_STEP, 0);
- xmlNewProp(nodeStep, C_ATTR_STEP_NUMBER, BAD_CAST XaoUtils::intToString(step->getStep()).c_str());
- if (step->getStamp() >= 0)
- {
- xmlNewProp(nodeStep, C_ATTR_STEP_STAMP, BAD_CAST XaoUtils::intToString(step->getStamp()).c_str());
- }
-
- for(int i = 0; i < step->countElements(); ++i)
- {
- xmlNodePtr nodeElt = xmlNewChild(nodeStep, 0, C_TAG_ELEMENT, 0);
- xmlNewProp(nodeElt, C_ATTR_ELEMENT_INDEX, BAD_CAST XaoUtils::intToString(i).c_str());
-
- for (int j = 0; j < step->countComponents(); ++j)
- {
- std::string content = step->getStringValue(i, j);
- xmlNodePtr nodeValue= xmlNewTextChild(nodeElt, 0, C_TAG_VALUE, BAD_CAST content.c_str());
- xmlNewProp(nodeValue, C_ATTR_VALUE_COMPONENT, BAD_CAST XaoUtils::intToString(j).c_str());
- }
- }
-}
-
-const bool XaoExporter::readFromFile(const std::string& fileName, Xao* xaoObject)
-{
- // parse the file and get the DOM
- int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
- xmlDocPtr doc = xmlReadFile(fileName.c_str(), NULL, options);
- if (doc == NULL)
- {
- throw SALOME_Exception("Cannot read XAO file");
- }
-
- parseXMLDoc(doc, xaoObject);
- return true;
-}
-
-const bool XaoExporter::setXML(const std::string& xml, Xao* xaoObject)
-{
- int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
- xmlDocPtr doc = xmlReadDoc(BAD_CAST xml.c_str(), "", NULL, options);
- if (doc == NULL)
- {
- throw SALOME_Exception("Cannot read XAO stream");
- }
-
- parseXMLDoc(doc, xaoObject);
- return true;
-}
-
-void XaoExporter::parseXMLDoc(xmlDocPtr doc, Xao* xaoObject)
-{
- // Get the root element node
- xmlNodePtr root = xmlDocGetRootElement(doc);
- if (xmlStrcmp(root->name , C_TAG_XAO) != 0)
- throw SALOME_Exception("Cannot read XAO file: invalid format XAO node not found");
-
- parseXaoNode(doc, root, xaoObject);
-
- xmlFreeDoc(doc); // free document
- xmlCleanupParser(); // free globals
-}
-
-void XaoExporter::parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject)
-{
- std::string version = readStringProp(xaoNode, C_ATTR_XAO_VERSION, false, "");
- if (version != "")
- xaoObject->setAuthor(version);
-
- std::string author = readStringProp(xaoNode, C_ATTR_XAO_AUTHOR, false, "");
- xaoObject->setAuthor(author);
-
- for (xmlNodePtr node = xaoNode->children; node; node = node->next)
- {
- if (xmlStrcmp(node->name, C_TAG_GEOMETRY) == 0)
- parseGeometryNode(doc, node, xaoObject);
- else if (xmlStrcmp(node->name, C_TAG_GROUPS) == 0)
- parseGroupsNode(node, xaoObject);
- else if (xmlStrcmp(node->name, C_TAG_FIELDS) == 0)
- parseFieldsNode(node, xaoObject);
- }
-}
-
-void XaoExporter::parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject)
-{
- // get the shape and topo nodes
- xmlNodePtr shapeNode = NULL;
- xmlNodePtr topoNode = NULL;
- for (xmlNodePtr node = geometryNode->children; node; node = node->next)
- {
- if (xmlStrcmp(node->name, C_TAG_SHAPE) == 0)
- shapeNode = node;
- else if (xmlStrcmp(node->name, C_TAG_TOPOLOGY) == 0)
- topoNode = node;
- }
-
- std::string name = readStringProp(geometryNode, C_ATTR_GEOMETRY_NAME, false, "");
- std::string strFormat = readStringProp(shapeNode, C_ATTR_SHAPE_FORMAT, true, "");
- XAO::Format shapeFormat = XaoUtils::stringToShapeFormat(strFormat);
- Geometry* geometry = Geometry::createGeometry(shapeFormat, name);
-
- parseShapeNode(doc, shapeNode, geometry);
- parseTopologyNode(topoNode, geometry);
-
- xaoObject->setGeometry(geometry);
-}
-
-void XaoExporter::parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry)
-{
- if (geometry->getFormat() == XAO::BREP)
- {
- xmlChar* data = xmlNodeGetContent(shapeNode->children);
- if (data == NULL)
- throw SALOME_Exception("Missing BREP");
- geometry->setShape((char*)data);
- xmlFree(data);
- }
- else
- {
- throw SALOME_Exception(MsgBuilder() << "Shape format not supported: "
- << XaoUtils::shapeFormatToString(geometry->getFormat()));
- }
-}
-
-void XaoExporter::parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry)
-{
- for (xmlNodePtr node = topologyNode->children; node; node = node->next)
- {
- if (xmlStrcmp(node->name, C_TAG_VERTICES) == 0)
- parseVerticesNode(node, geometry);
- else if (xmlStrcmp(node->name, C_TAG_EDGES) == 0)
- parseEdgesNode(node, geometry);
- else if (xmlStrcmp(node->name, C_TAG_FACES) == 0)
- parseFacesNode(node, geometry);
- else if (xmlStrcmp(node->name, C_TAG_SOLIDS) == 0)
- parseSolidsNode(node, geometry);
- }
-}
-
-void XaoExporter::parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry)
-{
- int count = readIntegerProp(verticesNode, C_ATTR_COUNT, true, -1);
- geometry->setCountVertices(count);
-
- for (xmlNodePtr node = verticesNode->children; node; node = node->next)
- {
- if (xmlStrcmp(node->name, C_TAG_VERTEX) == 0)
- {
- int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
- std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
- std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
-
- geometry->setVertex(index, name, reference);
- }
- }
-}
-
-void XaoExporter::parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry)
-{
- int count = readIntegerProp(edgesNode, C_ATTR_COUNT, true, -1);
- geometry->setCountEdges(count);
-
- for (xmlNodePtr node = edgesNode->children; node; node = node->next)
- {
- if (xmlStrcmp(node->name, C_TAG_EDGE) == 0)
- {
- int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
- std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
- std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
-
- geometry->setEdge(index, name, reference);
- }
- }
-}
-
-void XaoExporter::parseFacesNode(xmlNodePtr facesNode, Geometry* geometry)
-{
- int count = readIntegerProp(facesNode, C_ATTR_COUNT, true, -1);
- geometry->setCountFaces(count);
-
- for (xmlNodePtr node = facesNode->children; node; node = node->next)
- {
- if (xmlStrcmp(node->name, C_TAG_FACE) == 0)
- {
- int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
- std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
- std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
-
- geometry->setFace(index, name, reference);
- }
- }
-}
-
-void XaoExporter::parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry)
-{
- int count = readIntegerProp(solidsNode, C_ATTR_COUNT, true, -1);
- geometry->setCountSolids(count);
-
- for (xmlNodePtr node = solidsNode->children; node; node = node->next)
- {
- if (xmlStrcmp(node->name, C_TAG_SOLID) == 0)
- {
- int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
- std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
- std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
-
- geometry->setSolid(index, name, reference);
- }
- }
-}
-
-void XaoExporter::parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject)
-{
- for (xmlNodePtr node = groupsNode->children; node; node = node->next)
- {
- if (xmlStrcmp(node->name, C_TAG_GROUP) == 0)
- {
- parseGroupNode(node, xaoObject);
- }
- }
-}
-
-void XaoExporter::parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject)
-{
- std::string strDimension = readStringProp(groupNode, C_ATTR_GROUP_DIM, true, "");
- XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
- Group* group = xaoObject->addGroup(dim);
-
- std::string name = readStringProp(groupNode, C_ATTR_GROUP_NAME, false, "");
- group->setName(name);
-
- for (xmlNodePtr node = groupNode->children; node; node = node->next)
- {
- if (xmlStrcmp(node->name, C_TAG_ELEMENT) == 0)
- {
- int index = readIntegerProp(node, C_ATTR_ELEMENT_INDEX, true, -1);
- group->add(index);
- }
- }
-}
-
-void XaoExporter::parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject)
-{
- for (xmlNodePtr node = fieldsNode->children; node; node = node->next)
- {
- if (xmlStrcmp(node->name, C_TAG_FIELD) == 0)
- {
- parseFieldNode(node, xaoObject);
- }
- }
-}
-
-void XaoExporter::parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject)
-{
- std::string strDimension = readStringProp(fieldNode, C_ATTR_FIELD_DIMENSION, true, "");
- XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
-
- std::string strType = readStringProp(fieldNode, C_ATTR_FIELD_TYPE, true, "");
- XAO::Type type = XaoUtils::stringToFieldType(strType);
-
- // we need to get the number of components first to create the field
- xmlNodePtr componentsNode = NULL;
- xmlNodePtr stepsNode = NULL;
-
- for (xmlNodePtr node = fieldNode->children; node; node = node->next)
- {
- if (xmlStrcmp(node->name, C_TAG_COMPONENTS) == 0)
- componentsNode = node;
- else if (xmlStrcmp(node->name, C_TAG_STEPS) == 0)
- stepsNode = node;
- }
-
- // ensure that the components node is defined
- if (componentsNode == NULL)
- {
- throw SALOME_Exception(MsgBuilder() << "Line " << fieldNode->line << ": "
- << "No components defined for field.");
- }
-
- // create the field
- int nbComponents = readIntegerProp(componentsNode, C_ATTR_COUNT, true, -1);
- Field* field = xaoObject->addField(type, dim, nbComponents);
-
- // parse the components
- for (xmlNodePtr compNode = componentsNode->children; compNode; compNode = compNode->next)
- {
- std::string compName= readStringProp(compNode, C_ATTR_COMPONENT_NAME, false, "");
- if (compName.size() > 0)
- {
- int col = readIntegerProp(compNode, C_ATTR_COMPONENT_COLUMN, true, -1);
- field->setComponentName(col, compName);
- }
- }
-
- // set the name
- std::string name = readStringProp(fieldNode, C_ATTR_FIELD_NAME, false, "");
- if (name.size() > 0) field->setName(name);
-
- // read the steps
- if (stepsNode != 0)
- {
- for (xmlNodePtr stepNode = stepsNode->children; stepNode; stepNode = stepNode->next)
- {
- if (xmlStrcmp(stepNode->name, C_TAG_STEP) == 0)
- {
- parseStepNode(stepNode, field);
- }
- }
- }
-}
-
-void XaoExporter::parseStepNode(xmlNodePtr stepNode, Field* field)
-{
- int stepNumber = readIntegerProp(stepNode, C_ATTR_STEP_NUMBER, true, -1);
- Step* step = field->addNewStep(stepNumber);
-
- int stepStamp = readIntegerProp(stepNode, C_ATTR_STEP_STAMP, false, -1);
- if (stepStamp != -1)
- {
- step->setStamp(stepStamp);
- }
-
- for (xmlNodePtr eltNode = stepNode->children; eltNode; eltNode = eltNode->next)
- {
- if (xmlStrcmp(eltNode->name, C_TAG_ELEMENT) == 0)
- {
- parseStepElementNode(eltNode, step);
- }
- }
-}
-
-void XaoExporter::parseStepElementNode(xmlNodePtr eltNode, Step* step)
-{
- int index = readIntegerProp(eltNode, C_ATTR_ELT_INDEX, true, -1);
-
- for (xmlNodePtr valNode = eltNode->children; valNode; valNode = valNode->next)
- {
- if (xmlStrcmp(valNode->name, C_TAG_VALUE) == 0)
- {
- int component = readIntegerProp(valNode, C_ATTR_VALUE_COMPONENT, true, -1);
- xmlChar* data = xmlNodeGetContent(valNode->children);
-
- if (data == NULL)
- {
- throw SALOME_Exception(MsgBuilder() << "Line " << valNode->line << ": no content for value.");
- }
-
- std::string value = (char*)data;
- step->setStringValue(index, component, value);
- }
- }
-}
+++ /dev/null
-
-#ifndef __XAO_XAOEXPORTER_HXX__
-#define __XAO_XAOEXPORTER_HXX__
-
-#include <libxml/parser.h>
-
-#include "Xao.hxx"
-#include "Geometry.hxx"
-#include "Group.hxx"
-#include "Field.hxx"
-
-namespace XAO
-{
- class XaoExporter
- {
- public:
- static const bool saveToFile(Xao* xaoObject, const std::string& fileName);
- static const std::string saveToXml(Xao* xaoObject);
-
- static const bool readFromFile(const std::string& fileName, Xao* xaoObject);
- static const bool setXML(const std::string& xml, Xao* xaoObject);
-
- private:
- static xmlDocPtr exportXMLDoc(Xao* xaoObject);
- static void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao);
- static void exportGeometricElements(Geometry* xaoGeometry, xmlNodePtr topology,
- XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag);
- static void exportGroups(Xao* xaoObject, xmlNodePtr xao);
- static void exportFields(Xao* xaoObject, xmlNodePtr xao);
- static void exportStep(Step* step, Field* field, xmlNodePtr nodeSteps);
-
- static void parseXMLDoc(xmlDocPtr doc, Xao* xaoObject);
- static void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject);
- static void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject);
- static void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry);
- static void parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry);
- static void parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry);
- static void parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry);
- static void parseFacesNode(xmlNodePtr facesNode, Geometry* geometry);
- static void parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry);
- static void parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject);
- static void parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject);
-
- static void parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject);
- static void parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject);
- static void parseStepNode(xmlNodePtr stepNode, Field* field);
- static void parseStepElementNode(xmlNodePtr eltNode, Step* step);
-
- static std::string readStringProp(xmlNodePtr node, const xmlChar* attribute,
- const bool& required, const std::string& defaultValue, const std::string& exception = std::string(""));
- static int readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
- const bool& required, const int& defaultValue, const std::string& exception = std::string(""));
- };
-}
-
-
-#endif /* __XAO_XAOEXPORTER_HXX__ */
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#include <cstring>
-#include <sstream>
-#include <iosfwd>
-#include <Utils_SALOME_Exception.hxx>
-
-#include "Xao.hxx"
-#include "XaoUtils.hxx"
-
-using namespace XAO;
-
-
-const std::string XaoUtils::intToString(const int& value)
-{
- std::ostringstream str;
- str << value;
- return str.str();
-}
-
-const int XaoUtils::stringToInt(const std::string& value)
-{
- int res;
- std::istringstream convert(value);
- if ( !(convert >> res) )
- throw SALOME_Exception(MsgBuilder() << "Cannot convert '" << value << "' to integer.");
- return res;
-}
-
-const std::string XaoUtils::doubleToString(const double& value)
-{
- std::ostringstream str;
- str << value;
- return str.str();
-}
-
-const double XaoUtils::stringToDouble(const std::string& value)
-{
- double res;
- std::istringstream convert(value);
- if ( !(convert >> res) )
- throw SALOME_Exception(MsgBuilder() << "Cannot convert '" << value << "' to double.");
- return res;
-}
-
-const std::string XaoUtils::booleanToString(const bool& value)
-{
- if (value)
- return "true";
- return "false";
-}
-
-const bool XaoUtils::stringToBoolean(const std::string& value)
-{
- if (value == "true" || value == "1")
- return true;
- if (value == "false" || value == "0")
- return false;
-
- throw SALOME_Exception(MsgBuilder() << "Invalid boolean value: " << value);
-}
-
-const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
-{
- if (dimension == XAO::VERTEX)
- return "vertex";
- if (dimension == XAO::EDGE)
- return "edge";
- if (dimension == XAO::FACE)
- return "face";
- if (dimension == XAO::SOLID)
- return "solid";
- if (dimension == XAO::WHOLE)
- return "whole";
-
- throw SALOME_Exception(MsgBuilder() << "Bad dimension: " << dimension);
-}
-
-const XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension)
-{
- if (dimension == "vertex")
- return XAO::VERTEX;
- if (dimension == "edge")
- return XAO::EDGE;
- if (dimension == "face")
- return XAO::FACE;
- if (dimension == "solid")
- return XAO::SOLID;
- if (dimension == "whole")
- return XAO::WHOLE;
-
- throw SALOME_Exception(MsgBuilder() << "Bad dimension: " << dimension);
-}
-
-const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
-{
- if (type ==XAO:: BOOLEAN)
- return "boolean";
- if (type == XAO::INTEGER)
- return "integer";
- if (type == XAO::DOUBLE)
- return "double";
- if (type == XAO::STRING)
- return "string";
-
- throw SALOME_Exception(MsgBuilder() << "Bad type: " << type);
-}
-
-const XAO::Type XaoUtils::stringToFieldType(const std::string& type)
-{
- if (type == "boolean")
- return XAO::BOOLEAN;
- if (type == "integer")
- return XAO::INTEGER;
- if (type == "double")
- return XAO::DOUBLE;
- if (type == "string")
- return XAO::STRING;
-
- throw SALOME_Exception(MsgBuilder() << "Bad type: " << type);
-}
-
-const std::string XaoUtils::shapeFormatToString(const XAO::Format& format)
-{
- if (format == XAO::BREP)
- return "BREP";
- if (format == XAO::STEP)
- return "STEP";
-
- throw SALOME_Exception(MsgBuilder() << "Bad format: " << format);
-}
-
-const XAO::Format XaoUtils::stringToShapeFormat(const std::string& format)
-{
- if (format == "BREP")
- return XAO::BREP;
- if (format == "STEP")
- return XAO::STEP;
-
- throw SALOME_Exception(MsgBuilder() << "Bad format: " << format);
-}
+++ /dev/null
-// Copyright (C) 2013 CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// Author : Frederic Pons (OpenCascade)
-
-#ifndef __XAO_UTILS_HXX__
-#define __XAO_UTILS_HXX__
-
-#include <sstream>
-#include <string>
-
-#include "Xao.hxx"
-#include "Field.hxx"
-
-namespace XAO
-{
- /**
- * \class XaoUtils
- * Utilities class to convert types.
- */
- class XaoUtils
- {
- public:
- /**
- * Converts an integer into a string.
- * \param value the integer to convert.
- * \return the string.
- */
- static const std::string intToString(const int& value);
-
- /**
- * Converts a string into an integer.
- * \param value the string to convert.
- * \return the integer value.
- */
- static const int stringToInt(const std::string& value);
-
- /**
- * Converts a double into a string.
- * @param value the double to convert.
- * @return the string.
- */
- static const std::string doubleToString(const double& value);
- /**
- * Converts a string into a double.
- * @param value the string to convert.
- * @return the double value.
- */
- static const double stringToDouble(const std::string& value);
-
- /**
- * Converts a boolean into a string.
- * @param value the boolean to convert.
- * @return the string.
- */
- static const std::string booleanToString(const bool& value);
- /**
- * Converts a string into a boolean.
- * @param value the string to convert.
- * @return the boolean value.
- */
- static const bool stringToBoolean(const std::string& value);
-
- /**
- * Converts a Dimension to string.
- * \param dimension the Dimension to convert.
- * \return the dimension as a string.
- * \throw SALOME_Exception
- */
- static const std::string dimensionToString(const XAO::Dimension& dimension);
-
- /**
- * Converts a string into a Dimension.
- * \param dimension the dimension as a string.
- * \return the converted Dimension.
- * \throw SALOME_Exception
- */
- static const XAO::Dimension stringToDimension(const std::string& dimension);
-
- /**
- * Converts a Type to string.
- * \param type the Type to convert.
- * \return the Type as a string.
- * \throw SALOME_Exception
- */
- static const std::string fieldTypeToString(const XAO::Type& type);
-
- /**
- * Converts a string into a Type.
- * \param type the Type as a string.
- * \return the converted Type.
- * \throw SALOME_Exception
- */
- static const XAO::Type stringToFieldType(const std::string& type);
-
- /**
- * Converts a Format to string.
- * \param format the Format to convert.
- * \return the Format as a string.
- * \throw SALOME_Exception
- */
- static const std::string shapeFormatToString(const XAO::Format& format);
-
- /**
- * Converts a string into a Format.
- * \param format the Format as a string.
- * \return the converted Format.
- * \throw SALOME_Exception
- */
- static const XAO::Format stringToShapeFormat(const std::string& format);
- };
-
- class MsgBuilder
- {
- public:
- MsgBuilder() {};
-
- template <typename T>
- MsgBuilder& operator <<(const T& t)
- {
- m_stream << t;
- return *this;
- }
-
- operator const char*() const { return m_stream.str().c_str(); }
-
- private :
- std::stringstream m_stream;
- };
-
-}
-
-
-
-#endif /* __XAO_UTILS_HXX__ */
#include "TestUtils.hxx"
#include "BrepGeometryTest.hxx"
-#include "../Xao.hxx"
-#include "../BrepGeometry.hxx"
+#include "../XAO_Xao.hxx"
+#include "../XAO_BrepGeometry.hxx"
using namespace XAO;
#include <cppunit/extensions/HelperMacros.h>
-#include "../Xao.hxx"
-
namespace XAO
{
class BrepGeometryTest: public CppUnit::TestFixture
#include <Utils_SALOME_Exception.hxx>
#include "FieldTest.hxx"
-#include "../Xao.hxx"
-#include "../XaoUtils.hxx"
-#include "../Field.hxx"
-#include "../Step.hxx"
-#include "../BooleanField.hxx"
-#include "../IntegerField.hxx"
-#include "../DoubleField.hxx"
-#include "../StringField.hxx"
+#include "../XAO_Xao.hxx"
+#include "../XAO_XaoUtils.hxx"
+#include "../XAO_Field.hxx"
+#include "../XAO_Step.hxx"
+#include "../XAO_BooleanField.hxx"
+#include "../XAO_IntegerField.hxx"
+#include "../XAO_DoubleField.hxx"
+#include "../XAO_StringField.hxx"
using namespace XAO;
#include <cppunit/extensions/HelperMacros.h>
-#include "../Xao.hxx"
+#include "../XAO_Xao.hxx"
+#include "../XAO_Field.hxx"
namespace XAO
{
#include "TestUtils.hxx"
#include "GeometryTest.hxx"
-#include "../Geometry.hxx"
+#include "../XAO_Geometry.hxx"
using namespace XAO;
#include <cppunit/extensions/HelperMacros.h>
-#include "../Xao.hxx"
-
namespace XAO
{
class GeometryTest: public CppUnit::TestFixture
#include "TestUtils.hxx"
#include "GroupTest.hxx"
-#include "../Xao.hxx"
-#include "../Group.hxx"
+#include "../XAO_Xao.hxx"
+#include "../XAO_Group.hxx"
using namespace XAO;
#include <cppunit/extensions/HelperMacros.h>
-#include "../Xao.hxx"
-
namespace XAO
{
class GroupTest: public CppUnit::TestFixture
#include "TestUtils.hxx"
#include "ImportExportTest.hxx"
-#include "../Geometry.hxx"
-#include "../Group.hxx"
-#include "../Field.hxx"
-#include "../IntegerField.hxx"
-#include "../IntegerStep.hxx"
+#include "../XAO_Geometry.hxx"
+#include "../XAO_Group.hxx"
+#include "../XAO_Field.hxx"
+#include "../XAO_IntegerField.hxx"
+#include "../XAO_IntegerStep.hxx"
using namespace XAO;
#include <cppunit/extensions/HelperMacros.h>
-#include "../Xao.hxx"
+#include "../XAO_Xao.hxx"
namespace XAO
{
#define __XAO_TESTUTILS_HXX__
#include <fstream>
-#include "../Xao.hxx"
+#include <cstdlib>
namespace XAO
{
#include <Utils_SALOME_Exception.hxx>
#include "XaoUtilsTest.hxx"
-#include "../Xao.hxx"
-#include "../XaoUtils.hxx"
+#include "../XAO_Xao.hxx"
+#include "../XAO_XaoUtils.hxx"
using namespace XAO;
#include <cppunit/extensions/HelperMacros.h>
-#include "../Xao.hxx"
-
namespace XAO
{
class XaoUtilsTest: public CppUnit::TestFixture
--- /dev/null
+#!/bin/bash
+
+# This script can be used to generate the code coverage report.
+# Important: the library needs to be compiled in debug mode and with coverage option
+# add to configure options:
+# CXXFLAGS="-fprofile-arcs -ftest-coverage"
+# CFLAGS="-fprofile-arcs -ftest-coverage"
+
+# to run the script:
+# > cd BUILD/GEOM/src/XAO
+# > make
+# > cd tests
+# > make
+# > cp ../.libs/*.gcno .
+# > ./TestXAO
+# > cp ../.libs/*.gcda .
+# > ./coverage_report XAO
+
+QUIET=--quiet
+# report directory
+REPORT_PATH=report
+# browser to open the report
+BROWSER=firefox
+# name for the info file
+TITLE=$1
+
+# initialize
+if [[ $TITLE == "--reset" ]]
+then
+ lcov --base-directory . --directory . --zerocounters -q
+ echo "Reset counters"
+ exit 0
+fi
+
+
+if [ -z $TITLE ]
+then
+ echo $TITLE "name is required"
+ exit 1
+fi
+
+INFO_FILE=${TITLE}.info
+if [ -f $INFO_FILE ]
+then
+ rm -f $INFO_FILE
+fi
+
+# collecte des données
+lcov --directory . --capture --output-file $INFO_FILE
+
+# suppression des symboles externes
+lcov --remove $INFO_FILE "/usr*" -o $INFO_FILE $QUIET
+# prerequisites
+lcov --remove $INFO_FILE "/home2/*" -o $INFO_FILE $QUIET
+
+# suppression des tests
+lcov --remove $INFO_FILE "*/tests/*" -o $INFO_FILE $QUIET
+
+# génération du rapport
+genhtml --output-directory $REPORT_PATH --title $TITLE --num-spaces 4 $INFO_FILE
+
+if [ ! -z $BROWSER ]
+then
+ $BROWSER $REPORT_PATH/index.html &
+fi
\ No newline at end of file