Salome HOME
updated copyright message
[modules/shaper.git] / src / Model / Model_ResultPart.cpp
index 01d7ef900e78482cef0e320e097372a5f39ce653..6f459abc37062d77ee2de542b7b4f5f59485fb08 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -18,6 +18,7 @@
 //
 
 #include <Model_ResultPart.h>
+
 #include <ModelAPI_Data.h>
 #include <Model_Data.h>
 #include <ModelAPI_AttributeDocRef.h>
@@ -36,6 +37,8 @@
 
 #include <GeomAPI_Trsf.h>
 
+#include <GeomAlgoAPI_Transform.h>
+
 #include <Locale_Convert.h>
 
 #include <TNaming_Tool.hxx>
@@ -45,6 +48,8 @@
 #include <BRep_Builder.hxx>
 #include <TopExp_Explorer.hxx>
 
+#include <Basics_OCCTVersion.hxx>
+
 #define baseRef() \
   std::dynamic_pointer_cast<Model_ResultPart>(data()->reference(BASE_REF_ID())->value())
 
@@ -187,6 +192,30 @@ 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()) {
+#if OCC_VERSION_LARGE < 0x07070000
+      aShape.Move(theTrsf);
+#else
+      aShape.Move(theTrsf, Standard_False);
+#endif
+      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);
@@ -197,12 +226,8 @@ std::shared_ptr<GeomAPI_Shape> Model_ResultPart::shape()
       ResultPtr anOrigResult = baseRef();
       std::shared_ptr<GeomAPI_Shape> anOrigShape = anOrigResult->shape();
       if (anOrigShape.get()) {
-        TopoDS_Shape aShape = anOrigShape->impl<TopoDS_Shape>();
-        if (!aShape.IsNull()) {
-          aShape.Move(*(myTrsf.get()));
-          myShape = aShape;
-          aResult->setImpl(new TopoDS_Shape(aShape));
-        }
+        aResult = transformShape(anOrigShape, *myTrsf);
+        myShape = aResult->impl<TopoDS_Shape>();
       }
       if (!myShape.IsNull() && aToSendUpdate) {
         static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
@@ -271,7 +296,11 @@ std::wstring Model_ResultPart::nameInPart(const std::shared_ptr<GeomAPI_Shape>&
       TopExp_Explorer anExp(anOrigMain, aSelection.ShapeType());
       for(; anExp.More(); anExp.Next()) {
         if (anExp.Current().IsPartner(aSelection)) {
+#if OCC_VERSION_LARGE < 0x07070000
           TopoDS_Shape anOrigMoved = anExp.Current().Moved(*(myTrsf.get()));
+#else
+          TopoDS_Shape anOrigMoved = anExp.Current().Moved(*(myTrsf.get()), Standard_False);
+#endif
           //if (anOrigMoved.IsSame(aSelection)) {
           if (IsEqualTrsf(aSelTrsf, anOrigMoved.Location().Transformation())) {
             std::shared_ptr<GeomAPI_Shape> anOrigSel(new GeomAPI_Shape);
@@ -391,7 +420,11 @@ std::shared_ptr<GeomAPI_Shape> Model_ResultPart::shapeInPart(
   aResult = aSelAttr->value(theIndex - 1)->value();
   if (myTrsf.get() && aResult.get() && !aResult->isNull()) {
     gp_Trsf aSumTrsf = sumTrsf();
+#if OCC_VERSION_LARGE < 0x07070000
     TopoDS_Shape anOrigMoved = aResult->impl<TopoDS_Shape>().Moved(aSumTrsf);
+#else
+    TopoDS_Shape anOrigMoved = aResult->impl<TopoDS_Shape>().Moved(aSumTrsf, Standard_False);
+#endif
     aResult->setImpl(new TopoDS_Shape(anOrigMoved));
   }
   return aResult;
@@ -408,7 +441,11 @@ std::shared_ptr<GeomAPI_Shape> Model_ResultPart::selectionValue(const int theInd
   aResult = aSelAttr->value(theIndex - 1)->value();
   if (myTrsf.get() && aResult.get() && !aResult->isNull()) {
     gp_Trsf aSumTrsf = sumTrsf();
+#if OCC_VERSION_LARGE < 0x07070000
     TopoDS_Shape anOrigMoved = aResult->impl<TopoDS_Shape>().Moved(aSumTrsf);
+#else
+    TopoDS_Shape anOrigMoved = aResult->impl<TopoDS_Shape>().Moved(aSumTrsf, Standard_False);
+#endif
     aResult->setImpl(new TopoDS_Shape(anOrigMoved));
   }
   return aResult;