mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-02-10 23:43:07 +05:00
improve code
add more tests
This commit is contained in:
parent
86f1d92836
commit
a24956bf0a
@ -95,11 +95,15 @@ void BrepGeometry::initListIds(const TopAbs_ShapeEnum& shapeType, GeometricEleme
|
|||||||
TopTools_MapOfShape mapShape;
|
TopTools_MapOfShape mapShape;
|
||||||
TopTools_ListOfShape listShape;
|
TopTools_ListOfShape listShape;
|
||||||
|
|
||||||
|
int nbElt = 0;
|
||||||
TopExp_Explorer exp(m_shape, shapeType);
|
TopExp_Explorer exp(m_shape, shapeType);
|
||||||
for (; exp.More(); exp.Next())
|
for (; exp.More(); exp.Next())
|
||||||
{
|
{
|
||||||
if (mapShape.Add(exp.Current()))
|
if (mapShape.Add(exp.Current()))
|
||||||
|
{
|
||||||
listShape.Append(exp.Current());
|
listShape.Append(exp.Current());
|
||||||
|
nbElt++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listShape.IsEmpty())
|
if (listShape.IsEmpty())
|
||||||
@ -108,19 +112,14 @@ void BrepGeometry::initListIds(const TopAbs_ShapeEnum& shapeType, GeometricEleme
|
|||||||
TopTools_IndexedMapOfShape indices;
|
TopTools_IndexedMapOfShape indices;
|
||||||
TopExp::MapShapes(m_shape, indices);
|
TopExp::MapShapes(m_shape, indices);
|
||||||
|
|
||||||
std::list<int> indexList;
|
eltList.setSize(nbElt);
|
||||||
TopTools_ListIteratorOfListOfShape itSub(listShape);
|
TopTools_ListIteratorOfListOfShape itSub(listShape);
|
||||||
for (int index = 1; itSub.More(); itSub.Next(), ++index)
|
for (int index = 0; itSub.More(); itSub.Next(), ++index)
|
||||||
{
|
{
|
||||||
TopoDS_Shape value = itSub.Value();
|
TopoDS_Shape value = itSub.Value();
|
||||||
indexList.push_back(indices.FindIndex(value));
|
int ref = indices.FindIndex(value);
|
||||||
|
eltList.setReference(index, XaoUtils::intToString(ref));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<int>::iterator it = indexList.begin();
|
|
||||||
|
|
||||||
eltList.setSize(indexList.size());
|
|
||||||
for (int i = 0; it != indexList.end(); it++, i++)
|
|
||||||
eltList.setReference(i, XaoUtils::intToString((*it)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TopoDS_Shape BrepGeometry::getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex)
|
TopoDS_Shape BrepGeometry::getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex)
|
||||||
@ -137,14 +136,10 @@ TopoDS_Shape BrepGeometry::getSubShape(const TopoDS_Shape& mainShape, const TopA
|
|||||||
|
|
||||||
if (!listShape.IsEmpty())
|
if (!listShape.IsEmpty())
|
||||||
{
|
{
|
||||||
// use main shape indices
|
|
||||||
TopTools_IndexedMapOfShape indices;
|
|
||||||
TopExp::MapShapes(mainShape, indices);
|
|
||||||
|
|
||||||
TopTools_ListIteratorOfListOfShape itSub(listShape);
|
TopTools_ListIteratorOfListOfShape itSub(listShape);
|
||||||
for (int index = 1; itSub.More(); itSub.Next(), ++index)
|
for (int index = 0; itSub.More(); itSub.Next(), ++index)
|
||||||
{
|
{
|
||||||
if (shapeIndex + 1 == index)
|
if (shapeIndex == index)
|
||||||
{
|
{
|
||||||
TopoDS_Shape value = itSub.Value();
|
TopoDS_Shape value = itSub.Value();
|
||||||
return value;
|
return value;
|
||||||
@ -159,13 +154,9 @@ TopoDS_Shape BrepGeometry::getSubShape(const TopoDS_Shape& mainShape, const TopA
|
|||||||
const int BrepGeometry::countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType)
|
const int BrepGeometry::countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
TopTools_MapOfShape mapShape;
|
|
||||||
TopExp_Explorer exp(shape, shapeType);
|
TopExp_Explorer exp(shape, shapeType);
|
||||||
for (; exp.More(); exp.Next())
|
for (; exp.More(); exp.Next())
|
||||||
{
|
|
||||||
// if (mapShape.Add(exp.Current()))
|
|
||||||
res++;
|
res++;
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -191,7 +182,7 @@ std::vector<int> BrepGeometry::getGeometricalElements(const TopoDS_Shape& shape,
|
|||||||
TopExp::MapShapes(m_shape, indices);
|
TopExp::MapShapes(m_shape, indices);
|
||||||
|
|
||||||
TopTools_ListIteratorOfListOfShape itSub(listShape);
|
TopTools_ListIteratorOfListOfShape itSub(listShape);
|
||||||
for (int index = 1; itSub.More(); itSub.Next(), ++index)
|
for (int index = 0; itSub.More(); itSub.Next(), ++index)
|
||||||
{
|
{
|
||||||
TopoDS_Shape value = itSub.Value();
|
TopoDS_Shape value = itSub.Value();
|
||||||
int id = indices.FindIndex(value);
|
int id = indices.FindIndex(value);
|
||||||
@ -338,6 +329,7 @@ const int BrepGeometry::findElement(const XAO::Dimension& dim, const int& id)
|
|||||||
return findFace(id);
|
return findFace(id);
|
||||||
if (dim == XAO::SOLID)
|
if (dim == XAO::SOLID)
|
||||||
return findSolid(id);
|
return findSolid(id);
|
||||||
|
|
||||||
throw SALOME_Exception(MsgBuilder() << "Unknown Dimension: " << dim);
|
throw SALOME_Exception(MsgBuilder() << "Unknown Dimension: " << dim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,8 +146,6 @@ namespace XAO
|
|||||||
void setFaceID(const int& index, const int& id);
|
void setFaceID(const int& index, const int& id);
|
||||||
void setSolidID(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.
|
* Finds a vertex with its ID.
|
||||||
* @param id the ID of the vertex.
|
* @param id the ID of the vertex.
|
||||||
@ -238,6 +236,7 @@ namespace XAO
|
|||||||
TopoDS_Shape getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex);
|
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);
|
const int countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType);
|
||||||
std::vector<int> getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim);
|
std::vector<int> getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim);
|
||||||
|
const int findElement(const XAO::Dimension& dim, const int& id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TopoDS_Shape m_shape;
|
TopoDS_Shape m_shape;
|
||||||
|
@ -54,7 +54,7 @@ GeometricElementList::GeometricElementList()
|
|||||||
|
|
||||||
GeometricElementList::GeometricElementList(const int& count)
|
GeometricElementList::GeometricElementList(const int& count)
|
||||||
{
|
{
|
||||||
setSize(m_count);
|
setSize(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometricElementList::setSize(const int& nb)
|
void GeometricElementList::setSize(const int& nb)
|
||||||
@ -67,52 +67,48 @@ void GeometricElementList::setSize(const int& nb)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeometricElementList::checkElementIndex(const int& index) const
|
||||||
|
{
|
||||||
|
if (m_count >= 0 && index < m_count)
|
||||||
|
return;
|
||||||
|
|
||||||
|
throw SALOME_Exception(MsgBuilder() << "Index of element is out of range [0, " << m_count<< "]: " << index);
|
||||||
|
}
|
||||||
|
|
||||||
void GeometricElementList::setElement(const int& index, const std::string& name, const std::string& reference)
|
void GeometricElementList::setElement(const int& index, const std::string& name, const std::string& reference)
|
||||||
{
|
{
|
||||||
if (m_count == 0 || index > m_count)
|
checkElementIndex(index);
|
||||||
throw SALOME_Exception("Problem with number of elements");
|
|
||||||
|
|
||||||
m_elements[index].setName(name);
|
m_elements[index].setName(name);
|
||||||
m_elements[index].setReference(reference);
|
m_elements[index].setReference(reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string GeometricElementList::getName(const int& index)
|
const std::string GeometricElementList::getName(const int& index)
|
||||||
{
|
{
|
||||||
if (m_count == 0 || index > m_count)
|
checkElementIndex(index);
|
||||||
throw SALOME_Exception("Problem with number of elements");
|
|
||||||
|
|
||||||
return m_elements[index].getName();
|
return m_elements[index].getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometricElementList::setName(const int& index, const std::string& name)
|
void GeometricElementList::setName(const int& index, const std::string& name)
|
||||||
{
|
{
|
||||||
if (m_count == 0 || index > m_count)
|
checkElementIndex(index);
|
||||||
throw SALOME_Exception("Problem with number of elements");
|
|
||||||
|
|
||||||
m_elements[index].setName(name);
|
m_elements[index].setName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool GeometricElementList::hasName(const int& index)
|
const bool GeometricElementList::hasName(const int& index)
|
||||||
{
|
{
|
||||||
if (m_count == 0 || index > m_count)
|
checkElementIndex(index);
|
||||||
throw SALOME_Exception("Problem with number of elements");
|
|
||||||
|
|
||||||
return m_elements[index].hasName();
|
return m_elements[index].hasName();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string GeometricElementList::getReference(const int& index)
|
const std::string GeometricElementList::getReference(const int& index)
|
||||||
{
|
{
|
||||||
if (m_count == 0 || index > m_count)
|
checkElementIndex(index);
|
||||||
throw SALOME_Exception("Problem with number of elements");
|
|
||||||
|
|
||||||
return m_elements[index].getReference();
|
return m_elements[index].getReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometricElementList::setReference(const int& index, const std::string& name)
|
void GeometricElementList::setReference(const int& index, const std::string& name)
|
||||||
{
|
{
|
||||||
if (m_count == 0 || index > m_count)
|
checkElementIndex(index);
|
||||||
throw SALOME_Exception("Problem with number of elements");
|
|
||||||
|
|
||||||
m_elements[index].setReference(name);
|
m_elements[index].setReference(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,6 +200,9 @@ namespace XAO
|
|||||||
*/
|
*/
|
||||||
iterator end() { return m_elements.end(); }
|
iterator end() { return m_elements.end(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void checkElementIndex(const int& index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_count;
|
int m_count;
|
||||||
std::map<int, GeometricElement> m_elements;
|
std::map<int, GeometricElement> m_elements;
|
||||||
|
@ -30,20 +30,6 @@
|
|||||||
|
|
||||||
using namespace XAO;
|
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)
|
void Step::checkElementIndex(const int& element)
|
||||||
{
|
{
|
||||||
if (element < m_nbElements && element >= 0)
|
if (element < m_nbElements && element >= 0)
|
||||||
|
@ -33,17 +33,6 @@ namespace XAO
|
|||||||
Step() {}
|
Step() {}
|
||||||
|
|
||||||
public:
|
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.
|
* Destructor.
|
||||||
*/
|
*/
|
||||||
|
@ -71,6 +71,8 @@ const int Xao::countGroups() const
|
|||||||
|
|
||||||
Group* Xao::getGroup(const int& index)
|
Group* Xao::getGroup(const int& index)
|
||||||
{
|
{
|
||||||
|
checkGroupIndex(index);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it, ++i)
|
for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it, ++i)
|
||||||
{
|
{
|
||||||
@ -94,9 +96,11 @@ Group* Xao::addGroup(const std::string& name, const XAO::Dimension& dim)
|
|||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Xao::removeGroup(Group* group)
|
bool Xao::removeGroup(Group* group)
|
||||||
{
|
{
|
||||||
|
int nb = countGroups();
|
||||||
m_groups.remove(group);
|
m_groups.remove(group);
|
||||||
|
return (nb-1 == countGroups());
|
||||||
}
|
}
|
||||||
|
|
||||||
const int Xao::countFields() const
|
const int Xao::countFields() const
|
||||||
@ -106,6 +110,8 @@ const int Xao::countFields() const
|
|||||||
|
|
||||||
Field* Xao::getField(const int& index)
|
Field* Xao::getField(const int& index)
|
||||||
{
|
{
|
||||||
|
checkFieldIndex(index);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (std::list<Field*>::iterator it = m_fields.begin(); it != m_fields.end(); ++it, ++i)
|
for (std::list<Field*>::iterator it = m_fields.begin(); it != m_fields.end(); ++it, ++i)
|
||||||
{
|
{
|
||||||
@ -130,9 +136,11 @@ Field* Xao::addField(const XAO::Type& type, const std::string& name, const XAO::
|
|||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Xao::removeField(Field* field)
|
bool Xao::removeField(Field* field)
|
||||||
{
|
{
|
||||||
|
int nb = countFields();
|
||||||
m_fields.remove(field);
|
m_fields.remove(field);
|
||||||
|
return (nb-1 == countFields());
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool Xao::exportXAO(const std::string& fileName)
|
const bool Xao::exportXAO(const std::string& fileName)
|
||||||
@ -160,3 +168,21 @@ void Xao::checkGeometry() const
|
|||||||
if (m_geometry == NULL)
|
if (m_geometry == NULL)
|
||||||
throw SALOME_Exception("Geometry is null");
|
throw SALOME_Exception("Geometry is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Xao::checkGroupIndex(const int& index) const
|
||||||
|
{
|
||||||
|
if (index >= 0 && index < countGroups())
|
||||||
|
return;
|
||||||
|
|
||||||
|
throw SALOME_Exception(MsgBuilder() << "Group index is out of range [0, "
|
||||||
|
<< countGroups()-1 << "]: " << index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Xao::checkFieldIndex(const int& index) const
|
||||||
|
{
|
||||||
|
if (index >= 0 && index < countFields())
|
||||||
|
return;
|
||||||
|
|
||||||
|
throw SALOME_Exception(MsgBuilder() << "Field index is out of range [0, "
|
||||||
|
<< countFields()-1 << "]: " << index);
|
||||||
|
}
|
||||||
|
@ -170,8 +170,9 @@ namespace XAO
|
|||||||
/**
|
/**
|
||||||
* Removes a group.
|
* Removes a group.
|
||||||
* \param group the group to remove.
|
* \param group the group to remove.
|
||||||
|
* \return true if the group has been removed, false otherwise.
|
||||||
*/
|
*/
|
||||||
void removeGroup(Group* group);
|
bool removeGroup(Group* group);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Fields
|
// Fields
|
||||||
@ -208,8 +209,9 @@ namespace XAO
|
|||||||
/**
|
/**
|
||||||
* Removes a field.
|
* Removes a field.
|
||||||
* \param field the field to remove.
|
* \param field the field to remove.
|
||||||
|
* \return true if the field has been removed, false otherwise.
|
||||||
*/
|
*/
|
||||||
void removeField(Field* field);
|
bool removeField(Field* field);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Import / Export
|
// Import / Export
|
||||||
@ -241,6 +243,8 @@ namespace XAO
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void checkGeometry() const;
|
void checkGeometry() const;
|
||||||
|
void checkGroupIndex(const int& index) const;
|
||||||
|
void checkFieldIndex(const int& index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** The author of the file. */
|
/** The author of the file. */
|
||||||
|
@ -115,7 +115,7 @@ int XaoExporter::readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
|
|||||||
const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName)
|
const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName)
|
||||||
{
|
{
|
||||||
xmlDocPtr doc = exportXMLDoc(xaoObject);
|
xmlDocPtr doc = exportXMLDoc(xaoObject);
|
||||||
xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 2);
|
xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 1); // format = 1 for node indentation
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -127,7 +127,7 @@ const std::string XaoExporter::saveToXml(Xao* xaoObject)
|
|||||||
|
|
||||||
xmlChar *xmlbuff;
|
xmlChar *xmlbuff;
|
||||||
int buffersize;
|
int buffersize;
|
||||||
xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
|
xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
xmlCleanupGlobals();
|
xmlCleanupGlobals();
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ void XaoExporter::exportStep(Step* step, Field* field, xmlNodePtr nodeSteps)
|
|||||||
for (int j = 0; j < step->countComponents(); ++j)
|
for (int j = 0; j < step->countComponents(); ++j)
|
||||||
{
|
{
|
||||||
std::string content = step->getStringValue(i, j);
|
std::string content = step->getStringValue(i, j);
|
||||||
xmlNodePtr nodeValue= xmlNewTextChild(nodeElt, 0, C_TAG_VALUE, BAD_CAST content.c_str());
|
xmlNodePtr nodeValue = xmlNewChild(nodeElt, NULL, C_TAG_VALUE, BAD_CAST content.c_str());
|
||||||
xmlNewProp(nodeValue, C_ATTR_VALUE_COMPONENT, BAD_CAST XaoUtils::intToString(j).c_str());
|
xmlNewProp(nodeValue, C_ATTR_VALUE_COMPONENT, BAD_CAST XaoUtils::intToString(j).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,7 @@ namespace XAO
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MsgBuilder() {};
|
MsgBuilder() {};
|
||||||
|
~MsgBuilder() {};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
MsgBuilder& operator <<(const T& t)
|
MsgBuilder& operator <<(const T& t)
|
||||||
|
@ -92,6 +92,48 @@ void BrepGeometryTest::testGetReferences()
|
|||||||
delete geom;
|
delete geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BrepGeometryTest::testGetNames()
|
||||||
|
{
|
||||||
|
BrepGeometry* geom = new BrepGeometry("box");
|
||||||
|
readBrep(geom, "Box_1.brep");
|
||||||
|
|
||||||
|
int id;
|
||||||
|
|
||||||
|
// vertex of index 1 has id = 7
|
||||||
|
id = 7;
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findVertexName(id));
|
||||||
|
geom->changeVertexName(id, std::string("va"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("va"), geom->findVertexName(id));
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->changeVertexName(100, "a"), SALOME_Exception);
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->findVertexName(100), SALOME_Exception);
|
||||||
|
|
||||||
|
// edge of index 1 has id = 8
|
||||||
|
id = 8;
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findEdgeName(id));
|
||||||
|
geom->changeEdgeName(id, std::string("ea"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("ea"), geom->findEdgeName(id));
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->changeEdgeName(100, "a"), SALOME_Exception);
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->findEdgeName(100), SALOME_Exception);
|
||||||
|
|
||||||
|
// face of index 1 has id = 13
|
||||||
|
id = 13;
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findFaceName(id));
|
||||||
|
geom->changeFaceName(id, std::string("fa"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("fa"), geom->findFaceName(id));
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->changeFaceName(100, "a"), SALOME_Exception);
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->findFaceName(100), SALOME_Exception);
|
||||||
|
|
||||||
|
// solid of index 0 has id = 1
|
||||||
|
id = 1;
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findSolidName(id));
|
||||||
|
geom->changeSolidName(id, std::string("sa"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("sa"), geom->findSolidName(id));
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->changeSolidName(100, "a"), SALOME_Exception);
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->findSolidName(100), SALOME_Exception);
|
||||||
|
|
||||||
|
delete geom;
|
||||||
|
}
|
||||||
|
|
||||||
void BrepGeometryTest::testGetEdgeVertices()
|
void BrepGeometryTest::testGetEdgeVertices()
|
||||||
{
|
{
|
||||||
BrepGeometry* geom = new BrepGeometry("box");
|
BrepGeometry* geom = new BrepGeometry("box");
|
||||||
|
@ -10,6 +10,7 @@ namespace XAO
|
|||||||
CPPUNIT_TEST_SUITE(BrepGeometryTest);
|
CPPUNIT_TEST_SUITE(BrepGeometryTest);
|
||||||
CPPUNIT_TEST(testGetIDs);
|
CPPUNIT_TEST(testGetIDs);
|
||||||
CPPUNIT_TEST(testGetReferences);
|
CPPUNIT_TEST(testGetReferences);
|
||||||
|
CPPUNIT_TEST(testGetNames);
|
||||||
CPPUNIT_TEST(testGetEdgeVertices);
|
CPPUNIT_TEST(testGetEdgeVertices);
|
||||||
CPPUNIT_TEST(testGetFaceEdges);
|
CPPUNIT_TEST(testGetFaceEdges);
|
||||||
CPPUNIT_TEST(testSolidFaces);
|
CPPUNIT_TEST(testSolidFaces);
|
||||||
@ -26,6 +27,7 @@ namespace XAO
|
|||||||
|
|
||||||
void testGetIDs();
|
void testGetIDs();
|
||||||
void testGetReferences();
|
void testGetReferences();
|
||||||
|
void testGetNames();
|
||||||
void testGetEdgeVertices();
|
void testGetEdgeVertices();
|
||||||
void testGetFaceEdges();
|
void testGetFaceEdges();
|
||||||
void testSolidFaces();
|
void testSolidFaces();
|
||||||
|
@ -53,6 +53,7 @@ Field* FieldTest::testField(XAO::Type type)
|
|||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(0, f->countSteps());
|
CPPUNIT_ASSERT_EQUAL(0, f->countSteps());
|
||||||
Step* step = f->addNewStep(0);
|
Step* step = f->addNewStep(0);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(type, step->getType());
|
||||||
CPPUNIT_ASSERT_EQUAL(1, f->countSteps());
|
CPPUNIT_ASSERT_EQUAL(1, f->countSteps());
|
||||||
step = f->addNewStep(1);
|
step = f->addNewStep(1);
|
||||||
step = f->addNewStep(2);
|
step = f->addNewStep(2);
|
||||||
@ -125,9 +126,8 @@ void FieldTest::testStringField()
|
|||||||
CPPUNIT_ASSERT_THROW(f->addStep(10), SALOME_Exception); // step already exists
|
CPPUNIT_ASSERT_THROW(f->addStep(10), SALOME_Exception); // step already exists
|
||||||
}
|
}
|
||||||
|
|
||||||
void FieldTest::testStep(XAO::Type type)
|
void FieldTest::testStep(XAO::Type type, Step* step)
|
||||||
{
|
{
|
||||||
Step* step = Step::createStep(type, 0, 0, 5, 3);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(type, step->getType());
|
CPPUNIT_ASSERT_EQUAL(type, step->getType());
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(0, step->getStep());
|
CPPUNIT_ASSERT_EQUAL(0, step->getStep());
|
||||||
@ -145,19 +145,23 @@ void FieldTest::testStep(XAO::Type type)
|
|||||||
|
|
||||||
void FieldTest::testBooleanStep()
|
void FieldTest::testBooleanStep()
|
||||||
{
|
{
|
||||||
testStep(XAO::BOOLEAN);
|
Step* step = new BooleanStep(0, 0, 5, 3);
|
||||||
|
testStep(XAO::BOOLEAN, step);
|
||||||
}
|
}
|
||||||
void FieldTest::testIntegerStep()
|
void FieldTest::testIntegerStep()
|
||||||
{
|
{
|
||||||
testStep(XAO::INTEGER);
|
Step* step = new IntegerStep(0, 0, 5, 3);
|
||||||
|
testStep(XAO::INTEGER, step);
|
||||||
}
|
}
|
||||||
void FieldTest::testDoubleStep()
|
void FieldTest::testDoubleStep()
|
||||||
{
|
{
|
||||||
testStep(XAO::DOUBLE);
|
Step* step = new DoubleStep(0, 0, 5, 3);
|
||||||
|
testStep(XAO::DOUBLE, step);
|
||||||
}
|
}
|
||||||
void FieldTest::testStringStep()
|
void FieldTest::testStringStep()
|
||||||
{
|
{
|
||||||
testStep(XAO::STRING);
|
Step* step = new StringStep(0, 0, 5, 3);
|
||||||
|
testStep(XAO::STRING, step);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FieldTest::testBooleanStepValues()
|
void FieldTest::testBooleanStepValues()
|
||||||
@ -165,7 +169,7 @@ void FieldTest::testBooleanStepValues()
|
|||||||
int nbComponents = 3; // > 1
|
int nbComponents = 3; // > 1
|
||||||
int nbElements = 5; // > 1
|
int nbElements = 5; // > 1
|
||||||
|
|
||||||
BooleanStep* step = (BooleanStep*)Step::createStep(XAO::BOOLEAN, 0, 0, nbElements, nbComponents);
|
BooleanStep* step = new BooleanStep(0, 0, nbElements, nbComponents);
|
||||||
for (int i = 0; i < step->countElements(); ++i)
|
for (int i = 0; i < step->countElements(); ++i)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < step->countComponents(); ++j)
|
for (int j = 0; j < step->countComponents(); ++j)
|
||||||
@ -225,7 +229,7 @@ void FieldTest::testBooleanStepValues()
|
|||||||
|
|
||||||
// set string value
|
// set string value
|
||||||
step->setStringValue(0, 0, "true");
|
step->setStringValue(0, 0, "true");
|
||||||
CPPUNIT_ASSERT_NO_THROW(step->setStringValue(0, 0, "aa")); // set false
|
CPPUNIT_ASSERT_THROW(step->setStringValue(0, 0, "aa"), SALOME_Exception);
|
||||||
|
|
||||||
// set all values
|
// set all values
|
||||||
std::vector<bool> allValues;
|
std::vector<bool> allValues;
|
||||||
@ -243,7 +247,7 @@ void FieldTest::testIntegerStepValues()
|
|||||||
int nbComponents = 3;
|
int nbComponents = 3;
|
||||||
int nbElements = 5;
|
int nbElements = 5;
|
||||||
|
|
||||||
IntegerStep* step = (IntegerStep*)Step::createStep(XAO::INTEGER, 0, 0, nbElements, nbComponents);
|
IntegerStep* step = new IntegerStep(0, 0, nbElements, nbComponents);
|
||||||
for (int i = 0; i < step->countElements(); ++i)
|
for (int i = 0; i < step->countElements(); ++i)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < step->countComponents(); ++j)
|
for (int j = 0; j < step->countComponents(); ++j)
|
||||||
@ -314,7 +318,7 @@ void FieldTest::testDoubleStepValues()
|
|||||||
int nbComponents = 3;
|
int nbComponents = 3;
|
||||||
int nbElements = 5;
|
int nbElements = 5;
|
||||||
|
|
||||||
DoubleStep* step = (DoubleStep*)Step::createStep(XAO::DOUBLE, 0, 0, nbElements, nbComponents);
|
DoubleStep* step = new DoubleStep(0, 0, nbElements, nbComponents);
|
||||||
for (int i = 0; i < step->countElements(); ++i)
|
for (int i = 0; i < step->countElements(); ++i)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < step->countComponents(); ++j)
|
for (int j = 0; j < step->countComponents(); ++j)
|
||||||
@ -383,7 +387,7 @@ void FieldTest::testStringStepValues()
|
|||||||
int nbComponents = 3;
|
int nbComponents = 3;
|
||||||
int nbElements = 5;
|
int nbElements = 5;
|
||||||
|
|
||||||
StringStep* step = (StringStep*)Step::createStep(XAO::STRING, 0, 0, nbElements, nbComponents);
|
StringStep* step = new StringStep(0, 0, nbElements, nbComponents);
|
||||||
for (int i = 0; i < step->countElements(); ++i)
|
for (int i = 0; i < step->countElements(); ++i)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < step->countComponents(); ++j)
|
for (int j = 0; j < step->countComponents(); ++j)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "../XAO_Xao.hxx"
|
#include "../XAO_Xao.hxx"
|
||||||
#include "../XAO_Field.hxx"
|
#include "../XAO_Field.hxx"
|
||||||
|
#include "../XAO_Step.hxx"
|
||||||
|
|
||||||
namespace XAO
|
namespace XAO
|
||||||
{
|
{
|
||||||
@ -36,7 +37,7 @@ namespace XAO
|
|||||||
void testDoubleField();
|
void testDoubleField();
|
||||||
void testStringField();
|
void testStringField();
|
||||||
|
|
||||||
void testStep(XAO::Type type);
|
void testStep(XAO::Type type, Step* step);
|
||||||
void testBooleanStep();
|
void testBooleanStep();
|
||||||
void testIntegerStep();
|
void testIntegerStep();
|
||||||
void testDoubleStep();
|
void testDoubleStep();
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "TestUtils.hxx"
|
#include "TestUtils.hxx"
|
||||||
#include "GeometryTest.hxx"
|
#include "GeometryTest.hxx"
|
||||||
#include "../XAO_Geometry.hxx"
|
#include "../XAO_Geometry.hxx"
|
||||||
|
#include "../XAO_GeometricElement.hxx"
|
||||||
|
|
||||||
using namespace XAO;
|
using namespace XAO;
|
||||||
|
|
||||||
@ -19,6 +20,78 @@ void GeometryTest::cleanUp()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeometryTest::testGeometryElement()
|
||||||
|
{
|
||||||
|
GeometricElement elt;
|
||||||
|
CPPUNIT_ASSERT_EQUAL(false, elt.hasName());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getName());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getReference());
|
||||||
|
|
||||||
|
elt.setName("test");
|
||||||
|
CPPUNIT_ASSERT_EQUAL(true, elt.hasName());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("test"), elt.getName());
|
||||||
|
|
||||||
|
elt.setReference("abc");
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("abc"), elt.getReference());
|
||||||
|
|
||||||
|
GeometricElement elt2("aa", "bb");
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("aa"), elt2.getName());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("bb"), elt2.getReference());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeometryTest::testGeometryElementList()
|
||||||
|
{
|
||||||
|
GeometricElementList lst;
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, lst.getSize());
|
||||||
|
lst.setSize(10);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(10, lst.getSize());
|
||||||
|
|
||||||
|
GeometricElementList otherLst(15);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(15, otherLst.getSize());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0));
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_THROW(otherLst.getName(20), SALOME_Exception);
|
||||||
|
CPPUNIT_ASSERT_THROW(otherLst.getReference(20), SALOME_Exception);
|
||||||
|
CPPUNIT_ASSERT_THROW(otherLst.hasName(20), SALOME_Exception);
|
||||||
|
|
||||||
|
otherLst.setName(0, "aa");
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("aa"), otherLst.getName(0));
|
||||||
|
CPPUNIT_ASSERT_THROW(otherLst.setName(20, "aa"), SALOME_Exception);
|
||||||
|
otherLst.setReference(0, "bb");
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("bb"), otherLst.getReference(0));
|
||||||
|
CPPUNIT_ASSERT_THROW(otherLst.setReference(20, "aa"), SALOME_Exception);
|
||||||
|
|
||||||
|
otherLst.setSize(10);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(false, otherLst.hasName(0));
|
||||||
|
|
||||||
|
otherLst.setElement(3, "name", "ref");
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("name"), otherLst.getName(3));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("ref"), otherLst.getReference(3));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(true, otherLst.hasName(3));
|
||||||
|
CPPUNIT_ASSERT_THROW(otherLst.setElement(30, "name", "ref"), SALOME_Exception);
|
||||||
|
|
||||||
|
// ---- create elements "name i", "Ri"
|
||||||
|
for (int i = 0; i < otherLst.getSize(); ++i)
|
||||||
|
{
|
||||||
|
std::ostringstream name;
|
||||||
|
name << "name " << i;
|
||||||
|
std::ostringstream ref;
|
||||||
|
ref << "R" << i;
|
||||||
|
|
||||||
|
otherLst.setElement(i, name.str(), ref.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL(8, otherLst.getIndexByReference("R8"));
|
||||||
|
CPPUNIT_ASSERT_THROW(otherLst.getIndexByReference("ZZ"), SALOME_Exception);
|
||||||
|
|
||||||
|
GeometricElementList::iterator first = otherLst.begin();
|
||||||
|
GeometricElement firstElt = first->second;
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("R0"), firstElt.getReference());
|
||||||
|
}
|
||||||
|
|
||||||
void GeometryTest::testGeometry()
|
void GeometryTest::testGeometry()
|
||||||
{
|
{
|
||||||
Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
|
Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
|
||||||
@ -28,9 +101,42 @@ void GeometryTest::testGeometry()
|
|||||||
|
|
||||||
geom->setName("sphere");
|
geom->setName("sphere");
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("sphere"), geom->getName());
|
CPPUNIT_ASSERT_EQUAL(std::string("sphere"), geom->getName());
|
||||||
|
|
||||||
|
delete geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryTest::testGeometryErrors()
|
void GeometryTest::testGeometryErrors()
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT_THROW(Geometry::createGeometry(XAO::STEP), SALOME_Exception);
|
CPPUNIT_ASSERT_THROW(Geometry::createGeometry(XAO::STEP), SALOME_Exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeometryTest::testSetElement()
|
||||||
|
{
|
||||||
|
Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->setVertexName(0, "aa"), SALOME_Exception);
|
||||||
|
|
||||||
|
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("Box_1.brep"));
|
||||||
|
geom->setShape(txt);
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL(false, geom->hasVertexName(0));
|
||||||
|
geom->setVertexName(0, "va");
|
||||||
|
CPPUNIT_ASSERT_EQUAL(true, geom->hasVertexName(0));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("va"), geom->getVertexName(0));
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->getVertexName(100), SALOME_Exception);
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->hasVertexName(100), SALOME_Exception);
|
||||||
|
|
||||||
|
geom->setEdgeName(0, "ea");
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("ea"), geom->getEdgeName(0));
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->getEdgeName(100), SALOME_Exception);
|
||||||
|
|
||||||
|
geom->setFaceName(0, "fa");
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("fa"), geom->getFaceName(0));
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->getFaceName(100), SALOME_Exception);
|
||||||
|
|
||||||
|
geom->setSolidName(0, "sa");
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("sa"), geom->getSolidName(0));
|
||||||
|
CPPUNIT_ASSERT_THROW(geom->getSolidName(100), SALOME_Exception);
|
||||||
|
|
||||||
|
delete geom;
|
||||||
|
}
|
||||||
|
@ -8,6 +8,8 @@ namespace XAO
|
|||||||
class GeometryTest: public CppUnit::TestFixture
|
class GeometryTest: public CppUnit::TestFixture
|
||||||
{
|
{
|
||||||
CPPUNIT_TEST_SUITE(GeometryTest);
|
CPPUNIT_TEST_SUITE(GeometryTest);
|
||||||
|
CPPUNIT_TEST(testGeometryElement);
|
||||||
|
CPPUNIT_TEST(testGeometryElementList);
|
||||||
CPPUNIT_TEST(testGeometry);
|
CPPUNIT_TEST(testGeometry);
|
||||||
CPPUNIT_TEST(testGeometryErrors);
|
CPPUNIT_TEST(testGeometryErrors);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
@ -17,8 +19,11 @@ namespace XAO
|
|||||||
void tearDown();
|
void tearDown();
|
||||||
void cleanUp();
|
void cleanUp();
|
||||||
|
|
||||||
|
void testGeometryElement();
|
||||||
|
void testGeometryElementList();
|
||||||
void testGeometry();
|
void testGeometry();
|
||||||
void testGeometryErrors();
|
void testGeometryErrors();
|
||||||
|
void testSetElement();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ dist_TestXAO_SOURCES = \
|
|||||||
GeometryTest.cxx \
|
GeometryTest.cxx \
|
||||||
ImportExportTest.cxx \
|
ImportExportTest.cxx \
|
||||||
BrepGeometryTest.cxx \
|
BrepGeometryTest.cxx \
|
||||||
|
XaoTest.cxx \
|
||||||
XAOTests.cxx
|
XAOTests.cxx
|
||||||
|
|
||||||
UNIT_TEST_PROG = TestXAO
|
UNIT_TEST_PROG = TestXAO
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "GeometryTest.hxx"
|
#include "GeometryTest.hxx"
|
||||||
#include "ImportExportTest.hxx"
|
#include "ImportExportTest.hxx"
|
||||||
#include "BrepGeometryTest.hxx"
|
#include "BrepGeometryTest.hxx"
|
||||||
|
#include "XaoTest.hxx"
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::XaoUtilsTest);
|
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::XaoUtilsTest);
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GroupTest);
|
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GroupTest);
|
||||||
@ -11,5 +12,6 @@ CPPUNIT_TEST_SUITE_REGISTRATION(XAO::FieldTest);
|
|||||||
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GeometryTest);
|
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GeometryTest);
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::ImportExportTest);
|
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::ImportExportTest);
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::BrepGeometryTest);
|
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::BrepGeometryTest);
|
||||||
|
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::XaoTest);
|
||||||
|
|
||||||
#include "MainTest.hxx"
|
#include "MainTest.hxx"
|
||||||
|
Loading…
Reference in New Issue
Block a user