From 7671835a5a65114c1b0f5c8601a4c3ba1bdd8c09 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sat, 8 Apr 2017 10:10:36 +0200 Subject: [PATCH] refactoring --- Geo/GModelIO_OCC.cpp | 51 +++++++++++++++++++++++++++---- Geo/GModelIO_OCC.h | 72 ++++++++++++++++++++++++++++++++++++++------ Parser/Gmsh.tab.cpp | 4 +-- Parser/Gmsh.y | 4 +-- 4 files changed, 111 insertions(+), 20 deletions(-) diff --git a/Geo/GModelIO_OCC.cpp b/Geo/GModelIO_OCC.cpp index 4998acda41..9dd1c6c901 100644 --- a/Geo/GModelIO_OCC.cpp +++ b/Geo/GModelIO_OCC.cpp @@ -1877,12 +1877,11 @@ bool OCC_Internals::fillet(const std::vector<int> ®ionTags, return true; } -bool OCC_Internals::applyBooleanOperator - (int tag, BooleanOperator op, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - bool removeObject, bool removeTool) +bool OCC_Internals::booleanOperator(int tag, BooleanOperator op, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool) { double tolerance = CTX::instance()->geom.toleranceBoolean; bool parallel = CTX::instance()->geom.occParallel; @@ -2158,6 +2157,46 @@ bool OCC_Internals::applyBooleanOperator return true; } +bool OCC_Internals::booleanUnion(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool) +{ + return booleanOperator(tag, OCC_Internals::Union, objectDimTags, toolDimTags, + outDimTags, removeObject, removeTool); +} + +bool OCC_Internals::booleanIntersection(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool) +{ + return booleanOperator(tag, OCC_Internals::Intersection, objectDimTags, toolDimTags, + outDimTags, removeObject, removeTool); +} + +bool OCC_Internals::booleanDifference(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool) +{ + return booleanOperator(tag, OCC_Internals::Difference, objectDimTags, toolDimTags, + outDimTags, removeObject, removeTool); +} + +bool OCC_Internals::booleanFragments(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool) +{ + return booleanOperator(tag, OCC_Internals::Fragments, objectDimTags, toolDimTags, + outDimTags, removeObject, removeTool); +} + bool OCC_Internals::_transform(const std::vector<std::pair<int, int> > &inDimTags, BRepBuilderAPI_Transform *tfo, BRepBuilderAPI_GTransform *gtfo) diff --git a/Geo/GModelIO_OCC.h b/Geo/GModelIO_OCC.h index 04d6c72bd9..6693849401 100644 --- a/Geo/GModelIO_OCC.h +++ b/Geo/GModelIO_OCC.h @@ -239,11 +239,31 @@ class OCC_Internals { bool removeRegion); // apply boolean operator - bool applyBooleanOperator(int tag, BooleanOperator op, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - bool removeObject, bool removeTool); + bool booleanOperator(int tag, BooleanOperator op, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool); + bool booleanUnion(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool); + bool booleanIntersection(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool); + bool booleanDifference(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool); + bool booleanFragments(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool); // apply transformations bool translate(const std::vector<std::pair<int, int> > &inDimTags, @@ -508,14 +528,46 @@ public: { return _error("create fillet"); } - bool applyBooleanOperator(int tag, BooleanOperator op, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - bool removeObject, bool removeTool) + bool booleanOperator(int tag, BooleanOperator op, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool) { return _error("apply boolean operator"); } + bool booleanUnion(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool) + { + return _error("apply boolean union"); + } + bool booleanIntersection(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool) + { + return _error("apply boolean intersection"); + } + bool booleanDifference(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool) + { + return _error("apply boolean difference"); + } + bool booleanFragments(int tag, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + bool removeObject, bool removeTool) + { + return _error("apply boolean fragments"); + } bool translate(const std::vector<std::pair<int, int> > &inDimTags, double dx, double dy, double dz) { diff --git a/Parser/Gmsh.tab.cpp b/Parser/Gmsh.tab.cpp index 204c713bb4..7d299d99d5 100644 --- a/Parser/Gmsh.tab.cpp +++ b/Parser/Gmsh.tab.cpp @@ -10490,7 +10490,7 @@ yyreduce: // currently we don't distinguish between Delete and Recursive Delete: // we always delete recursively. Let us know if you have examples where // having the choice would be interesting - r = GModel::current()->getOCCInternals()->applyBooleanOperator + r = GModel::current()->getOCCInternals()->booleanOperator (-1, (OCC_Internals::BooleanOperator)(yyvsp[(1) - (9)].i), object, tool, out, (yyvsp[(4) - (9)].i), (yyvsp[(8) - (9)].i)); VectorOfPairs2ListOfShapes(out, (yyval.l)); } @@ -10533,7 +10533,7 @@ yyreduce: // currently we don't distinguish between Delete and Recursive Delete: // we always delete recursively. Let us know if you have examples where // having the choice would be interesting - r = GModel::current()->getOCCInternals()->applyBooleanOperator + r = GModel::current()->getOCCInternals()->booleanOperator ((int)(yyvsp[(3) - (14)].d), (OCC_Internals::BooleanOperator)(yyvsp[(1) - (14)].i), object, tool, out, (yyvsp[(8) - (14)].i), (yyvsp[(12) - (14)].i)); } if(!r) yymsg(0, "Could not apply boolean operator"); diff --git a/Parser/Gmsh.y b/Parser/Gmsh.y index 3de33fdf53..4c3b037c86 100644 --- a/Parser/Gmsh.y +++ b/Parser/Gmsh.y @@ -3922,7 +3922,7 @@ Boolean : // currently we don't distinguish between Delete and Recursive Delete: // we always delete recursively. Let us know if you have examples where // having the choice would be interesting - r = GModel::current()->getOCCInternals()->applyBooleanOperator + r = GModel::current()->getOCCInternals()->booleanOperator (-1, (OCC_Internals::BooleanOperator)$1, object, tool, out, $4, $8); VectorOfPairs2ListOfShapes(out, $$); } @@ -3963,7 +3963,7 @@ BooleanShape : // currently we don't distinguish between Delete and Recursive Delete: // we always delete recursively. Let us know if you have examples where // having the choice would be interesting - r = GModel::current()->getOCCInternals()->applyBooleanOperator + r = GModel::current()->getOCCInternals()->booleanOperator ((int)$3, (OCC_Internals::BooleanOperator)$1, object, tool, out, $8, $12); } if(!r) yymsg(0, "Could not apply boolean operator"); -- GitLab