0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / BRepAlgoAPI / BRepAlgoAPI_Section.cxx
CommitLineData
b311480e 1// Created on: 1994-02-18
2// Created by: Remi LEQUETTE
3// Copyright (c) 1994-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.
b311480e 16
7fd59977 17// modified by Michael KLOKOV Wed Mar 6 15:01:25 2002
4e57c75e 18// modified by Eugeny MALTCHIKOV Wed Jul 04 11:13:01 2012
7fd59977 19
42cf5bc1 20#include <BOPAlgo_BOP.hxx>
21#include <BOPAlgo_PaveFiller.hxx>
22#include <BOPAlgo_Section.hxx>
23#include <BOPDS_DS.hxx>
24#include <BRep_Tool.hxx>
25#include <BRepAlgoAPI_Section.hxx>
7fd59977 26#include <BRepBuilderAPI_MakeFace.hxx>
27#include <BRepBuilderAPI_MakeShell.hxx>
7fd59977 28#include <Geom2d_TrimmedCurve.hxx>
42cf5bc1 29#include <Geom_Plane.hxx>
30#include <Geom_Surface.hxx>
31#include <gp_Pln.hxx>
7fd59977 32#include <TopExp.hxx>
7fd59977 33#include <TopoDS.hxx>
34#include <TopoDS_Face.hxx>
42cf5bc1 35#include <TopoDS_Shape.hxx>
36#include <TopTools_IndexedMapOfShape.hxx>
37#include <TopTools_MapOfShape.hxx>
7fd59977 38
b1d15f53 39//
40static
41 TopoDS_Shape MakeShape(const Handle(Geom_Surface)& );
7fd59977 42
b1d15f53 43static
44 Standard_Boolean HasAncestorFaces(const BOPAlgo_PPaveFiller&,
45 const TopoDS_Shape&,
46 TopoDS_Shape&,
47 TopoDS_Shape&);
49b0c452 48static
49 Standard_Boolean HasAncestorFace (const BOPAlgo_PPaveFiller& ,
50 Standard_Integer ,
51 const TopoDS_Shape& ,
52 TopoDS_Shape& );
53//
b1d15f53 54//=======================================================================
55//function : BRepAlgoAPI_Section
56//purpose :
57//=======================================================================
58BRepAlgoAPI_Section::BRepAlgoAPI_Section()
59:
60 BRepAlgoAPI_BooleanOperation()
61{
49b0c452 62 Init(Standard_False);
b1d15f53 63}
64//=======================================================================
49b0c452 65//function : BRepAlgoAPI_Section
b1d15f53 66//purpose :
67//=======================================================================
49b0c452 68BRepAlgoAPI_Section::BRepAlgoAPI_Section(const BOPAlgo_PaveFiller& aPF)
69:
70 BRepAlgoAPI_BooleanOperation(aPF)
b1d15f53 71{
49b0c452 72 Init(Standard_False);
b1d15f53 73}
7fd59977 74//=======================================================================
75//function : Constructor
76//purpose :
77//=======================================================================
78BRepAlgoAPI_Section::BRepAlgoAPI_Section(const TopoDS_Shape& Sh1,
4e57c75e 79 const TopoDS_Shape& Sh2,
80 const Standard_Boolean PerformNow)
b1d15f53 81:
49b0c452 82 BRepAlgoAPI_BooleanOperation(Sh1,
83 Sh2,
84 BOPAlgo_SECTION)
7fd59977 85{
49b0c452 86 Init(PerformNow);
7fd59977 87}
b1d15f53 88//=======================================================================
89//function : BRepAlgoAPI_Section
90//purpose :
91//=======================================================================
92BRepAlgoAPI_Section::BRepAlgoAPI_Section
93 (const TopoDS_Shape& aS1,
94 const TopoDS_Shape& aS2,
95 const BOPAlgo_PaveFiller& aDSF,
96 const Standard_Boolean PerformNow)
97:
49b0c452 98 BRepAlgoAPI_BooleanOperation(aS1,
99 aS2,
100 aDSF,
101 BOPAlgo_SECTION)
7fd59977 102{
49b0c452 103 Init(PerformNow);
7fd59977 104}
7fd59977 105//=======================================================================
106//function : Constructor
107//purpose :
108//=======================================================================
b1d15f53 109BRepAlgoAPI_Section::BRepAlgoAPI_Section
110 (const TopoDS_Shape& Sh,
111 const gp_Pln& Pl,
112 const Standard_Boolean PerformNow)
113:
49b0c452 114 BRepAlgoAPI_BooleanOperation(Sh,
115 MakeShape(new Geom_Plane(Pl)),
b1d15f53 116 BOPAlgo_SECTION)
7fd59977 117{
49b0c452 118 Init(PerformNow);
7fd59977 119}
7fd59977 120//=======================================================================
121//function : Constructor
122//purpose :
123//=======================================================================
b1d15f53 124BRepAlgoAPI_Section::BRepAlgoAPI_Section
125 (const TopoDS_Shape& Sh,
126 const Handle(Geom_Surface)& Sf,
127 const Standard_Boolean PerformNow)
128:
49b0c452 129 BRepAlgoAPI_BooleanOperation(Sh,
130 MakeShape(Sf),
131 BOPAlgo_SECTION)
7fd59977 132{
49b0c452 133 Init(PerformNow);
7fd59977 134}
7fd59977 135//=======================================================================
136//function : Constructor
137//purpose :
138//=======================================================================
b1d15f53 139BRepAlgoAPI_Section::BRepAlgoAPI_Section
140 (const Handle(Geom_Surface)& Sf,
141 const TopoDS_Shape& Sh,
142 const Standard_Boolean PerformNow)
143:
49b0c452 144 BRepAlgoAPI_BooleanOperation(MakeShape(Sf),
145 Sh,
146 BOPAlgo_SECTION)
7fd59977 147{
49b0c452 148 Init(PerformNow);
7fd59977 149}
7fd59977 150//=======================================================================
151//function : Constructor
152//purpose :
153//=======================================================================
b1d15f53 154BRepAlgoAPI_Section::BRepAlgoAPI_Section
155 (const Handle(Geom_Surface)& Sf1,
156 const Handle(Geom_Surface)& Sf2,
157 const Standard_Boolean PerformNow)
158:
159 BRepAlgoAPI_BooleanOperation(MakeShape(Sf1),
160 MakeShape(Sf2),
161 BOPAlgo_SECTION)
7fd59977 162{
49b0c452 163 Init(PerformNow);
164}
165//=======================================================================
166//function : ~BRepAlgoAPI_Section
167//purpose :
168//=======================================================================
169BRepAlgoAPI_Section::~BRepAlgoAPI_Section()
170{
171}
172//=======================================================================
173//function : Init
174//purpose :
175//=======================================================================
176void BRepAlgoAPI_Section::Init(const Standard_Boolean bFlag)
177{
178 myOperation=BOPAlgo_SECTION;
179 myParametersChanged = Standard_False;
180 myApprox = Standard_False;
181 myComputePCurve1 = Standard_False;
182 myComputePCurve2 = Standard_False;
183 myParametersChanged = Standard_True;
184 //
185 if (bFlag) {
7fd59977 186 Build();
4e57c75e 187 }
7fd59977 188}
7fd59977 189//=======================================================================
190//function : Init1
191//purpose :
192//=======================================================================
193void BRepAlgoAPI_Section::Init1(const TopoDS_Shape& S1)
194{
49b0c452 195 myArguments.Clear();
196 myArguments.Append(S1);
197 myParametersChanged = Standard_True;
7fd59977 198}
7fd59977 199//=======================================================================
200//function : Init1
201//purpose :
202//=======================================================================
203void BRepAlgoAPI_Section::Init1(const gp_Pln& Pl)
204{
205 Init1(MakeShape(new Geom_Plane(Pl)));
206}
7fd59977 207//=======================================================================
208//function : Init1
209//purpose :
210//=======================================================================
211void BRepAlgoAPI_Section::Init1(const Handle(Geom_Surface)& Sf)
212{
213 Init1(MakeShape(Sf));
214}
7fd59977 215//=======================================================================
216//function : Init2
217//purpose :
218//=======================================================================
219void BRepAlgoAPI_Section::Init2(const TopoDS_Shape& S2)
220{
49b0c452 221 myTools.Clear();
222 myTools.Append(S2);
223 myParametersChanged = Standard_True;
7fd59977 224}
7fd59977 225//=======================================================================
226//function : Init2
227//purpose :
228//=======================================================================
229void BRepAlgoAPI_Section::Init2(const gp_Pln& Pl)
230{
231 Init2(MakeShape(new Geom_Plane(Pl)));
232}
7fd59977 233//=======================================================================
234//function : Init2
235//purpose :
236//=======================================================================
237void BRepAlgoAPI_Section::Init2(const Handle(Geom_Surface)& Sf)
238{
239 Init2(MakeShape(Sf));
240}
7fd59977 241//=======================================================================
242//function : Approximation
243//purpose :
244//=======================================================================
245void BRepAlgoAPI_Section::Approximation(const Standard_Boolean B)
246{
247 if(myApprox != B) {
248 myApprox = B;
49b0c452 249 myParametersChanged = Standard_True;
7fd59977 250 }
251}
7fd59977 252//=======================================================================
253//function : ComputePCurveOn1
254//purpose :
255//=======================================================================
256void BRepAlgoAPI_Section::ComputePCurveOn1(const Standard_Boolean B)
257{
258 if(myComputePCurve1 != B) {
259 myComputePCurve1 = B;
49b0c452 260 myParametersChanged = Standard_True;
7fd59977 261 }
262}
7fd59977 263//=======================================================================
264//function : ComputePCurveOn2
265//purpose :
266//=======================================================================
267void BRepAlgoAPI_Section::ComputePCurveOn2(const Standard_Boolean B)
268{
269 if(myComputePCurve2 != B) {
270 myComputePCurve2 = B;
49b0c452 271 myParametersChanged = Standard_True;
7fd59977 272 }
273}
7fd59977 274//=======================================================================
49b0c452 275//function : SetAttributes
276//purpose :
277//=======================================================================
278void BRepAlgoAPI_Section::SetAttributes()
279{
280 BOPAlgo_SectionAttribute theSecAttr(myApprox,
281 myComputePCurve1,
282 myComputePCurve2);
283 myDSFiller->SetSectionAttribute(theSecAttr);
284}
285//=======================================================================
7fd59977 286//function : Build
287//purpose :
288//=======================================================================
289void BRepAlgoAPI_Section::Build()
290{
49b0c452 291 BRepAlgoAPI_BooleanOperation::Build();
7fd59977 292}
7fd59977 293//=======================================================================
294//function : HasAncestorFaceOn1
295//purpose :
296//=======================================================================
b1d15f53 297Standard_Boolean BRepAlgoAPI_Section::HasAncestorFaceOn1
49b0c452 298 (const TopoDS_Shape& aE,
299 TopoDS_Shape& aF) const
7fd59977 300{
49b0c452 301 Standard_Boolean bRes;
302 //
303 bRes = HasAncestorFace(myDSFiller,1 , aE, aF);
304 return bRes;
7fd59977 305}
7fd59977 306//=======================================================================
307//function : HasAncestorFaceOn2
308//purpose :
309//=======================================================================
b1d15f53 310Standard_Boolean BRepAlgoAPI_Section::HasAncestorFaceOn2
49b0c452 311 (const TopoDS_Shape& aE,
312 TopoDS_Shape& aF) const
313{
314 Standard_Boolean bRes;
315 //
316 bRes = HasAncestorFace(myDSFiller, 2, aE, aF);
317 return bRes;
318}
319//=======================================================================
320//function : HasAncestorFace
321//purpose :
322//=======================================================================
323Standard_Boolean HasAncestorFace (const BOPAlgo_PPaveFiller& pPF,
324 Standard_Integer aIndex,
325 const TopoDS_Shape& aE,
326 TopoDS_Shape& aF)
7fd59977 327{
49b0c452 328 Standard_Boolean bRes;
329 //
330 bRes = Standard_False;
331 if(aE.IsNull()) {
332 return bRes;
7fd59977 333 }
49b0c452 334 if(aE.ShapeType() != TopAbs_EDGE) {
335 return bRes;
7fd59977 336 }
49b0c452 337 //
338 TopoDS_Shape aF1, aF2;
339 //
340 bRes=HasAncestorFaces(pPF, aE, aF1, aF2);
341 if (!bRes) {
342 return bRes;
7fd59977 343 }
49b0c452 344 //
345 aF=(aIndex==1) ? aF1 : aF2;
346 return bRes;
7fd59977 347}
348
7fd59977 349//=======================================================================
b1d15f53 350//function : HasAncestorFaces
7fd59977 351//purpose :
352//=======================================================================
49b0c452 353Standard_Boolean HasAncestorFaces (const BOPAlgo_PPaveFiller& pPF,
354 const TopoDS_Shape& aEx,
355 TopoDS_Shape& aF1,
356 TopoDS_Shape& aF2)
7fd59977 357{
b1d15f53 358
49b0c452 359 Standard_Integer aNbFF, i, j, nE, nF1, nF2, aNbVC;
360 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
4e57c75e 361 //
49b0c452 362 const BOPDS_PDS& pDS = pPF->PDS();
4e57c75e 363 BOPDS_VectorOfInterfFF& aFFs=pDS->InterfFF();
364 //
7a9d451a 365 //section edges
49b0c452 366 aNbFF=aFFs.Extent();
367 for (i = 0; i<aNbFF; ++i) {
4e57c75e 368 BOPDS_InterfFF& aFFi=aFFs(i);
369 aFFi.Indices(nF1, nF2);
370 //
49b0c452 371 const BOPDS_VectorOfCurve& aVC=aFFi.Curves();
372 aNbVC=aVC.Extent();
373 for (j=0; j<aNbVC; j++) {
374 const BOPDS_Curve& aBC=aVC(j);
375 //
376 const BOPDS_ListOfPaveBlock& aLPB = aBC.PaveBlocks();
377 //
378 aItLPB.Initialize(aLPB);
379 for(; aItLPB.More(); aItLPB.Next()) {
380 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
4e57c75e 381 nE = aPB->Edge();
49b0c452 382 if(nE < 0) {
383 continue;
384 }
4e57c75e 385 //
49b0c452 386 const TopoDS_Shape aE=pDS->Shape(nE);
387 if(aEx.IsSame(aE)) {
388 aF1 = pDS->Shape(nF1);
389 aF2 = pDS->Shape(nF2);
4e57c75e 390 return Standard_True;
391 }
7fd59977 392 }
393 }
7fd59977 394 }
395 return Standard_False;
396}
b1d15f53 397//=======================================================================
398//function : MakeShape
399//purpose :
400//=======================================================================
401TopoDS_Shape MakeShape(const Handle(Geom_Surface)& S)
402{
403 GeomAbs_Shape c = S->Continuity();
404 if (c >= GeomAbs_C2) {
405 return BRepBuilderAPI_MakeFace(S, Precision::Confusion());
406 }
407 return BRepBuilderAPI_MakeShell(S);
408}