]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue#1059: Consider operation state in selection validator
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 12 Oct 2015 14:18:04 +0000 (17:18 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 12 Oct 2015 14:18:18 +0000 (17:18 +0300)
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_SelectionValidator.cpp [deleted file]
src/ModuleBase/ModuleBase_SelectionValidator.h
src/PartSet/PartSet_Validators.cpp
src/PartSet/PartSet_Validators.h
src/XGUI/XGUI_ActionsMgr.cpp

index a0a85d709b5c1d958d358b7d814c96f68eb029f0..3bd1fba4f2563e663d5d727db325e55cc0c45839 100644 (file)
@@ -82,7 +82,6 @@ SET(PROJECT_SOURCES
   ModuleBase_ParamSpinBox.cpp
   ModuleBase_Preferences.cpp
   ModuleBase_ResultPrs.cpp
-  ModuleBase_SelectionValidator.cpp
   ModuleBase_ToolBox.cpp
   ModuleBase_Tools.cpp
   ModuleBase_ViewerFilters.cpp
diff --git a/src/ModuleBase/ModuleBase_SelectionValidator.cpp b/src/ModuleBase/ModuleBase_SelectionValidator.cpp
deleted file mode 100644 (file)
index 7c92d95..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModuleBase_SelectionValidator.cpp
-// Created:     8 Jul 2014
-// Author:      Vitaly SMETANNIKOV
-
-#include <ModuleBase_SelectionValidator.h>
-
-bool ModuleBase_SelectionValidator::isValid(const ModuleBase_ISelection* theSelection,
-                                            const std::list<std::string>& theArguments) const
-{
-  return isValid(theSelection);
-}
index 60d9574001f12752d0e654da7b64755fc7c46c6d..64eafc11200ec6ac3ababb56c73908755625360d 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "ModuleBase.h"
 #include "ModuleBase_ISelection.h"
+#include "ModuleBase_Operation.h"
 
 #include <ModelAPI_Validator.h>
 
 */
 class ModuleBase_SelectionValidator : public ModelAPI_Validator
 {
- public:
+public:
    /// Returns True if selection is valid
    /// \param theSelection selection instance
-   /// \param theArguments list of arguments
-  virtual MODULEBASE_EXPORT bool isValid(const ModuleBase_ISelection* theSelection,
-                       const std::list<std::string>& theArguments) const;
-
- protected:
-   /// Returns True if selection is valid
-   /// \param theSelection selection instance
-  virtual bool isValid(const ModuleBase_ISelection* theSelection) const = 0;
+   /// \param theOperation - current operation (can be 0)
+  virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const = 0;
 };
 
 #endif
index 849efa38357f58a2a09c18d4181fb25f9ba6cf91..5b985c8915e1918be97fabcaa9dd190716d56a27 100755 (executable)
@@ -16,6 +16,7 @@
 #include <GeomValidators_Tools.h>
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_OperationFeature.h>
 
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeSelection.h>
@@ -72,126 +73,274 @@ int shapesNbLines(const ModuleBase_ISelection* theSelection)
   return aCount;
 }
 
-bool PartSet_DistanceSelection::isValid(const ModuleBase_ISelection* theSelection) const
+
+std::shared_ptr<GeomAPI_Pln> sketcherPlane(ModuleBase_Operation* theOperation)
 {
-  int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection);
-  return (aCount > 0) && (aCount < 3);
+  std::shared_ptr<GeomAPI_Pln> aEmptyPln;
+  if (theOperation) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (aFeatureOp) {
+      CompositeFeaturePtr aFeature = 
+        std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeatureOp->feature());
+      if (aFeature && (aFeature->getKind() == SketchPlugin_Sketch::ID()))
+        return PartSet_Tools::sketchPlane(aFeature);
+    }
+  }
+  return aEmptyPln; 
 }
 
-bool PartSet_LengthSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_DistanceSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
 {
-  int aCount = shapesNbLines(theSelection);
-  return (aCount == 1);
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (!aFeatureOp->isEditOperation()) {
+      return true;
+    }
+    std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+    if (aPlane.get())
+      return true;
+    else 
+      return false;
+  } else {
+    int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection);
+    return (aCount > 0) && (aCount < 3);
+  }
 }
 
-bool PartSet_PerpendicularSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_LengthSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
 {
-  int aCount = shapesNbLines(theSelection);
-  return (aCount > 0) && (aCount < 3);
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (!aFeatureOp->isEditOperation()) {
+      return true;
+    }
+    std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+    if (aPlane.get())
+      return true;
+    else 
+      return false;
+  } else {
+    int aCount = shapesNbLines(theSelection);
+    return (aCount == 1);
+  }
 }
 
