TopAbs_ShapeEnum shapeGroup = m_groupOperations->GetType(currGroup);
XAO::Dimension dim = shapeEnumToDimension(shapeGroup);
- XAO::Group* group = xaoObject->addGroup(currGroup->GetName(), dim);
+ XAO::Group* group = xaoObject->addGroup(dim, currGroup->GetName());
switch (shapeGroup)
{
using namespace XAO;
-BooleanField::BooleanField(const std::string& name, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents)
- : Field(name, dimension, nbElements, nbComponents)
+BooleanField::BooleanField(const XAO::Dimension& dimension,
+ const int& nbElements, const int& nbComponents, const std::string& name)
+ : Field(dimension, nbElements, nbComponents, name)
{
}
public:
/**
* Constructor.
- * @param name the name of the field.
* @param dimension the dimension of the field.
* @param nbElements the number of elements.
* @param nbComponents the number of components.
+ * @param name the name of the field.
*/
- BooleanField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
+ BooleanField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name);
virtual const XAO::Type getType() { return XAO::BOOLEAN; }
{
}
-const std::string BrepGeometry::getShape()
+const std::string BrepGeometry::getShapeString()
{
std::ostringstream streamShape;
BRepTools::Write(m_shape, streamShape);
return res;
}
-void BrepGeometry::setShape(const std::string& shape)
+void BrepGeometry::setShapeString(const std::string& shape)
{
std::istringstream streamBrep(shape.c_str());
BRep_Builder builder;
*/
BrepGeometry(const std::string& name);
+ virtual ~BrepGeometry() {}
+
/**
* Gets the format of the geometry.
* @return the format of the geometry.
* Gets the shape as a string.
* @return the shape as a string.
*/
- virtual const std::string getShape();
+ virtual const std::string getShapeString();
/**
* Sets the shape from a string.
* @param shape the shape as a string.
*/
- virtual void setShape(const std::string& shape);
+ virtual void setShapeString(const std::string& shape);
+
+#ifdef SWIG
+ %pythoncode %{
+ def setShape(self, shape):
+ if shape is not None and 'GetShapeStream' in dir(shape):
+ self.setShapeString(shape.GetShapeStream())
+ else:
+ raise XAO_Exception("Cannot set shape")
+ %}
+#endif
/**
* Gets the shape as a TopoDS_Shape.
using namespace XAO;
-DoubleField::DoubleField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents)
- : Field(name, dimension, nbElements, nbComponents)
+DoubleField::DoubleField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name)
+ : Field(dimension, nbElements, nbComponents, name)
{
}
public:
/**
* Constructor.
- * @param name the name of the field.
* @param dimension the dimension of the field.
* @param nbElements the number of elements.
* @param nbComponents the number of components.
+ * @param name the name of the field.
*/
- DoubleField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
+ DoubleField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponentsconst, const std::string& name);
virtual const XAO::Type getType() { return XAO::DOUBLE; }
{
}
+ virtual ~XAO_Exception() throw() {};
+
/**
* Returns the error message.
* @return the error message.
return m_message;
}
+#ifdef SWIG
+ %extend
+ {
+ std::string __str__() const
+ {
+ return std::string(self->what());
+ }
+ }
+#endif
+
private:
const char* m_message;
};
// -------------------------------------------------------
-Field::Field(const std::string& name, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents)
+Field::Field(const XAO::Dimension& dimension,
+ const int& nbElements, const int& nbComponents, const std::string& name)
: m_name(name), m_dimension(dimension), m_nbElements(nbElements), m_nbComponents(nbComponents)
{
m_components.reserve(nbComponents);
}
Field* Field::createField(const XAO::Type& type, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents)
-throw (XAO_Exception)
-{
- return createField(type, "", dimension, nbElements, nbComponents);
-}
-
-Field* Field::createField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents)
+ const int& nbElements, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
if (type == XAO::BOOLEAN)
- return new BooleanField(name, dimension, nbElements, nbComponents);
+ return new BooleanField(dimension, nbElements, nbComponents, name);
if (type == XAO::INTEGER)
- return new IntegerField(name, dimension, nbElements, nbComponents);
+ return new IntegerField(dimension, nbElements, nbComponents, name);
if (type == XAO::DOUBLE)
- return new DoubleField(name, dimension, nbElements, nbComponents);
+ return new DoubleField(dimension, nbElements, nbComponents, name);
if (type == XAO::STRING)
- return new StringField(name, dimension, nbElements, nbComponents);
+ return new StringField(dimension, nbElements, nbComponents, name);
throw XAO_Exception(MsgBuilder() << "Bad Type: " << type);
}
return;
throw XAO_Exception(MsgBuilder() << "Step index is out of range [0, "
- << m_nbComponents << "]: " << component);
+ << m_nbComponents-1 << "]: " << component);
}
void Field::checkStepIndex(const int& step)
return;
throw XAO_Exception(MsgBuilder() << "Step index is out of range [0, "
- << m_steps.size() << "]: " << step);
+ << m_steps.size()-1 << "]: " << step);
}
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.
+ * @param name the name of the field.
*/
- Field(const std::string& name, const XAO::Dimension& dimension,
- const int& nbElements, const int& nbComponents);
+ Field(const XAO::Dimension& dimension,
+ const int& nbElements, const int& nbComponents, const std::string& name);
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)
- throw (XAO_Exception);
-
/**
/**
* 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.
+ * @name the name of the field.
* @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)
+ static Field* createField(const XAO::Type& type, const XAO::Dimension& dimension,
+ const int& nbElements, const int& nbComponents,
+ const std::string& name = std::string(""))
throw (XAO_Exception);
/**
if (m_count >= 0 && index < m_count)
return;
- throw XAO_Exception(MsgBuilder() << "Index of element is out of range [0, " << m_count<< "]: " << index);
+ throw XAO_Exception(MsgBuilder() << "Index of element is out of range [0, "
+ << m_count-1 << "]: " << index);
}
void GeometricElementList::setElement(const int& index, const std::string& name, const std::string& reference)
Geometry(const std::string& name);
public:
+
/**
* Creates a geometry.
* @param format the format of the geometry.
throw (XAO_Exception);
/** Destructor. */
- ~Geometry();
+ virtual ~Geometry();
/**
* Gets the name of the geometry.
*/
virtual const XAO::Format getFormat() = 0;
- virtual const std::string getShape() = 0;
- virtual void setShape(const std::string& shape) = 0;
+ virtual const std::string getShapeString() = 0;
+ virtual void setShapeString(const std::string& shape) = 0;
const int countElements(const XAO::Dimension& dim) const throw (XAO_Exception);
const int countVertices() const { return m_vertices.getSize(); }
using namespace XAO;
-Group::Group(const XAO::Dimension& dim, const int& nbElements)
-throw (XAO_Exception)
-{
- initGroup("", dim, nbElements);
-}
-
-Group::Group(const std::string& name, const XAO::Dimension& dim, const int& nbElements)
-throw (XAO_Exception)
-{
- initGroup(name, dim, nbElements);
-}
-
-void Group::initGroup(const std::string& name, const XAO::Dimension& dim, const int& nbElements)
+Group::Group(const XAO::Dimension& dim, const int& nbElements, const std::string& name)
throw (XAO_Exception)
{
if (dim == XAO::WHOLE)
* Constructor.
* @param dim the dimension of the group.
* @param nbElements the number of geometrical elements for the dimension in the geometry.
+ * @param the name of the group.
*/
- Group(const XAO::Dimension& dim, const int& nbElements) throw (XAO_Exception);
-
- /**
- * 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) throw (XAO_Exception);
+ Group(const XAO::Dimension& dim, const int& nbelements, const std::string& name = std::string(""))
+ throw (XAO_Exception);
/**
* Destructor.
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)
- throw (XAO_Exception);
-
/**
* Ensures that the given element is valid.
* @param element
using namespace XAO;
-IntegerField::IntegerField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents)
- : Field(name, dimension, nbElements, nbComponents)
+IntegerField::IntegerField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name)
+ : Field(dimension, nbElements, nbComponents, name)
{
}
public:
/**
* Constructor.
- * @param name the name of the field.
* @param dimension the dimension of the field.
* @param nbElements the number of elements.
* @param nbComponents the number of components.
+ * @param name the name of the field.
*/
- IntegerField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
+ IntegerField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name);
virtual const XAO::Type getType() { return XAO::INTEGER; }
return;
throw XAO_Exception(MsgBuilder() << "Element index is out of range [0, "
- << m_nbElements-1 << "]: " << element);
+ << m_nbElements-1 << "]: " << element);
}
void Step::checkComponentIndex(const int& component)
return;
throw XAO_Exception(MsgBuilder() << "Component index is out of range [0, "
- << m_nbComponents-1 << "]: " << component);
+ << m_nbComponents-1 << "]: " << component);
}
void Step::checkNbElements(const int& nbElements)
using namespace XAO;
-StringField::StringField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents)
- : Field(name, dimension, nbElements, nbComponents)
+StringField::StringField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name)
+ : Field(dimension, nbElements, nbComponents, name)
{
}
public:
/**
* Constructor.
- * @param name the name of the field.
* @param dimension the dimension of the field.
* @param nbElements the number of elements.
* @param nbComponents the number of components.
+ * @param name the name of the field.
*/
- StringField(const std::string& name, const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents);
+ StringField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name);
virtual const XAO::Type getType() { return XAO::STRING; }
//
// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
+#include <iostream>
#include "XAO_XaoUtils.hxx"
#include "XAO_Xao.hxx"
#include "XAO_Geometry.hxx"
#include "XAO_Group.hxx"
#include "XAO_Field.hxx"
+#include "XAO_IntegerField.hxx"
#include "XAO_XaoExporter.hxx"
using namespace XAO;
return NULL;
}
-Group* Xao::addGroup(const XAO::Dimension& dim)
-throw (XAO_Exception)
-{
- return addGroup("", dim);
-}
-
-Group* Xao::addGroup(const std::string& name, const XAO::Dimension& dim)
+Group* Xao::addGroup(const XAO::Dimension& dim, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
checkGroupDimension(dim);
- Group* group = new Group(name, dim, m_geometry->countElements(dim));
+ Group* group = new Group(dim, m_geometry->countElements(dim), name);
m_groups.push_back(group);
return group;
}
{
int nb = countGroups();
m_groups.remove(group);
- return (nb-1 == countGroups());
+
+ bool res = (nb-1 == countGroups());
+ if (res)
+ {
+ delete group;
+ group = NULL;
+ }
+
+ return res;
}
const int Xao::countFields() const
return NULL;
}
-Field* Xao::addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents)
-throw (XAO_Exception)
-{
- return addField(type, "", dim, nbComponents);
-}
-
-Field* Xao::addField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dim, const int& nbComponents)
+Field* Xao::addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
int nbElts = m_geometry->countElements(dim);
- Field* field = Field::createField(type, name, dim, nbElts, nbComponents);
+ Field* field = Field::createField(type, dim, nbElts, nbComponents, name);
m_fields.push_back(field);
return field;
}
{
int nb = countFields();
m_fields.remove(field);
- return (nb-1 == countFields());
+
+ bool res = (nb-1 == countFields());
+ if (res)
+ {
+ delete field;
+ field = NULL;
+ }
+
+ return res;
}
const bool Xao::exportXAO(const std::string& fileName)
/**
* Adds a group.
* \param dim the dimension of the group.
- * \return the created group.
- */
- Group* addGroup(const XAO::Dimension& dim) throw (XAO_Exception);
- /**
- * Adds a group.
* \param name the name of the group.
- * \param dim the dimension of the group.
* \return the created group.
*/
- Group* addGroup(const std::string& name, const XAO::Dimension& dim) throw (XAO_Exception);
+ Group* addGroup(const XAO::Dimension& dim, const std::string& name = std::string("")) throw (XAO_Exception);
/**
* Removes a group.
* \param group the group to remove.
* \return the field.
*/
Field* getField(const int& index) throw (XAO_Exception);
+
/**
* Adds a field.
* \param type the type of the field.
* \param dim the dimension of the field.
* \param nbComponents the number of components in the field.
- * \return the created field.
- */
- Field* addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents)
- throw (XAO_Exception);
- /**
- * Adds a field.
- * \param type the type of the field.
* \param name the name of the field.
- * \param dim the dimension of the field.
- * \param nbComponents the number of components in the field.
* \return the created field.
*/
- Field* addField(const XAO::Type& type, const std::string& name, const XAO::Dimension& dim, const int& nbComponents)
+ Field* addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents,
+ const std::string& name = std::string(""))
throw (XAO_Exception);
+
/**
* Removes a field.
* \param field the field to remove.
xmlNodePtr shape = xmlNewChild(geometry, 0, C_TAG_SHAPE, 0);
xmlNewProp(shape, C_ATTR_SHAPE_FORMAT, BAD_CAST XaoUtils::shapeFormatToString(xaoGeometry->getFormat()).c_str());
- std::string txtShape = xaoGeometry->getShape();
+ std::string txtShape = xaoGeometry->getShapeString();
xmlNodePtr cdata = xmlNewCDataBlock(doc, BAD_CAST txtShape.c_str(), txtShape.size());
xmlAddChild(shape, cdata);
xmlChar* data = xmlNodeGetContent(shapeNode->children);
if (data == NULL)
throw XAO_Exception("Missing BREP");
- geometry->setShape((char*)data);
+ geometry->setShapeString((char*)data);
xmlFree(data);
}
else
/** Destructor. */
~MsgBuilder() {};
+#ifndef SWIG
/** Stream operator. */
template <typename T>
MsgBuilder& operator <<(const T& t)
* Conversion operator to char*.
*/
operator const char*() const { return m_stream.str().c_str(); }
+#endif
private :
std::stringstream m_stream;
void readBrep(Geometry* geom, const std::string& fileName)
{
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath(fileName));
- geom->setShape(txt);
+ geom->setShapeString(txt);
}
void BrepGeometryTest::testGetIDs()
CPPUNIT_ASSERT_THROW(geom->setVertexName(0, "aa"), XAO_Exception);
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("Box_1.brep"));
- geom->setShape(txt);
+ geom->setShapeString(txt);
CPPUNIT_ASSERT_EQUAL(false, geom->hasVertexName(0));
geom->setVertexName(0, "va");
group->add(1);
// fields
- IntegerField* field = (IntegerField*)xao.addField(XAO::INTEGER, "color", XAO::FACE, 2);
+ IntegerField* field = (IntegerField*)xao.addField(XAO::INTEGER, XAO::FACE, 2, "color");
for (int stepIndex = 0; stepIndex < 10; ++stepIndex)
{
IntegerStep* istep = field->addStep(stepIndex, 100*stepIndex);
CPPUNIT_ASSERT_EQUAL(XAO::FACE, gr->getDimension());
CPPUNIT_ASSERT_EQUAL(1, obj.countGroups());
Group* gr2 = obj.addGroup(XAO::FACE);
+ gr2->setName("AA");
Group* agr = obj.getGroup(0);
CPPUNIT_ASSERT(gr == agr);
CPPUNIT_ASSERT_THROW(obj.getGroup(10), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(true, obj.removeGroup(gr2));
- CPPUNIT_ASSERT(gr2 != NULL);
CPPUNIT_ASSERT_EQUAL(1, obj.countGroups());
- CPPUNIT_ASSERT_EQUAL(false, obj.removeGroup(gr2)); // remove again
+
+ // remove other group
+ Group* gr3 = new Group(XAO::FACE, 3);
+ CPPUNIT_ASSERT_EQUAL(false, obj.removeGroup(gr3));
+ delete gr3;
}
void XaoTest::testFields()
CPPUNIT_ASSERT_THROW(obj.getField(10), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(true, obj.removeField(fb));
- CPPUNIT_ASSERT(fb != NULL);
CPPUNIT_ASSERT_EQUAL(3, obj.countFields());
- CPPUNIT_ASSERT_EQUAL(false, obj.removeField(fb)); // remove again
+
+
+ Field* ff = Field::createField(XAO::INTEGER, XAO::FACE, 3, 3);
+ CPPUNIT_ASSERT_EQUAL(false, obj.removeField(ff));
+ delete ff;
}