]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2559, 2560: use different shapes validator for points selector.
authormzn <mzn@opencascade.com>
Fri, 20 Jul 2018 10:48:06 +0000 (13:48 +0300)
committervsv <vsv@opencascade.com>
Tue, 24 Jul 2018 09:28:21 +0000 (12:28 +0300)
src/BuildPlugin/Test/TestInterpolation.py
src/BuildPlugin/Test/TestPolyline.py
src/BuildPlugin/interpolation_widget.xml
src/BuildPlugin/polyline_widget.xml
src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_Tools.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Tools.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_DifferentShapes.cpp
src/GeomValidators/GeomValidators_DifferentShapes.h

index a790170e8975b07f2fad8369c7a33166ab5d4516..805e6f97ac0c78df9627bcd11b9b3806b4bed26a 100644 (file)
@@ -100,8 +100,7 @@ model.checkBooleansResult(Interpolation_5, model, 1, [0], [0], [0], [1], [2])
 Interpolation_6 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_1], False, False)
 model.do()
 
-# TODO uncomment
-#model.testNbResults(Interpolation_6, 0)
+model.testNbResults(Interpolation_6, 0)
 
 # =============================================================================
 # Test 7. Try to create curve on a single point 3
@@ -161,11 +160,10 @@ Point_2 = model.addPoint(Part_4_doc, 0, 0, 0)
 P_1 = model.selection("VERTEX", "Point_1")
 P_2 = model.selection("VERTEX", "Point_2")
 
-# TODO uncomment
-#Interpolation_10 = model.addInterpolation(Part_4_doc, [P_1, P_2],
-#                                          False, False)
-#model.do()
-#model.testNbResults(Interpolation_10, 0)
+Interpolation_10 = model.addInterpolation(Part_4_doc, [P_1, P_2],
+                                          False, False)
+model.do()
+model.testNbResults(Interpolation_10, 0)
 
 # =============================================================================
 # Test 11. Check subshapes naming
index 622523cfb61e4551e2ed95d6eff0f0529a8711f5..578da8db79dd655a0945a5612e42c37868887551 100644 (file)
@@ -140,11 +140,10 @@ Point_2 = model.addPoint(Part_4_doc, 0, 0, 0)
 P_1 = model.selection("VERTEX", "Point_1")
 P_2 = model.selection("VERTEX", "Point_2")
 
-# TODO uncomment
-#Polyline_9 = model.addPolyline3D(Part_4_doc, [P_1, P_2], False)
-#model.do()
+Polyline_9 = model.addPolyline3D(Part_4_doc, [P_1, P_2], False)
+model.do()
 
-#model.testNbResults(Polyline_9, 0)
+model.testNbResults(Polyline_9, 0)
 
 # =============================================================================
 # Test 10. Check subshapes naming
index 4c12f2ea945c908f34f79c858c5c4f1b7b8c01b3..e5d6071ad783105464652c4bb547021585b36d22 100644 (file)
@@ -25,6 +25,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                   tooltip="Select points or vertices objects."
                   type_choice="vertices"
                   concealment="true">
+    <validator id="GeomValidators_DifferentShapes"/>
   </multi_selector>
   <boolvalue id="closed" label="Closed" tooltip="Makes the curve closed." default="false"/>
   <boolvalue id="reorder" label="Reorder" tooltip="Changes the order of points to construct the shortest curve." default="false"/>
index 4ac398d02c359320375d207c51ba9bab7d5bcb62..6f45ba36283737c06b074aa616fe6cfa67e82b8d 100644 (file)
@@ -25,6 +25,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                   tooltip="Select points or vertices objects."
                   type_choice="vertices"
                   concealment="true">
+    <validator id="GeomValidators_DifferentShapes"/>
   </multi_selector>
   <boolvalue id="closed" label="Closed" tooltip="Makes the polyline closed." default="false"/>
   <validator id="GeomValidators_MinObjectsSelected" parameters="base_objects,2"/>
