1 // Created on: 1994-02-18
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1994-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.
17 // modified by Michael KLOKOV Wed Mar 6 15:01:25 2002
18 // modified by Eugeny MALTCHIKOV Wed Jul 04 11:13:01 2012
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>
26 #include <BRepBuilderAPI_MakeFace.hxx>
27 #include <BRepBuilderAPI_MakeShell.hxx>
28 #include <Geom2d_TrimmedCurve.hxx>
29 #include <Geom_Plane.hxx>
30 #include <Geom_Surface.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopTools_IndexedMapOfShape.hxx>
37 #include <TopTools_MapOfShape.hxx>
41 TopoDS_Shape MakeShape(const Handle(Geom_Surface)& );
44 Standard_Boolean HasAncestorFaces(const BOPAlgo_PPaveFiller&,
49 Standard_Boolean HasAncestorFace (const BOPAlgo_PPaveFiller& ,
54 //=======================================================================
55 //function : BRepAlgoAPI_Section
57 //=======================================================================
58 BRepAlgoAPI_Section::BRepAlgoAPI_Section()
60 BRepAlgoAPI_BooleanOperation()
64 //=======================================================================
65 //function : BRepAlgoAPI_Section
67 //=======================================================================
68 BRepAlgoAPI_Section::BRepAlgoAPI_Section(const BOPAlgo_PaveFiller& aPF)
70 BRepAlgoAPI_BooleanOperation(aPF)
74 //=======================================================================
75 //function : Constructor
77 //=======================================================================
78 BRepAlgoAPI_Section::BRepAlgoAPI_Section(const TopoDS_Shape& Sh1,
79 const TopoDS_Shape& Sh2,
80 const Standard_Boolean PerformNow)
82 BRepAlgoAPI_BooleanOperation(Sh1,
88 //=======================================================================
89 //function : BRepAlgoAPI_Section
91 //=======================================================================
92 BRepAlgoAPI_Section::BRepAlgoAPI_Section
93 (const TopoDS_Shape& aS1,
94 const TopoDS_Shape& aS2,
95 const BOPAlgo_PaveFiller& aDSF,
96 const Standard_Boolean PerformNow)
98 BRepAlgoAPI_BooleanOperation(aS1,
105 //=======================================================================
106 //function : Constructor
108 //=======================================================================
109 BRepAlgoAPI_Section::BRepAlgoAPI_Section
110 (const TopoDS_Shape& Sh,
112 const Standard_Boolean PerformNow)
114 BRepAlgoAPI_BooleanOperation(Sh,
115 MakeShape(new Geom_Plane(Pl)),
120 //=======================================================================
121 //function : Constructor
123 //=======================================================================
124 BRepAlgoAPI_Section::BRepAlgoAPI_Section
125 (const TopoDS_Shape& Sh,
126 const Handle(Geom_Surface)& Sf,
127 const Standard_Boolean PerformNow)
129 BRepAlgoAPI_BooleanOperation(Sh,
135 //=======================================================================
136 //function : Constructor
138 //=======================================================================
139 BRepAlgoAPI_Section::BRepAlgoAPI_Section
140 (const Handle(Geom_Surface)& Sf,
141 const TopoDS_Shape& Sh,
142 const Standard_Boolean PerformNow)
144 BRepAlgoAPI_BooleanOperation(MakeShape(Sf),
150 //=======================================================================
151 //function : Constructor
153 //=======================================================================
154 BRepAlgoAPI_Section::BRepAlgoAPI_Section
155 (const Handle(Geom_Surface)& Sf1,
156 const Handle(Geom_Surface)& Sf2,
157 const Standard_Boolean PerformNow)
159 BRepAlgoAPI_BooleanOperation(MakeShape(Sf1),
165 //=======================================================================
166 //function : ~BRepAlgoAPI_Section
168 //=======================================================================
169 BRepAlgoAPI_Section::~BRepAlgoAPI_Section()
172 //=======================================================================
175 //=======================================================================
176 void BRepAlgoAPI_Section::Init(const Standard_Boolean bFlag)
178 myOperation=BOPAlgo_SECTION;
179 myParametersChanged = Standard_False;
180 myApprox = Standard_False;
181 myComputePCurve1 = Standard_False;
182 myComputePCurve2 = Standard_False;
183 myParametersChanged = Standard_True;
189 //=======================================================================
192 //=======================================================================
193 void BRepAlgoAPI_Section::Init1(const TopoDS_Shape& S1)
196 myArguments.Append(S1);
197 myParametersChanged = Standard_True;
199 //=======================================================================
202 //=======================================================================
203 void BRepAlgoAPI_Section::Init1(const gp_Pln& Pl)
205 Init1(MakeShape(new Geom_Plane(Pl)));
207 //=======================================================================
210 //=======================================================================
211 void BRepAlgoAPI_Section::Init1(const Handle(Geom_Surface)& Sf)
213 Init1(MakeShape(Sf));
215 //=======================================================================
218 //=======================================================================
219 void BRepAlgoAPI_Section::Init2(const TopoDS_Shape& S2)
223 myParametersChanged = Standard_True;
225 //=======================================================================
228 //=======================================================================
229 void BRepAlgoAPI_Section::Init2(const gp_Pln& Pl)
231 Init2(MakeShape(new Geom_Plane(Pl)));
233 //=======================================================================
236 //=======================================================================
237 void BRepAlgoAPI_Section::Init2(const Handle(Geom_Surface)& Sf)
239 Init2(MakeShape(Sf));
241 //=======================================================================
242 //function : Approximation
244 //=======================================================================
245 void BRepAlgoAPI_Section::Approximation(const Standard_Boolean B)
249 myParametersChanged = Standard_True;
252 //=======================================================================
253 //function : ComputePCurveOn1
255 //=======================================================================
256 void BRepAlgoAPI_Section::ComputePCurveOn1(const Standard_Boolean B)
258 if(myComputePCurve1 != B) {
259 myComputePCurve1 = B;
260 myParametersChanged = Standard_True;
263 //=======================================================================
264 //function : ComputePCurveOn2
266 //=======================================================================
267 void BRepAlgoAPI_Section::ComputePCurveOn2(const Standard_Boolean B)
269 if(myComputePCurve2 != B) {
270 myComputePCurve2 = B;
271 myParametersChanged = Standard_True;
274 //=======================================================================
275 //function : SetAttributes
277 //=======================================================================
278 void BRepAlgoAPI_Section::SetAttributes()
280 BOPAlgo_SectionAttribute theSecAttr(myApprox,
283 myDSFiller->SetSectionAttribute(theSecAttr);
285 //=======================================================================
288 //=======================================================================
289 void BRepAlgoAPI_Section::Build()
291 BRepAlgoAPI_BooleanOperation::Build();
293 //=======================================================================
294 //function : HasAncestorFaceOn1
296 //=======================================================================
297 Standard_Boolean BRepAlgoAPI_Section::HasAncestorFaceOn1
298 (const TopoDS_Shape& aE,
299 TopoDS_Shape& aF) const
301 Standard_Boolean bRes;
303 bRes = HasAncestorFace(myDSFiller,1 , aE, aF);
306 //=======================================================================
307 //function : HasAncestorFaceOn2
309 //=======================================================================
310 Standard_Boolean BRepAlgoAPI_Section::HasAncestorFaceOn2
311 (const TopoDS_Shape& aE,
312 TopoDS_Shape& aF) const
314 Standard_Boolean bRes;
316 bRes = HasAncestorFace(myDSFiller, 2, aE, aF);
319 //=======================================================================
320 //function : HasAncestorFace
322 //=======================================================================
323 Standard_Boolean HasAncestorFace (const BOPAlgo_PPaveFiller& pPF,
324 Standard_Integer aIndex,
325 const TopoDS_Shape& aE,
328 Standard_Boolean bRes;
330 bRes = Standard_False;
334 if(aE.ShapeType() != TopAbs_EDGE) {
338 TopoDS_Shape aF1, aF2;
340 bRes=HasAncestorFaces(pPF, aE, aF1, aF2);
345 aF=(aIndex==1) ? aF1 : aF2;
349 //=======================================================================
350 //function : HasAncestorFaces
352 //=======================================================================
353 Standard_Boolean HasAncestorFaces (const BOPAlgo_PPaveFiller& pPF,
354 const TopoDS_Shape& aEx,
359 Standard_Integer aNbFF, i, j, nE, nF1, nF2, aNbVC;
360 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
362 const BOPDS_PDS& pDS = pPF->PDS();
363 BOPDS_VectorOfInterfFF& aFFs=pDS->InterfFF();
367 for (i = 0; i<aNbFF; ++i) {
368 BOPDS_InterfFF& aFFi=aFFs(i);
369 aFFi.Indices(nF1, nF2);
371 const BOPDS_VectorOfCurve& aVC=aFFi.Curves();
373 for (j=0; j<aNbVC; j++) {
374 const BOPDS_Curve& aBC=aVC(j);
376 const BOPDS_ListOfPaveBlock& aLPB = aBC.PaveBlocks();
378 aItLPB.Initialize(aLPB);
379 for(; aItLPB.More(); aItLPB.Next()) {
380 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
386 const TopoDS_Shape aE=pDS->Shape(nE);
388 aF1 = pDS->Shape(nF1);
389 aF2 = pDS->Shape(nF2);
390 return Standard_True;
395 return Standard_False;
397 //=======================================================================
398 //function : MakeShape
400 //=======================================================================
401 TopoDS_Shape MakeShape(const Handle(Geom_Surface)& S)
403 GeomAbs_Shape c = S->Continuity();
404 if (c >= GeomAbs_C2) {
405 return BRepBuilderAPI_MakeFace(S, Precision::Confusion());
407 return BRepBuilderAPI_MakeShell(S);