#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
if (aContext.get())
aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
if(aConstruction.get()) {
- // Construciotn selected. Check that is is not infinite.
+ // Construction selected. Check that it is not infinite.
if(aConstruction->isInfinite()) {
theError = "Error: Infinite constructions is not allowed as base.";
return false;
return true;
}
}
-
return false;
}
if(aContext.get()) {
aDirShape = aContext->shape();
}
+
+ if (aDirShape.get() && aDirShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aDirShape);
+ aDirShape = anIt.current();
+ }
}
}
- if(!aDirShape.get()) {
+ if(!aDirShape.get() || aDirShape->isNull() ||
+ aDirShape->shapeType() != GeomAPI_Shape::EDGE) {
// Check that dir can be empty.
if(!isShapesCanBeEmpty(aCheckAttribute, theError)) {
theError = "Error: Base objects list contains vertex or edge, so attribute \"%1\" "
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.";
bool isSameFound = false;
AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
- for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) {
+ for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt)
+ {
if ((*anIt)->isEqual(aShapeToAdd)) {
isSameFound = true;
break;
return false;
}
- int anObjectsNb = 0, aToolsNb = 0;
- //int anOperationType = 0;
+ int anObjectsToolsNb[2] = { 0, 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();
- for (int anIndex = 0; anIndex < anObjectsNb; ++anIndex)
+ for (int* anArgNbIt = anObjectsToolsNb; anIt != aLast; ++anIt, ++anArgNbIt) {
+ AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
+ if (anAttrSelList)
{
- AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
- ResultPtr aContext = anAttr->context();
- ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
- if (aResCompSolidPtr.get())
- {
- if (aCompSolid.get())
- {
- isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
- }
- else
- {
- aCompSolid = aResCompSolidPtr;
- }
- }
- else
- {
- isAllInSameCompSolid = false;
- break;
- }
- }
- }
- anIt++;
-
-
- anAttrSelList = theFeature->selectionList(*anIt);
- if (anAttrSelList)
- {
- aToolsNb = anAttrSelList->size();
- if (isAllInSameCompSolid)
- {
- for (int anIndex = 0; anIndex < aToolsNb; ++anIndex)
- {
- AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
- ResultPtr aContext = anAttr->context();
- ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
- if (aResCompSolidPtr.get())
+ *anArgNbIt = anAttrSelList->size();
+ if (isAllInSameCompSolid) {
+ for (int anIndex = 0; anIndex < *anArgNbIt; ++anIndex)
{
- if (aCompSolid.get())
+ AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
+ ResultPtr aContext = anAttr->context();
+ ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
+ if (aResCompSolidPtr.get())
{
- isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
+ if (aCompSolid.get())
+ {
+ isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
+ }
+ else
+ {
+ aCompSolid = aResCompSolidPtr;
+ }
}
else
{
- aCompSolid = aResCompSolidPtr;
+ isAllInSameCompSolid = false;
+ break;
}
}
- else
- {
- isAllInSameCompSolid = false;
- break;
- }
}
}
}
- anIt++;
std::shared_ptr<FeaturesPlugin_Boolean> aFeature =
std::dynamic_pointer_cast<FeaturesPlugin_Boolean>(theFeature);
if (anOperationType == FeaturesPlugin_Boolean::BOOL_FUSE)
{
// Fuse operation
- if (anObjectsNb + aToolsNb < 2)
+ if (anObjectsToolsNb[0] + anObjectsToolsNb[1] < 2)
{
theError = "Not enough arguments for Fuse operation.";
return false;
}
else
{
- if (anObjectsNb < 1)
+ if (anObjectsToolsNb[0] < 1) // check number of objects
{
theError = "Objects not selected.";
return false;
}
- if (aToolsNb < 1)
+ if (anObjectsToolsNb[1] < 1) // check number of tools
{
theError = "Tools not selected.";
return false;
}
std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
GeomShapePtr aContextShape;
- if (!aShape.get() && aContext.get()) {
+ if (aContext.get()) {
aContextShape = aContext->shape();
+ }
+ if (!aShape.get()) {
aShape = aContextShape;
}
if (!aShape.get()) {