From cbe5929156574797612896a8d4e8021d2ecf6129 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 27 Feb 2015 15:41:34 +0300 Subject: [PATCH] Issue #353 constraint on 2 segments from not acive sketches A sketch shape validator for parallel/perpendicular constraints. --- src/ModelAPI/ModelAPI_ShapeValidator.cpp | 2 + src/ModelAPI/ModelAPI_ShapeValidator.h | 6 ++- .../ModuleBase_WidgetShapeSelector.cpp | 2 +- src/SketchPlugin/CMakeLists.txt | 2 + src/SketchPlugin/SketchPlugin_Plugin.cpp | 3 ++ .../SketchPlugin_ShapeValidator.cpp | 54 +++++++++++++++++++ .../SketchPlugin_ShapeValidator.h | 36 +++++++++++++ src/SketchPlugin/plugin-Sketch.xml | 8 ++- 8 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 src/SketchPlugin/SketchPlugin_ShapeValidator.cpp create mode 100644 src/SketchPlugin/SketchPlugin_ShapeValidator.h diff --git a/src/ModelAPI/ModelAPI_ShapeValidator.cpp b/src/ModelAPI/ModelAPI_ShapeValidator.cpp index b451ed1bb..08f0a687b 100644 --- a/src/ModelAPI/ModelAPI_ShapeValidator.cpp +++ b/src/ModelAPI/ModelAPI_ShapeValidator.cpp @@ -10,6 +10,8 @@ #include "ModelAPI_Object.h" bool ModelAPI_ShapeValidator::isValid(const FeaturePtr& theFeature, + const std::list& theArguments, + const ObjectPtr& theObject, const AttributePtr& theAttribute, const GeomShapePtr& theShape) const { diff --git a/src/ModelAPI/ModelAPI_ShapeValidator.h b/src/ModelAPI/ModelAPI_ShapeValidator.h index 596e1c08e..3be9323f7 100644 --- a/src/ModelAPI/ModelAPI_ShapeValidator.h +++ b/src/ModelAPI/ModelAPI_ShapeValidator.h @@ -24,9 +24,13 @@ public: /// returns True if the attribute is valid. It checks whether the feature of the attribute /// does not contain a selection attribute filled with the same shape /// \param theFeature a feature to check + /// \param theArguments a filter parameters + /// \param theObject an object /// \param theAttribute an attribute to check /// \param theShape a shape - MODELAPI_EXPORT bool isValid(const FeaturePtr& theFeature, const AttributePtr& theAttribute, + MODELAPI_EXPORT virtual bool isValid(const FeaturePtr& theFeature, + const std::list& theArguments, + const ObjectPtr& theObject, const AttributePtr& theAttribute, const GeomShapePtr& theShape) const; }; diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 9dc8c5063..30787899f 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -535,7 +535,7 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptrdata(); AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); - if (!aShapeValidator->isValid(myFeature, aSelectAttr, theShape)) { + if (!aShapeValidator->isValid(myFeature, *aArgs, theObj, aSelectAttr, theShape)) { return false; } } diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index d801aabac..3b9c8dc26 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -21,6 +21,7 @@ SET(PROJECT_HEADERS SketchPlugin_ConstraintPerpendicular.h SketchPlugin_ConstraintRadius.h SketchPlugin_ConstraintRigid.h + SketchPlugin_ShapeValidator.h SketchPlugin_Validators.h SketchPlugin_ResultValidators.h ) @@ -41,6 +42,7 @@ SET(PROJECT_SOURCES SketchPlugin_ConstraintPerpendicular.cpp SketchPlugin_ConstraintRadius.cpp SketchPlugin_ConstraintRigid.cpp + SketchPlugin_ShapeValidator.cpp SketchPlugin_Validators.cpp SketchPlugin_ResultValidators.cpp ) diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index c486acf65..20958c5e3 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -50,6 +51,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator); aFactory->registerValidator("SketchPlugin_ResultLine", new SketchPlugin_ResultLineValidator); aFactory->registerValidator("SketchPlugin_ResultArc", new SketchPlugin_ResultArcValidator); + aFactory->registerValidator("SketchPlugin_ShapeValidator", + new SketchPlugin_ShapeValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp b/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp new file mode 100644 index 000000000..1b2795900 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp @@ -0,0 +1,54 @@ +// 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 +#include + +bool SketchPlugin_ShapeValidator::isValid(const FeaturePtr& theFeature, + const std::list& theArguments, + const ObjectPtr& theObject, + const AttributePtr& theAttribute, + const GeomShapePtr& theShape) const +{ + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + std::shared_ptr aShape = ModelAPI_Tools::shape(aResult); + + // if the shapes are equal, that means that the given shape is a result. + // if the result is selected, the + if (aShape->isEqual(theShape)) + return true; + + // found a non-external argument on the feature + std::list::const_iterator anIt = theArguments.begin(), aLast = theArguments.end(); + bool aHasNullParam = false; + bool aHasNonExternalParams = false; + for (; anIt != aLast; anIt++) { + std::string aParamA = *anIt; + std::shared_ptr anAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(aParamA)); + if (anAttr) { + FeaturePtr anOtherFeature = ModelAPI_Feature::feature(anAttr->object()); + if (anOtherFeature.get() != NULL) { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(anOtherFeature); + if (aSketchFeature) { + aHasNonExternalParams = !aSketchFeature->isExternal(); + } + } + else + aHasNullParam = true; + } + } + if (aHasNullParam || aHasNonExternalParams) + return true; + return false; +} diff --git a/src/SketchPlugin/SketchPlugin_ShapeValidator.h b/src/SketchPlugin/SketchPlugin_ShapeValidator.h new file mode 100644 index 000000000..6e35f4da1 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ShapeValidator.h @@ -0,0 +1,36 @@ +// 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 +#include + +/**\class SketchPlugin_ResultPointValidator + * \ingroup Validators + * \brief Validator for the points selection + * + * Allows to select points only. + */ +class SketchPlugin_ShapeValidator : public ModelAPI_ShapeValidator +{ +public: + // returns true if there is an empty or non-external shape on the feature. + // in the given shape or in the list of attribute shapes + /// \param theFeature a feature to check + /// \param theArguments a filter parameters + /// \param theObject an object + /// \param theAttribute an attribute to check + /// \param theShape a shape + SKETCHPLUGIN_EXPORT virtual bool isValid(const FeaturePtr& theFeature, + const std::list& theArguments, + const ObjectPtr& theObject, const AttributePtr& theAttribute, + const GeomShapePtr& theShape) const; +}; + +#endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index cc23f8e00..2300c7a30 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -103,12 +103,14 @@ + + @@ -119,14 +121,16 @@ - + + - + + -- 2.39.2