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_ArcDriver.hxx>
24 #include <GEOMImpl_IArc.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_MakeArcOfCircle.hxx>
38 #include <Standard_ConstructionError.hxx>
39 #include <Precision.hxx>
42 #include <gce_MakeCirc.hxx>
43 #include <gce_MakePln.hxx>
45 #include <Geom_Circle.hxx>
46 #include <Geom_TrimmedCurve.hxx>
49 #include "utilities.h"
50 //=======================================================================
53 //=======================================================================
54 const Standard_GUID& GEOMImpl_ArcDriver::GetID()
56 static Standard_GUID aArcDriver("FF1BBB35-5D14-4df2-980B-3A668264EA16");
61 //=======================================================================
62 //function : GEOMImpl_ArcDriver
64 //=======================================================================
65 GEOMImpl_ArcDriver::GEOMImpl_ArcDriver()
69 //=======================================================================
72 //=======================================================================
73 Standard_Integer GEOMImpl_ArcDriver::Execute(TFunction_Logbook& log) const
75 if (Label().IsNull()) return 0;
76 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
78 GEOMImpl_IArc aCI (aFunction);
79 Standard_Integer aType = aFunction->GetType();
82 if ((aType == CIRC_ARC_THREE_PNT)||(aType == CIRC_ARC_CENTER)) {
83 Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
84 Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
85 Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
86 TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
87 TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
88 TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
89 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
90 aShapePnt2.ShapeType() == TopAbs_VERTEX &&
91 aShapePnt3.ShapeType() == TopAbs_VERTEX) {
92 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
93 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
94 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
95 if (aP1.Distance(aP2) < gp::Resolution() ||
96 aP1.Distance(aP3) < gp::Resolution() ||
97 aP2.Distance(aP3) < gp::Resolution())
98 Standard_ConstructionError::Raise("Arc creation aborted: coincident points given");
99 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
100 Standard_ConstructionError::Raise("Arc creation aborted: points lay on one line");
101 if (aType == CIRC_ARC_THREE_PNT){
102 GC_MakeArcOfCircle arc(aP1, aP2, aP3);
103 aShape = BRepBuilderAPI_MakeEdge(arc).Edge();
106 if (aType == CIRC_ARC_CENTER){
107 Standard_Real Rad = aP1.Distance(aP2);
108 gce_MakeCirc MC(aP1,gce_MakePln(aP1, aP2, aP3).Value(),Rad);
109 Standard_Boolean sense = aCI.GetSense();
111 const gp_Circ& Circ = MC.Value();
112 Standard_Real Alpha1 = ElCLib::Parameter(Circ,aP2);
113 Standard_Real Alpha2 = ElCLib::Parameter(Circ,aP3);
114 Handle(Geom_Circle) C = new Geom_Circle(Circ);
115 Handle(Geom_TrimmedCurve) TheArc;
117 TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,false);
119 TheArc= new Geom_TrimmedCurve(C,Alpha2,Alpha1,false);
120 aShape = BRepBuilderAPI_MakeEdge(TheArc).Edge();
127 if (aShape.IsNull()) return 0;
129 aFunction->SetValue(aShape);
131 log.SetTouched(Label());
132 MESSAGE("Out of building step ...");
137 //=======================================================================
138 //function : GEOMImpl_ArcDriver_Type_
140 //=======================================================================
141 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArcDriver_Type_()
144 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
145 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
146 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
147 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
148 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
149 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
152 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
153 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArcDriver",
154 sizeof(GEOMImpl_ArcDriver),
156 (Standard_Address)_Ancestors,
157 (Standard_Address)NULL);
162 //=======================================================================
163 //function : DownCast
165 //=======================================================================
166 const Handle(GEOMImpl_ArcDriver) Handle(GEOMImpl_ArcDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
168 Handle(GEOMImpl_ArcDriver) _anOtherObject;
170 if (!AnObject.IsNull()) {
171 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArcDriver))) {
172 _anOtherObject = Handle(GEOMImpl_ArcDriver)((Handle(GEOMImpl_ArcDriver)&)AnObject);
176 return _anOtherObject ;