From: nds Date: Thu, 26 Mar 2015 08:23:14 +0000 (+0300) Subject: Union of validator and filter functionalities. X-Git-Tag: V_1.1.0~80^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=139976bbdb4d10dbedc4ce966f7bef2843b83bcd;p=modules%2Fshaper.git Union of validator and filter functionalities. It renames the shape validator to the external validator. --- diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 22ce7d27e..e94f680c1 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -28,7 +28,7 @@ SET(PROJECT_HEADERS SketchPlugin_ConstraintTangent.h SketchPlugin_ConstraintMirror.h SketchPlugin_ConstraintFillet.h - SketchPlugin_ShapeValidator.h + SketchPlugin_ExternalValidator.h SketchPlugin_Validators.h ) @@ -55,7 +55,7 @@ SET(PROJECT_SOURCES SketchPlugin_ConstraintTangent.cpp SketchPlugin_ConstraintMirror.cpp SketchPlugin_ConstraintFillet.cpp - SketchPlugin_ShapeValidator.cpp + SketchPlugin_ExternalValidator.cpp SketchPlugin_Validators.cpp ) diff --git a/src/SketchPlugin/SketchPlugin_ExternalValidator.cpp b/src/SketchPlugin/SketchPlugin_ExternalValidator.cpp new file mode 100644 index 000000000..7b8587188 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ExternalValidator.cpp @@ -0,0 +1,51 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: Model_ResultValidators.cpp +// Created: 27 Feb 2015 +// Author: Natalia ERMOLAEVA + +#include "SketchPlugin_ExternalValidator.h" +#include "SketchPlugin_Feature.h" + +#include +#include +#include +#include + +bool SketchPlugin_ExternalValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const +{ + if (theArguments.size() != 1) + return true; + + // ask whether the feature of the attribute is external + bool isAttributeExternal = isExternalAttribute(theAttribute); + + // ask whether the feature of the attribute by parameter identifier is external + std::string aFrontArgument = theArguments.front(); + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + bool isParameterExternal = isExternalAttribute(aFeature->attribute(aFrontArgument)); + + // it is not possible that both features, attribute and attribute in parameter, are external + if (isAttributeExternal && isParameterExternal) + return false; + return true; +} + +bool SketchPlugin_ExternalValidator::isExternalAttribute(const AttributePtr& theAttribute) const +{ + bool isExternal = false; + AttributeRefAttrPtr anAttribute = std::dynamic_pointer_cast(theAttribute); + + if (anAttribute.get() != NULL) { + FeaturePtr anArgumentFeature = ModelAPI_Feature::feature(anAttribute->object()); + if (anArgumentFeature.get() != NULL) { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(anArgumentFeature); + if (aSketchFeature.get() != NULL) { + isExternal = aSketchFeature->isExternal(); + } + } + } + return isExternal; +} diff --git a/src/SketchPlugin/SketchPlugin_ExternalValidator.h b/src/SketchPlugin/SketchPlugin_ExternalValidator.h new file mode 100644 index 000000000..62d95bfe0 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ExternalValidator.h @@ -0,0 +1,35 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: Model_ResultValidators.h +// Created: 27 Feb 2015 +// Author: Natalia ERMOLAEVA + +#ifndef SketchPlugin_ExternalValidator_H +#define SketchPlugin_ExternalValidator_H + +#include +#include + +/**\class SketchPlugin_ResultPointValidator + * \ingroup Validators + * \brief Validator for the points selection + * + * Allows to select points only. + */ +class SketchPlugin_ExternalValidator : public ModelAPI_AttributeValidator +{ +public: + /// returns true if the feature of attribute do not contain external features in the given attribute and + /// among attributes listed in the arguments + /// \param theAttribute an attribute to check + /// \param theArguments a filter parameters + SKETCHPLUGIN_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; + +protected: + /// returns true if the feature of the attribute is external + /// \param theAttribute an attribute to check + bool isExternalAttribute(const AttributePtr& theAttribute) const; +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 04347759e..68302fee1 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -51,15 +51,12 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); aFactory->registerValidator("SketchPlugin_DistanceAttr", new SketchPlugin_DistanceAttrValidator); - //aFactory->registerValidator("SketchPlugin_DifferentObjects", - // new SketchPlugin_DifferentObjectsValidator); - - aFactory->registerValidator("SketchPlugin_ShapeValidator", - new SketchPlugin_ShapeValidator); + aFactory->registerValidator("SketchPlugin_ExternalValidator", + new SketchPlugin_ExternalValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); - + Config_PropManager::registerProp("Visualization", "sketch_entity_color", "Sketch enity color", Config_Prop::Color, SKETCH_ENTITY_COLOR); diff --git a/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp b/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp deleted file mode 100644 index 0722ce1b3..000000000 --- a/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: Model_ResultValidators.cpp -// Created: 27 Feb 2015 -// Author: Natalia ERMOLAEVA - -#include "SketchPlugin_ShapeValidator.h" -#include "SketchPlugin_Feature.h" - -#include -#include -#include -#include - -bool SketchPlugin_ShapeValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const -{ - if (theArguments.size() != 1) - return true; - - // ask whether the feature of the attribute is external - bool isAttributeExternal = isExternalAttribute(theAttribute); - - // ask whether the feature of the attribute by parameter identifier is external - std::string aFrontArgument = theArguments.front(); - FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); - bool isParameterExternal = isExternalAttribute(aFeature->attribute(aFrontArgument)); - - // it is not possible that both features, attribute and attribute in parameter, are external - if (isAttributeExternal && isParameterExternal) - return false; - return true; -} - -bool SketchPlugin_ShapeValidator::isExternalAttribute(const AttributePtr& theAttribute) const -{ - bool isExternal = false; - AttributeRefAttrPtr anAttribute = std::dynamic_pointer_cast(theAttribute); - - if (anAttribute.get() != NULL) { - FeaturePtr anArgumentFeature = ModelAPI_Feature::feature(anAttribute->object()); - if (anArgumentFeature.get() != NULL) { - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(anArgumentFeature); - if (aSketchFeature.get() != NULL) { - isExternal = aSketchFeature->isExternal(); - } - } - } - return isExternal; -} diff --git a/src/SketchPlugin/SketchPlugin_ShapeValidator.h b/src/SketchPlugin/SketchPlugin_ShapeValidator.h deleted file mode 100644 index d07581ebd..000000000 --- a/src/SketchPlugin/SketchPlugin_ShapeValidator.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: Model_ResultValidators.h -// Created: 27 Feb 2015 -// Author: Natalia ERMOLAEVA - -#ifndef SketchPlugin_ShapeValidator_H -#define SketchPlugin_ShapeValidator_H - -#include -#include - -/**\class SketchPlugin_ResultPointValidator - * \ingroup Validators - * \brief Validator for the points selection - * - * Allows to select points only. - */ -class SketchPlugin_ShapeValidator : public ModelAPI_AttributeValidator -{ -public: - /// returns true if the feature of attribute do not contain external features in the given attribute and - /// among attributes listed in the arguments - /// \param theAttribute an attribute to check - /// \param theArguments a filter parameters - SKETCHPLUGIN_EXPORT virtual bool isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const; - -protected: - /// returns true if the feature of the attribute is external - /// \param theAttribute an attribute to check - bool isExternalAttribute(const AttributePtr& theAttribute) const; -}; - -#endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index f1bc36d9b..9127d418f 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -57,7 +57,7 @@ label="First object" tooltip="Select point, line end point, line, center of circle or arc." shape_types="edge vertex"> - + /> - + @@ -108,14 +108,14 @@ - + - + @@ -125,7 +125,7 @@ - + @@ -133,7 +133,7 @@ label="Last line" tooltip="Select an line" shape_types="edge"> - +