Salome HOME
import image: add texture to transformations
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Tools.cpp
index c5f2f829d1135fb64864bd89901d508cba946818..29654258c11327eebcfccb74c40bcb8164674246 100644 (file)
@@ -31,6 +31,8 @@
 #include <GeomAPI_PlanarEdges.h>
 #include <GeomAPI_ShapeIterator.h>
 
+#include <GeomValidators_ShapeType.h>
+
 //==================================================================================================
 void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody,
                                               const ListOfShape& theBaseShapes,
@@ -92,6 +94,8 @@ void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody,
                                         GeomAPI_Shape::VERTEX,
                                         theName);
     }
+    default: // [to avoid compilation warning]
+      break;
   }
 }
 
@@ -199,15 +203,18 @@ bool FeaturesPlugin_Tools::getShape(const AttributeSelectionListPtr theSelection
         theError = "Error: Selected sketches does not have results.";
         return false;
       }
-      int aFacesNum = aConstruction->facesNum();
+      GeomValidators_ShapeType::TypeOfShape aSelType =
+          GeomValidators_ShapeType::shapeType(theSelectionList->selectionType());
+      int aFacesNum = 0;
+      if (aSelType != GeomValidators_ShapeType::Vertex &&
+          aSelType != GeomValidators_ShapeType::Edge)
+        aFacesNum = aConstruction->facesNum();
       if(aFacesNum == 0) {
         // Probably it can be construction.
         aBaseShape = aConstruction->shape();
         if(aBaseShape.get() && !aBaseShape->isNull()) {
           GeomAPI_Shape::ShapeType aST = aBaseShape->shapeType();
-          if(aST != GeomAPI_Shape::VERTEX && aST != GeomAPI_Shape::EDGE &&
-             aST != GeomAPI_Shape::WIRE &&
-             aST != GeomAPI_Shape::FACE && aST != GeomAPI_Shape::SHELL) {
+          if(aST == GeomAPI_Shape::SOLID || aST == GeomAPI_Shape::COMPSOLID) {
             theError = "Error: Selected shapes has unsupported type.";
             return false;
           }
@@ -252,13 +259,35 @@ bool FeaturesPlugin_Tools::getShape(const AttributeSelectionListPtr theSelection
 }
 
 //==================================================================================================
-bool FeaturesPlugin_Tools::shapesFromSelectionList(
-    const std::shared_ptr<ModelAPI_AttributeSelectionList> theSelectionList,
+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, std::string &theTextureFile)
 {
   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)
+      {
+        theTextureFile = aFeature->firstResult()->getTextureFile();
+      }
+      else
+      {
+        if(!aFeature.get())
+        {
+          auto aResult =  anObjectAttr->context();
+          if(aResult.get())
+          {
+            theTextureFile = aResult->getTextureFile();
+          }
+        }
+      }
+    }
+  }
   for (int anObjectsIndex = 0; anObjectsIndex < aSize; anObjectsIndex++) {
     AttributeSelectionPtr anObjectAttr = theSelectionList->value(anObjectsIndex);
     std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();