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 <Events_InfoMessage.h>
11 #include <ModelAPI_AttributeInteger.h>
12 #include <ModelAPI_AttributeSelectionList.h>
13 #include <ModelAPI_Feature.h>
15 bool GeomValidators_IntersectionSelection::isValid(const AttributePtr& theAttribute,
16 const std::list<std::string>& theArguments,
17 Events_InfoMessage& theError) const
19 if(!theAttribute.get()) {
20 theError = "Error: empty selection.";
23 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
24 AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
25 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
26 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
27 if(!anAttrSelection.get()) {
28 theError = "Error: empty attribute selection.";
31 ResultPtr aContext = anAttrSelection->context();
33 theError = "Error: empty selection context.";
36 FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
38 theError = "Error: empty feature.";
41 std::string aFeatureKind = aFeature->getKind();
42 if(aFeatureKind == "Sketch" ||
43 aFeatureKind == "Plane" ||
44 aFeatureKind == "Axis") {
45 theError = "Error: %1 shape is not allowed for selection.";
46 theError.arg(aFeatureKind);
49 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
50 GeomShapePtr aContextShape = aContext->shape();
52 aShape = aContextShape;
55 theError = "Error: empty shape.";
58 if(!aShape->isEqual(aContextShape)) {
59 theError = "Error: Local selection not allowed.";
63 int aShapeType = aShape->shapeType();
64 // Allow to select edges, faces and solids.
65 if(aShapeType != GeomAPI_Shape::EDGE &&
66 aShapeType != GeomAPI_Shape::FACE &&
67 aShapeType != GeomAPI_Shape::SOLID &&
68 aShapeType != GeomAPI_Shape::COMPSOLID &&
69 aShapeType != GeomAPI_Shape::COMPOUND) {
70 theError = "Error: selected shape has the wrong type.";