update BrepGeometry

more tests
This commit is contained in:
fps 2013-09-02 14:47:30 +00:00
parent 94561d0210
commit e9e620c9ba
16 changed files with 637 additions and 190 deletions

View File

@ -27,6 +27,11 @@
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <TColStd_HSequenceOfInteger.hxx>
#include <GProp_GProps.hxx>
#include <BRepGProp.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_Tool.hxx>
#include <Utils_SALOME_Exception.hxx>
@ -43,101 +48,153 @@ BrepGeometry::BrepGeometry(const std::string& name) : Geometry(name)
{
}
void BrepGeometry::getEdgeVertices(const int& edge, int& vertexA, int& vertexB)
TopoDS_Shape BrepGeometry::getGeometricalElement(TopAbs_ShapeEnum shapeType, const int& shapeIndex)
{
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));
TopExp_Explorer exp(m_shape, shapeType);
for (; exp.More(); exp.Next())
{
if (mapShape.Add(exp.Current()))
listShape.Append(exp.Current());
}
if (listShape.IsEmpty())
return;
if (!listShape.IsEmpty())
{
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();
if (shapeIndex == (int)indices.FindIndex(value))
return value;
}
}
throw SALOME_Exception("Shape not found"); // TODO
}
const int BrepGeometry::countGeometricalElements(TopoDS_Shape shape, TopAbs_ShapeEnum shapeType)
{
int res = 0;
TopTools_MapOfShape mapShape;
TopExp_Explorer exp(shape, shapeType);
for (; exp.More(); exp.Next())
{
// if (mapShape.Add(exp.Current()))
res++;
}
return res;
}
std::vector<int> BrepGeometry::getGeometricalElements(TopoDS_Shape shape, TopAbs_ShapeEnum shapeType)
{
std::vector<int> indexList;
TopTools_MapOfShape mapShape;
TopTools_ListOfShape listShape;
TopExp_Explorer exp(shape, shapeType);
for (; exp.More(); exp.Next())
{
if (mapShape.Add(exp.Current()))
listShape.Append(exp.Current());
}
if (!listShape.IsEmpty())
{
TopTools_IndexedMapOfShape indices;
TopExp::MapShapes(shape, indices);
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;
// }
// }
return indexList;
}
const double BrepGeometry::getEdgleLength(const int& edge)
void BrepGeometry::getEdgeVertices(const int& edge, int& vertexA, int& vertexB)
{
throw SALOME_Exception("Not impolemented");
throw SALOME_Exception("Not implemented");
}
const int BrepGeometry::countFaceWires(const int& face)
{
TopoDS_Shape shape = getGeometricalElement(TopAbs_FACE, face);
return countGeometricalElements(shape, TopAbs_WIRE);
}
std::vector<int> BrepGeometry::getFaceWires(const int& face)
{
TopoDS_Shape shape = getGeometricalElement(TopAbs_FACE, face);
return getGeometricalElements(shape, TopAbs_WIRE);
}
const int BrepGeometry::countSolidShells(const int& solid)
{
TopoDS_Shape shape = getGeometricalElement(TopAbs_SOLID, solid);
return countGeometricalElements(shape, TopAbs_SHELL);
}
std::vector<int> BrepGeometry::getSolidShells(const int& solid)
{
TopoDS_Shape shape = getGeometricalElement(TopAbs_SOLID, solid);
return getGeometricalElements(shape, TopAbs_SHELL);
}
void BrepGeometry::getVertexXYZ(const int& vertex, double& xCoord, double& yCoord, double& zCoord)
{
TopoDS_Shape shape = getGeometricalElement(TopAbs_VERTEX, vertex);
xCoord = 0.;
yCoord = 0.;
zCoord = 0.;
if ( shape.ShapeType() != TopAbs_VERTEX )
{
throw SALOME_Exception("not a point"); // TODO
}
TopoDS_Vertex aPoint = TopoDS::Vertex( shape );
if ( !aPoint.IsNull() )
{
gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
xCoord = aPnt.X();
yCoord = aPnt.Y();
zCoord = aPnt.Z();
}
}
const double BrepGeometry::getEdgeLength(const int& edge)
{
TopoDS_Shape shape = getGeometricalElement(TopAbs_EDGE, edge);
GProp_GProps system;
BRepGProp::LinearProperties(shape, system);
return system.Mass();
}
const double BrepGeometry::getFaceArea(const int& face)
{
throw SALOME_Exception("Not impolemented");
TopoDS_Shape shape = getGeometricalElement(TopAbs_FACE, face);
GProp_GProps system;
BRepGProp::SurfaceProperties(shape, system);
return system.Mass();
}
const double BrepGeometry::getSolidVolume(const int& solid)
{
throw SALOME_Exception("Not impolemented");
TopoDS_Shape shape = getGeometricalElement(TopAbs_SOLID, solid);
GProp_GProps system;
BRepGProp::VolumeProperties(shape, system);
return system.Mass();
}
const int BrepGeometry::getVertexID(const int& vertex)
@ -162,22 +219,22 @@ const int BrepGeometry::getSolidID(const int& solid)
void BrepGeometry::setVertexID(const int& vertex, const int& id)
{
throw SALOME_Exception("Not impolemented");
setVertexReference(vertex, XaoUtils::intToString(id));
}
void BrepGeometry::setEdgeID(const int& edge, const int& id)
{
throw SALOME_Exception("Not impolemented");
setEdgeReference(edge, XaoUtils::intToString(id));
}
void BrepGeometry::setFaceID(const int& face, const int& id)
{
throw SALOME_Exception("Not impolemented");
setEdgeReference(face, XaoUtils::intToString(id));
}
void BrepGeometry::setSolidID(const int& solid, const int& id)
{
throw SALOME_Exception("Not impolemented");
setEdgeReference(solid, XaoUtils::intToString(id));
}
const int BrepGeometry::findVertex(const int& id)

View File

@ -48,20 +48,90 @@ namespace XAO
*/
void getEdgeVertices(const int& edge, int& vertexA, int& vertexB);
const int countFacesWires(const int& face);
std::vector<int> getFacesWires(const int& face);
/**
* Gets the number of wires of a face (including holes).
* @param face the index of the face.
* @return the number of wires.
*/
const int countFaceWires(const int& face);
/**
* Gets the indices of the wires of the face.
* @param face the index of the face.
* @return the list of wires for the given face.
*/
std::vector<int> getFaceWires(const int& face);
/**
* Gets the number of shells of a solid (including cavities).
* @param solid the index of the solid.
* @return the number of shells.
*/
const int countSolidShells(const int& solid);
/**
* Gets the indices of the shells of the solids.
* @param solid the index of the solid.
* @return the list of shells for the given 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);
/**
* Gets the coordinates of a vertex.
* @param vertex the index of the vertex.
* @param xCoord the X coordinate.
* @param yCoord the Y coordinate.
* @param zCoord the Z coordinate.
*/
void getVertexXYZ(const int& vertex, 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& edge);
/**
* Gets the are of a face.
* @param face the index of a face.
* @return the area of the face.
*/
const double getFaceArea(const int& face);
/**
* Gets the volume of a solid.
* @param solid the index of the solid.
* @return the volume of the solid.
*/
const double getSolidVolume(const int& solid);
/**
* Gets the ID of a vertex.
* @param vertex the index of the vertex.
* @return the ID of the vertex.
*/
const int getVertexID(const int& vertex);
/**
* Gets the ID of an edge.
* @param edge the index of the edge.
* @return the ID of the edge.
*/
const int getEdgeID(const int& edge);
/**
* Gets the ID of a face.
* @param face the index of the face.
* @return the ID of the face.
*/
const int getFaceID(const int& face);
/**
* 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& vertex, const int& id);
@ -69,20 +139,95 @@ namespace XAO
void setFaceID(const int& face, const int& id);
void setSolidID(const int& solid, 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:
TopoDS_Shape getGeometricalElement(TopAbs_ShapeEnum shapeType, const int& shapeIndex);
const int countGeometricalElements(TopoDS_Shape shape, TopAbs_ShapeEnum shapeType);
std::vector<int> getGeometricalElements(TopoDS_Shape shape, TopAbs_ShapeEnum shapeType);
};
}

View File

@ -51,11 +51,33 @@ namespace XAO
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();
/**

View File

@ -89,7 +89,9 @@ namespace XAO
}
private:
/** The name of the element. */
std::string m_name;
/** The reference of the element. */
std::string m_reference;
};
@ -104,11 +106,13 @@ namespace XAO
* Default constructor.
*/
GeometricElementList();
/**
* Constructor with size.
* \param nb the size to set.
*/
GeometricElementList(const int& nb);
/**
* Destructor.
*/
@ -119,6 +123,7 @@ namespace XAO
* \return the size of the list.
*/
const int getSize() { return m_count; }
/**
* Sets the size of the list.
* \param nb the size to set.
@ -183,7 +188,16 @@ namespace XAO
*/
typedef std::map<int, GeometricElement>::iterator iterator;
/**
* Gets an iterator on the first element.
* @return an iterator on the first element.
*/
iterator begin() { return m_elements.begin(); }
/**
* Gets an iterator on the last element.
* @return an iterator on the last element.
*/
iterator end() { return m_elements.end(); }
private:

