]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ResultValidators.cpp
Salome HOME
Result attributes validators created
[modules/shaper.git] / src / ModuleBase / ModuleBase_ResultValidators.cpp
1 // File:        ModuleBase_ResultValidators.cpp
2 // Created:     23 July 2014
3 // Author:      Vitaly SMETANNIKOV
4
5 #include "ModuleBase_ResultValidators.h"
6 #include "ModuleBase_Tools.h"
7
8 #include <ModelAPI_Result.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
18 ResultPtr result(const ObjectPtr theObject)
19 {
20   return boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
21 }
22
23 TopoDS_Shape shape(ResultPtr theResult)
24 {
25   boost::shared_ptr<GeomAPI_Shape> aShape = ModuleBase_Tools::shape(theResult);
26   if (aShape)
27     return aShape->impl<TopoDS_Shape>();
28   return TopoDS_Shape();
29 }
30
31
32 bool ModuleBase_ResulPointValidator::isValid(const ObjectPtr theObject) const
33 {
34   ResultPtr aResult = result(theObject);
35   if (!aResult)
36     return false;
37   TopoDS_Shape aShape = shape(aResult);
38   if (aShape.IsNull())
39     return false;
40
41   return aShape.ShapeType() == TopAbs_VERTEX;
42 }
43
44
45 bool ModuleBase_ResulLineValidator::isValid(const ObjectPtr theObject) const
46 {
47   ResultPtr aResult = result(theObject);
48   if (!aResult)
49     return false;
50   TopoDS_Shape aShape = shape(aResult);
51   if (aShape.IsNull())
52     return false;
53
54   if (aShape.ShapeType() == TopAbs_EDGE) {
55     TopoDS_Edge aEdge = TopoDS::Edge(aShape);
56     Standard_Real aStart, aEnd;
57     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
58     GeomAdaptor_Curve aAdaptor(aCurve);
59     return aAdaptor.GetType() == GeomAbs_Line;
60   }
61   return false;
62 }
63
64
65 bool ModuleBase_ResulArcValidator::isValid(const ObjectPtr theObject) const
66 {
67   ResultPtr aResult = result(theObject);
68   if (!aResult)
69     return false;
70   TopoDS_Shape aShape = shape(aResult);
71   if (aShape.IsNull())
72     return false;
73
74   if (aShape.ShapeType() == TopAbs_EDGE) {
75     TopoDS_Edge aEdge = TopoDS::Edge(aShape);
76     Standard_Real aStart, aEnd;
77     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
78     GeomAdaptor_Curve aAdaptor(aCurve);
79     return aAdaptor.GetType() == GeomAbs_Circle;
80   }
81   return false;
82 }
83