0030364: Visualization, TKOpenGl - allow initializing a Surface-less EGL context
[occt.git] / src / BRepPrimAPI / BRepPrimAPI_MakeRevol.cxx
CommitLineData
b311480e 1// Created on: 1993-10-14
2// Created by: Remi LEQUETTE
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17// Modified by skv - Fri Mar 4 15:50:09 2005
18// Add methods for supporting history.
19
42cf5bc1 20#include <BRep_TEdge.hxx>
7fd59977 21#include <BRepLib.hxx>
42cf5bc1 22#include <BRepPrimAPI_MakeRevol.hxx>
23#include <BRepSweep_Revol.hxx>
24#include <gp_Ax1.hxx>
7fd59977 25#include <TopExp_Explorer.hxx>
42cf5bc1 26#include <TopoDS_Shape.hxx>
7e4ff648 27#include <TopTools_DataMapOfShapeListOfShape.hxx>
28#include <BRepTools_ReShape.hxx>
7fd59977 29// perform checks on the argument
7fd59977 30static const TopoDS_Shape& check(const TopoDS_Shape& S)
31{
32 BRepLib::BuildCurves3d(S);
33 return S;
34}
35
36//=======================================================================
37//function : BRepPrimAPI_MakeRevol
38//purpose :
39//=======================================================================
40
41BRepPrimAPI_MakeRevol::BRepPrimAPI_MakeRevol(const TopoDS_Shape& S,
42 const gp_Ax1& A,
43 const Standard_Real D,
44 const Standard_Boolean Copy) :
45 myRevol(check(S),A,D,Copy)
46{
47 Build();
48}
49
50
51//=======================================================================
52//function : BRepPrimAPI_MakeRevol
53//purpose :
54//=======================================================================
55
56BRepPrimAPI_MakeRevol::BRepPrimAPI_MakeRevol(const TopoDS_Shape& S,
57 const gp_Ax1& A,
58 const Standard_Boolean Copy) :
59 myRevol(check(S),A,Copy)
60{
61 Build();
62}
63
64
65//=======================================================================
66//function : Revol
67//purpose :
68//=======================================================================
69
70const BRepSweep_Revol& BRepPrimAPI_MakeRevol::Revol() const
71{
72 return myRevol;
73}
74
75
76//=======================================================================
77//function : Build
78//purpose :
79//=======================================================================
80
81void BRepPrimAPI_MakeRevol::Build()
82{
83 myShape = myRevol.Shape();
420f79f8 84 BRepLib::UpdateInnerTolerances(myShape);
85
7fd59977 86 Done();
7e4ff648 87 myHist.Nullify();
7fd59977 88 myDegenerated.Clear();
7e4ff648 89 TopTools_DataMapOfShapeListOfShape aDegE;
90 BRep_Builder aBB;
7fd59977 91
92 TopExp_Explorer anExp(myShape, TopAbs_EDGE);
7e4ff648 93 //Problem is that some degenerated edges can be shared by different faces.
94 //It is not valid for correct shape.
95 //To solve problem it is possible to copy shared degenerated edge for each face, which has it, and
96 //replace shared edge by its copy
7fd59977 97 for (; anExp.More(); anExp.Next()) {
98 const TopoDS_Shape &anEdge = anExp.Current();
99 Handle(BRep_TEdge) aTEdge = Handle(BRep_TEdge)::DownCast(anEdge.TShape());
100
101 if (aTEdge->Degenerated())
7e4ff648 102 {
103 TopTools_ListOfShape* anL = aDegE.ChangeSeek(anEdge);
104 if (anL)
105 {
106 //Make the copy if degenerated edge occurs more then once
107 TopoDS_Shape aCopyE = anEdge.EmptyCopied();
108 aCopyE.Orientation(TopAbs_FORWARD);
109 TopoDS_Iterator aVIter(anEdge.Oriented(TopAbs_FORWARD), Standard_False);
110 for (; aVIter.More(); aVIter.Next())
111 {
112 aBB.Add(aCopyE, aVIter.Value());
113 }
114 aCopyE.Orientation(anEdge.Orientation());
115 anL->Append(aCopyE);
116 myDegenerated.Append(aCopyE);
117 }
118 else
119 {
120 anL = aDegE.Bound(anEdge, TopTools_ListOfShape());
121 anL->Append(anEdge);
122 myDegenerated.Append(anEdge);
123 }
124 }
125 }
126 if (!myDegenerated.IsEmpty())
127 {
128 BRepTools_ReShape aSubs;
129 TopTools_DataMapOfShapeListOfShape aDegF;
130 Standard_Boolean isReplaced = Standard_False;
131 anExp.Init(myShape, TopAbs_FACE);
132 //Replace degenerated edge by its copies for different faces
133 //First, for each face list of d.e. is created
134 for (; anExp.More(); anExp.Next())
135 {
136 const TopoDS_Shape& aF = anExp.Current();
137 TopExp_Explorer anExpE(aF, TopAbs_EDGE);
138 for (; anExpE.More(); anExpE.Next())
139 {
140 const TopoDS_Shape &anE = anExpE.Current();
141 if (BRep_Tool::Degenerated(TopoDS::Edge(anE)))
142 {
143 TopTools_ListOfShape* anL = aDegF.ChangeSeek(aF);
144 if (!anL)
145 {
146 anL = aDegF.Bound(aF, TopTools_ListOfShape());
147 }
148 anL->Append(anE);
149 }
150 }
151 }
152 //
153 //Second, replace edges by copies using ReShape
154 BRepTools_ReShape aSubsF;
155 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aFIter(aDegF);
156 for (; aFIter.More(); aFIter.Next())
157 {
158 aSubs.Clear();
159 isReplaced = Standard_False;
160 const TopoDS_Shape& aF = aFIter.Key();
161 const TopTools_ListOfShape& aDEL = aFIter.ChangeValue();
162 TopTools_ListIteratorOfListOfShape anEIter(aDEL);
163 for (; anEIter.More(); anEIter.Next())
164 {
165 const TopoDS_Shape& anE = anEIter.Value();
166 if (aDegE.IsBound(anE))
167 {
168 TopTools_ListOfShape& aCEL = aDegE.ChangeFind(anE);
169 TopTools_ListIteratorOfListOfShape anIt(aCEL);
170 for (; anIt.More(); anIt.Next())
171 {
172 if (anIt.Value().IsEqual(anE))
173 {
174 //First occurence of initial deg. edge is not replaced
175 aCEL.Remove(anIt);
176 break;
177 }
178 if (anIt.Value().Orientation() == anE.Orientation())
179 {
180 //All other occurences of anE are replaced by any copy
181 //with suitable orientation
182 isReplaced = Standard_True;
183 aSubs.Replace(anE, anIt.Value());
184 aCEL.Remove(anIt);
185 break;
186 }
187 }
188 }
189 }
190 if (isReplaced)
191 {
192 TopoDS_Shape aNF = aSubs.Apply(aF);
193 aSubsF.Replace(aF, aNF);
194 if (myHist.IsNull())
195 {
196 myHist = aSubs.History();
197 }
198 else
199 {
200 myHist->Merge(aSubs.History());
201 }
202 myShape = aSubsF.Apply(myShape);
203 myHist->Merge(aSubsF.History());
204 //Pair aF->aNF is in history after first replacing of edge by aNF = aSubs.Apply(aF)
205 //After merging history for replacing faces, modified list for aF contains two exemplar of aNF
206 //So, using ReplaceModified clears modified list for aF and leaves only one exemplar of aNF
207 myHist->ReplaceModified(aF, aNF);
208 aSubsF.Clear();
209 }
210 }
7fd59977 211 }
7fd59977 212}
213
214
215//=======================================================================
216//function : FirstShape
217//purpose :
218//=======================================================================
219
220TopoDS_Shape BRepPrimAPI_MakeRevol::FirstShape()
221{
222 return myRevol.FirstShape();
223}
224
225
226//=======================================================================
227//function : LastShape
228//purpose :
229//=======================================================================
230
231TopoDS_Shape BRepPrimAPI_MakeRevol::LastShape()
232{
233 return myRevol.LastShape();
234}
235
7fd59977 236//=======================================================================
237//function : Generated
238//purpose :
239//=======================================================================
7fd59977 240const TopTools_ListOfShape& BRepPrimAPI_MakeRevol::Generated (const TopoDS_Shape& S)
241{
242 myGenerated.Clear();
7e4ff648 243 TopoDS_Shape aGS = myRevol.Shape(S);
244 if (!aGS.IsNull())
245 {
246 if (BRepTools_History::IsSupportedType(aGS))
247 {
248 if (myHist.IsNull())
249 {
250 myGenerated.Append(aGS);
251 return myGenerated;
252 }
253 if (myHist->Modified(aGS).IsEmpty())
254 {
255 myGenerated.Append(aGS);
256 return myGenerated;
257 }
258 //
259 TopTools_ListIteratorOfListOfShape anIt(myHist->Modified(aGS));
260 for (; anIt.More(); anIt.Next())
261 {
262 myGenerated.Append(anIt.Value());
263 }
264 if (aGS.ShapeType() == TopAbs_EDGE)
265 {
266 if (BRep_Tool::Degenerated(TopoDS::Edge(aGS)))
267 {
268 //Append initial common deg. edge
269 myGenerated.Append(aGS);
270 }
271 }
272 }
273 }
7fd59977 274 return myGenerated;
275}
276
7fd59977 277//=======================================================================
278//function : FirstShape
279//purpose : This method returns the shape of the beginning of the revolution,
280// generated with theShape (subShape of the generating shape).
281//=======================================================================
282
283TopoDS_Shape BRepPrimAPI_MakeRevol::FirstShape(const TopoDS_Shape &theShape)
284{
285 return myRevol.FirstShape(theShape);
286}
287
288
289//=======================================================================
290//function : LastShape
291//purpose : This method returns the shape of the end of the revolution,
292// generated with theShape (subShape of the generating shape).
293//=======================================================================
294
295TopoDS_Shape BRepPrimAPI_MakeRevol::LastShape(const TopoDS_Shape &theShape)
296{
297 return myRevol.LastShape(theShape);
298}
299
300//=======================================================================
301//function : HasDegenerated
302//purpose :
303//=======================================================================
304
305Standard_Boolean BRepPrimAPI_MakeRevol::HasDegenerated () const
306{
307 return (!myDegenerated.IsEmpty());
308}
309
310
311//=======================================================================
312//function : Degenerated
313//purpose :
314//=======================================================================
315
316const TopTools_ListOfShape& BRepPrimAPI_MakeRevol::Degenerated () const
317{
318 return myDegenerated;
319}
7e4ff648 320