View File

@ -47,12 +47,22 @@ Group::~Group()
{
}
void Group::checkElement(const int& element)
void Group::checkIndex(const int& element)
{
if (element >= m_nbElements || element < 0)
if (element >= m_elements.size() || element < 0)
{
std::ostringstream str;
str << "IndexOutOfRange element: " << element << " >= " << m_nbElements; // TODO
str << "Index of element is out of range [0, " << m_elements.size()-1 << "]: " << element;
throw SALOME_Exception(str.str().c_str());
}
}
void Group::add(const int& value)
{
m_elements.insert(value);
}
void Group::remove(const int& value)
{
m_elements.erase(value);
}

View File

@ -23,7 +23,7 @@
# include <iostream>
#include <string>
#include <vector>
#include <set>
#include "Xao.hxx"
@ -37,9 +37,18 @@ namespace XAO
{
public:
/**
* Default constructor.
* 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);
/**
@ -47,14 +56,6 @@ namespace XAO
*/
virtual ~Group();
/**
* Sets the name of the group.
* \param name the name to set.
*/
void setName(const std::string& name)
{
m_name = name;
}
/**
* Gets the name of the group.
* \return the name of the group.
@ -63,6 +64,14 @@ namespace XAO
{
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.
@ -74,43 +83,76 @@ namespace XAO
}
/**
* Gets the number of elements in the group.
* \return the number of elements.
* Gets the numbers of elements in the geometry of the same type than the group.
* \return the number of elements in the associated geometry.
*/
int getCount()
const int getNbElements()
{
return m_elements.size();
return m_nbElements;
}
/**
* Adds an element to the group.
* \param value the index of the element to add in the geometric element list (vertex, face...).
* Gets the number of elements in the group.
* \return the number of elements.
*/
void addElement(const int& value)
const int count()
{
checkElement(value);
m_elements.push_back(value);
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 getElement(const int& index)
const int get(const int& index)
{
checkElement(index);
return m_elements[index];
checkIndex(index);
std::set<int>::iterator it = m_elements.begin();
std::advance(it, index);
return (*it);
}
/**
* Adds an element to the group.
* \param value the index of the element to add.
*/
void add(const int& value);
/**
* Removes an element from the group.
* \param value the index of the element to remove.
*/
void remove(const int& value);
/**
* Gets an iterator on the first element in the group.
* @return an iterator on the first element.
*/
std::set<int>::iterator begin() { return m_elements.begin(); }
/**
* Gets an iterator on the last element in the group.
* @return an iterator on the last element.
*/
std::set<int>::iterator end() { return m_elements.end(); }
private:
/**
* Initialize the groups.
* @param name the name of the group.
* @param dim the dimension of the group.
* @param nbElements the number of elements in the geometry for the dimension.
*/
void initGroup(const std::string& name, const XAO::Dimension& dim, const int& nbElements);
/**
* Ensures that the given element is valid.
* @param element
* @throw SALOME_Exception if element is bigger than the number of elements.
*/
void checkElement(const int& element);
void checkIndex(const int& element);
private:
/** The name of the group. */
@ -122,7 +164,7 @@ namespace XAO
/** The number of elements in the group. */
int m_count;
/** The elements of the group. */
std::vector<int> m_elements;
std::set<int> m_elements;
};
}

