]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make impossible selection of the same line twice for parallel and perpendicular const...
authormpv <mikhail.ponikarov@opencascade.com>
Wed, 17 Sep 2014 12:11:52 +0000 (16:11 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Wed, 17 Sep 2014 12:11:52 +0000 (16:11 +0400)
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index 1b0730b7632337cbc3ab9fba0005199bb0480f51..40749b1919a6a57ee935ac70d29391548ebe6ca6 100644 (file)
@@ -27,11 +27,13 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
 {
   SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-  aFactory->registerValidator("SketchPlugin_DistanceAttrValidator",
+  aFactory->registerValidator("SketchPlugin_DistanceAttr",
                               new SketchPlugin_DistanceAttrValidator);
-  aFactory->registerValidator("SketchPlugin_ResultPointValidator", new SketchPlugin_ResultPointValidator);
-  aFactory->registerValidator("SketchPlugin_ResultLineValidator", new SketchPlugin_ResultLineValidator);
-  aFactory->registerValidator("SketchPlugin_ResultArcValidator", new SketchPlugin_ResultArcValidator);
+  aFactory->registerValidator("SketchPlugin_DifferentObjects",
+                              new SketchPlugin_DifferentObjectsValidator);
+  aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator);
+  aFactory->registerValidator("SketchPlugin_ResultLine", new SketchPlugin_ResultLineValidator);
+  aFactory->registerValidator("SketchPlugin_ResultArc", new SketchPlugin_ResultArcValidator);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index 94e5676f55f81fe56da609dedc5288e681207b1a..855ac9ab0584a88b7e92713fce7b8f9127f854cb 100644 (file)
@@ -8,6 +8,7 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_ResultValidator.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeRefAttr.h>
 #include <GeomDataAPI_Point2D.h>
 
 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
@@ -43,3 +44,47 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
   }
   return true; // it may be not reference attribute, in this case, it is OK
 }
+
+bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
+                                                 const std::list<std::string>& theArguments,
+                                                 const ObjectPtr& theObject) 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->object() == theObject)
+        return false;
+    }
+  }
+  return true;
+}
+
+bool SketchPlugin_DifferentObjectsValidator::isValid(
+  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+{
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  if (anOrigAttr && anOrigAttr->isObject()) {
+    const ObjectPtr& anObj = theAttribute->owner();
+    const FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+
+    std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttrs = 
+      aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+    std::list<boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+    for(; anAttr != anAttrs.end(); anAttr++) {
+      if (*anAttr && *anAttr != theAttribute) {
+        boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
+          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+        // check the object is already presented
+        if (aRef->isObject() && aRef->object() == anOrigAttr->object())
+          return false;
+      }
+    }
+  }
+  return true;
+}
index ece17e599458521ebe075ebc4b23e284ee655b84..d8dcba2e0d3782936b042374d5eedae5625bd207 100644 (file)
@@ -22,4 +22,22 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator
 
 };
 
+/**
+ * Check that there is no same object was already selected in the feature.
+ * For an example: to avoid perpendicularity on line and the same line.
+ */
+class SketchPlugin_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
+{
+ public:
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  virtual bool isValid(
+    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
+  //! 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;
+
+};
+
 #endif
index 47b2ccbe3a563a1f58f1b7267eee42262545fe0b..412944f03da4f305a980612b92357db790225f7d 100644 (file)
       <feature id="SketchConstraintDistance" title="Distance" tooltip="Create constraint for the distance from a point to an object" icon=":icons/distance.png">
         <label title="Select objects for distance difinition. Following objects can be accepted: point, line end point, line, center of circle or arc."/>
         <feature_or_attribute_selector id="ConstraintEntityA" label="First object" tooltip="Select point, line end point, line, center of circle or arc.">
-          <validator id="SketchPlugin_ResultPointValidator"/>
-          <validator id="SketchPlugin_ResultLineValidator"/>
+          <validator id="SketchPlugin_ResultPoint"/>
+          <validator id="SketchPlugin_ResultLine"/>
         </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_ResultPointValidator"/>
-          <validator id="SketchPlugin_ResultLineValidator"/>
-          <validator id="SketchPlugin_DistanceAttrValidator" parameters="ConstraintEntityA"/>
+          <validator id="SketchPlugin_ResultPoint"/>
+          <validator id="SketchPlugin_ResultLine"/>
+          <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
         </feature_or_attribute_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
@@ -47,7 +47,7 @@
       <feature id="SketchConstraintLength" title="Length" tooltip="Create constraint for the given length of a line segment" icon=":icons/length.png">
         <label title="Select a line on which to calculate lenght" tooltip="Select a line on which to calculate lenght"/>
         <feature_selector id="ConstraintEntityA" label="Line" tooltip="Select an line in the viewer">
-          <validator id="SketchPlugin_ResultLineValidator"/>
+          <validator id="SketchPlugin_ResultLine"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
@@ -57,7 +57,7 @@
       <feature id="SketchConstraintRadius" title="Radius" tooltip="Create constraint for the given radius of a circle or an arc" icon=":icons/radius_constr.png">
         <label title="Select a circle or an arc on which to calculate radius" tooltip="Select a circle or an arc on which to calculate radius"/>
         <feature_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc in the viewer">
-          <validator id="SketchPlugin_ResultArcValidator"/>
+          <validator id="SketchPlugin_ResultArc"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
       
       <feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines" icon=":icons/parallel.png">
         <feature_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer">
-          <validator id="SketchPlugin_ResultLineValidator"/>
+          <validator id="SketchPlugin_ResultLine"/>
+          <validator id="SketchPlugin_DifferentObjects"/>
         </feature_selector>
         <feature_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer">
-          <validator id="SketchPlugin_ResultLineValidator"/>
+          <validator id="SketchPlugin_ResultLine"/>
+          <validator id="SketchPlugin_DifferentObjects"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <validator id="PartSet_ParallelValidator"/>
       
       <feature id="SketchConstraintPerpendicular" title="Perpendicular" tooltip="Create constraint defining two perpendicular lines" icon=":icons/perpendicular.png">
         <feature_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer">
-          <validator id="SketchPlugin_ResultLineValidator"/>
+          <validator id="SketchPlugin_ResultLine"/>
+          <validator id="SketchPlugin_DifferentObjects"/>
         </feature_selector>
         <feature_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer">
-          <validator id="SketchPlugin_ResultLineValidator"/>
+          <validator id="SketchPlugin_ResultLine"/>
+          <validator id="SketchPlugin_DifferentObjects"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <validator id="PartSet_PerpendicularValidator"/>