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() : myDone(Standard_False)
57 //=======================================================================
60 //=======================================================================
62 void LocOpe_Revol::Perform(const TopoDS_Shape& Base,
64 const Standard_Real Angle)
67 myFirstShape.Nullify();
68 myLastShape.Nullify();
75 myIsTrans = Standard_False;
79 //=======================================================================
82 //=======================================================================
84 void LocOpe_Revol::Perform(const TopoDS_Shape& Base,
86 const Standard_Real Angle,
87 const Standard_Real angledec)
90 myFirstShape.Nullify();
91 myLastShape.Nullify();
98 myIsTrans = Standard_True;
103 //=======================================================================
106 //=======================================================================
108 void LocOpe_Revol::IntPerf()
110 TopoDS_Shape theBase = myBase;
111 BRepTools_Modifier Modif;
114 T.SetRotation(myAxis,myAngTra);
115 Handle(BRepTools_TrsfModification) modbase =
116 new BRepTools_TrsfModification(T);
118 Modif.Perform(modbase);
119 theBase = Modif.ModifiedShape(theBase);
122 BRepSweep_Revol theRevol(theBase,myAxis,myAngle);
124 myFirstShape = theRevol.FirstShape();
125 myLastShape = theRevol.LastShape();
128 if (theBase.ShapeType() == TopAbs_FACE) {
129 for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) {
130 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
131 if (!myMap.IsBound(edg)) {
132 TopTools_ListOfShape thelist;
133 myMap.Bind(edg, thelist);
134 TopoDS_Shape desc = theRevol.Shape(edg);
135 if (!desc.IsNull()) {
136 myMap(edg).Append(desc);
140 myRes = theRevol.Shape();
145 TopTools_IndexedDataMapOfShapeListOfShape theEFMap;
146 TopExp::MapShapesAndAncestors(theBase,TopAbs_EDGE,TopAbs_FACE,theEFMap);
147 TopTools_ListOfShape lfaces;
148 Standard_Boolean toremove = Standard_False;
149 for (Standard_Integer i=1; i<=theEFMap.Extent(); i++) {
150 const TopoDS_Shape& edg = theEFMap.FindKey(i);
151 TopTools_ListOfShape thelist1;
152 myMap.Bind(edg, thelist1);
153 TopoDS_Shape desc = theRevol.Shape(edg);
154 if (!desc.IsNull()) {
155 if (theEFMap(i).Extent() >= 2) {
156 toremove = Standard_True;
159 myMap(edg).Append(desc);
165 // Rajouter les faces de FirstShape et LastShape
166 for (exp.Init(myFirstShape,TopAbs_FACE);exp.More();exp.Next()) {
167 lfaces.Append(exp.Current());
169 for (exp.Init(myLastShape,TopAbs_FACE);exp.More();exp.Next()) {
170 lfaces.Append(exp.Current());
173 LocOpe_BuildShape BS(lfaces);
177 for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) {
178 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
179 if (!myMap.IsBound(edg)) {
180 TopTools_ListOfShape thelist2;
181 myMap.Bind(edg, thelist2);
182 TopoDS_Shape desc = theRevol.Shape(edg);
183 if (!desc.IsNull()) {
184 myMap(edg).Append(desc);
188 myRes = theRevol.Shape();
193 // m-a-j des descendants
194 TopExp_Explorer anExp;
195 for (anExp.Init(myBase,TopAbs_EDGE); anExp.More(); anExp.Next()) {
196 const TopoDS_Edge& edg = TopoDS::Edge(anExp.Current());
197 const TopoDS_Edge& edgbis = TopoDS::Edge(Modif.ModifiedShape(edg));
198 if (!edgbis.IsSame(edg) && myMap.IsBound(edgbis)) {
199 myMap.Bind(edg,myMap(edgbis));
200 myMap.UnBind(edgbis);
204 myDone = Standard_True;
207 //=======================================================================
210 //=======================================================================
212 const TopoDS_Shape& LocOpe_Revol::Shape () const
215 throw StdFail_NotDone();
221 //=======================================================================
222 //function : FirstShape
224 //=======================================================================
226 const TopoDS_Shape& LocOpe_Revol::FirstShape () const
231 //=======================================================================
232 //function : LastShape
234 //=======================================================================
236 const TopoDS_Shape& LocOpe_Revol::LastShape () const
242 //=======================================================================
245 //=======================================================================
247 const TopTools_ListOfShape& LocOpe_Revol::Shapes (const TopoDS_Shape& S) const
253 //=======================================================================
256 //=======================================================================
258 void LocOpe_Revol::Curves(TColGeom_SequenceOfCurve& Scurves) const
261 TColgp_SequenceOfPnt spt;
262 LocOpe::SampleEdges(myFirstShape,spt);
263 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
264 const gp_Pnt& pvt = spt(jj);
266 if (FindCircle(myAxis,pvt,CAX)) {
267 gp_Ax2 A2 = CAX.Position();
268 Standard_Real r = CAX.Radius();
269 Handle(Geom_Circle) Ci = new Geom_Circle(A2, r);
275 //=======================================================================
276 //function : BarycCurve
278 //=======================================================================
280 Handle(Geom_Curve) LocOpe_Revol::BarycCurve() const
282 gp_Pnt bar(0., 0., 0.);
283 TColgp_SequenceOfPnt spt;
284 LocOpe::SampleEdges(myFirstShape,spt);
285 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
286 const gp_Pnt& pvt = spt(jj);
287 bar.ChangeCoord() += pvt.XYZ();
289 bar.ChangeCoord().Divide(spt.Length());
291 Handle(Geom_Circle) theCi;
292 if (FindCircle(myAxis,bar,CAX)) {
293 gp_Ax2 A2 = CAX.Position();
294 Standard_Real r = CAX.Radius();
295 theCi = new Geom_Circle(A2, r);
302 //=======================================================================
303 //function : FincCircle
305 //=======================================================================
307 static Standard_Boolean FindCircle(const gp_Ax1& Ax,
312 const gp_Dir& Dax = Ax.Direction();
313 gp_Vec OP(Ax.Location(),Pt);
315 Standard_Real prm = OP.Dot(Dax);
317 gp_Pnt prj(Ax.Location().XYZ().Added(prm*Dax.XYZ()));
319 Standard_Real Radius = axx.Magnitude();
320 if (Radius < Precision::Confusion()) {
321 return Standard_False;
323 Ci.SetRadius(Radius);
324 Ci.SetPosition(gp_Ax2(prj,Dax,axx));
325 return Standard_True;