View File

@ -213,12 +213,14 @@ void XaoExporter::exportGroups(Xao* xaoObject, xmlNodePtr xao)
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->getCount()).c_str());
xmlNewProp(group, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(grp->count()).c_str());
for (int j = 0; j < grp->getCount(); j++)
//for (int j = 0; j < grp->count(); j++)
for (std::set<int>::iterator it = grp->begin(); it != grp->end(); ++it)
{
int grpElt = (*it);
xmlNodePtr elt = xmlNewChild(group, 0, C_TAG_ELEMENT, 0);
xmlNewProp(elt, C_ATTR_ELEMENT_INDEX, BAD_CAST XaoUtils::intToString(grp->getElement(j)).c_str());
xmlNewProp(elt, C_ATTR_ELEMENT_INDEX, BAD_CAST XaoUtils::intToString(grpElt).c_str());
}
}
}
@ -495,7 +497,7 @@ void XaoExporter::parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject)
if (xmlStrcmp(node->name, C_TAG_ELEMENT) == 0)
{
int index = readIntegerProp(node, C_ATTR_ELEMENT_INDEX, true, -1);
group->addElement(index);
group->add(index);
}
}
}

View File

@ -33,18 +33,81 @@ void BrepGeometryTest::testGetIDs()
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]);
CPPUNIT_ASSERT_EQUAL(vertices[i], geom->getVertexID(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]);
CPPUNIT_ASSERT_EQUAL(edges[i], geom->getEdgeID(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_EQUAL(faces[i], geom->getFaceID(i));
CPPUNIT_ASSERT(geom->getSolidID(0) == 1);
CPPUNIT_ASSERT_EQUAL(1, geom->getSolidID(0));
delete geom;
}
void BrepGeometryTest::testGeometricalElements()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
CPPUNIT_ASSERT_EQUAL(2, geom->countFaceWires(13));
CPPUNIT_ASSERT_EQUAL(1, geom->countFaceWires(29));
std::vector<int> wires = geom->getFaceWires(13);
CPPUNIT_ASSERT_EQUAL(2, (int)wires.size());
CPPUNIT_ASSERT_EQUAL(2, wires[0]);
CPPUNIT_ASSERT_EQUAL(11, wires[1]);
CPPUNIT_ASSERT_EQUAL(1, geom->countSolidShells(1));
delete geom;
}
void BrepGeometryTest::testGetVertex()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
double x, y, z;
geom->getVertexXYZ(59, x, y, z);
CPPUNIT_ASSERT_DOUBLES_EQUAL(60., x, 1e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(80., y, 1e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(60., z, 1e-6);
delete geom;
}
void BrepGeometryTest::testGetEdgeLength()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
CPPUNIT_ASSERT_DOUBLES_EQUAL(200., geom->getEdgeLength(5), 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(80., geom->getEdgeLength(21), 0);
delete geom;
}
void BrepGeometryTest::testGetFaceArea()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
CPPUNIT_ASSERT_DOUBLES_EQUAL(40000., geom->getFaceArea(3), 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(33600., geom->getFaceArea(13), 1e-9);
delete geom;
}
void BrepGeometryTest::testGetSolidVolume()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
CPPUNIT_ASSERT_DOUBLES_EQUAL(7488000., geom->getSolidVolume(1), 1e-9);
delete geom;
}

