add BrepGeometry

This commit is contained in:
fps 2013-08-30 14:13:47 +00:00
parent 56cbe27615
commit 94561d0210
35 changed files with 1415 additions and 252 deletions

View File

@ -176,7 +176,7 @@ bool GEOMImpl_IImportExportOperations::ExportXAO(Handle(GEOM_Object) shape,
XAO::Xao* xaoObject = new XAO::Xao();
xaoObject->setAuthor(author);
XAO::Geometry* geometry = new XAO::Geometry();
XAO::Geometry* geometry = XAO::Geometry::createGeometry(XAO::BREP);
TopoDS_Shape topoShape = shape->GetValue();
exportFunction->SetValue(topoShape);
geometry->setShape(topoShape);

View File

@ -35,6 +35,11 @@ BooleanField::BooleanField(const std::string& name, const XAO::Dimension& dimens
{
}
Step* BooleanField::addNewStep(const int& step)
{
return addStep(step);
}
BooleanStep* BooleanField::addStep(const int& step)
{
BooleanStep* bstep = new BooleanStep(step, m_nbElements, m_nbComponents);

View File

@ -39,6 +39,7 @@ namespace XAO
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);

View File

@ -135,7 +135,7 @@ void BooleanStep::setElements(const int& element, const std::vector<bool>& eleme
void BooleanStep::setComponents(const int& component, const std::vector<bool>& components)
{
checkElement(component);
checkComponent(component);
if (components.size() != m_nbElements)
throw SALOME_Exception("bad size"); // TODO

242
src/XAO/BrepGeometry.cxx Normal file
View File

@ -0,0 +1,242 @@
// 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 <TopTools_MapOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <TColStd_HSequenceOfInteger.hxx>
#include <Utils_SALOME_Exception.hxx>
#include "BrepGeometry.hxx"
#include "XaoUtils.hxx"
using namespace XAO;
BrepGeometry::BrepGeometry() : Geometry("")
{
}
BrepGeometry::BrepGeometry(const std::string& name) : Geometry(name)
{
}
void BrepGeometry::getEdgeVertices(const int& edge, int& vertexA, int& vertexB)
{
throw SALOME_Exception("Not impolemented");
}
const int BrepGeometry::countFacesWires(const int& face)
{
throw SALOME_Exception("Not impolemented");
}
std::vector<int> BrepGeometry::getFacesWires(const int& face)
{
throw SALOME_Exception("Not impolemented");
}
const int BrepGeometry::countSolidShells(const int& solid)
{
throw SALOME_Exception("Not impolemented");
}
std::vector<int> BrepGeometry::getSolidShells(const int& solid)
{
throw SALOME_Exception("Not impolemented");
}
void BrepGeometry::getVertexXYZ(const int& vertex, int& xCoord, int& yCoord, int& zCoord)
{
// TODO
TopTools_MapOfShape mapShape;
TopTools_ListOfShape listShape;
TopExp_Explorer exp(m_shape, TopAbs_ShapeEnum(TopAbs_VERTEX));
for (; exp.More(); exp.Next())
{
if (mapShape.Add(exp.Current()))
listShape.Append(exp.Current());
}
if (listShape.IsEmpty())
return;
TopTools_IndexedMapOfShape indices;
TopExp::MapShapes(m_shape, indices);
std::list<int> indexList;
TopTools_ListIteratorOfListOfShape itSub(listShape);
for (int index = 1; itSub.More(); itSub.Next(), ++index)
{
TopoDS_Shape value = itSub.Value();
indexList.push_back(indices.FindIndex(value));
}
std::list<int>::iterator it = indexList.begin();
// switch (shapeType)
// {
// case TopAbs_VERTEX:
// {
// }
// case TopAbs_EDGE:
// {
// m_edges.setSize(indexList.size());
// for (int i = 0; it != indexList.end(); it++, i++)
// m_edges.setReference(i, XaoUtils::intToString((*it)));
// break;
// }
// case TopAbs_FACE:
// {
// m_faces.setSize(indexList.size());
// for (int i = 0; it != indexList.end(); it++, i++)
// m_faces.setReference(i, XaoUtils::intToString((*it)));
// break;
// }
// case TopAbs_SOLID:
// {
// m_solids.setSize(indexList.size());
// for (int i = 0; it != indexList.end(); it++, i++)
// m_solids.setReference(i, XaoUtils::intToString((*it)));
// break;
// }
// }
}
const double BrepGeometry::getEdgleLength(const int& edge)
{
throw SALOME_Exception("Not impolemented");
}
const double BrepGeometry::getFaceArea(const int& face)
{
throw SALOME_Exception("Not impolemented");
}
const double BrepGeometry::getSolidVolume(const int& solid)
{
throw SALOME_Exception("Not impolemented");
}
const int BrepGeometry::getVertexID(const int& vertex)
{
return XaoUtils::stringToInt(getVertexReference(vertex));
}
const int BrepGeometry::getEdgeID(const int& edge)
{
return XaoUtils::stringToInt(getEdgeReference(edge));
}
const int BrepGeometry::getFaceID(const int& face)
{
return XaoUtils::stringToInt(getFaceReference(face));
}
const int BrepGeometry::getSolidID(const int& solid)
{
return XaoUtils::stringToInt(getSolidReference(solid));
}
void BrepGeometry::setVertexID(const int& vertex, const int& id)
{
throw SALOME_Exception("Not impolemented");
}
void BrepGeometry::setEdgeID(const int& edge, const int& id)
{
throw SALOME_Exception("Not impolemented");
}
void BrepGeometry::setFaceID(const int& face, const int& id)
{
throw SALOME_Exception("Not impolemented");
}
void BrepGeometry::setSolidID(const int& solid, const int& id)
{
throw SALOME_Exception("Not impolemented");
}
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);
}

89
src/XAO/BrepGeometry.hxx Normal file
View File

@ -0,0 +1,89 @@
// Copyright (C) 2013 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// Author : Frederic Pons (OpenCascade)
#ifndef __XAO_BREPGEOMETRY_HXX__
#define __XAO_BREPGEOMETRY_HXX__
#include <string>
#include <vector>
#include <SALOMEconfig.h>
#include <TopoDS_Shape.hxx>
#include "Xao.hxx"
#include "Geometry.hxx"
namespace XAO
{
class BrepGeometry : public Geometry
{
public:
BrepGeometry();
BrepGeometry(const std::string& name);
virtual const XAO::Format getFormat() { return XAO::BREP; }
/**
* Gives the two extrimities of an edge.
* @param edge
* @param vertexA
* @param vertexB
*/
void getEdgeVertices(const int& edge, int& vertexA, int& vertexB);
const int countFacesWires(const int& face);
std::vector<int> getFacesWires(const int& face);
const int countSolidShells(const int& solid);
std::vector<int> getSolidShells(const int& solid);
void getVertexXYZ(const int& vertex, int& xCoord, int& yCoord, int& zCoord);
const double getEdgleLength(const int& edge);
const double getFaceArea(const int& face);
const double getSolidVolume(const int& solid);
const int getVertexID(const int& vertex);
const int getEdgeID(const int& edge);
const int getFaceID(const int& face);
const int getSolidID(const int& solid);
void setVertexID(const int& vertex, const int& id);
void setEdgeID(const int& edge, const int& id);
void setFaceID(const int& face, const int& id);
void setSolidID(const int& solid, const int& id);
const int findVertex(const int& id);
const int findEdge(const int& id);
const int findFace(const int& id);
const int findSolid(const int& id);
const std::string findVertexName(const int& id);
const std::string findEdgeName(const int& id);
const std::string findFaceName(const int& id);
const std::string findSolidName(const int& id);
void changeVertexName(const int& id, const std::string& name);
void changeEdgeName(const int& id, const std::string& name);
void changeFaceName(const int& id, const std::string& name);
void changeSolidName(const int& id, const std::string& name);
};
}
#endif // __XAO_BREPGEOMETRY_HXX__

View File

@ -35,6 +35,11 @@ DoubleField::DoubleField(const std::string& name, const XAO::Dimension& dimensio
{
}
Step* DoubleField::addNewStep(const int& step)
{
return addStep(step);
}
DoubleStep* DoubleField::addStep(const int& step)
{
DoubleStep* bstep = new DoubleStep(step, m_nbElements, m_nbComponents);

View File

@ -40,6 +40,7 @@ namespace XAO
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);

View File

@ -19,6 +19,7 @@
// Author : Frederic Pons (OpenCascade)
#include <string>
#include <sstream>
#include <iostream>
#include "Xao.hxx"
#include "Field.hxx"
@ -42,6 +43,12 @@ Field::Field(const std::string& name, const XAO::Dimension& dimension,
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)
{
@ -97,3 +104,13 @@ bool Field::removeStep(Step* step)
return false;
}
void Field::checkStep(const int& step)
{
if (step >= m_steps.size() || step < 0)
{
std::ostringstream str;
str << "Step index is out of range [0, " << m_steps.size() << "] : " << step;
throw SALOME_Exception(str.str().c_str());
}
}

View File

@ -40,6 +40,13 @@ namespace XAO
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);
@ -49,7 +56,7 @@ namespace XAO
static Field* createField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dimension,
const int& nbElements, const int& nbComponents);
virtual ~Field() {};
virtual ~Field();
/**
* Gets the Type of the field.
@ -131,6 +138,13 @@ namespace XAO
*/
void setComponentName(const int& componentIndex, const std::string& name);
/**
* Adds a new step of the same type than the field.
* @param step the index of the step.
* @return the new create step.
*/
virtual Step* addNewStep(const int& step) = 0;
/**
* Remove a step.
* @param step the step to remove.
@ -138,11 +152,22 @@ namespace XAO
*/
bool removeStep(Step* 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(); }
private:
/** Ensures that component is valid (< m_nbComponents). */
void checkComponent(const int& component);
void checkStep(const int& step);
protected:
/** The name of the Field. */

View File

@ -18,8 +18,6 @@
//
// Author : Nathalie Gore (OpenCascade)
#include "XaoUtils.hxx"
#include "Geometry.hxx"
#include <Standard_TypeMismatch.hxx>
#include <BRepTools.hxx>
@ -45,11 +43,27 @@
#include <Utils_SALOME_Exception.hxx>
#include "XaoUtils.hxx"
#include "Geometry.hxx"
#include "BrepGeometry.hxx"
using namespace XAO;
Geometry::Geometry()
Geometry::Geometry(const std::string& name)
: m_name(name)
{
m_format = "BREP";
}
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("Geometry format not supported.");
}
Geometry::~Geometry()
@ -67,7 +81,7 @@ void Geometry::setShape(const TopoDS_Shape& shape)
initListIds(TopAbs_SOLID);
}
void Geometry::setShape(const char* brep)
void Geometry::setBREP(const char* brep)
{
std::istringstream streamBrep(brep);
BRep_Builder builder;
@ -123,28 +137,28 @@ void Geometry::initListIds(const Standard_Integer shapeType)
{
m_vertices.setSize(indexList.size());
for (int i = 0; it != indexList.end(); it++, i++)
m_vertices.setReference(i, XaoUtils::intToString((*it)).c_str());
m_vertices.setReference(i, XaoUtils::intToString((*it)));
break;
}
case TopAbs_EDGE:
{
m_edges.setSize(indexList.size());
for (int i = 0; it != indexList.end(); it++, i++)
m_edges.setReference(i, XaoUtils::intToString((*it)).c_str());
m_edges.setReference(i, XaoUtils::intToString((*it)));
break;
}
case TopAbs_FACE:
{
m_faces.setSize(indexList.size());
for (int i = 0; it != indexList.end(); it++, i++)
m_faces.setReference(i, XaoUtils::intToString((*it)).c_str());
m_faces.setReference(i, XaoUtils::intToString((*it)));
break;
}
case TopAbs_SOLID:
{
m_solids.setSize(indexList.size());
for (int i = 0; it != indexList.end(); it++, i++)
m_solids.setReference(i, XaoUtils::intToString((*it)).c_str());
m_solids.setReference(i, XaoUtils::intToString((*it)));
break;
}
}
@ -152,74 +166,70 @@ void Geometry::initListIds(const Standard_Integer shapeType)
const int Geometry::countElements(const XAO::Dimension& dim)
{
if (dim == VERTEX)
if (dim == XAO::VERTEX)
return countVertices();
if (dim == EDGE)
if (dim == XAO::EDGE)
return countEdges();
if (dim == FACE)
if (dim == XAO::FACE)
return countFaces();
if (dim == SOLID)
if (dim == XAO::SOLID)
return countSolids();
throw SALOME_Exception("Unknown dimension");
throw SALOME_Exception("Unknown dimension"); // TODO
}
const std::string Geometry::getElementReference(const XAO::Dimension& dim, const int& index)
{
if (dim == VERTEX)
if (dim == XAO::VERTEX)
return getVertexReference(index);
if (dim == EDGE)
if (dim == XAO::EDGE)
return getEdgeReference(index);
if (dim == FACE)
if (dim == XAO::FACE)
return getFaceReference(index);
if (dim == SOLID)
if (dim == XAO::SOLID)
return getSolidReference(index);
std::cout << "getElementReference: unknown dimension" << std::endl;
throw SALOME_Exception("Unknown dimension");
throw SALOME_Exception("Unknown dimension"); // TODO
}
const int Geometry::getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference)
{
if (dim == VERTEX)
if (dim == XAO::VERTEX)
return getVertexIndexByReference(reference);
if (dim == EDGE)
if (dim == XAO::EDGE)
return getEdgeIndexByReference(reference);
if (dim == FACE)
if (dim == XAO::FACE)
return getFaceIndexByReference(reference);
if (dim == SOLID)
if (dim == XAO::SOLID)
return getSolidIndexByReference(reference);
std::cout << "getElementIndexByReference: unknown dimension" << std::endl;
throw SALOME_Exception("Unknown dimension");
throw SALOME_Exception("Unknown dimension"); // TODO
}
GeometricElementList::iterator Geometry::begin(const XAO::Dimension& dim)
{
if (dim == VERTEX)
if (dim == XAO::VERTEX)
return m_vertices.begin();
if (dim == EDGE)
if (dim == XAO::EDGE)
return m_edges.begin();
if (dim == FACE)
if (dim == XAO::FACE)
return m_faces.begin();
if (dim == SOLID)
if (dim == XAO::SOLID)
return m_solids.begin();
std::cout << "begin: unknown dimension" << std::endl;
throw SALOME_Exception("Unknown dimension");
throw SALOME_Exception("Unknown dimension"); // TODO
}
GeometricElementList::iterator Geometry::end(const XAO::Dimension& dim)
{
if (dim == VERTEX)
if (dim == XAO::VERTEX)
return m_vertices.end();
if (dim == EDGE)
if (dim == XAO::EDGE)
return m_edges.end();
if (dim == FACE)
if (dim == XAO::FACE)
return m_faces.end();
if (dim == SOLID)
if (dim == XAO::SOLID)
return m_solids.end();
std::cout << "begin: unknown dimension" << std::endl;
throw SALOME_Exception("Unknown dimension");
throw SALOME_Exception("Unknown dimension"); // TODO
}

