]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1058 Crash when creating a distance between source and translated elements
authornds <nds@opencascade.com>
Tue, 11 Jul 2017 10:26:36 +0000 (13:26 +0300)
committernds <nds@opencascade.com>
Tue, 11 Jul 2017 10:26:36 +0000 (13:26 +0300)
Additionally a new equal points validator is implemented for distance constraint to avoid crash on selection coincident(equal) points of different segments.

src/ModuleBase/ModuleBase_WidgetEditor.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Validators.cpp
src/PartSet/PartSet_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index 93004ec366ec95c898638f064fc8905b7ea3ef38..e017a507d77ba6cc0ef0cc39e8ecb75f7db3b54e 100644 (file)
@@ -102,7 +102,7 @@ bool ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText)
 bool ModuleBase_WidgetEditor::focusTo()
 {
   showPopupEditor();
-  return true;
+  return false;
 }
 
 bool ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals)
index bd88803878d9e0690addcc0f7c83764a1388ce5e..3cc5c73ab56937be16e516537be005bb4d13fa83 100755 (executable)
@@ -255,6 +255,7 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
   aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
+  aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
   aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
   aFactory->registerValidator("PartSet_MultyTranslationSelection",
     new PartSet_MultyTranslationSelection);
index 178a4bfd49f2e74ecf0ba7a59b7b014e447f5af1..b2f95ddd3f665a4bc4871e814c7ba1e63996cd8b 100755 (executable)
@@ -33,6 +33,9 @@
 #include <ModuleBase_OperationFeature.h>
 #include <ModuleBase_ViewerPrs.h>
 
+#include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pnt2d.h>
+
 #include <Events_InfoMessage.h>
 
 #include <ModelAPI_AttributeRefAttr.h>
@@ -48,6 +51,7 @@
 #include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Point.h>
 #include <GeomAPI_Edge.h>
 
 #include <list>
@@ -609,6 +613,56 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
   return true;
 }
 
+bool PartSet_DifferentPointsValidator::isValid(const AttributePtr& theAttribute,
+                                               const std::list<std::string>& theArguments,
+                                               Events_InfoMessage& theError) const
+{
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+
+  // the type of validated attributes should be equal, attributes with
+  // different types are not validated
+  // Check RefAttr attributes
+  std::string anAttrType = theAttribute->attributeType();
+  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs;
+  if (anAttrType != ModelAPI_AttributeRefAttr::typeId())
+    return true;
+
+  // obtain point of the given attribute
+  AttributePoint2DPtr anAttributePoint = getRefPointAttribute(theAttribute);
+  if (!anAttributePoint.get() || !anAttributePoint->isInitialized())
+    return true;
+
+  // obtain point of the parameter attribute
+  AttributePoint2DPtr anArgumentPoint = getRefPointAttribute
+                                              (aFeature->attribute(theArguments.front()));
+
+  if (!anArgumentPoint.get() || !anArgumentPoint->isInitialized())
+    return true;
+
+  return !anAttributePoint->pnt()->isEqual(anArgumentPoint->pnt());
+}
+
+AttributePoint2DPtr PartSet_DifferentPointsValidator::getRefPointAttribute
+                                                     (const AttributePtr& theAttribute) const
+{
+  AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+
+  AttributePoint2DPtr aPointAttribute;
+  if (anAttr->isObject()) {
+    ObjectPtr anObject  = anAttr->object();
+    if (anObject.get()) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+      if (aFeature->getKind() == SketchPlugin_Point::ID())
+        aPointAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                          (aFeature->attribute(SketchPlugin_Point::COORD_ID()));
+    }
+  }
+  else {
+    aPointAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+  }
+  return aPointAttribute;
+}
+
 bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute,
                                      const std::list<std::string>& theArguments,
                                      Events_InfoMessage& theError) const
index a14456c4a933cbe5b4325184b7c0e3714ecb9b60..039d259ca9536dec339feab3d2f9cfb4b592225d 100644 (file)
@@ -27,6 +27,8 @@
 #include <ModuleBase_ISelection.h>
 #include <ModelAPI_AttributeValidator.h>
 
+class GeomDataAPI_Point2D;
+
 /*
  * Selector validators
  */
@@ -220,6 +222,34 @@ private:
 
 };
 
+/**
+* \ingroup Validators
+* A validator which checks that Point2D selected for feature attributes are different (not the same)
+* It iterates by the feature ModelAPI_AttributeRefAttr attributes, finds GeomDataAPI_Point2D attribute in
+* value or attribute of the attributes and if the point of the given attribute is geometrical equal to
+* a point of another attribute, returns false
+*/
+class PartSet_DifferentPointsValidator : public ModelAPI_AttributeValidator
+{
+ public:
+  //! Returns true if the attribute is good for the feature attribute
+  //! \param theAttribute an attribute
+  //! \param theArguments a list of arguments (names of attributes to check)
+  //! \param theError an output error string
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments,
+                       Events_InfoMessage& theError) const;
+private:
+  //! Finds Point2D attribute by reference attribute. It might be:
+  //! - COORD_ID attribute of SketchPlugin_Point if object
+  //! - Attribute casted to point if attribute
+  //! \param theAttribute an attribute
+  //! \return point 2d attribute or NULL
+  std::shared_ptr<GeomDataAPI_Point2D> getRefPointAttribute
+                      (const AttributePtr& theAttribute) const;
+};
+
+
 /**\class PartSet_CoincidentAttr
  * \ingroup Validators
  * \brief Validator to check whether there is a coincident constraint between
index d5b54374a8d3cf23466780e3e88683a88812ca6c..863d825318fe9659776d706eab9459a9ef2f6568 100644 (file)
@@ -545,6 +545,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
           <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
           <validator id="PartSet_DifferentObjects"/>
           <validator id="GeomValidators_ShapeType" parameters="vertex,line"/>
+          <validator id="PartSet_DifferentPoints" parameters="ConstraintEntityB"/>
         </sketch_shape_selector>
         <sketch_shape_selector
           id="ConstraintEntityB"
@@ -555,6 +556,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
           <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
           <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
           <validator id="GeomValidators_ShapeType" parameters="vertex,line"/>
+          <validator id="PartSet_DifferentPoints" parameters="ConstraintEntityA"/>
         </sketch_shape_selector>
         <sketch-2dpoint_flyout_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>