]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2608: Invalid shape when select compound as a tool object for cut
authordbv <dbv@opencascade.com>
Thu, 30 Aug 2018 07:59:45 +0000 (10:59 +0300)
committerdbv <dbv@opencascade.com>
Thu, 30 Aug 2018 08:00:01 +0000 (11:00 +0300)
Added validator that checks the cut arguments for self-intersection.

src/FeaturesPlugin/boolean_widget.xml
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_NotSelfIntersected.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_NotSelfIntersected.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Plugin.cpp

index e584a531facc839e3e9739c7fc6cf2e6a8f757fe..4e82542b9477e726b1fe50803358c7600737a95d 100644 (file)
@@ -41,4 +41,5 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
     <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>
index fc736ac749e379a753d92ebd081d988d59d5430b..4cde5e7361172393638f9787bf1a8a9012eda14e 100644 (file)
@@ -50,6 +50,9 @@
 #include <TopoDS_Shape.hxx>
 #include <NCollection_List.hxx>
 
+#include <BOPAlgo_CheckerSI.hxx>
+#include <BOPDS_DS.hxx>
+
 #include <sstream>
 #include <algorithm> // for std::transform
 
@@ -628,3 +631,19 @@ void GeomAPI_Shape::translate(const std::shared_ptr<GeomAPI_Dir> theDir, const d
   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;
+}
index 66e6a2aad465b963fba77d43aa9bc1f86fb3c32e..4091f5911daf398359f7699c1fc7c567ea133e8c 100644 (file)
@@ -200,6 +200,20 @@ public:
   /// 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
index 8de30586a278afbfd89a29b758e86d4f3fc687ac..85527474ee0c0ee69d3903a1a19228be3331a348 100644 (file)
@@ -38,6 +38,7 @@ SET(PROJECT_HEADERS
     GeomValidators_MinObjectsSelected.h
     GeomValidators_ValueOrder.h
     GeomValidators_Intersected.h
+    GeomValidators_NotSelfIntersected.h
 )
 
 SET(PROJECT_SOURCES
@@ -57,6 +58,7 @@ SET(PROJECT_SOURCES
     GeomValidators_MinObjectsSelected.cpp
     GeomValidators_ValueOrder.cpp
     GeomValidators_Intersected.cpp
+    GeomValidators_NotSelfIntersected.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/GeomValidators/GeomValidators_NotSelfIntersected.cpp b/src/GeomValidators/GeomValidators_NotSelfIntersected.cpp
new file mode 100644 (file)
index 0000000..e3032b6
--- /dev/null
@@ -0,0 +1,94 @@
+// 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;
+}
diff --git a/src/GeomValidators/GeomValidators_NotSelfIntersected.h b/src/GeomValidators/GeomValidators_NotSelfIntersected.h
new file mode 100644 (file)
index 0000000..1244389
--- /dev/null
@@ -0,0 +1,49 @@
+// 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
index 3a0d06ee0cb125c88d2a3170077cc67ac5f05b1e..733fc17bf384b193aec4fecd1c625be21f950a84 100644 (file)
@@ -32,6 +32,7 @@
 #include <GeomValidators_FeatureKind.h>
 #include <GeomValidators_MinObjectsSelected.h>
 #include <GeomValidators_Intersected.h>
+#include <GeomValidators_NotSelfIntersected.h>
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
@@ -61,6 +62,8 @@ GeomValidators_Plugin::GeomValidators_Plugin()
   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);