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 theError = "Error: sketch shape is selected, but only objects are acceptable.";
47 aShape = aContext->shape();
50 theError = "Error: empty shape.";
53 int aShapeType = aShape->shapeType();
54 if(anOperationType == 1) {
55 // Fuse operation. Allow to select edges, faces and solids.
56 if(aShapeType != GeomAPI_Shape::EDGE &&
57 aShapeType != GeomAPI_Shape::FACE &&
58 aShapeType != GeomAPI_Shape::SOLID &&
59 aShapeType != GeomAPI_Shape::COMPSOLID &&
60 aShapeType != GeomAPI_Shape::COMPOUND) {
61 theError = "Error: selected shape has the wrong type.";
65 if(aShapeType != GeomAPI_Shape::SOLID &&
66 aShapeType != GeomAPI_Shape::COMPSOLID &&
67 aShapeType != GeomAPI_Shape::COMPOUND) {
68 theError = "Error: selected shape has the wrong type.";