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>
16 int shapesNbPoints(const ModuleBase_ISelection* theSelection)
18 std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
19 std::list<ModuleBase_ViewerPrs>::iterator it;
20 ModuleBase_ViewerPrs aPrs;
22 for (it = aList.begin(); it != aList.end(); ++it) {
24 const TopoDS_Shape& aShape = aPrs.shape();
25 if (!aShape.IsNull()) {
26 if (aShape.ShapeType() == TopAbs_VERTEX)
33 int shapesNbLines(const ModuleBase_ISelection* theSelection)
35 std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
36 std::list<ModuleBase_ViewerPrs>::iterator it;
37 ModuleBase_ViewerPrs aPrs;
39 for (it = aList.begin(); it != aList.end(); ++it) {
41 const TopoDS_Shape& aShape = aPrs.shape();
42 if (!aShape.IsNull()) {
43 if (aShape.ShapeType() == TopAbs_EDGE) {
44 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
45 Standard_Real aStart, aEnd;
46 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
47 GeomAdaptor_Curve aAdaptor(aCurve);
48 if (aAdaptor.GetType() == GeomAbs_Line)
56 bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const
58 int aCount = shapesNbPoints(theSelection);
59 return (aCount > 0) && (aCount < 3);
62 bool PartSet_LengthValidator::isValid(const ModuleBase_ISelection* theSelection) const
64 int aCount = shapesNbLines(theSelection);
65 return (aCount > 0) && (aCount < 2);
68 bool PartSet_PerpendicularValidator::isValid(const ModuleBase_ISelection* theSelection) const
70 int aCount = shapesNbLines(theSelection);
71 return (aCount > 0) && (aCount < 3);
74 bool PartSet_ParallelValidator::isValid(const ModuleBase_ISelection* theSelection) const
76 int aCount = shapesNbLines(theSelection);
77 return (aCount > 0) && (aCount < 3);
80 bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) const
82 std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
83 std::list<ModuleBase_ViewerPrs>::iterator it;
84 ModuleBase_ViewerPrs aPrs;
86 for (it = aList.begin(); it != aList.end(); ++it) {
88 const TopoDS_Shape& aShape = aPrs.shape();
89 if (!aShape.IsNull()) {
90 if (aShape.ShapeType() == TopAbs_EDGE) {
91 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
92 Standard_Real aStart, aEnd;
93 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
94 GeomAdaptor_Curve aAdaptor(aCurve);
95 if (aAdaptor.GetType() == GeomAbs_Circle)
100 return (aCount > 0) && (aCount < 2);