]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #429: Activation of operations on selection
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 8 Apr 2015 14:38:24 +0000 (17:38 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 8 Apr 2015 14:38:24 +0000 (17:38 +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 b3332668714bd8b541491bb486fc5854a0b0435a..b81a64bb3291fb07b2280883008df0594e201f99 100644 (file)
@@ -139,6 +139,7 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
   aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
   aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
+  aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
 
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
   aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
index 2837ba7bff93c2e5e183119e70b0f47e53b05d5d..55f0157b003a2ff8e9f36cdc1ec364f706b1d98f 100644 (file)
@@ -23,6 +23,7 @@
 #include <ModelAPI_Session.h>
 
 #include <SketchPlugin_Sketch.h>
+#include <GeomAPI_Edge.h>
 
 #include <list>
 #ifdef _DEBUG
@@ -127,37 +128,53 @@ bool PartSet_HVDirSelection::isValid(const ModuleBase_ISelection* theSelection)
   return (aCount == 1);
 }
 
+bool PartSet_FilletSelection::isValid(const ModuleBase_ISelection* theSelection) const
+{
+  int aCount = shapesNbLines(theSelection);
+  return (aCount > 0) && (aCount < 3);
+}
+
 bool PartSet_TangentSelection::isValid(const ModuleBase_ISelection* theSelection) const
 {
   QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
-  ModuleBase_ViewerPrs aPrs;
-  if (aList.size() != 2)
+  if ((aList.size() == 0) || (aList.size() > 2))
     return false;
 
-  ModuleBase_ViewerPrs aPrs1 = aList.first();
-  ModuleBase_ViewerPrs aPrs2 = aList.last();
-
-  const TopoDS_Shape& aShape1 = aPrs1.shape();
-  const TopoDS_Shape& aShape2 = aPrs2.shape();
-  if (aShape1.IsNull() || aShape2.IsNull())
+  ModuleBase_ViewerPrs aPrs = aList.first();
+  const TopoDS_Shape& aShape = aPrs.shape();
+  if (aShape.IsNull())
     return false;
 
-  if ((aShape1.ShapeType() != TopAbs_EDGE) || (aShape2.ShapeType() != TopAbs_EDGE))
+  if (aShape.ShapeType() != TopAbs_EDGE)
     return false;
 
-  TopoDS_Edge aEdge1 = TopoDS::Edge(aShape1);
-  TopoDS_Edge aEdge2 = TopoDS::Edge(aShape2);
-
-  Standard_Real aStart, aEnd;
-  Handle(Geom_Curve) aCurve1 = BRep_Tool::Curve(aEdge1, aStart, aEnd);
-  Handle(Geom_Curve) aCurve2 = BRep_Tool::Curve(aEdge2, aStart, aEnd);
-
-  GeomAdaptor_Curve aAdaptor1(aCurve1);
-  GeomAdaptor_Curve aAdaptor2(aCurve2);
-  if (aAdaptor1.GetType() == GeomAbs_Circle)
-    return aAdaptor2.GetType() == GeomAbs_Line;
-  else if (aAdaptor2.GetType() == GeomAbs_Circle)
-    return aAdaptor1.GetType() == GeomAbs_Line;
+  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;
 }
 
index 101bba5f90ffd0dff1a7d7e0a51661610015c24e..7d78aeb10a7f2e879ef26261605d81ae8dda8f1a 100644 (file)
@@ -90,6 +90,14 @@ class PartSet_TangentSelection : public ModuleBase_SelectionValidator
   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
 };
 
