continue;
}
}
-
- if(!aShape->isEqual(aContextShape)) {
- // Local selection on body does not allowed.
- theError = "Selected shape is in the local selection. Only global selection is allowed.";
- return false;
- }
}
return true;
return false;
}
+ bool hasEdgesOrWires = false;
+ bool hasFaces = false;
+
// Collect base shapes.
ListOfShape anEdges;
for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
}
aShape = aSelection->context()->shape();
}
+ if (aShape->shapeType() == GeomAPI_Shape::FACE) {
+ // skip faces exploding
+ hasFaces = true;
+ continue;
+ }
+
for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
+ hasEdgesOrWires = true;
GeomShapePtr anEdge = anExp.current();
anEdges.push_back(anEdge);
}
}
- if(anEdges.empty()) {
+ if (hasFaces && hasEdgesOrWires) {
+ theError = "Faces and edges/wires should be selected together.";
+ return false;
+ } else if (hasEdgesOrWires && anEdges.empty()) {
theError = "Objects are not selected.";
return false;
}
}
}
- // Check that they are planar.
- std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
- if(!aPln.get()) {
- theError = "Selected object(s) should belong to only one plane.";
- return false;
- }
+ if (!anEdges.empty()) {
+ // Check that they are planar.
+ std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
+ if(!aPln.get()) {
+ theError = "Selected object(s) should belong to only one plane.";
+ return false;
+ }
- // Check that selected objects have closed contours.
- ListOfShape aFaces;
- GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(),
- aPln->direction(), anEdges, aFaces);
- if(aFaces.empty()) {
- theError = "Selected objects do not generate closed contour.";
- return false;
+ // Check that selected objects have closed contours.
+ ListOfShape aFaces;
+ GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(),
+ aPln->direction(), anEdges, aFaces);
+ if(aFaces.empty()) {
+ theError = "Selected objects do not generate closed contour.";
+ return false;
+ }
}
return true;
return true;
}
+
+
+//=================================================================================================
+bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ // Get base objects list.
+ if (theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
+ std::string aMsg =
+ "Error: BuildPlugin_ValidatorFillingSelection does not support attribute type \""
+ "%1\"\n Only \"%2\" supported.";
+ Events_InfoMessage("BuildPlugin_Validators", aMsg).
+ arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send();
+ return false;
+ }
+ AttributeSelectionListPtr aSelectionList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if (!aSelectionList.get()) {
+ theError = "Could not get selection list.";
+ return false;
+ }
+
+ FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
+
+ // Check selected shapes.
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelectionAttrInList = aSelectionList->value(anIndex);
+ if (!aSelectionAttrInList.get()) {
+ theError = "Empty attribute in list.";
+ return false;
+ }
+
+ // Check shape exists.
+ GeomShapePtr aShapeInList = aSelectionAttrInList->value();
+ if (!aShapeInList.get()) {
+ theError = "Object has no shape";
+ return false;
+ }
+
+ // Check shape type.
+ GeomAPI_Shape::ShapeType aType = aShapeInList->shapeType();
+ if (aType != GeomAPI_Shape::EDGE && aType != GeomAPI_Shape::WIRE) {
+ theError = "Incorrect objects selected";
+ return false;
+ }
+ }
+
+ return true;
+}