Salome HOME
CEA : Lot2 - Normal to a face
[modules/shaper.git] / src / Model / Model_ResultPart.cpp
index 7c42dd987e0148edfc40ce12a2d3d543fe67f00f..61e6ed2ea69580c780a68a443f52db98a2345160 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -189,6 +189,26 @@ bool Model_ResultPart::setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
   return false;
 }
 
+static GeomShapePtr transformShape(const GeomShapePtr theShape, const gp_Trsf& theTrsf)
+{
+  GeomShapePtr aResult(new GeomAPI_Shape);
+  if (theTrsf.ScaleFactor() > 0) {
+    // just update the location of the shape in case of affine transformation
+    TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+    if (!aShape.IsNull()) {
+      aShape.Move(theTrsf);
+      aResult->setImpl(new TopoDS_Shape(aShape));
+    }
+  }
+  else {
+    // all other transformations will modify the shape
+    GeomTrsfPtr aTrsf = std::make_shared<GeomAPI_Trsf>(new gp_Trsf(theTrsf));
+    GeomAlgoAPI_Transform aTransform(theShape, aTrsf);
+    aResult = aTransform.shape();
+  }
+  return aResult;
+}
+
 std::shared_ptr<GeomAPI_Shape> Model_ResultPart::shape()
 {
   std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
@@ -199,9 +219,7 @@ std::shared_ptr<GeomAPI_Shape> Model_ResultPart::shape()
       ResultPtr anOrigResult = baseRef();
       std::shared_ptr<GeomAPI_Shape> anOrigShape = anOrigResult->shape();
       if (anOrigShape.get()) {
-        GeomTrsfPtr aTrsf = std::make_shared<GeomAPI_Trsf>(new gp_Trsf(*myTrsf));
-        GeomAlgoAPI_Transform aTransform(anOrigShape, aTrsf);
-        aResult = aTransform.shape();
+        aResult = transformShape(anOrigShape, *myTrsf);
         myShape = aResult->impl<TopoDS_Shape>();
       }
       if (!myShape.IsNull() && aToSendUpdate) {