X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Validators.cpp;h=ee82a62f5c8c415cd3a897a4818c44d102358822;hb=bf663b5a63ae8d55e6d19ef29235cb9cda040c3d;hp=8d785e658827d2d621b0d78407242db548749450;hpb=c66ffb67c688d6a40a765957538b635a94a35ecf;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 8d785e658..ee82a62f5 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 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 "FeaturesPlugin_Validators.h" @@ -68,8 +67,10 @@ bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute, AttributeSelectionPtr aPathAttrSelection = std::dynamic_pointer_cast(theAttribute); if(!aPathAttrSelection.get()) { +// LCOV_EXCL_START theError = "Error: This validator can only work with path selector in \"Pipe\" feature."; return false; +// LCOV_EXCL_STOP } GeomShapePtr aPathShape = aPathAttrSelection->value(); @@ -96,17 +97,21 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid(const AttributePtr& theAttri AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast(theAttribute); if(!anAttrSelectionList.get()) { +// LCOV_EXCL_START theError = "Error: This validator can only work with selection list attributes in \"Pipe\" feature."; return false; +// LCOV_EXCL_STOP } std::shared_ptr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); AttributeSelectionPtr aPathSelection = aFeature->selection(FeaturesPlugin_Pipe::PATH_OBJECT_ID()); if (!aPathSelection.get()) { +// LCOV_EXCL_START theError = "Error: Path not selected."; return false; +// LCOV_EXCL_STOP } GeomShapePtr aPathShape = aPathSelection->value(); @@ -161,6 +166,7 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid(const AttributePtr& theAttri } //================================================================================================== +// LCOV_EXCL_START bool FeaturesPlugin_ValidatorPipeLocationsNumber::isValid( const std::shared_ptr& theFeature, const std::list& theArguments, @@ -209,16 +215,19 @@ bool FeaturesPlugin_ValidatorPipeLocationsNumber::isValid( return true; } +// LCOV_EXCL_STOP //================================================================================================== bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const { +// LCOV_EXCL_START if(theArguments.empty()) { theError = "Error: Validator parameters is empty."; return false; } +// LCOV_EXCL_STOP // Checking attribute. if(!isValidAttribute(theAttribute, theArguments, theError)) { @@ -245,7 +254,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA std::dynamic_pointer_cast(aContext); if(!aResultConstruction.get()) { // It is not a result construction. - // If shape is compound check that it contains only faces and edges. + // If shape is compound check that it contains only faces, edges or vertices. GeomShapePtr aShape = aSelectionAttr->value(); if(!aShape.get()) { if (aContext.get()) { @@ -259,9 +268,10 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA if(aShape->shapeType() == GeomAPI_Shape::COMPOUND) { for(GeomAPI_ShapeIterator anIt(aShape); anIt.more(); anIt.next()) { GeomShapePtr aSubShape = anIt.current(); - if(aSubShape->shapeType() != GeomAPI_Shape::EDGE + if(aSubShape->shapeType() != GeomAPI_Shape::VERTEX + && aSubShape->shapeType() != GeomAPI_Shape::EDGE && aSubShape->shapeType() != GeomAPI_Shape::FACE) { - theError = "Error: Compound should contain only faces and edges."; + theError = "Error: Compound should contain only faces, edges or vertices."; return false; } } @@ -309,9 +319,11 @@ bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isValid( AttributeSelectionListPtr aListAttr = theFeature->selectionList(aBaseObjectsID); if(!aListAttr.get()) { +// LCOV_EXCL_START theError = "Error: Could not get \"%1\" attribute."; theError.arg(aBaseObjectsID); return false; +// LCOV_EXCL_STOP } std::set aSelectedSketches; @@ -369,8 +381,10 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute Events_InfoMessage& theError) const { if(!theAttribute.get()) { +// LCOV_EXCL_START theError = "Error: Empty attribute."; return false; +// LCOV_EXCL_STOP } std::string anAttributeType = theAttribute->attributeType(); @@ -411,7 +425,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute if (aContext.get()) aConstruction = std::dynamic_pointer_cast(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; @@ -430,7 +444,6 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute return true; } } - return false; } @@ -458,15 +471,18 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute } } else { +// LCOV_EXCL_START theError = "Error: Attribute \"%1\" does not supported by this validator."; theError.arg(anAttributeType); return false; +// LCOV_EXCL_STOP } return true; } //================================================================================================== +// LCOV_EXCL_START bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const @@ -513,6 +529,7 @@ bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theA bool aValid = !aFeatureKind && aPlanarFace; return aValid; } +// LCOV_EXCL_STOP //================================================================================================== bool FeaturesPlugin_ValidatorExtrusionDir::isValid( @@ -521,8 +538,10 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid( Events_InfoMessage& theError) const { if(theArguments.size() != 2) { +// LCOV_EXCL_START theError = "Error: Validator should be used with 2 parameters for extrusion."; return false; +// LCOV_EXCL_STOP } std::list::const_iterator @@ -547,10 +566,16 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid( 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\" " @@ -615,9 +640,11 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid( bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute, Events_InfoMessage& theError) const { +// LCOV_EXCL_START if(!theAttribute.get()) { return true; } +// LCOV_EXCL_STOP std::string anAttributeType = theAttribute->attributeType(); if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) { @@ -667,9 +694,11 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast(theAttribute); if(!anAttrSelectionList.get()) { +// LCOV_EXCL_START theError = "Error: This validator can only work with selection list attributes in \"Boolean\" feature."; return false; +// LCOV_EXCL_STOP } std::shared_ptr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); @@ -756,9 +785,11 @@ bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAtt AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast(theAttribute); if(!anAttrSelectionList.get()) { +// LCOV_EXCL_START theError = "Error: This validator can only work with selection list attributes in \"Fillet\" feature."; return false; +// LCOV_EXCL_STOP } FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); @@ -819,8 +850,10 @@ bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& the AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast(theAttribute); if(!anAttrSelectionList.get()) { +// LCOV_EXCL_START theError = "Error: This validator can only work with selection list in \"Partition\" feature."; return false; +// LCOV_EXCL_STOP } for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) { @@ -877,9 +910,11 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt AttributeSelectionListPtr aSubShapesAttrList = std::dynamic_pointer_cast(theAttribute); if(!aSubShapesAttrList.get()) { +// LCOV_EXCL_START theError = "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature."; return false; +// LCOV_EXCL_STOP } static const std::string aBaseShapeID = "base_shape"; @@ -887,9 +922,11 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID); if(!aShapeAttrSelection.get()) { +// LCOV_EXCL_START theError = "Error: Could not get \"%1\" attribute."; theError.arg(aBaseShapeID); return false; +// LCOV_EXCL_STOP } GeomShapePtr aBaseShape = aShapeAttrSelection->value(); @@ -936,6 +973,7 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid( static const std::string aBaseShapeID = "base_shape"; static const std::string aSubShapesID = "subshapes_to_keep"; +// LCOV_EXCL_START if(theFeature->getKind() != "Remove_SubShapes") { theError = "Error: Feature \"%1\" does not supported by this validator."; theError.arg(theFeature->getKind()); @@ -955,6 +993,7 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid( theError.arg(aSubShapesID); return false; } +// LCOV_EXCL_STOP // Copy base shape. GeomShapePtr aBaseShape = aShapeAttrSelection->value(); @@ -986,6 +1025,7 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid( } //================================================================================================== +// LCOV_EXCL_START bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const @@ -1035,6 +1075,7 @@ bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttr return true; } +// LCOV_EXCL_STOP //================================================================================================== bool FeaturesPlugin_ValidatorUnionArguments::isValid( @@ -1042,6 +1083,7 @@ bool FeaturesPlugin_ValidatorUnionArguments::isValid( const std::list& theArguments, Events_InfoMessage& theError) const { +// LCOV_EXCL_START // Check feature kind. if(theFeature->getKind() != FeaturesPlugin_Union::ID()) { theError = "Error: This validator supports only \"%1\" feature."; @@ -1057,6 +1099,7 @@ bool FeaturesPlugin_ValidatorUnionArguments::isValid( theError.arg(FeaturesPlugin_Union::BASE_OBJECTS_ID()); return false; } +// LCOV_EXCL_STOP // Get all shapes. GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::COMPSOLID; @@ -1074,14 +1117,10 @@ bool FeaturesPlugin_ValidatorUnionArguments::isValid( // Make compound and find connected. GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseShapesList); - ListOfShape aCombined, aFree; - GeomAlgoAPI_ShapeTools::combineShapes( - aCompound, - aType, - aCombined, - aFree); - - if(aFree.size() > 0 || aCombined.size() > 1) { + ListOfShape aResults; + GeomAlgoAPI_ShapeTools::combineShapes(aCompound, aType, aResults); + + if(aResults.size() > 1 || (aResults.size() == 1 && aResults.front()->shapeType() > aType)) { theError = "Error: Not all shapes have shared topology."; return false; } @@ -1094,9 +1133,11 @@ bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAtt Events_InfoMessage& theError) const { if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) { +// LCOV_EXCL_START theError = "Error: The attribute with the %1 type is not processed"; theError.arg(theAttribute->attributeType()); return false; +// LCOV_EXCL_STOP } AttributeReferencePtr aRefAttribute = std::dynamic_pointer_cast @@ -1157,81 +1198,52 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid( const std::list& theArguments, Events_InfoMessage& theError) const { +// LCOV_EXCL_START if (theArguments.size() != 2) { theError = "Wrong number of arguments (expected 2)."; return false; } +// LCOV_EXCL_STOP - int anObjectsNb = 0, aToolsNb = 0; - //int anOperationType = 0; + int anObjectsToolsNb[2] = { 0, 0 }; std::list::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) - { - 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* anArgNbIt = anObjectsToolsNb; anIt != aLast; ++anIt, ++anArgNbIt) { + AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt); + if (anAttrSelList) { - 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 aFeature = std::dynamic_pointer_cast(theFeature); @@ -1240,7 +1252,7 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid( 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; @@ -1253,12 +1265,12 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid( } 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; @@ -1274,6 +1286,7 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid( } //================================================================================================= +// LCOV_EXCL_START bool FeaturesPlugin_ValidatorBooleanArguments::isNotObligatory(std::string theFeature, std::string theAttribute) { @@ -1284,6 +1297,7 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isNotObligatory(std::string theFe return false; } +// LCOV_EXCL_STOP //================================================================================================== bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid( @@ -1297,9 +1311,11 @@ bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid( AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast(theAttribute); if (!aFeature.get() || !anAttrSelectionList.get()) { +// LCOV_EXCL_START theError = "Error: Validator used in wrong feature or attribute"; return false; +// LCOV_EXCL_STOP } AttributeSelectionListPtr anOtherAttrSelectionList; @@ -1325,9 +1341,12 @@ bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid( ResultPtr aContext = anAttrSelection->context(); std::shared_ptr aShape = anAttrSelection->value(); - GeomShapePtr aContextShape = aContext->shape(); if (!aShape.get()) { - aShape = aContextShape; + if (!aContext.get()) { + theError = "Error: Empty selection."; + return false; + } + aShape = aContext->shape(); } if (aShape->isSolid() || aShape->isCompSolid()) { @@ -1407,15 +1426,6 @@ bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid( theError = "Error: Selected shapes should have the same type."; return false; } - - ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext); - if (aResCompSolidPtr.get()) { - GeomShapePtr aCompSolidShape = aResCompSolidPtr->shape(); - if (aSelectedCompSolidsInOtherList.isBound(aCompSolidShape)) { - theError = "Error: Solids from compsolid in other list not allowed."; - return false; - } - } } else { GeomAPI_Face aFace(aShape); GeomPlanePtr aPln = aFace.getPlane(); @@ -1436,6 +1446,7 @@ bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid( } //================================================================================================== +// LCOV_EXCL_START bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const @@ -1504,8 +1515,10 @@ bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttrib return true; } +// LCOV_EXCL_STOP //================================================================================================== +// LCOV_EXCL_START bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid( const AttributePtr& theAttribute, const std::list& theArguments, @@ -1557,6 +1570,7 @@ bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid( return true; } +// LCOV_EXCL_STOP //================================================================================================= bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid( @@ -1564,10 +1578,12 @@ bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid( const std::list& theArguments, Events_InfoMessage& theError) const { +// LCOV_EXCL_START if (theArguments.size() != 2) { theError = "Wrong number of arguments (expected 2)."; return false; } +// LCOV_EXCL_STOP std::shared_ptr aFeature = std::dynamic_pointer_cast(theFeature); @@ -1639,6 +1655,7 @@ bool FeaturesPlugin_ValidatorBooleanFuseArguments::isValid( } //================================================================================================= +// LCOV_EXCL_START bool FeaturesPlugin_ValidatorBooleanFuseArguments::isNotObligatory( std::string theFeature, std::string theAttribute) @@ -1649,8 +1666,10 @@ bool FeaturesPlugin_ValidatorBooleanFuseArguments::isNotObligatory( return false; } +// LCOV_EXCL_STOP //================================================================================================== +// LCOV_EXCL_START bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid( const AttributePtr& theAttribute, const std::list& theArguments, @@ -1685,8 +1704,10 @@ bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid( } std::shared_ptr aShape = anAttrSelection->value(); GeomShapePtr aContextShape; - if (!aShape.get() && aContext.get()) { + if (aContext.get()) { aContextShape = aContext->shape(); + } + if (!aShape.get()) { aShape = aContextShape; } if (!aShape.get()) { @@ -1706,6 +1727,7 @@ bool FeaturesPlugin_ValidatorBooleanCommonSelection::isValid( return true; } +// LCOV_EXCL_STOP //================================================================================================= bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid( @@ -1714,8 +1736,10 @@ bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid( Events_InfoMessage& theError) const { if (theArguments.size() != 2) { +// LCOV_EXCL_START theError = "Wrong number of arguments (expected 2)."; return false; +// LCOV_EXCL_STOP } std::shared_ptr aFeature = @@ -1752,9 +1776,11 @@ bool FeaturesPlugin_ValidatorBooleanCommonArguments::isValid( } //================================================================================================= +// LCOV_EXCL_START bool FeaturesPlugin_ValidatorBooleanCommonArguments::isNotObligatory( std::string theFeature, std::string theAttribute) { return false; } +// LCOV_EXCL_STOP