1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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());
162 //================================================================================
164 * \brief Returns a name of creation operation and names and values of creation parameters
166 //================================================================================
168 bool GEOMImpl_DiskDriver::
169 GetCreationInformation(std::string& theOperationName,
170 std::vector<GEOM_Param>& theParams)
172 if (Label().IsNull()) return 0;
173 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
175 GEOMImpl_IDisk aCI( function );
176 Standard_Integer aType = function->GetType();
178 theOperationName = "DISK";
182 AddParam( theParams, "Center Point", aCI.GetCenter() );
183 AddParam( theParams, "Vector", aCI.GetVector() );
184 AddParam( theParams, "Radius", aCI.GetRadius() );
187 AddParam( theParams, "Point 1", aCI.GetPoint1() );
188 AddParam( theParams, "Point 2", aCI.GetPoint2() );
189 AddParam( theParams, "Point 3", aCI.GetPoint3() );
192 AddParam( theParams, "Radius", aCI.GetRadius() );
193 AddParam( theParams, "Orientation", aCI.GetOrientation() );
201 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_DiskDriver,GEOM_BaseDriver);
203 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_DiskDriver,GEOM_BaseDriver);