1 // File: PartSet_Validators.cpp
2 // Created: 09 July 2014
3 // Author: Vitaly SMETANNIKOV
5 #include "PartSet_Validators.h"
8 #include <TopoDS_Edge.hxx>
9 #include <BRep_Tool.hxx>
10 #include <GeomAdaptor_Curve.hxx>
11 #include <GeomAbs_CurveType.hxx>
12 #include <ModuleBase_ISelection.h>
16 int shapesNbPoints(const ModuleBase_ISelection* theSelection)
18 QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
20 foreach (ModuleBase_ViewerPrs aPrs, aList) {
21 const TopoDS_Shape& aShape = aPrs.shape();
22 if (!aShape.IsNull()) {
23 if (aShape.ShapeType() == TopAbs_VERTEX)
30 int shapesNbLines(const ModuleBase_ISelection* theSelection)
32 QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
34 foreach(ModuleBase_ViewerPrs aPrs, aList) {
35 const TopoDS_Shape& aShape = aPrs.shape();
36 if (!aShape.IsNull()) {
37 if (aShape.ShapeType() == TopAbs_EDGE) {
38 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
39 Standard_Real aStart, aEnd;
40 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
41 GeomAdaptor_Curve aAdaptor(aCurve);
42 if (aAdaptor.GetType() == GeomAbs_Line)
50 bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const
52 int aCount = shapesNbPoints(theSelection);
53 return (aCount > 0) && (aCount < 3);
56 bool PartSet_LengthValidator::isValid(const ModuleBase_ISelection* theSelection) const
58 int aCount = shapesNbLines(theSelection);
59 return (aCount > 0) && (aCount < 2);
62 bool PartSet_PerpendicularValidator::isValid(const ModuleBase_ISelection* theSelection) const
64 int aCount = shapesNbLines(theSelection);
65 return (aCount > 0) && (aCount < 3);
68 bool PartSet_ParallelValidator::isValid(const ModuleBase_ISelection* theSelection) const
70 int aCount = shapesNbLines(theSelection);
71 return (aCount > 0) && (aCount < 3);
74 bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) const
76 QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
77 ModuleBase_ViewerPrs aPrs;
79 foreach (ModuleBase_ViewerPrs aPrs, aList) {
80 const TopoDS_Shape& aShape = aPrs.shape();
81 if (!aShape.IsNull()) {
82 if (aShape.ShapeType() == TopAbs_EDGE) {
83 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
84 Standard_Real aStart, aEnd;
85 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
86 GeomAdaptor_Curve aAdaptor(aCurve);
87 if (aAdaptor.GetType() == GeomAbs_Circle)
92 return (aCount > 0) && (aCount < 2);