3 #include "GEOMImpl_ArcDriver.hxx"
4 #include "GEOMImpl_IArc.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_MakeArcOfCircle.hxx>
19 #include <Standard_ConstructionError.hxx>
20 #include <Precision.hxx>
24 //=======================================================================
27 //=======================================================================
28 const Standard_GUID& GEOMImpl_ArcDriver::GetID()
30 static Standard_GUID aArcDriver("FF1BBB35-5D14-4df2-980B-3A668264EA16");
35 //=======================================================================
36 //function : GEOMImpl_ArcDriver
38 //=======================================================================
39 GEOMImpl_ArcDriver::GEOMImpl_ArcDriver()
43 //=======================================================================
46 //=======================================================================
47 Standard_Integer GEOMImpl_ArcDriver::Execute(TFunction_Logbook& log) const
49 if (Label().IsNull()) return 0;
50 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
52 GEOMImpl_IArc aCI (aFunction);
53 Standard_Integer aType = aFunction->GetType();
57 if (aType == CIRC_ARC_THREE_PNT) {
58 Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
59 Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
60 Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
61 TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
62 TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
63 TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
64 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
65 aShapePnt2.ShapeType() == TopAbs_VERTEX &&
66 aShapePnt3.ShapeType() == TopAbs_VERTEX) {
67 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
68 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
69 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
70 if (aP1.Distance(aP2) < gp::Resolution() ||
71 aP1.Distance(aP3) < gp::Resolution() ||
72 aP2.Distance(aP3) < gp::Resolution())
73 Standard_ConstructionError::Raise("Arc creation aborted: coincident points given");
74 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
75 Standard_ConstructionError::Raise("Arc creation aborted: points lay on one line");
76 GC_MakeArcOfCircle arc (aP1, aP2, aP3);
77 aShape = BRepBuilderAPI_MakeEdge(arc).Edge();
82 if (aShape.IsNull()) return 0;
84 aFunction->SetValue(aShape);
86 log.SetTouched(Label());
92 //=======================================================================
93 //function : GEOMImpl_ArcDriver_Type_
95 //=======================================================================
96 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArcDriver_Type_()
99 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
100 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
101 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
102 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
103 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
104 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
107 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
108 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArcDriver",
109 sizeof(GEOMImpl_ArcDriver),
111 (Standard_Address)_Ancestors,
112 (Standard_Address)NULL);
117 //=======================================================================
118 //function : DownCast
120 //=======================================================================
121 const Handle(GEOMImpl_ArcDriver) Handle(GEOMImpl_ArcDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
123 Handle(GEOMImpl_ArcDriver) _anOtherObject;
125 if (!AnObject.IsNull()) {
126 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArcDriver))) {
127 _anOtherObject = Handle(GEOMImpl_ArcDriver)((Handle(GEOMImpl_ArcDriver)&)AnObject);
131 return _anOtherObject ;