-bool PartSet_ParallelSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_PerpendicularSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
 {
-  int aCount = shapesNbLines(theSelection);
-  return (aCount > 0) && (aCount < 3);
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (!aFeatureOp->isEditOperation()) {
+      return true;
+    }
+    std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+    if (aPlane.get())
+      return true;
+    else 
+      return false;
+  } else {
+    int aCount = shapesNbLines(theSelection);
+    return (aCount > 0) && (aCount < 3);
+  }
 }
 
-bool PartSet_RadiusSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_ParallelSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
 {
-  QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
-  ModuleBase_ViewerPrs aPrs;
-  int aCount = 0;
-  foreach (ModuleBase_ViewerPrs aPrs, aList) {
-    const TopoDS_Shape& aShape = aPrs.shape();
-    if (!aShape.IsNull()) {
-      if (aShape.ShapeType() == TopAbs_EDGE) {
-        TopoDS_Edge aEdge = TopoDS::Edge(aShape);
-        Standard_Real aStart, aEnd;
-        Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
-        GeomAdaptor_Curve aAdaptor(aCurve);
-        if (aAdaptor.GetType() == GeomAbs_Circle)
-          aCount++;
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (!aFeatureOp->isEditOperation()) {
+      return true;
+    }
+    std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+    if (aPlane.get())
+      return true;
+    else 
+      return false;
+  } else {
+    int aCount = shapesNbLines(theSelection);
+    return (aCount > 0) && (aCount < 3);
+  }
+}
+
+bool PartSet_RadiusSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
+{
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (!aFeatureOp->isEditOperation()) {
+      return true;
+    }
+    std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+    if (aPlane.get())
+      return true;
+    else 
+      return false;
+  } else {
+    QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+    ModuleBase_ViewerPrs aPrs;
+    int aCount = 0;
+    foreach (ModuleBase_ViewerPrs aPrs, aList) {
+      const TopoDS_Shape& aShape = aPrs.shape();
+      if (!aShape.IsNull()) {
+        if (aShape.ShapeType() == TopAbs_EDGE) {
+          TopoDS_Edge aEdge = TopoDS::Edge(aShape);
+          Standard_Real aStart, aEnd;
+          Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
+          GeomAdaptor_Curve aAdaptor(aCurve);
+          if (aAdaptor.GetType() == GeomAbs_Circle)
+            aCount++;
+        }
       }
     }
+    return (aCount == 1);
   }
-  return (aCount == 1);
 }
 
-bool PartSet_RigidSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_RigidSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
 {
-  QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
-  return (aList.count() == 1);
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (!aFeatureOp->isEditOperation()) {
+      return true;
+    }
+    std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+    if (aPlane.get())
+      return true;
+    else 
+      return false;
+  } else {
+    QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+    return (aList.count() == 1);
+  }
 }
 
 
-bool PartSet_CoincidentSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_CoincidentSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
 {
-  // Coincident can be applied to points and to lines
-  int aCount = shapesNbPoints(theSelection);
-  aCount += shapesNbLines(theSelection);
-  return (aCount > 0) && (aCount < 3);
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (!aFeatureOp->isEditOperation()) {
+      return true;
+    }
+    std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+    if (aPlane.get())
+      return true;
+    else 
+      return false;
+  } else {
+    // Coincident can be applied to points and to lines
+    int aCount = shapesNbPoints(theSelection);
+    aCount += shapesNbLines(theSelection);
+    return (aCount > 0) && (aCount < 3);
+  }
 }
 
-bool PartSet_HVDirSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_HVDirSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
 {
-  int aCount = shapesNbLines(theSelection);
-  return (aCount == 1);
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (!aFeatureOp->isEditOperation()) {
+      return true;
+    }
+    std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+    if (aPlane.get())
+      return true;
+    else 
+      return false;
+  } else {
+    int aCount = shapesNbLines(theSelection);
+    return (aCount == 1);
+  }
 }
 
-bool PartSet_FilletSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_FilletSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
 {
-  int aCount = shapesNbLines(theSelection);
-  return (aCount > 0) && (aCount < 3);
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (!aFeatureOp->isEditOperation()) {
+      return true;
+    }
+    std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+    if (aPlane.get())
+      return true;
+    else 
+      return false;
+  } else {
+    int aCount = shapesNbLines(theSelection);
+    return (aCount > 0) && (aCount < 3);
+  }
 }
 
