-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File: FeaturesPlugin_Validators.cpp
-// Created: 22 March 2016
-// Author: Dmitry Bobylev
-
-#include "FeaturesPlugin_Validators.h"
-
-#include <ModelAPI_Attribute.h>
-#include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_AttributeString.h>
-#include <ModelAPI_AttributeReference.h>
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_ResultConstruction.h>
-
-#include <Events_Error.h>
-
-#include <GeomValidators_BodyShapes.h>
-#include <GeomValidators_FeatureKind.h>
-#include <GeomValidators_ShapeType.h>
-
-#include <GeomAPI_DataMapOfShapeShape.h>
-#include <GeomAPI_PlanarEdges.h>
-#include <GeomAPI_ShapeExplorer.h>
-#include <GeomAPI_ShapeIterator.h>
-
-#include <GeomAlgoAPI_ShapeBuilder.h>
-#include <GeomAlgoAPI_ShapeTools.h>
-#include <GeomAlgoAPI_WireBuilder.h>
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::list<std::string>& theArguments,
- std::string& theError) const
-{
- static const std::string aCreationMethodID = "creation_method";
- static const std::string aBaseObjectsID = "base_objects";
- static const std::string aLocationsID = "locations_objects";
-
- if(theFeature->getKind() != "Pipe") {
- theError = "Error: Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
- return false;
- }
-
- AttributeStringPtr aCreationMethodAttr = theFeature->string(aCreationMethodID);
- if(!aCreationMethodAttr.get()) {
- theError = "Error: Could not get \"" + aCreationMethodID + "\" attribute.";
- return false;
- }
-
- if(aCreationMethodAttr->value() != "locations") {
- return true;
- }
-
- AttributeSelectionListPtr aBaseObjectsSelectionList = theFeature->selectionList(aBaseObjectsID);
- if(!aBaseObjectsSelectionList.get()) {
- theError = "Error: Could not get \"" + aBaseObjectsID + "\" attribute.";
- return false;
- }
-
- AttributeSelectionListPtr aLocationsSelectionList = theFeature->selectionList(aLocationsID);
- if(!aLocationsSelectionList.get()) {
- theError = "Error: Could not get \"" + aBaseObjectsID + "\" attribute.";
- return false;
- }
-
- if(aLocationsSelectionList->size() > 0 && aLocationsSelectionList->size() != aBaseObjectsSelectionList->size()) {
- theError = "Error: Number of locations should be the same as base objects.";
- return false;
- }
-
- return true;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeature, std::string theAttribute)
-{
- return false;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- std::string& theError) const
-{
- if(theArguments.empty()) {
- theError = "Error: Validator parameters is empty.";
- return false;
- }
-
- // Checking attribute.
- if(!isValidAttribute(theAttribute, theArguments, theError)) {
- if(theError.empty()) {
- theError = "Error: Attribute contains unacceptable shape.";
- }
- return false;
- }
-
- std::set<ResultConstructionPtr> aSelectedSketches;
- std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
- GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects;
- std::string anAttributeType = theAttribute->attributeType();
- if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
- AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
- AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
- ResultConstructionPtr aContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSelectionAttr->context());
- if(!aContext.get()) {
- // It is not a result construction, continue.
- continue;
- }
-
- GeomShapePtr aShape = aSelectionAttr->value();
- GeomShapePtr aContextShape = aContext->shape();
- if(!aShape.get()) {
- // Whole sketch selected.
- if(aSelectedSketchesFromObjects.find(aContext) != aSelectedSketchesFromObjects.cend()) {
- theError = "Error: Object from this sketch is already selected. Sketch is not allowed for selection.";
- return false;
- }
-
- aSelectedSketches.insert(aContext);
- } else {
- // Object from sketch selected.
- if(aSelectedSketches.find(aContext) != aSelectedSketches.cend()) {
- theError = "Error: Whole sketch with this object is already selected. Don't allow to select this object.";
- return false;
- }
-
- for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
- GeomShapePtr aWire = anExp.current();
- if(aWire->orientation() != GeomAPI_Shape::FORWARD) {
- theError = "Error: Wire with wrong orientation selected.";
- return false;
- }
-
- if(aSelectedWiresFromObjects.isBound(aWire)) {
- theError = "Error: Objects with such wire already selected. Don't allow to select this object.";
- return false;
- }
-
- aSelectedWiresFromObjects.bind(aWire, aWire);
- aSelectedSketchesFromObjects.insert(aContext);
- }
- }
- }
- }
-
- return true;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- std::string& theError) const
-{
- if(!theAttribute.get()) {
- theError = "Error: Empty attribute.";
- return false;
- }
-
- std::string anAttributeType = theAttribute->attributeType();
- if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
- AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
- // If at least one attribute is invalid, the result is false.
- if(!isValidAttribute(aListAttr->value(anIndex), theArguments, theError)) {
- return false;
- }
- }
- } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
- // Getting context.
- AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
- ResultPtr aContext = anAttr->context();
- if(!aContext.get()) {
- theError = "Error: Attribute have empty context.";
- return false;
- }
-
- GeomShapePtr aShape = anAttr->value();
- GeomShapePtr aContextShape = aContext->shape();
- if(!aShape.get()) {
- aShape = aContextShape;
- }
- if(!aShape.get()) {
- theError = "Error: Empty shape selected";
- return false;
- }
-
- ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
- if(aConstruction.get()) {
- // Construciotn selected. Check that is is not infinite.
- if(aConstruction->isInfinite()) {
- theError = "Error: Infinite constructions is not allowed as base.";
- return false;
- }
-
- if(aShape->isEqual(aContextShape)) {
- // Whole construction selected. Check that it have faces.
- if(aConstruction->facesNum() > 0) {
- return true;
- }
- } else {
- // Shape on construction selected. Check that it is a face or wire.
- if(aShape->shapeType() == GeomAPI_Shape::WIRE || aShape->shapeType() == GeomAPI_Shape::FACE) {
- return true;
- }
- }
-
- return false;
- }
-
- if(!aShape->isEqual(aContextShape)) {
- // Local selection on body does not allowed.
- theError = "Error: Selected shape is in the local selection. Only global selection is allowed.";
- return false;
- }
-
- // Check that object is a shape with allowed type.
- GeomValidators_ShapeType aShapeTypeValidator;
- if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {
- theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or wires on sketch, "
- "whole sketch(if it has at least one face), and whole objects with shape types: ";
- std::list<std::string>::const_iterator anIt = theArguments.cbegin();
- theError += *anIt;
- for(++anIt; anIt != theArguments.cend(); ++anIt) {
- theError += ", " + *anIt;
- }
- return false;
- }
-
- } else {
- theError = "Error: Attribute \"" + anAttributeType + "\" does not supported by this validator.";
- return false;
- }
-
- return true;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- std::string& theError) const
-{
- if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
- theError = "Error: The attribute with the " + theAttribute->attributeType() + " type is not processed";
- return false;
- }
- if (theArguments.size() != 2) {
- theError = "Error: Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
- return false;
- }
- // first argument is for the base attribute, second - for skipping feature kind
- std::list<std::string>::const_iterator anIt = theArguments.begin();
- std::string aBaseAttributeId = *anIt;
- FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
- AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);
- if (!aBaseAttribute.get()) {
- theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
- return false;
- }
- if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,
- // this validator is not necessary anymore
- return true;
-
- anIt++;
- std::string aFeatureAttributeKind = *anIt;
- GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind();
- // check whether the selection is on the sketch
- std::list<std::string> anArguments;
- anArguments.push_back(aFeatureAttributeKind);
-
- bool aFeatureKind = aValidator->isValid(theAttribute, theArguments, theError);
- bool aPlanarFace = false;
- // check if selection has Face selected
- GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType();
- anArguments.clear();
- anArguments.push_back("face");
- aPlanarFace = aShapeType->isValid(theAttribute, anArguments, theError);
-
- bool aValid = !aFeatureKind && aPlanarFace;
- return aValid;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorCanBeEmpty::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::list<std::string>& theArguments,
- std::string& theError) const
-{
- if(theArguments.size() != 2) {
- theError = "Error: Validator should be used with 2 parameters for extrusion.";
- return false;
- }
-
- std::list<std::string>::const_iterator anArgsIt = theArguments.begin(), aLast = theArguments.end();
-
- AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt);
- ++anArgsIt;
-
- if(isShapesCanBeEmpty(aCheckAttribute, theError)) {
- return true;
- }
-
- AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);
- if(!aSelAttr.get()) {
- theError = "Error: Could not get selection attribute \"" + *anArgsIt + "\".";
- return false;
- }
-
- GeomShapePtr aShape = aSelAttr->value();
- if(!aShape.get()) {
- ResultPtr aContext = aSelAttr->context();
- if(!aContext.get()) {
- theError = "Error: Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
- + "\" can not be used with default value. Select direction for extrusion.";
- return false;
- }
-
- aShape = aContext->shape();
- }
-
- if(!aShape.get()) {
- theError = "Error: Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
- + "\" can not be used with default value. Select direction for extrusion.";
- return false;
- }
-
- return true;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorCanBeEmpty::isNotObligatory(std::string theFeature, std::string theAttribute)
-{
- return false;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorCanBeEmpty::isShapesCanBeEmpty(const AttributePtr& theAttribute,
- std::string& theError) const
-{
- if(!theAttribute.get()) {
- return true;
- }
-
- std::string anAttributeType = theAttribute->attributeType();
- if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
- AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
- // If at least one attribute is invalid, the result is false.
- if(!isShapesCanBeEmpty(aListAttr->value(anIndex), theError)) {
- return false;
- }
- }
- } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
- // Getting context.
- AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
- ResultPtr aContext = anAttr->context();
- if(!aContext.get()) {
- return false;
- }
-
- GeomShapePtr aShape = anAttr->value();
- GeomShapePtr aContextShape = aContext->shape();
- if(!aShape.get()) {
- aShape = aContextShape;
- }
- if(!aShape.get()) {
- return false;
- }
-
- if(aShape->shapeType() == GeomAPI_Shape::VERTEX ||
- aShape->shapeType() == GeomAPI_Shape::EDGE ||
- !aShape->isPlanar()) {
- return false;
- }
- } else {
- return false;
- }
-
- return true;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- std::string& 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;
- }
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
- int anOperationType = aFeature->integer("bool_type")->value();
-
- 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;
- }
- ResultConstructionPtr aResultConstruction =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
- if(aResultConstruction.get()) {
- theError = "Error: Result construction not allowed for selection.";
- return false;
- }
- std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
- if(!aShape.get()) {
- aShape = aContext->shape();
- }
- if(!aShape.get()) {
- theError = "Error: Empty 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;
- }
- } else {
- if(aShapeType != GeomAPI_Shape::SOLID &&
- aShapeType != GeomAPI_Shape::COMPSOLID &&
- aShapeType != GeomAPI_Shape::COMPOUND) {
- theError = "Error: Selected shape has the wrong type.";
- return false;
- }
- }
- }
-
- return true;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- std::string& theError) const
-{
- AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- if(!anAttrSelectionList.get()) {
- theError = "Error: This validator can only work with selection list in \"Partition\" feature.";
- return false;
- }
-
- for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
- AttributeSelectionPtr aSelectAttr = anAttrSelectionList->value(anIndex);
-
- //GeomValidators_BodyShapes aBodyValidator;
- //if(aBodyValidator.isValid(aSelectAttr, theArguments, theError)) {
- // continue;
- //}
-
- GeomValidators_FeatureKind aFeatureKindValidator;
- if(aFeatureKindValidator.isValid(aSelectAttr, theArguments, theError)) {
- continue;
- }
-
- ResultPtr aContext = aSelectAttr->context();
- ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
- if(aResultConstruction.get()) {
-
- }
-
- theError = "Error: Only body shapes and construction planes are allowed for selection.";
- return false;
- }
-
- return true;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- std::string& theError) const
-{
- AttributeSelectionListPtr aSubShapesAttrList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- if(!aSubShapesAttrList.get()) {
- theError = "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
- return false;
- }
-
- static const std::string aBaseShapeID = "base_shape";
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
- AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);
-
- if(!aShapeAttrSelection.get()) {
- theError = "Error: Could not get \"" + aBaseShapeID + "\" attribute.";
- return false;
- }
-
- GeomShapePtr aBaseShape = aShapeAttrSelection->value();
- ResultPtr aContext = aShapeAttrSelection->context();
- if(!aContext.get()) {
- theError = "Error: Empty context.";
- return false;
- }
- if(!aBaseShape.get()) {
- aBaseShape = aContext->shape();
- }
- if(!aBaseShape.get()) {
- theError = "Error: Empty base shape.";
- return false;
- }
-
- 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)) {
- isSameFound = true;
- break;
- }
- }
- if(!isSameFound) {
- theError = "Error: Only sub-shapes of selected shape is allowed for selection.";
- return false;
- }
- }
-
- return true;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::list<std::string>& theArguments,
- std::string& theError) const
-{
- static const std::string aBaseShapeID = "base_shape";
- static const std::string aSubShapesID = "subshapes";
-
- if(theFeature->getKind() != "Remove_SubShapes") {
- theError = "Error: Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
- return false;
- }
-
- AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);
- if(!aShapeAttrSelection.get()) {
- theError = "Error: Could not get \"" + aBaseShapeID + "\" attribute.";
- return false;
- }
-
- AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);
- if(!aSubShapesAttrList.get()) {
- theError = "Error: Could not get \"" + aSubShapesID + "\" attribute.";
- return false;
- }
-
- // Copy base shape.
- GeomShapePtr aBaseShape = aShapeAttrSelection->value();
- if(!aBaseShape.get()) {
- return false;
- }
- GeomShapePtr aResultShape = aBaseShape->emptyCopied();
-
- // Copy sub-shapes from list to new shape.
- for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
- AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
- GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
- GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd);
- }
-
- // Check new shape.
- if(!GeomAlgoAPI_ShapeTools::isShapeValid(aResultShape)) {
- theError = "Error: Resulting shape is not valid.";
- return false;
- }
-
- return true;
-}
-
-//==================================================================================================
-bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isNotObligatory(std::string theFeature,
- std::string theAttribute)
-{
- return false;
-}
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->\r
+\r
+// File: FeaturesPlugin_Validators.cpp\r
+// Created: 22 March 2016\r
+// Author: Dmitry Bobylev\r
+\r
+#include "FeaturesPlugin_Validators.h"\r
+\r
+#include "FeaturesPlugin_Union.h"\r
+\r
+#include <Events_InfoMessage.h>\r
+\r
+#include <ModelAPI_Attribute.h>\r
+#include <ModelAPI_AttributeInteger.h>\r
+#include <ModelAPI_AttributeSelectionList.h>\r
+#include <ModelAPI_AttributeString.h>\r
+#include <ModelAPI_AttributeReference.h>\r
+#include <ModelAPI_AttributeRefList.h>\r
+#include <ModelAPI_Feature.h>\r
+#include <ModelAPI_ResultCompSolid.h>\r
+#include <ModelAPI_ResultConstruction.h>\r
+#include <ModelAPI_Tools.h>\r
+\r
+#include <GeomValidators_BodyShapes.h>\r
+#include <GeomValidators_FeatureKind.h>\r
+#include <GeomValidators_ShapeType.h>\r
+\r
+#include <GeomAPI_DataMapOfShapeShape.h>\r
+#include <GeomAPI_Lin.h>\r
+#include <GeomAPI_PlanarEdges.h>\r
+#include <GeomAPI_ShapeExplorer.h>\r
+#include <GeomAPI_ShapeIterator.h>\r
+\r
+#include <GeomAlgoAPI_CompoundBuilder.h>\r
+#include <GeomAlgoAPI_ShapeBuilder.h>\r
+#include <GeomAlgoAPI_ShapeTools.h>\r
+#include <GeomAlgoAPI_WireBuilder.h>\r
+\r
+#define _USE_MATH_DEFINES\r
+#include <math.h>\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ AttributeSelectionPtr aPathAttrSelection = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);\r
+ if(!aPathAttrSelection.get()) {\r
+ theError = "Error: This validator can only work with path selector in \"Pipe\" feature.";\r
+ return false;\r
+ }\r
+\r
+ GeomShapePtr aPathShape = aPathAttrSelection->value();\r
+ ResultPtr aContext = aPathAttrSelection->context();\r
+ if(!aContext.get()) {\r
+ theError = "Error: Empty context.";\r
+ return false;\r
+ }\r
+ GeomShapePtr aContextShape = aContext->shape();\r
+ if(aPathShape.get() && aPathShape->shapeType() == GeomAPI_Shape::WIRE && !aPathShape->isEqual(aContextShape)) {\r
+ theError = "Error: Local selection of wires not allowed.";\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ static const std::string aCreationMethodID = "creation_method";\r
+ static const std::string aBaseObjectsID = "base_objects";\r
+ static const std::string aLocationsID = "locations_objects";\r
+\r
+ if(theFeature->getKind() != "Pipe") {\r
+ theError = "Error: Feature \"%1\" does not supported by this validator.";\r
+ theError.arg(theFeature->getKind());\r
+ return false;\r
+ }\r
+\r
+ AttributeStringPtr aCreationMethodAttr = theFeature->string(aCreationMethodID);\r
+ if(!aCreationMethodAttr.get()) {\r
+ theError = "Error: Could not get \"%1\" attribute.";\r
+ theError.arg(aCreationMethodID);\r
+ return false;\r
+ }\r
+\r
+ if(aCreationMethodAttr->value() != "locations") {\r
+ return true;\r
+ }\r
+\r
+ AttributeSelectionListPtr aBaseObjectsSelectionList = theFeature->selectionList(aBaseObjectsID);\r
+ if(!aBaseObjectsSelectionList.get()) {\r
+ theError = "Error: Could not get \"%1\" attribute.";\r
+ theError.arg(aBaseObjectsID);\r
+ return false;\r
+ }\r
+\r
+ AttributeSelectionListPtr aLocationsSelectionList = theFeature->selectionList(aLocationsID);\r
+ if(!aLocationsSelectionList.get()) {\r
+ theError = "Error: Could not get \"%1\" attribute.";\r
+ theError.arg(aBaseObjectsID);\r
+ return false;\r
+ }\r
+\r
+ if(aLocationsSelectionList->size() > 0 && aLocationsSelectionList->size() != aBaseObjectsSelectionList->size()) {\r
+ theError = "Error: Number of locations should be the same as base objects.";\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeature, std::string theAttribute)\r
+{\r
+ return false;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ if(theArguments.empty()) {\r
+ theError = "Error: Validator parameters is empty.";\r
+ return false;\r
+ }\r
+\r
+ // Checking attribute.\r
+ if(!isValidAttribute(theAttribute, theArguments, theError)) {\r
+ if(theError.empty()) {\r
+ theError = "Error: Attribute contains unacceptable shape.";\r
+ }\r
+ return false;\r
+ }\r
+\r
+ std::set<ResultConstructionPtr> aSelectedSketches;\r
+ std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;\r
+ GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects;\r
+ std::string anAttributeType = theAttribute->attributeType();\r
+ if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {\r
+ AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);\r
+ for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {\r
+ AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);\r
+ ResultPtr aContext = aSelectionAttr->context();\r
+ if(!aContext.get()) {\r
+ theError = "Error: Empty context.";\r
+ return false;\r
+ }\r
+\r
+ ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);\r
+ if(!aResultConstruction.get()) {\r
+ // It is not a result construction. If shape is compound check that it contains only faces and edges.\r
+ GeomShapePtr aShape = aSelectionAttr->value();\r
+ if(!aShape.get()) {\r
+ aShape = aContext->shape();\r
+ }\r
+\r
+ if(aShape->shapeType() == GeomAPI_Shape::COMPOUND) {\r
+ for(GeomAPI_ShapeIterator anIt(aShape); anIt.more(); anIt.next()) {\r
+ GeomShapePtr aSubShape = anIt.current();\r
+ if(aSubShape->shapeType() != GeomAPI_Shape::EDGE\r
+ && aSubShape->shapeType() != GeomAPI_Shape::FACE) {\r
+ theError = "Error: Compound should contain only faces and edges.";\r
+ return false;\r
+ }\r
+ }\r
+ }\r
+\r
+ continue;\r
+ }\r
+\r
+ GeomShapePtr aShape = aSelectionAttr->value();\r
+ GeomShapePtr aContextShape = aResultConstruction->shape();\r
+ if(!aShape.get()) {\r
+ // Whole sketch selected.\r
+ if(aSelectedSketchesFromObjects.find(aResultConstruction) != aSelectedSketchesFromObjects.cend()) {\r
+ theError = "Error: Object from this sketch is already selected. Sketch is not allowed for selection.";\r
+ return false;\r
+ }\r
+\r
+ aSelectedSketches.insert(aResultConstruction);\r
+ } else {\r
+ // Object from sketch selected.\r
+ if(aSelectedSketches.find(aResultConstruction) != aSelectedSketches.cend()) {\r
+ theError = "Error: Whole sketch with this object is already selected. Don't allow to select this object.";\r
+ return false;\r
+ }\r
+\r
+ for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {\r
+ GeomShapePtr aWire = anExp.current();\r
+ if(aWire->orientation() != GeomAPI_Shape::FORWARD) {\r
+ theError = "Error: Wire with wrong orientation selected.";\r
+ return false;\r
+ }\r
+\r
+ if(aSelectedWiresFromObjects.isBound(aWire)) {\r
+ theError = "Error: Objects with such wire already selected. Don't allow to select this object.";\r
+ return false;\r
+ }\r
+\r
+ aSelectedWiresFromObjects.bind(aWire, aWire);\r
+ aSelectedSketchesFromObjects.insert(aResultConstruction);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ if(!theAttribute.get()) {\r
+ theError = "Error: Empty attribute.";\r
+ return false;\r
+ }\r
+\r
+ std::string anAttributeType = theAttribute->attributeType();\r
+ if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {\r
+ AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);\r
+ for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {\r
+ // If at least one attribute is invalid, the result is false.\r
+ if(!isValidAttribute(aListAttr->value(anIndex), theArguments, theError)) {\r
+ return false;\r
+ }\r
+ }\r
+ } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {\r
+ // Getting context.\r
+ AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);\r
+ ResultPtr aContext = anAttr->context();\r
+ if(!aContext.get()) {\r
+ theError = "Error: Attribute have empty context.";\r
+ return false;\r
+ }\r
+\r
+ GeomShapePtr aShape = anAttr->value();\r
+ GeomShapePtr aContextShape = aContext->shape();\r
+ if(!aShape.get()) {\r
+ aShape = aContextShape;\r
+ }\r
+ if(!aShape.get()) {\r
+ theError = "Error: Empty shape selected";\r
+ return false;\r
+ }\r
+\r
+ ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);\r
+ if(aConstruction.get()) {\r
+ // Construciotn selected. Check that is is not infinite.\r
+ if(aConstruction->isInfinite()) {\r
+ theError = "Error: Infinite constructions is not allowed as base.";\r
+ return false;\r
+ }\r
+\r
+ if(aShape->isEqual(aContextShape)) {\r
+ // Whole construction selected. Check that it have faces.\r
+ if(aConstruction->facesNum() > 0) {\r
+ return true;\r
+ }\r
+ } else {\r
+ // Shape on construction selected. Check that it is a face or wire.\r
+ if(aShape->shapeType() == GeomAPI_Shape::WIRE || aShape->shapeType() == GeomAPI_Shape::FACE) {\r
+ return true;\r
+ }\r
+ }\r
+\r
+ return false;\r
+ }\r
+\r
+ if(!aShape->isEqual(aContextShape)) {\r
+ // Local selection on body does not allowed.\r
+ theError = "Error: Selected shape is in the local selection. Only global selection is allowed.";\r
+ return false;\r
+ }\r
+\r
+ // Check that object is a shape with allowed type.\r
+ GeomValidators_ShapeType aShapeTypeValidator;\r
+ if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {\r
+ theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or wires on sketch, whole sketch(if it has at least one face), and whole objects with shape types: %1";\r
+ std::string anArgumentString;\r
+ for(auto anIt = theArguments.cbegin(); anIt != theArguments.cend(); ++anIt) {\r
+ if (!anArgumentString.empty())\r
+ anArgumentString += ", ";\r
+ anArgumentString += *anIt;\r
+ }\r
+ theError.arg(anArgumentString);\r
+ return false;\r
+ }\r
+\r
+ } else {\r
+ theError = "Error: Attribute \"%1\" does not supported by this validator.";\r
+ theError.arg(anAttributeType);\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {\r
+ theError = "Error: The attribute with the %1 type is not processed";\r
+ theError.arg(theAttribute->attributeType());\r
+ return false;\r
+ }\r
+ if (theArguments.size() != 2) {\r
+ theError = "Error: Wrong parameters in XML definition for %1 type";\r
+ theError.arg(theAttribute->attributeType());\r
+ return false;\r
+ }\r
+ // first argument is for the base attribute, second - for skipping feature kind\r
+ std::list<std::string>::const_iterator anIt = theArguments.begin();\r
+ std::string aBaseAttributeId = *anIt;\r
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());\r
+ AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);\r
+ if (!aBaseAttribute.get()) {\r
+ theError = "Wrong parameters in XML definition for %1 type";\r
+ theError.arg(theAttribute->attributeType());\r
+ return false;\r
+ }\r
+ if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,\r
+ // this validator is not necessary anymore\r
+ return true;\r
+\r
+ anIt++;\r
+ std::string aFeatureAttributeKind = *anIt;\r
+ GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind();\r
+ // check whether the selection is on the sketch\r
+ std::list<std::string> anArguments;\r
+ anArguments.push_back(aFeatureAttributeKind);\r
+\r
+ bool aFeatureKind = aValidator->isValid(theAttribute, theArguments, theError);\r
+ bool aPlanarFace = false;\r
+ // check if selection has Face selected\r
+ GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType();\r
+ anArguments.clear();\r
+ anArguments.push_back("face");\r
+ aPlanarFace = aShapeType->isValid(theAttribute, anArguments, theError);\r
+\r
+ bool aValid = !aFeatureKind && aPlanarFace;\r
+ return aValid;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorExtrusionDir::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ if(theArguments.size() != 2) {\r
+ theError = "Error: Validator should be used with 2 parameters for extrusion.";\r
+ return false;\r
+ }\r
+\r
+ std::list<std::string>::const_iterator anArgsIt = theArguments.begin(), aLast = theArguments.end();\r
+\r
+ AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt);\r
+ ++anArgsIt;\r
+\r
+ GeomShapePtr aDirShape;\r
+ AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);\r
+ if(aSelAttr.get()) {\r
+ aDirShape = aSelAttr->value();\r
+ if(!aDirShape.get()) {\r
+ ResultPtr aContext = aSelAttr->context();\r
+ if(aContext.get()) {\r
+ aDirShape = aContext->shape();\r
+ }\r
+ }\r
+ }\r
+\r
+ if(!aDirShape.get()) {\r
+ // Check that dir can be empty.\r
+ if(!isShapesCanBeEmpty(aCheckAttribute, theError)) {\r
+ theError = "Error: Base objects list contains vertex or edge, so attribute \"%1\" can not be used with default value. Select direction for extrusion.";\r
+ theError.arg(*anArgsIt);\r
+ return false;\r
+ } else {\r
+ return true;\r
+ }\r
+ }\r
+\r
+ std::shared_ptr<GeomAPI_Edge> aDirEdge(new GeomAPI_Edge(aDirShape));\r
+\r
+ // If faces selected check that direction not parallel with them.\r
+ AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aCheckAttribute);\r
+ for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {\r
+ AttributeSelectionPtr anAttr = aListAttr->value(anIndex);\r
+ GeomShapePtr aShapeInList = anAttr->value();\r
+ if(!aShapeInList.get()) {\r
+ aShapeInList = anAttr->context()->shape();\r
+ }\r
+ bool isParallel = true;\r
+ if(aShapeInList->shapeType() == GeomAPI_Shape::FACE || aShapeInList->shapeType() == GeomAPI_Shape::SHELL) {\r
+ for(GeomAPI_ShapeExplorer anExp(aShapeInList, GeomAPI_Shape::FACE); anExp.more(); anExp.next()) {\r
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(anExp.current()));\r
+ isParallel = GeomAlgoAPI_ShapeTools::isParallel(aDirEdge, aFace);\r
+ if(isParallel) {\r
+ break;\r
+ }\r
+ }\r
+ } else if(aShapeInList->shapeType() == GeomAPI_Shape::COMPOUND) {\r
+ std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapeInList);\r
+ if(aPlanarEdges.get()) {\r
+ std::shared_ptr<GeomAPI_Dir> aSketchDir = aPlanarEdges->norm();\r
+ if(aDirEdge->isLine()) {\r
+ std::shared_ptr<GeomAPI_Dir> aDir = aDirEdge->line()->direction();\r
+ isParallel = abs(aSketchDir->angle(aDir) - M_PI / 2.0) < 10e-7;\r
+ } else {\r
+ isParallel = false;\r
+ }\r
+ } else {\r
+ isParallel = false;\r
+ }\r
+ } else {\r
+ isParallel = false;\r
+ }\r
+ if(isParallel) {\r
+ theError = "Error: Direction is parallel to one of the selected face or face on selected shell.";\r
+ return false;\r
+ }\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorExtrusionDir::isNotObligatory(std::string theFeature, std::string theAttribute)\r
+{\r
+ return false;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ if(!theAttribute.get()) {\r
+ return true;\r
+ }\r
+\r
+ std::string anAttributeType = theAttribute->attributeType();\r
+ if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {\r
+ AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);\r
+ for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {\r
+ // If at least one attribute is invalid, the result is false.\r
+ if(!isShapesCanBeEmpty(aListAttr->value(anIndex), theError)) {\r
+ return false;\r
+ }\r
+ }\r
+ } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {\r
+ // Getting context.\r
+ AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);\r
+ ResultPtr aContext = anAttr->context();\r
+ if(!aContext.get()) {\r
+ return false;\r
+ }\r
+\r
+ GeomShapePtr aShape = anAttr->value();\r
+ GeomShapePtr aContextShape = aContext->shape();\r
+ if(!aShape.get()) {\r
+ aShape = aContextShape;\r
+ }\r
+ if(!aShape.get()) {\r
+ return false;\r
+ }\r
+\r
+ if(aShape->shapeType() == GeomAPI_Shape::VERTEX ||\r
+ aShape->shapeType() == GeomAPI_Shape::EDGE ||\r
+ !aShape->isPlanar()) {\r
+ return false;\r
+ }\r
+ } else {\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAttribute,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);\r
+ if(!anAttrSelectionList.get()) {\r
+ theError = "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";\r
+ return false;\r
+ }\r
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());\r
+ int anOperationType = aFeature->integer("bool_type")->value();\r
+\r
+ for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {\r
+ AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);\r
+ if(!anAttrSelection.get()) {\r
+ theError = "Error: Empty attribute selection.";\r
+ return false;\r
+ }\r
+ ResultPtr aContext = anAttrSelection->context();\r
+ if(!aContext.get()) {\r
+ theError = "Error: Empty selection context.";\r
+ return false;\r
+ }\r
+ ResultConstructionPtr aResultConstruction =\r
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);\r
+ if(aResultConstruction.get()) {\r
+ theError = "Error: Result construction not allowed for selection.";\r
+ return false;\r
+ }\r
+ std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();\r
+ GeomShapePtr aContextShape = aContext->shape();\r
+ if(!aShape.get()) {\r
+ aShape = aContextShape;\r
+ }\r
+ if(!aShape.get()) {\r
+ theError = "Error: Empty shape.";\r
+ return false;\r
+ }\r
+ if(!aShape->isEqual(aContextShape)) {\r
+ theError = "Error: Local selection not allowed.";\r
+ return false;\r
+ }\r
+\r
+ int aShapeType = aShape->shapeType();\r
+ if(anOperationType == 1) {\r
+ // Fuse operation. Allow to select edges, faces and solids.\r
+ if(aShapeType != GeomAPI_Shape::EDGE &&\r
+ aShapeType != GeomAPI_Shape::FACE &&\r
+ aShapeType != GeomAPI_Shape::SOLID &&\r
+ aShapeType != GeomAPI_Shape::COMPSOLID &&\r
+ aShapeType != GeomAPI_Shape::COMPOUND) {\r
+ theError = "Error: Selected shape has the wrong type.";\r
+ return false;\r
+ }\r
+ } else {\r
+ if(aShapeType != GeomAPI_Shape::SOLID &&\r
+ aShapeType != GeomAPI_Shape::COMPSOLID &&\r
+ aShapeType != GeomAPI_Shape::COMPOUND) {\r
+ theError = "Error: Selected shape has the wrong type.";\r
+ return false;\r
+ }\r
+ }\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& theAttribute,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);\r
+ if(!anAttrSelectionList.get()) {\r
+ theError = "Error: This validator can only work with selection list in \"Partition\" feature.";\r
+ return false;\r
+ }\r
+\r
+ for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {\r
+ AttributeSelectionPtr aSelectAttr = anAttrSelectionList->value(anIndex);\r
+\r
+ //GeomValidators_BodyShapes aBodyValidator;\r
+ //if(aBodyValidator.isValid(aSelectAttr, theArguments, theError)) {\r
+ // continue;\r
+ //}\r
+\r
+ GeomValidators_FeatureKind aFeatureKindValidator;\r
+ if(aFeatureKindValidator.isValid(aSelectAttr, theArguments, theError)) {\r
+ continue;\r
+ }\r
+\r
+ ResultPtr aContext = aSelectAttr->context();\r
+ ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);\r
+ if(aResultConstruction.get()) {\r
+ theError = "Error: Only body shapes and construction planes are allowed for selection.";\r
+ return false;\r
+ }\r
+\r
+ ResultCompSolidPtr aResultCompsolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);\r
+ if(aResultCompsolid.get()) {\r
+ continue;\r
+ }\r
+\r
+ theError = "Error: Only body shapes and construction planes are allowed for selection.";\r
+ return false;\r
+ }\r
+\r
+ theError = "";\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePtr& theAttribute,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ AttributeSelectionListPtr aSubShapesAttrList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);\r
+ if(!aSubShapesAttrList.get()) {\r
+ theError = "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";\r
+ return false;\r
+ }\r
+\r
+ static const std::string aBaseShapeID = "base_shape";\r
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());\r
+ AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);\r
+\r
+ if(!aShapeAttrSelection.get()) {\r
+ theError = "Error: Could not get \"%1\" attribute.";\r
+ theError.arg(aBaseShapeID);\r
+ return false;\r
+ }\r
+\r
+ GeomShapePtr aBaseShape = aShapeAttrSelection->value();\r
+ ResultPtr aContext = aShapeAttrSelection->context();\r
+ if(!aContext.get()) {\r
+ theError = "Error: Empty context.";\r
+ return false;\r
+ }\r
+ if(!aBaseShape.get()) {\r
+ aBaseShape = aContext->shape();\r
+ }\r
+ if(!aBaseShape.get()) {\r
+ theError = "Error: Empty base shape.";\r
+ return false;\r
+ }\r
+\r
+ for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {\r
+ bool isSameFound = false;\r
+ AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);\r
+ GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();\r
+ for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) {\r
+ if(anIt.current()->isEqual(aShapeToAdd)) {\r
+ isSameFound = true;\r
+ break;\r
+ }\r
+ }\r
+ if(!isSameFound) {\r
+ theError = "Error: Only sub-shapes of selected shape is allowed for selection.";\r
+ return false;\r
+ }\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ static const std::string aBaseShapeID = "base_shape";\r
+ static const std::string aSubShapesID = "subshapes";\r
+\r
+ if(theFeature->getKind() != "Remove_SubShapes") {\r
+ theError = "Error: Feature \"%1\" does not supported by this validator.";\r
+ theError.arg(theFeature->getKind());\r
+ return false;\r
+ }\r
+\r
+ AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);\r
+ if(!aShapeAttrSelection.get()) {\r
+ theError = "Error: Could not get \"%1\" attribute.";\r
+ theError.arg(aBaseShapeID);\r
+ return false;\r
+ }\r
+\r
+ AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);\r
+ if(!aSubShapesAttrList.get()) {\r
+ theError = "Error: Could not get \"%1\" attribute.";\r
+ theError.arg(aSubShapesID);\r
+ return false;\r
+ }\r
+\r
+ // Copy base shape.\r
+ GeomShapePtr aBaseShape = aShapeAttrSelection->value();\r
+ if(!aBaseShape.get()) {\r
+ theError = "Error: Base shape is empty.";\r
+ return false;\r
+ }\r
+ GeomShapePtr aResultShape = aBaseShape->emptyCopied();\r
+\r
+ // Copy sub-shapes from list to new shape.\r
+ for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {\r
+ AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);\r
+ GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();\r
+ GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd);\r
+ }\r
+\r
+ // Check new shape.\r
+ if(!GeomAlgoAPI_ShapeTools::isShapeValid(aResultShape)) {\r
+ theError = "Error: Resulting shape is not valid.";\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isNotObligatory(std::string theFeature,\r
+ std::string theAttribute)\r
+{\r
+ return false;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ AttributeSelectionListPtr aBaseObjectsAttrList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);\r
+ if(!aBaseObjectsAttrList.get()) {\r
+ theError = "Error: This validator can only work with selection list in \"%1\" feature.";\r
+ theError.arg(FeaturesPlugin_Union::ID());\r
+ return false;\r
+ }\r
+\r
+ for(int anIndex = 0; anIndex < aBaseObjectsAttrList->size(); ++anIndex) {\r
+ bool isSameFound = false;\r
+ AttributeSelectionPtr anAttrSelectionInList = aBaseObjectsAttrList->value(anIndex);\r
+ ResultCompSolidPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anAttrSelectionInList->context());\r
+ if(!aResult.get()) {\r
+ continue;\r
+ }\r
+ if(aResult->numberOfSubs() > 0) {\r
+ theError = "Error: Whole compsolids not allowed for selection.";\r
+ return false;\r
+ }\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorUnionArguments::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ // Check feature kind.\r
+ if(theFeature->getKind() != FeaturesPlugin_Union::ID()) {\r
+ theError = "Error: This validator supports only \"%1\" feature.";\r
+ theError.arg(FeaturesPlugin_Union::ID());\r
+ return false;\r
+ }\r
+\r
+ // Get base objects attribute list.\r
+ AttributeSelectionListPtr aBaseObejctsAttrList = theFeature->selectionList(FeaturesPlugin_Union::BASE_OBJECTS_ID());\r
+ if(!aBaseObejctsAttrList.get()) {\r
+ theError = "Error: Could not get \"%1\" attribute.";\r
+ theError.arg(FeaturesPlugin_Union::BASE_OBJECTS_ID());\r
+ return false;\r
+ }\r
+\r
+ // Get all shapes.\r
+ ListOfShape aBaseShapesList;\r
+ for(int anIndex = 0; anIndex < aBaseObejctsAttrList->size(); ++anIndex) {\r
+ AttributeSelectionPtr anAttrSelectionInList = aBaseObejctsAttrList->value(anIndex);\r
+ GeomShapePtr aShape = anAttrSelectionInList->value();\r
+ aBaseShapesList.push_back(aShape);\r
+ }\r
+\r
+ // Make componud and find connected.\r
+ GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList);\r
+ ListOfShape aCombined, aFree;\r
+ GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCombined, aFree);\r
+\r
+ if(aFree.size() > 0 || aCombined.size() > 1) {\r
+ theError = "Error: Not all shapes have shared topology.";\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//==================================================================================================\r
+bool FeaturesPlugin_ValidatorUnionArguments::isNotObligatory(std::string theFeature,\r
+ std::string theAttribute)\r
+{\r
+ return false;\r
+}\r
+\r
+bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAttribute,\r
+ const std::list<std::string>& theArguments,\r
+ Events_InfoMessage& theError) const\r
+{\r
+ if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {\r
+ theError = "Error: The attribute with the %1 type is not processed";\r
+ theError.arg(theAttribute->attributeType());\r
+ return false;\r
+ }\r
+\r
+ AttributeReferencePtr aRefAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeReference>\r
+ (theAttribute);\r
+ ObjectPtr aRefObject = aRefAttribute->value();\r
+ if (!aRefObject.get()) {\r
+ theError = "Error: Empty feature.";\r
+ return false;\r
+ }\r
+\r
+ FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aRefObject);\r
+ if (!aRefFeature.get()) {\r
+ theError = "Error: Empty feature.";\r
+ return false;\r
+ }\r
+ std::list<std::shared_ptr<ModelAPI_Result> > aResults;\r
+ ModelAPI_Tools::getConcealedResults(aRefFeature, aResults);\r
+\r
+ int aConcealedResults = aResults.size();\r
+ if (!aConcealedResults && !theArguments.empty()) {\r
+ // find if these results are touched by the feature in another attribute\r
+ std::list<std::string>::const_iterator anIt = theArguments.begin();\r
+ std::string aRecoveredList = *anIt;\r
+ if (!aRecoveredList.empty()) {\r
+ std::shared_ptr<ModelAPI_AttributeRefList> aParameterList =\r
+ theAttribute->owner()->data()->reflist(aRecoveredList);\r
+ if (aParameterList.get())\r
+ aConcealedResults = aParameterList->size();\r
+ }\r
+ }\r
+\r
+ if (aConcealedResults == 0)\r
+ theError = "Error: No concealed results.";\r
+\r
+ return theError.empty();\r
+}\r