1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomValidators_Tools.cpp
4 // Created: 06 Aug 2014
5 // Author: Vitaly Smetannikov
7 #include "GeomValidators_Tools.h"
9 #include "ModelAPI_AttributeRefAttr.h"
10 #include "ModelAPI_AttributeSelection.h"
11 #include "ModelAPI_AttributeReference.h"
13 #include <TopoDS_Iterator.hxx>
15 namespace GeomValidators_Tools {
17 ObjectPtr getObject(const AttributePtr& theAttribute)
20 std::string anAttrType = theAttribute->attributeType();
21 if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
22 AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
23 if (anAttr != NULL && anAttr->isObject())
24 anObject = anAttr->object();
26 if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
27 AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
29 anObject = anAttr->context();
31 if (anAttrType == ModelAPI_AttributeReference::typeId()) {
32 AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
33 if (anAttr.get() != NULL)
34 anObject = anAttr->value();
39 TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape)
41 TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
43 // for compounds check sub-shapes: it may be compound of needed type:
44 // Booleans may produce compounds of Solids
45 if (aShapeType == TopAbs_COMPOUND) {
46 for(TopoDS_Iterator aSubs(theShape); aSubs.More(); aSubs.Next()) {
47 if (!aSubs.Value().IsNull()) {
48 TopAbs_ShapeEnum aSubType = aSubs.Value().ShapeType();
49 if (aSubType == TopAbs_COMPOUND) { // compound of compound(s)
50 aShapeType = TopAbs_COMPOUND;
53 if (aShapeType == TopAbs_COMPOUND) {
54 aShapeType = aSubType;
55 } else if (aShapeType != aSubType) { // compound of shapes of different types
56 aShapeType = TopAbs_COMPOUND;