1 // Created on: 1994-02-18
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // modified by Michael KLOKOV Wed Mar 6 15:01:25 2002
22 // modified by Eugeny MALTCHIKOV Wed Jul 04 11:13:01 2012
24 #include <BRepAlgoAPI_Section.ixx>
27 #include <BRepBuilderAPI_MakeFace.hxx>
28 #include <BRepBuilderAPI_MakeShell.hxx>
29 #include <Geom_Plane.hxx>
30 #include <Geom2d_TrimmedCurve.hxx>
33 #include <TopTools_IndexedMapOfShape.hxx>
34 #include <TopTools_MapOfShape.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <BRep_Tool.hxx>
39 #include <BOPAlgo_PaveFiller.hxx>
40 #include <BOPAlgo_BOP.hxx>
41 #include <BOPDS_DS.hxx>
43 static TopoDS_Shape MakeShape(const Handle(Geom_Surface)& S)
45 GeomAbs_Shape c = S->Continuity();
46 if (c >= GeomAbs_C2) return BRepBuilderAPI_MakeFace(S, Precision::Confusion());
47 else return BRepBuilderAPI_MakeShell(S);
50 static Standard_Boolean HasAncestorFaces(const BOPAlgo_PPaveFiller& theDSFiller,
51 const TopoDS_Shape& E,
55 //=======================================================================
56 //function : Constructor
58 //=======================================================================
59 BRepAlgoAPI_Section::BRepAlgoAPI_Section(const TopoDS_Shape& Sh1,
60 const TopoDS_Shape& Sh2,
61 const Standard_Boolean PerformNow)
62 : BRepAlgoAPI_BooleanOperation(Sh1, Sh2, BOPAlgo_SECTION)
65 myparameterschanged = Standard_True;
67 if(myS1.IsNull() || myS2.IsNull()) {
68 // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL");
69 myshapeisnull = Standard_True;
76 BRepAlgoAPI_Section::BRepAlgoAPI_Section(const TopoDS_Shape& aS1,
77 const TopoDS_Shape& aS2,
78 const BOPAlgo_PaveFiller& aDSF,
79 const Standard_Boolean PerformNow)
80 : BRepAlgoAPI_BooleanOperation(aS1, aS2, aDSF, BOPAlgo_SECTION)
83 myparameterschanged = Standard_True;
85 if(myS1.IsNull() || myS2.IsNull()) {
86 // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL");
87 myshapeisnull = Standard_True;
96 //=======================================================================
97 //function : Constructor
99 //=======================================================================
100 BRepAlgoAPI_Section::BRepAlgoAPI_Section(const TopoDS_Shape& Sh,
102 const Standard_Boolean PerformNow)
103 : BRepAlgoAPI_BooleanOperation(Sh, MakeShape(new Geom_Plane(Pl)), BOPAlgo_SECTION)
106 myparameterschanged = Standard_True;
108 if(Sh.IsNull() || myS2.IsNull()) {
109 // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL");
110 myshapeisnull = Standard_True;
117 //=======================================================================
118 //function : Constructor
120 //=======================================================================
121 BRepAlgoAPI_Section::BRepAlgoAPI_Section(const TopoDS_Shape& Sh,
122 const Handle(Geom_Surface)& Sf,
123 const Standard_Boolean PerformNow)
124 : BRepAlgoAPI_BooleanOperation(Sh, MakeShape(Sf), BOPAlgo_SECTION)
127 myparameterschanged = Standard_True;
129 if(Sh.IsNull() || myS2.IsNull()) {
130 // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL");
131 myshapeisnull = Standard_True;
138 //=======================================================================
139 //function : Constructor
141 //=======================================================================
142 BRepAlgoAPI_Section::BRepAlgoAPI_Section(const Handle(Geom_Surface)& Sf,
143 const TopoDS_Shape& Sh,
144 const Standard_Boolean PerformNow)
145 : BRepAlgoAPI_BooleanOperation(MakeShape(Sf), Sh, BOPAlgo_SECTION)
148 myparameterschanged = Standard_True;
150 if(myS1.IsNull() || Sh.IsNull()) {
151 // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL");
152 myshapeisnull = Standard_True;
159 //=======================================================================
160 //function : Constructor
162 //=======================================================================
163 BRepAlgoAPI_Section::BRepAlgoAPI_Section(const Handle(Geom_Surface)& Sf1,
164 const Handle(Geom_Surface)& Sf2,
165 const Standard_Boolean PerformNow)
166 : BRepAlgoAPI_BooleanOperation(MakeShape(Sf1), MakeShape(Sf2), BOPAlgo_SECTION)
169 myparameterschanged = Standard_True;
171 if(myS1.IsNull() || myS2.IsNull()) {
172 // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL");
173 myshapeisnull = Standard_True;
181 //=======================================================================
184 //=======================================================================
185 void BRepAlgoAPI_Section::Init1(const TopoDS_Shape& S1)
188 if (!S1.IsEqual(myS1)) {
192 myshapeisnull = Standard_False;
194 myparameterschanged = Standard_True;
200 myshapeisnull = Standard_True;
201 myparameterschanged = Standard_True;
205 if(myparameterschanged)
209 //=======================================================================
212 //=======================================================================
213 void BRepAlgoAPI_Section::Init1(const gp_Pln& Pl)
215 Init1(MakeShape(new Geom_Plane(Pl)));
218 //=======================================================================
221 //=======================================================================
222 void BRepAlgoAPI_Section::Init1(const Handle(Geom_Surface)& Sf)
224 Init1(MakeShape(Sf));
227 //=======================================================================
230 //=======================================================================
231 void BRepAlgoAPI_Section::Init2(const TopoDS_Shape& S2)
234 if (!S2.IsEqual(myS2)) {
238 myshapeisnull = Standard_False;
240 myparameterschanged = Standard_True;
246 myshapeisnull = Standard_True;
247 myparameterschanged = Standard_True;
251 if(myparameterschanged) {
256 //=======================================================================
259 //=======================================================================
260 void BRepAlgoAPI_Section::Init2(const gp_Pln& Pl)
262 Init2(MakeShape(new Geom_Plane(Pl)));
265 //=======================================================================
268 //=======================================================================
269 void BRepAlgoAPI_Section::Init2(const Handle(Geom_Surface)& Sf)
271 Init2(MakeShape(Sf));
274 //=======================================================================
275 //function : Approximation
277 //=======================================================================
278 void BRepAlgoAPI_Section::Approximation(const Standard_Boolean B)
282 myparameterschanged = Standard_True;
286 //=======================================================================
287 //function : ComputePCurveOn1
289 //=======================================================================
290 void BRepAlgoAPI_Section::ComputePCurveOn1(const Standard_Boolean B)
292 if(myComputePCurve1 != B) {
293 myComputePCurve1 = B;
294 myparameterschanged = Standard_True;
298 //=======================================================================
299 //function : ComputePCurveOn2
301 //=======================================================================
302 void BRepAlgoAPI_Section::ComputePCurveOn2(const Standard_Boolean B)
304 if(myComputePCurve2 != B) {
305 myComputePCurve2 = B;
306 myparameterschanged = Standard_True;
310 //=======================================================================
313 //=======================================================================
314 void BRepAlgoAPI_Section::Build()
322 if(myparameterschanged) {
323 Standard_Boolean bIsNewFiller = PrepareFiller();
325 if (myErrorStatus!=1) {
327 // there were errors during the preparation
332 BOPAlgo_SectionAttribute theSecAttr(myApprox, myComputePCurve1, myComputePCurve2);
333 myDSFiller->SetSectionAttribute(theSecAttr);
334 myDSFiller->Perform();
337 BRepAlgoAPI_BooleanOperation::Build();
339 myparameterschanged = Standard_False;
343 //=======================================================================
344 //function : HasAncestorFaceOn1
346 //=======================================================================
347 Standard_Boolean BRepAlgoAPI_Section::HasAncestorFaceOn1(const TopoDS_Shape& E, TopoDS_Shape& F) const
349 Standard_Boolean aResult = Standard_False;
354 if(E.ShapeType() != TopAbs_EDGE) {
358 aResult = HasAncestorFaces(myDSFiller, E, F1, F2);
361 return Standard_False;
367 //=======================================================================
368 //function : HasAncestorFaceOn2
370 //=======================================================================
371 Standard_Boolean BRepAlgoAPI_Section::HasAncestorFaceOn2(const TopoDS_Shape& E,TopoDS_Shape& F) const
373 Standard_Boolean aResult = Standard_False;
378 if(E.ShapeType() != TopAbs_EDGE) {
382 aResult = HasAncestorFaces(myDSFiller, E, F1, F2);
385 return Standard_False;
391 //=======================================================================
392 //function : PCurveOn1
394 //=======================================================================
395 Handle(Geom2d_Curve) BRepAlgoAPI_Section::PCurveOn1(const TopoDS_Shape& E) const
397 Handle(Geom2d_Curve) aResult;
399 if(myComputePCurve1) {
402 if(HasAncestorFaceOn1(E, aShape)) {
403 const TopoDS_Edge& anEdge = TopoDS::Edge(E);
404 const TopoDS_Face& aFace = TopoDS::Face(aShape);
406 aResult = BRep_Tool::CurveOnSurface(anEdge, aFace, f, l);
408 if(!aResult->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
409 aResult = new Geom2d_TrimmedCurve(aResult, f, l);
416 //=======================================================================
417 //function : PCurveOn2
419 //=======================================================================
420 Handle(Geom2d_Curve) BRepAlgoAPI_Section::PCurveOn2(const TopoDS_Shape& E) const
422 Handle(Geom2d_Curve) aResult;
424 if(myComputePCurve2) {
427 if(HasAncestorFaceOn2(E, aShape)) {
428 const TopoDS_Edge& anEdge = TopoDS::Edge(E);
429 const TopoDS_Face& aFace = TopoDS::Face(aShape);
431 aResult = BRep_Tool::CurveOnSurface(anEdge, aFace, f, l);
433 if(!aResult->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
434 aResult = new Geom2d_TrimmedCurve(aResult, f, l);
441 //=======================================================================
442 //function : InitParameters
444 //=======================================================================
445 void BRepAlgoAPI_Section::InitParameters()
447 myparameterschanged = Standard_False;
448 myshapeisnull = Standard_False;
449 myApprox = Standard_False;
450 myComputePCurve1 = Standard_False;
451 myComputePCurve2 = Standard_False;
454 // ------------------------------------------------------------------------
455 // static function : HasAncestorFaces
457 // ------------------------------------------------------------------------
458 static Standard_Boolean HasAncestorFaces(const BOPAlgo_PPaveFiller& theDSFiller,
459 const TopoDS_Shape& E,
463 Standard_Integer aNb, i, j, nE, nF1, nF2, aNbCurves;;
465 const BOPDS_PDS& pDS = theDSFiller->PDS();
466 BOPDS_VectorOfInterfFF& aFFs=pDS->InterfFF();
470 for (i = 0; i < aNb; i++) {
471 BOPDS_InterfFF& aFFi=aFFs(i);
472 aFFi.Indices(nF1, nF2);
475 const BOPDS_VectorOfCurve& aSeqOfCurve=aFFi.Curves();
476 aNbCurves=aSeqOfCurve.Extent();
477 for (j=0; j<aNbCurves; j++) {
478 const BOPDS_Curve& aCurve=aSeqOfCurve(j);
480 const BOPDS_ListOfPaveBlock& aSectEdges = aCurve.PaveBlocks();
482 BOPDS_ListIteratorOfListOfPaveBlock anIt;
483 anIt.Initialize(aSectEdges);
485 for(; anIt.More(); anIt.Next()) {
486 const Handle(BOPDS_PaveBlock)& aPB = anIt.Value();
490 if(E.IsSame(pDS->Shape(nE))) {
491 F1 = pDS->Shape(nF1);
492 F2 = pDS->Shape(nF2);
493 return Standard_True;
498 //existing pave blocks
499 BOPCol_ListOfInteger aLSE;
500 BOPCol_ListIteratorOfListOfInteger aItLSE;
502 pDS->SharedEdges(nF1, nF2, aLSE, theDSFiller->Allocator());
503 aItLSE.Initialize(aLSE);
504 for (; aItLSE.More(); aItLSE.Next()) {
507 if(E.IsSame(pDS->Shape(nE))) {
508 F1 = pDS->Shape(nF1);
509 F2 = pDS->Shape(nF2);
510 return Standard_True;
514 return Standard_False;