X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FBuildPlugin%2FBuildPlugin_Validators.cpp;h=195672ddbbabb3d913c500a8aa4b654e37942d92;hb=602e2d79b412f79f66f880dd27442d67a4bcd180;hp=7dbc38e9d76f1a90a384b76631f7bb4378a08d49;hpb=97917d3698f5a2f7fc9596e7c755ff8f6751e373;p=modules%2Fshaper.git diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index 7dbc38e9d..195672ddb 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -18,8 +18,12 @@ // #include "BuildPlugin_Validators.h" +#include "BuildPlugin_Solid.h" +#include "BuildPlugin_Face.h" +#include "BuildPlugin_Wire.h" #include +#include #include #include @@ -39,6 +43,10 @@ #include #include +#include + +#include + #include //================================================================================================= @@ -99,20 +107,9 @@ bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute std::dynamic_pointer_cast(aContext); if(aConstruction.get()) { if(aConstruction->isInfinite()) { - theError = "Inifinte objects not acceptable."; + theError = "Infinite objects not acceptable."; return false; } - - std::shared_ptr anEdges = - std::dynamic_pointer_cast(aContextShape); - if(anEdges.get()) { - if(aShape->isEqual(aContextShape)) { - // It is whole sketch. - return false; - } - - continue; - } } } @@ -125,12 +122,6 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptrselectionList(theArguments.front()); if(!aSelectionList.get()) { theError = "Empty attribute \"%1\"."; @@ -138,25 +129,87 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptrgetKind() == BuildPlugin_Wire::ID()) { + /// remove objects of sub-type if ojects of correct type is in List, in some cases : + /// Wire builder: wires and edges selected + std::set aRemove; + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if (aShape.get()) { + GeomAPI_Shape::ShapeType aType = aShape->shapeType(); + if (aType == GeomAPI_Shape::WIRE) { + // check for edges + GeomAPI_ShapeExplorer anEdgeExp(aShape, GeomAPI_Shape::EDGE); + for (; anEdgeExp.more(); anEdgeExp.next()) { + GeomShapePtr aEdge = anEdgeExp.current(); + for (int i = 0; i < aSelectionList->size(); ++i) { + AttributeSelectionPtr aSel = aSelectionList->value(i); + GeomShapePtr aShp = aSel->value(); + if (aShp.get()) { + if (aShp->shapeType() == GeomAPI_Shape::EDGE) { + if (aShp->isEqual(aEdge) || aShp->isSameGeometry(aEdge)) + aRemove.insert(i); + } + } + else { + aRemove.insert(anIndex); + } + } + } + } + } + } + if (aRemove.size() > 0) + aSelectionList->remove(aRemove); + } + GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::shapeTypeByStr(theArguments.back()); // Collect base shapes. ListOfShape aListOfShapes; for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); GeomShapePtr aShape = aSelection->value(); - if(!aShape.get()) { - if (aSelection->context().get()) - aShape = aSelection->context()->shape(); - } - if (aShape.get()) + ResultPtr aContext = aSelection->context(); + if (!aShape.get() && aContext.get()) + aShape = aContext->shape(); + + bool isProper = aShape.get() && + (aShape->shapeType() == GeomAPI_Shape::EDGE || aShape->shapeType() == aShapeType); + + if (isProper) aListOfShapes.push_back(aShape); + else { + // is it a sketch? + FeaturePtr aFeature = aSelection->contextFeature(); + if (!aFeature.get()) { + GeomShapePtr aValue = aSelection->value(); + // whole sketch is allowed only + if (aContext.get() && !aValue.get()) { + aFeature = ModelAPI_Feature::feature(aContext); + } + } + + if (!aFeature.get()) { + theError = "Error: Incorrect selection."; + return false; + } + + if (aFeature->getKind() != SketchPlugin_Sketch::ID()) { + theError = "Error: %1 shape is not allowed for selection."; + theError.arg(aFeature->getKind()); + return false; + } + } } - // Create wire. - GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes); - if(!aWire.get()) { - theError = "Result wire empty. Probably it has disconnected edges or non-manifold."; - return false; + if (aShapeType == GeomAPI_Shape::WIRE) { + // Create wire. + GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes); + if (!aWire.get() && !aListOfShapes.empty()) { + theError = "Result wire empty. Probably it has disconnected edges or non-manifold."; + return false; + } } return true; @@ -181,6 +234,60 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptrgetKind() == BuildPlugin_Face::ID()) { + /// remove objects of sub-type if ojects of correct type is in List, in some cases : + /// - Face builder: edges, faces and wires selected + /// --> remove edges and wires + std::set aRemove; + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if (aShape.get()) { + GeomAPI_Shape::ShapeType aType = aShape->shapeType(); + if (aType == GeomAPI_Shape::FACE) { + // Check for wires + GeomAPI_ShapeExplorer anWireExp(aShape, GeomAPI_Shape::WIRE); + for (; anWireExp.more(); anWireExp.next()) { + GeomShapePtr aWire = anWireExp.current(); + for (int i = 0; i < aSelectionList->size(); ++i) { + AttributeSelectionPtr aSel = aSelectionList->value(i); + GeomShapePtr aShp = aSel->value(); + if (aShp.get()) { + if (aShp->shapeType() == GeomAPI_Shape::WIRE) { + if (aShp->isEqual(aWire) || aShp->isSameGeometry(aWire)) + aRemove.insert(i); + } + } + else { + aRemove.insert(anIndex); + } + } + } + + // check for edges + GeomAPI_ShapeExplorer anEdgeExp(aShape, GeomAPI_Shape::EDGE); + for (; anEdgeExp.more(); anEdgeExp.next()) { + GeomShapePtr aEdge = anEdgeExp.current(); + for (int i = 0; i < aSelectionList->size(); ++i) { + AttributeSelectionPtr aSel = aSelectionList->value(i); + GeomShapePtr aShp = aSel->value(); + if (aShp.get()) { + if (aShp->shapeType() == GeomAPI_Shape::EDGE) { + if (aShp->isEqual(aEdge) || aShp->isSameGeometry(aEdge)) + aRemove.insert(i); + } + } + else { + aRemove.insert(anIndex); + } + } + } + } + } + } + if (aRemove.size() > 0) + aSelectionList->remove(aRemove); + } bool hasEdgesOrWires = false; bool hasFaces = false; @@ -196,7 +303,11 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptrcontext()->shape(); } - if (aShape->shapeType() == GeomAPI_Shape::FACE) { + ResultConstructionPtr aSketchRes = + std::dynamic_pointer_cast(aSelection->context()); + + if (aShape->shapeType() == GeomAPI_Shape::FACE || + (!aSelection->value() && aSketchRes && aSketchRes->facesNum() > 0)) { // skip faces exploding hasFaces = true; continue; @@ -226,7 +337,7 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptrlocation(), aPln->xDirection(), - aPln->direction(), anEdges, aFaces); + GeomAlgoAPI_SketchBuilder aBuilder(aPln, anEdges); + const ListOfShape& aFaces = aBuilder.faces(); if(aFaces.empty()) { theError = "Selected objects do not generate closed contour."; return false; @@ -274,6 +384,45 @@ bool BuildPlugin_ValidatorBaseForSolids::isValid( return false; } + if (theFeature->getKind() == BuildPlugin_Solid::ID()) { + /// remove objects of sub-type if ojects of correct type is in List, in some cases : + /// Solid builder: faces and shapes shells or solids seleted + /// --> remove faces + + std::set aRemove; + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if (aShape.get()) { + GeomAPI_Shape::ShapeType aType = aShape->shapeType(); + if ((aType == GeomAPI_Shape::SHAPE) || + (aType == GeomAPI_Shape::SOLID) || + (aType == GeomAPI_Shape::SHELL)) { + + GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::FACE); + for (; anExp.more(); anExp.next()) { + GeomShapePtr aFace = anExp.current(); + for (int i = 0; i < aSelectionList->size(); ++i) { + AttributeSelectionPtr aSel = aSelectionList->value(i); + GeomShapePtr aShp = aSel->value(); + if (aShp.get()) { + if (aShp->shapeType() == GeomAPI_Shape::FACE) { + if (aShp->isEqual(aFace)) + aRemove.insert(i); + } + } + else { + aRemove.insert(anIndex); + } + } + } + } + } + } + if (aRemove.size() > 0) + aSelectionList->remove(aRemove); + } + // Collect base shapes. ListOfShape anOriginalShapes; for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { @@ -344,20 +493,24 @@ bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAtt Events_InfoMessage& theError) const { if(theArguments.size() != 1) { + // LCOV_EXCL_START std::string aMsg = "Error: BuildPlugin_ValidatorSubShapesSelection should be used only with " "1 parameter(Sketch feature id)."; Events_InfoMessage("BuildPlugin_Validators", aMsg).send(); return false; + // LCOV_EXCL_STOP } // Get base objects list. if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) { + // LCOV_EXCL_START std::string aMsg = "Error: BuildPlugin_ValidatorSubShapesSelection does not support attribute type \"" "%1\"\n Only \"%2\" supported."; Events_InfoMessage("BuildPlugin_Validators", aMsg). arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send(); return false; + // LCOV_EXCL_STOP } AttributeSelectionListPtr aSelectionList = std::dynamic_pointer_cast(theAttribute); @@ -440,17 +593,19 @@ bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAtt //================================================================================================= bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - Events_InfoMessage& theError) const + const std::list& /*theArguments*/, + Events_InfoMessage& theError) const { // Get base objects list. if (theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) { + // LCOV_EXCL_START std::string aMsg = "Error: BuildPlugin_ValidatorFillingSelection does not support attribute type \"" "%1\"\n Only \"%2\" supported."; Events_InfoMessage("BuildPlugin_Validators", aMsg). arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send(); return false; + // LCOV_EXCL_STOP } AttributeSelectionListPtr aSelectionList = std::dynamic_pointer_cast(theAttribute); @@ -459,7 +614,7 @@ bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttri return false; } - FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner()); + //FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner()); // Check selected shapes. for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { @@ -486,3 +641,88 @@ bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttri return true; } + + +//================================================================================================= +bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribute, + const std::list& /*theArguments*/, + Events_InfoMessage& theError) const +{ + if (!theAttribute.get()) { + theError = "Error: empty selection."; + return false; + } + + AttributeSelectionListPtr aSelectionList = + std::dynamic_pointer_cast(theAttribute); + if (!aSelectionList.get()) { + theError = "Could not get selection list."; + return false; + } + + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelectionAttr = aSelectionList->value(anIndex); + if (!aSelectionAttr.get()) { + theError = "Empty attribute in list."; + return false; + } + + // Vertex? + bool isVertex = false; + GeomShapePtr aShape = aSelectionAttr->value(); + ResultPtr aContext = aSelectionAttr->context(); + if (!aShape.get() && aContext.get()) + aShape = aContext->shape(); + if (aShape.get()) + isVertex = (aShape->shapeType() == GeomAPI_Shape::VERTEX); + + if (!isVertex) { + // Sketch? + FeaturePtr aFeature = aSelectionAttr->contextFeature(); + if (!aFeature.get()) { + GeomShapePtr aValue = aSelectionAttr->value(); + // whole sketch is allowed only + if (aContext.get() && !aValue.get()) { + aFeature = ModelAPI_Feature::feature(aContext); + } + } + + if (!aFeature.get()) { + theError = "Error: Incorrect selection."; + return false; + } + + if (aFeature->getKind() != SketchPlugin_Sketch::ID()) { + theError = "Error: %1 shape is not allowed for selection."; + theError.arg(aFeature->getKind()); + return false; + } + } + } + + return true; +} + +//================================================================================================= +bool BuildPlugin_ValidatorExpressionInterpolation::isValid(const AttributePtr& theAttribute, + const std::list& /*theArguments*/, + Events_InfoMessage& theError) const +{ + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + + AttributeStringPtr aStrAttr = + std::dynamic_pointer_cast(theAttribute); + if (!aStrAttr->isInitialized()) { + theError = "Attribute \"%1\" is not initialized."; + theError.arg(aStrAttr->id()); + return false; + } + bool isEmptyExpr = aStrAttr->value().empty(); + if (isEmptyExpr) { + theError = "Expression is empty."; + return false; + } + + theError = aFeature->string(BuildPlugin_Interpolation::EXPRESSION_ERROR_ID())->value(); + return theError.empty(); +}