3 #include "GEOMImpl_PointDriver.hxx"
4 #include "GEOMImpl_IPoint.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRep_Tool.hxx>
9 #include <BRepBuilderAPI_MakeVertex.hxx>
13 #include <TopoDS_Edge.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Vertex.hxx>
17 #include <Geom_Curve.hxx>
20 //=======================================================================
23 //=======================================================================
24 const Standard_GUID& GEOMImpl_PointDriver::GetID()
26 static Standard_GUID aPointDriver("FF1BBB02-5D14-4df2-980B-3A668264EA16");
31 //=======================================================================
32 //function : GEOMImpl_PointDriver
34 //=======================================================================
35 GEOMImpl_PointDriver::GEOMImpl_PointDriver()
39 //=======================================================================
42 //=======================================================================
43 Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
45 if (Label().IsNull()) return 0;
46 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
48 GEOMImpl_IPoint aPI (aFunction);
49 Standard_Integer aType = aFunction->GetType();
53 if (aType == POINT_XYZ) {
54 aPnt = gp_Pnt(aPI.GetX(), aPI.GetY(), aPI.GetZ());
56 } else if (aType == POINT_XYZ_REF) {
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");
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());
67 } else if (aType == POINT_CURVE_PAR) {
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");
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);
84 BRepBuilderAPI_MakeVertex mkVertex (aPnt);
85 TopoDS_Shape aShape = mkVertex.Shape();
86 aShape.Infinite(Standard_True);
87 aFunction->SetValue(aShape);
89 log.SetTouched(Label());
95 //=======================================================================
96 //function : GEOMImpl_PointDriver_Type_
98 //=======================================================================
99 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PointDriver_Type_()
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);
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),
114 (Standard_Address)_Ancestors,
115 (Standard_Address)NULL);
120 //=======================================================================
121 //function : DownCast
123 //=======================================================================
125 const Handle(GEOMImpl_PointDriver) Handle(GEOMImpl_PointDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
127 Handle(GEOMImpl_PointDriver) _anOtherObject;
129 if (!AnObject.IsNull()) {
130 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PointDriver))) {
131 _anOtherObject = Handle(GEOMImpl_PointDriver)((Handle(GEOMImpl_PointDriver)&)AnObject);
135 return _anOtherObject ;