add addXXXField and getXXXField on Xao to add and get field of givent type because of issue with SWIG

This commit is contained in:
fps 2013-09-18 15:15:40 +00:00
parent 7fb55ab92e
commit 811909e23f
4 changed files with 139 additions and 1 deletions

View File

@ -25,6 +25,9 @@
#include "XAO_Group.hxx"
#include "XAO_Field.hxx"
#include "XAO_IntegerField.hxx"
#include "XAO_BooleanField.hxx"
#include "XAO_DoubleField.hxx"
#include "XAO_StringField.hxx"
#include "XAO_XaoExporter.hxx"
using namespace XAO;
@ -115,6 +118,12 @@ const int Xao::countFields() const
return m_fields.size();
}
const XAO::Type Xao::getFieldType(const int& index)
throw (XAO_Exception)
{
return getField(index)->getType();
}
Field* Xao::getField(const int& index)
throw (XAO_Exception)
{
@ -127,7 +136,43 @@ throw (XAO_Exception)
return (*it);
}
return NULL;
throw XAO_Exception("Field not found.");
}
BooleanField* Xao::getBooleanField(const int& index)
throw (XAO_Exception)
{
Field* field = getField(index);
if (field->getType() != XAO::BOOLEAN)
throw XAO_Exception(MsgBuilder() << "Field " << index << " is not a boolean field.");
return (BooleanField*)field;
}
DoubleField* Xao::getDoubleField(const int& index)
throw (XAO_Exception)
{
Field* field = getField(index);
if (field->getType() != XAO::DOUBLE)
throw XAO_Exception(MsgBuilder() << "Field " << index << " is not a double field.");
return (DoubleField*)field;
}
IntegerField* Xao::getIntegerField(const int& index)
throw (XAO_Exception)
{
Field* field = getField(index);
if (field->getType() != XAO::INTEGER)
throw XAO_Exception(MsgBuilder() << "Field " << index << " is not an integer field.");
return (IntegerField*)field;
}
StringField* Xao::getStringField(const int& index)
throw (XAO_Exception)
{
Field* field = getField(index);
if (field->getType() != XAO::STRING)
throw XAO_Exception(MsgBuilder() << "Field " << index << " is not a string field.");
return (StringField*)field;
}
Field* Xao::addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents, const std::string& name)
@ -140,6 +185,45 @@ throw (XAO_Exception)
return field;
}
IntegerField* Xao::addIntegerField(const XAO::Dimension& dim, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
int nbElts = m_geometry->countElements(dim);
IntegerField* field = new IntegerField(dim, nbElts, nbComponents, name);
m_fields.push_back(field);
return field;
}
BooleanField* Xao::addBooleanField(const XAO::Dimension& dim, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
int nbElts = m_geometry->countElements(dim);
BooleanField* field = new BooleanField(dim, nbElts, nbComponents, name);
m_fields.push_back(field);
return field;
}
DoubleField* Xao::addDoubleField(const XAO::Dimension& dim, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
int nbElts = m_geometry->countElements(dim);
DoubleField* field = new DoubleField(dim, nbElts, nbComponents, name);
m_fields.push_back(field);
return field;
}
StringField* Xao::addStringField(const XAO::Dimension& dim, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
int nbElts = m_geometry->countElements(dim);
StringField* field = new StringField(dim, nbElts, nbComponents, name);
m_fields.push_back(field);
return field;
}
bool Xao::removeField(Field* field)
{
int nb = countFields();

View File

@ -31,6 +31,10 @@ namespace XAO
{
class Group;
class Field;
class IntegerField;
class DoubleField;
class BooleanField;
class StringField;
/**
* @class Xao
@ -150,6 +154,14 @@ namespace XAO
* \return the number of fields.
*/
const int countFields() const;
/**
* Gets the type of a field.
* \param index the index of the wanted field.
* \return the type of the field.
*/
const XAO::Type getFieldType(const int& index) throw (XAO_Exception);
/**
* Gets a field.
* \param index the index of the wanted field.
@ -157,6 +169,11 @@ namespace XAO
*/
Field* getField(const int& index) throw (XAO_Exception);
BooleanField* getBooleanField(const int& index) throw (XAO_Exception);
DoubleField* getDoubleField(const int& index) throw (XAO_Exception);
IntegerField* getIntegerField(const int& index) throw (XAO_Exception);
StringField* getStringField(const int& index) throw (XAO_Exception);
/**
* Adds a field.
* \param type the type of the field.
@ -169,6 +186,15 @@ namespace XAO
const std::string& name = std::string(""))
throw (XAO_Exception);
BooleanField* addBooleanField(const XAO::Dimension& dim, const int& nbComponents,
const std::string& name = std::string("")) throw (XAO_Exception);
IntegerField* addIntegerField(const XAO::Dimension& dim, const int& nbComponents,
const std::string& name = std::string("")) throw (XAO_Exception);
DoubleField* addDoubleField(const XAO::Dimension& dim, const int& nbComponents,
const std::string& name = std::string("")) throw (XAO_Exception);
StringField* addStringField(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

@ -75,3 +75,29 @@ void XaoTest::testFields()
CPPUNIT_ASSERT_EQUAL(false, obj.removeField(ff));
delete ff;
}
void XaoTest::testFieldsTypes()
{
Xao obj;
BrepGeometry* geom = new BrepGeometry("test");
obj.setGeometry(geom);
IntegerField* fi = obj.addIntegerField(XAO::FACE, 3);
BooleanField* fb = obj.addBooleanField(XAO::FACE, 3);
DoubleField* fd = obj.addDoubleField(XAO::FACE, 3);
StringField* fs = obj.addStringField(XAO::FACE, 3);
IntegerField* gfi = obj.getIntegerField(0);
CPPUNIT_ASSERT(gfi == fi);
BooleanField* gfb = obj.getBooleanField(1);
CPPUNIT_ASSERT(gfb == fb);
DoubleField* gfd = obj.getDoubleField(2);
CPPUNIT_ASSERT(gfd == fd);
StringField* gfs = obj.getStringField(3);
CPPUNIT_ASSERT(gfs == fs);
CPPUNIT_ASSERT_THROW(obj.getIntegerField(1), XAO_Exception);
CPPUNIT_ASSERT_THROW(obj.getBooleanField(0), XAO_Exception);
CPPUNIT_ASSERT_THROW(obj.getDoubleField(0), XAO_Exception);
CPPUNIT_ASSERT_THROW(obj.getStringField(0), XAO_Exception);
}

View File

@ -10,6 +10,7 @@ namespace XAO
CPPUNIT_TEST_SUITE(XaoTest);
CPPUNIT_TEST(testGroups);
CPPUNIT_TEST(testFields);
CPPUNIT_TEST(testFieldsTypes);
CPPUNIT_TEST_SUITE_END();
public:
@ -19,6 +20,7 @@ namespace XAO
void testGroups();
void testFields();
void testFieldsTypes();
};
}