Salome HOME
Added selection validator for intersection. Fixed dll exports.
[modules/shaper.git] / src / GeomValidators / GeomValidators_IntersectionSelection.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomValidators_IntersectionSelection.cpp
4 // Created:     16 Feb 2016
5 // Author:      Dmitry Bobylev
6
7 #include "GeomValidators_IntersectionSelection.h"
8
9 #include <ModelAPI_AttributeInteger.h>
10 #include <ModelAPI_AttributeSelectionList.h>
11 #include <ModelAPI_Feature.h>
12
13 bool GeomValidators_IntersectionSelection::isValid(const AttributePtr& theAttribute,
14                                                    const std::list<std::string>& theArguments,
15                                                    std::string& theError) const
16 {
17   if(!theAttribute.get()) {
18     theError = "Error: empty selection.";
19     return false;
20   }
21   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
22   AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
23   for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
24     AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
25     if(!anAttrSelection.get()) {
26       theError = "Error: empty attribute selection.";
27       return false;
28     }
29     ResultPtr aContext = anAttrSelection->context();
30     if(!aContext.get()) {
31       theError = "Error: empty selection context.";
32       return false;
33     }
34     FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
35     if(!aFeature.get()) {
36       theError = "Error: empty feature.";
37       return false;
38     }
39     std::string aFeatureKind = aFeature->getKind();
40     if(aFeatureKind == "Sketch" ||
41        aFeatureKind == "Plane" ||
42        aFeatureKind == "Axis") {
43       theError = "Error: ";
44       theError += aFeatureKind;
45       theError += " shape is not allowed for selection.";
46       return false;
47     }
48     std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
49     if(!aShape.get()) {
50       aShape = aContext->shape();
51     }
52     if(!aShape.get()) {
53       theError = "Error: empty shape.";
54       return false;
55     }
56     int aShapeType = aShape->shapeType();
57     // Allow to select edges, faces and solids.
58     if(aShapeType != GeomAPI_Shape::EDGE &&
59        aShapeType != GeomAPI_Shape::FACE &&
60        aShapeType != GeomAPI_Shape::SOLID &&
61        aShapeType != GeomAPI_Shape::COMPSOLID &&
62        aShapeType != GeomAPI_Shape::COMPOUND) {
63       theError = "Error: selected shape has the wrong type.";
64       return false;
65     }
66   }
67
68   return true;
69 }