]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1063: Use selection validators in update of ActionMgr. Equal constraint select...
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 19 Oct 2015 09:17:40 +0000 (12:17 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 19 Oct 2015 09:17:57 +0000 (12:17 +0300)
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Validators.cpp
src/PartSet/PartSet_Validators.h
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_ActionsMgr.cpp

index a20479f8cbc70524c11d1c2e0dc863d9608e0429..ac927a6fc829a29b21b12dde0f5b9876faf12d32 100755 (executable)
@@ -203,6 +203,7 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
   aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
   aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
+  aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
   aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
 
index 5b985c8915e1918be97fabcaa9dd190716d56a27..cc80fc8c894b7bc0385d186e06d8e3fd00faf0ea 100755 (executable)
@@ -89,18 +89,24 @@ std::shared_ptr<GeomAPI_Pln> sketcherPlane(ModuleBase_Operation* theOperation)
   return aEmptyPln; 
 }
 
+
+bool isEmptySelectionValid(ModuleBase_Operation* theOperation)
+{
+  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;
+}
+
 bool PartSet_DistanceSelection::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;
+    return isEmptySelectionValid(theOperation);
   } else {
     int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection);
     return (aCount > 0) && (aCount < 3);
@@ -110,15 +116,7 @@ bool PartSet_DistanceSelection::isValid(const ModuleBase_ISelection* theSelectio
 bool PartSet_LengthSelection::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;
+    return isEmptySelectionValid(theOperation);
   } else {
     int aCount = shapesNbLines(theSelection);
     return (aCount == 1);
@@ -128,15 +126,7 @@ bool PartSet_LengthSelection::isValid(const ModuleBase_ISelection* theSelection,
 bool PartSet_PerpendicularSelection::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;
+    return isEmptySelectionValid(theOperation);
   } else {
     int aCount = shapesNbLines(theSelection);
     return (aCount > 0) && (aCount < 3);
@@ -146,15 +136,7 @@ bool PartSet_PerpendicularSelection::isValid(const ModuleBase_ISelection* theSel
 bool PartSet_ParallelSelection::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;
+    return isEmptySelectionValid(theOperation);
   } else {
     int aCount = shapesNbLines(theSelection);
     return (aCount > 0) && (aCount < 3);
@@ -164,15 +146,7 @@ bool PartSet_ParallelSelection::isValid(const ModuleBase_ISelection* theSelectio
 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;
+    return isEmptySelectionValid(theOperation);
   } else {
     QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
     ModuleBase_ViewerPrs aPrs;
@@ -197,15 +171,7 @@ bool PartSet_RadiusSelection::isValid(const ModuleBase_ISelection* theSelection,
 bool PartSet_RigidSelection::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;
+    return isEmptySelectionValid(theOperation);
   } else {
     QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
     return (aList.count() == 1);
@@ -216,15 +182,7 @@ bool PartSet_RigidSelection::isValid(const ModuleBase_ISelection* theSelection,
 bool PartSet_CoincidentSelection::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;
+    return isEmptySelectionValid(theOperation);
   } else {
     // Coincident can be applied to points and to lines
     int aCount = shapesNbPoints(theSelection);
@@ -236,15 +194,7 @@ bool PartSet_CoincidentSelection::isValid(const ModuleBase_ISelection* theSelect
 bool PartSet_HVDirSelection::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;
+    return isEmptySelectionValid(theOperation);
   } else {
     int aCount = shapesNbLines(theSelection);
     return (aCount == 1);
@@ -254,15 +204,7 @@ bool PartSet_HVDirSelection::isValid(const ModuleBase_ISelection* theSelection,
 bool PartSet_FilletSelection::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;
+    return isEmptySelectionValid(theOperation);
   } else {
     int aCount = shapesNbLines(theSelection);
     return (aCount > 0) && (aCount < 3);
@@ -272,15 +214,7 @@ bool PartSet_FilletSelection::isValid(const ModuleBase_ISelection* theSelection,
 bool PartSet_TangentSelection::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;
+    return isEmptySelectionValid(theOperation);
   } else {
     QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
     if ((aList.size() == 0) || (aList.size() > 2))
@@ -328,21 +262,52 @@ bool PartSet_TangentSelection::isValid(const ModuleBase_ISelection* theSelection
 bool PartSet_AngleSelection::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;
+    return isEmptySelectionValid(theOperation);
   } else {
     int aCount = shapesNbLines(theSelection);
     return (aCount > 0) && (aCount < 3);
   }
 }
 
+bool PartSet_EqualSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
+{
+  if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+    return isEmptySelectionValid(theOperation);
+  } else {
+    QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+    ModuleBase_ViewerPrs aPrs;
+    int aCount = 0;
+    int aType = 0;
+    foreach (ModuleBase_ViewerPrs aPrs, aList) {
+      std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
+      aShape->setImpl(new TopoDS_Shape(aPrs.shape()));
+      if (aShape->isEdge()) {
+        aCount++;
+        GeomAPI_Edge aEdge(aShape);
+        if (aEdge.isLine()) {
+          if (aCount == 1)
+            aType = 1;
+          else if (aType != 1)
+            return false;
+        } else if (aEdge.isCircle()) {
+          if (aCount == 1)
+            aType = 2;
+          else if (aType != 2)
+            return false;
+        } else if (aEdge.isArc()) {
+          if (aCount == 1)
+            aType = 3;
+          else if (aType != 3)
+            return false;
+        }
+      } else
+        return false;
+    }
+    return (aCount > 0) && (aCount < 3);
+  }
+}
+
+
 std::string PartSet_DifferentObjectsValidator::errorMessage(
                          const PartSet_DifferentObjectsValidator::ErrorType& theType,
                          const std::string& thEqualObject, const std::string& theFirstAttribute,
index fae29cec67e65b6e034d8850fb807f67bb91998a..36f78e031d894dddfc382d1b3f78a99abb006724 100644 (file)
@@ -17,6 +17,7 @@
  * Selector validators
  */
 
+
 //! \ingroup Validators
 //! A class to validate a selection for Distance constraint operation
 class PartSet_DistanceSelection : public ModuleBase_SelectionValidator
@@ -106,6 +107,14 @@ public:
   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
 };
 
+//! \ingroup Validators
+//! A class to validate a selection for Equal constraints operation
+class PartSet_EqualSelection : public ModuleBase_SelectionValidator
+{
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
+};
+
 ////////////// Attribute validators ////////////////
 
 
index 381d4fb8099783476fd1198724f88df7e9d462fe..546a445ccc84fdda8a3f14c807a926f15ad11e8f 100644 (file)
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
         </sketch_shape_selector>
+        <validator id="PartSet_EqualSelection"/>
       </feature>
       
     <!--  SketchConstraintTangent  -->
index b1b5f1cf512760d49678b83e0528254f82381170..1f721eea9812574438227612d906910bbfb3ee6e 100644 (file)
@@ -95,25 +95,30 @@ bool XGUI_ActionsMgr::isNested(const QString& theId) const
 
 void XGUI_ActionsMgr::update()
 {
-  FeaturePtr anActiveFeature = FeaturePtr();
-  ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
-                                                         (myOperationMgr->currentOperation());
-  if (aFOperation) {
-    anActiveFeature = aFOperation->feature();
-    if(anActiveFeature.get()) {
-      setAllEnabled(false);
-      QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
-      setActionEnabled(aFeatureId, true);
-    }
-    setNestedStackEnabled(aFOperation);
+  XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+  if (aSelection->getSelected(ModuleBase_ISelection::Viewer).size() > 0) {
+    updateOnViewSelection();
   } else {
-    setAllEnabled(true);
-    setNestedCommandsEnabled(false);
+    FeaturePtr anActiveFeature = FeaturePtr();
+    ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+                                                           (myOperationMgr->currentOperation());
+    if (aFOperation) {
+      anActiveFeature = aFOperation->feature();
+      if(anActiveFeature.get()) {
+        setAllEnabled(false);
+        QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
+        setActionEnabled(aFeatureId, true);
+      }
+      setNestedStackEnabled(aFOperation);
+    } else {
+      setAllEnabled(true);
+      setNestedCommandsEnabled(false);
+    }
+    // TODO(SBH): Get defaults state of actions from XML and remove the following method
+    updateByDocumentKind();
+    updateCheckState();
+    updateByPlugins(anActiveFeature);
   }
-  // TODO(SBH): Get defaults state of actions from XML and remove the following method
-  updateByDocumentKind();
-  updateCheckState();
-  updateByPlugins(anActiveFeature);
 }
 
 void XGUI_ActionsMgr::updateCheckState()
@@ -154,9 +159,8 @@ void XGUI_ActionsMgr::updateOnViewSelection()
       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));
+        if (aSelValidator)
+          setActionEnabled(aId, aSelValidator->isValid(aSelection, theOperation));
       }
     }
   }