Special validator to avoid selecting non-intersected edges has been implemented.
shape_types="edge"
default="">
<validator id="GeomValidators_ShapeType" parameters="edge"/>
+ <validator id="GeomValidators_Intersected" parameters="angle_to"/>
</shape_selector>
<shape_selector id="angle_to"
icon="icons/Features/edge.png"
shape_types="edge"
default="">
<validator id="GeomValidators_ShapeType" parameters="edge"/>
+ <validator id="GeomValidators_Intersected" parameters="angle_from"/>
</shape_selector>
</box>
</toolbox>
GeomValidators_IntersectionSelection.h
GeomValidators_MinObjectsSelected.h
GeomValidators_ValueOrder.h
+ GeomValidators_Intersected.h
)
SET(PROJECT_SOURCES
GeomValidators_IntersectionSelection.cpp
GeomValidators_MinObjectsSelected.cpp
GeomValidators_ValueOrder.cpp
+ GeomValidators_Intersected.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// 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<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "GeomValidators_Intersected.h"
+
+#include <GeomAPI_Shape.h>
+
+#include <Events_InfoMessage.h>
+
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Feature.h>
+
+bool GeomValidators_Intersected::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& 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<ModelAPI_AttributeSelection>(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<std::string>::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;
+}
--- /dev/null
+// 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<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef GeomValidators_Intersected_H
+#define GeomValidators_Intersected_H
+
+#include <GeomValidators.h>
+
+#include <ModelAPI_AttributeValidator.h>
+#include <ModelAPI_Attribute.h>
+
+/// \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<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+};
+
+#endif
#include <GeomValidators_IntersectionSelection.h>
#include <GeomValidators_FeatureKind.h>
#include <GeomValidators_MinObjectsSelected.h>
+#include <GeomValidators_Intersected.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
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);