-bool PartSet_TangentSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_TangentSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
 {
-  QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
-  if ((aList.size() == 0) || (aList.size() > 2))
-    return false;
-
-  ModuleBase_ViewerPrs aPrs = aList.first();
-  const TopoDS_Shape& aShape = aPrs.shape();
-  if (aShape.IsNull())
-    return false;
-
-  if (aShape.ShapeType() != TopAbs_EDGE)
-    return false;
-
-  std::shared_ptr<GeomAPI_Shape> aShapePtr(new GeomAPI_Shape);
-  aShapePtr->setImpl(new TopoDS_Shape(aShape));
-  GeomAPI_Edge aEdge1(aShapePtr);
-
-  if (aEdge1.isLine() || aEdge1.isArc()) {
-    if (aList.size() == 2) {
-      // Check second selection
-      aPrs = aList.last();
-      const TopoDS_Shape& aShape2 = aPrs.shape();
-      if (aShape2.IsNull())
-        return false;
-
-      if (aShape2.ShapeType() != TopAbs_EDGE)
-        return false;
-
-      std::shared_ptr<GeomAPI_Shape> aShapePtr2(new GeomAPI_Shape);
-      aShapePtr2->setImpl(new TopoDS_Shape(aShape2));
-      GeomAPI_Edge aEdge2(aShapePtr2);
-      if (aEdge1.isLine() && aEdge2.isArc())
-        return true;
-      else if (aEdge1.isArc() && aEdge2.isLine())
-        return true;
-      else
-        return false;
-    } else
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (!aFeatureOp->isEditOperation()) {
+      return true;
+    }
+    std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+    if (aPlane.get())
       return true;
+    else 
+      return false;
+  } else {
+    QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+    if ((aList.size() == 0) || (aList.size() > 2))
+      return false;
+
+    ModuleBase_ViewerPrs aPrs = aList.first();
+    const TopoDS_Shape& aShape = aPrs.shape();
+    if (aShape.IsNull())
+      return false;
+
+    if (aShape.ShapeType() != TopAbs_EDGE)
+      return false;
+
+    std::shared_ptr<GeomAPI_Shape> aShapePtr(new GeomAPI_Shape);
+    aShapePtr->setImpl(new TopoDS_Shape(aShape));
+    GeomAPI_Edge aEdge1(aShapePtr);
+
+    if (aEdge1.isLine() || aEdge1.isArc()) {
+      if (aList.size() == 2) {
+        // Check second selection
+        aPrs = aList.last();
+        const TopoDS_Shape& aShape2 = aPrs.shape();
+        if (aShape2.IsNull())
+          return false;
+
+        if (aShape2.ShapeType() != TopAbs_EDGE)
+          return false;
+
+        std::shared_ptr<GeomAPI_Shape> aShapePtr2(new GeomAPI_Shape);
+        aShapePtr2->setImpl(new TopoDS_Shape(aShape2));
+        GeomAPI_Edge aEdge2(aShapePtr2);
+        if (aEdge1.isLine() && aEdge2.isArc())
+          return true;
+        else if (aEdge1.isArc() && aEdge2.isLine())
+          return true;
+        else
+          return false;
+      } else
+        return true;
+    }
+    return false;
   }
-  return false;
 }
 
