2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_ArcDriver.hxx>
5 #include <GEOMImpl_IArc.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_MakeArcOfCircle.hxx>
20 #include <Standard_ConstructionError.hxx>
21 #include <Precision.hxx>
25 //=======================================================================
28 //=======================================================================
29 const Standard_GUID& GEOMImpl_ArcDriver::GetID()
31 static Standard_GUID aArcDriver("FF1BBB35-5D14-4df2-980B-3A668264EA16");
36 //=======================================================================
37 //function : GEOMImpl_ArcDriver
39 //=======================================================================
40 GEOMImpl_ArcDriver::GEOMImpl_ArcDriver()
44 //=======================================================================
47 //=======================================================================
48 Standard_Integer GEOMImpl_ArcDriver::Execute(TFunction_Logbook& log) const
50 if (Label().IsNull()) return 0;
51 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
53 GEOMImpl_IArc aCI (aFunction);
54 Standard_Integer aType = aFunction->GetType();
58 if (aType == CIRC_ARC_THREE_PNT) {
59 Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
60 Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
61 Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
62 TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
63 TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
64 TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
65 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
66 aShapePnt2.ShapeType() == TopAbs_VERTEX &&
67 aShapePnt3.ShapeType() == TopAbs_VERTEX) {
68 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
69 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
70 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
71 if (aP1.Distance(aP2) < gp::Resolution() ||
72 aP1.Distance(aP3) < gp::Resolution() ||
73 aP2.Distance(aP3) < gp::Resolution())
74 Standard_ConstructionError::Raise("Arc creation aborted: coincident points given");
75 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
76 Standard_ConstructionError::Raise("Arc creation aborted: points lay on one line");
77 GC_MakeArcOfCircle arc (aP1, aP2, aP3);
78 aShape = BRepBuilderAPI_MakeEdge(arc).Edge();
83 if (aShape.IsNull()) return 0;
85 aFunction->SetValue(aShape);
87 log.SetTouched(Label());
93 //=======================================================================
94 //function : GEOMImpl_ArcDriver_Type_
96 //=======================================================================
97 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArcDriver_Type_()
100 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
101 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
102 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
103 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
104 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
105 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
108 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
109 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArcDriver",
110 sizeof(GEOMImpl_ArcDriver),
112 (Standard_Address)_Ancestors,
113 (Standard_Address)NULL);
118 //=======================================================================
119 //function : DownCast
121 //=======================================================================
122 const Handle(GEOMImpl_ArcDriver) Handle(GEOMImpl_ArcDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
124 Handle(GEOMImpl_ArcDriver) _anOtherObject;
126 if (!AnObject.IsNull()) {
127 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArcDriver))) {
128 _anOtherObject = Handle(GEOMImpl_ArcDriver)((Handle(GEOMImpl_ArcDriver)&)AnObject);
132 return _anOtherObject ;