Salome HOME
Fix for the issue #2693 : groups in error after loading dump (3-holes plate)
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Translation.cpp
index 4e7dcef66a9b08d3b02e39bc27c658b8bd79e7ef..19ec3564ae804999dd42963d2851767990d137e9 100644 (file)
@@ -1,10 +1,22 @@
-// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
-
-// File:        FeaturesPlugin_Translation.cpp
-// Created:     8 June 2015
-// Author:      Dmitry Bobylev
+// Copyright (C) 2014-2017  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// 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<mailto:webmaster.salome@opencascade.com>
 //
-// Modified by Clarisse Genrault (CEA) : 17 Nov 2016
 
 #include <FeaturesPlugin_Translation.h>
 
@@ -18,6 +30,7 @@
 
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Lin.h>
+#include <GeomAPI_Trsf.h>
 
 #include <GeomAlgoAPI_PointBuilder.h>
 
@@ -123,7 +136,7 @@ void FeaturesPlugin_Translation::performTranslationByAxisAndDistance()
   for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
         anObjectsIt++, aContext++) {
     std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
-    bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
+    bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group();
 
     // Setting result.
     if (isPart) {
@@ -134,34 +147,39 @@ void FeaturesPlugin_Translation::performTranslationByAxisAndDistance()
       aResultPart->setTrsf(*aContext, aTrsf);
       setResult(aResultPart, aResultIndex);
     } else {
-      GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, anAxis, aDistance);
+      std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgo(
+        new GeomAlgoAPI_Translation(aBaseShape, anAxis, aDistance));
 
-      if (!aTranslationAlgo.check()) {
-        setError(aTranslationAlgo.getError());
+      if (!aTranslationAlgo->check()) {
+        setError(aTranslationAlgo->getError());
         return;
       }
 
-      aTranslationAlgo.build();
+      aTranslationAlgo->build();
 
       // Checking that the algorithm worked properly.
-      if(!aTranslationAlgo.isDone()) {
+      if(!aTranslationAlgo->isDone()) {
         static const std::string aFeatureError = "Error: Translation algorithm failed.";
         setError(aFeatureError);
         break;
       }
-      if(aTranslationAlgo.shape()->isNull()) {
+      if(aTranslationAlgo->shape()->isNull()) {
         static const std::string aShapeError = "Error: Resulting shape is Null.";
         setError(aShapeError);
         break;
       }
-      if(!aTranslationAlgo.isValid()) {
+      if(!aTranslationAlgo->isValid()) {
         std::string aFeatureError = "Error: Resulting shape is not valid.";
         setError(aFeatureError);
         break;
       }
 
       ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      loadNamingDS(aTranslationAlgo, aResultBody, aBaseShape);
+      aResultBody->storeModified(aBaseShape, aTranslationAlgo->shape());
+      FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
+                                               aBaseShape,
+                                               aTranslationAlgo,
+                                               "Translated");
       setResult(aResultBody, aResultIndex);
     }
     aResultIndex++;
@@ -205,7 +223,7 @@ void FeaturesPlugin_Translation::performTranslationByDimensions()
   for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
         anObjectsIt++, aContext++) {
     std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
-    bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
+    bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group();
 
     // Setting result.
     if (isPart) {
@@ -216,34 +234,39 @@ void FeaturesPlugin_Translation::performTranslationByDimensions()
       aResultPart->setTrsf(*aContext, aTrsf);
       setResult(aResultPart, aResultIndex);
     } else {
-      GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, aDX, aDY, aDZ);
+      std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgo(
+        new GeomAlgoAPI_Translation(aBaseShape, aDX, aDY, aDZ));
 
-      if (!aTranslationAlgo.check()) {
-        setError(aTranslationAlgo.getError());
+      if (!aTranslationAlgo->check()) {
+        setError(aTranslationAlgo->getError());
         return;
       }
 
-      aTranslationAlgo.build();
+      aTranslationAlgo->build();
 
       // Checking that the algorithm worked properly.
-      if(!aTranslationAlgo.isDone()) {
+      if(!aTranslationAlgo->isDone()) {
         static const std::string aFeatureError = "Error: Translation algorithm failed.";
         setError(aFeatureError);
         break;
       }
-      if(aTranslationAlgo.shape()->isNull()) {
+      if(aTranslationAlgo->shape()->isNull()) {
         static const std::string aShapeError = "Error: Resulting shape is Null.";
         setError(aShapeError);
         break;
       }
-      if(!aTranslationAlgo.isValid()) {
+      if(!aTranslationAlgo->isValid()) {
         std::string aFeatureError = "Error: Resulting shape is not valid.";
         setError(aFeatureError);
         break;
       }
 
       ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      loadNamingDS(aTranslationAlgo, aResultBody, aBaseShape);
+      aResultBody->storeModified(aBaseShape, aTranslationAlgo->shape());
+      FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
+                                               aBaseShape,
+                                               aTranslationAlgo,
+                                               "Translated");
       setResult(aResultBody, aResultIndex);
     }
     aResultIndex++;
@@ -300,7 +323,7 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints()
   for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
         anObjectsIt++, aContext++) {
     std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
-    bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
+    bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group();
 
     // Setting result.
     if (isPart) {
@@ -311,34 +334,39 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints()
       aResultPart->setTrsf(*aContext, aTrsf);
       setResult(aResultPart, aResultIndex);
     } else {
-      GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, aFirstPoint, aSecondPoint);
+      std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgo(
+        new GeomAlgoAPI_Translation(aBaseShape, aFirstPoint, aSecondPoint));
 
-      if (!aTranslationAlgo.check()) {
-        setError(aTranslationAlgo.getError());
+      if (!aTranslationAlgo->check()) {
+        setError(aTranslationAlgo->getError());
         return;
       }
 
-      aTranslationAlgo.build();
+      aTranslationAlgo->build();
 
       // Checking that the algorithm worked properly.
-      if(!aTranslationAlgo.isDone()) {
+      if(!aTranslationAlgo->isDone()) {
         static const std::string aFeatureError = "Error: Translation algorithm failed.";
         setError(aFeatureError);
         break;
       }
-      if(aTranslationAlgo.shape()->isNull()) {
+      if(aTranslationAlgo->shape()->isNull()) {
         static const std::string aShapeError = "Error: Resulting shape is Null.";
         setError(aShapeError);
         break;
       }
-      if(!aTranslationAlgo.isValid()) {
+      if(!aTranslationAlgo->isValid()) {
         std::string aFeatureError = "Error: Resulting shape is not valid.";
         setError(aFeatureError);
         break;
       }
 
       ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      loadNamingDS(aTranslationAlgo, aResultBody, aBaseShape);
+      aResultBody->storeModified(aBaseShape, aTranslationAlgo->shape());
+      FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
+                                               aBaseShape,
+                                               aTranslationAlgo,
+                                               "Translated");
       setResult(aResultBody, aResultIndex);
     }
     aResultIndex++;
@@ -347,20 +375,3 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints()
   // Remove the rest results if there were produced in the previous pass.
   removeResults(aResultIndex);
 }
-
-//=================================================================================================
-void FeaturesPlugin_Translation::loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo,
-                                              std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-                                              std::shared_ptr<GeomAPI_Shape> theBaseShape)
-{
-  // Store result.
-  theResultBody->storeModified(theBaseShape, theTranslationAlgo.shape());
-
-  int aTranslatedTag = 1;
-  std::string aTranslatedName = "Translated";
-  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theTranslationAlgo.mapOfSubShapes();
-
-  FeaturesPlugin_Tools::storeModifiedShapes(theTranslationAlgo, theResultBody,
-                                            theBaseShape, aTranslatedTag, aTranslatedName,
-                                            *aSubShapes.get());
-}