From: vsv Date: Thu, 10 Jul 2014 15:09:19 +0000 (+0400) Subject: Selection validators improvements X-Git-Tag: V_0.4.4~202 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=47c18d4de2719126f6b045b5c37525cd8f170aa1;p=modules%2Fshaper.git Selection validators improvements --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 2824363e1..3814ed1c6 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -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) diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 296f8daa6..1d6250afe 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -4,10 +4,16 @@ #include "PartSet_Validators.h" +#include +#include +#include +#include +#include + #include -int shapesNb(const ModuleBase_ISelection* theSelection, TopAbs_ShapeEnum theType) +int shapesNbPoints(const ModuleBase_ISelection* theSelection) { std::list aList = theSelection->getSelected(); std::list::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 aList = theSelection->getSelected(); + std::list::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 aList = theSelection->getSelected(); + std::list::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); +} diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h index 10cdcf26a..90487fe4f 100644 --- a/src/PartSet/PartSet_Validators.h +++ b/src/PartSet/PartSet_Validators.h @@ -10,16 +10,39 @@ #include #include +//! 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