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_DiskDriver.hxx>
24 #include <GEOMImpl_IDisk.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRepBuilderAPI_MakeEdge.hxx>
29 #include <BRepBuilderAPI_MakeWire.hxx>
30 #include <BRepBuilderAPI_MakeFace.hxx>
31 #include <BRep_Tool.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Vertex.hxx>
36 #include <TopoDS_Wire.hxx>
40 #include <GC_MakeCircle.hxx>
41 #include <Geom_Circle.hxx>
43 #include <Standard_ConstructionError.hxx>
44 #include <Precision.hxx>
47 #include <gp_Circ.hxx>
49 //=======================================================================
52 //=======================================================================
53 const Standard_GUID& GEOMImpl_DiskDriver::GetID()
55 static Standard_GUID aDiskDriver("C1FEEF9D-1C6D-41ce-9507-F10D75430CE1");
60 //=======================================================================
61 //function : GEOMImpl_DiskDriver
63 //=======================================================================
64 GEOMImpl_DiskDriver::GEOMImpl_DiskDriver()
68 //=======================================================================
71 //=======================================================================
72 Standard_Integer GEOMImpl_DiskDriver::Execute(TFunction_Logbook& log) const
74 if (Label().IsNull()) return 0;
75 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
77 GEOMImpl_IDisk aCI (aFunction);
78 Standard_Integer aType = aFunction->GetType();
82 if (aType == DISK_PNT_VEC_R) {
83 Handle(GEOM_Function) aRefPoint = aCI.GetCenter();
84 Handle(GEOM_Function) aRefVector = aCI.GetVector();
85 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
86 TopoDS_Shape aShapeVec = aRefVector->GetValue();
87 if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
88 aShapeVec.ShapeType() == TopAbs_EDGE) {
89 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
90 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
92 TopExp::Vertices(anE, V1, V2, Standard_True);
93 if (!V1.IsNull() && !V2.IsNull()) {
94 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
95 gp_Ax2 anAxes (aP, aV);
96 gp_Circ aCirc (anAxes, aCI.GetRadius());
97 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
98 BRepBuilderAPI_MakeWire MW;
99 MW.Add(TopoDS::Edge(aCircle));
100 BRepBuilderAPI_MakeFace MF (MW, Standard_False);
105 else if (aType == DISK_THREE_PNT) {
106 Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
107 Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
108 Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
109 TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
110 TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
111 TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
112 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
113 aShapePnt2.ShapeType() == TopAbs_VERTEX &&
114 aShapePnt3.ShapeType() == TopAbs_VERTEX) {
115 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
116 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
117 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
118 if (aP1.Distance(aP2) < gp::Resolution() ||
119 aP1.Distance(aP3) < gp::Resolution() ||
120 aP2.Distance(aP3) < gp::Resolution())
121 Standard_ConstructionError::Raise("Disk creation aborted: coincident points given");
122 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
123 Standard_ConstructionError::Raise("Disk creation aborted: points lay on one line");
124 Handle(Geom_Circle) aCirc = GC_MakeCircle(aP1, aP2, aP3).Value();
125 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
126 BRepBuilderAPI_MakeWire MW;
127 MW.Add(TopoDS::Edge(aCircle));
128 BRepBuilderAPI_MakeFace MF (MW, Standard_False);
132 else if (aType == DISK_R) {
133 int anOrient = aCI.GetOrientation();
134 gp_Pnt aP = gp::Origin();
138 else if (anOrient == 2)
140 else if (anOrient == 3)
143 gp_Ax2 anAxes (aP, aV);
144 gp_Circ aCirc (anAxes, aCI.GetRadius());
145 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
146 BRepBuilderAPI_MakeWire MW;
147 MW.Add(TopoDS::Edge(aCircle));
148 BRepBuilderAPI_MakeFace MF (MW, Standard_False);
154 if (aShape.IsNull()) return 0;
156 aFunction->SetValue(aShape);
158 log.SetTouched(Label());
164 //=======================================================================
165 //function : GEOMImpl_DiskDriver_Type_
167 //=======================================================================
168 Standard_EXPORT Handle_Standard_Type& GEOMImpl_DiskDriver_Type_()
171 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
172 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
173 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
174 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
175 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
176 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
179 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
180 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_DiskDriver",
181 sizeof(GEOMImpl_DiskDriver),
183 (Standard_Address)_Ancestors,
184 (Standard_Address)NULL);
189 //=======================================================================
190 //function : DownCast
192 //=======================================================================
193 const Handle(GEOMImpl_DiskDriver) Handle(GEOMImpl_DiskDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
195 Handle(GEOMImpl_DiskDriver) _anOtherObject;
197 if (!AnObject.IsNull()) {
198 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_DiskDriver))) {
199 _anOtherObject = Handle(GEOMImpl_DiskDriver)((Handle(GEOMImpl_DiskDriver)&)AnObject);
203 return _anOtherObject ;