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_ValidatorBaseForWire::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 ListOfShape aListOfShapes;
41 for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
42 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
43 if(!aSelection.get()) {
44 theError = "Could not get selection.";
47 ResultPtr aContext = aSelection->context();
49 theError = "Attribute have empty context.";
53 GeomShapePtr aShape = aSelection->value();
54 GeomShapePtr aContextShape = aContext->shape();
56 aShape = aContextShape;
59 theError = "Empty shape selected.";
63 // Check that shape has acceptable type.
64 if(aShape->shapeType() != GeomAPI_Shape::EDGE && aShape->shapeType() != GeomAPI_Shape::WIRE) {
65 theError = "Selected shape has wrong type. Only edges and wires acceptable.";
69 // Check that it is edge on sketch.
70 ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
71 if(aConstruction.get()) {
72 if(aConstruction->isInfinite()) {
73 theError = "Inifinte objects not acceptable.";
77 std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
79 // It is not an edge on the sketch.
80 // Check that it is not local selection.
81 if(!aShape->isEqual(aContextShape)) {
82 // Local selection on body does not allowed.
83 theError = "Selected shape is in the local selection. Only global selection is allowed.";
89 aListOfShapes.push_back(aShape);
93 GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes);
95 theError = "Result wire empty. Probably it has disconnected edges or non-manifold.";