Salome HOME
Issue #2547: Measurement - Angle – if selected pair of edges do not intersect, add...
authorazv <azv@opencascade.com>
Wed, 4 Jul 2018 05:43:04 +0000 (08:43 +0300)
committerazv <azv@opencascade.com>
Wed, 4 Jul 2018 05:43:04 +0000 (08:43 +0300)
Special validator to avoid selecting non-intersected edges has been implemented.

src/FeaturesPlugin/measurement_widget.xml
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_Intersected.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_Intersected.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Plugin.cpp

index 22c557b1d6f5ded91eb89d3d3b7363f9563e0b27..e16856771aea77c02f3393eb0238715d6f5bb88e 100644 (file)
@@ -65,6 +65,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                       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"
@@ -73,6 +74,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                       shape_types="edge"
                       default="">
         <validator id="GeomValidators_ShapeType" parameters="edge"/>
+        <validator id="GeomValidators_Intersected" parameters="angle_from"/>
       </shape_selector>
     </box>
   </toolbox>
index 3b343b2926f792021ec168c46ce8dc59e0c782ea..ddc6baa0fef93085d9e4447e8624f367ae40e8c0 100644 (file)
@@ -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 (file)
index 0000000..aeef9bd
--- /dev/null
@@ -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<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;
+}
diff --git a/src/GeomValidators/GeomValidators_Intersected.h b/src/GeomValidators/GeomValidators_Intersected.h
new file mode 100644 (file)
index 0000000..18e8313
--- /dev/null
@@ -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<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
index 54ee61429f09e152bde94df11b0c9ebfb27b25d8..2bf421fa055a052270fd028456982a4e5000008d 100644 (file)
@@ -33,6 +33,7 @@
 #include <GeomValidators_IntersectionSelection.h>
 #include <GeomValidators_FeatureKind.h>
 #include <GeomValidators_MinObjectsSelected.h>
+#include <GeomValidators_Intersected.h>
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
@@ -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);