1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-06 18:26:22 +03:00
occt/src/BOPTest/BOPTest_Objects.cxx
emv 948fe6ca88 0028747: Incorrect result of the section operation after edge refinement
Implementation of the method for simplification of the result of Boolean Operation on the API level.
The method BRepAlgoAPI_BuilderAlgo::SimplifyResult has been added, so the derived classes such as BooleanOpeation and Splitter can also use this method.
The result shape simplification should be called after the operation is done. The simplification is performed by the means of ShapeUpgrade_UnifySameDomain algorithm.

Draw command "bsimplify" has been added to control the simplification options.
Documentation for new functionality and draw commands controlling the options of Boolean operations.
Test cases for the new functionality.

Side-effect change:
The algorithms in Boolean component have been changed to use the BRepTools_History as a History tool.
Now it became possible to disable the collection of shapes modifications during Boolean Operations, which may be useful for performance sake (in draw the option is controlled by *setfillhistory* command).
Draw command "unifysamedom" has been changed to accept the angular tolerance in degrees instead of radians.
2018-06-14 14:03:06 +03:00

517 lines
15 KiB
C++

// 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 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 <BOPAlgo_BOP.hxx>
#include <BOPAlgo_Builder.hxx>
#include <BOPAlgo_PaveFiller.hxx>
#include <BOPAlgo_Section.hxx>
#include <BOPTest_Objects.hxx>
#include <BOPAlgo_CellsBuilder.hxx>
#include <BOPAlgo_Splitter.hxx>
#include <NCollection_BaseAllocator.hxx>
#include <Precision.hxx>
static Handle(NCollection_BaseAllocator)& Allocator1();
//=======================================================================
//function : BOPTest_Session
//purpose :
//=======================================================================
class BOPTest_Session {
public:
//
BOPTest_Session() {
Init();
};
//
~BOPTest_Session(){
Clear();
};
//
// Init
void Init() {
Handle(NCollection_BaseAllocator) pA1, pA2;
//
pA1=NCollection_BaseAllocator::CommonBaseAllocator();
pA2=NCollection_BaseAllocator::CommonBaseAllocator();
//
myPaveFiller=new BOPAlgo_PaveFiller(pA1);
myBuilderDefault=new BOPAlgo_Builder(pA2);
//
myBuilder=myBuilderDefault;
SetDefaultOptions();
};
//
// Clear
void Clear() {
if (myPaveFiller) {
delete myPaveFiller;
myPaveFiller=NULL;
}
//
if (myBuilderDefault) {
delete myBuilderDefault;
myBuilderDefault=NULL;
}
};
//
// IsValid
Standard_Boolean IsValid() const {
return (myPaveFiller!=NULL);
}
// PaveFiller
BOPAlgo_PaveFiller& PaveFiller() {
return *myPaveFiller;
};
//
// Builder
BOPAlgo_Builder& Builder() {
return *myBuilder;
};
//
// SetBuilder
void SetBuilder(BOPAlgo_Builder* pBuilder) {
myBuilder=pBuilder;
};
//
// SetBuilderDef
void SetBuilderDefault() {
myBuilder=myBuilderDefault;
};
//
TopTools_ListOfShape& Shapes() {
return myShapes;
}
//
TopTools_ListOfShape& Tools() {
return myTools;
}
// Resets all options to default values
void SetDefaultOptions()
{
myRunParallel = Standard_False;
myNonDestructive = Standard_False;
myFuzzyValue = Precision::Confusion();
myGlue = BOPAlgo_GlueOff;
myDrawWarnShapes = Standard_False;
myCheckInverted = Standard_True;
myUseOBB = Standard_False;
myUnifyEdges = Standard_False;
myUnifyFaces = Standard_False;
myAngTol = Precision::Angular();
}
//
void SetRunParallel(const Standard_Boolean bFlag) {
myRunParallel=bFlag;
};
//
Standard_Boolean RunParallel()const {
return myRunParallel;
};
//
void SetFuzzyValue(const Standard_Real aValue) {
myFuzzyValue=aValue;
};
//
Standard_Real FuzzyValue()const {
return myFuzzyValue;
};
//
void SetNonDestructive(const Standard_Boolean theFlag) {
myNonDestructive = theFlag;
};
//
Standard_Boolean NonDestructive()const {
return myNonDestructive;
};
//
void SetGlue(const BOPAlgo_GlueEnum theGlue) {
myGlue = theGlue;
};
//
BOPAlgo_GlueEnum Glue() const {
return myGlue;
};
//
void SetDrawWarnShapes(const Standard_Boolean bDraw) {
myDrawWarnShapes = bDraw;
};
//
Standard_Boolean DrawWarnShapes() const {
return myDrawWarnShapes;
};
//
void SetCheckInverted(const Standard_Boolean bCheck) {
myCheckInverted = bCheck;
};
//
Standard_Boolean CheckInverted() const {
return myCheckInverted;
};
//
void SetUseOBB(const Standard_Boolean bUse) {
myUseOBB = bUse;
};
//
Standard_Boolean UseOBB() const {
return myUseOBB;
};
// Controls the Unification of Edges after BOP
void SetUnifyEdges(const Standard_Boolean bUE) { myUnifyEdges = bUE; }
// Returns flag of Edges unification
Standard_Boolean UnifyEdges() const { return myUnifyEdges; }
// Controls the Unification of Faces after BOP
void SetUnifyFaces(const Standard_Boolean bUF) { myUnifyFaces = bUF; }
// Returns flag of Faces unification
Standard_Boolean UnifyFaces() const { return myUnifyFaces; }
// Sets angular tolerance for Edges and Faces unification
void SetAngular(const Standard_Real theAngTol) { myAngTol = theAngTol; }
// Returns angular tolerance
Standard_Real Angular() const { return myAngTol; }
protected:
//
BOPTest_Session(const BOPTest_Session&);
BOPTest_Session& operator=(const BOPTest_Session&);
//
protected:
//
BOPAlgo_PaveFiller* myPaveFiller;
BOPAlgo_Builder* myBuilder;
BOPAlgo_Builder* myBuilderDefault;
//
TopTools_ListOfShape myShapes;
TopTools_ListOfShape myTools;
Standard_Boolean myRunParallel;
Standard_Boolean myNonDestructive;
Standard_Real myFuzzyValue;
BOPAlgo_GlueEnum myGlue;
Standard_Boolean myDrawWarnShapes;
Standard_Boolean myCheckInverted;
Standard_Boolean myUseOBB;
Standard_Boolean myUnifyEdges;
Standard_Boolean myUnifyFaces;
Standard_Real myAngTol;
};
//
//=======================================================================
//function : GetSession
//purpose :
//=======================================================================
static BOPTest_Session& GetSession()
{
static BOPTest_Session* pSession=new BOPTest_Session;
//
if (!pSession->IsValid()) {
pSession->Init();
}
return *pSession;
}
//
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void BOPTest_Objects::Init()
{
GetSession().Init();
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void BOPTest_Objects::Clear()
{
GetSession().Clear();
Shapes().Clear();
Tools().Clear();
}
//=======================================================================
//function : PaveFiller
//purpose :
//=======================================================================
BOPAlgo_PaveFiller& BOPTest_Objects::PaveFiller()
{
return GetSession().PaveFiller();
}
//=======================================================================
//function : PDS
//purpose :
//=======================================================================
BOPDS_PDS BOPTest_Objects::PDS()
{
return BOPTest_Objects::PaveFiller().PDS();
}
//=======================================================================
//function : Builder
//purpose :
//=======================================================================
BOPAlgo_Builder& BOPTest_Objects::Builder()
{
return GetSession().Builder();
}
//=======================================================================
//function : SetBuilder
//purpose :
//=======================================================================
void BOPTest_Objects::SetBuilder(const BOPAlgo_PBuilder& theBuilder)
{
BOPAlgo_Builder* pB;
//
pB=(BOPAlgo_Builder*)theBuilder;
GetSession().SetBuilder(pB);
}
//=======================================================================
//function : SetBuilderDefault
//purpose :
//=======================================================================
void BOPTest_Objects::SetBuilderDefault()
{
GetSession().SetBuilderDefault();
}
//=======================================================================
//function : BOP
//purpose :
//=======================================================================
BOPAlgo_BOP& BOPTest_Objects::BOP()
{
static BOPAlgo_BOP sBOP(Allocator1());
return sBOP;
}
//=======================================================================
//function : Section
//purpose :
//=======================================================================
BOPAlgo_Section& BOPTest_Objects::Section()
{
static BOPAlgo_Section sSection(Allocator1());
return sSection;
}
//=======================================================================
//function : CellsBuilder
//purpose :
//=======================================================================
BOPAlgo_CellsBuilder& BOPTest_Objects::CellsBuilder()
{
static BOPAlgo_CellsBuilder sCBuilder(Allocator1());
return sCBuilder;
}
//=======================================================================
//function : Splitter
//purpose :
//=======================================================================
BOPAlgo_Splitter& BOPTest_Objects::Splitter()
{
static BOPAlgo_Splitter aSplitter(Allocator1());
return aSplitter;
}
//=======================================================================
//function : Shapes
//purpose :
//=======================================================================
TopTools_ListOfShape& BOPTest_Objects::Shapes()
{
return GetSession().Shapes();
}
//=======================================================================
//function : Tools
//purpose :
//=======================================================================
TopTools_ListOfShape& BOPTest_Objects::Tools()
{
return GetSession().Tools();
}
//=======================================================================
//function : SetDefaultOptions
//purpose :
//=======================================================================
void BOPTest_Objects::SetDefaultOptions()
{
GetSession().SetDefaultOptions();
}
//=======================================================================
//function : SetRunParallel
//purpose :
//=======================================================================
void BOPTest_Objects::SetRunParallel(const Standard_Boolean bFlag)
{
GetSession().SetRunParallel(bFlag);
}
//=======================================================================
//function : RunParallel
//purpose :
//=======================================================================
Standard_Boolean BOPTest_Objects::RunParallel()
{
return GetSession().RunParallel();
}
//=======================================================================
//function : SetFuzzyValue
//purpose :
//=======================================================================
void BOPTest_Objects::SetFuzzyValue(const Standard_Real aValue)
{
GetSession().SetFuzzyValue(aValue);
}
//=======================================================================
//function : FuzzyValue
//purpose :
//=======================================================================
Standard_Real BOPTest_Objects::FuzzyValue()
{
return GetSession().FuzzyValue();
}
//=======================================================================
//function : SetNonDestructive
//purpose :
//=======================================================================
void BOPTest_Objects::SetNonDestructive(const Standard_Boolean theFlag)
{
GetSession().SetNonDestructive(theFlag);
}
//=======================================================================
//function : NonDestructive
//purpose :
//=======================================================================
Standard_Boolean BOPTest_Objects::NonDestructive()
{
return GetSession().NonDestructive();
}
//=======================================================================
//function : SetGlue
//purpose :
//=======================================================================
void BOPTest_Objects::SetGlue(const BOPAlgo_GlueEnum theGlue)
{
GetSession().SetGlue(theGlue);
}
//=======================================================================
//function : Glue
//purpose :
//=======================================================================
BOPAlgo_GlueEnum BOPTest_Objects::Glue()
{
return GetSession().Glue();
}
//=======================================================================
//function : SetDrawWarnShapes
//purpose :
//=======================================================================
void BOPTest_Objects::SetDrawWarnShapes(const Standard_Boolean bDraw)
{
GetSession().SetDrawWarnShapes(bDraw);
}
//=======================================================================
//function : DrawWarnShapes
//purpose :
//=======================================================================
Standard_Boolean BOPTest_Objects::DrawWarnShapes()
{
return GetSession().DrawWarnShapes();
}
//=======================================================================
//function : SetCheckInverted
//purpose :
//=======================================================================
void BOPTest_Objects::SetCheckInverted(const Standard_Boolean bCheck)
{
GetSession().SetCheckInverted(bCheck);
}
//=======================================================================
//function : CheckInverted
//purpose :
//=======================================================================
Standard_Boolean BOPTest_Objects::CheckInverted()
{
return GetSession().CheckInverted();
}
//=======================================================================
//function : SetUseOBB
//purpose :
//=======================================================================
void BOPTest_Objects::SetUseOBB(const Standard_Boolean bUseOBB)
{
GetSession().SetUseOBB(bUseOBB);
}
//=======================================================================
//function : UseOBB
//purpose :
//=======================================================================
Standard_Boolean BOPTest_Objects::UseOBB()
{
return GetSession().UseOBB();
}
//=======================================================================
//function : SetUnifyEdges
//purpose :
//=======================================================================
void BOPTest_Objects::SetUnifyEdges(const Standard_Boolean bUE)
{
GetSession().SetUnifyEdges(bUE);
}
//=======================================================================
//function : UnifyEdges
//purpose :
//=======================================================================
Standard_Boolean BOPTest_Objects::UnifyEdges()
{
return GetSession().UnifyEdges();
}
//=======================================================================
//function : SetUnifyFaces
//purpose :
//=======================================================================
void BOPTest_Objects::SetUnifyFaces(const Standard_Boolean bUF)
{
GetSession().SetUnifyFaces(bUF);
}
//=======================================================================
//function : UnifyFaces
//purpose :
//=======================================================================
Standard_Boolean BOPTest_Objects::UnifyFaces()
{
return GetSession().UnifyFaces();
}
//=======================================================================
//function : SetAngular
//purpose :
//=======================================================================
void BOPTest_Objects::SetAngular(const Standard_Real theAngTol)
{
GetSession().SetAngular(theAngTol);
}
//=======================================================================
//function : Angular
//purpose :
//=======================================================================
Standard_Real BOPTest_Objects::Angular()
{
return GetSession().Angular();
}
//=======================================================================
//function : Allocator1
//purpose :
//=======================================================================
Handle(NCollection_BaseAllocator)& Allocator1()
{
static Handle(NCollection_BaseAllocator) sAL1=
NCollection_BaseAllocator::CommonBaseAllocator();
return sAL1;
}