Salome HOME
Multi-selection widget to be used in the extrusion feature.
authornds <natalia.donis@opencascade.com>
Wed, 18 Mar 2015 07:33:25 +0000 (10:33 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 18 Mar 2015 07:33:25 +0000 (10:33 +0300)
Shape validator correction

src/ModelAPI/ModelAPI_ShapeValidator.cpp
src/ModelAPI/ModelAPI_ShapeValidator.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_FilterValidated.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_FilterValidated.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp
src/SketchPlugin/SketchPlugin_ShapeValidator.cpp
src/SketchPlugin/SketchPlugin_ShapeValidator.h
src/XGUI/XGUI_Displayer.h

index 08f0a687b5dce9002c96f38fe0bfdf1e1ab1a25a..0ef625cd74f04ea4831d65016c0857947b64c292 100644 (file)
@@ -9,17 +9,19 @@
 #include <ModelAPI_AttributeSelection.h>
 #include "ModelAPI_Object.h"
 
-bool ModelAPI_ShapeValidator::isValid(const FeaturePtr& theFeature,
-                                      const std::list<std::string>& theArguments,
-                                      const ObjectPtr& theObject,
-                                      const AttributePtr& theAttribute,
-                                      const GeomShapePtr& theShape) const
+bool ModelAPI_ShapeValidator::isValid(const AttributePtr& theAttribute,
+                                       const std::list<std::string>& theArguments) const
 {
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  AttributeSelectionPtr aSelectionAttribute = 
+                     std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  GeomShapePtr aShape = aSelectionAttribute->value();
+
   std::string aCurrentAttributeId = theAttribute->id();
   // get all feature attributes
   std::list<AttributePtr> anAttrs = 
-                   theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
-  if (anAttrs.size() > 0 && theShape.get() != NULL) {
+                   aFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+  if (anAttrs.size() > 0 && aShape.get() != NULL) {
     std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
     for(; anAttr != anAttrs.end(); anAttr++) {
       AttributePtr anAttribute = *anAttr;
@@ -28,7 +30,7 @@ bool ModelAPI_ShapeValidator::isValid(const FeaturePtr& theFeature,
         AttributeSelectionPtr aSelectionAttribute = 
           std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
         // the shape of the attribute should be not the same
-        if (aSelectionAttribute.get() != NULL && theShape->isEqual(aSelectionAttribute->value())) {
+        if (aSelectionAttribute.get() != NULL && aShape->isEqual(aSelectionAttribute->value())) {
           return false;
         }
       }
index 3be9323f7558e5c8a0dae67a915a3e80778fc4fb..beac5e2c9d76600741e5a3f1d4d68199f81ffe3d 100644 (file)
@@ -9,29 +9,21 @@
 
 #include <ModelAPI.h>
 
-#include <ModelAPI_Validator.h>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_Attribute.h>
 
-#include <GeomAPI_Shape.h>
-
 /**
  * Generic validator for any attribute of a feature.
  */
-class ModelAPI_ShapeValidator : public ModelAPI_Validator
+class ModelAPI_ShapeValidator : public ModelAPI_AttributeValidator
 {
 public:
   /// returns True if the attribute is valid. It checks whether the feature of the attribute
   /// does not contain a selection attribute filled with the same shape
-  /// \param theFeature a feature to check
-  /// \param theArguments a filter parameters
-  /// \param theObject an object
   /// \param theAttribute an attribute to check
-  /// \param theShape a shape
-  MODELAPI_EXPORT virtual bool isValid(const FeaturePtr& theFeature,
-                               const std::list<std::string>& theArguments,
-                               const ObjectPtr& theObject, const AttributePtr& theAttribute,
-                               const GeomShapePtr& theShape) const;
+  /// \param theArguments a filter parameters
+  MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                       const std::list<std::string>& theArguments) const;
 };
 
 #endif
index cf2020c1201b461db91435e0f5c99151e2bcb54b..a7ad900d1a3e73c31a83527e2fe0868fa27a53d8 100644 (file)
@@ -14,6 +14,7 @@ SET(PROJECT_HEADERS
        ModuleBase_FilterNoConsructionSubShapes.h
        ModuleBase_FilterNoDegeneratedEdge.h
        ModuleBase_FilterShapeType.h
+       ModuleBase_FilterValidated.h
        ModuleBase_Tools.h
        ModuleBase_IModule.h
        ModuleBase_Operation.h
@@ -62,6 +63,7 @@ SET(PROJECT_SOURCES
        ModuleBase_FilterNoConsructionSubShapes.cpp
        ModuleBase_FilterNoDegeneratedEdge.cpp
        ModuleBase_FilterShapeType.cpp
+       ModuleBase_FilterValidated.cpp
        ModuleBase_Tools.cpp
        ModuleBase_IModule.cpp
        ModuleBase_IWorkshop.cpp
diff --git a/src/ModuleBase/ModuleBase_FilterValidated.cpp b/src/ModuleBase/ModuleBase_FilterValidated.cpp
new file mode 100644 (file)
index 0000000..20c1692
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_FilterValidated.h
+// Created:     17 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+
+#include "ModuleBase_FilterValidated.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+
+#include <StdSelect_BRepOwner.hxx>
+
+#include <BRep_Tool.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <Geom_Curve.hxx>
+
+#include <ModelAPI_CompositeFeature.h>
+#include <GeomAPI_ICustomPrs.h>
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterValidated, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterValidated, SelectMgr_Filter);
+
+Standard_Boolean ModuleBase_FilterValidated::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+/*  // global selection should be ignored, the filter processes only selected sub-shapes
+  Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+  if (!aShapeOwner.IsNull()) {
+    if (!aShapeOwner->ComesFromDecomposition())
+      return Standard_True;
+  }
+
+  if (theOwner->HasSelectable()) {
+    Handle(AIS_InteractiveObject) aAisObj = 
+      Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+    if (!aAisObj.IsNull()) {
+      std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+      aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
+      ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
+
+      ResultConstructionPtr aConstr = 
+        std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
+      if (aConstr != NULL) {
+        // it provides selection only on compositie features, construction without composite
+        // feature is not selectable
+        FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
+        CompositeFeaturePtr aComposite = 
+          std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
+        return aComposite && aComposite->numberOfSubs() > 0;
+      }
+    }
+  }
+  */
+  return Standard_False;
+}
+
diff --git a/src/ModuleBase/ModuleBase_FilterValidated.h b/src/ModuleBase/ModuleBase_FilterValidated.h
new file mode 100644 (file)
index 0000000..2fd2371
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_FilterValidated.h
+// Created:     17 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+
+#ifndef ModuleBase_FilterValidated_H
+#define ModuleBase_FilterValidated_H
+
+#include <SelectMgr_Filter.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+
+class ModuleBase_IWorkshop;
+
+/**
+* \ingroup GUI
+* \class ModuleBase_FilterValidated
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select objects which belong to 
+* currently active document or to global document
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_FilterValidated, SelectMgr_Filter);
+class ModuleBase_FilterValidated: public SelectMgr_Filter
+{
+public:
+  /// Constructor
+  /// \param theWorkshop instance of workshop interface
+  Standard_EXPORT ModuleBase_FilterValidated(ModuleBase_IWorkshop* theWorkshop):
+      SelectMgr_Filter(), myWorkshop(theWorkshop) {}
+
+  /**
+   * Returns true if the owner is computed from decomposition(it is global selection, not the sub-shapes)
+   * of if the selected result is a construction and the result feature is composite and has sub-elements.
+   * \param theOwner the result of selection
+   * \return whether the owner is selectable in the viewer
+  */
+  Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+  DEFINE_STANDARD_RTTI(ModuleBase_FilterValidated)
+
+protected:
+  /// Instance of workshop interface
+  ModuleBase_IWorkshop* myWorkshop;
+};
+
+#endif
\ No newline at end of file
index 7a9c2449de797a294c54197ef6c259c092479434..a2034fce6538f751c7ab8ae5ed29bee67e8d4dbe 100644 (file)
@@ -34,7 +34,7 @@
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_ResultValidator.h>
-#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_ShapeValidator.h>
 
 #include <Config_WidgetAPI.h>
@@ -486,13 +486,13 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<G
   aData->blockSendAttributeUpdated(true);
   storeAttributeValues(theObj, theShape);
 
-// 3. check the acceptability of the current values
+  // 3. check the acceptability of the current values
   std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
   std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
   bool aValid = true;
   for (; aValidator != aValidators.end() && aValid; aValidator++, aArgs++) {
-    const ModelAPI_RefAttrValidator* aAttrValidator =
-        dynamic_cast<const ModelAPI_RefAttrValidator*>(*aValidator);
+    const ModelAPI_AttributeValidator* aAttrValidator =
+        dynamic_cast<const ModelAPI_AttributeValidator*>(*aValidator);
     if (aAttrValidator) {
       aValid = aAttrValidator->isValid(anAttribute, *aArgs);
     }
index 405fc74b5b40d17ecdf5deeef1b7167f614480c4..e559fa608b8e464b67a2490b2526c5577ac50ae7 100644 (file)
@@ -15,7 +15,6 @@
 bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const
 {
   ObjectPtr aSelectedObject = theSelectedObject;
-  GeomShapePtr aShape = theShape;
 
   FeaturePtr aFeature = ModelAPI_Feature::feature(aSelectedObject);
   if (aFeature) {
@@ -25,11 +24,10 @@ bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSe
       ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
                                                                   aSelectedObject, mySketch);
       if (aObj) {
-        PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this;
         aSelectedObject = aObj;
       } else 
         return false;
     }
   }
-  return ModuleBase_WidgetShapeSelector::storeAttributeValues(theSelectedObject, theShape);
+  return ModuleBase_WidgetShapeSelector::storeAttributeValues(aSelectedObject, theShape);
 }
index 1b279590016224b74b2a5a4ca62b2b06b905adf1..2aca20171ee6a3eccf0ecd4e54047cb8c124c0dd 100644 (file)
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_ResultValidator.h>
 
-bool SketchPlugin_ShapeValidator::isValid(const FeaturePtr& theFeature,
-                                                  const std::list<std::string>& theArguments,
-                                                  const ObjectPtr& theObject,
-                                                  const AttributePtr& theAttribute,
-                                                  const GeomShapePtr& theShape) const
+bool SketchPlugin_ShapeValidator::isValid(const AttributePtr& theAttribute,
+                                          const std::list<std::string>& theArguments) const
 {
-  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-  std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
-
-  // if the shapes are equal, that means that the given shape is a result.
-  // if the result is selected, the 
-  if (aShape->isEqual(theShape))
+  if (theArguments.size() != 1)
     return true;
 
-  // found a non-external argument on the feature
-  std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
-  bool aHasNullParam = false;
-  bool aHasNonExternalParams = false;
-  for (; anIt != aLast; anIt++) {
-    std::string aParamA = *anIt;
-    std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
-          ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(aParamA));
-    if (anAttr) {
-      FeaturePtr anOtherFeature = ModelAPI_Feature::feature(anAttr->object());
-      if (anOtherFeature.get() != NULL) {
-        std::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
-          std::dynamic_pointer_cast<SketchPlugin_Feature>(anOtherFeature);
-        if (aSketchFeature) {
-          aHasNonExternalParams = !aSketchFeature->isExternal();
-        }
+  // ask whether the feature of the attribute is external
+  //std::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
+  //AttributeRefAttrPtr anAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  //                               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+  bool isAttributeExternal = isExternalAttribute(theAttribute);
+
+  // ask whether the feature of the attribute by parameter identifier is external
+  std::string aFrontArgument = theArguments.front();
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  bool isParameterExternal = isExternalAttribute(aFeature->attribute(aFrontArgument));
+
+  // it is not possible that both features, attribute and attribute in parameter, are external
+  if (isAttributeExternal && isParameterExternal)
+    return false;
+  return true;
+}
+
+bool SketchPlugin_ShapeValidator::isExternalAttribute(const AttributePtr& theAttribute) const
+{
+  bool isExternal = false;
+  AttributeRefAttrPtr anAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+
+  if (anAttribute.get() != NULL) {
+    FeaturePtr anArgumentFeature = ModelAPI_Feature::feature(anAttribute->object());
+    if (anArgumentFeature.get() != NULL) {
+      std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+                                    std::dynamic_pointer_cast<SketchPlugin_Feature>(anArgumentFeature);
+      if (aSketchFeature.get() != NULL) {
+        isExternal = aSketchFeature->isExternal();
       }
-      else
-        aHasNullParam = true;
     }
   }
-  if (aHasNullParam || aHasNonExternalParams)
-    return true;
-  return false;
+  return isExternal;
 }
index 6e35f4da1e0848c8d41f1ae10d5b3eddfd911b8f..d07581ebda92b2c912c285c910040a87b0f6c042 100644 (file)
@@ -8,8 +8,7 @@
 #define SketchPlugin_ShapeValidator_H
 
 #include <SketchPlugin.h>
-#include <ModelAPI_ShapeValidator.h>
-#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeValidator.h>
 
 /**\class SketchPlugin_ResultPointValidator
  * \ingroup Validators
  *
  * Allows to select points only.
  */
-class SketchPlugin_ShapeValidator : public ModelAPI_ShapeValidator
+class SketchPlugin_ShapeValidator : public ModelAPI_AttributeValidator
 {
 public:
-  // returns true if there is an empty or non-external shape on the feature.
-  // in the given shape or in the list of attribute shapes
-  /// \param theFeature a feature to check
+  /// returns true if the feature of attribute do not contain external features in the given attribute and
+  /// among attributes listed in the arguments
+  /// \param theAttribute an attribute to check
   /// \param theArguments a filter parameters
-  /// \param theObject an object
+  SKETCHPLUGIN_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                           const std::list<std::string>& theArguments) const;
+
+protected:
+  /// returns true if the feature of the attribute is external
   /// \param theAttribute an attribute to check
-  /// \param theShape a shape
-  SKETCHPLUGIN_EXPORT virtual bool isValid(const FeaturePtr& theFeature,
-                               const std::list<std::string>& theArguments,
-                               const ObjectPtr& theObject, const AttributePtr& theAttribute,
-                               const GeomShapePtr& theShape) const;
+  bool isExternalAttribute(const AttributePtr& theAttribute) const;
 };
 
 #endif
index da11c4d8ef6f65ba1ca039fe7f9c208d41c92a43..bfdf8a5d58dfc26824948896719e6dc78ec70907 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <ModuleBase_Definitions.h>
 #include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_FilterValidated.h>
 
 #include <GeomAPI_ICustomPrs.h>
 
@@ -231,6 +232,8 @@ class XGUI_EXPORT XGUI_Displayer
   /// A container for selection filters
   Handle(SelectMgr_AndFilter) myAndFilter;
 
+  Handle(ModuleBase_FilterValidated) myFilterValidated;
+
   /// A default custom presentation, which is used if the displayed feature is not a custom presentation
   GeomCustomPrsPtr myCustomPrs;