]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #222 - correction to do not select the same parameters in the distance constraint.
authornds <natalia.donis@opencascade.com>
Wed, 5 Nov 2014 10:01:48 +0000 (13:01 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 5 Nov 2014 10:01:48 +0000 (13:01 +0300)
refs #196 - return an empty preview presentation if the parameters are invalid.

src/ModelAPI/ModelAPI_RefAttrValidator.h
src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp
src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index e5b1b6690ed968315e3ca3e36bec7b1e580c22fe..1f690ca47445e1597ca3584946a7fa14a6eda265 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_Attribute.h>
 #include <ModelAPI_AttributeValidator.h>
 
 /*
@@ -18,6 +19,11 @@ public:
   //! Returns true if object is good for the feature attribute
   virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
                        const ObjectPtr& theObject) const = 0;
+
+  //! Returns true if the attribute is good for the feature attribute
+  virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
+                       const AttributePtr& theAttribute) const = 0;
+
 };
 
 #endif
index d9674c4d45d7e0856c33fed4b493c160f280f8f8..cea8d1ec49bc7c75adcb7dacc1131ceaec1d6580 100644 (file)
@@ -7,6 +7,9 @@
 #include <ModuleBase_WidgetValueFeature.h>
 #include <ModuleBase_WidgetValue.h>
 
+#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_Session.h>
+
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
 
@@ -49,30 +52,16 @@ bool ModuleBase_WidgetFeatureOrAttribute::setValue(ModuleBase_WidgetValue* theVa
     ModuleBase_WidgetValueFeature* aFeatureValue =
         dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
     if (aFeatureValue) {
-      boost::shared_ptr<GeomAPI_Pnt2d> aValuePoint = aFeatureValue->point();
       ObjectPtr aObject = aFeatureValue->object();
-      if (aObject) {
-        isDone = setObject(aObject, false);
+
+      boost::shared_ptr<ModelAPI_Attribute> anAttribute = findAttribute(aFeatureValue);
+      if (anAttribute) {
+        isDone = setAttribute(anAttribute, false);
       }
-      if (aValuePoint) {
-        FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
-        if (aFeature) {
-          // find the given point in the feature attributes
-          std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes = aFeature->data()
-              ->attributes(GeomDataAPI_Point2D::type());
-          std::list<boost::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes
-              .begin(), aLast = anAttiributes.end();
-          boost::shared_ptr<GeomDataAPI_Point2D> aFPoint;
-          for (; anIt != aLast && !aFPoint; anIt++) {
-            boost::shared_ptr<GeomDataAPI_Point2D> aCurPoint = boost::dynamic_pointer_cast<
-                GeomDataAPI_Point2D>(*anIt);
-            if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion())
-              aFPoint = aCurPoint;
-          }
-          if (aFPoint)
-            isDone = setAttribute(aFPoint, false);
-        }
+      else if (aObject) {
+        isDone = setObject(aObject, false);
       }
+
       if (isDone)
         emit valuesChanged();
     }
@@ -125,12 +114,62 @@ bool ModuleBase_WidgetFeatureOrAttribute::restoreValue()
   return false;
 }
 
+boost::shared_ptr<ModelAPI_Attribute> ModuleBase_WidgetFeatureOrAttribute::findAttribute(
+                                                        ModuleBase_WidgetValue* theValue)
+{
+  boost::shared_ptr<ModelAPI_Attribute> anAttribute;
+  ModuleBase_WidgetValueFeature* aFeatureValue =
+                                  dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
+  if (!aFeatureValue)
+    return anAttribute;
+
+  boost::shared_ptr<GeomAPI_Pnt2d> aValuePoint = aFeatureValue->point();
+  if (aValuePoint) {
+    ObjectPtr aObject = aFeatureValue->object();
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
+    if (aFeature) {
+      // find the given point in the feature attributes
+      std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes = aFeature->data()
+          ->attributes(GeomDataAPI_Point2D::type());
+      std::list<boost::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes
+          .begin(), aLast = anAttiributes.end();
+      for (; anIt != aLast && !anAttribute; anIt++) {
+        boost::shared_ptr<GeomDataAPI_Point2D> aCurPoint = boost::dynamic_pointer_cast<
+            GeomDataAPI_Point2D>(*anIt);
+        if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion())
+          anAttribute = aCurPoint;
+      }
+    }
+  }
+  return anAttribute;
+}
+
 bool ModuleBase_WidgetFeatureOrAttribute::setAttribute(
     const boost::shared_ptr<ModelAPI_Attribute>& theAttribute, bool theSendEvent)
 {
   if (!theAttribute)  // || !featureKinds().contains(theAttribute->attributeType().c_str()))
     return false;
 
+  SessionPtr aMgr = ModelAPI_Session::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  std::list<ModelAPI_Validator*> aValidators;
+  std::list<std::list<std::string> > anArguments;
+  aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
+
+  // Check the acceptability of the attribute
+  std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
+  int aSize = aValidators.size();
+  std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
+  for (; aValidator != aValidators.end(); aValidator++, aArgs++) {
+    const ModelAPI_RefAttrValidator* aAttrValidator =
+        dynamic_cast<const ModelAPI_RefAttrValidator*>(*aValidator);
+    if (aAttrValidator) {
+      if (!aAttrValidator->isValid(myFeature, *aArgs, theAttribute)) {
+        return false;
+      }
+    }
+  }
+
   myAttribute = theAttribute;
   editor()->setText(theAttribute ? theAttribute->attributeType().c_str() : "");
   if (theSendEvent)
index 9774bd20554d99f967b80b57e6c472664f08945d..1dfd055ceb48f2b8699942cc7e59ec4f927cd5c9 100644 (file)
@@ -44,6 +44,11 @@ Q_OBJECT
   virtual bool isViewerSelector() { return true; }
 
  protected:
+   /// Returns the feature attribute if it can be found by the given value
+   /// \param theValue the widget value
+   /// \return an attribute or null
+   boost::shared_ptr<ModelAPI_Attribute> findAttribute(ModuleBase_WidgetValue* theValue);
+
   /// Set the attribute
   /// \param theAttribute value
   /// \return the boolean result of the attribute set
index 0ce7f355819270fc6de275b53f44d6fe1839a120..031a3b98b7a08107a74fc85e088c80a403430f11 100644 (file)
@@ -101,8 +101,8 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi
       aPnt_B = getProjectionPoint(aLine, aPnt_A);
     }
   }
-  if (!aPnt_A || !aPnt_B || aPnt_A->isEqual(aPnt_B))
-    return thePrevious;
+  if (!aPnt_A || !aPnt_B)
+    return AISObjectPtr();
 
   boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = boost::dynamic_pointer_cast<
       GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
index b71d5adbd69b29d7baf6f03b3c0e9e924ebe2fc9..822ddaf6ceb365cb404720053783280fb16a25d7 100644 (file)
@@ -89,3 +89,21 @@ bool SketchPlugin_DifferentObjectsValidator::isValid(
   }
   return true;
 }
+
+bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
+  const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
+{
+  std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttrs = 
+    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+  std::list<boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+  for(; anAttr != anAttrs.end(); anAttr++) {
+    if (*anAttr) {
+      boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
+        boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+      // check the object is already presented
+      if (!aRef->isObject() && aRef->attr() == theAttribute)
+        return false;
+    }
+  }
+  return true;
+}
index d8dcba2e0d3782936b042374d5eedae5625bd207..14647fa71b35f372f84e8844b3996cb067950b0d 100644 (file)
@@ -20,6 +20,9 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator
   virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
                        const ObjectPtr& theObject) const;
 
+  //! Returns true if the attribute is good for the feature attribute
+  virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
+                       const AttributePtr& theAttribute) const { return true; };
 };
 
 /**
@@ -37,7 +40,9 @@ class SketchPlugin_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
   //! Returns true if object is good for the feature attribute
   virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
                        const ObjectPtr& theObject) const;
-
+  //! Returns true if the attribute is good for the feature attribute
+  virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
+                       const AttributePtr& theAttribute) const;
 };
 
 #endif
index 14deb7083d3773f5f4e14cba643c2e9e284c1ee5..82ba507be416c1da2d605d16569da7d85cbd66d6 100644 (file)
         <feature_or_attribute_selector id="ConstraintEntityA" label="First object" tooltip="Select point, line end point, line, center of circle or arc.">
           <validator id="SketchPlugin_ResultPoint"/>
           <validator id="SketchPlugin_ResultLine"/>
+          <validator id="SketchPlugin_DifferentObjects"/>
         </feature_or_attribute_selector>
         <feature_or_attribute_selector id="ConstraintEntityB" label="Last object" tooltip="Select point, line end point, line, center of circle or arc.">
           <validator id="SketchPlugin_ResultPoint"/>
           <validator id="SketchPlugin_ResultLine"/>
           <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
+          <validator id="SketchPlugin_DifferentObjects"/>
         </feature_or_attribute_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
-        <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed">
+        <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed" min="0">
           <validator id="GeomValidators_Positive"/>
         </doublevalue_editor>
         <validator id="PartSet_DistanceValidator"/>