1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: BuildPlugin_Validators.cpp
4 // Created: 22 March 2016
5 // Author: Dmitry Bobylev
7 #include "BuildPlugin_Validators.h"
9 #include <ModelAPI_AttributeSelectionList.h>
10 #include <ModelAPI_ResultConstruction.h>
12 #include <GeomAPI_PlanarEdges.h>
14 #include <GeomAlgoAPI_WireBuilder.h>
16 #include <GeomValidators_ShapeType.h>
18 #include <Events_Error.h>
20 //=================================================================================================
21 bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute,
22 const std::list<std::string>& theArguments,
23 std::string& theError) const
25 // Get base objects list.
26 if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
27 Events_Error::send("Validator does not support attribute type \"" + theAttribute->attributeType()
28 + "\"\n Only \"" + ModelAPI_AttributeSelectionList::typeId() + "\" supported.");
31 AttributeSelectionListPtr aSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
32 if(!aSelectionList.get()) {
33 theError = "Could not get selection list.";
36 if(aSelectionList->size() == 0) {
37 theError = "Empty selection list.";
41 // Collect base shapes.
42 for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
43 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
44 if(!aSelection.get()) {
45 theError = "Could not get selection.";
48 ResultPtr aContext = aSelection->context();
50 theError = "Attribute have empty context.";
54 GeomShapePtr aShape = aSelection->value();
55 GeomShapePtr aContextShape = aContext->shape();
57 aShape = aContextShape;
60 theError = "Empty shape selected.";
64 // Check that shapes has acceptable type.
65 GeomValidators_ShapeType aValidatorShapeType;
66 if(!aValidatorShapeType.isValid(aSelection, theArguments, theError)) {
70 // Check that it is shape on sketch.
71 ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
72 if(aConstruction.get()) {
73 if(aConstruction->isInfinite()) {
74 theError = "Inifinte objects not acceptable.";
78 std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
79 if(anEdges.get() && !aShape->isEqual(aContextShape)) {
80 // It is local selection on sketch. Ok.
85 if(!aShape->isEqual(aContextShape)) {
86 // Local selection on body does not allowed.
87 theError = "Selected shape is in the local selection. Only global selection is allowed.";
95 //=================================================================================================
96 bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
97 const std::list<std::string>& theArguments,
98 std::string& theError) const
100 // Get base objects list.
101 BuildPlugin_ValidatorBaseForBuild aValidatorBaseForBuild;
102 if(!aValidatorBaseForBuild.isValid(theAttribute, theArguments, theError)) {
106 // Collect base shapes.
107 AttributeSelectionListPtr aSelectionList =
108 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
109 ListOfShape aListOfShapes;
110 for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
111 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
112 ResultPtr aContext = aSelection->context();
113 GeomShapePtr aShape = aSelection->value();
114 GeomShapePtr aContextShape = aContext->shape();
116 aShape = aSelection->context()->shape();
118 aListOfShapes.push_back(aShape);
122 GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes);
124 theError = "Result wire empty. Probably it has disconnected edges or non-manifold.";