Salome HOME
Fix for the issue #2693 : groups in error after loading dump (3-holes plate)
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Rotation.cpp
index 27b1b859161cfc7f921d12b39b9a49bad5d2c2c2..f9a11c5c6ac156b1a8c39dbcb62485c48c0836a5 100755 (executable)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        FeaturesPlugin_Rotation.cpp
-// Created:     12 May 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>
+//
 
 #include <FeaturesPlugin_Rotation.h>
 
@@ -109,7 +123,7 @@ void FeaturesPlugin_Rotation::performTranslationByAxisAndAngle()
   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) {
@@ -120,34 +134,37 @@ void FeaturesPlugin_Rotation::performTranslationByAxisAndAngle()
       aResultPart->setTrsf(*aContext, aTrsf);
       setResult(aResultPart, aResultIndex);
     } else {
-      GeomAlgoAPI_Rotation aRotationAlgo(aBaseShape, anAxis, anAngle);
+      std::shared_ptr<GeomAlgoAPI_Rotation> aRotationAlgo(new GeomAlgoAPI_Rotation(aBaseShape,
+                                                                                   anAxis,
+                                                                                   anAngle));
 
-      if (!aRotationAlgo.check()) {
-        setError(aRotationAlgo.getError());
+      if (!aRotationAlgo->check()) {
+        setError(aRotationAlgo->getError());
         return;
       }
 
-      aRotationAlgo.build();
+      aRotationAlgo->build();
 
       // Checking that the algorithm worked properly.
-      if(!aRotationAlgo.isDone()) {
+      if(!aRotationAlgo->isDone()) {
         static const std::string aFeatureError = "Error: Rotation algorithm failed.";
         setError(aFeatureError);
         break;
       }
-      if(aRotationAlgo.shape()->isNull()) {
+      if(aRotationAlgo->shape()->isNull()) {
         static const std::string aShapeError = "Error: Resulting shape is Null.";
         setError(aShapeError);
         break;
       }
-      if(!aRotationAlgo.isValid()) {
+      if(!aRotationAlgo->isValid()) {
         std::string aFeatureError = "Error: Resulting shape is not valid.";
         setError(aFeatureError);
         break;
       }
 
       ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      loadNamingDS(aRotationAlgo, aResultBody, aBaseShape);
+      aResultBody->storeModified(aBaseShape, aRotationAlgo->shape());
+      FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, aBaseShape, aRotationAlgo, "Rotated");
       setResult(aResultBody, aResultIndex);
     }
     aResultIndex++;
@@ -224,52 +241,40 @@ void FeaturesPlugin_Rotation::performTranslationByThreePoints()
        aResultPart->setTrsf(*aContext, aTrsf);
        setResult(aResultPart, aResultIndex);
     } else {
-      GeomAlgoAPI_Rotation aRotationAlgo(aBaseShape, aCenterPoint, aStartPoint, anEndPoint);
+      std::shared_ptr<GeomAlgoAPI_Rotation> aRotationAlgo(new GeomAlgoAPI_Rotation(aBaseShape,
+                                                                                   aCenterPoint,
+                                                                                   aStartPoint,
+                                                                                   anEndPoint));
 
-      if (!aRotationAlgo.check()) {
-        setError(aRotationAlgo.getError());
+      if (!aRotationAlgo->check()) {
+        setError(aRotationAlgo->getError());
         return;
       }
 
-      aRotationAlgo.build();
+      aRotationAlgo->build();
 
       // Checking that the algorithm worked properly.
-      if(!aRotationAlgo.isDone()) {
+      if(!aRotationAlgo->isDone()) {
         static const std::string aFeatureError = "Error: Rotation algorithm failed.";
         setError(aFeatureError);
         break;
       }
-      if(aRotationAlgo.shape()->isNull()) {
+      if(aRotationAlgo->shape()->isNull()) {
         static const std::string aShapeError = "Error : Resulting shape is Null.";
         setError(aShapeError);
         break;
       }
-      if(!aRotationAlgo.isValid()) {
+      if(!aRotationAlgo->isValid()) {
         std::string aFeatureError = "Error: Resulting shape is not valid.";
         setError(aFeatureError);
         break;
       }
 
       ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      loadNamingDS(aRotationAlgo, aResultBody, aBaseShape);
+      aResultBody->storeModified(aBaseShape, aRotationAlgo->shape());
+      FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, aBaseShape, aRotationAlgo, "Rotated");
       setResult(aResultBody, aResultIndex);
     }
     aResultIndex++;
   }
 }
-
-//=================================================================================================
-void FeaturesPlugin_Rotation::loadNamingDS(GeomAlgoAPI_Rotation& theRotaionAlgo,
-                                           std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-                                           std::shared_ptr<GeomAPI_Shape> theBaseShape)
-{
-  // Store result.
-  theResultBody->storeModified(theBaseShape, theRotaionAlgo.shape());
-
-  std::string aRotatedName = "Rotated";
-  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theRotaionAlgo.mapOfSubShapes();
-
-  FeaturesPlugin_Tools::storeModifiedShapes(theRotaionAlgo, theResultBody,
-                                            theBaseShape, 1, 2, 3, aRotatedName,
-                                            *aSubShapes.get());
-}