index b75212b547336fce43aa271dd167dd3c54a3f2ab..7cc297767586e1fa6c14536f6478e7b804ca1eb9 100644 (file)
@@ -59,6 +59,7 @@ SET(PROJECT_HEADERS
     GeomAPI_Wire.h
     GeomAPI_Ellipse.h
     GeomAPI_Ellipse2d.h
+       GeomAPI_Tools.h
 )
 
 SET(PROJECT_SOURCES
@@ -96,6 +97,7 @@ SET(PROJECT_SOURCES
     GeomAPI_Wire.cpp
     GeomAPI_Ellipse.cpp
     GeomAPI_Ellipse2d.cpp
+       GeomAPI_Tools.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/GeomAPI/GeomAPI_Tools.cpp b/src/GeomAPI/GeomAPI_Tools.cpp
new file mode 100644 (file)
index 0000000..0825957
--- /dev/null
@@ -0,0 +1,51 @@
+// 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 "GeomAPI_Tools.h"
+
+#include "GeomAPI_Vertex.h"
+#include "GeomAPI_Edge.h"
+#include "GeomAPI_Face.h"
+#include "GeomAPI_Wire.h"
+
+//==================================================================================================
+GeomShapePtr GeomAPI_Tools::getTypedShape(const GeomShapePtr& theShape)
+{
+  GeomShapePtr aTypedShape = theShape;
+
+  GeomAPI_Shape::ShapeType aType = theShape->shapeType();
+
+  switch (theShape->shapeType()) {
+  case GeomAPI_Shape::VERTEX:
+    aTypedShape = GeomShapePtr(new GeomAPI_Vertex(theShape));
+    break;
+  case GeomAPI_Shape::EDGE:
+    aTypedShape = GeomShapePtr(new GeomAPI_Edge(theShape));
+    break;
+  case GeomAPI_Shape::FACE:
+    aTypedShape = GeomShapePtr(new GeomAPI_Face(theShape));
+    break;
+  case GeomAPI_Shape::WIRE:
+    aTypedShape = GeomShapePtr(new GeomAPI_Wire(theShape));
+    break;
+  }
+
+  return aTypedShape;
+}
diff --git a/src/GeomAPI/GeomAPI_Tools.h b/src/GeomAPI/GeomAPI_Tools.h
new file mode 100644 (file)
index 0000000..3ee2027
--- /dev/null
@@ -0,0 +1,39 @@
+// 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 GeomAPI_Tools_H_
+#define GeomAPI_Tools_H_
+
+#include "GeomAPI.h"
+#include "GeomAPI_Shape.h"
+
+/// \class GeomAPI_Tools
+/// \ingroup DataModel
+/// \brief Provides auxiliary methods for shapes processing
+class GeomAPI_Tools
+{
+public:
+  /// \brief Returns typed shape.
+  /// \param[in] theShape the shape.
+  /// \return shape of the corresponding type
+  GEOMAPI_EXPORT static GeomShapePtr getTypedShape(const GeomShapePtr& theShape);
+};
+
+#endif
\ No newline at end of file
index 75f3535004cd3e7a0c841a7d84afbf08c7da9421..985f7acf061df9d556354343f239a7d42f1bd584 100644 (file)
 #include <Events_InfoMessage.h>
 
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include "ModelAPI_Object.h"
 
 #include <GeomAPI_Shape.h>
+#include <GeomAPI_Tools.h>
 
+//=================================================================================================
 bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute,
                                       const std::list<std::string>& theArguments,
                                       Events_InfoMessage& theError) const
 {
-  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  bool isValid = false;
+
+  std::string anAttributeType = theAttribute->attributeType();
+  bool isList = anAttributeType == ModelAPI_AttributeSelectionList::typeId();
+
+  std::list<AttributePtr> anAttrs;
+  if (isList) {
+    AttributeSelectionListPtr aListAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+    // get all selection attributes from the list
+    for (int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
+      anAttrs.push_back(aListAttr->value(anIndex));
+    }
+
+    isValid = checkEquals(anAttrs);
+  }
+  else {
+    // get all feature selection attributes
+    FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+    anAttrs = aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
+
+    isValid = checkEqualToCurrent(anAttrs, theAttribute);
+  }
+
+  if (!isValid) {
+    theError = isList ? "The selection list contains equal shapes." :
+                        "The feature uses equal shapes.";
+    return false;
+  }
+
+  return true;
+}
+
+//=================================================================================================
+bool GeomValidators_DifferentShapes::checkEquals(std::list<AttributePtr>& theAttributes)
+{
+  std::list<AttributePtr>::iterator anIt = theAttributes.begin();
+  for (; anIt != theAttributes.end(); anIt++) {
+    AttributePtr anAttribute = *anIt;
+
+    std::list<AttributePtr>::iterator anOthersIt = std::next(anIt);
+    for (; anOthersIt != theAttributes.end(); anOthersIt++) {
+      AttributePtr anOtherAttribute = *anOthersIt;
+      if (isAttrShapesEqual(anAttribute, anOtherAttribute)) {
+        return false;
+      }
+    }
+  }
+
+  return true;
+}
+
+//=================================================================================================
+bool GeomValidators_DifferentShapes::checkEqualToCurrent(std::list<AttributePtr>& theAttributes,
+  const AttributePtr& theCurrentAttribute)
+{
   AttributeSelectionPtr aSelectionAttribute =
-                     std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theCurrentAttribute);
+
   GeomShapePtr aShape = aSelectionAttribute->value();
   if (!aShape.get()) {
     ResultPtr aResult = aSelectionAttribute->context();
@@ -41,13 +100,10 @@ bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute,
       aShape = aResult->shape();
   }
 
-  std::string aCurrentAttributeId = theAttribute->id();
-  // get all feature attributes
-  std::list<AttributePtr> anAttrs =
-      aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
-  if (anAttrs.size() > 0 && aShape.get() != NULL) {
-    std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
-    for(; anAttr != anAttrs.end(); anAttr++) {
+  std::string aCurrentAttributeId = theCurrentAttribute->id();
+  if (theAttributes.size() > 0 && aShape.get() != NULL) {
+    std::list<AttributePtr>::iterator anAttr = theAttributes.begin();
+    for (; anAttr != theAttributes.end(); anAttr++) {
       AttributePtr anAttribute = *anAttr;
       // take into concideration only other attributes
       if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) {
@@ -62,12 +118,39 @@ bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute,
               anAttrShape = aResult->shape();
           }
           if (aShape->isEqual(anAttrShape)) {
-            theError = "The feature uses equal shapes.";
             return false;
           }
         }
       }
     }
   }