View File

@ -33,36 +33,67 @@ namespace XAO
{
class Geometry
{
protected:
Geometry(const std::string& name);
public:
Geometry();
/**
* 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;
}
const std::string getFormat()
{
return m_format;
}
void setFormat(const std::string& format)
{
m_format = format;
}
/**
* Gets the format of the geometry.
* @return the format of the geometry.
*/
virtual const XAO::Format getFormat() = 0;
/**
* Gets the shape of the geometry.
* @return the shape of the geometry.
*/
TopoDS_Shape getShape()
{
return m_shape;
}
/**
* Sets the shape of the geometry.
* @param shape the shape to set.
*/
void setShape(const TopoDS_Shape& shape);
const char* getBREP();
void setShape(const char* brep);
void setBREP(const char* brep);
const int countElements(const XAO::Dimension& dim);
const int countVertices() { return m_vertices.getSize(); }
@ -75,11 +106,6 @@ namespace XAO
void setCountFaces(const int& nb) { m_faces.setSize(nb); }
void setCountSolids(const int& nb) { m_solids.setSize(nb); }
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 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); }
@ -106,6 +132,11 @@ namespace XAO
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); }
@ -118,10 +149,10 @@ namespace XAO
private:
void initListIds(const Standard_Integer shapeType);
private:
TopoDS_Shape m_shape;
protected:
std::string m_name;
std::string m_format;
TopoDS_Shape m_shape;
GeometricElementList m_vertices;
GeometricElementList m_edges;
GeometricElementList m_faces;

