TopTools_MapOfShape mapShape;
TopTools_ListOfShape listShape;
+ int nbElt = 0;
TopExp_Explorer exp(m_shape, shapeType);
for (; exp.More(); exp.Next())
{
if (mapShape.Add(exp.Current()))
+ {
listShape.Append(exp.Current());
+ nbElt++;
+ }
}
if (listShape.IsEmpty())
TopTools_IndexedMapOfShape indices;
TopExp::MapShapes(m_shape, indices);
- std::list<int> indexList;
+ eltList.setSize(nbElt);
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();
- 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)
if (!listShape.IsEmpty())
{
- // use main shape indices
- TopTools_IndexedMapOfShape indices;
- TopExp::MapShapes(mainShape, indices);
-
TopTools_ListIteratorOfListOfShape itSub(listShape);
- for (int index = 1; itSub.More(); itSub.Next(), ++index)
+ for (int index = 0; itSub.More(); itSub.Next(), ++index)
{
- if (shapeIndex + 1 == index)
+ if (shapeIndex == index)
{
TopoDS_Shape value = itSub.Value();
return value;
const int BrepGeometry::countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType)
{
int res = 0;
- TopTools_MapOfShape mapShape;
TopExp_Explorer exp(shape, shapeType);
for (; exp.More(); exp.Next())
- {
-// if (mapShape.Add(exp.Current()))
- res++;
- }
+ res++;
return res;
}
TopExp::MapShapes(m_shape, indices);
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();
int id = indices.FindIndex(value);
return findFace(id);
if (dim == XAO::SOLID)
return findSolid(id);
+
throw SALOME_Exception(MsgBuilder() << "Unknown Dimension: " << dim);
}
void setFaceID(const int& index, const int& id);
void setSolidID(const int& index, const int& id);
- const int findElement(const XAO::Dimension& dim, const int& id);
-
/**
* Finds a vertex with its ID.
* @param id the ID of the vertex.
TopoDS_Shape getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex);
const int countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType);
std::vector<int> getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim);
+ const int findElement(const XAO::Dimension& dim, const int& id);
private:
TopoDS_Shape m_shape;
GeometricElementList::GeometricElementList(const int& count)
{
- setSize(m_count);
+ setSize(count);
}
void GeometricElementList::setSize(const int& nb)
}
}
-void GeometricElementList::setElement(const int& index, const std::string& name, const std::string& reference)
+void GeometricElementList::checkElementIndex(const int& index) const
{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
+ 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)
+{
+ checkElementIndex(index);
m_elements[index].setName(name);
m_elements[index].setReference(reference);
}
const std::string GeometricElementList::getName(const int& index)
{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
-
+ checkElementIndex(index);
return m_elements[index].getName();
}
void GeometricElementList::setName(const int& index, const std::string& name)
{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
-
+ checkElementIndex(index);
m_elements[index].setName(name);
}
const bool GeometricElementList::hasName(const int& index)
{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
-
+ checkElementIndex(index);
return m_elements[index].hasName();
}
const std::string GeometricElementList::getReference(const int& index)
{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
-
+ checkElementIndex(index);
return m_elements[index].getReference();
}
void GeometricElementList::setReference(const int& index, const std::string& name)
{
- if (m_count == 0 || index > m_count)
- throw SALOME_Exception("Problem with number of elements");
-
+ checkElementIndex(index);
m_elements[index].setReference(name);
}
*/
iterator end() { return m_elements.end(); }
+ private:
+ void checkElementIndex(const int& index) const;
+
private:
int m_count;
std::map<int, GeometricElement> m_elements;
using namespace XAO;
-Step* Step::createStep(const XAO::Type& type, const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
-{
- if (type == XAO::BOOLEAN)
- return new BooleanStep(step, stamp, nbElements, nbComponents);
- if (type == XAO::INTEGER)
- return new IntegerStep(step, stamp, nbElements, nbComponents);
- if (type == XAO::DOUBLE)
- return new DoubleStep(step, stamp, nbElements, nbComponents);
- if (type == XAO::STRING)
- return new StringStep(step, stamp, nbElements, nbComponents);
-
- throw SALOME_Exception("Unknown Type");
-}
-
void Step::checkElementIndex(const int& element)
{
if (element < m_nbElements && element >= 0)
Step() {}
public:
- /**
- * Creates a step.
- * @param type the type of the values for the step.
- * @param step the index of the step.
- * @param stamp the stamp of the step.
- * @param nbElements the number of elements in the step.
- * @param nbComponents the number of components in the step.
- * @return
- */
- static Step* createStep(const XAO::Type& type, const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
-
/**
* Destructor.
*/
Group* Xao::getGroup(const int& index)
{
+ checkGroupIndex(index);
+
int i = 0;
for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it, ++i)
{
return group;
}
-void Xao::removeGroup(Group* group)
+bool Xao::removeGroup(Group* group)
{
+ int nb = countGroups();
m_groups.remove(group);
+ return (nb-1 == countGroups());
}
const int Xao::countFields() const
Field* Xao::getField(const int& index)
{
+ checkFieldIndex(index);
+
int i = 0;
for (std::list<Field*>::iterator it = m_fields.begin(); it != m_fields.end(); ++it, ++i)
{
return field;
}
-void Xao::removeField(Field* field)
+bool Xao::removeField(Field* field)
{
+ int nb = countFields();
m_fields.remove(field);
+ return (nb-1 == countFields());
}
const bool Xao::exportXAO(const std::string& fileName)
if (m_geometry == 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);
+}
/**
* Removes a group.
* \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
/**
* Removes a field.
* \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
private:
void checkGeometry() const;
+ void checkGroupIndex(const int& index) const;
+ void checkFieldIndex(const int& index) const;
private:
/** The author of the file. */
const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName)
{
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);
return true;
xmlChar *xmlbuff;
int buffersize;
- xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
+ xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation
xmlFreeDoc(doc);
xmlCleanupGlobals();
for (int j = 0; j < step->countComponents(); ++j)
{
std::string content = step->getStringValue(i, j);
- xmlNodePtr nodeValue= xmlNewTextChild(nodeElt, 0, C_TAG_VALUE, BAD_CAST content.c_str());
+ 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());
}
}
{
public:
MsgBuilder() {};
+ ~MsgBuilder() {};
template <typename T>
MsgBuilder& operator <<(const T& t)
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()
{
BrepGeometry* geom = new BrepGeometry("box");
CPPUNIT_TEST_SUITE(BrepGeometryTest);
CPPUNIT_TEST(testGetIDs);
CPPUNIT_TEST(testGetReferences);
+ CPPUNIT_TEST(testGetNames);
CPPUNIT_TEST(testGetEdgeVertices);
CPPUNIT_TEST(testGetFaceEdges);
CPPUNIT_TEST(testSolidFaces);
void testGetIDs();
void testGetReferences();
+ void testGetNames();
void testGetEdgeVertices();
void testGetFaceEdges();
void testSolidFaces();
CPPUNIT_ASSERT_EQUAL(0, f->countSteps());
Step* step = f->addNewStep(0);
+ CPPUNIT_ASSERT_EQUAL(type, step->getType());
CPPUNIT_ASSERT_EQUAL(1, f->countSteps());
step = f->addNewStep(1);
step = f->addNewStep(2);
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(0, step->getStep());
void FieldTest::testBooleanStep()
{
- testStep(XAO::BOOLEAN);
+ Step* step = new BooleanStep(0, 0, 5, 3);
+ testStep(XAO::BOOLEAN, step);
}
void FieldTest::testIntegerStep()
{
- testStep(XAO::INTEGER);
+ Step* step = new IntegerStep(0, 0, 5, 3);
+ testStep(XAO::INTEGER, step);
}
void FieldTest::testDoubleStep()
{
- testStep(XAO::DOUBLE);
+ Step* step = new DoubleStep(0, 0, 5, 3);
+ testStep(XAO::DOUBLE, step);
}
void FieldTest::testStringStep()
{
- testStep(XAO::STRING);
+ Step* step = new StringStep(0, 0, 5, 3);
+ testStep(XAO::STRING, step);
}
void FieldTest::testBooleanStepValues()
int nbComponents = 3; // > 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 j = 0; j < step->countComponents(); ++j)
// set string value
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
std::vector<bool> allValues;
int nbComponents = 3;
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 j = 0; j < step->countComponents(); ++j)
int nbComponents = 3;
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 j = 0; j < step->countComponents(); ++j)
int nbComponents = 3;
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 j = 0; j < step->countComponents(); ++j)
#include "../XAO_Xao.hxx"
#include "../XAO_Field.hxx"
+#include "../XAO_Step.hxx"
namespace XAO
{
void testDoubleField();
void testStringField();
- void testStep(XAO::Type type);
+ void testStep(XAO::Type type, Step* step);
void testBooleanStep();
void testIntegerStep();
void testDoubleStep();
#include "TestUtils.hxx"
#include "GeometryTest.hxx"
#include "../XAO_Geometry.hxx"
+#include "../XAO_GeometricElement.hxx"
using namespace XAO;
{
}
+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()
{
Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
geom->setName("sphere");
CPPUNIT_ASSERT_EQUAL(std::string("sphere"), geom->getName());
+
+ delete geom;
}
void GeometryTest::testGeometryErrors()
{
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;
+}
class GeometryTest: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(GeometryTest);
+ CPPUNIT_TEST(testGeometryElement);
+ CPPUNIT_TEST(testGeometryElementList);
CPPUNIT_TEST(testGeometry);
CPPUNIT_TEST(testGeometryErrors);
CPPUNIT_TEST_SUITE_END();
void tearDown();
void cleanUp();
+ void testGeometryElement();
+ void testGeometryElementList();
void testGeometry();
void testGeometryErrors();
+ void testSetElement();
};
}
GeometryTest.cxx \
ImportExportTest.cxx \
BrepGeometryTest.cxx \
+ XaoTest.cxx \
XAOTests.cxx
UNIT_TEST_PROG = TestXAO
#include "GeometryTest.hxx"
#include "ImportExportTest.hxx"
#include "BrepGeometryTest.hxx"
+#include "XaoTest.hxx"
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::XaoUtilsTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GroupTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GeometryTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::ImportExportTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::BrepGeometryTest);
+CPPUNIT_TEST_SUITE_REGISTRATION(XAO::XaoTest);
#include "MainTest.hxx"