]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Selection validators improvements
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 10 Jul 2014 15:09:19 +0000 (19:09 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 10 Jul 2014 15:09:19 +0000 (19:09 +0400)
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Validators.cpp
src/PartSet/PartSet_Validators.h

index 2824363e1d4d8b3a9c3f7039774e30b880546eb3..3814ed1c610caab29970f3c062f468037f6dc8bf 100644 (file)
@@ -114,6 +114,15 @@ void PartSet_Module::createFeatures()
 
   aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
   aFactory->assignValidator("PartSet_LengthValidator", "SketchConstraintLength");
+
+  aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
+  aFactory->assignValidator("PartSet_PerpendicularValidator", "SketchConstraintPerpendicular");
+
+  aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
+  aFactory->assignValidator("PartSet_ParallelValidator", "SketchConstraintParallel");
+
+  aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
+  aFactory->assignValidator("PartSet_RadiusValidator", "SketchConstraintRadius");
 }
 
 void PartSet_Module::featureCreated(QAction* theFeature)
index 296f8daa6e8e44a8c49b56444befb1e539063cb4..1d6250afe4c3245bffd2b1be651f7af52b089a3b 100644 (file)
@@ -4,10 +4,16 @@
 
 #include "PartSet_Validators.h"
 
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <BRep_Tool.hxx>
+#include <GeomAdaptor_Curve.hxx>
+#include <GeomAbs_CurveType.hxx>
+
 #include <list>
 
 
-int shapesNb(const ModuleBase_ISelection* theSelection, TopAbs_ShapeEnum theType)
+int shapesNbPoints(const ModuleBase_ISelection* theSelection)
 {
   std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
   std::list<ModuleBase_ViewerPrs>::iterator it;
@@ -17,21 +23,79 @@ int shapesNb(const ModuleBase_ISelection* theSelection, TopAbs_ShapeEnum theType
     aPrs = *it;
     const TopoDS_Shape& aShape = aPrs.shape();
     if (!aShape.IsNull()) {
-      if (aShape.ShapeType() == theType)
+      if (aShape.ShapeType() == TopAbs_VERTEX)
         aCount++;
     }
   }
   return aCount;
 }
 
+int shapesNbLines(const ModuleBase_ISelection* theSelection)
+{
+  std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
+  std::list<ModuleBase_ViewerPrs>::iterator it;
+  ModuleBase_ViewerPrs aPrs;
+  int aCount = 0;
+  for (it = aList.begin(); it != aList.end(); ++it) {
+    aPrs = *it;
+    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_Line)
+          aCount++;
+      }
+    }
+  }
+  return aCount;
+}
+
 bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const
 {
-  int aCount = shapesNb(theSelection, TopAbs_VERTEX);
+  int aCount = shapesNbPoints(theSelection);
   return (aCount > 0) && (aCount < 3);
 }
 
 bool PartSet_LengthValidator::isValid(const ModuleBase_ISelection* theSelection) const
 {
-  int aCount = shapesNb(theSelection, TopAbs_EDGE);
-  return (aCount == 1);
-}
\ No newline at end of file
+  int aCount = shapesNbLines(theSelection);
+  return (aCount > 0) && (aCount < 2);
+}
+
+bool PartSet_PerpendicularValidator::isValid(const ModuleBase_ISelection* theSelection) const
+{
+  int aCount = shapesNbLines(theSelection);
+  return (aCount > 0) && (aCount < 3);
+}
+
+bool PartSet_ParallelValidator::isValid(const ModuleBase_ISelection* theSelection) const
+{
+  int aCount = shapesNbLines(theSelection);
+  return (aCount > 0) && (aCount < 3);
+}
+
+bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) const
+{
+  std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
+  std::list<ModuleBase_ViewerPrs>::iterator it;
+  ModuleBase_ViewerPrs aPrs;
+  int aCount = 0;
+  for (it = aList.begin(); it != aList.end(); ++it) {
+    aPrs = *it;
+    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 > 0) && (aCount < 2);
+}
index 10cdcf26a72e3fd5064ea39a6abbefc210746818..90487fe4f722de683f0cdee5caab1d4b69e4df83 100644 (file)
 #include <ModuleBase_SelectionValidator.h>
 #include <ModuleBase_ISelection.h>
 
+//! A class to validate a selection for Distance constraint operation
 class PartSet_DistanceValidator: public ModuleBase_SelectionValidator
 {
 public:
   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
 };
 
+//! A class to validate a selection for Length constraint operation
 class PartSet_LengthValidator: public ModuleBase_SelectionValidator
 {
 public:
   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
 };
 
+//! A class to validate a selection for Perpendicular constraint operation
+class PartSet_PerpendicularValidator: public ModuleBase_SelectionValidator
+{
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
+//! A class to validate a selection for Perpendicular constraint operation
+class PartSet_ParallelValidator: public ModuleBase_SelectionValidator
+{
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
+//! A class to validate a selection for Perpendicular constraint operation
+class PartSet_RadiusValidator: public ModuleBase_SelectionValidator
+{
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
 #endif