Added validator that checks the cut arguments for self-intersection.
<validator id="FeaturesPlugin_ValidatorBooleanSelection"/>
</multi_selector>
<validator id="FeaturesPlugin_ValidatorBooleanArguments" parameters="main_objects,tool_objects"/>
+ <validator id="GeomValidators_NotSelfIntersected" parameters="main_objects,tool_objects"/>
</source>
#include <TopoDS_Shape.hxx>
#include <NCollection_List.hxx>
+#include <BOPAlgo_CheckerSI.hxx>
+#include <BOPDS_DS.hxx>
+
#include <sstream>
#include <algorithm> // for std::transform
TopoDS_Shape aResult = MY_SHAPE->Moved(aTranslation);
setImpl(new TopoDS_Shape(aResult));
}
+
+bool GeomAPI_Shape::isSelfIntersected(const int theLevelOfCheck) const
+{
+ BOPAlgo_CheckerSI aCSI; // checker of self-interferences
+ aCSI.SetLevelOfCheck(theLevelOfCheck);
+ TopTools_ListOfShape aList;
+ const TopoDS_Shape& aThisShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ aList.Append(aThisShape);
+ aCSI.SetArguments(aList);
+ aCSI.Perform();
+ if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0) {
+ return true;
+ }
+
+ return false;
+}
/// Returns type of shapes in the compound.
// If shapes are of different type then it will return SHAPE type
GEOMAPI_EXPORT ShapeType typeOfCompoundShapes() const;
+
+ /// Returns true if shape have self-intersections.
+ /// \param[in] theLevelOfCheck defines which interferences will be checked:<br>
+ /// 0 - only V/V;<br>
+ /// 1 - V/V and V/E;<br>
+ /// 2 - V/V, V/E and E/E;<br>
+ /// 3 - V/V, V/E, E/E and V/F;<br>
+ /// 4 - V/V, V/E, E/E, V/F and E/F;<br>
+ /// 5 - V/V, V/E, E/E, V/F, E/F and F/F;<br>
+ /// 6 - V/V, V/E, E/E, V/F, E/F, F/F and V/S;<br>
+ /// 7 - V/V, V/E, E/E, V/F, E/F, F/F, V/S and E/S;<br>
+ /// 8 - V/V, V/E, E/E, V/F, E/F, F/F, V/S, E/S and F/S;<br>
+ /// 9 - V/V, V/E, E/E, V/F, E/F, F/F, V/S, E/S, F/S and S/S - all interferences (Default value)
+ GEOMAPI_EXPORT bool isSelfIntersected(const int theLevelOfCheck = 9) const;
};
//! Pointer on list of shapes
GeomValidators_MinObjectsSelected.h
GeomValidators_ValueOrder.h
GeomValidators_Intersected.h
+ GeomValidators_NotSelfIntersected.h
)
SET(PROJECT_SOURCES
GeomValidators_MinObjectsSelected.cpp
GeomValidators_ValueOrder.cpp
GeomValidators_Intersected.cpp
+ GeomValidators_NotSelfIntersected.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_NotSelfIntersected.h"
+
+#include <GeomAPI_Shape.h>
+
+#include <Events_InfoMessage.h>
+
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>>
+#include <ModelAPI_Feature.h>
+
+bool GeomValidators_NotSelfIntersected::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ if (theArguments.empty()) {
+ theError = "Error: empty selection.";
+ return false;
+ }
+
+ for (std::list<std::string>::const_iterator anIt = theArguments.cbegin();
+ anIt != theArguments.cend();
+ ++anIt)
+ {
+ std::string anArgument = *anIt;
+ AttributePtr anAttribute = theFeature->attribute(anArgument);
+ if (!anAttribute.get()) {
+ theError = std::string("Error: Feature does not contain attribute: ") + anArgument;
+ return false;
+ }
+ if (anAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) {
+ AttributeSelectionListPtr anAttrSelectionList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
+ 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()) {
+ FeaturePtr aContFeat = anAttrSelection->contextFeature();
+ if (!aContFeat.get() || !aContFeat->results().size()) {
+ theError = "Error: Empty selection context.";
+ return false;
+ }
+ }
+ std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+ if (!aShape.get() && aContext.get()) {
+ GeomShapePtr aContextShape = aContext->shape();
+ aShape = aContextShape;
+ }
+ if (!aShape.get()) {
+ theError = "Error: Empty shape.";
+ return false;
+ }
+
+ if (aShape->isSelfIntersected()) {
+ theError = "Error: One of selected shapes are self-intersected.";
+ return false;
+ }
+ }
+ }
+ else {
+ theError = std::string("Error: validator does not support attribute with type: ")
+ + anAttribute->attributeType();
+ }
+ }
+}
+
+bool GeomValidators_NotSelfIntersected::isNotObligatory(std::string /*theFeature*/,
+ std::string /*theAttribute*/)
+{
+ return false;
+}
--- /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_NotSelfIntersected_H
+#define GeomValidators_NotSelfIntersected_H
+
+#include <GeomValidators.h>
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_FeatureValidator.h>
+
+/// \class GeomValidators_NotSelfIntersected
+/// \ingroup Validators
+/// \brief Validates that selected shapes are not self intersected.
+class GeomValidators_NotSelfIntersected: public ModelAPI_FeatureValidator
+{
+public:
+ /// \return True if the attribute is valid. It checks whether the selection
+ /// is not self intersected.
+ /// \param[in] theAttribute an attribute to check.
+ /// \param[in] theArguments a filter parameters.
+ /// \param[out] theError error message.
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+
+ /// \return true if the attribute in feature is not obligatory for the feature execution.
+ GEOMVALIDATORS_EXPORT virtual bool isNotObligatory(std::string theFeature,
+ std::string theAttribute);
+};
+
+#endif
#include <GeomValidators_FeatureKind.h>
#include <GeomValidators_MinObjectsSelected.h>
#include <GeomValidators_Intersected.h>
+#include <GeomValidators_NotSelfIntersected.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
aFactory->registerValidator("GeomValidators_MinObjectsSelected",
new GeomValidators_MinObjectsSelected);
aFactory->registerValidator("GeomValidators_Intersected", new GeomValidators_Intersected);
+ aFactory->registerValidator("GeomValidators_NotSelfIntersected",
+ new GeomValidators_NotSelfIntersected);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);