View File

@ -11,6 +11,11 @@ namespace XAO
{
CPPUNIT_TEST_SUITE(BrepGeometryTest);
CPPUNIT_TEST(testGetIDs);
CPPUNIT_TEST(testGeometricalElements);
CPPUNIT_TEST(testGetVertex);
CPPUNIT_TEST(testGetEdgeLength);
CPPUNIT_TEST(testGetFaceArea);
CPPUNIT_TEST(testGetSolidVolume);
CPPUNIT_TEST_SUITE_END();
public:
@ -19,6 +24,12 @@ namespace XAO
void cleanUp();
void testGetIDs();
void testGeometricalElements();
void testGetVertex();
void testGetEdgeLength();
void testGetFaceArea();
void testGetSolidVolume();
};
}

View File

@ -26,24 +26,24 @@ void FieldTest::testField(XAO::Type type)
{
Field* f = Field::createField(type, XAO::FACE, 10, 3);
CPPUNIT_ASSERT(f->getName().size() == 0);
CPPUNIT_ASSERT(f->getType() == type);
CPPUNIT_ASSERT(f->getDimension() == XAO::FACE);
CPPUNIT_ASSERT(f->countComponents() == 3);
CPPUNIT_ASSERT(f->countElements() == 10);
CPPUNIT_ASSERT(f->countValues() == 30);
CPPUNIT_ASSERT_EQUAL(0, (int)f->getName().size());
CPPUNIT_ASSERT_EQUAL(type, f->getType());
CPPUNIT_ASSERT_EQUAL(XAO::FACE, f->getDimension());
CPPUNIT_ASSERT_EQUAL(3, f->countComponents());
CPPUNIT_ASSERT_EQUAL(10, f->countElements());
CPPUNIT_ASSERT_EQUAL(30, f->countValues());
f->setName("field1");
CPPUNIT_ASSERT(f->getName() == "field1");
CPPUNIT_ASSERT_EQUAL(std::string("field1"), f->getName());
CPPUNIT_ASSERT(f->getComponentName(0).size() == 0);
CPPUNIT_ASSERT_EQUAL(0, (int)f->getComponentName(0).size());
f->setComponentName(0, "x");
f->setComponentName(1, "y");
f->setComponentName(2, "z");
CPPUNIT_ASSERT(f->countComponents() == 3);
CPPUNIT_ASSERT(f->getComponentName(0) == "x");
CPPUNIT_ASSERT(f->getComponentName(1) == "y");
CPPUNIT_ASSERT(f->getComponentName(2) == "z");
CPPUNIT_ASSERT_EQUAL(3, f->countComponents());
CPPUNIT_ASSERT_EQUAL(std::string("x"), f->getComponentName(0));
CPPUNIT_ASSERT_EQUAL(std::string("y"), f->getComponentName(1));
CPPUNIT_ASSERT_EQUAL(std::string("z"), f->getComponentName(2));
CPPUNIT_ASSERT_THROW(f->setComponentName(3, "a"), SALOME_Exception);
CPPUNIT_ASSERT_THROW(f->getComponentName(3), SALOME_Exception);
}
@ -68,19 +68,19 @@ void FieldTest::testStringField()
void FieldTest::testStep(XAO::Type type)
{
Step* step = Step::createStep(type, 0, 0, 5, 3);
CPPUNIT_ASSERT(step->getType() == type);
CPPUNIT_ASSERT_EQUAL(type, step->getType());
CPPUNIT_ASSERT(step->getStep() == 0);
CPPUNIT_ASSERT_EQUAL(0, step->getStep());
step->setStep(10);
CPPUNIT_ASSERT(step->getStep() == 10);
CPPUNIT_ASSERT_EQUAL(10, step->getStep());
CPPUNIT_ASSERT(step->getStamp() == 0);
CPPUNIT_ASSERT_EQUAL(0, step->getStamp());
step->setStamp(100);
CPPUNIT_ASSERT(step->getStamp() == 100);
CPPUNIT_ASSERT_EQUAL(100, step->getStamp());
CPPUNIT_ASSERT(step->countElements() == 5);
CPPUNIT_ASSERT(step->countComponents() == 3);
CPPUNIT_ASSERT(step->countValues() == 15);
CPPUNIT_ASSERT_EQUAL(5, step->countElements());
CPPUNIT_ASSERT_EQUAL(3, step->countComponents());
CPPUNIT_ASSERT_EQUAL(15, step->countValues());
}
void FieldTest::testBooleanStep()
@ -112,33 +112,33 @@ void FieldTest::testIntegerStepValues()
istep->setValue(i, j, i*10 + j);
}
CPPUNIT_ASSERT(istep->getValue(1, 2) == 12);
CPPUNIT_ASSERT_EQUAL(12, istep->getValue(1, 2));
CPPUNIT_ASSERT_THROW(istep->getValue(nbElements, 2), SALOME_Exception);
CPPUNIT_ASSERT_THROW(istep->getValue(1, nbComponents), SALOME_Exception);
// get all values
std::vector<int> values;
values = istep->getValues();
CPPUNIT_ASSERT(values.size() == nbElements * nbComponents);
CPPUNIT_ASSERT_EQUAL(nbElements*nbComponents, (int)values.size());
for (int i = 0; i < nbElements; ++i)
{
for (int j = 0; j < nbComponents; ++j)
CPPUNIT_ASSERT(values[i*nbComponents+j] == 10*i+j);
CPPUNIT_ASSERT_EQUAL(10*i+j, values[i*nbComponents+j]);
}
// get one element
values = istep->getElement(2);
CPPUNIT_ASSERT_THROW(istep->getElement(nbElements), SALOME_Exception);
CPPUNIT_ASSERT(values.size() == nbComponents);
CPPUNIT_ASSERT_EQUAL(nbComponents, (int)values.size());
for (int i = 0; i < nbComponents; ++i)
CPPUNIT_ASSERT(values[i] == 20+i);
CPPUNIT_ASSERT_EQUAL(20+i, values[i]);
// get one component
values = istep->getComponent(1);
CPPUNIT_ASSERT_THROW(istep->getComponent(nbComponents), SALOME_Exception);
CPPUNIT_ASSERT(values.size() == nbElements);
CPPUNIT_ASSERT_EQUAL(nbElements, (int)values.size());
for (int i = 0; i < nbElements; ++i)
CPPUNIT_ASSERT(values[i] == 10*i+1);
CPPUNIT_ASSERT_EQUAL(10*i+1, values[i]);
// set one element
std::vector<int> newEltValues;

