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