-bool PartSet_AngleSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_AngleSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
 {
-  int aCount = shapesNbLines(theSelection);
-  return (aCount > 0) && (aCount < 3);
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+    if (!aFeatureOp->isEditOperation()) {
+      return true;
+    }
+    std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+    if (aPlane.get())
+      return true;
+    else 
+      return false;
+  } else {
+    int aCount = shapesNbLines(theSelection);
+    return (aCount > 0) && (aCount < 3);
+  }
 }
 
 std::string PartSet_DifferentObjectsValidator::errorMessage(
index 23706f81ccc27b286f3f44df3409f261e483b027..fae29cec67e65b6e034d8850fb807f67bb91998a 100644 (file)
 //! A class to validate a selection for Distance constraint operation
 class PartSet_DistanceSelection : public ModuleBase_SelectionValidator
 {
- protected:
-  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
 //! \ingroup Validators
 //! A class to validate a selection for Length constraint operation
 class PartSet_LengthSelection : public ModuleBase_SelectionValidator
 {
- protected:
-  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
 //! \ingroup Validators
 //! A class to validate a selection for Perpendicular constraint operation
 class PartSet_PerpendicularSelection : public ModuleBase_SelectionValidator
 {
- protected:
-  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
 //! \ingroup Validators
 //! A class to validate a selection for Parallel constraint operation
 class PartSet_ParallelSelection : public ModuleBase_SelectionValidator
 {
- protected:
-  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
 //! \ingroup Validators
 //! A class to validate a selection for Radius constraint operation
 class PartSet_RadiusSelection : public ModuleBase_SelectionValidator
 {
- protected:
-  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
 //! \ingroup Validators
 //! A class to validate a selection for Rigid constraint operation
 class PartSet_RigidSelection : public ModuleBase_SelectionValidator
 {
- protected:
-  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
 
@@ -70,40 +70,40 @@ class PartSet_RigidSelection : public ModuleBase_SelectionValidator
 //! A class to validate a selection for coincedence constraint operation
 class PartSet_CoincidentSelection : public ModuleBase_SelectionValidator
 {
- protected:
-  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
 //! \ingroup Validators
 //! A class to validate a selection for Horizontal and Vertical constraints operation
 class PartSet_HVDirSelection : public ModuleBase_SelectionValidator
 {
- protected:
-  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
 //! \ingroup Validators
 //! A class to validate a selection for Tangential constraints operation
 class PartSet_TangentSelection : public ModuleBase_SelectionValidator
 {
- protected:
-  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
 //! \ingroup Validators
 //! A class to validate a selection for Fillet constraints operation
 class PartSet_FilletSelection : public ModuleBase_SelectionValidator
 {
- protected:
-  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
 //! \ingroup Validators
 //! A class to validate a selection for Angle constraints operation
 class PartSet_AngleSelection : public ModuleBase_SelectionValidator
 {
- protected:
-  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
 ////////////// Attribute validators ////////////////
index 8b6fbadd1c685e94305ef78d791405823e73c060..b1b5f1cf512760d49678b83e0528254f82381170 100644 (file)
@@ -140,34 +140,23 @@ void XGUI_ActionsMgr::updateOnViewSelection()
   if (aIdList.isEmpty())
     return;
 
+  ModuleBase_Operation* theOperation = myOperationMgr->currentOperation();
   //QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
   XGUI_Selection* aSelection = myWorkshop->selector()->selection();
   // only viewer selection is processed
-  if (aSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
-    // it seems that this code is not nesessary anymore. It leads to incorrect case:
-    // sketch operation start, click in any place in the viewer. The result is all nested
-    // entities are enabled(but the sketch plane is not selected yet). Any sketch operation
-    // can be started but will be incorrect on preview build before it uses the sketch unset plane.
-    /*foreach(QString aFeatureId, aIdList) {
-      foreach(QString aId, nestedCommands(aFeatureId)) {
-        setActionEnabled(aId, true);
-      }
-    }*/
-  } else { 
-    SessionPtr aMgr = ModelAPI_Session::get();
-    ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-    foreach(QString aFeatureId, aIdList) {
-      foreach(QString aId, nestedCommands(aFeatureId)) {
-        ModelAPI_ValidatorsFactory::Validators aValidators;
-        aFactory->validators(aId.toStdString(), aValidators);
-        ModelAPI_ValidatorsFactory::Validators::iterator aValidatorIt = aValidators.begin();
-        for (; aValidatorIt != aValidators.end(); ++aValidatorIt) {
-          const ModuleBase_SelectionValidator* aSelValidator =
-              dynamic_cast<const ModuleBase_SelectionValidator*>(aFactory->validator(aValidatorIt->first));
-          if (!aSelValidator)
-            continue;
-          setActionEnabled(aId, aSelValidator->isValid(aSelection, aValidatorIt->second));
-        }
+  SessionPtr aMgr = ModelAPI_Session::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  foreach(QString aFeatureId, aIdList) {
+    foreach(QString aId, nestedCommands(aFeatureId)) {
+      ModelAPI_ValidatorsFactory::Validators aValidators;
+      aFactory->validators(aId.toStdString(), aValidators);
+      ModelAPI_ValidatorsFactory::Validators::iterator aValidatorIt = aValidators.begin();
+      for (; aValidatorIt != aValidators.end(); ++aValidatorIt) {
+        const ModuleBase_SelectionValidator* aSelValidator =
+            dynamic_cast<const ModuleBase_SelectionValidator*>(aFactory->validator(aValidatorIt->first));
+        if (!aSelValidator)
+          continue;
+        setActionEnabled(aId, aSelValidator->isValid(aSelection, theOperation));
       }
     }
   }