#include "FeaturesPlugin_Boolean.h"
#include "FeaturesPlugin_BooleanFuse.h"
+#include "FeaturesPlugin_BooleanCommon.h"
#include "FeaturesPlugin_BooleanSmash.h"
+#include "FeaturesPlugin_Pipe.h"
#include "FeaturesPlugin_Union.h"
#include <Events_InfoMessage.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_Feature.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_Tools.h>
}
//==================================================================================================
-bool FeaturesPlugin_ValidatorPipeLocations::isValid(
+bool FeaturesPlugin_ValidatorPipeLocations::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 \"Pipe\" feature.";
+ return false;
+ }
+ std::shared_ptr<FeaturesPlugin_Pipe> aFeature =
+ std::dynamic_pointer_cast<FeaturesPlugin_Pipe>(theAttribute->owner());
+
+ AttributeSelectionPtr aPathSelection = aFeature->selection(FeaturesPlugin_Pipe::PATH_OBJECT_ID());
+ if (!aPathSelection.get()) {
+ theError = "Error: Path not selected.";
+ return false;
+ }
+
+ GeomShapePtr aPathShape = aPathSelection->value();
+ if (!aPathShape.get()) {
+ ResultPtr aContext = aPathSelection->context();
+ if (!aContext.get()) {
+ FeaturePtr aContFeat = aPathSelection->contextFeature();
+ if (!aContFeat.get() || !aContFeat->results().size()) {
+ theError = "Error: Empty selection context.";
+ return false;
+ }
+ }
+ aPathShape = aContext->shape();
+ }
+
+ if (!aPathShape.get()) {
+ theError = "Error: Empty path shape.";
+ return false;
+ }
+
+ 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()) {
+ FeaturePtr aContFeat = anAttrSelection->contextFeature();
+ if (!aContFeat.get() || !aContFeat->results().size()) {
+ theError = "Error: Empty selection context.";
+ return false;
+ }
+ }
+ std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+ if (!aShape.get() && aContext.get()) {
+ GeomShapePtr aContextShape = aContext->shape();
+ aShape = aContextShape;
+ }
+ if (!aShape.get()) {
+ theError = "Error: Empty shape.";
+ return false;
+ }
+
+ if (!aPathShape->isSubShape(aShape)) {
+ theError = "Error: Location should be a vertex subshape from path shape.";
+ return false;
+ }
+ }
+
+ return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorPipeLocationsNumber::isValid(
const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::list<std::string>& theArguments,
Events_InfoMessage& theError) const
for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
ResultPtr aContext = aSelectionAttr->context();
- if(!aContext.get()) {
+ if(!aContext.get() && !aSelectionAttr->contextFeature().get()) {
theError = "Error: Empty context.";
return false;
}
// If shape is compound check that it contains only faces and edges.
GeomShapePtr aShape = aSelectionAttr->value();
if(!aShape.get()) {
- aShape = aContext->shape();
+ if (aContext.get()) {
+ aShape = aContext->shape();
+ } else {
+ theError = "Error: Empty context.";
+ return false;
+ }
}
if(aShape->shapeType() == GeomAPI_Shape::COMPOUND) {
AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
ResultPtr aContext = aSelectionAttr->context();
if(!aContext.get()) {
- theError = "Error: Empty context.";
- return false;
+ FeaturePtr aFeature = aSelectionAttr->contextFeature();
+ if (!aFeature.get() || aFeature->results().empty()) {
+ theError = "Error: Empty context.";
+ return false;
+ } else {
+ aContext = aFeature->firstResult();
+ }
}
ResultConstructionPtr aResultConstruction =
AttributeSelectionPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
ResultPtr aContext = anAttr->context();
- if(!aContext.get()) {
+ if(!aContext.get() && !anAttr->contextFeature().get()) {
theError = "Error: Attribute have empty context.";
return false;
}
GeomShapePtr aShape = anAttr->value();
- GeomShapePtr aContextShape = aContext->shape();
- if(!aShape.get()) {
+ GeomShapePtr aContextShape;
+ if(!aShape.get() && aContext.get()) {
+ aContextShape = aContext->shape();
aShape = aContextShape;
}
if(!aShape.get()) {
return false;
}
- ResultConstructionPtr aConstruction =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+ ResultConstructionPtr aConstruction;
+ if (!aContext.get() && anAttr->contextFeature()->results().size() == 1) {
+ aContext = anAttr->contextFeature()->firstResult();
+ }
+ if (aContext.get())
+ aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
if(aConstruction.get()) {
// Construciotn selected. Check that is is not infinite.
if(aConstruction->isInfinite()) {
return false;
}
+ GeomShapePtr aContextShape = aContext->shape();
if(aShape->isEqual(aContextShape)) {
// Whole construction selected. Check that it have faces.
if(aConstruction->facesNum() > 0) {
return false;
}
- if(!aShape->isEqual(aContextShape)) {
+ if(aContextShape.get() && !aShape->isEqual(aContextShape)) {
// Local selection on body does not allowed.
theError =
"Error: Selected shape is in the local selection. Only global selection is allowed.";
aDirShape = aSelAttr->value();
if(!aDirShape.get()) {
ResultPtr aContext = aSelAttr->context();
+ if(!aContext.get()) {
+ FeaturePtr aFeature = aSelAttr->contextFeature();
+ if (aFeature.get() && !aFeature->results().empty()) {
+ aContext = aFeature->firstResult();
+ }
+ }
+
if(aContext.get()) {
aDirShape = aContext->shape();
}
+
+ if (aDirShape.get() && aDirShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aDirShape);
+ aDirShape = anIt.current();
+ }
}
}
AttributeSelectionPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
ResultPtr aContext = anAttr->context();
- if(!aContext.get()) {
+ if(!aContext.get() && !anAttr->contextFeature().get()) {
return false;
}
GeomShapePtr aShape = anAttr->value();
- GeomShapePtr aContextShape = aContext->shape();
- if(!aShape.get()) {
+ if(!aShape.get() && aContext.get()) {
+ GeomShapePtr aContextShape = aContext->shape();
aShape = aContextShape;
}
if(!aShape.get()) {
}
ResultPtr aContext = anAttrSelection->context();
if(!aContext.get()) {
- theError = "Error: Empty selection context.";
- return false;
+ FeaturePtr aContFeat = anAttrSelection->contextFeature();
+ if (!aContFeat.get() || !aContFeat->results().size()) {
+ theError = "Error: Empty selection context.";
+ return false;
+ }
}
ResultConstructionPtr aResultConstruction =
std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
}
}
std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
- GeomShapePtr aContextShape = aContext->shape();
- if(!aShape.get()) {
+ if(!aShape.get() && aContext.get()) {
+ GeomShapePtr aContextShape = aContext->shape();
aShape = aContextShape;
}
if(!aShape.get()) {
theError = "Error: Empty shape.";
return false;
}
- if(!aShape->isEqual(aContextShape)) {
+ if (aContext.get() && !aShape->isEqual(aContext->shape())) {
theError = "Error: Local selection not allowed.";
return false;
}
}
ResultPtr aContext = anAttrSelection->context();
if(!aContext.get()) {
- theError = "Error: Empty selection context.";
- return false;
+ FeaturePtr aContFeat = anAttrSelection->contextFeature();
+ if (!aContFeat.get() || !aContFeat->results().size() ||
+ aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
+ theError = "Error: Empty selection context.";
+ return false;
+ }
+ if (aContFeat->results().size() == 1)
+ aContext = aContFeat->firstResult();
+ else {
+ theError = "Error: Too many shapes selected.";
+ return false;
+ }
}
- ResultCompSolidPtr aContextOwner = ModelAPI_Tools::compSolidOwner(aContext);
+ ResultBodyPtr aContextOwner = ModelAPI_Tools::bodyOwner(aContext);
GeomShapePtr anOwner = aContextOwner.get() ? aContextOwner->shape() : aContext->shape();
+ if (!anOwner) {
+ theError = "Error: wrong feature is selected.";
+ return false;
+ }
+
if (anOwner->shapeType() != GeomAPI_Shape::SOLID &&
anOwner->shapeType() != GeomAPI_Shape::COMPSOLID) {
- theError = "Error: Not all selected shapes are sub-shapes of solids";
+ theError = "Error: Not all selected shapes are sub-shapes of solids.";
return false;
}
return false;
}
- ResultCompSolidPtr aResultCompsolid =
- std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
- if(aResultCompsolid.get()) {
+ ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
+ if(aResultBody.get()) {
continue;
}
+ FeaturePtr aResultFeature = aSelectAttr->contextFeature();
+ if(aResultFeature.get()) {
+ bool aOkRes = false;
+ std::list<ResultPtr>::const_iterator aFRes = aResultFeature->results().cbegin();
+ for(; aFRes != aResultFeature->results().cend() && !aOkRes; aFRes++) {
+ ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aFRes);
+ if (aBody.get() && !aBody->isDisabled())
+ aOkRes = true;
+ }
+ if (aOkRes)
+ continue;
+ }
theError = "Error: Only body shapes and construction planes are allowed for selection.";
return false;
return false;
}
+ std::list<GeomShapePtr> aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape);
for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
bool isSameFound = false;
AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
- for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) {
- if(anIt.current()->isEqual(aShapeToAdd)) {
+ for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt)
+ {
+ if ((*anIt)->isEqual(aShapeToAdd)) {
isSameFound = true;
break;
}
}
- if(!isSameFound) {
+ if (!isSameFound) {
theError = "Error: Only sub-shapes of selected shape is allowed for selection.";
return false;
}
return false;
}
- ResultCompSolidPtr aResult =
- std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
+ ResultBodyPtr aResult =
+ std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
if(!aResult.get()) {
continue;
}
std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
bool isAllInSameCompSolid = true;
- ResultCompSolidPtr aCompSolid;
+ ResultBodyPtr aCompSolid;
AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
if (anAttrSelList)
{
AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
ResultPtr aContext = anAttr->context();
- ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+ ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
if (aResCompSolidPtr.get())
{
if (aCompSolid.get())
{
AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
ResultPtr aContext = anAttr->context();
- ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+ ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
if (aResCompSolidPtr.get())
{
if (aCompSolid.get())
for (int anIndex = 0; anIndex < anOtherAttrSelectionList->size(); ++anIndex) {
AttributeSelectionPtr anAttrSelection = anOtherAttrSelectionList->value(anIndex);
+
+ if (anAttrSelection->contextFeature().get()) {
+ theError = "Error: Features not allowed for selection.";
+ return false;
+ }
+
ResultPtr aContext = anAttrSelection->context();
std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
GeomShapePtr aContextShape = aContext->shape();
if (aShape->isSolid() || aShape->isCompSolid()) {
aSelectedShapesType = GeomAPI_Shape::SOLID;
- ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+ ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
if (aResCompSolidPtr.get()) {
GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
aSelectedCompSolidsInOtherList.bind(aCompSolidShape, aCompSolidShape);
theError = "Error: Empty attribute selection.";
return false;
}
- ResultPtr aContext = anAttrSelection->context();
- if (!aContext.get()) {
- theError = "Error: Empty selection context.";
+
+ if (anAttrSelection->contextFeature().get()) {
+ theError = "Error: Features not allowed for selection.";
return false;
}
+
+ ResultPtr aContext = anAttrSelection->context();
+ if(!aContext.get()) {
+ FeaturePtr aContFeat = anAttrSelection->contextFeature();
+ if (!aContFeat.get() || !aContFeat->results().size() ||
+ aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
+ theError = "Error: Empty selection context.";
+ return false;
+ }
+ }
ResultConstructionPtr aResultConstruction =
std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
if (aResultConstruction.get()) {
return false;
}
- ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+ ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
if (aResCompSolidPtr.get()) {
GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape();
if (aSelectedCompSolidsInOtherList.isBound(aCompSolidShape)) {
return false;
}
ResultPtr aContext = anAttrSelection->context();
- if (!aContext.get()) {
- theError = "Error: empty selection context.";
- return false;
+ if(!aContext.get()) {
+ FeaturePtr aContFeat = anAttrSelection->contextFeature();
+ if (!aContFeat.get() || !aContFeat->results().size() ||
+ aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
+ theError = "Error: Empty selection context.";
+ return false;
+ }
}
- FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
+ FeaturePtr aFeature = anAttrSelection->contextFeature().get() ?
+ anAttrSelection->contextFeature() : ModelAPI_Feature::feature(aContext);
if (!aFeature.get()) {
theError = "Error: empty feature.";
return false;
return false;
}
std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
- GeomShapePtr aContextShape = aContext->shape();
if (!aShape.get()) {
+ GeomShapePtr aContextShape = aContext->shape();
aShape = aContextShape;
}
if (!aShape.get()) {
theError = "Error: empty shape.";
return false;
}
- if (!aShape->isEqual(aContextShape)) {
+ if (aContext.get() && !aShape->isEqual(aContext->shape())) {
theError = "Error: Local selection not allowed.";
return false;
}
return false;
}
ResultPtr aContext = anAttrSelection->context();
- if (!aContext.get()) {
- theError = "Error: Empty selection context.";
- return false;
+ if(!aContext.get()) {
+ FeaturePtr aContFeat = anAttrSelection->contextFeature();
+ if (!aContFeat.get() || !aContFeat->results().size() ||
+ aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) {
+ theError = "Error: Empty selection context.";
+ return false;
+ }
}
ResultConstructionPtr aResultConstruction =
std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
return false;
}
std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
- GeomShapePtr aContextShape = aContext->shape();
if (!aShape.get()) {
+ GeomShapePtr aContextShape = aContext->shape();
aShape = aContextShape;
}
if (!aShape.get()) {
theError = "Error: Empty shape.";
return false;
}
- if (!aShape->isEqual(aContextShape)) {
+ if (aContext.get() && !aShape->isEqual(aContext->shape())) {
theError = "Error: Local selection not allowed.";
return false;
}
std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
bool isAllInSameCompSolid = true;
- ResultCompSolidPtr aCompSolid;
+ ResultBodyPtr aCompSolid;
AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
if (anAttrSelList) {
for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
ResultPtr aContext = anAttr->context();
- ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+ ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
if (aResCompSolidPtr.get()) {
if (aCompSolid.get()) {
isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
for (int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
ResultPtr aContext = anAttr->context();
- ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+ ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
if (aResCompSolidPtr.get()) {
if (aCompSolid.get()) {
isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
}
return false;
-}
\ No newline at end of file
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorBooleanCommonSelection::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 \"Boolean\" feature.";
+ return false;
+ }
+
+ 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() && !anAttrSelection->contextFeature().get()) {
+ theError = "Error: Empty selection context.";
+ return false;
+ }
+ ResultConstructionPtr aResultConstruction =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+ if (aResultConstruction.get()) {
+ if (theAttribute->id() != FeaturesPlugin_BooleanCommon::TOOL_LIST_ID()) {
+ theError = "Error: Result construction not allowed for selection.";
+ return false;
+ }
+ }
+ std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+ GeomShapePtr aContextShape;
+ if (aContext.get()) {
+ aContextShape = aContext->shape();
+ }
+ if (!aShape.get()) {
+ aShape = aContextShape;
+ }
+ if (!aShape.get()) {
+ theError = "Error: Empty shape.";
+ return false;
+ }
+ if (aContextShape.get() && !aShape->isEqual(aContextShape)) {
+ theError = "Error: Local selection not allowed.";
+ return false;
+ }
+
+ if (aResultConstruction.get() && aShape->shapeType() != GeomAPI_Shape::FACE) {
+ theError = "Error: Result construction should be plane.";
+ return false;
+ }
+ }
+
+ return true;
+}
+
+//=================================================================================================
+bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ if (theArguments.size() != 2) {
+ theError = "Wrong number of arguments (expected 2).";
+ return false;
+ }
+
+ std::shared_ptr<FeaturesPlugin_BooleanCommon> aFeature =
+ std::dynamic_pointer_cast<FeaturesPlugin_BooleanCommon>(theFeature);
+
+ int anObjectsNb = 0, aToolsNb = 0;
+
+ std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+
+ bool isAllInSameCompSolid = true;
+ ResultBodyPtr aCompSolid;
+
+ AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
+ if (anAttrSelList) {
+ anObjectsNb = anAttrSelList->size();
+ }
+
+ bool isSimpleMode = aFeature->string(FeaturesPlugin_BooleanCommon::CREATION_METHOD())->value()
+ == FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE();
+
+ if (!isSimpleMode) {
+ anAttrSelList = theFeature->selectionList(*anIt);
+ if (anAttrSelList) {
+ aToolsNb = anAttrSelList->size();
+ }
+ }
+
+ if ((isSimpleMode && anObjectsNb < 2)
+ || (!isSimpleMode && (anObjectsNb == 0 || aToolsNb == 0))) {
+ theError = "Not enough arguments for Fuse operation.";
+ return false;
+ }
+ return true;
+}
+
+//=================================================================================================
+bool FeaturesPlugin_ValidatorBooleanCommonArguments::isNotObligatory(
+ std::string theFeature,
+ std::string theAttribute)
+{
+ return false;
+}