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