// Created by: Peter KURNEV // 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 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 #include #include #include #include #include #include #include #include #include #include #include static TopAbs_ShapeEnum TypeToExplore(const Standard_Integer theDim); //======================================================================= //function : //purpose : //======================================================================= BOPAlgo_BOP::BOPAlgo_BOP() : BOPAlgo_Builder(), myTools(myAllocator), myMapTools(100, myAllocator) { myNbArgs=2; Clear(); } //======================================================================= //function : //purpose : //======================================================================= BOPAlgo_BOP::BOPAlgo_BOP(const Handle(NCollection_BaseAllocator)& theAllocator) : BOPAlgo_Builder(theAllocator), myTools(myAllocator), myMapTools(100, myAllocator) { myNbArgs=2; Clear(); } //======================================================================= //function : ~ //purpose : //======================================================================= BOPAlgo_BOP::~BOPAlgo_BOP() { } //======================================================================= //function : Clear //purpose : //======================================================================= void BOPAlgo_BOP::Clear() { myOperation=BOPAlgo_UNKNOWN; myTools.Clear(); myMapTools.Clear(); myDims[0]=-1; myDims[1]=-1; // BOPAlgo_Builder::Clear(); } //======================================================================= //function : AddArgument //purpose : //======================================================================= void BOPAlgo_BOP::AddArgument(const TopoDS_Shape& theShape) { if (myMapFence.Add(theShape)) { myArguments.Append(theShape); myArgs[0]=theShape; } } //======================================================================= //function : AddTool //purpose : //======================================================================= void BOPAlgo_BOP::AddTool(const TopoDS_Shape& theShape) { if (myMapTools.Add(theShape)) { myTools.Append(theShape); myArgs[1]=theShape; // if (myMapFence.Add(theShape)) { myArguments.Append(theShape); } } } //======================================================================= //function : Object //purpose : //======================================================================= const TopoDS_Shape& BOPAlgo_BOP::Object()const { return myArgs[0]; } //======================================================================= //function : Tool //purpose : //======================================================================= const TopoDS_Shape& BOPAlgo_BOP::Tool()const { return myArgs[1]; } //======================================================================= //function : SetOperation //purpose : //======================================================================= void BOPAlgo_BOP::SetOperation(const BOPAlgo_Operation theOperation) { myOperation=theOperation; } //======================================================================= //function : Operation //purpose : //======================================================================= BOPAlgo_Operation BOPAlgo_BOP::Operation()const { return myOperation; } //======================================================================= //function : CheckData //purpose : //======================================================================= void BOPAlgo_BOP::CheckData() { Standard_Integer i, aNb; Standard_Boolean bFlag; // myErrorStatus=0; // aNb=myArguments.Extent(); if (aNb!=myNbArgs) { if (aNb!=1 || !(myArgs[0].IsSame(myArgs[1]))) { myErrorStatus=10; // invalid number of arguments return; } } // if (!myPaveFiller) { myErrorStatus=101; return; } // myErrorStatus=myPaveFiller->ErrorStatus(); if (myErrorStatus) { return; } // for (i=0; imyDims[1]) { if (myOperation==BOPAlgo_FUSE || myOperation==BOPAlgo_CUT) { myErrorStatus=14; // non-licit operation for the arguments return; } } } //======================================================================= //function : Prepare //purpose : //======================================================================= void BOPAlgo_BOP::Prepare() { Standard_Integer i; BRep_Builder aBB; // BOPAlgo_Builder::Prepare(); // if(myWarningStatus == 2) { switch(myOperation) { case BOPAlgo_FUSE: for ( i = 0; i < myNbArgs; i++ ) { aBB.Add(myShape, myArgs[i]); } break; case BOPAlgo_COMMON: case BOPAlgo_SECTION: break; case BOPAlgo_CUT: if(BOPTools_AlgoTools3D::IsEmptyShape(myArgs[0])) { break; } else { aBB.Add(myShape, myArgs[0]); } break; case BOPAlgo_CUT21: if(BOPTools_AlgoTools3D::IsEmptyShape(myArgs[1])) { break; } else { aBB.Add(myShape, myArgs[1]); } break; default: break; } } } //======================================================================= //function : PerformInternal //purpose : //======================================================================= void BOPAlgo_BOP::PerformInternal(const BOPAlgo_PaveFiller& theFiller) { myErrorStatus=0; myWarningStatus=0; // myPaveFiller=(BOPAlgo_PaveFiller*)&theFiller; myDS=myPaveFiller->PDS(); myContext=myPaveFiller->Context(); // // 1. CheckData CheckData(); if (myErrorStatus && !myWarningStatus) { return; } // // 2. Prepare Prepare(); if (myErrorStatus) { return; } if(myWarningStatus == 2) { return; } // // 3. Fill Images // 3.1 Vertices FillImagesVertices(); if (myErrorStatus) { return; } // BuildResult(TopAbs_VERTEX); if (myErrorStatus) { return; } // 3.2 Edges FillImagesEdges(); if (myErrorStatus) { return; } BuildResult(TopAbs_EDGE); if (myErrorStatus) { return; } //-------------------------------- SECTION f if (myOperation==BOPAlgo_SECTION) { BuildSection(); PrepareHistory(); PostTreat(); return; } //-------------------------------- SECTION t // // 3.3 Wires FillImagesContainers(TopAbs_WIRE); if (myErrorStatus) { return; } BuildResult(TopAbs_WIRE); if (myErrorStatus) { return; } // 3.4 Faces FillImagesFaces(); if (myErrorStatus) { return; } BuildResult(TopAbs_FACE); if (myErrorStatus) { return; } // 3.5 Shells FillImagesContainers(TopAbs_SHELL); if (myErrorStatus) { return; } BuildResult(TopAbs_SHELL); if (myErrorStatus) { return; } // 3.6 Solids FillImagesSolids(); if (myErrorStatus) { return; } BuildResult(TopAbs_SOLID); if (myErrorStatus) { return; } // 3.7 CompSolids FillImagesContainers(TopAbs_COMPSOLID); if (myErrorStatus) { return; } BuildResult(TopAbs_COMPSOLID); if (myErrorStatus) { return; } // 3.8 Compounds FillImagesCompounds(); if (myErrorStatus) { return; } BuildResult(TopAbs_COMPOUND); if (myErrorStatus) { return; } // // 6.BuildShape; BuildShape(); // // 4.History PrepareHistory(); // // 5 Post-treatment PostTreat(); } //======================================================================= //function : BuildShape //purpose : //======================================================================= void BOPAlgo_BOP::BuildShape() { Standard_Integer aDmin, aNbLCB; TopAbs_ShapeEnum aT1, aT2, aTR; TopoDS_Shape aR, aRC; TopoDS_Iterator aIt; BRep_Builder aBB; BOPCol_ListOfShape aLCB; BOPCol_ListIteratorOfListOfShape aItLCB; // myErrorStatus=0; // BuildRC(); //myShape=myRC; // aDmin=myDims[1]; if (myDims[0]aNb[1])? 1 : 0; } else { iX=(myDims[0]