#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;
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);
+}