View File

@ -49,10 +49,10 @@ Group::~Group()
void Group::checkElement(const int& element)
{
if (element >= m_nbElements)
if (element >= m_nbElements || element < 0)
{
std::ostringstream str;
str << "IndexOutOfRange element: " << element << " >= " << m_nbElements;
throw SALOME_Exception(str.str().c_str()); // TODO
str << "IndexOutOfRange element: " << element << " >= " << m_nbElements; // TODO
throw SALOME_Exception(str.str().c_str());
}
}

View File

@ -105,6 +105,11 @@ namespace XAO
private:
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 checkElement(const int& element);
private:

View File

@ -35,6 +35,11 @@ IntegerField::IntegerField(const std::string& name, const XAO::Dimension& dimens
{
}
Step* IntegerField::addNewStep(const int& step)
{
return addStep(step);
}
IntegerStep* IntegerField::addStep(const int& step)
{
IntegerStep* bstep = new IntegerStep(step, m_nbElements, m_nbComponents);

View File

@ -40,9 +40,10 @@ namespace XAO
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& index);
IntegerStep* getStep(const int& step);
};
}

View File

@ -31,6 +31,7 @@ salomeinclude_HEADERS = \
GeometricElement.hxx \
Xao.hxx \
Geometry.hxx \
BrepGeometry.hxx \
Group.hxx \
Field.hxx \
BooleanField.hxx \
@ -50,6 +51,7 @@ dist_libXAO_la_SOURCES = \
GeometricElement.cxx \
Xao.cxx \
Geometry.cxx \
BrepGeometry.cxx \
Group.cxx \
Field.cxx \
BooleanField.cxx \

View File

