1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomValidators_IntersectionSelection.cpp
4 // Created: 16 Feb 2016
5 // Author: Dmitry Bobylev
7 #include "GeomValidators_IntersectionSelection.h"
9 #include <ModelAPI_AttributeInteger.h>
10 #include <ModelAPI_AttributeSelectionList.h>
11 #include <ModelAPI_Feature.h>
13 bool GeomValidators_IntersectionSelection::isValid(const AttributePtr& theAttribute,
14 const std::list<std::string>& theArguments,
15 std::string& theError) const
17 if(!theAttribute.get()) {
18 theError = "Error: empty selection.";
21 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
22 AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
23 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
24 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
25 if(!anAttrSelection.get()) {
26 theError = "Error: empty attribute selection.";
29 ResultPtr aContext = anAttrSelection->context();
31 theError = "Error: empty selection context.";
34 FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
36 theError = "Error: empty feature.";
39 std::string aFeatureKind = aFeature->getKind();
40 if(aFeatureKind == "Sketch" ||
41 aFeatureKind == "Plane" ||
42 aFeatureKind == "Axis") {
44 theError += aFeatureKind;
45 theError += " shape is not allowed for selection.";
48 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
50 aShape = aContext->shape();
53 theError = "Error: empty shape.";
56 int aShapeType = aShape->shapeType();
57 // Allow to select edges, faces and solids.
58 if(aShapeType != GeomAPI_Shape::EDGE &&
59 aShapeType != GeomAPI_Shape::FACE &&
60 aShapeType != GeomAPI_Shape::SOLID &&
61 aShapeType != GeomAPI_Shape::COMPSOLID &&
62 aShapeType != GeomAPI_Shape::COMPOUND) {
63 theError = "Error: selected shape has the wrong type.";