#include "FeaturesPlugin_Validators.h"
+#include "FeaturesPlugin_Boolean.h"
#include "FeaturesPlugin_Union.h"
#include <Events_InfoMessage.h>
ResultConstructionPtr aResultConstruction =
std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
if(aResultConstruction.get()) {
- theError = "Error: Result construction not allowed for selection.";
- return false;
+ if (anOperationType != FeaturesPlugin_Boolean::BOOL_FILL
+ || theAttribute->id() != FeaturesPlugin_Boolean::TOOL_LIST_ID()) {
+ theError = "Error: Result construction not allowed for selection.";
+ return false;
+ }
}
std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
GeomShapePtr aContextShape = aContext->shape();
return false;
}
- int aShapeType = aShape->shapeType();
- if(anOperationType == 1) {
- // Fuse operation. Allow to select edges, faces and solids.
- if(aShapeType != GeomAPI_Shape::EDGE &&
- aShapeType != GeomAPI_Shape::FACE &&
- aShapeType != GeomAPI_Shape::SOLID &&
- aShapeType != GeomAPI_Shape::COMPSOLID &&
- aShapeType != GeomAPI_Shape::COMPOUND) {
- theError = "Error: Selected shape has the wrong type.";
- return false;
- }
+ GeomAPI_Shape::ShapeType aShapeType = aShape->shapeType();
+ std::set<GeomAPI_Shape::ShapeType> anAllowedTypes;
+ if(anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE) {
+ anAllowedTypes.insert(GeomAPI_Shape::EDGE);
+ anAllowedTypes.insert(GeomAPI_Shape::FACE);
+ anAllowedTypes.insert(GeomAPI_Shape::SOLID);
+ anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
+ anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
+ } else if (anOperationType == FeaturesPlugin_Boolean::BOOL_FILL) {
+ anAllowedTypes.insert(GeomAPI_Shape::VERTEX);
+ anAllowedTypes.insert(GeomAPI_Shape::EDGE);
+ anAllowedTypes.insert(GeomAPI_Shape::WIRE);
+ anAllowedTypes.insert(GeomAPI_Shape::FACE);
+ anAllowedTypes.insert(GeomAPI_Shape::SHELL);
+ anAllowedTypes.insert(GeomAPI_Shape::SOLID);
+ anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
+ anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
} else {
- if(aShapeType != GeomAPI_Shape::SOLID &&
- aShapeType != GeomAPI_Shape::COMPSOLID &&
- aShapeType != GeomAPI_Shape::COMPOUND) {
- theError = "Error: Selected shape has the wrong type.";
- return false;
- }
+ anAllowedTypes.insert(GeomAPI_Shape::SOLID);
+ anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
+ anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
+ }
+
+ if(anAllowedTypes.find(aShapeType) == anAllowedTypes.end()
+ || (aResultConstruction.get() && aShapeType != GeomAPI_Shape::FACE)) {
+ theError = "Error: Selected shape has the wrong type.";
+ return false;
+ }
+
+ }
+
+ return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ AttributeSelectionListPtr anAttrSelectionList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if(!anAttrSelectionList.get()) {
+ theError =
+ "Error: This validator can only work with selection list attributes in \"Fillet\" feature.";
+ return false;
+ }
+
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ // Check all selected entities are sub-shapes of single solid
+ GeomShapePtr aBaseSolid;
+ for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+ if(!anAttrSelection.get()) {
+ theError = "Error: Empty attribute selection.";
+ return false;
+ }
+ ResultPtr aContext = anAttrSelection->context();
+ if(!aContext.get()) {
+ theError = "Error: Empty selection context.";
+ return false;
+ }
+
+ ResultCompSolidPtr aContextOwner = ModelAPI_Tools::compSolidOwner(aContext);
+ GeomShapePtr anOwner = aContextOwner.get() ? aContextOwner->shape() : aContext->shape();
+ if (!aBaseSolid)
+ aBaseSolid = anOwner;
+ else if (!aBaseSolid->isEqual(anOwner)) {
+ theError = "Error: Sub-shapes of different solids have been selected.";
+ return false;
}
}
Events_InfoMessage& theError) const
{
static const std::string aBaseShapeID = "base_shape";
- static const std::string aSubShapesID = "subshapes";
+ static const std::string aSubShapesID = "subshapes_to_keep";
if(theFeature->getKind() != "Remove_SubShapes") {
theError = "Error: Feature \"%1\" does not supported by this validator.";
}
GeomShapePtr aResultShape = aBaseShape->emptyCopied();
+ if (aSubShapesAttrList->size() == 0) {
+ theError = "Error: Resulting shape is not valid.";
+ return false;
+ }
+
// Copy sub-shapes from list to new shape.
for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
for(int anIndex = 0; anIndex < aBaseObjectsAttrList->size(); ++anIndex) {
bool isSameFound = false;
AttributeSelectionPtr anAttrSelectionInList = aBaseObjectsAttrList->value(anIndex);
+ ResultPtr aContext = anAttrSelectionInList->context();
+
+ ResultConstructionPtr aConstruction =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+ if(aConstruction.get()) {
+ theError = "Error: Result construction not allowed for selection.";
+ return false;
+ }
+
+ GeomShapePtr aShape = anAttrSelectionInList->value();
+ GeomShapePtr aContextShape = aContext->shape();
+ if (aShape.get() && aContextShape.get() && !aContextShape->isEqual(aShape)) {
+ theError = "Error: Local selection not allowed.";
+ return false;
+ }
+
ResultCompSolidPtr aResult =
- std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anAttrSelectionInList->context());
+ std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
if(!aResult.get()) {
continue;
}
+
if(aResult->numberOfSubs() > 0) {
theError = "Error: Whole compsolids not allowed for selection.";
return false;
}
// Get all shapes.
+ GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::COMPSOLID;
ListOfShape aBaseShapesList;
for(int anIndex = 0; anIndex < aBaseObejctsAttrList->size(); ++anIndex) {
AttributeSelectionPtr anAttrSelectionInList = aBaseObejctsAttrList->value(anIndex);
GeomShapePtr aShape = anAttrSelectionInList->value();
+ if (!aShape.get()) {
+ continue;
+ }
aBaseShapesList.push_back(aShape);
+ aType = aShape->shapeType() == GeomAPI_Shape::FACE ? GeomAPI_Shape::SHELL :
+ GeomAPI_Shape::COMPSOLID;
}
- // Make componud and find connected.
+ // Make compound and find connected.
GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);
ListOfShape aCombined, aFree;
- GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCombined, aFree);
+ GeomAlgoAPI_ShapeTools::combineShapes(
+ aCompound,
+ aType,
+ aCombined,
+ aFree);
if(aFree.size() > 0 || aCombined.size() > 1) {
theError = "Error: Not all shapes have shared topology.";