@ -18,6 +18,9 @@
//
// Author : Frederic Pons (OpenCascade)
#include <sstream>
#include <Utils_SALOME_Exception.hxx>
#include "Xao.hxx"
#include "Step.hxx"
#include "BooleanStep.hxx"
@ -25,20 +28,9 @@
#include "DoubleStep.hxx"
#include "StringStep.hxx"
#include <Utils_SALOME_Exception.hxx>
using namespace XAO;
Step* Step::createStep(const XAO::Type& type, const int& nbElements, const int& nbComponents)
{
return createStep(type, 0, 0, nbElements, nbComponents);
}
Step* Step::createStep(const XAO::Type& type, const int& step, const int& nbElements, const int& nbComponents)
{
return createStep(type, step, 0, nbElements, nbComponents);
}
Step* Step::createStep(const XAO::Type& type, const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
{
if (type == XAO::BOOLEAN)
@ -55,12 +47,20 @@ Step* Step::createStep(const XAO::Type& type, const int& step, const int& stamp,
void Step::checkElement(const int& element)
{
if (element >= m_nbElements)
throw SALOME_Exception("IndexOutOfRange element"); // TODO
if (element >= m_nbElements || element < 0)
{
std::ostringstream str;
str << "Element index is out of range [0, " << m_nbElements-1 << "] : " << element;
throw SALOME_Exception(str.str().c_str());
}
}
void Step::checkComponent(const int& component)
{
if (component >= m_nbComponents)
throw SALOME_Exception("IndexOutOfRange component"); // TODO
if (component >= m_nbComponents || component < 0)
{
std::ostringstream str;
str << "Component index is out of range [0, " << m_nbComponents-1 << "] : " << component;
throw SALOME_Exception(str.str().c_str());
}
}

View File

@ -29,13 +29,30 @@ namespace XAO
class Step
{
protected:
/** Default constructor. */
Step() {}
public:
static Step* createStep(const XAO::Type& type, const int& nbElements, const int& nbComponents);
static Step* createStep(const XAO::Type& type, const int& step, const int& nbElements, const int& nbComponents);
/**
* 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;
/**
@ -62,13 +79,39 @@ namespace XAO
*/
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:
@ -76,9 +119,13 @@ namespace XAO
void checkComponent(const int& component);
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;
};
}

View File

@ -35,6 +35,11 @@ StringField::StringField(const std::string& name, const XAO::Dimension& dimensio
{
}
Step* StringField::addNewStep(const int& step)
{
return addStep(step);
}
StringStep* StringField::addStep(const int& step)
{
StringStep* bstep = new StringStep(step, m_nbElements, m_nbComponents);

View File

@ -40,6 +40,7 @@ namespace XAO
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);

View File

@ -27,6 +27,15 @@
namespace XAO
{
/**
* @enum CAD
*/
enum Format
{
BREP,
STEP
};
/**
* @enum Dimension
*/
@ -39,12 +48,15 @@ namespace XAO
WHOLE = -1 //!< WHOLE
};
/**
* @enum Type
*/
enum Type
{
BOOLEAN = 0,
INTEGER = 1,
DOUBLE = 2,
STRING = 3
BOOLEAN = 0,//!< BOOLEAN
INTEGER = 1,//!< INTEGER
DOUBLE = 2, //!< DOUBLE
STRING = 3 //!< STRING
};
class Geometry;

View File

@ -1,4 +1,5 @@
#include <sstream>
#include <libxml/parser.h>
#include <Utils_SALOME_Exception.hxx>
@ -68,6 +69,57 @@ namespace XAO
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());
std::ostringstream str;
str << "Line " << node->line << ": ";
str << "Property " << (char*)attribute << " is required.";
throw SALOME_Exception(str.str().c_str());
}
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());
std::ostringstream str;
str << "Property " << (char*)attribute << " is required.";
throw SALOME_Exception(str.str().c_str());
}
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);
@ -123,8 +175,6 @@ void XaoExporter::exportGeometricElements(Geometry* xaoGeometry,
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 xaoGeometry->getVertexName(i));
//xmlNewProp(vertex, C_ATTR_ELT_REFERENCE, BAD_CAST xaoGeometry->getVertexReference(i));
xmlNewProp(vertex, C_ATTR_ELT_NAME, BAD_CAST elt.getName().c_str());
xmlNewProp(vertex, C_ATTR_ELT_REFERENCE, BAD_CAST elt.getReference().c_str());
}
@ -137,7 +187,7 @@ void XaoExporter::exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePt
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 xaoGeometry->getFormat().c_str());
xmlNewProp(shape, C_ATTR_SHAPE_FORMAT, BAD_CAST XaoUtils::shapeFormatToString(xaoGeometry->getFormat()).c_str());
const char* brep = xaoGeometry->getBREP();
xmlNodePtr cdata = xmlNewCDataBlock(doc, BAD_CAST brep, strlen(brep));
xmlAddChild(shape, cdata);
@ -200,7 +250,6 @@ void XaoExporter::exportFields(Xao* xaoObject, xmlNodePtr xao)
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 (int j = 0; j < nbSteps; j++)
for (stepIterator itStep = field->begin(); itStep != field->end(); itStep++)
{
Step* step = *itStep;
@ -274,19 +323,12 @@ void XaoExporter::parseXMLDoc(xmlDocPtr doc, Xao* xaoObject)
void XaoExporter::parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject)
{
xmlChar* version = xmlGetProp(xaoNode, C_ATTR_XAO_VERSION);
if (version != NULL)
{
xaoObject->setVersion((char*)version);
xmlFree(version);
}
std::string version = readStringProp(xaoNode, C_ATTR_XAO_VERSION, false, "");
if (version != "")
xaoObject->setAuthor(version);
xmlChar* author = xmlGetProp(xaoNode, C_ATTR_XAO_AUTHOR);
if (author != NULL)
{
xaoObject->setAuthor((char*)author);
xmlFree(author);
}
std::string author = readStringProp(xaoNode, C_ATTR_XAO_AUTHOR, false, "");
xaoObject->setAuthor(author);
for (xmlNodePtr node = xaoNode->children; node; node = node->next)
{
@ -294,45 +336,50 @@ void XaoExporter::parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject
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)
{
Geometry* geometry = new Geometry();
xmlChar* name = xmlGetProp(geometryNode, C_ATTR_GEOMETRY_NAME);
if (name != NULL)
{
geometry->setName((char*)name);
xmlFree(name);
}
// 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)
parseShapeNode(doc, node, geometry);
shapeNode = node;
else if (xmlStrcmp(node->name, C_TAG_TOPOLOGY) == 0)
parseTopologyNode(node, geometry);
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)
{
xmlChar* shapeType = xmlGetProp(shapeNode, C_ATTR_SHAPE_FORMAT);
if (xmlStrcmp(shapeType, (xmlChar*)"BREP") == 0)
if (geometry->getFormat() == XAO::BREP)
{
xmlChar* data = xmlNodeGetContent(shapeNode->children);
if (data == NULL)
throw SALOME_Exception("Missing BREP");
geometry->setShape((char*)data);
geometry->setBREP((char*)data);
xmlFree(data);
}
else
{
throw SALOME_Exception("Shape format not supported");
std::ostringstream str;
str << "Shape format not supported: " << XaoUtils::shapeFormatToString(geometry->getFormat());
throw SALOME_Exception(str.str().c_str());
}
}
@ -353,120 +400,72 @@ void XaoExporter::parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry)
void XaoExporter::parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry)
{
xmlChar* count = xmlGetProp(verticesNode, C_ATTR_COUNT);
if (count == NULL)
throw SALOME_Exception("No count attribute for vertices");
geometry->setCountVertices(atoi((char*)count));
xmlFree(count);
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)
{
xmlChar* index = xmlGetProp(node, C_ATTR_ELT_INDEX);
if (index == NULL)
throw SALOME_Exception("Bad index for vertex");
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, "");
xmlChar* name = xmlGetProp(node, C_ATTR_ELT_NAME);
if (name == NULL)
name = (xmlChar*)"";
xmlChar* reference = xmlGetProp(node, C_ATTR_ELT_REFERENCE);
if (reference == NULL)
throw SALOME_Exception("Bad reference for vertex");
geometry->setVertex(atoi((char*)index), (char*)name, (char*)reference);
geometry->setVertex(index, name, reference);
}
}
}
void XaoExporter::parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry)
{
xmlChar* count = xmlGetProp(edgesNode, C_ATTR_COUNT);
if (count == NULL)
throw SALOME_Exception("No count attribute for edges");
geometry->setCountEdges(atoi((char*)count));
xmlFree(count);
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)
{
xmlChar* index = xmlGetProp(node, C_ATTR_ELT_INDEX);
if (index == NULL)
throw SALOME_Exception("Bad index for edge");
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, "");
xmlChar* name = xmlGetProp(node, C_ATTR_ELT_NAME);
if (name == NULL)
name = (xmlChar*)"";
xmlChar* reference = xmlGetProp(node, C_ATTR_ELT_REFERENCE);
if (reference == NULL)
throw SALOME_Exception("Bad reference for edge");
geometry->setEdge(atoi((char*)index), (char*)name, (char*)reference);
geometry->setEdge(index, name, reference);
}
}
}
void XaoExporter::parseFacesNode(xmlNodePtr facesNode, Geometry* geometry)
{
xmlChar* count = xmlGetProp(facesNode, C_ATTR_COUNT);
if (count == NULL)
throw SALOME_Exception("No count attribute for faces");
geometry->setCountFaces(atoi((char*)count));
xmlFree(count);
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)
{
xmlChar* index = xmlGetProp(node, C_ATTR_ELT_INDEX);
if (index == NULL)
throw SALOME_Exception("Bad index for face");
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, "");
xmlChar* name = xmlGetProp(node, C_ATTR_ELT_NAME);
if (name == NULL)
name = (xmlChar*)"";
xmlChar* reference = xmlGetProp(node, C_ATTR_ELT_REFERENCE);
if (reference == NULL)
throw SALOME_Exception("Bad reference for face");
geometry->setFace(atoi((char*)index), (char*)name, (char*)reference);
geometry->setFace(index, name, reference);
}
}
}
void XaoExporter::parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry)
{
xmlChar* count = xmlGetProp(solidsNode, C_ATTR_COUNT);
if (count == NULL)
throw SALOME_Exception("No count attribute for solids");
geometry->setCountSolids(atoi((char*)count));
xmlFree(count);
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)
{
xmlChar* index = xmlGetProp(node, C_ATTR_ELT_INDEX);
if (index == NULL)
throw SALOME_Exception("Bad index for solid");
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, "");
xmlChar* name = xmlGetProp(node, C_ATTR_ELT_NAME);
if (name == NULL)
name = (xmlChar*)"";
xmlChar* reference = xmlGetProp(node, C_ATTR_ELT_REFERENCE);
if (reference == NULL)
throw SALOME_Exception("Bad reference for solid");
geometry->setSolid(atoi((char*)index), (char*)name, (char*)reference);
geometry->setSolid(index, name, reference);
}
}
}
@ -484,28 +483,130 @@ void XaoExporter::parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject)
void XaoExporter::parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject)
{
xmlChar* dimension = xmlGetProp(groupNode, C_ATTR_GROUP_DIM);
if (dimension == NULL)
throw SALOME_Exception("Bad dimension for group");
XAO::Dimension dim = XaoUtils::stringToDimension((char*)dimension);
std::string strDimension = readStringProp(groupNode, C_ATTR_GROUP_DIM, true, "");
XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
Group* group = xaoObject->addGroup(dim);
xmlFree(dimension);
xmlChar* name = xmlGetProp(groupNode, C_ATTR_GROUP_NAME);
if (name == NULL) name = (xmlChar*)"";
group->setName((char*)name);
xmlFree(name);
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)
{
xmlChar* index = xmlGetProp(node, C_ATTR_ELEMENT_INDEX);
if (index == NULL)
throw SALOME_Exception("Bad index for group element");
group->addElement(atoi((char*)index));
xmlFree(index);
int index = readIntegerProp(node, C_ATTR_ELEMENT_INDEX, true, -1);
group->addElement(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("No components defined for field"); // TODO
// 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)
{
std::ostringstream str;
str << "Line " << valNode->line << ": no content for value.";
throw SALOME_Exception(str.str().c_str());
}
std::string value = (char*)data;
step->setStringValue(index, component, value);
}
}
}

