From: spo Date: Wed, 8 Jul 2015 14:03:05 +0000 (+0300) Subject: Issue #653 - Double and triple click edges X-Git-Tag: V_1.3.0~71 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=364cef2e3a61f6d511a8389ae445c03319b7bbca;p=modules%2Fshaper.git Issue #653 - Double and triple click edges --- diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt index 07004c22a..ced6fea05 100644 --- a/src/GeomValidators/CMakeLists.txt +++ b/src/GeomValidators/CMakeLists.txt @@ -11,6 +11,7 @@ SET(PROJECT_HEADERS GeomValidators_ShapeType.h GeomValidators_Tools.h GeomValidators_ZeroOffset.h + GeomValidators_Different.h ) SET(PROJECT_SOURCES @@ -21,6 +22,7 @@ SET(PROJECT_SOURCES GeomValidators_ShapeType.cpp GeomValidators_Tools.cpp GeomValidators_ZeroOffset.cpp + GeomValidators_Different.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomValidators/GeomValidators_Different.cpp b/src/GeomValidators/GeomValidators_Different.cpp new file mode 100644 index 000000000..65b834d3a --- /dev/null +++ b/src/GeomValidators/GeomValidators_Different.cpp @@ -0,0 +1,83 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_Different.cpp +// Created: 08 July 2015 +// Author: Sergey POKHODENKO + +#include + +#include + +#include +#include +#include + +//================================================================================================= +/* Help +To extend GeomValidators_Different validator with new attribute types: +1. Modify function isEqualAttributes +2. Create new implementation of isEqual() for the new type +*/ +//================================================================================================= + +bool isEqual(const AttributePoint2DPtr& theLeft, const AttributePoint2DPtr& theRight) +{ + return theLeft->x() == theRight->x() && + theLeft->y() == theRight->y(); +} + +bool isEqualAttributes(const AttributePtr& theLeft, const AttributePtr& theRight) +{ + if (theLeft->attributeType() == GeomDataAPI_Point2D::typeId() && + theRight->attributeType() == GeomDataAPI_Point2D::typeId()) + return isEqual(std::dynamic_pointer_cast(theLeft), + std::dynamic_pointer_cast(theRight)); + return false; +} + +class IsEqual { + AttributePtr myAttribute; +public: + IsEqual(const AttributePtr& theAttribute) : myAttribute(theAttribute) {} + bool operator()(const AttributePtr& theAttribute) { + return isEqualAttributes(myAttribute, theAttribute); + } +}; + +bool GeomValidators_Different::isValid(const std::shared_ptr& theFeature, + const std::list& theArguments) const +{ + std::map > anAttributesMap; + // For all attributes referred by theArguments + // sort it using attributeType() and store into anAttributesMap + std::list::const_iterator anArgumentIt = theArguments.begin(); + for (; anArgumentIt != theArguments.end(); ++anArgumentIt) { + AttributePtr anAttribute = theFeature->attribute(*anArgumentIt); + anAttributesMap[anAttribute->attributeType()].push_back(anAttribute); + } + + // Search differences inside each attribute list + std::map >::const_iterator anAttributesMapIt = anAttributesMap.begin(); + for (; anAttributesMapIt != anAttributesMap.end(); ++anAttributesMapIt) { + const std::list& anAttributes = anAttributesMapIt->second; + // for the list of attributes check that all elements are unique + std::list::const_iterator anAttributeIt = anAttributes.begin(); + if (anAttributeIt != anAttributes.end()) { + std::list::const_iterator aNextIt = anAttributeIt; ++aNextIt; + while (aNextIt != anAttributes.end()) { + // if equal attribute is found then all attributes are not different + if (std::find_if(aNextIt, anAttributes.end(), IsEqual(*anAttributeIt)) != anAttributes.end()) + return false; + ++anAttributeIt; + ++aNextIt; + } + } + } + + return true; +} + +bool GeomValidators_Different::isNotObligatory(std::string theFeature, std::string theAttribute) +{ + return true; +} diff --git a/src/GeomValidators/GeomValidators_Different.h b/src/GeomValidators/GeomValidators_Different.h new file mode 100644 index 000000000..14380dd3e --- /dev/null +++ b/src/GeomValidators/GeomValidators_Different.h @@ -0,0 +1,32 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_Different.h +// Created: 08 July 2015 +// Author: Sergey POKHODENKO + +#ifndef GeomValidators_Different_H +#define GeomValidators_Different_H + +#include +#include +#include + +/** \class GeomValidators_Different + * \ingroup Validators + * \brief Validates that attributes are not the same. + */ +class GeomValidators_Different : public ModelAPI_FeatureValidator +{ +public: + /** \brief Returns true if feature and/or attributes are valid. + * \param[in] theFeature the validated feature. + * \param[in] theArguments the arguments in the configuration file for this validator. + * \returns true if feature is valid. + */ + GEOMVALIDATORS_EXPORT virtual bool isValid(const std::shared_ptr& theFeature, + const std::list& theArguments) const; + + GEOMVALIDATORS_EXPORT virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); +}; + +#endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index e518c7df3..cce9ffc82 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -208,6 +209,9 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("PartSet_SameTypeAttr", new PartSet_SameTypeAttrValidator); + + aFactory->registerValidator("GeomValidators_Different", + new GeomValidators_Different); } void PartSet_Module::registerFilters() diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 9cdbb2b0e..626ec3089 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -23,6 +23,7 @@ + @@ -36,6 +37,7 @@ +