#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;
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)
{
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)
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();
{
class Group;
class Field;
+ class IntegerField;
+ class DoubleField;
+ class BooleanField;
+ class StringField;
/**
* @class 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.
*/
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.
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.
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);
+}