1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_CircleDriver.hxx>
24 #include <GEOMImpl_ICircle.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRepBuilderAPI_MakeEdge.hxx>
29 #include <BRep_Tool.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Vertex.hxx>
37 #include <GC_MakeCircle.hxx>
38 #include <Geom_Circle.hxx>
40 #include <Standard_ConstructionError.hxx>
41 #include <Precision.hxx>
44 #include <gp_Circ.hxx>
46 //=======================================================================
49 //=======================================================================
50 const Standard_GUID& GEOMImpl_CircleDriver::GetID()
52 static Standard_GUID aCircleDriver("FF1BBB32-5D14-4df2-980B-3A668264EA16");
57 //=======================================================================
58 //function : GEOMImpl_CircleDriver
60 //=======================================================================
61 GEOMImpl_CircleDriver::GEOMImpl_CircleDriver()
65 //=======================================================================
68 //=======================================================================
69 Standard_Integer GEOMImpl_CircleDriver::Execute(TFunction_Logbook& log) const
71 if (Label().IsNull()) return 0;
72 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
74 GEOMImpl_ICircle aCI (aFunction);
75 Standard_Integer aType = aFunction->GetType();
79 if (aType == CIRCLE_PNT_VEC_R) {
80 Handle(GEOM_Function) aRefPoint = aCI.GetCenter();
81 Handle(GEOM_Function) aRefVector = aCI.GetVector();
82 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
83 TopoDS_Shape aShapeVec = aRefVector->GetValue();
84 if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
85 aShapeVec.ShapeType() == TopAbs_EDGE) {
86 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
87 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
89 TopExp::Vertices(anE, V1, V2, Standard_True);
90 if (!V1.IsNull() && !V2.IsNull()) {
91 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
92 gp_Ax2 anAxes (aP, aV);
93 gp_Circ aCirc (anAxes, aCI.GetRadius());
94 aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge();
98 else if (aType == CIRCLE_THREE_PNT) {
99 Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
100 Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
101 Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
102 TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
103 TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
104 TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
105 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
106 aShapePnt2.ShapeType() == TopAbs_VERTEX &&
107 aShapePnt3.ShapeType() == TopAbs_VERTEX) {
108 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
109 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
110 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
111 if (aP1.Distance(aP2) < gp::Resolution() ||
112 aP1.Distance(aP3) < gp::Resolution() ||
113 aP2.Distance(aP3) < gp::Resolution())
114 Standard_ConstructionError::Raise("Circle creation aborted: coincident points given");
115 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
116 Standard_ConstructionError::Raise("Circle creation aborted: points lay on one line");
117 Handle(Geom_Circle) aCirc = GC_MakeCircle(aP1, aP2, aP3).Value();
118 aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge();
124 if (aShape.IsNull()) return 0;
126 aFunction->SetValue(aShape);
128 log.SetTouched(Label());
134 //=======================================================================
135 //function : GEOMImpl_CircleDriver_Type_
137 //=======================================================================
138 Standard_EXPORT Handle_Standard_Type& GEOMImpl_CircleDriver_Type_()
141 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
142 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
143 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
144 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
145 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
146 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
149 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
150 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_CircleDriver",
151 sizeof(GEOMImpl_CircleDriver),
153 (Standard_Address)_Ancestors,
154 (Standard_Address)NULL);
159 //=======================================================================
160 //function : DownCast
162 //=======================================================================
163 const Handle(GEOMImpl_CircleDriver) Handle(GEOMImpl_CircleDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
165 Handle(GEOMImpl_CircleDriver) _anOtherObject;
167 if (!AnObject.IsNull()) {
168 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CircleDriver))) {
169 _anOtherObject = Handle(GEOMImpl_CircleDriver)((Handle(GEOMImpl_CircleDriver)&)AnObject);
173 return _anOtherObject ;