1 // Created on: 1996-09-04
2 // Created by: Olga PILLOT
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRepLib_MakeVertex.hxx>
19 #include <BRepSweep_Revol.hxx>
20 #include <BRepTools_Modifier.hxx>
21 #include <BRepTools_TrsfModification.hxx>
22 #include <Geom_Circle.hxx>
23 #include <Geom_Curve.hxx>
25 #include <gp_Circ.hxx>
26 #include <gp_Trsf.hxx>
29 #include <LocOpe_BuildShape.hxx>
30 #include <LocOpe_Revol.hxx>
31 #include <Precision.hxx>
32 #include <Standard_NoSuchObject.hxx>
33 #include <StdFail_NotDone.hxx>
34 #include <TColgp_SequenceOfPnt.hxx>
36 #include <TopExp_Explorer.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
42 static Standard_Boolean FindCircle(const gp_Ax1&,
47 //=======================================================================
48 //function : LocOpe_Revol
50 //=======================================================================
52 LocOpe_Revol::LocOpe_Revol()
55 myIsTrans(Standard_False),
56 myDone(Standard_False)
60 //=======================================================================
63 //=======================================================================
65 void LocOpe_Revol::Perform(const TopoDS_Shape& Base,
67 const Standard_Real Angle)
70 myFirstShape.Nullify();
71 myLastShape.Nullify();
78 myIsTrans = Standard_False;
82 //=======================================================================
85 //=======================================================================
87 void LocOpe_Revol::Perform(const TopoDS_Shape& Base,
89 const Standard_Real Angle,
90 const Standard_Real angledec)
93 myFirstShape.Nullify();
94 myLastShape.Nullify();
101 myIsTrans = Standard_True;
106 //=======================================================================
109 //=======================================================================
111 void LocOpe_Revol::IntPerf()
113 TopoDS_Shape theBase = myBase;
114 BRepTools_Modifier Modif;
117 T.SetRotation(myAxis,myAngTra);
118 Handle(BRepTools_TrsfModification) modbase =
119 new BRepTools_TrsfModification(T);
121 Modif.Perform(modbase);
122 theBase = Modif.ModifiedShape(theBase);
125 BRepSweep_Revol theRevol(theBase,myAxis,myAngle);
127 myFirstShape = theRevol.FirstShape();
128 myLastShape = theRevol.LastShape();
131 if (theBase.ShapeType() == TopAbs_FACE) {
132 for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) {
133 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
134 if (!myMap.IsBound(edg)) {
135 TopTools_ListOfShape thelist;
136 myMap.Bind(edg, thelist);
137 TopoDS_Shape desc = theRevol.Shape(edg);
138 if (!desc.IsNull()) {
139 myMap(edg).Append(desc);
143 myRes = theRevol.Shape();
148 TopTools_IndexedDataMapOfShapeListOfShape theEFMap;
149 TopExp::MapShapesAndAncestors(theBase,TopAbs_EDGE,TopAbs_FACE,theEFMap);
150 TopTools_ListOfShape lfaces;
151 Standard_Boolean toremove = Standard_False;
152 for (Standard_Integer i=1; i<=theEFMap.Extent(); i++) {
153 const TopoDS_Shape& edg = theEFMap.FindKey(i);
154 TopTools_ListOfShape thelist1;
155 myMap.Bind(edg, thelist1);
156 TopoDS_Shape desc = theRevol.Shape(edg);
157 if (!desc.IsNull()) {
158 if (theEFMap(i).Extent() >= 2) {
159 toremove = Standard_True;
162 myMap(edg).Append(desc);
168 // Rajouter les faces de FirstShape et LastShape
169 for (exp.Init(myFirstShape,TopAbs_FACE);exp.More();exp.Next()) {
170 lfaces.Append(exp.Current());
172 for (exp.Init(myLastShape,TopAbs_FACE);exp.More();exp.Next()) {
173 lfaces.Append(exp.Current());
176 LocOpe_BuildShape BS(lfaces);
180 for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) {
181 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
182 if (!myMap.IsBound(edg)) {
183 TopTools_ListOfShape thelist2;
184 myMap.Bind(edg, thelist2);
185 TopoDS_Shape desc = theRevol.Shape(edg);
186 if (!desc.IsNull()) {
187 myMap(edg).Append(desc);
191 myRes = theRevol.Shape();
196 // m-a-j des descendants
197 TopExp_Explorer anExp;
198 for (anExp.Init(myBase,TopAbs_EDGE); anExp.More(); anExp.Next()) {
199 const TopoDS_Edge& edg = TopoDS::Edge(anExp.Current());
200 const TopoDS_Edge& edgbis = TopoDS::Edge(Modif.ModifiedShape(edg));
201 if (!edgbis.IsSame(edg) && myMap.IsBound(edgbis)) {
202 myMap.Bind(edg,myMap(edgbis));
203 myMap.UnBind(edgbis);
207 myDone = Standard_True;
210 //=======================================================================
213 //=======================================================================
215 const TopoDS_Shape& LocOpe_Revol::Shape () const
218 throw StdFail_NotDone();
224 //=======================================================================
225 //function : FirstShape
227 //=======================================================================
229 const TopoDS_Shape& LocOpe_Revol::FirstShape () const
234 //=======================================================================
235 //function : LastShape
237 //=======================================================================
239 const TopoDS_Shape& LocOpe_Revol::LastShape () const
245 //=======================================================================
248 //=======================================================================
250 const TopTools_ListOfShape& LocOpe_Revol::Shapes (const TopoDS_Shape& S) const
256 //=======================================================================
259 //=======================================================================
261 void LocOpe_Revol::Curves(TColGeom_SequenceOfCurve& Scurves) const
264 TColgp_SequenceOfPnt spt;
265 LocOpe::SampleEdges(myFirstShape,spt);
266 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
267 const gp_Pnt& pvt = spt(jj);
269 if (FindCircle(myAxis,pvt,CAX)) {
270 gp_Ax2 A2 = CAX.Position();
271 Standard_Real r = CAX.Radius();
272 Handle(Geom_Circle) Ci = new Geom_Circle(A2, r);
278 //=======================================================================
279 //function : BarycCurve
281 //=======================================================================
283 Handle(Geom_Curve) LocOpe_Revol::BarycCurve() const
285 gp_Pnt bar(0., 0., 0.);
286 TColgp_SequenceOfPnt spt;
287 LocOpe::SampleEdges(myFirstShape,spt);
288 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
289 const gp_Pnt& pvt = spt(jj);
290 bar.ChangeCoord() += pvt.XYZ();
292 bar.ChangeCoord().Divide(spt.Length());
294 Handle(Geom_Circle) theCi;
295 if (FindCircle(myAxis,bar,CAX)) {
296 gp_Ax2 A2 = CAX.Position();
297 Standard_Real r = CAX.Radius();
298 theCi = new Geom_Circle(A2, r);
305 //=======================================================================
306 //function : FincCircle
308 //=======================================================================
310 static Standard_Boolean FindCircle(const gp_Ax1& Ax,
315 const gp_Dir& Dax = Ax.Direction();
316 gp_Vec OP(Ax.Location(),Pt);
318 Standard_Real prm = OP.Dot(Dax);
320 gp_Pnt prj(Ax.Location().XYZ().Added(prm*Dax.XYZ()));
322 Standard_Real Radius = axx.Magnitude();
323 if (Radius < Precision::Confusion()) {
324 return Standard_False;
326 Ci.SetRadius(Radius);
327 Ci.SetPosition(gp_Ax2(prj,Dax,axx));
328 return Standard_True;