From 8898b87144f1b532591b59c331da0b682b2628dd Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 23 Mar 2017 22:34:30 +0100
Subject: [PATCH] combine _transform and _gtransform

---
 Geo/GModelIO_OCC.cpp | 50 +++++++++++++++++++-------------------------
 Geo/GModelIO_OCC.h   |  7 ++-----
 Parser/Gmsh.tab.cpp  |  4 ++--
 Parser/Gmsh.y        |  4 ++--
 4 files changed, 27 insertions(+), 38 deletions(-)

diff --git a/Geo/GModelIO_OCC.cpp b/Geo/GModelIO_OCC.cpp
index 19475a083b..f89f7d6915 100644
--- a/Geo/GModelIO_OCC.cpp
+++ b/Geo/GModelIO_OCC.cpp
@@ -1878,27 +1878,7 @@ bool OCC_Internals::applyBooleanOperator
 }
 
 bool OCC_Internals::_transform(const std::vector<std::pair<int, int> > &inDimTags,
-                               BRepBuilderAPI_Transform *tfo)
-{
-  for(unsigned int i = 0; i < inDimTags.size(); i++){
-    int dim = inDimTags[i].first;
-    int tag = inDimTags[i].second;
-    if(!isBound(dim, tag)){
-      Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d",
-                 dim, tag);
-      return false;
-    }
-    tfo->Perform(find(dim, tag), Standard_False);
-    if(!tfo->IsDone()){
-      Msg::Error("Could not apply transformation");
-      return false;
-    }
-    bind(tfo->Shape(), dim, tag);
-  }
-  return true;
-}
-
-bool OCC_Internals::_gtransform(const std::vector<std::pair<int, int> > &inDimTags,
+                               BRepBuilderAPI_Transform *tfo,
                                BRepBuilderAPI_GTransform *gtfo)
 {
   for(unsigned int i = 0; i < inDimTags.size(); i++){
@@ -1909,12 +1889,24 @@ bool OCC_Internals::_gtransform(const std::vector<std::pair<int, int> > &inDimTa
                  dim, tag);
       return false;
     }
-    gtfo->Perform(find(dim, tag), Standard_False);
-    if(!gtfo->IsDone()){
-      Msg::Error("Could not apply transformation");
-      return false;
+    TopoDS_Shape result;
+    if(tfo){
+      tfo->Perform(find(dim, tag), Standard_False);
+      if(!tfo->IsDone()){
+        Msg::Error("Could not apply transformation");
+        return false;
+      }
+      result = tfo->Shape();
+    }
+    else if(gtfo){
+      gtfo->Perform(find(dim, tag), Standard_False);
+      if(!gtfo->IsDone()){
+        Msg::Error("Could not apply transformation");
+        return false;
+      }
+      result = gtfo->Shape();
     }
-    bind(gtfo->Shape(), dim, tag);
+    bind(result, dim, tag);
   }
   return true;
 }
