]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2405: Fatal error when create Length constraint on axis
authorazv <azv@opencascade.com>
Mon, 22 Jan 2018 10:51:53 +0000 (13:51 +0300)
committerazv <azv@opencascade.com>
Mon, 22 Jan 2018 10:51:53 +0000 (13:51 +0300)
Created a validator to avoid selection of non-sketch features as objects of the Length constraints

src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index ecc760c1e5226c889f900364e39efa826013e1c5..3181dd460568fbba944963df8f1977325c95e539 100644 (file)
@@ -136,6 +136,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
   aFactory->registerValidator("SketchPlugin_HasNoConstraint", new SketchPlugin_HasNoConstraint);
   aFactory->registerValidator("SketchPlugin_ReplicationReference",
                               new SketchPlugin_ReplicationReferenceValidator);
+  aFactory->registerValidator("SketchPlugin_SketchFeatureValidator",
+                              new SketchPlugin_SketchFeatureValidator);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index 3c6fcc3471828c096c8eab647290c5953d7dcec4..91728508f83ced9e58f1bb6d9221c842cdde3c34 100755 (executable)
@@ -1609,3 +1609,34 @@ bool SketchPlugin_ReplicationReferenceValidator::isValid(
 
   return true;
 }
+
+bool SketchPlugin_SketchFeatureValidator::isValid(const AttributePtr& theAttribute,
+                                                  const std::list<std::string>& theArguments,
+                                                  Events_InfoMessage& theError) const
+{
+  if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+    theError = "The attribute with the %1 type is not processed";
+    theError.arg(theAttribute->attributeType());
+    return false;
+  }
+
+  // check the attribute refers to a sketch feature
+  AttributeRefAttrPtr aRefAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  bool isSketchFeature = aRefAttr->isObject();
+  if (isSketchFeature) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+    isSketchFeature = aFeature;
+    if (isSketchFeature) {
+      std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+          std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+      isSketchFeature = aSketchFeature;
+    }
+  }
+
+  if (isSketchFeature)
+    return true;
+
+  theError = "The object selected is not a sketch feature";
+  return false;
+}
index d2cf26bbc29580efa7fcd08ff55edb5277586eb4..56ab74b7a236a5e18fecf8e52a0b58448a53b353 100644 (file)
@@ -464,4 +464,20 @@ class SketchPlugin_ReplicationReferenceValidator: public ModelAPI_AttributeValid
                        Events_InfoMessage& theError) const;
 };
 
+/**\class SketchPlugin_SketchFeatureValidator
+ * \ingroup Validators
+ * \brief Validator for checking whether the feature referred by attribute is a sketch feature.
+ */
+class SketchPlugin_SketchFeatureValidator: public ModelAPI_AttributeValidator
+{
+ public:
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  //! \param theError error message
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments,
+                       Events_InfoMessage& theError) const;
+};
+
 #endif
index 6b728d2730f78dc1e15a846efe39d6b628ee2ee8..5da3a4645c3e89123c32d8d138da89931baee82e 100644 (file)
@@ -769,6 +769,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
         <label title="Select a line on which to calculate length" tooltip="Select a line on which to calculate length"/>
         <shape_selector id="ConstraintEntityA" label="Line" tooltip="Select a line" shape_types="edge" >
           <validator id="GeomValidators_ShapeType" parameters="line"/>
+          <validator id="SketchPlugin_SketchFeatureValidator"/>
         </shape_selector>
         <sketch-2dpoint_flyout_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
         <doublevalue_editor label="Value" tooltip="Length" id="ConstraintValue" default="computed">