X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FBuildPlugin%2FBuildPlugin_Validators.cpp;h=ac454e620fd03348cf9162e682171fb8320e2fda;hb=8f43b985d2f7170b8dfa06abd3edc7d6cb0c2e1f;hp=244ddb6e4f7ae9d0ed8ee89500e2c8e8b6c2b8a5;hpb=7074394f8f08413d885f63be01df6bd5007b868c;p=modules%2Fshaper.git diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index 244ddb6e4..ac454e620 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 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 @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "BuildPlugin_Validators.h" @@ -26,6 +25,7 @@ #include #include #include +#include #include #include @@ -33,10 +33,14 @@ #include #include #include +#include +#include #include #include +#include + #include //================================================================================================= @@ -97,26 +101,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; - } - } - - if(!aShape->isEqual(aContextShape)) { - // Local selection on body does not allowed. - theError = "Selected shape is in the local selection. Only global selection is allowed."; - return false; } } @@ -129,12 +116,6 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptrselectionList(theArguments.front()); if(!aSelectionList.get()) { theError = "Empty attribute \"%1\"."; @@ -142,37 +123,58 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptrsize(); ++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; } -//================================================================================================= -bool BuildPlugin_ValidatorBaseForWire::isNotObligatory(std::string theFeature, - std::string theAttribute) -{ - return false; -} - //================================================================================================= bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr& theFeature, const std::list& theArguments, @@ -192,6 +194,9 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptrsize(); ++anIndex) { @@ -204,13 +209,27 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptrcontext()->shape(); } + 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; + } + for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { + hasEdgesOrWires = true; GeomShapePtr anEdge = anExp.current(); anEdges.push_back(anEdge); } } - if(anEdges.empty()) { + if (hasFaces && hasEdgesOrWires) { + theError = "Faces and edges/wires should be selected together."; + return false; + } else if (hasEdgesOrWires && anEdges.empty()) { theError = "Objects are not selected."; return false; } @@ -224,7 +243,7 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges); - if(!aPln.get()) { - theError = "Selected object(s) should belong to only one plane."; - return false; - } + if (!anEdges.empty()) { + // Check that they are planar. + std::shared_ptr aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges); + if(!aPln.get()) { + theError = "Selected object(s) should belong to only one plane."; + return false; + } - // Check that selected objects have closed contours. - ListOfShape aFaces; - GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(), - aPln->direction(), anEdges, aFaces); - if(aFaces.empty()) { - theError = "Selected objects do not generate closed contour."; - return false; + // Check that selected objects have closed contours. + GeomAlgoAPI_SketchBuilder aBuilder(aPln, anEdges); + const ListOfShape& aFaces = aBuilder.faces(); + if(aFaces.empty()) { + theError = "Selected objects do not generate closed contour."; + return false; + } } return true; } //================================================================================================= -bool BuildPlugin_ValidatorBaseForFace::isNotObligatory(std::string theFeature, - std::string theAttribute) +bool BuildPlugin_ValidatorBaseForSolids::isValid( + const std::shared_ptr& theFeature, const std::list& theArguments, + Events_InfoMessage& theError) const { - return false; + // Get base objects list. + AttributeSelectionListPtr aSelectionList = theFeature->selectionList(theArguments.front()); + if (!aSelectionList.get()) { + theError = "Could not get selection list."; + return false; + } + if (aSelectionList->size() == 0) { + theError = "Empty selection list."; + return false; + } + + // Collect base shapes. + ListOfShape anOriginalShapes; + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + if (!aSelection->context().get()) { + theError = "Invalid selection."; + return false; + } + GeomShapePtr aShape = aSelection->value(); + if (!aShape.get()) + aShape = aSelection->context()->shape(); + anOriginalShapes.push_back(aShape); + } + + std::shared_ptr anAlgorithm( + new GeomAlgoAPI_MakeVolume(anOriginalShapes, false)); + + std::string anErr; + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(anAlgorithm, "MakeVolume", anErr)) { + theError = anErr; + return false; + } + + // set of allowed types of results + std::set aResultType; + std::string aType = theArguments.back(); + if (aType == "solid") + aResultType.insert(GeomAPI_Shape::SOLID); + else if (aType == "compsolid") { + aResultType.insert(GeomAPI_Shape::COMPSOLID); + aResultType.insert(GeomAPI_Shape::SOLID); + } + + GeomShapePtr aCompound = anAlgorithm->shape(); + if (aCompound->shapeType() == GeomAPI_Shape::COMPOUND) { + GeomAPI_ShapeIterator anIt(aCompound); + GeomShapePtr aFoundSub; + for (; anIt.more() && !aFoundSub; anIt.next()) { + aFoundSub = anIt.current(); + if (aResultType.count(aFoundSub->shapeType()) == 0) { + theError = "Unable to build a solid"; + return false; + } + } + if (anIt.more() || !aFoundSub.get()) { + theError = "Unable to build a solid"; + return false; + } + } else if (aResultType.count(aCompound->shapeType()) == 0) { + theError = "Unable to build a solid"; + return false; + } + // check the internal faces presence + for(GeomAPI_ShapeExplorer aFaces(aCompound, GeomAPI_Shape::FACE); aFaces.more(); aFaces.next()) { + if (aFaces.current()->orientation() == GeomAPI_Shape::INTERNAL) { + theError = "Internal faces are not allowed in the resulting solid"; + return false; + } + } + + return true; } + //================================================================================================= bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAttribute, const std::list& theArguments, 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); @@ -359,3 +456,116 @@ bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAtt return true; } + + +//================================================================================================= +bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttribute, + 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); + if (!aSelectionList.get()) { + theError = "Could not get selection list."; + return false; + } + + //FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner()); + + // Check selected shapes. + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelectionAttrInList = aSelectionList->value(anIndex); + if (!aSelectionAttrInList.get()) { + theError = "Empty attribute in list."; + return false; + } + + // Check shape exists. + GeomShapePtr aShapeInList = aSelectionAttrInList->value(); + if (!aShapeInList.get()) { + theError = "Object has no shape"; + return false; + } + + // Check shape type. + GeomAPI_Shape::ShapeType aType = aShapeInList->shapeType(); + if (aType != GeomAPI_Shape::EDGE && aType != GeomAPI_Shape::WIRE) { + theError = "Incorrect objects selected"; + return false; + } + } + + 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; +}