Salome HOME
7f16f08144f74048798b6dd4a902d6fcf8d0be97
[modules/shaper.git] / src / GeomValidators / GeomValidators_Tools.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomValidators_Tools.cpp
4 // Created:     06 Aug 2014
5 // Author:      Vitaly Smetannikov
6
7 #include "GeomValidators_Tools.h"
8
9 #include "ModelAPI_AttributeRefAttr.h"
10 #include "ModelAPI_AttributeSelection.h"
11 #include "ModelAPI_AttributeReference.h"
12
13 #include <TopoDS_Iterator.hxx>
14
15 namespace GeomValidators_Tools {
16
17   ObjectPtr getObject(const AttributePtr& theAttribute)
18   {
19     ObjectPtr anObject;
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();
25     }
26     if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
27       AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
28       if (anAttr != NULL)
29         anObject = anAttr->context();
30     }
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();
35     }
36     return anObject;
37   }
38
39   TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape)
40   {
41     TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
42
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;
51             break;
52           }
53           if (aShapeType == TopAbs_COMPOUND) {
54             aShapeType = aSubType;
55           } else if (aShapeType != aSubType) { // compound of shapes of different types
56             aShapeType = TopAbs_COMPOUND;
57             break;
58           }
59         }
60       }
61     }
62     return aShapeType;
63   }
64
65 }