From: azv Date: Wed, 4 Jul 2018 05:43:04 +0000 (+0300) Subject: Issue #2547: Measurement - Angle – if selected pair of edges do not intersect, add... X-Git-Tag: EDF_2018-1~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f2be9398eed82f5f18df9a5bc9a55a69f5bf87ff;p=modules%2Fshaper.git Issue #2547: Measurement - Angle – if selected pair of edges do not intersect, add “Not intersected” Special validator to avoid selecting non-intersected edges has been implemented. --- diff --git a/src/FeaturesPlugin/measurement_widget.xml b/src/FeaturesPlugin/measurement_widget.xml index 22c557b1d..e16856771 100644 --- a/src/FeaturesPlugin/measurement_widget.xml +++ b/src/FeaturesPlugin/measurement_widget.xml @@ -65,6 +65,7 @@ email : webmaster.salome@opencascade.com + + diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt index 3b343b292..ddc6baa0f 100644 --- a/src/GeomValidators/CMakeLists.txt +++ b/src/GeomValidators/CMakeLists.txt @@ -39,6 +39,7 @@ SET(PROJECT_HEADERS GeomValidators_IntersectionSelection.h GeomValidators_MinObjectsSelected.h GeomValidators_ValueOrder.h + GeomValidators_Intersected.h ) SET(PROJECT_SOURCES @@ -59,6 +60,7 @@ SET(PROJECT_SOURCES GeomValidators_IntersectionSelection.cpp GeomValidators_MinObjectsSelected.cpp GeomValidators_ValueOrder.cpp + GeomValidators_Intersected.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomValidators/GeomValidators_Intersected.cpp b/src/GeomValidators/GeomValidators_Intersected.cpp new file mode 100644 index 000000000..aeef9bd12 --- /dev/null +++ b/src/GeomValidators/GeomValidators_Intersected.cpp @@ -0,0 +1,80 @@ +// Copyright (C) 2014-2017 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_Intersected.h" + +#include + +#include + +#include +#include + +bool GeomValidators_Intersected::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + if (!theAttribute) { + theError = "Error: empty selection."; + return false; + } + + if (theArguments.empty()) { + theError = "Error: compare with nothing"; + return false; + } + + FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); + + // get shape selected by theAttribute + AttributeSelectionPtr aSelection = + std::dynamic_pointer_cast(theAttribute); + GeomShapePtr aBaseShape; + if (aSelection) + aBaseShape = aSelection->value(); + if (!aBaseShape && aSelection->context()) + aBaseShape = aSelection->context()->shape(); + if (!aBaseShape) + return true; // nothing selected, thus applicable + + // check intersection with all arguments + bool isOk = true; + for (std::list::const_iterator anIt = theArguments.begin(); + anIt != theArguments.end() && isOk; ++anIt) { + aSelection = aFeature->selection(*anIt); + if (!aSelection) { + theError = "Error: incorrect type of attribute"; + return false; + } + + GeomShapePtr aShape; + if (aSelection) + aShape = aSelection->value(); + if (!aShape && aSelection->context()) + aShape = aSelection->context()->shape(); + if (aShape) { + isOk = aBaseShape->isIntersect(aShape); + } + } + + if (!isOk) + theError = "Error: arguments are not intersected"; + return isOk; +} diff --git a/src/GeomValidators/GeomValidators_Intersected.h b/src/GeomValidators/GeomValidators_Intersected.h new file mode 100644 index 000000000..18e831318 --- /dev/null +++ b/src/GeomValidators/GeomValidators_Intersected.h @@ -0,0 +1,45 @@ +// Copyright (C) 2014-2017 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 +// + +#ifndef GeomValidators_Intersected_H +#define GeomValidators_Intersected_H + +#include + +#include +#include + +/// \class GeomValidators_Intersected +/// \ingroup Validators +/// \brief Validates that selected shapes are intersected. +class GeomValidators_Intersected : public ModelAPI_AttributeValidator +{ +public: + /// \return True if the attribute is valid. It checks whether the selection + /// is intersected with shape given as a name of attribute. + /// \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, + Events_InfoMessage& theError) const; +}; + +#endif diff --git a/src/GeomValidators/GeomValidators_Plugin.cpp b/src/GeomValidators/GeomValidators_Plugin.cpp index 54ee61429..2bf421fa0 100644 --- a/src/GeomValidators/GeomValidators_Plugin.cpp +++ b/src/GeomValidators/GeomValidators_Plugin.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -65,6 +66,7 @@ GeomValidators_Plugin::GeomValidators_Plugin() aFactory->registerValidator("GeomValidators_FeatureKind", new GeomValidators_FeatureKind); aFactory->registerValidator("GeomValidators_MinObjectsSelected", new GeomValidators_MinObjectsSelected); + aFactory->registerValidator("GeomValidators_Intersected", new GeomValidators_Intersected); // register this plugin ModelAPI_Session::get()->registerPlugin(this);