+ } else if (theAttrType == Model_AttributeBoolean::type()) {
+ anAttr = new Model_AttributeBoolean(anAttrLab);
+ } else if (theAttrType == Model_AttributeString::type()) {
+ anAttr = new Model_AttributeString(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeReference::type()) {
+ anAttr = new Model_AttributeReference(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeSelection::type()) {
+ anAttr = new Model_AttributeSelection(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeSelectionList::type()) {
+ anAttr = new Model_AttributeSelectionList(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeRefAttr::type()) {
+ anAttr = new Model_AttributeRefAttr(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeRefList::type()) {
+ anAttr = new Model_AttributeRefList(anAttrLab);
+ }
+ // create also GeomData attributes here because only here the OCAF strucure is known
+ else if (theAttrType == GeomData_Point::type()) {
+ anAttr = new GeomData_Point(anAttrLab);
+ } else if (theAttrType == GeomData_Dir::type()) {
+ anAttr = new GeomData_Dir(anAttrLab);
+ } else if (theAttrType == GeomData_Point2D::type()) {
+ anAttr = new GeomData_Point2D(anAttrLab);
+ }
+ if (anAttr) {
+ myAttrs[theID] = std::shared_ptr<ModelAPI_Attribute>(anAttr);
+ anAttr->setObject(myObject);
+ anAttr->setID(theID);
+ } else {
+ Events_Error::send("Can not create unknown type of attribute " + theAttrType);
+ }
+}
+
+// macro for gthe generic returning of the attribute by the ID
+#define GET_ATTRIBUTE_BY_ID(ATTR_TYPE, METHOD_NAME) \
+ std::shared_ptr<ATTR_TYPE> Model_Data::METHOD_NAME(const std::string& theID) { \
+ std::shared_ptr<ATTR_TYPE> aRes; \
+ std::map<std::string, AttributePtr >::iterator aFound = \
+ myAttrs.find(theID); \
+ if (aFound != myAttrs.end()) { \
+ aRes = std::dynamic_pointer_cast<ATTR_TYPE>(aFound->second); \
+ } \
+ return aRes; \
+ }
+// implement nice getting methods for all ModelAPI attributes
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDocRef, document);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDouble, real);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeInteger, integer);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeBoolean, boolean);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeString, string);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeReference, reference);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelection, selection);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist);
+
+std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
+{
+ std::shared_ptr<ModelAPI_Attribute> aResult;
+ if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
+ return aResult;
+ return myAttrs[theID];
+}
+
+const std::string& Model_Data::id(const std::shared_ptr<ModelAPI_Attribute>& theAttr)
+{
+ std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr =
+ myAttrs.begin();
+ for (; anAttr != myAttrs.end(); anAttr++) {
+ if (anAttr->second == theAttr)
+ return anAttr->first;
+ }
+ // not found
+ static std::string anEmpty;
+ return anEmpty;
+}
+
+bool Model_Data::isEqual(const std::shared_ptr<ModelAPI_Data>& theData)
+{
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theData);
+ if (aData)
+ return myLab.IsEqual(aData->myLab) == Standard_True ;
+ return false;
+}
+
+bool Model_Data::isValid()
+{
+ return !myLab.IsNull() && myLab.HasAttribute();
+}
+
+std::list<std::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const std::string& theType)
+{
+ std::list<std::shared_ptr<ModelAPI_Attribute> > aResult;
+ std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
+ myAttrs.begin();
+ for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
+ if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
+ aResult.push_back(anAttrsIter->second);
+ }
+ }
+ return aResult;
+}