]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Provide a different object validator with selected shape to check it
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 11 Mar 2015 09:52:00 +0000 (12:52 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 11 Mar 2015 09:52:00 +0000 (12:52 +0300)
src/ModelAPI/ModelAPI_RefAttrValidator.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/PartSet/PartSet_Validators.cpp
src/PartSet/PartSet_Validators.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index ab8ffc6cd5709f22a6819110506f65be5a870b4e..cfa3886c70708ac6722e2aa092e5c384e4719ff7 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_AttributeValidator.h>
+#include <GeomAPI_Shape.h>
 
 /**\class ModelAPI_RefAttrValidator
  * \ingroup DataModel
@@ -21,7 +22,7 @@ class ModelAPI_RefAttrValidator : public ModelAPI_AttributeValidator
 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;
+                       const ObjectPtr& theObject, const GeomShapePtr& theShape) 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,
index 81e45ef0a11c250d5709646e0dc210c9dd14acb5..74bd7f61aa2b07a82c43e7b2fc32adb5f966a2b5 100644 (file)
@@ -499,7 +499,7 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<G
     const ModelAPI_RefAttrValidator* aAttrValidator =
         dynamic_cast<const ModelAPI_RefAttrValidator*>(*aValidator);
     if (aAttrValidator) {
-      if (!aAttrValidator->isValid(myFeature, *aArgs, theObj)) {
+      if (!aAttrValidator->isValid(myFeature, *aArgs, theObj, theShape)) {
         return false;
       }
     }
index 30d95d4729e786de0cd6f168a3f6bb2ec876b95c..f92793f71974c2e9f34d9cf8274ec30226d99a28 100644 (file)
@@ -112,7 +112,8 @@ bool PartSet_RigidValidator::isValid(const ModuleBase_ISelection* theSelection)
 
 bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, 
                                                 const std::list<std::string>& theArguments,
-                                                const ObjectPtr& theObject) const
+                                                const ObjectPtr& theObject,
+                                                const GeomShapePtr& theShape) const
 {
   // Check RefAttr attributes
   std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
@@ -138,8 +139,13 @@ bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
         std::shared_ptr<ModelAPI_AttributeSelection> aRef = 
           std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*anAttr);
         // check the object is already presented
-        if (aRef->isInitialized() && aRef->context() == theObject)
-          return false;
+        if (aRef->isInitialized() && aRef->context() == theObject) {
+          if (theShape.get() != NULL) {
+            if (aRef->value()->isEqual(theShape))
+              return false;
+          } else
+            return false;
+        }
       }
     }
   }
@@ -164,7 +170,22 @@ bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
                                                 const std::list<std::string>& theArguments,
                                                 const AttributePtr& theAttribute) const
 {
-  return PartSet_DifferentObjectsValidator::isValid(theAttribute, theArguments);
+  if (PartSet_DifferentObjectsValidator::isValid(theAttribute, theArguments)) {
+    std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
+      theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
+    std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+    for(; anAttr != anAttrs.end(); anAttr++) {
+      if (*anAttr) {
+        std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
+          std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+        // check the object is already presented
+        if (!aRef->isObject() && aRef->attr() == theAttribute)
+          return false;
+      }
+    }
+    return true;
+  }
+  return false;
 }
 
 bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute, 
index be1bb0ef5c149fa4ea04866b636f62e49aaa74f0..0118dce90422b81bc1aa3ef79d9ab3b2e86520d4 100644 (file)
@@ -78,7 +78,7 @@ class PartSet_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
    /// \param theArguments a list of arguments (names of attributes to check)
    /// \param theObject a selected object
   virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
-                       const ObjectPtr& theObject) const;
+                       const ObjectPtr& theObject, const GeomShapePtr& theShape) const;
 
   //! Returns true if the attribute is good for the feature attribute
   //! \param theFeature a feature to check
index cd69a1998d2e0620624667848994846ae8003549..d0b1f8bc1a6abcd85d2c2066d93b70d727fedbb9 100644 (file)
@@ -116,7 +116,7 @@ bool PartSet_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<Geom
       }
       else
       {
-        if (!aAttrValidator->isValid(myFeature, *aArgs, theObj)) {
+        if (!aAttrValidator->isValid(myFeature, *aArgs, theObj, theShape)) {
           return false;
         }
       }
index 030f786f18b1d78d2e5d0f218b0dd3e0d98ebb85..21f74bc637d296c989f26d7159acada465de565c 100644 (file)
@@ -43,8 +43,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   aFactory->registerValidator("SketchPlugin_DistanceAttr",
                               new SketchPlugin_DistanceAttrValidator);  
-  aFactory->registerValidator("SketchPlugin_DifferentObjects",
-                              new SketchPlugin_DifferentObjectsValidator);
+  //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);
index abef5066c21a8809d83327f5d92be9627796bb73..43186329b9ea56e7f6e811899bfb4c2bea1b06b5 100644 (file)
@@ -16,7 +16,8 @@
 
 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
                                                  const std::list<std::string>& theArguments,
-                                                 const ObjectPtr& theObject) const
+                                                 const ObjectPtr& theObject,
+                                                 const GeomShapePtr& theShape) const
 {
   std::string aParamA = theArguments.front();
   SessionPtr aMgr = ModelAPI_Session::get();
@@ -57,64 +58,64 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
   return isValid(theAttribute, theArguments);
 }
 
-bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
-                                                 const std::list<std::string>& theArguments,
-                                                 const ObjectPtr& theObject) const
-{
-  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
-    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
-  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
-  for(; anAttr != anAttrs.end(); anAttr++) {
-    if (*anAttr) {
-      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
-        std::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
-{
-  std::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr = 
-    std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-  if (anOrigAttr && anOrigAttr->isObject()) {
-    const ObjectPtr& anObj = theAttribute->owner();
-    const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
+//                                                 const std::list<std::string>& theArguments,
+//                                                 const ObjectPtr& theObject) const
+//{
+//  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
+//    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
+//  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+//  for(; anAttr != anAttrs.end(); anAttr++) {
+//    if (*anAttr) {
+//      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
+//        std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+//      // check the object is already presented
+//      if (aRef->isObject() && aRef->object() == theObject)
+//        return false;
+//    }
+//  }
+//  return true;
+//}
 
-    std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
-      aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
-    std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
-    for(; anAttr != anAttrs.end(); anAttr++) {
-      if (*anAttr && *anAttr != theAttribute) {
-        std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
-          std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
-        // check the object is already presented
-        if (aRef->isObject() && aRef->object() == anOrigAttr->object())
-          return false;
-      }
-    }
-  }
-  return true;
-}
+//bool SketchPlugin_DifferentObjectsValidator::isValid(
+//  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+//{
+//  std::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr = 
+//    std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+//  if (anOrigAttr && anOrigAttr->isObject()) {
+//    const ObjectPtr& anObj = theAttribute->owner();
+//    const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+//
+//    std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
+//      aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
+//    std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+//    for(; anAttr != anAttrs.end(); anAttr++) {
+//      if (*anAttr && *anAttr != theAttribute) {
+//        std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
+//          std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+//        // check the object is already presented
+//        if (aRef->isObject() && aRef->object() == anOrigAttr->object())
+//          return false;
+//      }
+//    }
+//  }
+//  return true;
+//}
 
-bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
-  const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
-{
-  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
-    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
-  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
-  for(; anAttr != anAttrs.end(); anAttr++) {
-    if (*anAttr) {
-      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
-        std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
-      // check the object is already presented
-      if (!aRef->isObject() && aRef->attr() == theAttribute)
-        return false;
-    }
-  }
-  return true;
-}
+//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
+//  const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
+//{
+//  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
+//    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
+//  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+//  for(; anAttr != anAttrs.end(); anAttr++) {
+//    if (*anAttr) {
+//      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
+//        std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+//      // check the object is already presented
+//      if (!aRef->isObject() && aRef->attr() == theAttribute)
+//        return false;
+//    }
+//  }
+//  return true;
+//}
index d6368a1eb3e30ba13697582c7c57f30a34187993..88c8d3a485fbff2b39924377124d68b71d5a8973 100644 (file)
@@ -22,11 +22,12 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator
   //! 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;
+  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;
+                       const ObjectPtr& theObject, const GeomShapePtr& theShape) const;
 
   //! Returns true if the attribute is good for the feature attribute
   virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
@@ -39,20 +40,21 @@ 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;
-  //! 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;
-};
+// Use PartSet_DifferentObjectsValidator instead
+//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;
+//  //! 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 0f6201227b8d1027f9e3b2aa12ae990b84e1c364..81c396a779e844a8e6eb2345786d218b3a022fc5 100644 (file)
@@ -57,7 +57,7 @@
           label="Last object" 
           tooltip="Select point, line end point, line, center of circle or arc." 
                            shape_types="edge vertex">
-                       <validator id="SketchPlugin_DifferentObjects"/>
+                       <validator id="PartSet_DifferentObjects"/>
       <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
       <selection_filter id="MultiFilter" parameters="line,vertex"/>
     </sketch_shape_selector>
                <sketch_constraint_shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select a line" 
                        shape_types="edge">
                        <selection_filter id="EdgeFilter" parameters="line"/>
-                       <validator id="SketchPlugin_DifferentObjects"/>
+                       <validator id="PartSet_DifferentObjects"/>
                </sketch_constraint_shape_selector>
                
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
                <sketch_constraint_shape_selector id="ConstraintEntityB" 
                        label="Last line" tooltip="Select an line" 
                        shape_types="edge">
-                       <validator id="SketchPlugin_DifferentObjects"/>
+                       <validator id="PartSet_DifferentObjects"/>
       <selection_filter id="EdgeFilter" parameters="line"/>
     </sketch_constraint_shape_selector>
         <validator id="PartSet_PerpendicularValidator"/>