#include "FeaturesPlugin_BooleanFuse.h"
#include "FeaturesPlugin_BooleanCommon.h"
#include "FeaturesPlugin_BooleanSmash.h"
+#include "FeaturesPlugin_Pipe.h"
#include "FeaturesPlugin_Union.h"
#include <Events_InfoMessage.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()) {
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.";
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;
}
ResultPtr aContext = anAttrSelection->context();
- if (!aContext.get()) {
+ if (!aContext.get() && !anAttrSelection->contextFeature().get()) {
theError = "Error: Empty selection context.";
return false;
}
}
}
std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
- GeomShapePtr aContextShape = aContext->shape();
+ GeomShapePtr aContextShape;
+ if (aContext.get()) {
+ aContextShape = aContext->shape();
+ }
if (!aShape.get()) {
aShape = aContextShape;
}
theError = "Error: Empty shape.";
return false;
}
- if (!aShape->isEqual(aContextShape)) {
+ if (aContextShape.get() && !aShape->isEqual(aContextShape)) {
theError = "Error: Local selection not allowed.";
return false;
}
theError = "Not enough arguments for Fuse operation.";
return false;
}
+ return true;
}
//=================================================================================================