3 #include "GEOMImpl_CircleDriver.hxx"
4 #include "GEOMImpl_ICircle.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRepBuilderAPI_MakeEdge.hxx>
9 #include <BRep_Tool.hxx>
11 #include <TopoDS_Shape.hxx>
12 #include <TopoDS_Edge.hxx>
13 #include <TopoDS_Vertex.hxx>
17 #include <GC_MakeCircle.hxx>
18 #include <Geom_Circle.hxx>
20 #include <Standard_ConstructionError.hxx>
21 #include <Precision.hxx>
24 #include <gp_Circ.hxx>
26 //=======================================================================
29 //=======================================================================
30 const Standard_GUID& GEOMImpl_CircleDriver::GetID()
32 static Standard_GUID aCircleDriver("FF1BBB32-5D14-4df2-980B-3A668264EA16");
37 //=======================================================================
38 //function : GEOMImpl_CircleDriver
40 //=======================================================================
41 GEOMImpl_CircleDriver::GEOMImpl_CircleDriver()
45 //=======================================================================
48 //=======================================================================
49 Standard_Integer GEOMImpl_CircleDriver::Execute(TFunction_Logbook& log) const
51 if (Label().IsNull()) return 0;
52 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
54 GEOMImpl_ICircle aCI (aFunction);
55 Standard_Integer aType = aFunction->GetType();
59 if (aType == CIRCLE_PNT_VEC_R) {
60 Handle(GEOM_Function) aRefPoint = aCI.GetCenter();
61 Handle(GEOM_Function) aRefVector = aCI.GetVector();
62 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
63 TopoDS_Shape aShapeVec = aRefVector->GetValue();
64 if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
65 aShapeVec.ShapeType() == TopAbs_EDGE) {
66 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
67 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
69 TopExp::Vertices(anE, V1, V2, Standard_True);
70 if (!V1.IsNull() && !V2.IsNull()) {
71 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
72 gp_Ax2 anAxes (aP, aV);
73 gp_Circ aCirc (anAxes, aCI.GetRadius());
74 aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge();
78 else if (aType == CIRCLE_THREE_PNT) {
79 Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
80 Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
81 Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
82 TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
83 TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
84 TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
85 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
86 aShapePnt2.ShapeType() == TopAbs_VERTEX &&
87 aShapePnt3.ShapeType() == TopAbs_VERTEX) {
88 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
89 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
90 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
91 if (aP1.Distance(aP2) < gp::Resolution() ||
92 aP1.Distance(aP3) < gp::Resolution() ||
93 aP2.Distance(aP3) < gp::Resolution())
94 Standard_ConstructionError::Raise("Circle creation aborted: coincident points given");
95 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
96 Standard_ConstructionError::Raise("Circle creation aborted: points lay on one line");
97 Handle(Geom_Circle) aCirc = GC_MakeCircle(aP1, aP2, aP3).Value();
98 aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge();
104 if (aShape.IsNull()) return 0;
106 aFunction->SetValue(aShape);
108 log.SetTouched(Label());
114 //=======================================================================
115 //function : GEOMImpl_CircleDriver_Type_
117 //=======================================================================
118 Standard_EXPORT Handle_Standard_Type& GEOMImpl_CircleDriver_Type_()
121 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
122 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
123 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
124 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
125 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
126 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
129 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
130 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_CircleDriver",
131 sizeof(GEOMImpl_CircleDriver),
133 (Standard_Address)_Ancestors,
134 (Standard_Address)NULL);
139 //=======================================================================
140 //function : DownCast
142 //=======================================================================
143 const Handle(GEOMImpl_CircleDriver) Handle(GEOMImpl_CircleDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
145 Handle(GEOMImpl_CircleDriver) _anOtherObject;
147 if (!AnObject.IsNull()) {
148 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CircleDriver))) {
149 _anOtherObject = Handle(GEOMImpl_CircleDriver)((Handle(GEOMImpl_CircleDriver)&)AnObject);
153 return _anOtherObject ;