Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PointDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_PointDriver.hxx"
4 #include "GEOMImpl_IPoint.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRep_Tool.hxx>
9 #include <BRepBuilderAPI_MakeVertex.hxx>
10
11 #include <TopAbs.hxx>
12 #include <TopoDS.hxx>
13 #include <TopoDS_Edge.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Vertex.hxx>
16
17 #include <Geom_Curve.hxx>
18 #include <gp_Pnt.hxx>
19
20 //=======================================================================
21 //function : GetID
22 //purpose  :
23 //=======================================================================
24 const Standard_GUID& GEOMImpl_PointDriver::GetID()
25 {
26   static Standard_GUID aPointDriver("FF1BBB02-5D14-4df2-980B-3A668264EA16");
27   return aPointDriver;
28 }
29
30
31 //=======================================================================
32 //function : GEOMImpl_PointDriver
33 //purpose  :
34 //=======================================================================
35 GEOMImpl_PointDriver::GEOMImpl_PointDriver()
36 {
37 }
38
39 //=======================================================================
40 //function : Execute
41 //purpose  :
42 //=======================================================================
43 Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
44 {
45   if (Label().IsNull())  return 0;
46   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
47
48   GEOMImpl_IPoint aPI (aFunction);
49   Standard_Integer aType = aFunction->GetType();
50
51   gp_Pnt aPnt;
52
53   if (aType == POINT_XYZ) {
54     aPnt = gp_Pnt(aPI.GetX(), aPI.GetY(), aPI.GetZ());
55
56   } else if (aType == POINT_XYZ_REF) {
57
58     Handle(GEOM_Function) aRefPoint = aPI.GetRef();
59     TopoDS_Shape aRefShape = aRefPoint->GetValue();
60     if (aRefShape.ShapeType() != TopAbs_VERTEX) {
61       Standard_TypeMismatch::Raise
62         ("Point creation aborted : referenced shape is not a vertex");
63     }
64     gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(aRefShape));
65     aPnt = gp_Pnt(P.X() + aPI.GetX(), P.Y() + aPI.GetY(), P.Z() + aPI.GetZ());
66
67   } else if (aType == POINT_CURVE_PAR) {
68
69     Handle(GEOM_Function) aRefCurve = aPI.GetCurve();
70     TopoDS_Shape aRefShape = aRefCurve->GetValue();
71     if (aRefShape.ShapeType() != TopAbs_EDGE) {
72       Standard_TypeMismatch::Raise
73         ("Point On Curve creation aborted : curve shape is not an edge");
74     }
75     Standard_Real aFP, aLP, aP;
76     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aRefShape), aFP, aLP);
77     aP = aFP + (aLP - aFP) * aPI.GetParameter();
78     aPnt = aCurve->Value(aP);
79
80   } else {
81     return 0;
82   }
83
84   BRepBuilderAPI_MakeVertex mkVertex (aPnt);
85   TopoDS_Shape aShape = mkVertex.Shape();
86   aShape.Infinite(Standard_True);
87   aFunction->SetValue(aShape);
88
89   log.SetTouched(Label());
90
91   return 1;
92 }
93
94
95 //=======================================================================
96 //function :  GEOMImpl_PointDriver_Type_
97 //purpose  :
98 //=======================================================================
99 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PointDriver_Type_()
100 {
101
102   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
103   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
104   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
105   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
106   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
107   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
108
109
110   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
111   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PointDriver",
112                                                          sizeof(GEOMImpl_PointDriver),
113                                                          1,
114                                                          (Standard_Address)_Ancestors,
115                                                          (Standard_Address)NULL);
116
117   return _aType;
118 }
119
120 //=======================================================================
121 //function : DownCast
122 //purpose  :
123 //=======================================================================
124
125 const Handle(GEOMImpl_PointDriver) Handle(GEOMImpl_PointDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
126 {
127   Handle(GEOMImpl_PointDriver) _anOtherObject;
128
129   if (!AnObject.IsNull()) {
130      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PointDriver))) {
131        _anOtherObject = Handle(GEOMImpl_PointDriver)((Handle(GEOMImpl_PointDriver)&)AnObject);
132      }
133   }
134
135   return _anOtherObject ;
136 }
137
138