1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Standard_Stream.hxx>
22 #include <GEOMImpl_DiskDriver.hxx>
23 #include <GEOMImpl_IDisk.hxx>
24 #include <GEOMImpl_Types.hxx>
25 #include <GEOM_Function.hxx>
27 #include <BRepBuilderAPI_MakeEdge.hxx>
28 #include <BRepBuilderAPI_MakeWire.hxx>
29 #include <BRepBuilderAPI_MakeFace.hxx>
30 #include <BRep_Tool.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <TopoDS_Wire.hxx>
39 #include <GC_MakeCircle.hxx>
40 #include <Geom_Circle.hxx>
42 #include <Standard_ConstructionError.hxx>
43 #include <Precision.hxx>
46 #include <gp_Circ.hxx>
48 //=======================================================================
51 //=======================================================================
52 const Standard_GUID& GEOMImpl_DiskDriver::GetID()
54 static Standard_GUID aDiskDriver("C1FEEF9D-1C6D-41ce-9507-F10D75430CE1");
59 //=======================================================================
60 //function : GEOMImpl_DiskDriver
62 //=======================================================================
63 GEOMImpl_DiskDriver::GEOMImpl_DiskDriver()
67 //=======================================================================
70 //=======================================================================
71 Standard_Integer GEOMImpl_DiskDriver::Execute(TFunction_Logbook& log) const
73 if (Label().IsNull()) return 0;
74 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
76 GEOMImpl_IDisk aCI (aFunction);
77 Standard_Integer aType = aFunction->GetType();
81 if (aType == DISK_PNT_VEC_R) {
82 Handle(GEOM_Function) aRefPoint = aCI.GetCenter();
83 Handle(GEOM_Function) aRefVector = aCI.GetVector();
84 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
85 TopoDS_Shape aShapeVec = aRefVector->GetValue();
86 if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
87 aShapeVec.ShapeType() == TopAbs_EDGE) {
88 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
89 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
91 TopExp::Vertices(anE, V1, V2, Standard_True);
92 if (!V1.IsNull() && !V2.IsNull()) {
93 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
94 gp_Ax2 anAxes (aP, -aV);
95 gp_Circ aCirc (anAxes, aCI.GetRadius());
96 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
97 BRepBuilderAPI_MakeWire MW;
98 MW.Add(TopoDS::Edge(aCircle));
99 BRepBuilderAPI_MakeFace MF (MW, Standard_False);
104 else if (aType == DISK_THREE_PNT) {
105 Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
106 Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
107 Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
108 TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
109 TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
110 TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
111 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
112 aShapePnt2.ShapeType() == TopAbs_VERTEX &&
113 aShapePnt3.ShapeType() == TopAbs_VERTEX) {
114 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
115 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
116 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
117 if (aP1.Distance(aP2) < gp::Resolution() ||
118 aP1.Distance(aP3) < gp::Resolution() ||
119 aP2.Distance(aP3) < gp::Resolution())
120 Standard_ConstructionError::Raise("Disk creation aborted: coincident points given");
121 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
122 Standard_ConstructionError::Raise("Disk creation aborted: points lay on one line");
123 Handle(Geom_Circle) aCirc = GC_MakeCircle(aP3, aP2, aP1).Value();
124 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
125 BRepBuilderAPI_MakeWire MW;
126 MW.Add(TopoDS::Edge(aCircle));
127 BRepBuilderAPI_MakeFace MF (MW, Standard_False);
131 else if (aType == DISK_R) {
132 int anOrient = aCI.GetOrientation();
133 gp_Pnt aP = gp::Origin();
137 else if (anOrient == 2)
139 else if (anOrient == 3)
142 gp_Ax2 anAxes (aP, -aV);
143 gp_Circ aCirc (anAxes, aCI.GetRadius());
144 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
145 BRepBuilderAPI_MakeWire MW;
146 MW.Add(TopoDS::Edge(aCircle));
147 BRepBuilderAPI_MakeFace MF (MW, Standard_False);
153 if (aShape.IsNull()) return 0;
155 aFunction->SetValue(aShape);
157 log.SetTouched(Label());
163 //=======================================================================
164 //function : GEOMImpl_DiskDriver_Type_
166 //=======================================================================
167 Standard_EXPORT Handle_Standard_Type& GEOMImpl_DiskDriver_Type_()
170 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
171 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
172 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
173 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
174 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
175 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
178 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
179 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_DiskDriver",
180 sizeof(GEOMImpl_DiskDriver),
182 (Standard_Address)_Ancestors,
183 (Standard_Address)NULL);
188 //=======================================================================
189 //function : DownCast
191 //=======================================================================
192 const Handle(GEOMImpl_DiskDriver) Handle(GEOMImpl_DiskDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
194 Handle(GEOMImpl_DiskDriver) _anOtherObject;
196 if (!AnObject.IsNull()) {
197 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_DiskDriver))) {
198 _anOtherObject = Handle(GEOMImpl_DiskDriver)((Handle(GEOMImpl_DiskDriver)&)AnObject);
202 return _anOtherObject ;