]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_ResultValidators.cpp
Salome HOME
Sources formated according to the codeing standards
[modules/shaper.git] / src / Model / Model_ResultValidators.cpp
1 // File:        Model_ResultValidators.cpp
2 // Created:     23 July 2014
3 // Author:      Vitaly SMETANNIKOV
4
5 #include "Model_ResultValidators.h"
6
7 #include <ModelAPI_Result.h>
8 #include <ModelAPI_Tools.h>
9 #include <GeomAPI_Shape.h>
10
11 #include <TopoDS_Shape.hxx>
12 #include <TopoDS_Edge.hxx>
13 #include <TopoDS.hxx>
14 #include <BRep_Tool.hxx>
15 #include <GeomAdaptor_Curve.hxx>
16
17 ResultPtr result(const ObjectPtr theObject)
18 {
19   return boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
20 }
21
22 TopoDS_Shape shape(ResultPtr theResult)
23 {
24   boost::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(theResult);
25   if (aShape)
26     return aShape->impl<TopoDS_Shape>();
27   return TopoDS_Shape();
28 }
29
30 bool Model_ResultPointValidator::isValid(const ObjectPtr theObject) const
31 {
32   ResultPtr aResult = result(theObject);
33   if (!aResult)
34     return false;
35   TopoDS_Shape aShape = shape(aResult);
36   if (aShape.IsNull())
37     return false;
38
39   return aShape.ShapeType() == TopAbs_VERTEX;
40 }
41
42 bool Model_ResultLineValidator::isValid(const ObjectPtr theObject) const
43 {
44   ResultPtr aResult = result(theObject);
45   if (!aResult)
46     return false;
47   TopoDS_Shape aShape = shape(aResult);
48   if (aShape.IsNull())
49     return false;
50
51   if (aShape.ShapeType() == TopAbs_EDGE) {
52     TopoDS_Edge aEdge = TopoDS::Edge(aShape);
53     Standard_Real aStart, aEnd;
54     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
55     GeomAdaptor_Curve aAdaptor(aCurve);
56     return aAdaptor.GetType() == GeomAbs_Line;
57   }
58   return false;
59 }
60
61 bool Model_ResultArcValidator::isValid(const ObjectPtr theObject) const
62 {
63   ResultPtr aResult = result(theObject);
64   if (!aResult)
65     return false;
66   TopoDS_Shape aShape = shape(aResult);
67   if (aShape.IsNull())
68     return false;
69
70   TopAbs_ShapeEnum aa = aShape.ShapeType();
71   if (aShape.ShapeType() == TopAbs_EDGE) {
72     TopoDS_Edge aEdge = TopoDS::Edge(aShape);
73     Standard_Real aStart, aEnd;
74     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
75     GeomAdaptor_Curve aAdaptor(aCurve);
76     return aAdaptor.GetType() == GeomAbs_Circle;
77   }
78   return false;
79 }
80