2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_CircleDriver.hxx>
5 #include <GEOMImpl_ICircle.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRepBuilderAPI_MakeEdge.hxx>
10 #include <BRep_Tool.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Edge.hxx>
14 #include <TopoDS_Vertex.hxx>
18 #include <GC_MakeCircle.hxx>
19 #include <Geom_Circle.hxx>
21 #include <Standard_ConstructionError.hxx>
22 #include <Precision.hxx>
25 #include <gp_Circ.hxx>
27 //=======================================================================
30 //=======================================================================
31 const Standard_GUID& GEOMImpl_CircleDriver::GetID()
33 static Standard_GUID aCircleDriver("FF1BBB32-5D14-4df2-980B-3A668264EA16");
38 //=======================================================================
39 //function : GEOMImpl_CircleDriver
41 //=======================================================================
42 GEOMImpl_CircleDriver::GEOMImpl_CircleDriver()
46 //=======================================================================
49 //=======================================================================
50 Standard_Integer GEOMImpl_CircleDriver::Execute(TFunction_Logbook& log) const
52 if (Label().IsNull()) return 0;
53 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
55 GEOMImpl_ICircle aCI (aFunction);
56 Standard_Integer aType = aFunction->GetType();
60 if (aType == CIRCLE_PNT_VEC_R) {
61 Handle(GEOM_Function) aRefPoint = aCI.GetCenter();
62 Handle(GEOM_Function) aRefVector = aCI.GetVector();
63 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
64 TopoDS_Shape aShapeVec = aRefVector->GetValue();
65 if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
66 aShapeVec.ShapeType() == TopAbs_EDGE) {
67 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
68 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
70 TopExp::Vertices(anE, V1, V2, Standard_True);
71 if (!V1.IsNull() && !V2.IsNull()) {
72 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
73 gp_Ax2 anAxes (aP, aV);
74 gp_Circ aCirc (anAxes, aCI.GetRadius());
75 aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge();
79 else if (aType == CIRCLE_THREE_PNT) {
80 Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
81 Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
82 Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
83 TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
84 TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
85 TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
86 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
87 aShapePnt2.ShapeType() == TopAbs_VERTEX &&
88 aShapePnt3.ShapeType() == TopAbs_VERTEX) {
89 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
90 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
91 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
92 if (aP1.Distance(aP2) < gp::Resolution() ||
93 aP1.Distance(aP3) < gp::Resolution() ||
94 aP2.Distance(aP3) < gp::Resolution())
95 Standard_ConstructionError::Raise("Circle creation aborted: coincident points given");
96 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
97 Standard_ConstructionError::Raise("Circle creation aborted: points lay on one line");
98 Handle(Geom_Circle) aCirc = GC_MakeCircle(aP1, aP2, aP3).Value();
99 aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge();
105 if (aShape.IsNull()) return 0;
107 aFunction->SetValue(aShape);
109 log.SetTouched(Label());
115 //=======================================================================
116 //function : GEOMImpl_CircleDriver_Type_
118 //=======================================================================
119 Standard_EXPORT Handle_Standard_Type& GEOMImpl_CircleDriver_Type_()
122 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
123 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
124 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
125 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
126 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
127 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
130 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
131 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_CircleDriver",
132 sizeof(GEOMImpl_CircleDriver),
134 (Standard_Address)_Ancestors,
135 (Standard_Address)NULL);
140 //=======================================================================
141 //function : DownCast
143 //=======================================================================
144 const Handle(GEOMImpl_CircleDriver) Handle(GEOMImpl_CircleDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
146 Handle(GEOMImpl_CircleDriver) _anOtherObject;
148 if (!AnObject.IsNull()) {
149 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CircleDriver))) {
150 _anOtherObject = Handle(GEOMImpl_CircleDriver)((Handle(GEOMImpl_CircleDriver)&)AnObject);
154 return _anOtherObject ;