Salome HOME
Copyright update 2022
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Tools.cpp
index f436e8011ad637f9703efcc5e2d76c276a4bb993..ffaabc0200b71ee902f42dc6439bc853cc6631af 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  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
 
 #include <GeomValidators_ShapeType.h>
 
-//==================================================================================================
-void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody,
-                                              const ListOfShape& theBaseShapes,
-                                              const ListOfShape& theTools,
-                                              const GeomMakeShapePtr& theMakeShape,
-                                              const GeomShapePtr theResultShape,
-                                              const std::string& theNamePrefix)
-{
-  theResultBody->storeModified(theBaseShapes, theResultShape, theMakeShape);
-
-  ListOfShape aShapes = theBaseShapes;
-  ListOfShape::const_iterator aToolIter = theTools.cbegin();
-  for(; aToolIter != theTools.cend(); aToolIter++)
-    aShapes.push_back(*aToolIter);
-
-  for (ListOfShape::const_iterator anIter = aShapes.begin(); anIter != aShapes.end(); ++anIter)
-  {
-    theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::VERTEX, theNamePrefix);
-    theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::EDGE, theNamePrefix);
-    theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE, theNamePrefix);
-  }
-}
-
-//==================================================================================================
-void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody,
-                                              const GeomShapePtr& theBaseShape,
-                                              const GeomMakeShapePtr& theMakeShape,
-                                              const std::string theName)
-{
-  switch(theBaseShape->shapeType()) {
-    case GeomAPI_Shape::COMPOUND: {
-      for(GeomAPI_ShapeIterator anIt(theBaseShape); anIt.more(); anIt.next())
-      {
-        loadModifiedShapes(theResultBody,
-                           anIt.current(),
-                           theMakeShape,
-                           theName);
-      }
-      break;
-    }
-    case GeomAPI_Shape::COMPSOLID:
-    case GeomAPI_Shape::SOLID:
-    case GeomAPI_Shape::SHELL: {
-      theResultBody->loadModifiedShapes(theMakeShape,
-                                        theBaseShape,
-                                        GeomAPI_Shape::FACE,
-                                        theName);
-    }
-    case GeomAPI_Shape::FACE:
-    case GeomAPI_Shape::WIRE: {
-      theResultBody->loadModifiedShapes(theMakeShape,
-                                        theBaseShape,
-                                        GeomAPI_Shape::EDGE,
-                                        theName);
-    }
-    case GeomAPI_Shape::EDGE: {
-      theResultBody->loadModifiedShapes(theMakeShape,
-                                        theBaseShape,
-                                        GeomAPI_Shape::VERTEX,
-                                        theName);
-    }
-    default: // [to avoid compilation warning]
-      break;
-  }
-}
-
-//==================================================================================================
-void FeaturesPlugin_Tools::loadDeletedShapes(ResultBodyPtr theResultBody,
-  const GeomShapePtr theBaseShape,
-  const ListOfShape& theTools,
-  const GeomMakeShapePtr& theMakeShape,
-  const GeomShapePtr theResultShapesCompound)
-{
-  ListOfShape aShapes = theTools;
-  if (theBaseShape.get())
-    aShapes.push_front(theBaseShape);
-
-  for (ListOfShape::const_iterator anIter = aShapes.begin(); anIter != aShapes.end(); anIter++)
-  {
-    theResultBody->loadDeletedShapes(theMakeShape,
-                                     *anIter,
-                                     GeomAPI_Shape::VERTEX,
-                                     theResultShapesCompound);
-    theResultBody->loadDeletedShapes(theMakeShape,
-                                     *anIter,
-                                     GeomAPI_Shape::EDGE,
-                                     theResultShapesCompound);
-    theResultBody->loadDeletedShapes(theMakeShape,
-                                     *anIter,
-                                     GeomAPI_Shape::FACE,
-                                     theResultShapesCompound);
-    // store information about deleted solids because of unittest TestBooleanCommon_SolidsHistory
-    // on OCCT 7.4.0 : common produces modified compsolid, so, move to the end for removed solids
-    // starts to produce whole compsolid
-    theResultBody->loadDeletedShapes(theMakeShape,
-                                     *anIter,
-                                     GeomAPI_Shape::SOLID,
-                                     theResultShapesCompound);
-  }
-}
-
-//==================================================================================================
-void FeaturesPlugin_Tools::loadDeletedShapes(
-  std::vector<ResultBaseAlgo>& theResultBaseAlgoList,
-  const ListOfShape& theTools,
-  const GeomShapePtr theResultShapesCompound)
-{
-  for (std::vector<ResultBaseAlgo>::iterator anIt = theResultBaseAlgoList.begin();
-       anIt != theResultBaseAlgoList.end();
-       ++anIt)
-  {
-    ResultBaseAlgo& aRCA = *anIt;
-    loadDeletedShapes(aRCA.resultBody,
-                      aRCA.baseShape,
-                      theTools,
-                      aRCA.makeShape,
-                      theResultShapesCompound);
-  }
-}
-
 //==================================================================================================
 bool FeaturesPlugin_Tools::getShape(const AttributeSelectionListPtr theSelectionList,
                                     const bool theShareTopology,
@@ -263,9 +143,26 @@ bool FeaturesPlugin_Tools::shapesFromSelectionList(
     const std::shared_ptr<ModelAPI_AttributeSelectionList> theSelectionList,
     const bool theStoreFullHierarchy,
     GeomAPI_ShapeHierarchy& theHierarchy,
-    std::list<ResultPtr>& theParts)
+    std::list<ResultPtr>& theParts, ResultPtr& theTextureSource)
 {
   int aSize = theSelectionList->size();
+  if (aSize == 1) {
+    auto anObjectAttr = theSelectionList->value(0);
+    if (anObjectAttr.get()) {
+      FeaturePtr aFeature = anObjectAttr->contextFeature();
+      if (aFeature.get() && aFeature->results().size() == 1) {
+        theTextureSource = aFeature->firstResult();
+      }
+      else {
+        if (!aFeature.get()) {
+          auto aResult = anObjectAttr->context();
+          if (aResult.get()) {
+            theTextureSource = aResult;
+          }
+        }
+      }
+    }
+  }
   for (int anObjectsIndex = 0; anObjectsIndex < aSize; anObjectsIndex++) {
     AttributeSelectionPtr anObjectAttr = theSelectionList->value(anObjectsIndex);
     std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();