From 811909e23ff5af744e35663b7bbc38af4a8a2cc2 Mon Sep 17 00:00:00 2001 From: fps Date: Wed, 18 Sep 2013 15:15:40 +0000 Subject: [PATCH] add addXXXField and getXXXField on Xao to add and get field of givent type because of issue with SWIG --- src/XAO/XAO_Xao.cxx | 86 ++++++++++++++++++++++++++++++++++++++- src/XAO/XAO_Xao.hxx | 26 ++++++++++++ src/XAO/tests/XaoTest.cxx | 26 ++++++++++++ src/XAO/tests/XaoTest.hxx | 2 + 4 files changed, 139 insertions(+), 1 deletion(-) diff --git a/src/XAO/XAO_Xao.cxx b/src/XAO/XAO_Xao.cxx index 2bff2edf7..2bd64a357 100644 --- a/src/XAO/XAO_Xao.cxx +++ b/src/XAO/XAO_Xao.cxx @@ -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(); diff --git a/src/XAO/XAO_Xao.hxx b/src/XAO/XAO_Xao.hxx index 241cf4cd7..451d327cb 100644 --- a/src/XAO/XAO_Xao.hxx +++ b/src/XAO/XAO_Xao.hxx @@ -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. diff --git a/src/XAO/tests/XaoTest.cxx b/src/XAO/tests/XaoTest.cxx index 6d1ed0a83..cb96cac27 100644 --- a/src/XAO/tests/XaoTest.cxx +++ b/src/XAO/tests/XaoTest.cxx @@ -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); +} diff --git a/src/XAO/tests/XaoTest.hxx b/src/XAO/tests/XaoTest.hxx index 777afb399..35516750e 100644 --- a/src/XAO/tests/XaoTest.hxx +++ b/src/XAO/tests/XaoTest.hxx @@ -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(); }; } -- 2.39.2