diff --git a/src/boolean_operations/BOPBuilderShapeToBRepBuilderShapeAdapter.cpp b/src/boolean_operations/BOPBuilderShapeToBRepBuilderShapeAdapter.cpp index 3f9e06a..3f7cdb3 100644 --- a/src/boolean_operations/BOPBuilderShapeToBRepBuilderShapeAdapter.cpp +++ b/src/boolean_operations/BOPBuilderShapeToBRepBuilderShapeAdapter.cpp @@ -18,9 +18,9 @@ #include "BOPBuilderShapeToBRepBuilderShapeAdapter.h" -#include +#include -BOPBuilderShapeToBRepBuilderShapeAdapter::BOPBuilderShapeToBRepBuilderShapeAdapter(BOPAlgo_BuilderShape& adaptee) +BOPBuilderShapeToBRepBuilderShapeAdapter::BOPBuilderShapeToBRepBuilderShapeAdapter(BRepAlgoAPI_BuilderAlgo & adaptee) : _adaptee(adaptee) { } diff --git a/src/boolean_operations/BOPBuilderShapeToBRepBuilderShapeAdapter.h b/src/boolean_operations/BOPBuilderShapeToBRepBuilderShapeAdapter.h index 6487244..700a18b 100644 --- a/src/boolean_operations/BOPBuilderShapeToBRepBuilderShapeAdapter.h +++ b/src/boolean_operations/BOPBuilderShapeToBRepBuilderShapeAdapter.h @@ -22,12 +22,12 @@ #include #include "geoml_internal.h" -class BOPAlgo_BuilderShape; +class BRepAlgoAPI_BuilderAlgo ; class BOPBuilderShapeToBRepBuilderShapeAdapter : public BRepBuilderAPI_MakeShape { public: - GEOML_EXPORT BOPBuilderShapeToBRepBuilderShapeAdapter(BOPAlgo_BuilderShape& adaptee); + GEOML_EXPORT BOPBuilderShapeToBRepBuilderShapeAdapter(BRepAlgoAPI_BuilderAlgo & adaptee); GEOML_EXPORT const TopoDS_Shape& Shape() const; GEOML_EXPORT operator TopoDS_Shape() const; @@ -37,7 +37,7 @@ class BOPBuilderShapeToBRepBuilderShapeAdapter : public BRepBuilderAPI_MakeShape GEOML_EXPORT Standard_Boolean IsDeleted(const TopoDS_Shape& S) override; private: - BOPAlgo_BuilderShape& _adaptee; + BRepAlgoAPI_BuilderAlgo& _adaptee; }; #endif // BOPBUILDERSHAPETOBREPBUILDERSHAPEADAPTER_H diff --git a/src/boolean_operations/CTrimShape.cpp b/src/boolean_operations/CTrimShape.cpp index cbe2407..bfe7b83 100644 --- a/src/boolean_operations/CTrimShape.cpp +++ b/src/boolean_operations/CTrimShape.cpp @@ -19,7 +19,7 @@ #include "CTrimShape.h" #include "CBooleanOperTools.h" -#include "GEOMAlgo_Splitter.hxx" +#include "BRepAlgoAPI_Splitter.hxx" #include "BOPBuilderShapeToBRepBuilderShapeAdapter.h" #include "common/CommonFunctions.h" #include "geoml/error.h" @@ -47,6 +47,7 @@ #include #include #include +#include #if OCC_VERSION_HEX < VERSION_HEX_CODE(7,3,0) #include #endif @@ -231,11 +232,13 @@ void CTrimShape::Perform() } PrepareFiller(); - GEOMAlgo_Splitter splitter; + BRepAlgoAPI_Splitter splitter(*_dsfiller); BOPBuilderShapeToBRepBuilderShapeAdapter splitAdapter(splitter); - splitter.AddArgument(_source->Shape()); - splitter.AddTool(_tool->Shape()); - splitter.PerformWithFiller(*_dsfiller); + TopTools_ListOfShape aLS; + aLS.Append(_source->Shape()); + aLS.Append(_tool->Shape()); + splitter.SetTools(aLS); + splitter.Build(); if (debug) { WriteDebugShape(splitter.Shape(), "split"); diff --git a/src/boolean_operations/GEOMAlgo_Splitter.cxx b/src/boolean_operations/GEOMAlgo_Splitter.cxx deleted file mode 100644 index 29fa0d9..0000000 --- a/src/boolean_operations/GEOMAlgo_Splitter.cxx +++ /dev/null @@ -1,407 +0,0 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: GEOMAlgo_Splitter.cxx -// Created: Thu Sep 06 10:54:04 2012 -// Author: Peter KURNEV -// -// - -#include - -#include - -#include -#include -#include - -#include -#include - -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) -#include -#include -#include -#include -#else -#include -#include -#include -#include -#endif - - -static - void TreatCompound(const TopoDS_Shape& aC, -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - TopTools_ListOfShape& aLSX); -#else - BOPCol_ListOfShape& aLSX); -#endif - -//======================================================================= -//function : -//purpose : -//======================================================================= -GEOMAlgo_Splitter::GEOMAlgo_Splitter() -: - BOPAlgo_Builder(), - myTools(myAllocator), - myMapTools(100, myAllocator) -{ - myLimit=TopAbs_SHAPE; - myLimitMode=0; -} -//======================================================================= -//function : -//purpose : -//======================================================================= -GEOMAlgo_Splitter::GEOMAlgo_Splitter - (const Handle(NCollection_BaseAllocator)& theAllocator) -: - BOPAlgo_Builder(theAllocator), - myTools(myAllocator), - myMapTools(100, myAllocator) -{ - myLimit=TopAbs_SHAPE; - myLimitMode=0; -} -//======================================================================= -//function : ~ -//purpose : -//======================================================================= -GEOMAlgo_Splitter::~GEOMAlgo_Splitter() -{ -} -//======================================================================= -//function : AddTool -//purpose : -//======================================================================= -void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape) -{ - if (myMapTools.Add(theShape)) { - myTools.Append(theShape); - // - AddArgument(theShape); - } -} -//======================================================================= -//function : Tools -//purpose : -//======================================================================= -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) -const TopTools_ListOfShape& GEOMAlgo_Splitter::Tools()const -#else -const BOPCol_ListOfShape& GEOMAlgo_Splitter::Tools()const -#endif -{ - return myTools; -} -//======================================================================= -//function : SetLimit -//purpose : -//======================================================================= -void GEOMAlgo_Splitter::SetLimit(const TopAbs_ShapeEnum aLimit) -{ - myLimit=aLimit; -} -//======================================================================= -//function : Limit -//purpose : -//======================================================================= -TopAbs_ShapeEnum GEOMAlgo_Splitter::Limit()const -{ - return myLimit; -} -//======================================================================= -//function : SetLimitMode -//purpose : -//======================================================================= -void GEOMAlgo_Splitter::SetLimitMode(const Standard_Integer aMode) -{ - myLimitMode=aMode; -} -//======================================================================= -//function : LimitMode -//purpose : -//======================================================================= -Standard_Integer GEOMAlgo_Splitter::LimitMode()const -{ - return myLimitMode; -} -//======================================================================= -//function : Clear -//purpose : -//======================================================================= -void GEOMAlgo_Splitter::Clear() -{ - myTools.Clear(); - myMapTools.Clear(); - myLimit=TopAbs_SHAPE; - BOPAlgo_Builder::Clear(); -} -//======================================================================= -//function : BuildResult -//purpose : -//======================================================================= -void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType) -{ -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,2,0) - myReport->Clear(); -#else - myErrorStatus=0; -#endif - // - TopAbs_ShapeEnum aType; - BRep_Builder aBB; -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - TopTools_MapOfShape aM; - TopTools_ListIteratorOfListOfShape aIt, aItIm; -#else - BOPCol_MapOfShape aM; - BOPCol_ListIteratorOfListOfShape aIt, aItIm; -#endif - // - aIt.Initialize(myArguments); - for (; aIt.More(); aIt.Next()) { - const TopoDS_Shape& aS=aIt.Value(); - aType=aS.ShapeType(); - if (aType==theType && !myMapTools.Contains(aS)) { - if (myImages.IsBound(aS)) { -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - const TopTools_ListOfShape& aLSIm=myImages.Find(aS); -#else - const BOPCol_ListOfShape& aLSIm=myImages.Find(aS); -#endif - aItIm.Initialize(aLSIm); - for (; aItIm.More(); aItIm.Next()) { - const TopoDS_Shape& aSIm=aItIm.Value(); - if (aM.Add(aSIm)) { - aBB.Add(myShape, aSIm); - } - } - } - else { - if (aM.Add(aS)) { - aBB.Add(myShape, aS); - } - } - } - } -} -//======================================================================= -//function : PostTreat -//purpose : -//======================================================================= -void GEOMAlgo_Splitter::PostTreat() -{ - if (myLimit!=TopAbs_SHAPE) { - Standard_Integer i, aNbS; - BRep_Builder aBB; - TopoDS_Compound aC; -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - TopTools_IndexedMapOfShape aMx; -#else - BOPCol_IndexedMapOfShape aMx; -#endif - // - aBB.MakeCompound(aC); - // -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - TopExp::MapShapes(myShape, myLimit, aMx); -#else - BOPTools::MapShapes(myShape, myLimit, aMx); -#endif - aNbS=aMx.Extent(); - for (i=1; i<=aNbS; ++i) { - const TopoDS_Shape& aS=aMx(i); - aBB.Add(aC, aS); - } - if (myLimitMode) { - Standard_Integer iType, iLimit, iTypeX; - TopAbs_ShapeEnum aType, aTypeX; -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - TopTools_ListOfShape aLSP, aLSX; - TopTools_ListIteratorOfListOfShape aIt, aItX, aItIm; - TopTools_MapOfShape aM; -#else - BOPCol_ListOfShape aLSP, aLSX; - BOPCol_ListIteratorOfListOfShape aIt, aItX, aItIm; - BOPCol_MapOfShape aM; -#endif - // - iLimit=(Standard_Integer)myLimit; - // - // 1. Collect the shapes to process aLSP - aIt.Initialize(myArguments); - for (; aIt.More(); aIt.Next()) { - const TopoDS_Shape& aS=aIt.Value(); - if (myMapTools.Contains(aS)) { - continue; - } - // - aType=aS.ShapeType(); - iType=(Standard_Integer)aType; - // - if (iType>iLimit) { - aLSP.Append(aS); - } - // - else if (aType==TopAbs_COMPOUND) { - aLSX.Clear(); - // - TreatCompound(aS, aLSX); - // - aItX.Initialize(aLSX); - for (; aItX.More(); aItX.Next()) { - const TopoDS_Shape& aSX=aItX.Value(); - aTypeX=aSX.ShapeType(); - iTypeX=(Standard_Integer)aTypeX; - // - if (iTypeX>iLimit) { - aLSP.Append(aSX); - } - } - } - }// for (; aIt.More(); aIt.Next()) { - // - aMx.Clear(); -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - TopExp::MapShapes(aC, aMx); -#else - BOPTools::MapShapes(aC, aMx); -#endif - // 2. Add them to aC - aIt.Initialize(aLSP); - for (; aIt.More(); aIt.Next()) { - const TopoDS_Shape& aS=aIt.Value(); - if (myImages.IsBound(aS)) { -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - const TopTools_ListOfShape& aLSIm=myImages.Find(aS); -#else - const BOPCol_ListOfShape& aLSIm=myImages.Find(aS); -#endif - aItIm.Initialize(aLSIm); - for (; aItIm.More(); aItIm.Next()) { - const TopoDS_Shape& aSIm=aItIm.Value(); - if (aM.Add(aSIm)) { - if (!aMx.Contains(aSIm)) { - aBB.Add(aC, aSIm); - } - } - } - } - else { - if (aM.Add(aS)) { - if (!aMx.Contains(aS)) { - aBB.Add(aC, aS); - } - } - } - } - }// if (myLimitMode) { - myShape=aC; - }//if (myLimit!=TopAbs_SHAPE) { - // - Standard_Integer aNbS; - TopoDS_Iterator aIt; -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - TopTools_ListOfShape aLS; -#else - BOPCol_ListOfShape aLS; -#endif - // - aIt.Initialize(myShape); - for (; aIt.More(); aIt.Next()) { - const TopoDS_Shape& aS=aIt.Value(); - aLS.Append(aS); - } - aNbS=aLS.Extent(); - if (aNbS==1) { - myShape=aLS.First(); - } - // - BOPAlgo_Builder::PostTreat(Message_ProgressRange()); -} -//======================================================================= -//function : TreatCompound -//purpose : -//======================================================================= -void TreatCompound(const TopoDS_Shape& aC1, -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - TopTools_ListOfShape& aLSX) -#else - BOPCol_ListOfShape& aLSX) -#endif -{ - Standard_Integer aNbC1; - TopAbs_ShapeEnum aType; -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - TopTools_ListOfShape aLC, aLC1; - TopTools_ListIteratorOfListOfShape aIt, aIt1; -#else - BOPCol_ListOfShape aLC, aLC1; - BOPCol_ListIteratorOfListOfShape aIt, aIt1; -#endif - TopoDS_Iterator aItC; - // - aLC.Append (aC1); - while(1) { - aLC1.Clear(); - aIt.Initialize(aLC); - for (; aIt.More(); aIt.Next()) { - const TopoDS_Shape& aC=aIt.Value(); //C is compound - // - aItC.Initialize(aC); - for (; aItC.More(); aItC.Next()) { - const TopoDS_Shape& aS=aItC.Value(); - aType=aS.ShapeType(); - if (aType==TopAbs_COMPOUND) { - aLC1.Append(aS); - } - else { - aLSX.Append(aS); - } - } - } - // - aNbC1=aLC1.Extent(); - if (!aNbC1) { - break; - } - // - aLC.Clear(); - aIt.Initialize(aLC1); - for (; aIt.More(); aIt.Next()) { - const TopoDS_Shape& aSC=aIt.Value(); - aLC.Append(aSC); - } - }// while(1) -} -// -// myErrorStatus -// -// 0 - Ok -// 1 - The object is just initialized -// 2 - PaveFiller is failed -// 10 - No shapes to process -// 30 - SolidBuilder failed diff --git a/src/boolean_operations/GEOMAlgo_Splitter.hxx b/src/boolean_operations/GEOMAlgo_Splitter.hxx deleted file mode 100644 index 19146a8..0000000 --- a/src/boolean_operations/GEOMAlgo_Splitter.hxx +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File: GEOMAlgo_Splitter.hxx -// -// Author: Peter KURNEV -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE - -#ifndef GEOMAlgo_Splitter_HeaderFile -#define GEOMAlgo_Splitter_HeaderFile - -#include "geoml_internal.h" - -#include -#include -#include -#include -#include - -#include - -#include - -#include - -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) -#include -#include -#else -#include -#include -#endif - -#include - -//======================================================================= -//class : GEOMAlgo_Splitter -//purpose : -//======================================================================= -class GEOMAlgo_Splitter : public BOPAlgo_Builder -{ -public: - - GEOML_EXPORT - GEOMAlgo_Splitter(); - - GEOML_EXPORT - GEOMAlgo_Splitter(const Handle(NCollection_BaseAllocator)& theAllocator); - - GEOML_EXPORT - ~GEOMAlgo_Splitter() override; - - GEOML_EXPORT - void AddTool(const TopoDS_Shape& theShape); - -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - GEOML_EXPORT - const TopTools_ListOfShape& Tools()const; -#else - GEOML_EXPORT - const BOPCol_ListOfShape& Tools()const; -#endif - - GEOML_EXPORT - void SetLimit(const TopAbs_ShapeEnum aLimit); - - GEOML_EXPORT - TopAbs_ShapeEnum Limit()const; - - GEOML_EXPORT - void SetLimitMode(const Standard_Integer aMode); - - GEOML_EXPORT - Standard_Integer LimitMode()const; - - GEOML_EXPORT - void Clear() override; - - protected: - GEOML_EXPORT - void BuildResult(const TopAbs_ShapeEnum theType) override; - - GEOML_EXPORT - void PostTreat(); - - protected: -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,3,0) - TopTools_ListOfShape myTools; - TopTools_MapOfShape myMapTools; -#else - BOPCol_ListOfShape myTools; - BOPCol_MapOfShape myMapTools; -#endif - TopAbs_ShapeEnum myLimit; - Standard_Integer myLimitMode; -}; - -#endif diff --git a/src/boolean_operations/Splitter.cpp b/src/boolean_operations/Splitter.cpp new file mode 100644 index 0000000..513b44d --- /dev/null +++ b/src/boolean_operations/Splitter.cpp @@ -0,0 +1,65 @@ +/* +* Copyright (C) 2007-2025 German Aerospace Center (DLR/SC) +* +* Created: 2025-01-08 Jan Kleinert +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#include "Splitter.h" +#include "geoml/error.h" +#include "Logging.h" + +#include +#include +#include +#include +#include + +namespace geoml { + +Splitter::Splitter(Shape const& shape, Shape const& cutting_tool) + : BRepBuilderAPI_MakeShape_Operation(&m_splitter, {shape, cutting_tool}) + , m_splitter() +{ + TopTools_ListOfShape inputs; + inputs.Append(shape); + inputs.Append(cutting_tool); + m_splitter.SetTools(inputs); + m_splitter.SetFuzzyValue(Precision::Confusion()); +} + +Shape Splitter::perform() { + + try { + m_splitter.Build(); + } + catch (const Standard_Failure& f) { + std::stringstream ss; + ss << "ERROR: splitting of shapes failed: " << f.GetMessageString(); + LOG(ERROR) << ss.str(); + throw geoml::Error(ss.str()); + } + + if (m_splitter.HasErrors()) { + std::ostringstream oss; + m_splitter.GetReport()->Dump(oss); + LOG(ERROR) << "unable to split passed shapes: " << oss.str(); + throw geoml::Error("unable to split passed shapes: " + oss.str()); + } + + return m_splitter.Shape(); +} + +} // namespace geoml \ No newline at end of file diff --git a/src/boolean_operations/Splitter.h b/src/boolean_operations/Splitter.h new file mode 100644 index 0000000..20a9fd4 --- /dev/null +++ b/src/boolean_operations/Splitter.h @@ -0,0 +1,39 @@ +/* +* Copyright (C) 2007-2025 German Aerospace Center (DLR/SC) +* +* Created: 2025-01-08 Jan Kleinert +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#pragma once + +#include "geoml/naming_choosing/Shape.h" +#include "topology/BRepBuilderAPI_MakeShape_Operation.h" +#include "geoml/geoml.h" +#include "BRepAlgoAPI_Splitter.hxx" + +namespace geoml { + +class Splitter : public BRepBuilderAPI_MakeShape_Operation +{ +public: + GEOML_API_EXPORT Splitter(Shape const& shape, Shape const& cutting_tool); + + GEOML_API_EXPORT Shape perform() override final; + +private: + BRepAlgoAPI_Splitter m_splitter; +}; + +} // namespace geoml \ No newline at end of file diff --git a/src/common/CommonFunctions.cpp b/src/common/CommonFunctions.cpp index 969259a..79d3c17 100644 --- a/src/common/CommonFunctions.cpp +++ b/src/common/CommonFunctions.cpp @@ -41,6 +41,7 @@ #include "PNamedShape.h" #include "ProjectPointOnCurveAtAngle.h" #include "BSplineAlgorithms.h" +#include "Splitter.h" #include "Geom_Curve.hxx" #include "Geom_Surface.hxx" @@ -101,7 +102,6 @@ #include #include #include -#include #include #include #include @@ -1388,60 +1388,8 @@ TopoDS_Shape CutShapes(const TopoDS_Shape& shape1, const TopoDS_Shape& shape2) TopoDS_Shape SplitShape(const TopoDS_Shape& src, const TopoDS_Shape& tool) { -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(6,9,0) - double fuzzyValue = Precision::Confusion(); - const int c_tries = 3; -#endif - - for (int i = 0;; i++) { - GEOMAlgo_Splitter splitter; - splitter.AddArgument(src); - splitter.AddTool(tool); -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(6,9,0) - splitter.SetFuzzyValue(fuzzyValue); -#endif - try { - splitter.Perform(); - } - catch (const Standard_Failure& f) { - std::stringstream ss; - ss << "ERROR: splitting of shapes failed: " << f.GetMessageString(); - LOG(ERROR) << ss.str(); - throw geoml::Error(ss.str()); - } - -#if OCC_VERSION_HEX >= VERSION_HEX_CODE(7,2,0) - if (splitter.HasErrors()) { - if (i < c_tries - 1) { - fuzzyValue *= 10; - LOG(WARNING) << "SplitShape failed, retrying with fuzzyValue: " << fuzzyValue; - continue; - } - - std::ostringstream oss; - splitter.GetReport()->Dump(oss); - LOG(ERROR) << "unable to split passed shapes: " << oss.str(); - throw geoml::Error("unable to split passed shapes: " + oss.str()); - } -#elif OCC_VERSION_HEX >= VERSION_HEX_CODE(6,9,0) - if (splitter.ErrorStatus() != 0) { - if (i < c_tries - 1) { - fuzzyValue *= 10; - LOG(WARNING) << "SplitShape failed, retrying with fuzzyValue: " << fuzzyValue; - continue; - } - - LOG(ERROR) << "unable to split passed shapes!"; - throw geoml::Error("unable to split passed shapes!"); - } -#else - if (splitter.ErrorStatus() != 0) { - LOG(ERROR) << "unable to split passed shapes!"; - throw geoml::Error("unable to split passed shapes!"); - } -#endif - return splitter.Shape(); - } + geoml::Splitter splitter(src, tool); + return splitter.value(); } void FindAllConnectedEdges(const TopoDS_Edge& edge, TopTools_ListOfShape& edgeList, TopTools_ListOfShape& targetList) diff --git a/src/geoml/boolean_ops/modeling.cpp b/src/geoml/boolean_ops/modeling.cpp index ed7782a..0af46ae 100644 --- a/src/geoml/boolean_ops/modeling.cpp +++ b/src/geoml/boolean_ops/modeling.cpp @@ -1,5 +1,6 @@ -#include "boolean_ops/modeling.hpp" -#include "topology/BRepBuilderAPI_MakeShape_Operation.hpp" +#include "boolean_ops/modeling.h" +#include "topology/BRepBuilderAPI_MakeShape_Operation.h" +#include "Splitter.h" #include "BRepAlgoAPI_Cut.hxx" #include "BRepAlgoAPI_Fuse.hxx" @@ -18,6 +19,23 @@ Shape operator-(Shape const& shape, Shape const& cutting_tool) return boolean_subtract(shape, cutting_tool); } +Shape boolean_union(Shape const& shape_1, Shape const& shape_2) +{ + BRepAlgoAPI_Fuse fuser(shape_1, shape_2); + auto operation = BRepBuilderAPI_MakeShape_Operation(&fuser, {shape_1, shape_2}); + return operation.value(); +} + +Shape operator+(Shape const& shape_1, Shape const& shape_2) +{ + return boolean_union(shape_1, shape_2); +} + +Shape split(Shape const& shape, Shape const& cutting_tool) +{ + Splitter splitter(shape, cutting_tool); + return splitter.value(); +} } // namespace geoml diff --git a/src/geoml/boolean_ops/modeling.hpp b/src/geoml/boolean_ops/modeling.h similarity index 64% rename from src/geoml/boolean_ops/modeling.hpp rename to src/geoml/boolean_ops/modeling.h index 3ff817c..352c6b9 100644 --- a/src/geoml/boolean_ops/modeling.hpp +++ b/src/geoml/boolean_ops/modeling.h @@ -17,7 +17,7 @@ namespace geoml * @param shape The Shape from which the cutting tool should be subtracted * @param cutting_tool The Shape that is the cutting tool */ -Shape boolean_subtract(Shape const& shape, Shape const& cutting_tool); +GEOML_API_EXPORT Shape boolean_subtract(Shape const& shape, Shape const& cutting_tool); /** * @brief A function that subracts a Shape (cutting tool) from a Shape. This function has a history mapping. @@ -26,7 +26,7 @@ Shape boolean_subtract(Shape const& shape, Shape const& cutting_tool); * @param shape The Shape from which the cutting tool should be subtracted * @param cutting_tool The Shape that is the cutting tool */ -Shape operator-(Shape const& shape, Shape const& cutting_tool); +GEOML_API_EXPORT Shape operator-(Shape const& shape, Shape const& cutting_tool); /** * @brief A function that returns the boolean union of two Shapes. This function has a history mapping. @@ -35,7 +35,7 @@ Shape operator-(Shape const& shape, Shape const& cutting_tool); * @param shape_1 The first Shape * @param shape_2 The second Shape */ -Shape boolean_union(Shape const& shape_1, Shape const& shape_2); +GEOML_API_EXPORT Shape boolean_union(Shape const& shape_1, Shape const& shape_2); /** * @brief A function that returns the boolean union of two Shapes. This function has a history mapping. @@ -44,8 +44,16 @@ Shape boolean_union(Shape const& shape_1, Shape const& shape_2); * @param shape_1 The first Shape * @param shape_2 The second Shape */ -Shape operator+(Shape const& shape_1, Shape const& shape_2); +GEOML_API_EXPORT Shape operator+(Shape const& shape_1, Shape const& shape_2); +/** + * @brief A function that splits a Shape with a cutting tool. This function has a history mapping. + * + * @param shape The Shape to be split + * @param cutting_tool The Shape that is the cutting tool + */ +GEOML_API_EXPORT Shape split(Shape const& shape, Shape const& cutting_tool); + } // namespace geoml diff --git a/src/geoml/predicates/predicate_functions.h b/src/geoml/predicates/predicate_functions.h index c23c06e..1d46617 100644 --- a/src/geoml/predicates/predicate_functions.h +++ b/src/geoml/predicates/predicate_functions.h @@ -38,6 +38,7 @@ GEOML_API_EXPORT ShapePredicate operator!(ShapePredicate const& pred); inline ShapePredicate const is_vertex = [](Shape const& s){ return s.is_type(TopAbs_VERTEX); }; inline ShapePredicate const is_edge = [](Shape const& s){ return s.is_type(TopAbs_EDGE); }; inline ShapePredicate const is_face = [](Shape const& s){ return s.is_type(TopAbs_FACE); }; +inline ShapePredicate const is_shell = [](Shape const& s){ return s.is_type(TopAbs_SHELL); }; inline ShapePredicate const is_solid = [](Shape const& s){ return s.is_type(TopAbs_SOLID); }; inline ShapePredicate const has_origin = [](Shape const& s){ return s.has_origin(); }; diff --git a/src/topology/BRepBuilderAPI_MakeShape_Operation.cpp b/src/topology/BRepBuilderAPI_MakeShape_Operation.cpp index 4879275..94f7707 100644 --- a/src/topology/BRepBuilderAPI_MakeShape_Operation.cpp +++ b/src/topology/BRepBuilderAPI_MakeShape_Operation.cpp @@ -1,6 +1,4 @@ -#include "BRepBuilderAPI_MakeShape_Operation.hpp" -#include "BRepAlgoAPI_Cut.hxx" -#include "BRepAlgoAPI_Fuse.hxx" +#include "BRepBuilderAPI_MakeShape_Operation.h" namespace geoml { @@ -12,10 +10,9 @@ BRepBuilderAPI_MakeShape_Operation::BRepBuilderAPI_MakeShape_Operation( m_algo(algo) {} -Shape BRepBuilderAPI_MakeShape_Operation::perform() const +Shape BRepBuilderAPI_MakeShape_Operation::perform() { return m_algo->Shape(); - } void BRepBuilderAPI_MakeShape_Operation::map_subshapes(Shape& result) const diff --git a/src/topology/BRepBuilderAPI_MakeShape_Operation.hpp b/src/topology/BRepBuilderAPI_MakeShape_Operation.h similarity index 75% rename from src/topology/BRepBuilderAPI_MakeShape_Operation.hpp rename to src/topology/BRepBuilderAPI_MakeShape_Operation.h index 01ff359..be1d52d 100644 --- a/src/topology/BRepBuilderAPI_MakeShape_Operation.hpp +++ b/src/topology/BRepBuilderAPI_MakeShape_Operation.h @@ -16,13 +16,13 @@ class BRepBuilderAPI_MakeShape_Operation : public Operation const& inputs ); + virtual ~BRepBuilderAPI_MakeShape_Operation() = default; - Shape perform() const; - void map_subshapes(Shape& result) const; + virtual Shape perform(); + virtual void map_subshapes(Shape& result) const; private: BRepBuilderAPI_MakeShape* m_algo; - // std::vector m_inputs; // Lifetime issue: Operation may not outlive the inputs! }; } // namespace geoml diff --git a/src/topology/Operation.h b/src/topology/Operation.h index 6cf8f84..b82e783 100644 --- a/src/topology/Operation.h +++ b/src/topology/Operation.h @@ -11,7 +11,6 @@ namespace geoml { * * Shape perform() const * void map_subshapes(Shape& result) const - * std::string id() const * * The first function performs the operation and returns the result. The second function maps * the result's subshapes to the inputs' subshapes by setting the result's subshapes' origin. @@ -27,9 +26,9 @@ class Operation virtual ~Operation() = default; - Shape value() const { - Shape ret = static_cast(*this).perform(); - static_cast(*this).map_subshapes(ret); + Shape value() { + Shape ret = static_cast(*this).perform(); + static_cast(*this).map_subshapes(ret); merge_and_apply_tag_tracks(ret); diff --git a/tests/apitests/src/testNamingChoosing.cpp b/tests/apitests/src/testNamingChoosing.cpp index 1136ca8..5cd9837 100644 --- a/tests/apitests/src/testNamingChoosing.cpp +++ b/tests/apitests/src/testNamingChoosing.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include