View File

@ -0,0 +1,60 @@
#include <vector>
#include <Utils_SALOME_Exception.hxx>
#include "TestUtils.hxx"
#include "GroupTest.hxx"
#include "../Xao.hxx"
#include "../Group.hxx"
using namespace XAO;
void GroupTest::setUp()
{
}
void GroupTest::tearDown()
{
}
void GroupTest::cleanUp()
{
}
void GroupTest::testGroup()
{
Group* group = new Group(XAO::FACE, 20);
CPPUNIT_ASSERT_EQUAL(XAO::FACE, group->getDimension());
CPPUNIT_ASSERT_EQUAL(20, group->getNbElements());
CPPUNIT_ASSERT_EQUAL(std::string(""), group->getName());
group->setName("the Group");
CPPUNIT_ASSERT_EQUAL(std::string("the Group"), group->getName());
CPPUNIT_ASSERT_EQUAL(0, group->count());
group->add(10);
CPPUNIT_ASSERT_EQUAL(1, group->count());
group->add(12);
CPPUNIT_ASSERT_EQUAL(2, group->count());
group->add(12);
CPPUNIT_ASSERT_EQUAL(2, group->count());
CPPUNIT_ASSERT_EQUAL(10, group->get(0));
CPPUNIT_ASSERT_EQUAL(12, group->get(1));
CPPUNIT_ASSERT_THROW(group->get(2), SALOME_Exception);
group->remove(15);
CPPUNIT_ASSERT_EQUAL(2, group->count());
group->remove(10);
CPPUNIT_ASSERT_EQUAL(1, group->count());
CPPUNIT_ASSERT_EQUAL(12, group->get(0));
delete group;
}

