-// File: BRepAlgoAPI_BooleanOperation.cxx
-// Created: Fri Oct 15 11:35:03 1993
-// Author: Remi LEQUETTE
-// <rle@phylox>
+// Created on: 1993-10-15
+// Created by: Remi LEQUETTE
+// Copyright (c) 1993-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
#include <BRepAlgoAPI_BooleanOperation.ixx>
-#include <BOP_Builder.hxx>
-#include <BOP_Section.hxx>
-#include <BOP_ShellShell.hxx>
-#include <BOP_SolidSolid.hxx>
-#include <BOP_ShellSolid.hxx>
-#include <BOP_WireWire.hxx>
-#include <BOP_WireShell.hxx>
-#include <BOP_WireSolid.hxx>
-#include <BOPTools_DSFiller.hxx>
-#include <BOPTools_Tools3D.hxx>
-#include <BOP_EmptyBuilder.hxx>
-
-#include <BOP_WireSolidHistoryCollector.hxx>
-#include <BOP_ShellSolidHistoryCollector.hxx>
-#include <BOP_SolidSolidHistoryCollector.hxx>
-#include <BOP_SectionHistoryCollector.hxx>
+#include <BRepAlgoAPI.hxx>
+#include <BRepAlgoAPI_Check.hxx>
+
#include <BRepLib_FuseEdges.hxx>
#include <TopExp.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
-static Handle(BOP_HistoryCollector) MakeCollector(const TopoDS_Shape& theShape1,
- const TopoDS_Shape& theShape2,
- const BOP_Operation theOperation);
-
+#include <BOPAlgo_PaveFiller.hxx>
+#include <BOPAlgo_BOP.hxx>
+#include <BOPDS_DS.hxx>
//=======================================================================
//function : BRepAlgoAPI_BooleanOperation
//purpose :
//=======================================================================
BRepAlgoAPI_BooleanOperation::BRepAlgoAPI_BooleanOperation(const TopoDS_Shape& aS1,
- const TopoDS_Shape& aS2,
- const BOP_Operation anOp)
+ const TopoDS_Shape& aS2,
+ const BOPAlgo_Operation anOp)
:
myS1(aS1),
myS2(aS2),
//purpose :
//=======================================================================
BRepAlgoAPI_BooleanOperation::BRepAlgoAPI_BooleanOperation(const TopoDS_Shape& aS1,
- const TopoDS_Shape& aS2,
- const BOPTools_DSFiller& aDSFiller,
- const BOP_Operation anOp)
+ const TopoDS_Shape& aS2,
+ const BOPAlgo_PaveFiller& aDSFiller,
+ const BOPAlgo_Operation anOp)
:
myS1(aS1),
myS2(aS2),
myFuseEdges(Standard_False)
{
if ((Standard_Address) &aDSFiller!=NULL) {
- myDSFiller=(BOPTools_PDSFiller)&aDSFiller;
+ myDSFiller=(BOPAlgo_PaveFiller*)&aDSFiller;
}
}
//=======================================================================
delete myDSFiller;
myDSFiller=NULL;
}
+
+ //
+ myModifFaces.Clear();
+ myEdgeMap.Clear();
}
//=======================================================================
//function : SetOperation
//purpose :
//=======================================================================
- void BRepAlgoAPI_BooleanOperation::SetOperation (const BOP_Operation anOp)
+ void BRepAlgoAPI_BooleanOperation::SetOperation (const BOPAlgo_Operation anOp)
{
myOperation=anOp;
}
//function : Operation
//purpose :
//=======================================================================
- BOP_Operation BRepAlgoAPI_BooleanOperation::Operation ()const
+ BOPAlgo_Operation BRepAlgoAPI_BooleanOperation::Operation ()const
{
return myOperation;
}
return myGenerated;
}
else {
- const TopTools_ListOfShape& aLM=myBuilder->Modified(aS);
+ myGenerated = myBuilder->Modified(aS);
if(myFuseEdges) {
- return RefinedList(aLM);
+ TopTools_ListOfShape theLS;
+ theLS.Assign(myGenerated);
+ //
+ RefinedList(theLS);
}
-
- return aLM;
+ return myGenerated;
}
}
//=======================================================================
Standard_Boolean BRepAlgoAPI_BooleanOperation::IsDeleted(const TopoDS_Shape& aS)
{
-
-// Standard_Boolean bDeleted = Standard_True;
-// if (myBuilder==NULL) {
-// return bDeleted;
-// }
-// else {
-// bDeleted=myBuilder->IsDeleted(aS);
-// return bDeleted;
-// }
- if(myHistory.IsNull()) {
- Standard_Boolean bDeleted = Standard_True;
-
- if (myBuilder==NULL) {
- return bDeleted;
- }
- else {
- bDeleted = myBuilder->IsDeleted(aS);
- return bDeleted;
- }
+ Standard_Boolean bDeleted = Standard_True;
+ if (myBuilder != NULL) {
+ bDeleted=myBuilder->IsDeleted(aS);
}
- return myHistory->IsDeleted(aS);
+ return bDeleted;
}
+
//=======================================================================
//function : PrepareFiller
//purpose :
return bIsNewFiller;
}
//
- if (myOperation==BOP_UNKNOWN) {
+ if (myOperation==BOPAlgo_UNKNOWN) {
myErrorStatus=6;
return bIsNewFiller;
}
if (myDSFiller==NULL) {
bIsNewFiller=!bIsNewFiller;
- myDSFiller=new BOPTools_DSFiller;
+ myDSFiller=new BOPAlgo_PaveFiller;
//
if (myDSFiller==NULL) {
myErrorStatus=4;
return bIsNewFiller;
}
//
- myDSFiller->SetShapes(myS1, myS2);
- if (!myDSFiller->IsDone()) {
- myErrorStatus=3;
- if (myDSFiller!=NULL) {
- delete myDSFiller;
- myDSFiller = NULL;
- return bIsNewFiller;
- }
- }
+ BOPCol_ListOfShape aLS;
+ aLS.Append(myS1);
+ aLS.Append(myS2);
+ //
+ myDSFiller->SetArguments(aLS);
}
return bIsNewFiller;
//=======================================================================
void BRepAlgoAPI_BooleanOperation::Build()
{
- Standard_Boolean bIsDone, bIsNewFiller;
+ Standard_Boolean bIsNewFiller;
+ Standard_Integer iErr;
+ //
+ //dump arguments and result of boolean operation in tcl script
+ char *pathdump = getenv("CSF_DEBUG_BOP");
+ Standard_Boolean isDump = (pathdump != NULL),
+ isDumpArgs = Standard_False,
+ isDumpRes = Standard_False;
+ Standard_CString aPath = pathdump;
//
myBuilderCanWork=Standard_False;
NotDone();
myBuilder=NULL;
}
//
- const TopoDS_Shape& aS1 = myDSFiller->Shape1();
- const TopoDS_Shape& aS2 = myDSFiller->Shape2();
- //
- myShape.Nullify();
- //
- // SECTION
+ const TopoDS_Shape& aS1 = myS1;
+ const TopoDS_Shape& aS2 = myS2;
//
- if (myOperation==BOP_SECTION) {
- myBuilder=new BOP_Section;
+ if (isDump) {
+ BRepAlgoAPI_Check aChekArgs(aS1, aS2, myOperation);
+ isDumpArgs = !aChekArgs.IsValid();
}
- //
- // COMMON, FUSE, CUT12, CUT21
//
- else if (myOperation==BOP_COMMON || myOperation==BOP_FUSE ||
- myOperation==BOP_CUT || myOperation==BOP_CUT21) {
- //
- // Check whether one or both of the arguments is(are) empty shape(s)
- // If yes, create BOP_EmptyBuilder object and build the result fast.
- {
- Standard_Boolean bIsEmptyShape1, bIsEmptyShape2;
-
- bIsEmptyShape1=BOPTools_Tools3D::IsEmptyShape(aS1);
- bIsEmptyShape2=BOPTools_Tools3D::IsEmptyShape(aS2);
- //
- if (bIsEmptyShape1 || bIsEmptyShape2) {
- myBuilder=new BOP_EmptyBuilder;
- //
- if (myBuilder==NULL) {
- myErrorStatus=7;
- return ;
- }
- //
- myBuilder->SetShapes(aS1, aS2);
- myBuilder->SetOperation (myOperation);
- myBuilder->DoWithFiller (*myDSFiller);
-
- bIsDone=myBuilder->IsDone();
-
- if (bIsDone) {
- myErrorStatus=0;
- myBuilderCanWork=Standard_True;
- myShape=myBuilder->Result();
- Done();
- }
- else {
- myErrorStatus=100+myBuilder->ErrorStatus();
- NotDone();
- }
- return;
- }
- }
- //
- TopAbs_ShapeEnum aT1, aT2;
+ myShape.Nullify();
- aT1=aS1.ShapeType();
- aT2=aS2.ShapeType();
- //
- // Shell / Shell
- if (aT1==TopAbs_SHELL && aT2==TopAbs_SHELL) {
- myBuilder=new BOP_ShellShell;
- }
- //
- // Solid / Solid
- else if (aT1==TopAbs_SOLID && aT2==TopAbs_SOLID) {
- myBuilder=new BOP_SolidSolid;
- }
- //
- // Shell / Solid
- else if ((aT1==TopAbs_SOLID && aT2==TopAbs_SHELL)
- ||
- (aT2==TopAbs_SOLID && aT1==TopAbs_SHELL)) {
- myBuilder=new BOP_ShellSolid;
- }
- //
- // Wire / Wire
- else if (aT1==TopAbs_WIRE && aT2==TopAbs_WIRE){
- myBuilder=new BOP_WireWire;
- }
- //
- // Wire / Shell
- else if ((aT1==TopAbs_WIRE && aT2==TopAbs_SHELL)
- ||
- (aT2==TopAbs_WIRE && aT1==TopAbs_SHELL)) {
- myBuilder=new BOP_WireShell;
- }
- //
- // Wire / Shell
- else if ((aT1==TopAbs_WIRE && aT2==TopAbs_SOLID)
- ||
- (aT2==TopAbs_WIRE && aT1==TopAbs_SOLID)) {
- myBuilder=new BOP_WireSolid;
- }
- else {
- myErrorStatus=5;
- return ;
- }
- }
- //
- if (myBuilder==NULL) {
- myErrorStatus=7;
- return ;
- }
+ myBuilder=new BOPAlgo_BOP;
+ myBuilder->AddArgument(aS1);
+ myBuilder->AddTool(aS2);
+ myBuilder->SetOperation(myOperation);
//
- myBuilder->SetShapes(aS1, aS2);
- myBuilder->SetOperation (myOperation);
-
- myHistory = MakeCollector(aS1, aS2, myOperation);
- myBuilder->SetHistoryCollector(myHistory);
-
- myBuilder->DoWithFiller (*myDSFiller);
-
- bIsDone=myBuilder->IsDone();
-
- if (bIsDone) {
+ myBuilder->PerformWithFiller(*myDSFiller);
+ iErr = myBuilder->ErrorStatus();
+ if (!iErr) {
myErrorStatus=0;
myBuilderCanWork=Standard_True;
- myShape=myBuilder->Result();
+ myShape=myBuilder->Shape();
+ //
+ if (isDump) {
+ BRepAlgoAPI_Check aCheckRes(myShape);
+ isDumpRes = !aCheckRes.IsValid();
+ if (isDumpArgs || isDumpRes) {
+ BRepAlgoAPI::DumpOper(aPath, aS1, aS2, myShape, myOperation, isDumpArgs);
+ }
+ }
+ //
Done();
- }
+ }
else {
- myErrorStatus=100+myBuilder->ErrorStatus();
+ myErrorStatus=100+iErr;
NotDone();
}
}
myGenerated.Clear();
return myGenerated;
}
- else {
- const TopTools_ListOfShape& aLM=myBuilder->SectionEdges();
-
- if(myFuseEdges) {
- return RefinedList(aLM);
+ //
+ Standard_Integer aNb, i, j, aNbCurves, nE;
+ BOPDS_ListIteratorOfListOfPaveBlock anIt;
+ //
+ const BOPDS_PDS& pDS = myDSFiller->PDS();
+ BOPDS_VectorOfInterfFF& aFFs=pDS->InterfFF();
+ myGenerated.Clear();
+ //
+ aNb=aFFs.Extent();
+ for (i = 0; i < aNb; i++) {
+ BOPDS_InterfFF& aFFi=aFFs(i);
+ const BOPDS_VectorOfCurve& aSeqOfCurve=aFFi.Curves();
+ //
+ aNbCurves=aSeqOfCurve.Extent();
+ for (j=0; j<aNbCurves; j++) {
+ const BOPDS_Curve& aCurve=aSeqOfCurve(j);
+ const BOPDS_ListOfPaveBlock& aSectEdges = aCurve.PaveBlocks();
+ //
+ anIt.Initialize(aSectEdges);
+ for(; anIt.More(); anIt.Next()) {
+ const Handle(BOPDS_PaveBlock)& aPB = anIt.Value();
+ nE = aPB->Edge();
+ const TopoDS_Shape& aE = pDS->Shape(nE);
+ myGenerated.Append(aE);
+ }
}
-
- return aLM;
}
-}
-//
-
-// ================================================================================================
-// function: Modified2
-// purpose:
-// ================================================================================================
-const TopTools_ListOfShape& BRepAlgoAPI_BooleanOperation::Modified2(const TopoDS_Shape& aS)
-{
- if(myHistory.IsNull()) {
- myGenerated.Clear();
- return myGenerated;
- }
-
+ //
if(myFuseEdges) {
- const TopTools_ListOfShape& aL = myHistory->Modified(aS);
- return RefinedList(aL);
+ TopTools_ListOfShape theLS;
+ theLS.Assign(myGenerated);
+ //
+ RefinedList(theLS);
}
-
- return myHistory->Modified(aS);
+ //
+ return myGenerated;
}
// ================================================================================================
// ================================================================================================
const TopTools_ListOfShape& BRepAlgoAPI_BooleanOperation::Generated(const TopoDS_Shape& S)
{
- if(myHistory.IsNull()) {
+ if (myBuilder==NULL) {
myGenerated.Clear();
return myGenerated;
}
-
+ //
if(myFuseEdges) {
- const TopTools_ListOfShape& aL = myHistory->Generated(S);
+ const TopTools_ListOfShape& aL = myBuilder->Generated(S);
return RefinedList(aL);
}
-
- return myHistory->Generated(S);
+
+ return myBuilder->Generated(S);
}
// ================================================================================================
// ================================================================================================
Standard_Boolean BRepAlgoAPI_BooleanOperation::HasModified() const
{
- if(myHistory.IsNull()) {
+ if (myBuilder==NULL) {
return Standard_False;
}
- return myHistory->HasModified();
+ return myBuilder->HasModified();
}
// ================================================================================================
// ================================================================================================
Standard_Boolean BRepAlgoAPI_BooleanOperation::HasGenerated() const
{
- if(myHistory.IsNull()) {
+ if (myBuilder==NULL) {
return Standard_False;
}
- return myHistory->HasGenerated();
+ return myBuilder->HasGenerated();
}
// ================================================================================================
// ================================================================================================
Standard_Boolean BRepAlgoAPI_BooleanOperation::HasDeleted() const
{
- if(myHistory.IsNull()) {
+ if (myBuilder==NULL) {
return Standard_False;
}
- return myHistory->HasDeleted();
+ return myBuilder->HasDeleted();
}
//=======================================================================
//function : RefineEdges
void BRepAlgoAPI_BooleanOperation::RefineEdges ()
{
-
if(myFuseEdges) return; //Edges have been refined yet
BRepLib_FuseEdges FE(myShape);
FE.ResultEdges(aResultEdges);
FE.Faces(myModifFaces);
myFuseEdges = Standard_True;
-
Standard_Integer i;
for(i = 1; i <= nle; ++i) {
const TopTools_ListOfShape& aListOfOldEdges = aFusedEdges(i);
TopTools_ListIteratorOfListOfShape anIter(aListOfOldEdges);
for(; anIter.More(); anIter.Next()) {
- myEdgeMap.Bind(anIter.Value(), aNewE);
+ myEdgeMap.Bind(anIter.Value(), aNewE);
}
}
}
-
}
//=======================================================================
if(anS.ShapeType() == TopAbs_EDGE) {
if(myEdgeMap.IsBound(anS)) {
- const TopoDS_Shape& aNewEdge = myEdgeMap.Find(anS);
- if(aMap.Add(aNewEdge)) {
- myGenerated.Append(aNewEdge);
- }
+ const TopoDS_Shape& aNewEdge = myEdgeMap.Find(anS);
+ if(aMap.Add(aNewEdge)) {
+ myGenerated.Append(aNewEdge);
+ }
}
else {
- myGenerated.Append(anS);
+ myGenerated.Append(anS);
}
}
else if (anS.ShapeType() == TopAbs_FACE) {
if(myModifFaces.IsBound(anS)) {
- myGenerated.Append(myModifFaces.Find(anS));
+ myGenerated.Append(myModifFaces.Find(anS));
}
else {
- myGenerated.Append(anS);
+ myGenerated.Append(anS);
}
}
else {
return myGenerated;
}
-// -----------------------------------------------------------------------------------------
-// static function: MakeCollector
-// purpose:
-// -----------------------------------------------------------------------------------------
-Handle(BOP_HistoryCollector) MakeCollector(const TopoDS_Shape& theShape1,
- const TopoDS_Shape& theShape2,
- const BOP_Operation theOperation) {
-
- Handle(BOP_HistoryCollector) aresult;
-
- if(theOperation == BOP_SECTION) {
- aresult = new BOP_SectionHistoryCollector(theShape1, theShape2);
- return aresult;
- }
-
- TopAbs_ShapeEnum aT1, aT2;
-
- aT1 = theShape1.ShapeType();
- aT2 = theShape2.ShapeType();
- //
- // Shell / Shell
- if (aT1==TopAbs_SHELL && aT2==TopAbs_SHELL) {
- // aresult = new BOP_ShellShellHistoryCollector(theShape1, theShape2, theOperation, theDSFiller);
- }
- //
- // Solid / Solid
- else if (aT1==TopAbs_SOLID && aT2==TopAbs_SOLID) {
- aresult = new BOP_SolidSolidHistoryCollector(theShape1, theShape2, theOperation);
- }
- //
- // Shell / Solid
- else if ((aT1==TopAbs_SOLID && aT2==TopAbs_SHELL)
- ||
- (aT2==TopAbs_SOLID && aT1==TopAbs_SHELL)) {
- aresult = new BOP_ShellSolidHistoryCollector(theShape1, theShape2, theOperation);
- }
- //
- // Wire / Wire
- else if (aT1==TopAbs_WIRE && aT2==TopAbs_WIRE){
- // aresult = new BOP_WireWireHistoryCollector(theShape1, theShape2, theOperation, theDSFiller);
- }
- //
- // Wire / Shell
- else if ((aT1==TopAbs_WIRE && aT2==TopAbs_SHELL)
- ||
- (aT2==TopAbs_WIRE && aT1==TopAbs_SHELL)) {
- // aresult = new BOP_WireShellHistoryCollector(theShape1, theShape2, theOperation, theDSFiller);
- }
- //
- // Wire / Shell
- else if ((aT1==TopAbs_WIRE && aT2==TopAbs_SOLID)
- ||
- (aT2==TopAbs_WIRE && aT1==TopAbs_SOLID)) {
- aresult = new BOP_WireSolidHistoryCollector(theShape1, theShape2, theOperation);
- }
- return aresult;
-}
-