X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomValidators%2FGeomValidators_DifferentShapes.cpp;h=92efa01ef61d47b8b9e425036af23935d37e555f;hb=50a8df0c6a66da8067b16155e5ae39f8f26a7ebc;hp=e9470daf4b6fea239ccbcc8e2b523bd86c63e63b;hpb=e98f5ede19029ac09ae9fe78061a4485bd6b86b5;p=modules%2Fshaper.git diff --git a/src/GeomValidators/GeomValidators_DifferentShapes.cpp b/src/GeomValidators/GeomValidators_DifferentShapes.cpp index e9470daf4..92efa01ef 100644 --- a/src/GeomValidators/GeomValidators_DifferentShapes.cpp +++ b/src/GeomValidators/GeomValidators_DifferentShapes.cpp @@ -1,55 +1,176 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomValidators_DifferentShapes.cpp -// Created: 2 Feb 2015 -// Author: Natalia ERMOLAEVA +// 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "GeomValidators_DifferentShapes.h" +#include + #include +#include #include "ModelAPI_Object.h" +#include +#include + +//================================================================================================= bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute, const std::list& theArguments, - std::string& theError) const + Events_InfoMessage& theError) const +{ + bool isValid = false; + + std::string anAttributeType = theAttribute->attributeType(); + bool isList = anAttributeType == ModelAPI_AttributeSelectionList::typeId(); + + std::list anAttrs; + if (isList) { + AttributeSelectionListPtr aListAttr = + std::dynamic_pointer_cast(theAttribute); + // get all selection attributes from the list + for (int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) { + anAttrs.push_back(aListAttr->value(anIndex)); + } + + isValid = checkEquals(anAttrs); + } + else { + // get all feature selection attributes + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + anAttrs = aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId()); + + isValid = checkEqualToCurrent(anAttrs, theAttribute); + } + + if (!isValid) { + theError = isList ? "The selection list contains equal shapes." : + "The feature uses equal shapes."; + return false; + } + + return true; +} + +//================================================================================================= +bool GeomValidators_DifferentShapes::checkEquals(std::list& theAttributes) { - FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); - AttributeSelectionPtr aSelectionAttribute = - std::dynamic_pointer_cast(theAttribute); + std::list::iterator anIt = theAttributes.begin(); + for (; anIt != theAttributes.end(); anIt++) { + AttributePtr anAttribute = *anIt; + + std::list::iterator anOthersIt = std::next(anIt); + for (; anOthersIt != theAttributes.end(); anOthersIt++) { + AttributePtr anOtherAttribute = *anOthersIt; + if (isAttrShapesEqual(anAttribute, anOtherAttribute)) { + return false; + } + } + } + + return true; +} + +//================================================================================================= +bool GeomValidators_DifferentShapes::checkEqualToCurrent(std::list& theAttributes, + const AttributePtr& theCurrentAttribute) +{ + AttributeSelectionPtr aSelectionAttribute = + std::dynamic_pointer_cast(theCurrentAttribute); + GeomShapePtr aShape = aSelectionAttribute->value(); + ResultPtr aResultContext = aSelectionAttribute->context(); if (!aShape.get()) { - ResultPtr aResult = aSelectionAttribute->context(); - if (aResult.get()) - aShape = aResult->shape(); + if (aResultContext.get()) + aShape = aResultContext->shape(); } + // whole feature selection + FeaturePtr aFeature = aSelectionAttribute->contextFeature(); - std::string aCurrentAttributeId = theAttribute->id(); - // get all feature attributes - std::list anAttrs = - aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId()); - if (anAttrs.size() > 0 && aShape.get() != NULL) { - std::list::iterator anAttr = anAttrs.begin(); - for(; anAttr != anAttrs.end(); anAttr++) { + std::string aCurrentAttributeId = theCurrentAttribute->id(); + if (theAttributes.size() > 0 && aShape.get() != NULL) { + std::list::iterator anAttr = theAttributes.begin(); + for (; anAttr != theAttributes.end(); anAttr++) { AttributePtr anAttribute = *anAttr; // take into concideration only other attributes if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) { - aSelectionAttribute = + aSelectionAttribute = std::dynamic_pointer_cast(anAttribute); // the shape of the attribute should be not the same if (aSelectionAttribute.get() != NULL) { GeomShapePtr anAttrShape = aSelectionAttribute->value(); + ResultPtr aResult = aSelectionAttribute->context(); if (!anAttrShape.get()) { - ResultPtr aResult = aSelectionAttribute->context(); if (aResult.get()) anAttrShape = aResult->shape(); } if (aShape->isEqual(anAttrShape)) { - theError = "The feature uses equal shapes."; return false; } + if (aFeature.get()) { + if (aResult.get()) { // check result is in feature + if (aResult->document()->feature(aResult) == aFeature) + return false; + } + else { // check selection of the same features + if (aFeature == aSelectionAttribute->contextFeature()) + return false; + } + } + else { + if (!aResult.get() && aResultContext.get()) { + FeaturePtr aSelectedFeature = aSelectionAttribute->contextFeature(); + if (aResultContext->document()->feature(aResultContext) == aSelectedFeature) + return false; + } + } } } } } + return true; } + +bool GeomValidators_DifferentShapes::isAttrShapesEqual(const AttributePtr& theAttribute, + const AttributePtr& theOtherAttribute) +{ + AttributeSelectionPtr aSelectionAttribute = + std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr anOtherSelectionAttribute = + std::dynamic_pointer_cast(theOtherAttribute); + + GeomShapePtr aShape = aSelectionAttribute->value(); + if (!aShape.get()) { + ResultPtr aResult = aSelectionAttribute->context(); + if (aResult.get()) + aShape = aResult->shape(); + } + GeomShapePtr aTypedShape = GeomAPI_Tools::getTypedShape(aShape); + + GeomShapePtr anOtherShape = anOtherSelectionAttribute->value(); + if (!anOtherShape.get()) { + ResultPtr aResult = anOtherSelectionAttribute->context(); + if (aResult.get()) + anOtherShape = aResult->shape(); + } + GeomShapePtr aOtherTypedShape = GeomAPI_Tools::getTypedShape(anOtherShape); + + if (!aTypedShape.get()) + return !aTypedShape.get() && !aOtherTypedShape.get(); + return aTypedShape->isEqual(aOtherTypedShape); +}