1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomValidators_BooleanSelection.cpp
5 // Author: Dmitry Bobylev
7 #include "GeomValidators_BooleanSelection.h"
9 #include <ModelAPI_AttributeInteger.h>
10 #include <ModelAPI_AttributeSelectionList.h>
11 #include <ModelAPI_Feature.h>
13 bool GeomValidators_BooleanSelection::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 int anOperationType = aFeature->integer("bool_type")->value();
23 AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
24 for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
25 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
26 if(!anAttrSelection.get()) {
27 theError = "Error: empty attribute selection.";
30 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
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") {
47 theError += aFeatureKind;
48 theError += " shape is not allowed for selection.";
51 aShape = aContext->shape();
54 theError = "Error: empty shape.";
57 int aShapeType = aShape->shapeType();
58 if(anOperationType == 1) {
59 // Fuse operation. Allow to select edges, faces and solids.
60 if(aShapeType != GeomAPI_Shape::EDGE &&
61 aShapeType != GeomAPI_Shape::FACE &&
62 aShapeType != GeomAPI_Shape::SOLID &&
63 aShapeType != GeomAPI_Shape::COMPSOLID &&
64 aShapeType != GeomAPI_Shape::COMPOUND) {
65 theError = "Error: selected shape has the wrong type.";
69 if(aShapeType != GeomAPI_Shape::SOLID &&
70 aShapeType != GeomAPI_Shape::COMPSOLID &&
71 aShapeType != GeomAPI_Shape::COMPOUND) {
72 theError = "Error: selected shape has the wrong type.";