View File

@ -40,6 +40,16 @@ namespace XAO
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(""));
};
}

View File

@ -65,15 +65,15 @@ const double XaoUtils::stringToDouble(const std::string& value)
const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
{
if (dimension == VERTEX)
if (dimension == XAO::VERTEX)
return "vertex";
if (dimension == EDGE)
if (dimension == XAO::EDGE)
return "edge";
if (dimension == FACE)
if (dimension == XAO::FACE)
return "face";
if (dimension == SOLID)
if (dimension == XAO::SOLID)
return "solid";
if (dimension == WHOLE)
if (dimension == XAO::WHOLE)
return "whole";
throw SALOME_Exception("Bad dimension");
}
@ -81,27 +81,27 @@ const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
const XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension)
{
if (dimension == "vertex")
return VERTEX;
return XAO::VERTEX;
if (dimension == "edge")
return EDGE;
return XAO::EDGE;
if (dimension == "face")
return FACE;
return XAO::FACE;
if (dimension == "solid")
return SOLID;
return XAO::SOLID;
if (dimension == "whole")
return WHOLE;
return XAO::WHOLE;
throw SALOME_Exception("Bad dimension");
}
const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
{
if (type == BOOLEAN)
if (type ==XAO:: BOOLEAN)
return "boolean";
if (type == INTEGER)
if (type == XAO::INTEGER)
return "integer";
if (type == DOUBLE)
if (type == XAO::DOUBLE)
return "double";
if (type == STRING)
if (type == XAO::STRING)
return "string";
throw SALOME_Exception("Bad type");
}
@ -109,12 +109,30 @@ const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
const XAO::Type XaoUtils::stringToFieldType(const std::string& type)
{
if (type == "boolean")
return BOOLEAN;
return XAO::BOOLEAN;
if (type == "integer")
return INTEGER;
return XAO::INTEGER;
if (type == "double")
return DOUBLE;
return XAO::DOUBLE;
if (type == "string")
return STRING;
return XAO::STRING;
throw SALOME_Exception("Bad 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("Bad 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("Bad format");
}

View File

@ -38,7 +38,6 @@ namespace XAO
* \param value the integer to convert.
* \return the string.
*/
//static const char* intToString(const int value);
static const std::string intToString(const int& value);
static const int stringToInt(const std::string& value);
@ -76,7 +75,23 @@ namespace XAO
* \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);
};
}

