From: fps Date: Fri, 6 Sep 2013 12:39:33 +0000 (+0000) Subject: rename files XAO_* to follow SALOME standard X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=285715917ca39b3a323a0898bb81ee9159440625;p=modules%2Fgeom.git rename files XAO_* to follow SALOME standard --- diff --git a/src/XAO/BooleanField.cxx b/src/XAO/BooleanField.cxx deleted file mode 100644 index 7a91d00b5..000000000 --- a/src/XAO/BooleanField.cxx +++ /dev/null @@ -1,59 +0,0 @@ -// 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 - -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]; -} diff --git a/src/XAO/BooleanField.hxx b/src/XAO/BooleanField.hxx deleted file mode 100644 index 2a240db79..000000000 --- a/src/XAO/BooleanField.hxx +++ /dev/null @@ -1,48 +0,0 @@ -// 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 -#include -#include - -#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__ */ diff --git a/src/XAO/BooleanStep.cxx b/src/XAO/BooleanStep.cxx deleted file mode 100644 index 3fab963bc..000000000 --- a/src/XAO/BooleanStep.cxx +++ /dev/null @@ -1,140 +0,0 @@ -// 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 -#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 row; - row.reserve(m_nbComponents); - for (int j = 0; j < m_nbComponents; ++j) - row.push_back(false); - m_values.push_back(row); - } -} - -std::vector BooleanStep::getValues() -{ - std::vector result; - result.reserve(m_nbElements * m_nbComponents); - - std::vector< std::vector >::iterator it; - for (it = m_values.begin(); it != m_values.end(); ++it) - { - std::vector eltValues = *it; - result.insert(result.end(), eltValues.begin(), eltValues.end()); - } - - return result; -} - -std::vector BooleanStep::getElement(const int& element) -{ - checkElementIndex(element); - - std::vector result(m_values[element]); - return result; -} - -std::vector BooleanStep::getComponent(const int& component) -{ - checkComponentIndex(component); - - std::vector result; - result.reserve(m_nbElements); - - std::vector< std::vector >::iterator it; - for (it = m_values.begin(); it != m_values.end(); ++it) - { - std::vector 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& 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& 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& 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)); -} diff --git a/src/XAO/BooleanStep.hxx b/src/XAO/BooleanStep.hxx deleted file mode 100644 index d82ee4a38..000000000 --- a/src/XAO/BooleanStep.hxx +++ /dev/null @@ -1,82 +0,0 @@ -// 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 -#include - -#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 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 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 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& values); - void setElements(const int& element, const std::vector& elements); - void setComponents(const int& component, const std::vector& 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 > m_values; - }; -} - - -#endif /* __XAO_BOOLEANSTEP_HXX__ */ diff --git a/src/XAO/BrepGeometry.cxx b/src/XAO/BrepGeometry.cxx deleted file mode 100644 index 25e8ab2b0..000000000 --- a/src/XAO/BrepGeometry.cxx +++ /dev/null @@ -1,407 +0,0 @@ -// 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 - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -//#include -//#include -#include -#include -#include -#include - -#include - -#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 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::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 BrepGeometry::getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim) -{ - std::vector 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 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 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 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); -} diff --git a/src/XAO/BrepGeometry.hxx b/src/XAO/BrepGeometry.hxx deleted file mode 100644 index 82724bf85..000000000 --- a/src/XAO/BrepGeometry.hxx +++ /dev/null @@ -1,247 +0,0 @@ -// 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 -#include - -#include - -#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 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 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 getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim); - - private: - TopoDS_Shape m_shape; - }; -} - -#endif // __XAO_BREPGEOMETRY_HXX__ diff --git a/src/XAO/DoubleField.cxx b/src/XAO/DoubleField.cxx deleted file mode 100644 index 35adcfeca..000000000 --- a/src/XAO/DoubleField.cxx +++ /dev/null @@ -1,58 +0,0 @@ -// 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 - -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]; -} diff --git a/src/XAO/DoubleField.hxx b/src/XAO/DoubleField.hxx deleted file mode 100644 index 152efbd5b..000000000 --- a/src/XAO/DoubleField.hxx +++ /dev/null @@ -1,49 +0,0 @@ -// 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 -#include -#include -#include - -#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__ */ diff --git a/src/XAO/DoubleStep.cxx b/src/XAO/DoubleStep.cxx deleted file mode 100644 index 10cb30fcf..000000000 --- a/src/XAO/DoubleStep.cxx +++ /dev/null @@ -1,140 +0,0 @@ -// 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 -#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 row; - row.reserve(m_nbComponents); - for (int j = 0; j < m_nbComponents; ++j) - row.push_back(0); - m_values.push_back(row); - } -} - -std::vector DoubleStep::getValues() -{ - std::vector result; - result.reserve(m_nbElements * m_nbComponents); - - std::vector< std::vector >::iterator it; - for (it = m_values.begin(); it != m_values.end(); ++it) - { - std::vector eltValues = *it; - result.insert(result.end(), eltValues.begin(), eltValues.end()); - } - - return result; -} - -std::vector DoubleStep::getElement(const int& element) -{ - checkElementIndex(element); - - std::vector result(m_values[element]); - return result; -} - -std::vector DoubleStep::getComponent(const int& component) -{ - checkComponentIndex(component); - - std::vector result; - result.reserve(m_nbElements); - - std::vector< std::vector >::iterator it; - for (it = m_values.begin(); it != m_values.end(); ++it) - { - std::vector 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& 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& 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& 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)); -} diff --git a/src/XAO/DoubleStep.hxx b/src/XAO/DoubleStep.hxx deleted file mode 100644 index ccf25ada3..000000000 --- a/src/XAO/DoubleStep.hxx +++ /dev/null @@ -1,59 +0,0 @@ -// 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 - -#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 getValues(); - std::vector getElement(const int& element); - std::vector getComponent(const int& component); - - const double getValue(const int& element, const int& component); - - void setValues(const std::vector& values); - void setElements(const int& element, const std::vector& elements); - void setComponents(const int& component, const std::vector& 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 > m_values; - }; -} - - -#endif /* __XAO_DOUBLESTEP_HXX__ */ diff --git a/src/XAO/Field.cxx b/src/XAO/Field.cxx deleted file mode 100644 index 12289f14a..000000000 --- a/src/XAO/Field.cxx +++ /dev/null @@ -1,130 +0,0 @@ -// 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 -#include -#include - -#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::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::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); -} diff --git a/src/XAO/Field.hxx b/src/XAO/Field.hxx deleted file mode 100644 index 5e7c65e04..000000000 --- a/src/XAO/Field.hxx +++ /dev/null @@ -1,219 +0,0 @@ -// 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 -#include -#include -#include - -#include "Xao.hxx" -#include "Step.hxx" - -namespace XAO -{ - typedef std::vector::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 m_components; - /** The number of elements. */ - int m_nbElements; - - /** The list of steps. */ - std::vector m_steps; - }; -} - -#endif diff --git a/src/XAO/GeometricElement.cxx b/src/XAO/GeometricElement.cxx deleted file mode 100644 index a2cf99dd1..000000000 --- a/src/XAO/GeometricElement.cxx +++ /dev/null @@ -1,128 +0,0 @@ -// 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 - -#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); -} diff --git a/src/XAO/GeometricElement.hxx b/src/XAO/GeometricElement.hxx deleted file mode 100644 index a2be162db..000000000 --- a/src/XAO/GeometricElement.hxx +++ /dev/null @@ -1,209 +0,0 @@ -// 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 -#include - -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::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 m_elements; - }; -} - -#endif /* __XAO_GEOMETRICELEMENT_HXX__ */ diff --git a/src/XAO/Geometry.cxx b/src/XAO/Geometry.cxx deleted file mode 100644 index 151849cf7..000000000 --- a/src/XAO/Geometry.cxx +++ /dev/null @@ -1,119 +0,0 @@ -// 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 - -#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); -} diff --git a/src/XAO/Geometry.hxx b/src/XAO/Geometry.hxx deleted file mode 100644 index 61cbd2825..000000000 --- a/src/XAO/Geometry.hxx +++ /dev/null @@ -1,142 +0,0 @@ -// 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 - -#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 diff --git a/src/XAO/Group.cxx b/src/XAO/Group.cxx deleted file mode 100644 index 30ac938bc..000000000 --- a/src/XAO/Group.cxx +++ /dev/null @@ -1,71 +0,0 @@ -// 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 - -#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); -} diff --git a/src/XAO/Group.hxx b/src/XAO/Group.hxx deleted file mode 100644 index cb55ca8b4..000000000 --- a/src/XAO/Group.hxx +++ /dev/null @@ -1,171 +0,0 @@ -// 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 -#include -#include - -#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::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::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::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 m_elements; - }; -} - -#endif diff --git a/src/XAO/IntegerField.cxx b/src/XAO/IntegerField.cxx deleted file mode 100644 index 75d9ca0a9..000000000 --- a/src/XAO/IntegerField.cxx +++ /dev/null @@ -1,58 +0,0 @@ -// 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 - -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]; -} diff --git a/src/XAO/IntegerField.hxx b/src/XAO/IntegerField.hxx deleted file mode 100644 index bc8ff1d27..000000000 --- a/src/XAO/IntegerField.hxx +++ /dev/null @@ -1,49 +0,0 @@ -// 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 -#include -#include -#include - -#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__ */ diff --git a/src/XAO/IntegerStep.cxx b/src/XAO/IntegerStep.cxx deleted file mode 100644 index f1e4a3ca1..000000000 --- a/src/XAO/IntegerStep.cxx +++ /dev/null @@ -1,140 +0,0 @@ -// 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 -#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 row; - row.reserve(m_nbComponents); - for (int j = 0; j < m_nbComponents; ++j) - row.push_back(0); - m_values.push_back(row); - } -} - -std::vector IntegerStep::getValues() -{ - std::vector result; - result.reserve(m_nbElements * m_nbComponents); - - std::vector< std::vector >::iterator it; - for (it = m_values.begin(); it != m_values.end(); ++it) - { - std::vector eltValues = *it; - result.insert(result.end(), eltValues.begin(), eltValues.end()); - } - - return result; -} - -std::vector IntegerStep::getElement(const int& element) -{ - checkElementIndex(element); - - std::vector result(m_values[element]); - return result; -} - -std::vector IntegerStep::getComponent(const int& component) -{ - checkComponentIndex(component); - - std::vector result; - result.reserve(m_nbElements); - - std::vector< std::vector >::iterator it; - for (it = m_values.begin(); it != m_values.end(); ++it) - { - std::vector 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& 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& 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& 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)); -} diff --git a/src/XAO/IntegerStep.hxx b/src/XAO/IntegerStep.hxx deleted file mode 100644 index b1ad9ce21..000000000 --- a/src/XAO/IntegerStep.hxx +++ /dev/null @@ -1,59 +0,0 @@ -// 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 - -#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 getValues(); - std::vector getElement(const int& element); - std::vector getComponent(const int& component); - - const int getValue(const int& element, const int& component); - - void setValues(const std::vector& values); - void setElements(const int& element, const std::vector& elements); - void setComponents(const int& element, const std::vector& 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 > m_values; - }; -} - - -#endif /* __XAO_INTEGERSTEP_HXX__ */ diff --git a/src/XAO/Makefile.am b/src/XAO/Makefile.am index 9cda11665..8dbb40e4d 100644 --- a/src/XAO/Makefile.am +++ b/src/XAO/Makefile.am @@ -27,43 +27,43 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am # # 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) \ diff --git a/src/XAO/Step.cxx b/src/XAO/Step.cxx deleted file mode 100644 index bbc2decd9..000000000 --- a/src/XAO/Step.cxx +++ /dev/null @@ -1,90 +0,0 @@ -// 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 - -#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); -} diff --git a/src/XAO/Step.hxx b/src/XAO/Step.hxx deleted file mode 100644 index d0f32653f..000000000 --- a/src/XAO/Step.hxx +++ /dev/null @@ -1,138 +0,0 @@ -// 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__ */ diff --git a/src/XAO/StringField.cxx b/src/XAO/StringField.cxx deleted file mode 100644 index 57e48fad4..000000000 --- a/src/XAO/StringField.cxx +++ /dev/null @@ -1,58 +0,0 @@ -// 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 - -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]; -} diff --git a/src/XAO/StringField.hxx b/src/XAO/StringField.hxx deleted file mode 100644 index d7855cb33..000000000 --- a/src/XAO/StringField.hxx +++ /dev/null @@ -1,49 +0,0 @@ -// 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 -#include -#include -#include - -#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__ */ diff --git a/src/XAO/StringStep.cxx b/src/XAO/StringStep.cxx deleted file mode 100644 index f4611013c..000000000 --- a/src/XAO/StringStep.cxx +++ /dev/null @@ -1,139 +0,0 @@ -// 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 - -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 row; - row.reserve(m_nbComponents); - for (int j = 0; j < m_nbComponents; ++j) - row.push_back(""); - m_values.push_back(row); - } -} - -std::vector StringStep::getValues() -{ - std::vector result; - result.reserve(m_nbElements * m_nbComponents); - - std::vector< std::vector >::iterator it; - for (it = m_values.begin(); it != m_values.end(); ++it) - { - std::vector eltValues = *it; - result.insert(result.end(), eltValues.begin(), eltValues.end()); - } - - return result; -} - -std::vector StringStep::getElement(const int& element) -{ - checkElementIndex(element); - - std::vector result(m_values[element]); - return result; -} - -std::vector StringStep::getComponent(const int& component) -{ - checkComponentIndex(component); - - std::vector result; - result.reserve(m_nbElements); - - std::vector< std::vector >::iterator it; - for (it = m_values.begin(); it != m_values.end(); ++it) - { - std::vector 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& 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& 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& 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); -} diff --git a/src/XAO/StringStep.hxx b/src/XAO/StringStep.hxx deleted file mode 100644 index bbd43592d..000000000 --- a/src/XAO/StringStep.hxx +++ /dev/null @@ -1,62 +0,0 @@ -// 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 -#include - -#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 getValues(); - std::vector getElement(const int& element); - std::vector getComponent(const int& component); - - const std::string getValue(const int& element, const int& component); - - void setValues(const std::vector& values); - void setElements(const int& element, const std::vector& elements); - void setComponents(const int& component, const std::vector& 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 > m_values; - }; -} - - -#endif /* __XAO_STRINGSTEP_HXX__ */ diff --git a/src/XAO/XAO_BooleanField.cxx b/src/XAO/XAO_BooleanField.cxx new file mode 100644 index 000000000..26b8cb5d0 --- /dev/null +++ b/src/XAO/XAO_BooleanField.cxx @@ -0,0 +1,59 @@ +// 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 + +#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]; +} diff --git a/src/XAO/XAO_BooleanField.hxx b/src/XAO/XAO_BooleanField.hxx new file mode 100644 index 000000000..eefb49234 --- /dev/null +++ b/src/XAO/XAO_BooleanField.hxx @@ -0,0 +1,46 @@ +// 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 + +#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__ */ diff --git a/src/XAO/XAO_BooleanStep.cxx b/src/XAO/XAO_BooleanStep.cxx new file mode 100644 index 000000000..d6c03d1e3 --- /dev/null +++ b/src/XAO/XAO_BooleanStep.cxx @@ -0,0 +1,141 @@ +// 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 + +#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 row; + row.reserve(m_nbComponents); + for (int j = 0; j < m_nbComponents; ++j) + row.push_back(false); + m_values.push_back(row); + } +} + +std::vector BooleanStep::getValues() +{ + std::vector result; + result.reserve(m_nbElements * m_nbComponents); + + std::vector< std::vector >::iterator it; + for (it = m_values.begin(); it != m_values.end(); ++it) + { + std::vector eltValues = *it; + result.insert(result.end(), eltValues.begin(), eltValues.end()); + } + + return result; +} + +std::vector BooleanStep::getElement(const int& element) +{ + checkElementIndex(element); + + std::vector result(m_values[element]); + return result; +} + +std::vector BooleanStep::getComponent(const int& component) +{ + checkComponentIndex(component); + + std::vector result; + result.reserve(m_nbElements); + + std::vector< std::vector >::iterator it; + for (it = m_values.begin(); it != m_values.end(); ++it) + { + std::vector 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& 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& 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& 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)); +} diff --git a/src/XAO/XAO_BooleanStep.hxx b/src/XAO/XAO_BooleanStep.hxx new file mode 100644 index 000000000..4f514407a --- /dev/null +++ b/src/XAO/XAO_BooleanStep.hxx @@ -0,0 +1,81 @@ +// 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 + +#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 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 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 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& values); + void setElements(const int& element, const std::vector& elements); + void setComponents(const int& component, const std::vector& 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 > m_values; + }; +} + + +#endif /* __XAO_BOOLEANSTEP_HXX__ */ diff --git a/src/XAO/XAO_BrepGeometry.cxx b/src/XAO/XAO_BrepGeometry.cxx new file mode 100644 index 000000000..29cbd514b --- /dev/null +++ b/src/XAO/XAO_BrepGeometry.cxx @@ -0,0 +1,404 @@ +// 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 + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#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 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::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 BrepGeometry::getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim) +{ + std::vector 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 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 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 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); +} diff --git a/src/XAO/XAO_BrepGeometry.hxx b/src/XAO/XAO_BrepGeometry.hxx new file mode 100644 index 000000000..923520cf3 --- /dev/null +++ b/src/XAO/XAO_BrepGeometry.hxx @@ -0,0 +1,247 @@ +// 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 +#include + +#include + +#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 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 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 getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim); + + private: + TopoDS_Shape m_shape; + }; +} + +#endif // __XAO_BREPGEOMETRY_HXX__ diff --git a/src/XAO/XAO_DoubleField.cxx b/src/XAO/XAO_DoubleField.cxx new file mode 100644 index 000000000..6bb6fbed1 --- /dev/null +++ b/src/XAO/XAO_DoubleField.cxx @@ -0,0 +1,58 @@ +// 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 + +#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]; +} diff --git a/src/XAO/XAO_DoubleField.hxx b/src/XAO/XAO_DoubleField.hxx new file mode 100644 index 000000000..383ff0ca8 --- /dev/null +++ b/src/XAO/XAO_DoubleField.hxx @@ -0,0 +1,46 @@ +// 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 + +#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__ */ diff --git a/src/XAO/XAO_DoubleStep.cxx b/src/XAO/XAO_DoubleStep.cxx new file mode 100644 index 000000000..3f2bb6e1f --- /dev/null +++ b/src/XAO/XAO_DoubleStep.cxx @@ -0,0 +1,141 @@ +// 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 + +#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 row; + row.reserve(m_nbComponents); + for (int j = 0; j < m_nbComponents; ++j) + row.push_back(0); + m_values.push_back(row); + } +} + +std::vector DoubleStep::getValues() +{ + std::vector result; + result.reserve(m_nbElements * m_nbComponents); + + std::vector< std::vector >::iterator it; + for (it = m_values.begin(); it != m_values.end(); ++it) + { + std::vector eltValues = *it; + result.insert(result.end(), eltValues.begin(), eltValues.end()); + } + + return result; +} + +std::vector DoubleStep::getElement(const int& element) +{ + checkElementIndex(element); + + std::vector result(m_values[element]); + return result; +} + +std::vector DoubleStep::getComponent(const int& component) +{ + checkComponentIndex(component); + + std::vector result; + result.reserve(m_nbElements); + + std::vector< std::vector >::iterator it; + for (it = m_values.begin(); it != m_values.end(); ++it) + { + std::vector 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& 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& 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& 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)); +} diff --git a/src/XAO/XAO_DoubleStep.hxx b/src/XAO/XAO_DoubleStep.hxx new file mode 100644 index 000000000..d5301aafe --- /dev/null +++ b/src/XAO/XAO_DoubleStep.hxx @@ -0,0 +1,59 @@ +// 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 + +#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 getValues(); + std::vector getElement(const int& element); + std::vector getComponent(const int& component); + + const double getValue(const int& element, const int& component); + + void setValues(const std::vector& values); + void setElements(const int& element, const std::vector& elements); + void setComponents(const int& component, const std::vector& 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 > m_values; + }; +} + + +#endif /* __XAO_DOUBLESTEP_HXX__ */ diff --git a/src/XAO/XAO_Field.cxx b/src/XAO/XAO_Field.cxx new file mode 100644 index 000000000..fb3773bad --- /dev/null +++ b/src/XAO/XAO_Field.cxx @@ -0,0 +1,130 @@ +// 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 +#include +#include + +#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::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::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); +} diff --git a/src/XAO/XAO_Field.hxx b/src/XAO/XAO_Field.hxx new file mode 100644 index 000000000..7e9bf8305 --- /dev/null +++ b/src/XAO/XAO_Field.hxx @@ -0,0 +1,217 @@ +// 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 +#include + +#include "XAO_Xao.hxx" +#include "XAO_Step.hxx" + +namespace XAO +{ + typedef std::vector::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 m_components; + /** The number of elements. */ + int m_nbElements; + + /** The list of steps. */ + std::vector m_steps; + }; +} + +#endif diff --git a/src/XAO/XAO_GeometricElement.cxx b/src/XAO/XAO_GeometricElement.cxx new file mode 100644 index 000000000..a0f39600b --- /dev/null +++ b/src/XAO/XAO_GeometricElement.cxx @@ -0,0 +1,128 @@ +// 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 + +#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); +} diff --git a/src/XAO/XAO_GeometricElement.hxx b/src/XAO/XAO_GeometricElement.hxx new file mode 100644 index 000000000..a2be162db --- /dev/null +++ b/src/XAO/XAO_GeometricElement.hxx @@ -0,0 +1,209 @@ +// 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 +#include + +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::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 m_elements; + }; +} + +#endif /* __XAO_GEOMETRICELEMENT_HXX__ */ diff --git a/src/XAO/XAO_Geometry.cxx b/src/XAO/XAO_Geometry.cxx new file mode 100644 index 000000000..c44800d36 --- /dev/null +++ b/src/XAO/XAO_Geometry.cxx @@ -0,0 +1,119 @@ +// 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 + +#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); +} diff --git a/src/XAO/XAO_Geometry.hxx b/src/XAO/XAO_Geometry.hxx new file mode 100644 index 000000000..9f20fbcaa --- /dev/null +++ b/src/XAO/XAO_Geometry.hxx @@ -0,0 +1,142 @@ +// 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 + +#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 diff --git a/src/XAO/XAO_Group.cxx b/src/XAO/XAO_Group.cxx new file mode 100644 index 000000000..dd755f6d5 --- /dev/null +++ b/src/XAO/XAO_Group.cxx @@ -0,0 +1,71 @@ +// 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 + +#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); +} diff --git a/src/XAO/XAO_Group.hxx b/src/XAO/XAO_Group.hxx new file mode 100644 index 000000000..ec85ef326 --- /dev/null +++ b/src/XAO/XAO_Group.hxx @@ -0,0 +1,170 @@ +// 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 +#include + +#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::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::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::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 m_elements; + }; +} + +#endif diff --git a/src/XAO/XAO_IntegerField.cxx b/src/XAO/XAO_IntegerField.cxx new file mode 100644 index 000000000..4416fbf7e --- /dev/null +++ b/src/XAO/XAO_IntegerField.cxx @@ -0,0 +1,58 @@ +// 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 + +#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]; +} diff --git a/src/XAO/XAO_IntegerField.hxx b/src/XAO/XAO_IntegerField.hxx new file mode 100644 index 000000000..807592e7f --- /dev/null +++ b/src/XAO/XAO_IntegerField.hxx @@ -0,0 +1,46 @@ +// 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 + +#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__ */ diff --git a/src/XAO/XAO_IntegerStep.cxx b/src/XAO/XAO_IntegerStep.cxx new file mode 100644 index 000000000..95472fa03 --- /dev/null +++ b/src/XAO/XAO_IntegerStep.cxx @@ -0,0 +1,141 @@ +// 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 + +#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 row; + row.reserve(m_nbComponents); + for (int j = 0; j < m_nbComponents; ++j) + row.push_back(0); + m_values.push_back(row); + } +} + +std::vector IntegerStep::getValues() +{ + std::vector result; + result.reserve(m_nbElements * m_nbComponents); + + std::vector< std::vector >::iterator it; + for (it = m_values.begin(); it != m_values.end(); ++it) + { + std::vector eltValues = *it; + result.insert(result.end(), eltValues.begin(), eltValues.end()); + } + + return result; +} + +std::vector IntegerStep::getElement(const int& element) +{ + checkElementIndex(element); + + std::vector result(m_values[element]); + return result; +} + +std::vector IntegerStep::getComponent(const int& component) +{ + checkComponentIndex(component); + + std::vector result; + result.reserve(m_nbElements); + + std::vector< std::vector >::iterator it; + for (it = m_values.begin(); it != m_values.end(); ++it) + { + std::vector 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& 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& 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& 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)); +} diff --git a/src/XAO/XAO_IntegerStep.hxx b/src/XAO/XAO_IntegerStep.hxx new file mode 100644 index 000000000..8c3f65939 --- /dev/null +++ b/src/XAO/XAO_IntegerStep.hxx @@ -0,0 +1,59 @@ +// 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 + +#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 getValues(); + std::vector getElement(const int& element); + std::vector getComponent(const int& component); + + const int getValue(const int& element, const int& component); + + void setValues(const std::vector& values); + void setElements(const int& element, const std::vector& elements); + void setComponents(const int& element, const std::vector& 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 > m_values; + }; +} + + +#endif /* __XAO_INTEGERSTEP_HXX__ */ diff --git a/src/XAO/XAO_Step.cxx b/src/XAO/XAO_Step.cxx new file mode 100644 index 000000000..e14eb7004 --- /dev/null +++ b/src/XAO/XAO_Step.cxx @@ -0,0 +1,90 @@ +// 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 + +#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); +} diff --git a/src/XAO/XAO_Step.hxx b/src/XAO/XAO_Step.hxx new file mode 100644 index 000000000..c588d164a --- /dev/null +++ b/src/XAO/XAO_Step.hxx @@ -0,0 +1,138 @@ +// 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__ */ diff --git a/src/XAO/XAO_StringField.cxx b/src/XAO/XAO_StringField.cxx new file mode 100644 index 000000000..95fa814c2 --- /dev/null +++ b/src/XAO/XAO_StringField.cxx @@ -0,0 +1,58 @@ +// 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 + +#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]; +} diff --git a/src/XAO/XAO_StringField.hxx b/src/XAO/XAO_StringField.hxx new file mode 100644 index 000000000..7257f8df6 --- /dev/null +++ b/src/XAO/XAO_StringField.hxx @@ -0,0 +1,46 @@ +// 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 + +#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__ */ diff --git a/src/XAO/XAO_StringStep.cxx b/src/XAO/XAO_StringStep.cxx new file mode 100644 index 000000000..9b72ad809 --- /dev/null +++ b/src/XAO/XAO_StringStep.cxx @@ -0,0 +1,140 @@ +// 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 + +#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 row; + row.reserve(m_nbComponents); + for (int j = 0; j < m_nbComponents; ++j) + row.push_back(""); + m_values.push_back(row); + } +} + +std::vector StringStep::getValues() +{ + std::vector result; + result.reserve(m_nbElements * m_nbComponents); + + std::vector< std::vector >::iterator it; + for (it = m_values.begin(); it != m_values.end(); ++it) + { + std::vector eltValues = *it; + result.insert(result.end(), eltValues.begin(), eltValues.end()); + } + + return result; +} + +std::vector StringStep::getElement(const int& element) +{ + checkElementIndex(element); + + std::vector result(m_values[element]); + return result; +} + +std::vector StringStep::getComponent(const int& component) +{ + checkComponentIndex(component); + + std::vector result; + result.reserve(m_nbElements); + + std::vector< std::vector >::iterator it; + for (it = m_values.begin(); it != m_values.end(); ++it) + { + std::vector 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& 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& 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& 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); +} diff --git a/src/XAO/XAO_StringStep.hxx b/src/XAO/XAO_StringStep.hxx new file mode 100644 index 000000000..cce7271b5 --- /dev/null +++ b/src/XAO/XAO_StringStep.hxx @@ -0,0 +1,62 @@ +// 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 +#include + +#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 getValues(); + std::vector getElement(const int& element); + std::vector getComponent(const int& component); + + const std::string getValue(const int& element, const int& component); + + void setValues(const std::vector& values); + void setElements(const int& element, const std::vector& elements); + void setComponents(const int& component, const std::vector& 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 > m_values; + }; +} + + +#endif /* __XAO_STRINGSTEP_HXX__ */ diff --git a/src/XAO/XAO_Xao.cxx b/src/XAO/XAO_Xao.cxx new file mode 100644 index 000000000..95923aa67 --- /dev/null +++ b/src/XAO/XAO_Xao.cxx @@ -0,0 +1,162 @@ +// 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 + +#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::iterator it = m_groups.begin(); it != m_groups.end(); ++it) + { + delete (*it); + } + + for (std::list::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::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::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"); +} diff --git a/src/XAO/XAO_Xao.hxx b/src/XAO/XAO_Xao.hxx new file mode 100644 index 000000000..7c092be2a --- /dev/null +++ b/src/XAO/XAO_Xao.hxx @@ -0,0 +1,260 @@ +// 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 +#include + +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 m_groups; + /** The list of fields. */ + std::list m_fields; + }; + +} + +#endif diff --git a/src/XAO/XAO_XaoExporter.cxx b/src/XAO/XAO_XaoExporter.cxx new file mode 100644 index 000000000..65e84247b --- /dev/null +++ b/src/XAO/XAO_XaoExporter.cxx @@ -0,0 +1,604 @@ + +#include +#include + +#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::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); + } + } +} diff --git a/src/XAO/XAO_XaoExporter.hxx b/src/XAO/XAO_XaoExporter.hxx new file mode 100644 index 000000000..510572d09 --- /dev/null +++ b/src/XAO/XAO_XaoExporter.hxx @@ -0,0 +1,57 @@ + +#ifndef __XAO_XAOEXPORTER_HXX__ +#define __XAO_XAOEXPORTER_HXX__ + +#include + +#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__ */ diff --git a/src/XAO/XAO_XaoUtils.cxx b/src/XAO/XAO_XaoUtils.cxx new file mode 100644 index 000000000..922536e8d --- /dev/null +++ b/src/XAO/XAO_XaoUtils.cxx @@ -0,0 +1,159 @@ +// 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 +#include +#include +#include + +#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); +} diff --git a/src/XAO/XAO_XaoUtils.hxx b/src/XAO/XAO_XaoUtils.hxx new file mode 100644 index 000000000..06e43f629 --- /dev/null +++ b/src/XAO/XAO_XaoUtils.hxx @@ -0,0 +1,150 @@ +// 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 +#include + +#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 + 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__ */ diff --git a/src/XAO/Xao.cxx b/src/XAO/Xao.cxx deleted file mode 100644 index b6e2da70f..000000000 --- a/src/XAO/Xao.cxx +++ /dev/null @@ -1,163 +0,0 @@ -// 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 - -#include "XaoUtils.hxx" -#include "Xao.hxx" -#include "Geometry.hxx" -#include "Group.hxx" -#include "Field.hxx" -#include "XaoExporter.hxx" -#include - -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::iterator it = m_groups.begin(); it != m_groups.end(); ++it) - { - delete (*it); - } - - for (std::list::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::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::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"); -} diff --git a/src/XAO/Xao.hxx b/src/XAO/Xao.hxx deleted file mode 100644 index f02f50c2c..000000000 --- a/src/XAO/Xao.hxx +++ /dev/null @@ -1,261 +0,0 @@ -// 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 -#include -#include - -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 m_groups; - /** The list of fields. */ - std::list m_fields; - }; - -} - -#endif diff --git a/src/XAO/XaoExporter.cxx b/src/XAO/XaoExporter.cxx deleted file mode 100644 index 7109510c8..000000000 --- a/src/XAO/XaoExporter.cxx +++ /dev/null @@ -1,608 +0,0 @@ - -#include -#include - -#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::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); - } - } -} diff --git a/src/XAO/XaoExporter.hxx b/src/XAO/XaoExporter.hxx deleted file mode 100644 index ef8245228..000000000 --- a/src/XAO/XaoExporter.hxx +++ /dev/null @@ -1,57 +0,0 @@ - -#ifndef __XAO_XAOEXPORTER_HXX__ -#define __XAO_XAOEXPORTER_HXX__ - -#include - -#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__ */ diff --git a/src/XAO/XaoUtils.cxx b/src/XAO/XaoUtils.cxx deleted file mode 100644 index c61d6980c..000000000 --- a/src/XAO/XaoUtils.cxx +++ /dev/null @@ -1,159 +0,0 @@ -// 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 -#include -#include -#include - -#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); -} diff --git a/src/XAO/XaoUtils.hxx b/src/XAO/XaoUtils.hxx deleted file mode 100644 index a626c5a1b..000000000 --- a/src/XAO/XaoUtils.hxx +++ /dev/null @@ -1,150 +0,0 @@ -// 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 -#include - -#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 - 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__ */ diff --git a/src/XAO/tests/BrepGeometryTest.cxx b/src/XAO/tests/BrepGeometryTest.cxx index aefc7c713..ef8a524aa 100644 --- a/src/XAO/tests/BrepGeometryTest.cxx +++ b/src/XAO/tests/BrepGeometryTest.cxx @@ -3,8 +3,8 @@ #include "TestUtils.hxx" #include "BrepGeometryTest.hxx" -#include "../Xao.hxx" -#include "../BrepGeometry.hxx" +#include "../XAO_Xao.hxx" +#include "../XAO_BrepGeometry.hxx" using namespace XAO; diff --git a/src/XAO/tests/BrepGeometryTest.hxx b/src/XAO/tests/BrepGeometryTest.hxx index dda6b0b09..bb4b057a3 100644 --- a/src/XAO/tests/BrepGeometryTest.hxx +++ b/src/XAO/tests/BrepGeometryTest.hxx @@ -3,8 +3,6 @@ #include -#include "../Xao.hxx" - namespace XAO { class BrepGeometryTest: public CppUnit::TestFixture diff --git a/src/XAO/tests/FieldTest.cxx b/src/XAO/tests/FieldTest.cxx index 2a1664c39..caf2b38ee 100644 --- a/src/XAO/tests/FieldTest.cxx +++ b/src/XAO/tests/FieldTest.cxx @@ -2,14 +2,14 @@ #include #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; diff --git a/src/XAO/tests/FieldTest.hxx b/src/XAO/tests/FieldTest.hxx index e7b19bcc9..babf12df1 100644 --- a/src/XAO/tests/FieldTest.hxx +++ b/src/XAO/tests/FieldTest.hxx @@ -3,7 +3,8 @@ #include -#include "../Xao.hxx" +#include "../XAO_Xao.hxx" +#include "../XAO_Field.hxx" namespace XAO { diff --git a/src/XAO/tests/GeometryTest.cxx b/src/XAO/tests/GeometryTest.cxx index 501f29993..cae08b67c 100644 --- a/src/XAO/tests/GeometryTest.cxx +++ b/src/XAO/tests/GeometryTest.cxx @@ -3,7 +3,7 @@ #include "TestUtils.hxx" #include "GeometryTest.hxx" -#include "../Geometry.hxx" +#include "../XAO_Geometry.hxx" using namespace XAO; diff --git a/src/XAO/tests/GeometryTest.hxx b/src/XAO/tests/GeometryTest.hxx index 6a11d240e..4cac2c91c 100644 --- a/src/XAO/tests/GeometryTest.hxx +++ b/src/XAO/tests/GeometryTest.hxx @@ -3,8 +3,6 @@ #include -#include "../Xao.hxx" - namespace XAO { class GeometryTest: public CppUnit::TestFixture diff --git a/src/XAO/tests/GroupTest.cxx b/src/XAO/tests/GroupTest.cxx index dde372cc4..ef93a388c 100644 --- a/src/XAO/tests/GroupTest.cxx +++ b/src/XAO/tests/GroupTest.cxx @@ -3,8 +3,8 @@ #include "TestUtils.hxx" #include "GroupTest.hxx" -#include "../Xao.hxx" -#include "../Group.hxx" +#include "../XAO_Xao.hxx" +#include "../XAO_Group.hxx" using namespace XAO; diff --git a/src/XAO/tests/GroupTest.hxx b/src/XAO/tests/GroupTest.hxx index 8cab813cf..ad54e0773 100644 --- a/src/XAO/tests/GroupTest.hxx +++ b/src/XAO/tests/GroupTest.hxx @@ -3,8 +3,6 @@ #include -#include "../Xao.hxx" - namespace XAO { class GroupTest: public CppUnit::TestFixture diff --git a/src/XAO/tests/ImportExportTest.cxx b/src/XAO/tests/ImportExportTest.cxx index ed66029af..a7a30727f 100644 --- a/src/XAO/tests/ImportExportTest.cxx +++ b/src/XAO/tests/ImportExportTest.cxx @@ -22,11 +22,11 @@ #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; diff --git a/src/XAO/tests/ImportExportTest.hxx b/src/XAO/tests/ImportExportTest.hxx index 317760cab..2756b2ea8 100644 --- a/src/XAO/tests/ImportExportTest.hxx +++ b/src/XAO/tests/ImportExportTest.hxx @@ -3,7 +3,7 @@ #include -#include "../Xao.hxx" +#include "../XAO_Xao.hxx" namespace XAO { diff --git a/src/XAO/tests/TestUtils.hxx b/src/XAO/tests/TestUtils.hxx index c720b1dad..f754db107 100644 --- a/src/XAO/tests/TestUtils.hxx +++ b/src/XAO/tests/TestUtils.hxx @@ -2,7 +2,7 @@ #define __XAO_TESTUTILS_HXX__ #include -#include "../Xao.hxx" +#include namespace XAO { diff --git a/src/XAO/tests/XaoUtilsTest.cxx b/src/XAO/tests/XaoUtilsTest.cxx index 37d12ce2a..4781c5fbb 100644 --- a/src/XAO/tests/XaoUtilsTest.cxx +++ b/src/XAO/tests/XaoUtilsTest.cxx @@ -1,8 +1,8 @@ #include #include "XaoUtilsTest.hxx" -#include "../Xao.hxx" -#include "../XaoUtils.hxx" +#include "../XAO_Xao.hxx" +#include "../XAO_XaoUtils.hxx" using namespace XAO; diff --git a/src/XAO/tests/XaoUtilsTest.hxx b/src/XAO/tests/XaoUtilsTest.hxx index b69c66cc0..28860d80d 100644 --- a/src/XAO/tests/XaoUtilsTest.hxx +++ b/src/XAO/tests/XaoUtilsTest.hxx @@ -3,8 +3,6 @@ #include -#include "../Xao.hxx" - namespace XAO { class XaoUtilsTest: public CppUnit::TestFixture diff --git a/src/XAO/tests/coverage_report.sh b/src/XAO/tests/coverage_report.sh new file mode 100755 index 000000000..4bec866da --- /dev/null +++ b/src/XAO/tests/coverage_report.sh @@ -0,0 +1,65 @@ +#!/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