1 // Copyright (C) 2007-2016 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>
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(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_Ax3 anAxes3(anAxes);
98 gp_Ax2 anAxes1(aP, -aV);
99 gp_Circ aCirc (anAxes1, aCI.GetRadius());
100 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
101 BRepBuilderAPI_MakeWire MW;
102 MW.Add(TopoDS::Edge(aCircle));
103 BRepBuilderAPI_MakeFace MF (aPln, MW);
108 else if (aType == DISK_THREE_PNT) {
109 Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
110 Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
111 Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
112 TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
113 TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
114 TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
115 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
116 aShapePnt2.ShapeType() == TopAbs_VERTEX &&
117 aShapePnt3.ShapeType() == TopAbs_VERTEX) {
118 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
119 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
120 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
121 if (aP1.Distance(aP2) < gp::Resolution() ||
122 aP1.Distance(aP3) < gp::Resolution() ||
123 aP2.Distance(aP3) < gp::Resolution())
124 Standard_ConstructionError::Raise("Disk creation aborted: coincident points given");
125 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
126 Standard_ConstructionError::Raise("Disk creation aborted: points lay on one line");
127 Handle(Geom_Circle) aCirc = GC_MakeCircle(aP3, aP2, aP1).Value();
128 gp_Circ aGpCirc = aCirc->Circ();
129 gp_Ax2 anAxes = aGpCirc.Position();
130 gp_Ax3 anAxes3(anAxes.Location(), -anAxes.Direction());
131 gp_Pln aPln(anAxes3);
132 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
133 BRepBuilderAPI_MakeWire MW;
134 MW.Add(TopoDS::Edge(aCircle));
135 BRepBuilderAPI_MakeFace MF (aPln, MW);
139 else if (aType == DISK_R) {
140 int anOrient = aCI.GetOrientation();
141 gp_Pnt aP = gp::Origin();
145 else if (anOrient == 2)
147 else if (anOrient == 3)
150 gp_Ax2 anAxes (aP, aV);
151 gp_Ax2 anAxes1(aP, -aV);
152 gp_Ax3 anAxes3(anAxes);
153 gp_Pln aPln(anAxes3);
154 gp_Circ aCirc (anAxes1, aCI.GetRadius());
155 TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
156 BRepBuilderAPI_MakeWire MW;
157 MW.Add(TopoDS::Edge(aCircle));
158 BRepBuilderAPI_MakeFace MF (aPln, MW);
164 if (aShape.IsNull()) return 0;
166 aFunction->SetValue(aShape);
168 #if OCC_VERSION_MAJOR < 7
169 log.SetTouched(Label());
171 log->SetTouched(Label());
177 //================================================================================
179 * \brief Returns a name of creation operation and names and values of creation parameters
181 //================================================================================
183 bool GEOMImpl_DiskDriver::
184 GetCreationInformation(std::string& theOperationName,
185 std::vector<GEOM_Param>& theParams)
187 if (Label().IsNull()) return 0;
188 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
190 GEOMImpl_IDisk aCI( function );
191 Standard_Integer aType = function->GetType();
193 theOperationName = "DISK";
197 AddParam( theParams, "Center Point", aCI.GetCenter() );
198 AddParam( theParams, "Vector", aCI.GetVector() );
199 AddParam( theParams, "Radius", aCI.GetRadius() );
202 AddParam( theParams, "Point 1", aCI.GetPoint1() );
203 AddParam( theParams, "Point 2", aCI.GetPoint2() );
204 AddParam( theParams, "Point 3", aCI.GetPoint3() );
207 AddParam( theParams, "Radius", aCI.GetRadius() );
208 AddParam( theParams, "Orientation", aCI.GetOrientation() );
217 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_DiskDriver,GEOM_BaseDriver);