View File

@ -0,0 +1,50 @@
#include <vector>
#include <Utils_SALOME_Exception.hxx>
#include "TestUtils.hxx"
#include "BrepGeometryTest.hxx"
#include "../Xao.hxx"
#include "../BrepGeometry.hxx"
using namespace XAO;
void BrepGeometryTest::setUp()
{
}
void BrepGeometryTest::tearDown()
{
}
void BrepGeometryTest::cleanUp()
{
}
void readBrep(Geometry* geom, const std::string& fileName)
{
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath(fileName));
geom->setBREP(txt);
}
void BrepGeometryTest::testGetIDs()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_1.brep");
int vertices[8] = { 6,7,9,11,16,17,19,21 };
for (int i = 0; i < 8; ++i)
CPPUNIT_ASSERT(geom->getVertexID(i) == vertices[i]);
int edges[12] = { 5,8,10,12,15,18,20,22,25,26,29,30 };
for (int i = 0; i < 12; ++i)
CPPUNIT_ASSERT(geom->getEdgeID(i) == edges[i]);
int faces[6] = { 3,13,23,27,31,33 };
for (int i = 0; i < 6; ++i)
CPPUNIT_ASSERT(geom->getFaceID(i) == faces[i]);
CPPUNIT_ASSERT(geom->getSolidID(0) == 1);
}

View File

@ -0,0 +1,25 @@
#ifndef __XAO_BREPGEOMETRY_TEST_HXX__
#define __XAO_BREPGEOMETRY_TEST_HXX__
#include <cppunit/extensions/HelperMacros.h>
#include "../Xao.hxx"
namespace XAO
{
class BrepGeometryTest: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(BrepGeometryTest);
CPPUNIT_TEST(testGetIDs);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void cleanUp();
void testGetIDs();
};
}
#endif // __XAO_BREPGEOMETRY_TEST_HXX__

View File