@@ -1925,7 +1917,7 @@ bool OCC_Internals::translate(const std::vector<std::pair<int, int> > &inDimTags
   gp_Trsf t;
   t.SetTranslation(gp_Pnt(0, 0, 0), gp_Pnt(dx, dy, dz));
   BRepBuilderAPI_Transform tfo(t);
-  return _transform(inDimTags, &tfo);
+  return _transform(inDimTags, &tfo, 0);
 }
 
 bool OCC_Internals::rotate(const std::vector<std::pair<int, int> > &inDimTags,
@@ -1936,7 +1928,7 @@ bool OCC_Internals::rotate(const std::vector<std::pair<int, int> > &inDimTags,
   gp_Ax1 axisOfRevolution(gp_Pnt(x, y, z), gp_Dir(ax, ay, az));
   t.SetRotation(axisOfRevolution, angle);
   BRepBuilderAPI_Transform tfo(t);
-  return _transform(inDimTags, &tfo);
+  return _transform(inDimTags, &tfo, 0);
 }
 
 bool OCC_Internals::dilate(const std::vector<std::pair<int, int> > &inDimTags,
@@ -1947,7 +1939,7 @@ bool OCC_Internals::dilate(const std::vector<std::pair<int, int> > &inDimTags,
   t.SetTranslationPart(gp_XYZ(x,y,z));
   t.SetVectorialPart(gp_Mat(a, 0, 0, 0, b, 0, 0, 0, c));
   BRepBuilderAPI_GTransform gtfo(t);
-  return _gtransform(inDimTags, &gtfo);
+  return _transform(inDimTags, 0, &gtfo);
 }
 
 bool OCC_Internals::copy(const std::vector<std::pair<int, int> > &inDimTags,
diff --git a/Geo/GModelIO_OCC.h b/Geo/GModelIO_OCC.h
index b553a79cc5..64252e8129 100644
--- a/Geo/GModelIO_OCC.h
+++ b/Geo/GModelIO_OCC.h
@@ -82,12 +82,9 @@ class OCC_Internals {
                   bool fixsmalledges, bool fixspotstripfaces, bool sewfaces,
                   bool makesolids=false, double scaling=0.0);
 
-  // apply a geometrical transformation (does not modify Shape)
+  // apply a geometrical transformation
   bool _transform(const std::vector<std::pair<int, int> > &inDimTags,
-                  BRepBuilderAPI_Transform *tfo);
-
-  // apply a G geometrical transformation (modifies Shape : affinity...)
-  bool _gtransform(const std::vector<std::pair<int, int> > &inDimTags,
+                  BRepBuilderAPI_Transform *tfo,
                   BRepBuilderAPI_GTransform *gtfo);
 
   // add circle or ellipse arc
diff --git a/Parser/Gmsh.tab.cpp b/Parser/Gmsh.tab.cpp
index f55ef80766..32eaf13f36 100644
--- a/Parser/Gmsh.tab.cpp
+++ b/Parser/Gmsh.tab.cpp
@@ -8661,7 +8661,7 @@ yyreduce:
       if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){
         yymsg(1, "Warning Dilate OCC: Dilatation (second argument) + Translation (first argument) ");
         r = GModel::current()->getOCCInternals()->dilate
-                  (dimTags, (yyvsp[(3) - (9)].v)[0], (yyvsp[(3) - (9)].v)[1], (yyvsp[(3) - (9)].v)[2], (yyvsp[(5) - (9)].d), (yyvsp[(5) - (9)].d), (yyvsp[(5) - (9)].d));
+          (dimTags, (yyvsp[(3) - (9)].v)[0], (yyvsp[(3) - (9)].v)[1], (yyvsp[(3) - (9)].v)[2], (yyvsp[(5) - (9)].d), (yyvsp[(5) - (9)].d), (yyvsp[(5) - (9)].d));
       }
       else{
         r = GModel::current()->getGEOInternals()->dilate
@@ -8681,7 +8681,7 @@ yyreduce:
       if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){
         yymsg(1, "Warning Dilate OCC: Dilatation (second argument) + Translation (first argument) ");
         r = GModel::current()->getOCCInternals()->dilate
-                  (dimTags, (yyvsp[(3) - (9)].v)[0], (yyvsp[(3) - (9)].v)[1], (yyvsp[(3) - (9)].v)[2], (yyvsp[(5) - (9)].v)[0], (yyvsp[(5) - (9)].v)[1], (yyvsp[(5) - (9)].v)[2]);
+          (dimTags, (yyvsp[(3) - (9)].v)[0], (yyvsp[(3) - (9)].v)[1], (yyvsp[(3) - (9)].v)[2], (yyvsp[(5) - (9)].v)[0], (yyvsp[(5) - (9)].v)[1], (yyvsp[(5) - (9)].v)[2]);
       }
       else{
         r = GModel::current()->getGEOInternals()->dilate
diff --git a/Parser/Gmsh.y b/Parser/Gmsh.y
index 4be93093fe..f9a95a667d 100644
--- a/Parser/Gmsh.y
+++ b/Parser/Gmsh.y
@@ -2319,7 +2319,7 @@ Transform :
       if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){
         yymsg(1, "Warning Dilate OCC: Dilatation (second argument) + Translation (first argument) ");
         r = GModel::current()->getOCCInternals()->dilate
-                  (dimTags, $3[0], $3[1], $3[2], $5, $5, $5);
+          (dimTags, $3[0], $3[1], $3[2], $5, $5, $5);
       }
       else{
         r = GModel::current()->getGEOInternals()->dilate
@@ -2336,7 +2336,7 @@ Transform :
       if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){
         yymsg(1, "Warning Dilate OCC: Dilatation (second argument) + Translation (first argument) ");
         r = GModel::current()->getOCCInternals()->dilate
-                  (dimTags, $3[0], $3[1], $3[2], $5[0], $5[1], $5[2]);
+          (dimTags, $3[0], $3[1], $3[2], $5[0], $5[1], $5[2]);
       }
       else{
         r = GModel::current()->getGEOInternals()->dilate
-- 
GitLab