move optional name parameter to the end

This commit is contained in:
fps 2013-09-17 11:12:14 +00:00
parent d1d1ae4704
commit 390054003f
27 changed files with 121 additions and 137 deletions

View File

@ -154,7 +154,7 @@ void GEOMImpl_IImportExportOperations::exportGroups(std::list<Handle(GEOM_Object
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)
{

View File

@ -24,9 +24,9 @@
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)
{
}

View File

@ -38,12 +38,12 @@ namespace XAO
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; }

View File

@ -49,7 +49,7 @@ BrepGeometry::BrepGeometry(const std::string& name) : Geometry(name)
{
}
const std::string BrepGeometry::getShape()
const std::string BrepGeometry::getShapeString()
{
std::ostringstream streamShape;
BRepTools::Write(m_shape, streamShape);
@ -59,7 +59,7 @@ const std::string BrepGeometry::getShape()
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;

View File

@ -49,6 +49,8 @@ namespace XAO
*/
BrepGeometry(const std::string& name);
virtual ~BrepGeometry() {}
/**
* Gets the format of the geometry.
* @return the format of the geometry.
@ -59,13 +61,23 @@ namespace XAO
* 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.

View File

@ -24,8 +24,8 @@
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)
{
}

View File

@ -38,12 +38,12 @@ namespace XAO
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; }

View File

@ -38,6 +38,8 @@ namespace XAO
{
}
virtual ~XAO_Exception() throw() {};
/**
* Returns the error message.
* @return the error message.
@ -47,6 +49,16 @@ namespace XAO
return m_message;
}
#ifdef SWIG
%extend
{
std::string __str__() const
{
return std::string(self->what());
}
}
#endif
private:
const char* m_message;
};

View File

@ -33,8 +33,8 @@ using namespace XAO;
// -------------------------------------------------------
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);
@ -49,24 +49,17 @@ Field::~Field()
}
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);
}
@ -121,7 +114,7 @@ throw (XAO_Exception)
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)
@ -131,5 +124,5 @@ throw (XAO_Exception)
return;
throw XAO_Exception(MsgBuilder() << "Step index is out of range [0, "
<< m_steps.size() << "]: " << step);
<< m_steps.size()-1 << "]: " << step);
}

View File

@ -40,39 +40,28 @@ namespace XAO
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.
* @name the name of the field.
* @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.
* @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)
const int& nbElements, const int& nbComponents,
const std::string& name = std::string(""))
throw (XAO_Exception);
/**

View File

@ -71,7 +71,8 @@ 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)

View File

@ -43,6 +43,7 @@ namespace XAO
Geometry(const std::string& name);
public:
/**
* Creates a geometry.
* @param format the format of the geometry.
@ -60,7 +61,7 @@ namespace XAO
throw (XAO_Exception);
/** Destructor. */
~Geometry();
virtual ~Geometry();
/**
* Gets the name of the geometry.
@ -85,8 +86,8 @@ namespace XAO
*/
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(); }

View File

@ -24,19 +24,7 @@
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)

View File

@ -39,16 +39,10 @@ namespace XAO
* 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.
@ -138,15 +132,6 @@ namespace XAO
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

View File

@ -24,8 +24,8 @@
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)
{
}

View File

@ -38,12 +38,12 @@ namespace XAO
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; }

View File

@ -35,7 +35,7 @@ throw (XAO_Exception)
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)
@ -45,7 +45,7 @@ throw (XAO_Exception)
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)

View File

@ -24,8 +24,8 @@
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)
{
}

View File

@ -38,12 +38,12 @@ namespace XAO
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; }

View File

@ -18,11 +18,13 @@
//
// 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;
@ -82,19 +84,13 @@ throw (XAO_Exception)
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;
}
@ -103,7 +99,15 @@ bool Xao::removeGroup(Group* 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
@ -126,18 +130,12 @@ throw (XAO_Exception)
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;
}
@ -146,7 +144,15 @@ bool Xao::removeField(Field* 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)

View File

@ -130,16 +130,10 @@ namespace XAO
/**
* 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.
@ -162,25 +156,19 @@ namespace XAO
* \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.

View File

@ -200,7 +200,7 @@ void XaoExporter::exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePt
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);
@ -386,7 +386,7 @@ void XaoExporter::parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry*
xmlChar* data = xmlNodeGetContent(shapeNode->children);
if (data == NULL)
throw XAO_Exception("Missing BREP");
geometry->setShape((char*)data);
geometry->setShapeString((char*)data);
xmlFree(data);
}
else

View File

@ -174,6 +174,7 @@ namespace XAO
/** Destructor. */
~MsgBuilder() {};
#ifndef SWIG
/** Stream operator. */
template <typename T>
MsgBuilder& operator <<(const T& t)
@ -186,6 +187,7 @@ namespace XAO
* Conversion operator to char*.
*/
operator const char*() const { return m_stream.str().c_str(); }
#endif
private :
std::stringstream m_stream;

View File

@ -23,7 +23,7 @@ void BrepGeometryTest::cleanUp()
void readBrep(Geometry* geom, const std::string& fileName)
{
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath(fileName));
geom->setShape(txt);
geom->setShapeString(txt);
}
void BrepGeometryTest::testGetIDs()

View File

@ -117,7 +117,7 @@ void GeometryTest::testSetElement()
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");

View File

@ -90,7 +90,7 @@ void ImportExportTest::testExportGeometry()
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);

View File

@ -33,15 +33,19 @@ void XaoTest::testGroups()
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()
@ -64,7 +68,10 @@ 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;
}