From 87094243225a12a13af2025f5f55e978eb59ff52 Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 16 Feb 2016 12:14:33 +0300 Subject: [PATCH] Added selection validator for intersection. Fixed dll exports. --- src/FeaturesPlugin/intersection_widget.xml | 4 +- src/GeomValidators/CMakeLists.txt | 2 + .../GeomValidators_BodyShapes.h | 8 +-- .../GeomValidators_BooleanSelection.h | 8 +-- .../GeomValidators_DifferentShapes.h | 8 +-- .../GeomValidators_IntersectionSelection.cpp | 69 +++++++++++++++++++ .../GeomValidators_IntersectionSelection.h | 31 +++++++++ src/GeomValidators/GeomValidators_Plugin.cpp | 2 + 8 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 src/GeomValidators/GeomValidators_IntersectionSelection.cpp create mode 100644 src/GeomValidators/GeomValidators_IntersectionSelection.h diff --git a/src/FeaturesPlugin/intersection_widget.xml b/src/FeaturesPlugin/intersection_widget.xml index 988f3e07f..7dac829ae 100644 --- a/src/FeaturesPlugin/intersection_widget.xml +++ b/src/FeaturesPlugin/intersection_widget.xml @@ -9,7 +9,7 @@ use_choice="false" concealment="true"> - + - + diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt index ceb12b40d..b18ae35aa 100644 --- a/src/GeomValidators/CMakeLists.txt +++ b/src/GeomValidators/CMakeLists.txt @@ -18,6 +18,7 @@ SET(PROJECT_HEADERS GeomValidators_ZeroOffset.h GeomValidators_Different.h GeomValidators_BooleanSelection.h + GeomValidators_IntersectionSelection.h ) SET(PROJECT_SOURCES @@ -35,6 +36,7 @@ SET(PROJECT_SOURCES GeomValidators_ZeroOffset.cpp GeomValidators_Different.cpp GeomValidators_BooleanSelection.cpp + GeomValidators_IntersectionSelection.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomValidators/GeomValidators_BodyShapes.h b/src/GeomValidators/GeomValidators_BodyShapes.h index 19fe81f79..33e2f8f50 100644 --- a/src/GeomValidators/GeomValidators_BodyShapes.h +++ b/src/GeomValidators/GeomValidators_BodyShapes.h @@ -7,7 +7,7 @@ #ifndef GeomValidators_BodyShapes_H #define GeomValidators_BodyShapes_H -#include +#include #include #include @@ -23,9 +23,9 @@ public: /// \param[in] theAttribute an attribute to check /// \param[in] theArguments a filter parameters /// \param[out] theError error message. - MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const; + GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; }; #endif diff --git a/src/GeomValidators/GeomValidators_BooleanSelection.h b/src/GeomValidators/GeomValidators_BooleanSelection.h index 59b5d3ce6..19ced9baa 100644 --- a/src/GeomValidators/GeomValidators_BooleanSelection.h +++ b/src/GeomValidators/GeomValidators_BooleanSelection.h @@ -7,7 +7,7 @@ #ifndef GeomValidators_BooleanSelection_H #define GeomValidators_BooleanSelection_H -#include +#include #include #include @@ -23,9 +23,9 @@ public: /// \param[in] theAttribute an attribute to check. /// \param[in] theArguments a filter parameters. /// \param[out] theError error message. - MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const; + GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; }; #endif diff --git a/src/GeomValidators/GeomValidators_DifferentShapes.h b/src/GeomValidators/GeomValidators_DifferentShapes.h index 033ef1b3c..ac3dd5b58 100644 --- a/src/GeomValidators/GeomValidators_DifferentShapes.h +++ b/src/GeomValidators/GeomValidators_DifferentShapes.h @@ -7,7 +7,7 @@ #ifndef GeomValidators_DifferentShapes_H #define GeomValidators_DifferentShapes_H -#include +#include #include #include @@ -23,9 +23,9 @@ public: /// \param[in] theAttribute an attribute to check /// \param[in] theArguments a filter parameters /// \param[out] theError error message. - MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const; + GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; }; #endif diff --git a/src/GeomValidators/GeomValidators_IntersectionSelection.cpp b/src/GeomValidators/GeomValidators_IntersectionSelection.cpp new file mode 100644 index 000000000..e3899d7f5 --- /dev/null +++ b/src/GeomValidators/GeomValidators_IntersectionSelection.cpp @@ -0,0 +1,69 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_IntersectionSelection.cpp +// Created: 16 Feb 2016 +// Author: Dmitry Bobylev + +#include "GeomValidators_IntersectionSelection.h" + +#include +#include +#include + +bool GeomValidators_IntersectionSelection::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + if(!theAttribute.get()) { + theError = "Error: empty selection."; + return false; + } + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast(theAttribute); + for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) { + AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex); + if(!anAttrSelection.get()) { + theError = "Error: empty attribute selection."; + return false; + } + ResultPtr aContext = anAttrSelection->context(); + if(!aContext.get()) { + theError = "Error: empty selection context."; + return false; + } + FeaturePtr aFeature = ModelAPI_Feature::feature(aContext); + if(!aFeature.get()) { + theError = "Error: empty feature."; + return false; + } + std::string aFeatureKind = aFeature->getKind(); + if(aFeatureKind == "Sketch" || + aFeatureKind == "Plane" || + aFeatureKind == "Axis") { + theError = "Error: "; + theError += aFeatureKind; + theError += " shape is not allowed for selection."; + return false; + } + std::shared_ptr aShape = anAttrSelection->value(); + if(!aShape.get()) { + aShape = aContext->shape(); + } + if(!aShape.get()) { + theError = "Error: empty shape."; + return false; + } + int aShapeType = aShape->shapeType(); + // Allow to select edges, faces and solids. + if(aShapeType != GeomAPI_Shape::EDGE && + aShapeType != GeomAPI_Shape::FACE && + aShapeType != GeomAPI_Shape::SOLID && + aShapeType != GeomAPI_Shape::COMPSOLID && + aShapeType != GeomAPI_Shape::COMPOUND) { + theError = "Error: selected shape has the wrong type."; + return false; + } + } + + return true; +} diff --git a/src/GeomValidators/GeomValidators_IntersectionSelection.h b/src/GeomValidators/GeomValidators_IntersectionSelection.h new file mode 100644 index 000000000..6773a11ba --- /dev/null +++ b/src/GeomValidators/GeomValidators_IntersectionSelection.h @@ -0,0 +1,31 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_IntersectionSelection.h +// Created: 16 Feb 2016 +// Author: Dmitry Bobylev + +#ifndef GeomValidators_IntersectionSelection_H +#define GeomValidators_IntersectionSelection_H + +#include + +#include +#include + +/// \class GeomValidators_ZeroOffset +/// \ingroup Validators +/// \brief Validates selection for boolean operation. +class GeomValidators_IntersectionSelection: public ModelAPI_AttributeValidator +{ +public: + /// \return True if the attribute is valid. It checks whether the selection + /// is acceptable for boolean operation. + /// \param[in] theAttribute an attribute to check. + /// \param[in] theArguments a filter parameters. + /// \param[out] theError error message. + GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; +}; + +#endif diff --git a/src/GeomValidators/GeomValidators_Plugin.cpp b/src/GeomValidators/GeomValidators_Plugin.cpp index 497e0a70a..824206f63 100644 --- a/src/GeomValidators/GeomValidators_Plugin.cpp +++ b/src/GeomValidators/GeomValidators_Plugin.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -37,6 +38,7 @@ GeomValidators_Plugin::GeomValidators_Plugin() aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType); aFactory->registerValidator("GeomValidators_ZeroOffset", new GeomValidators_ZeroOffset); aFactory->registerValidator("GeomValidators_BooleanSelection", new GeomValidators_BooleanSelection); + aFactory->registerValidator("GeomValidators_IntersectionSelection", new GeomValidators_IntersectionSelection); // register this plugin ModelAPI_Session::get()->registerPlugin(this); -- 2.39.2