1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_DiskDriver.hxx>
25 #include <GEOMImpl_IDisk.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
29 #include <BRepBuilderAPI_MakeEdge.hxx>
30 #include <BRepBuilderAPI_MakeWire.hxx>
31 #include <BRepBuilderAPI_MakeFace.hxx>
32 #include <BRep_Tool.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Vertex.hxx>
37 #include <TopoDS_Wire.hxx>
41 #include <GC_MakeCircle.hxx>
42 #include <Geom_Circle.hxx>
44 #include <Standard_ConstructionError.hxx>
45 #include <Precision.hxx>
48 #include <gp_Circ.hxx>
50 //=======================================================================
53 //=======================================================================
54 const Standard_GUID& GEOMImpl_DiskDriver::GetID()
56 static Standard_GUID aDiskDriver("C1FEEF9D-1C6D-41ce-9507-F10D75430CE1");
61 //=======================================================================
62 //function : GEOMImpl_DiskDriver
64 //=======================================================================
65 GEOMImpl_DiskDriver::GEOMImpl_DiskDriver()
69 //=======================================================================
72 //=======================================================================
73 Standard_Integer GEOMImpl_DiskDriver::Execute(TFunction_Logbook& log) const
75 if (Label().IsNull()) return 0;
76 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
78 GEOMImpl_IDisk aCI (aFunction);
79 Standard_Integer aType = aFunction->GetType();
83 if (aType == DISK_PNT_VEC_R) {
84 Handle(GEOM_Function) aRefPoint = aCI.GetCenter();
85 Handle(GEOM_Function) aRefVector = aCI.GetVector();
86 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
87 TopoDS_Shape aShapeVec = aRefVector->GetValue();
88 if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
89 aShapeVec.ShapeType() == TopAbs_EDGE) {
90 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
91 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
93 TopExp::Vertices(anE, V1, V2, Standard_True);
94 if (!V1.IsNull() && !V2.IsNull()) {
95 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
96 gp_Ax2 anAxes (aP, -aV);
97 gp_Circ aCirc (anAxes, aCI.GetRadius());
98 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
99 BRepBuilderAPI_MakeWire MW;
100 MW.Add(TopoDS::Edge(aCircle));
101 BRepBuilderAPI_MakeFace MF (MW, Standard_False);
106 else if (aType == DISK_THREE_PNT) {
107 Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
108 Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
109 Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
110 TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
111 TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
112 TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
113 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
114 aShapePnt2.ShapeType() == TopAbs_VERTEX &&
115 aShapePnt3.ShapeType() == TopAbs_VERTEX) {
116 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
117 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
118 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
119 if (aP1.Distance(aP2) < gp::Resolution() ||
120 aP1.Distance(aP3) < gp::Resolution() ||
121 aP2.Distance(aP3) < gp::Resolution())
122 Standard_ConstructionError::Raise("Disk creation aborted: coincident points given");
123 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
124 Standard_ConstructionError::Raise("Disk creation aborted: points lay on one line");
125 Handle(Geom_Circle) aCirc = GC_MakeCircle(aP3, aP2, aP1).Value();
126 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
127 BRepBuilderAPI_MakeWire MW;
128 MW.Add(TopoDS::Edge(aCircle));
129 BRepBuilderAPI_MakeFace MF (MW, Standard_False);
133 else if (aType == DISK_R) {
134 int anOrient = aCI.GetOrientation();
135 gp_Pnt aP = gp::Origin();
139 else if (anOrient == 2)
141 else if (anOrient == 3)
144 gp_Ax2 anAxes (aP, -aV);
145 gp_Circ aCirc (anAxes, aCI.GetRadius());
146 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
147 BRepBuilderAPI_MakeWire MW;
148 MW.Add(TopoDS::Edge(aCircle));
149 BRepBuilderAPI_MakeFace MF (MW, Standard_False);
155 if (aShape.IsNull()) return 0;
157 aFunction->SetValue(aShape);
159 log.SetTouched(Label());
165 //=======================================================================
166 //function : GEOMImpl_DiskDriver_Type_
168 //=======================================================================
169 Standard_EXPORT Handle_Standard_Type& GEOMImpl_DiskDriver_Type_()
172 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
173 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
174 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
175 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
176 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
177 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
180 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
181 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_DiskDriver",
182 sizeof(GEOMImpl_DiskDriver),
184 (Standard_Address)_Ancestors,
185 (Standard_Address)NULL);
190 //=======================================================================
191 //function : DownCast
193 //=======================================================================
194 const Handle(GEOMImpl_DiskDriver) Handle(GEOMImpl_DiskDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
196 Handle(GEOMImpl_DiskDriver) _anOtherObject;
198 if (!AnObject.IsNull()) {
199 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_DiskDriver))) {
200 _anOtherObject = Handle(GEOMImpl_DiskDriver)((Handle(GEOMImpl_DiskDriver)&)AnObject);
204 return _anOtherObject ;