+
   return true;
 }
+
+bool GeomValidators_DifferentShapes::isAttrShapesEqual(const AttributePtr& theAttribute,
+                                                       const AttributePtr& theOtherAttribute)
+{
+  AttributeSelectionPtr aSelectionAttribute =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  AttributeSelectionPtr anOtherSelectionAttribute =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theOtherAttribute);
+
+  GeomShapePtr aShape = aSelectionAttribute->value();
+  if (!aShape.get()) {
+    ResultPtr aResult = aSelectionAttribute->context();
+    if (aResult.get())
+      aShape = aResult->shape();
+  }
+  GeomShapePtr aTypedShape = GeomAPI_Tools::getTypedShape(aShape);
+
+  GeomShapePtr anOtherShape = anOtherSelectionAttribute->value();
+  if (!anOtherShape.get()) {
+    ResultPtr aResult = anOtherSelectionAttribute->context();
+    if (aResult.get())
+      anOtherShape = aResult->shape();
+  }
+  GeomShapePtr aOtherTypedShape = GeomAPI_Tools::getTypedShape(anOtherShape);
+
+  return aTypedShape->isEqual(aOtherTypedShape);
+}
\ No newline at end of file
index 737a2f63d1b721973db52d322ac84575829774a1..f1d826cc4430c7c3ff78f23fc91caae369462439 100644 (file)
@@ -40,6 +40,16 @@ public:
   GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
                                              const std::list<std::string>& theArguments,
                                              Events_InfoMessage& theError) const;
+
+private:
+  /// Check if the list contains equal shape selection.
+  static bool checkEquals(std::list<AttributePtr>& theAttributes);
+  /// Check if the list contains shape selection equal to the given one.
+  static bool checkEqualToCurrent(std::list<AttributePtr>& theAttributes,
+                                  const AttributePtr& theCurrentAttribute);
+  /// Check if shapes corresponding to the attributes are equal.
+  static bool isAttrShapesEqual(const AttributePtr& theAttribute,
+                                const AttributePtr& theOtherAttribute);
 };
 
 #endif