@ -67,7 +67,7 @@ void FieldTest::testStringField()
void FieldTest::testStep(XAO::Type type)
{
Step* step = Step::createStep(type, 5, 3);
Step* step = Step::createStep(type, 0, 0, 5, 3);
CPPUNIT_ASSERT(step->getType() == type);
CPPUNIT_ASSERT(step->getStep() == 0);
@ -105,7 +105,7 @@ void FieldTest::testIntegerStepValues()
int nbComponents = 3;
int nbElements = 5;
IntegerStep* istep = (IntegerStep*)Step::createStep(XAO::INTEGER, nbElements, nbComponents);
IntegerStep* istep = (IntegerStep*)Step::createStep(XAO::INTEGER, 0, 0, nbElements, nbComponents);
for (int i = 0; i < istep->countElements(); ++i)
{
for (int j = 0; j < istep->countComponents(); ++j)

View File

@ -18,21 +18,18 @@
//
// Author : Frederic Pons (OpenCascade)
#include <stdio.h>
#include <Utils_SALOME_Exception.hxx>
#include "TestUtils.hxx";
#include "ImportExportTest.hxx"
#include "../Geometry.hxx"
#include "../Group.hxx"
#include "../Field.hxx"
#include "../IntegerField.hxx"
#include "../IntegerStep.hxx"
using namespace XAO;
std::string getTestFile(std::string fileName)
{
std::string dataDir = getenv("GEOM_SRC_DIR");
dataDir += "/src/XAO/tests/data/" + fileName;
return dataDir;
}
void ImportExportTest::setUp()
{
@ -57,7 +54,7 @@ void ImportExportTest::testExportNoGeometry()
void ImportExportTest::testExportGeometry()
{
Xao xao("me", "1.0");
Geometry* geom = new Geometry();
Geometry* geom = Geometry::createGeometry(XAO::BREP);
geom->setName("mygeom");
xao.setGeometry(geom);
@ -90,6 +87,20 @@ void ImportExportTest::testExportGeometry()
group->addElement(0);
group->addElement(1);
// fields
IntegerField* field = (IntegerField*)xao.addField(XAO::INTEGER, "color", XAO::FACE, 2);
for (int stepIndex = 0; stepIndex < 10; ++stepIndex)
{
IntegerStep* istep = field->addStep(stepIndex, 100*stepIndex);
for (int eltIndex = 0; eltIndex < istep->countElements(); ++eltIndex)
{
for (int compIndex = 0; compIndex < istep->countComponents(); ++compIndex)
{
istep->setValue(eltIndex, compIndex, istep->getStamp() + eltIndex*10 + compIndex);
}
}
}
bool res = xao.exportXAO("mygeom.xao");
CPPUNIT_ASSERT(res);
@ -100,7 +111,7 @@ void ImportExportTest::testExportGeometry()
void ImportExportTest::testGeometryError()
{
Xao xao("me", "1.0");
Geometry* geom = new Geometry();
Geometry* geom = Geometry::createGeometry(XAO::BREP);
geom->setName("mygeom");
xao.setGeometry(geom);
@ -110,22 +121,13 @@ void ImportExportTest::testGeometryError()
void ImportExportTest::testImportXao()
{
//std::cout << std::endl;
Xao xao;
xao.importXAO(getTestFile("test.xao").c_str());
xao.importXAO(TestUtils::getTestFilePath("test.xao"));
checkImport(xao);
}
void ImportExportTest::checkImport(Xao& xao)
{
// std::string zz = "toto";
// std::cout << "?? " << (zz == "toto" ? "yes" : "no" ) << std::endl;
//
// std::cout << std::endl << "Author = " << xao.getAuthor()
// << " : " << (xao.getAuthor() == "me" ? "yes" : "no") << std::endl;
// std::cout << " : " << ("me" == xao.getAuthor() ? "yes" : "no") << std::endl;
// std::cout << " : " << (xao.getAuthor().compare("me") ? "yes" : "no") << std::endl;
CPPUNIT_ASSERT(xao.getAuthor() == "me");
CPPUNIT_ASSERT(xao.getVersion() == "1.0");
@ -177,15 +179,16 @@ void ImportExportTest::checkImport(Xao& xao)
void ImportExportTest::testImportXaoFromText()
{
std::ifstream rstr;
int length;
rstr.open(getTestFile("test.xao").c_str());
rstr.seekg(0, rstr.end); // go to the end
length = rstr.tellg(); // report location (this is the length)
rstr.seekg(0, rstr.beg); // go back to the beginning
char* txt = new char[length]; // allocate memory for a buffer of appropriate dimension
rstr.read(txt, length); // read the whole file into the buffer
rstr.close();
// std::ifstream rstr;
// int length;
// rstr.open(TestUtils::getTestFilePath("test.xao").c_str());
// rstr.seekg(0, rstr.end); // go to the end
// length = rstr.tellg(); // report location (this is the length)
// rstr.seekg(0, rstr.beg); // go back to the beginning
// char* txt = new char[length]; // allocate memory for a buffer of appropriate dimension
// rstr.read(txt, length); // read the whole file into the buffer
// rstr.close();
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("test.xao"));
Xao xao;
xao.setXML(txt);

View File

@ -41,6 +41,7 @@ TestXAO_LDFLAGS = \
dist_TestXAO_SOURCES = \
FieldTest.cxx \
ImportExportTest.cxx \
BrepGeometryTest.cxx \
XAOTests.cxx
UNIT_TEST_PROG = TestXAO

View File

@ -0,0 +1,43 @@
/*
* TestUtils.hxx
*
* Created on: 30 août 2013
* Author: salome
*/
#ifndef __XAO_TESTUTILS_HXX__
#define __XAO_TESTUTILS_HXX__
#include <fstream>
#include "../Xao.hxx"
namespace XAO
{
class TestUtils
{
public:
static std::string getTestFilePath(const std::string& fileName)
{
std::string dataDir = getenv("GEOM_SRC_DIR");
dataDir += "/src/XAO/tests/data/" + fileName;
return dataDir;
}
static char* readTextFile(const std::string& filePath)
{
std::ifstream rstr;
int length;
rstr.open(filePath.c_str());
rstr.seekg(0, rstr.end); // go to the end
length = rstr.tellg(); // report location (this is the length)
rstr.seekg(0, rstr.beg); // go back to the beginning
char* txt = new char[length]; // allocate memory for a buffer of appropriate dimension
rstr.read(txt, length); // read the whole file into the buffer
rstr.close();
return txt;
}
};
}
#endif /* __XAO_TESTUTILS_HXX__ */

View File

@ -1,7 +1,9 @@
#include "FieldTest.hxx"
#include "ImportExportTest.hxx"
#include "BrepGeometryTest.hxx"
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::FieldTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::ImportExportTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::BrepGeometryTest);
#include "MainTest.hxx"

View File

@ -0,0 +1,366 @@
DBRep_DrawableShape
CASCADE Topology V1, (c) Matra-Datavision
Locations 0
Curve2ds 24
1 0 0 1 0
1 0 0 1 0
1 200 0 0 -1
1 0 0 0 1
1 0 -200 1 0
1 0 0 1 0
1 0 0 0 -1
1 0 0 0 1
1 0 0 1 0
1 0 200 1 0
1 200 0 0 -1
1 200 0 0 1
1 0 -200 1 0
1 0 200 1 0
1 0 0 0 -1
1 200 0 0 1
1 0 0 0 1
1 0 0 1 0
1 200 0 0 1
1 0 0 1 0
1 0 0 0 1
1 0 200 1 0
1 200 0 0 1
1 0 200 1 0
Curves 12
1 0 0 0 0 0 1
1 0 0 200 -0 1 0
1 0 200 0 0 0 1
1 0 0 0 -0 1 0
1 200 0 0 0 0 1
1 200 0 200 0 1 0
1 200 200 0 0 0 1
1 200 0 0 -0 1 0
1 0 0 0 1 0 -0
1 0 0 200 1 0 -0
1 0 200 0 1 0 -0
1 0 200 200 1 0 -0
Polygon3D 0
PolygonOnTriangulations 24
2 1 2
p 0.8000000008 1 0 200
2 1 4
p 0.8000000008 1 0 200
2 2 3
p 0.8000000008 1 0 200
2 1 2
p 0.8000000008 1 0 200
2 4 3
p 0.8000000008 1 0 200
2 1 4
p 0.8000000008 1 0 200
2 1 4
p 0.8000000008 1 0 200
2 1 2
p 0.8000000008 1 0 200
2 1 2
p 0.8000000008 1 0 200
2 2 3
p 0.8000000008 1 0 200
2 2 3
p 0.8000000008 1 0 200
2 4 3
p 0.8000000008 1 0 200
2 4 3
p 0.8000000008 1 0 200
2 2 3
p 0.8000000008 1 0 200
2 1 4
p 0.8000000008 1 0 200
2 4 3
p 0.8000000008 1 0 200
2 1 2
p 0.8000000008 1 0 200
2 1 4
p 0.8000000008 1 0 200
2 4 3
p 0.8000000008 1 0 200
2 1 4
p 0.8000000008 1 0 200
2 1 2
p 0.8000000008 1 0 200
2 2 3
p 0.8000000008 1 0 200
2 4 3
p 0.8000000008 1 0 200
2 2 3
p 0.8000000008 1 0 200
Surfaces 6
1 0 0 0 1 0 -0 0 0 1 0 -1 0
1 0 0 0 -0 1 0 0 0 1 1 0 -0
1 0 0 200 0 0 1 1 0 -0 -0 1 0
1 0 200 0 -0 1 0 0 0 1 1 0 -0
1 0 0 0 0 0 1 1 0 -0 -0 1 0
1 200 0 0 1 0 -0 0 0 1 0 -1 0
Triangulations 6
4 2 1 0
0 0 0 0 0 200 0 200 200 0 200 0 0 0 200 0 200 -200 0 -200 2 4 3 2 1 4
4 2 1 0
0 0 0 200 0 0 200 0 200 0 0 200 0 0 0 200 200 200 200 0 3 2 1 3 1 4
4 2 1 0
0 0 200 0 200 200 200 200 200 200 0 200 0 0 0 200 200 200 200 0 3 2 1 3 1 4
4 2 1 0
0 200 0 200 200 0 200 200 200 0 200 200 0 0 0 200 200 200 200 0 3 2 1 3 1 4
4 2 1 0
0 0 0 0 200 0 200 200 0 200 0 0 0 0 0 200 200 200 200 0 3 2 1 3 1 4
4 2 1 0
200 0 0 200 0 200 200 200 200 200 200 0 0 0 200 0 200 -200 0 -200 2 4 3 2 1 4
TShapes 34
Ve
1e-07
0 0 200
0 0
0101101
*
Ve
1e-07
0 0 0
0 0
0101101
*
Ed
1e-07 1 1 0
1 1 0 0 200
2 1 1 0 0 200
2 2 2 0 0 200
6 1 1 0
6 2 2 0
0
0101000
-34 0 +33 0 *
Ve
1e-07
0 200 200
0 0
0101101
*
Ed
1e-07 1 1 0
1 2 0 0 200
2 3 1 0 0 200
2 4 3 0 0 200
6 3 1 0
6 4 3 0
0
0101000
-31 0 +34 0 *
Ve
1e-07
0 200 0
0 0
0101101
*
Ed
1e-07 1 1 0
1 3 0 0 200
2 5 1 0 0 200
2 6 4 0 0 200
6 5 1 0
6 6 4 0
0
0101000
-31 0 +29 0 *
Ed
1e-07 1 1 0
1 4 0 0 200
2 7 1 0 0 200
2 8 5 0 0 200
6 7 1 0
6 8 5 0
0
0101000
-29 0 +33 0 *
Wi
0101000
-32 0 -30 0 +28 0 +27 0 *
Fa
0 1e-07 1 0
2 1
0101000
+26 0 *
Ve
1e-07
200 0 200
0 0
0101101
*
Ve
1e-07
200 0 0
0 0
0101101
*
Ed
1e-07 1 1 0
1 5 0 0 200
2 9 6 0 0 200
2 10 2 0 0 200
6 9 6 0
6 10 2 0
0
0101000
-24 0 +23 0 *
Ve
1e-07
200 200 200
0 0
0101101
*
Ed
1e-07 1 1 0
1 6 0 0 200
2 11 6 0 0 200
2 12 3 0 0 200
6 11 6 0
6 12 3 0
0
0101000
-21 0 +24 0 *
Ve
1e-07
200 200 0
0 0
0101101
*
Ed
1e-07 1 1 0
1 7 0 0 200
2 13 6 0 0 200
2 14 4 0 0 200
6 13 6 0
6 14 4 0
0
0101000
-21 0 +19 0 *
Ed
1e-07 1 1 0
1 8 0 0 200
2 15 6 0 0 200
2 16 5 0 0 200
6 15 6 0
6 16 5 0
0
0101000
-19 0 +23 0 *
Wi
0101000
-22 0 -20 0 +18 0 +17 0 *
Fa
0 1e-07 6 0
2 6
0101000
+16 0 *
Ed
1e-07 1 1 0
1 9 0 0 200
2 17 2 0 0 200
2 18 5 0 0 200
6 17 2 0
6 18 5 0
0
0101000
-23 0 +33 0 *
Ed
1e-07 1 1 0
1 10 0 0 200
2 19 2 0 0 200
2 20 3 0 0 200
6 19 2 0
6 20 3 0
0
0101000
-24 0 +34 0 *
Wi
0101000
-14 0 -22 0 +13 0 +32 0 *
Fa
0 1e-07 2 0
2 2
0101000
+12 0 *
Ed
1e-07 1 1 0
1 11 0 0 200
2 21 4 0 0 200
2 22 5 0 0 200
6 21 4 0
6 22 5 0
0
0101000
-19 0 +29 0 *
Ed
1e-07 1 1 0
1 12 0 0 200
2 23 4 0 0 200
2 24 3 0 0 200
6 23 4 0
6 24 3 0
0
0101000
-21 0 +31 0 *
Wi
0101000
-10 0 -18 0 +9 0 +28 0 *
Fa
0 1e-07 4 0
2 4
0101000
+8 0 *
Wi
0101000
-27 0 -10 0 +17 0 +14 0 *
Fa
0 1e-07 5 0
2 5
0101000
+6 0 *
Wi
0101000
-30 0 -9 0 +20 0 +13 0 *
Fa
0 1e-07 3 0
2 3
0101000
+4 0 *
Sh
0101100
-25 0 +15 0 -11 0 +7 0 -5 0 +3 0 *
So
1100000
+2 0 *
+1 0

View File

@ -317,4 +317,29 @@ So
<element index="1" />
</group>
</groups>
<fields count="1">
<field name="color" type="integer" dimension="solid">
<components count="3">
<component column="0" name="Red" />
<component column="1" name="Green" />
<component column="2" name="Blue" />
</components>
<steps count="2">
<step number="0" stamp="100">
<element index="0">
<value component="0">100</value>
<value component="1">110</value>
<value component="2">120</value>
</element>
</step>
<step number="1" stamp="200">
<element index="0">
<value component="0">255</value>
<value component="1">0</value>
<value component="2">0</value>
</element>
</step>
</steps>
</field>
</fields>
</XAO>