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 =
25 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
26 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
27 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
28 if(!anAttrSelection.get()) {
29 theError = "Error: empty attribute selection.";
32 ResultPtr aContext = anAttrSelection->context();
34 theError = "Error: empty selection context.";
37 FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
39 theError = "Error: empty feature.";
42 std::string aFeatureKind = aFeature->getKind();
43 if(aFeatureKind == "Sketch" ||
44 aFeatureKind == "Plane" ||
45 aFeatureKind == "Axis") {
46 theError = "Error: %1 shape is not allowed for selection.";
47 theError.arg(aFeatureKind);
50 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
51 GeomShapePtr aContextShape = aContext->shape();
53 aShape = aContextShape;
56 theError = "Error: empty shape.";
59 if(!aShape->isEqual(aContextShape)) {
60 theError = "Error: Local selection not allowed.";
64 int aShapeType = aShape->shapeType();
65 // Allow to select edges, faces and solids.
66 if(aShapeType != GeomAPI_Shape::EDGE &&
67 aShapeType != GeomAPI_Shape::FACE &&
68 aShapeType != GeomAPI_Shape::SOLID &&
69 aShapeType != GeomAPI_Shape::COMPSOLID &&
70 aShapeType != GeomAPI_Shape::COMPOUND) {
71 theError = "Error: selected shape has the wrong type.";