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 <Events_Error.h>
18 //=================================================================================================
19 bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribute,
20 const std::list<std::string>& theArguments,
21 std::string& theError) const
23 // Get base objects list.
24 if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
25 Events_Error::send("Validator does not support attribute type \"" + theAttribute->attributeType()
26 + "\"\n Only \"" + ModelAPI_AttributeSelectionList::typeId() + "\" supported.");
29 AttributeSelectionListPtr aSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
30 if(!aSelectionList.get()) {
31 theError = "Could not get selection list.";
34 if(aSelectionList->size() == 0) {
35 theError = "Empty selection list.";
39 // Collect base shapes.
40 for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
41 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
42 if(!aSelection.get()) {
43 theError = "Could not get selection.";
46 ResultPtr aContext = aSelection->context();
48 theError = "Attribute have empty context.";
52 GeomShapePtr aShape = aSelection->value();
53 GeomShapePtr aContextShape = aContext->shape();
55 aShape = aContextShape;
58 theError = "Empty shape selected.";
62 // Check that shape has acceptable type.
63 if(aShape->shapeType() != GeomAPI_Shape::VERTEX) {
64 theError = "Selected shape has wrong type. Only vertices acceptable.";
68 // Check that it is vertex on sketch.
69 ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
70 if(aConstruction.get()) {
71 if(aConstruction->isInfinite()) {
72 theError = "Inifinte objects not acceptable.";
76 std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
78 // It is not an edge on the sketch.
79 // Check that it is not local selection.
80 if(!aShape->isEqual(aContextShape)) {
81 // Local selection on body does not allowed.
82 theError = "Selected shape is in the local selection. Only global selection is allowed.";
92 //=================================================================================================
93 bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
94 const std::list<std::string>& theArguments,
95 std::string& theError) const
97 // Get base objects list.
98 if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
99 Events_Error::send("Validator does not support attribute type \"" + theAttribute->attributeType()
100 + "\"\n Only \"" + ModelAPI_AttributeSelectionList::typeId() + "\" supported.");
103 AttributeSelectionListPtr aSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
104 if(!aSelectionList.get()) {
105 theError = "Could not get selection list.";
108 if(aSelectionList->size() == 0) {
109 theError = "Empty selection list.";
113 // Collect base shapes.
114 ListOfShape aListOfShapes;
115 for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
116 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
117 if(!aSelection.get()) {
118 theError = "Could not get selection.";
121 ResultPtr aContext = aSelection->context();
122 if(!aContext.get()) {
123 theError = "Attribute have empty context.";
127 GeomShapePtr aShape = aSelection->value();
128 GeomShapePtr aContextShape = aContext->shape();
130 aShape = aContextShape;
133 theError = "Empty shape selected.";
137 // Check that shape has acceptable type.
138 if(aShape->shapeType() != GeomAPI_Shape::EDGE && aShape->shapeType() != GeomAPI_Shape::WIRE) {
139 theError = "Selected shape has wrong type. Only edges and wires acceptable.";
143 // Check that it is edge on sketch.
144 ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
145 if(aConstruction.get()) {
146 if(aConstruction->isInfinite()) {
147 theError = "Inifinte objects not acceptable.";
151 std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
153 // It is not an edge on the sketch.
154 // Check that it is not local selection.
155 if(!aShape->isEqual(aContextShape)) {
156 // Local selection on body does not allowed.
157 theError = "Selected shape is in the local selection. Only global selection is allowed.";
163 aListOfShapes.push_back(aShape);
167 GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes);
169 theError = "Result wire empty. Probably it has disconnected edges or non-manifold.";