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>
15 int shapesNbPoints(const ModuleBase_ISelection* theSelection)
17 std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
18 std::list<ModuleBase_ViewerPrs>::iterator it;
19 ModuleBase_ViewerPrs aPrs;
21 for (it = aList.begin(); it != aList.end(); ++it) {
23 const TopoDS_Shape& aShape = aPrs.shape();
24 if (!aShape.IsNull()) {
25 if (aShape.ShapeType() == TopAbs_VERTEX)
32 int shapesNbLines(const ModuleBase_ISelection* theSelection)
34 std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
35 std::list<ModuleBase_ViewerPrs>::iterator it;
36 ModuleBase_ViewerPrs aPrs;
38 for (it = aList.begin(); it != aList.end(); ++it) {
40 const TopoDS_Shape& aShape = aPrs.shape();
41 if (!aShape.IsNull()) {
42 if (aShape.ShapeType() == TopAbs_EDGE) {
43 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
44 Standard_Real aStart, aEnd;
45 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
46 GeomAdaptor_Curve aAdaptor(aCurve);
47 if (aAdaptor.GetType() == GeomAbs_Line)
55 bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const
57 int aCount = shapesNbPoints(theSelection);
58 return (aCount > 0) && (aCount < 3);
61 bool PartSet_LengthValidator::isValid(const ModuleBase_ISelection* theSelection) const
63 int aCount = shapesNbLines(theSelection);
64 return (aCount > 0) && (aCount < 2);
67 bool PartSet_PerpendicularValidator::isValid(const ModuleBase_ISelection* theSelection) const
69 int aCount = shapesNbLines(theSelection);
70 return (aCount > 0) && (aCount < 3);
73 bool PartSet_ParallelValidator::isValid(const ModuleBase_ISelection* theSelection) const
75 int aCount = shapesNbLines(theSelection);
76 return (aCount > 0) && (aCount < 3);
79 bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) const
81 std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
82 std::list<ModuleBase_ViewerPrs>::iterator it;
83 ModuleBase_ViewerPrs aPrs;
85 for (it = aList.begin(); it != aList.end(); ++it) {
87 const TopoDS_Shape& aShape = aPrs.shape();
88 if (!aShape.IsNull()) {
89 if (aShape.ShapeType() == TopAbs_EDGE) {
90 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
91 Standard_Real aStart, aEnd;
92 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
93 GeomAdaptor_Curve aAdaptor(aCurve);
94 if (aAdaptor.GetType() == GeomAbs_Circle)
99 return (aCount > 0) && (aCount < 2);