+//! \ingroup Validators
+//! A class to validate a selection for Fillet constraints operation
+class PartSet_FilletSelection : public ModuleBase_SelectionValidator
+{
+ public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
 ////////////// Attribute validators ////////////////
 
 
index 323120ce97e118b7ba7a2a910aaef4489415b097..03a092c822df208d2bc4bdd230d07688941402b7 100644 (file)
         <validator id="PartSet_TangentSelection"/>
       </feature>
       
-    <!--  SketchConstraintMirror  -->
-      <feature
-        id="SketchConstraintMirror"
-        title="Mirror" icon=":icons/mirror.png"
-        tooltip="Create constraint, mirroring group of objects">
-        <sketch_constraint_shape_selector id="ConstraintEntityA" 
-            label="Mirror line" tooltip="Select mirror line" shape_types="edge">
-            <validator id="GeomValidators_Edge" parameters="line"/>
-        </sketch_constraint_shape_selector>
-        <multi_selector id="ConstraintMirrorList" 
-            label="List of objects"
-            tooltip="Select list of mirroring objects"
-            type_choice="Edges">
-        </multi_selector>
-      </feature>
     </group>
     
     <group id="Edit">
         <doublevalue_editor label="Value" tooltip="Fillet radius" id="ConstraintValue" min="0">
           <validator id="GeomValidators_Positive"/>
         </doublevalue_editor>
+        <validator id="PartSet_FilletSelection"/>
+      </feature>
+      
+      <!--  SketchConstraintMirror  -->
+      <feature
+        id="SketchConstraintMirror"
+        title="Mirror" icon=":icons/mirror.png"
+        tooltip="Create constraint, mirroring group of objects">
+        <sketch_constraint_shape_selector id="ConstraintEntityA"
+            label="Mirror line" tooltip="Select mirror line" shape_types="edge">
+          <validator id="GeomValidators_Edge" parameters="line"/>
+        </sketch_constraint_shape_selector>
+        <multi_selector id="ConstraintMirrorList"
+            label="List of objects"
+            tooltip="Select list of mirroring objects"
+            type_choice="Edges">
+        </multi_selector>
       </feature>
     </group>
   </workbench>
index 9e7ce02ae348cfb50ee3f37950e607beb4bfd377..129fdb2cfd9db0b6c6fe493c8034fc8dc2ce25f9 100644 (file)
@@ -131,35 +131,41 @@ void XGUI_ActionsMgr::updateOnViewSelection()
   if (!myOperationMgr->hasOperation())
     return;
 
-  ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
-  FeaturePtr anActiveFeature = anOperation->feature();
-  if(!anActiveFeature.get())
+  QStringList aIdList = myOperationMgr->operationList();
+  //ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
+  //FeaturePtr anActiveFeature = anOperation->feature();
+  //if(!anActiveFeature.get())
+  if (aIdList.isEmpty())
     return;
 
-  QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
+  //QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
   XGUI_Selection* aSelection = myWorkshop->selector()->selection();
   if (aSelection->getSelected().size() == 0) {
-    foreach(QString aId, nestedCommands(aFeatureId)) {
-      setActionEnabled(aId, true);
+    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 aId, nestedCommands(aFeatureId)) {
-      std::list<ModelAPI_Validator*> aValidators;
-      std::list<std::list<std::string> > anArguments;
-      aFactory->validators(aId.toStdString(), aValidators, anArguments);
-      std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
-      std::list<std::list<std::string> >::iterator aValidatorArgs = anArguments.begin();
-      for (; aValidator != aValidators.end(); aValidator++, aValidatorArgs++) {
-        if (!(*aValidator))
-          continue;
-        const ModuleBase_SelectionValidator* aSelValidator =
-            dynamic_cast<const ModuleBase_SelectionValidator*>(*aValidator);
-        if (!aSelValidator)
-          continue;
-        setActionEnabled(aId, aSelValidator->isValid(aSelection, *aValidatorArgs));
+    foreach(QString aFeatureId, aIdList) {
+      foreach(QString aId, nestedCommands(aFeatureId)) {
+        std::list<ModelAPI_Validator*> aValidators;
+        std::list<std::list<std::string> > anArguments;
+        aFactory->validators(aId.toStdString(), aValidators, anArguments);
+        std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
+        std::list<std::list<std::string> >::iterator aValidatorArgs = anArguments.begin();
+        for (; aValidator != aValidators.end(); aValidator++, aValidatorArgs++) {
+          if (!(*aValidator))
+            continue;
+          const ModuleBase_SelectionValidator* aSelValidator =
+              dynamic_cast<const ModuleBase_SelectionValidator*>(*aValidator);
+          if (!aSelValidator)
+            continue;
+          setActionEnabled(aId, aSelValidator->isValid(aSelection, *aValidatorArgs));
 
+        }
       }
     }
   }