View File

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

View File

@ -20,7 +20,7 @@
#include <Utils_SALOME_Exception.hxx>
#include "TestUtils.hxx";
#include "TestUtils.hxx"
#include "ImportExportTest.hxx"
#include "../Geometry.hxx"
#include "../Group.hxx"
@ -80,12 +80,12 @@ void ImportExportTest::testExportGeometry()
// groups
Group* group = xao.addGroup(XAO::SOLID);
group->setName("boite1");
group->addElement(0);
group->add(0);
group = xao.addGroup(XAO::FACE);
group->setName("faces");
group->addElement(0);
group->addElement(1);
group->add(0);
group->add(1);
// fields
IntegerField* field = (IntegerField*)xao.addField(XAO::INTEGER, "color", XAO::FACE, 2);
@ -105,7 +105,7 @@ void ImportExportTest::testExportGeometry()
CPPUNIT_ASSERT(res);
std::string xml = xao.getXML();
//CPPUNIT_ASSERT(strlen(xml) == 1007);
//CPPUNIT_ASSERT_EQUAL(strlen(xml) == 1007);
}
void ImportExportTest::testGeometryError()
@ -128,53 +128,53 @@ void ImportExportTest::testImportXao()
void ImportExportTest::checkImport(Xao& xao)
{
CPPUNIT_ASSERT(xao.getAuthor() == "me");
CPPUNIT_ASSERT(xao.getVersion() == "1.0");
CPPUNIT_ASSERT_EQUAL(std::string("me"), xao.getAuthor());
CPPUNIT_ASSERT_EQUAL(std::string("1.0"), xao.getVersion());
Geometry* geom = xao.getGeometry();
CPPUNIT_ASSERT(geom != NULL);
CPPUNIT_ASSERT(geom->getName() == "mygeom");
CPPUNIT_ASSERT_EQUAL(std::string("mygeom"), geom->getName());
CPPUNIT_ASSERT(geom->countVertices() == 4);
CPPUNIT_ASSERT(geom->getVertexName(0) == "v1");
CPPUNIT_ASSERT(geom->getVertexReference(0) == "1");
CPPUNIT_ASSERT(geom->getVertexName(1) == "");
CPPUNIT_ASSERT(geom->getVertexReference(1) == "2");
CPPUNIT_ASSERT(geom->getVertexName(2) == "v3");
CPPUNIT_ASSERT(geom->getVertexReference(2) == "3");
CPPUNIT_ASSERT(geom->getVertexName(3) == "");
CPPUNIT_ASSERT(geom->getVertexReference(3) == "4");
CPPUNIT_ASSERT_EQUAL(4, geom->countVertices());
CPPUNIT_ASSERT_EQUAL(std::string("v1"), geom->getVertexName(0));
CPPUNIT_ASSERT_EQUAL(std::string("1"), geom->getVertexReference(0));
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getVertexName(1));
CPPUNIT_ASSERT_EQUAL(std::string("2"), geom->getVertexReference(1));
CPPUNIT_ASSERT_EQUAL(std::string("v3"), geom->getVertexName(2));
CPPUNIT_ASSERT_EQUAL(std::string("3"), geom->getVertexReference(2));
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getVertexName(3));
CPPUNIT_ASSERT_EQUAL(std::string("4"), geom->getVertexReference(3));
CPPUNIT_ASSERT(geom->countEdges() == 3);
CPPUNIT_ASSERT(geom->getEdgeName(0) == "e1");
CPPUNIT_ASSERT(geom->getEdgeReference(0) == "5");
CPPUNIT_ASSERT(geom->getEdgeName(1) == "");
CPPUNIT_ASSERT(geom->getEdgeReference(1) == "6");
CPPUNIT_ASSERT(geom->getEdgeName(2) == "e3");
CPPUNIT_ASSERT(geom->getEdgeReference(2) == "7");
CPPUNIT_ASSERT_EQUAL(3, geom->countEdges());
CPPUNIT_ASSERT_EQUAL(std::string("e1"), geom->getEdgeName(0));
CPPUNIT_ASSERT_EQUAL(std::string("5"), geom->getEdgeReference(0));
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getEdgeName(1));
CPPUNIT_ASSERT_EQUAL(std::string("6"), geom->getEdgeReference(1));
CPPUNIT_ASSERT_EQUAL(std::string("e3"), geom->getEdgeName(2));
CPPUNIT_ASSERT_EQUAL(std::string("7"), geom->getEdgeReference(2));
CPPUNIT_ASSERT(geom->countFaces() == 2);
CPPUNIT_ASSERT(geom->getFaceName(0) == "f1");
CPPUNIT_ASSERT(geom->getFaceReference(0) == "8");
CPPUNIT_ASSERT(geom->getFaceName(1) == "");
CPPUNIT_ASSERT(geom->getFaceReference(1) == "9");
CPPUNIT_ASSERT_EQUAL(2, geom->countFaces());
CPPUNIT_ASSERT_EQUAL(std::string("f1"), geom->getFaceName(0));
CPPUNIT_ASSERT_EQUAL(std::string("8"), geom->getFaceReference(0));
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getFaceName(1));
CPPUNIT_ASSERT_EQUAL(std::string("9"), geom->getFaceReference(1));
CPPUNIT_ASSERT(geom->countSolids() == 1);
CPPUNIT_ASSERT(geom->getSolidName(0) == "s1");
CPPUNIT_ASSERT(geom->getSolidReference(0) == "10");
CPPUNIT_ASSERT_EQUAL(1, geom->countSolids());
CPPUNIT_ASSERT_EQUAL(std::string("s1"), geom->getSolidName(0));
CPPUNIT_ASSERT_EQUAL(std::string("10"), geom->getSolidReference(0));
CPPUNIT_ASSERT(xao.countGroups() == 2);
CPPUNIT_ASSERT_EQUAL(2, xao.countGroups());
Group* group = xao.getGroup(0);
CPPUNIT_ASSERT(group->getCount() == 1);
CPPUNIT_ASSERT(group->getName() == "boite_1");
CPPUNIT_ASSERT(group->getDimension() == XAO::SOLID);
CPPUNIT_ASSERT(group->getElement(0) == 0);
CPPUNIT_ASSERT_EQUAL(1, group->count());
CPPUNIT_ASSERT_EQUAL(std::string("boite_1"), group->getName());
CPPUNIT_ASSERT_EQUAL(XAO::SOLID, group->getDimension());
CPPUNIT_ASSERT_EQUAL(0, group->get(0));
group = xao.getGroup(1);
CPPUNIT_ASSERT(group->getCount() == 2);
CPPUNIT_ASSERT(group->getName() == "");
CPPUNIT_ASSERT(group->getDimension() == XAO::FACE);
CPPUNIT_ASSERT(group->getElement(0) == 0);
CPPUNIT_ASSERT(group->getElement(1) == 1);
CPPUNIT_ASSERT_EQUAL(2, group->count());
CPPUNIT_ASSERT_EQUAL(std::string(""), group->getName());
CPPUNIT_ASSERT_EQUAL(XAO::FACE, group->getDimension());
CPPUNIT_ASSERT_EQUAL(0, group->get(0));
CPPUNIT_ASSERT_EQUAL(1, group->get(1));
}
void ImportExportTest::testImportXaoFromText()

View File

@ -39,6 +39,7 @@ TestXAO_LDFLAGS = \
../libXAO.la
dist_TestXAO_SOURCES = \
GroupTest.cxx \
FieldTest.cxx \
ImportExportTest.cxx \
BrepGeometryTest.cxx \

View File

@ -1,10 +1,3 @@
/*
* TestUtils.hxx
*
* Created on: 30 août 2013
* Author: salome
*/
#ifndef __XAO_TESTUTILS_HXX__
#define __XAO_TESTUTILS_HXX__

View File

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