]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
import image: add texture to transformations
authorrraphael <raphael.raphael@c-s.fr>
Sun, 13 Dec 2020 13:44:54 +0000 (14:44 +0100)
committerrraphael <raphael.raphael@c-s.fr>
Fri, 15 Jan 2021 11:10:10 +0000 (12:10 +0100)
16 files changed:
src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp
src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp
src/FeaturesPlugin/FeaturesPlugin_Placement.cpp
src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp
src/FeaturesPlugin/FeaturesPlugin_Scale.cpp
src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp
src/FeaturesPlugin/FeaturesPlugin_Symmetry.h
src/FeaturesPlugin/FeaturesPlugin_Tools.cpp
src/FeaturesPlugin/FeaturesPlugin_Tools.h
src/FeaturesPlugin/FeaturesPlugin_Translation.cpp
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/ModelAPI/ModelAPI_Object.h
src/PartSet/PartSet_CustomPrs.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h

index 1fb43b872ddbf0d637044f839517126340c6ec0d..45796ddd3cb8196ec5c24dad88f471e2d8d82216 100644 (file)
@@ -166,8 +166,9 @@ void FeaturesPlugin_MultiRotation::performRotation1D()
 
   GeomAPI_ShapeHierarchy anObjects;
   std::list<ResultPtr> aParts;
+  std::string theTextureFile;
   if (!FeaturesPlugin_Tools::shapesFromSelectionList(
-       anObjectsSelList, isKeepSubShapes, anObjects, aParts))
+       anObjectsSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
     return;
 
   // Parameters of rotation.
@@ -224,6 +225,7 @@ void FeaturesPlugin_MultiRotation::performRotation1D()
     ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
     FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
                                              aMakeShapeList, *anIt, "Rotated");
+    aResultBody->setTextureFile(theTextureFile);
     setResult(aResultBody, aResultIndex++);
   }
 
index bf8f9a06e237cd6910f2af883cfe3d5e32c5f0a5..e9f29c0ddb3d93e2dec222d7ba34a4dcb054dd58 100644 (file)
@@ -91,8 +91,9 @@ void FeaturesPlugin_MultiTranslation::execute()
 
   GeomAPI_ShapeHierarchy anObjects;
   std::list<ResultPtr> aParts;
+  std::string theTextureFile;
   if (!FeaturesPlugin_Tools::shapesFromSelectionList(
-       anObjectsSelList, isKeepSubShapes, anObjects, aParts))
+       anObjectsSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
     return;
 
   std::shared_ptr<GeomAPI_Dir> aFirstDir, aSecondDir;
@@ -170,6 +171,7 @@ void FeaturesPlugin_MultiTranslation::execute()
     ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
     FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
                                              aMakeShapeList, *anIt, "Translated");
+    aResultBody->setTextureFile(theTextureFile);
     setResult(aResultBody, aResultIndex++);
   }
 
index 248b0a1a6877cad8ca287bc7ef2abafa0ffc9a97..fbda5b8f9a7c8c7f920d6f13d4acf7999479fce7 100644 (file)
@@ -71,9 +71,10 @@ void FeaturesPlugin_Placement::execute()
   // Getting objects.
   GeomAPI_ShapeHierarchy anObjects;
   std::list<ResultPtr> aParts;
+  std::string theTextureFile;
   AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECTS_LIST_ID());
   if (!FeaturesPlugin_Tools::shapesFromSelectionList(
-       anObjectsSelList, isKeepSubShapes, anObjects, aParts))
+       anObjectsSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
     return;
 
   // Verify the start shape
@@ -180,6 +181,7 @@ void FeaturesPlugin_Placement::execute()
     ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
     FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
                                              aMakeShapeList, *anIt, "Placed");
+    aResultBody->setTextureFile(theTextureFile);
     setResult(aResultBody, aResultIndex++);
   }
 
index 61692d2bd2ed2653e843745d4ba7f94a05dcbf27..63ce379a4de4eed68ccde6ba4561a405ce91930c 100644 (file)
@@ -184,9 +184,10 @@ void FeaturesPlugin_Rotation::performRotation(const GeomTrsfPtr& theTrsf)
   // Getting objects.
   GeomAPI_ShapeHierarchy anObjects;
   std::list<ResultPtr> aParts;
+  std::string theTextureFile;
   AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID());
   if (!FeaturesPlugin_Tools::shapesFromSelectionList(
-       anObjSelList, isKeepSubShapes, anObjects, aParts))
+       anObjSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
     return;
 
   std::string anError;
@@ -225,6 +226,7 @@ void FeaturesPlugin_Rotation::performRotation(const GeomTrsfPtr& theTrsf)
     ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
     FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
                                              aMakeShapeList, *anIt, "Rotated");
+    aResultBody->setTextureFile(theTextureFile);
     setResult(aResultBody, aResultIndex++);
   }
 
index 91dabbe379d7e361bb82ecc04db7bbdd5089d4b7..7992c7c81817e585a6cccadc792c057819fc5946 100644 (file)
@@ -92,9 +92,10 @@ void FeaturesPlugin_Scale::performScaleByFactor()
   // Getting objects.
   GeomAPI_ShapeHierarchy anObjects;
   std::list<ResultPtr> aParts;
+  std::string theTextureFile;
   AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID());
   if (!FeaturesPlugin_Tools::shapesFromSelectionList(
-       anObjSelList, isKeepSubShapes, anObjects, aParts))
+       anObjSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
     return;
 
   // Getting the center point
@@ -142,6 +143,7 @@ void FeaturesPlugin_Scale::performScaleByFactor()
     ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
     FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
                                              aMakeShapeList, *anIt, "Scaled");
+    aResultBody->setTextureFile(theTextureFile);
     setResult(aResultBody, aResultIndex++);
   }
 
@@ -157,9 +159,10 @@ void FeaturesPlugin_Scale::performScaleByDimensions()
   // Getting objects.
   GeomAPI_ShapeHierarchy anObjects;
   std::list<ResultPtr> aParts;
+  std::string theTextureFile;
   AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID());
   if (!FeaturesPlugin_Tools::shapesFromSelectionList(
-       anObjSelList, isKeepSubShapes, anObjects, aParts))
+       anObjSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
     return;
 
   // Getting the center point
@@ -212,6 +215,7 @@ void FeaturesPlugin_Scale::performScaleByDimensions()
     ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
     FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
                                              aMakeShapeList, *anIt, "Scaled");
+    aResultBody->setTextureFile(theTextureFile);
     setResult(aResultBody, aResultIndex++);
   }
 
index f399746b0ed662e359ed8f9cb63c1dd9efc546a2..6dce5b6c8d459c7101fe1f4b080ec1e42352f9f7 100644 (file)
@@ -203,12 +203,13 @@ GeomTrsfPtr FeaturesPlugin_Symmetry::symmetryByPlane()
 void FeaturesPlugin_Symmetry::buildResult(
     const std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theAlgo,
     const std::list<std::shared_ptr<GeomAPI_Shape> >& theOriginalShapes,
-    std::shared_ptr<GeomAPI_Shape> theTargetShape, int& theResultIndex)
+    std::shared_ptr<GeomAPI_Shape> theTargetShape, int& theResultIndex, std::string & theTextureFile)
 {
   // Store and name the result.
   ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex);
   FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, theOriginalShapes, ListOfShape(),
                                            theAlgo, theTargetShape, "Symmetried");
+  aResultBody->setTextureFile(theTextureFile);
   setResult(aResultBody, theResultIndex++);
 }
 
@@ -279,9 +280,10 @@ void FeaturesPlugin_Symmetry::performSymmetry(GeomTrsfPtr theTrsf)
   // Getting objects.
   GeomAPI_ShapeHierarchy anObjects;
   std::list<ResultPtr> aParts;
+  std::string theTextureFile;
   AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID());
   if (!FeaturesPlugin_Tools::shapesFromSelectionList(
-       anObjSelList, isKeepSubShapes, anObjects, aParts))
+       anObjSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
     return;
 
   std::string anError;
@@ -309,7 +311,7 @@ void FeaturesPlugin_Symmetry::performSymmetry(GeomTrsfPtr theTrsf)
   ListOfShape aTopLevel;
   anObjects.topLevelObjects(aTopLevel);
   for (ListOfShape::iterator anIt = aTopLevel.begin(); anIt != aTopLevel.end(); ++anIt)
-    buildResult(aMakeShapeList, anOriginalShapes, *anIt, aResultIndex);
+    buildResult(aMakeShapeList, anOriginalShapes, *anIt, aResultIndex, theTextureFile);
 
   // Remove the rest results if there were produced in the previous pass.
   removeResults(aResultIndex);
index b0756ec56db352af0f19b38b0620c5fa27228eb1..da43928993ccf1ec746b2b87395b2f80dcf02182 100644 (file)
@@ -137,7 +137,7 @@ private:
   void buildResult(const std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theAlgo,
                    const std::list<std::shared_ptr<GeomAPI_Shape> >& theOriginalShapes,
                    std::shared_ptr<GeomAPI_Shape> theTargetShape,
-                   int& theResultIndex);
+                   int& theResultIndex, std::string &theTextureFile);
 
   /// Create new result for the given part and transformation
   void buildResult(std::shared_ptr<ModelAPI_ResultPart> theOriginal,
index 44068e38394423c0a93d4a1e7e1f83fd2a6e05d4..29654258c11327eebcfccb74c40bcb8164674246 100644 (file)
@@ -259,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();
index 5b5a6d9222faf4787b72866477e74dbfda96ea14..6f77dc4af00f7f0a2969b81b9fd6b657b6fa9b26 100644 (file)
@@ -69,7 +69,7 @@ public:
       const std::shared_ptr<ModelAPI_AttributeSelectionList> theSelectionList,
       const bool theStoreFullHierarchy,
       GeomAPI_ShapeHierarchy& theHierarchy,
-      std::list<ResultPtr>& theParts);
+      std::list<ResultPtr>& theParts, std::string& theTextureFile);
 };
 
 #endif /* FeaturesPlugin_Tools_H_ */
index 37695957df3b59afc4133ca34f8c025ccc7895cd..c419d2ea8dea16cf706fd5cc2fc4900bbe2d38e9 100644 (file)
@@ -197,9 +197,10 @@ void FeaturesPlugin_Translation::performTranslation(const GeomTrsfPtr& theTrsf)
   // Getting objects.
   GeomAPI_ShapeHierarchy anObjects;
   std::list<ResultPtr> aParts;
+  std::string theTextureFile;
   AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECTS_LIST_ID());
   if (!FeaturesPlugin_Tools::shapesFromSelectionList(
-       anObjectsSelList, isKeepSubShapes, anObjects, aParts))
+       anObjectsSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
     return;
 
   std::string anError;
@@ -240,6 +241,7 @@ void FeaturesPlugin_Translation::performTranslation(const GeomTrsfPtr& theTrsf)
     ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
     FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
                                              aMakeShapeList, *anIt, "Translated");
+    aResultBody->setTextureFile(theTextureFile);
     setResult(aResultBody, aResultIndex++);
   }
 
index c58ed7b065c3ed05a6826cc93ef713979d03dfe5..df4a8d4cec647453c266121c4ee274987a07bef0 100644 (file)
@@ -408,6 +408,16 @@ void Model_ResultBody::updateSubs(
   myHistoryCash.Clear();
 }
 
+void  Model_ResultBody::setTextureFile(const std::string & theTextureFile)
+{
+  ModelAPI_Result::setTextureFile(theTextureFile);
+  for( auto sub : mySubs){
+    sub->setTextureFile(theTextureFile);
+  }
+  for(auto map : mySubsMap){
+    map.first->setTextureFile(theTextureFile);
+  }
+}
 
 bool Model_ResultBody::isConnectedTopology()
 {
index fff856c5ff1fa9aa6632e312b0fcbe2a80b1cf4b..93b6a0ad63a5c23ca2a124a9ac8658d33959df7f 100644 (file)
@@ -113,6 +113,10 @@ public:
   /// Cleans cash related to the already stored elements
   MODEL_EXPORT virtual void cleanCash() override;
 
+  /// sets the texture file
+  MODEL_EXPORT virtual void  setTextureFile(const std::string & theTextureFile) override;
+
+
 protected:
   /// Makes a body on the given feature
   Model_ResultBody();
index a8b08adc6020fcb80fe61d24be15e6b42b935f85..92022cb2f1722eceb6c4f177392e7571e02a40a4 100644 (file)
@@ -106,7 +106,7 @@ class ModelAPI_Object: public ModelAPI_Entity
     return (textureFile != "");
   }
 
-  MODELAPI_EXPORT void setTextureFile(const std::string & theTextureFile)
+  MODELAPI_EXPORT virtual void setTextureFile(const std::string & theTextureFile)
   {
     textureFile = theTextureFile;
   }
index fc0fb74d4e1088e4f02c78698dbe5de81a8d95aa..e425d6a6be8cbed60aa64d81cda7440731a8fa0d 100644 (file)
@@ -171,6 +171,10 @@ bool PartSet_CustomPrs::displayPresentation(
       isModified = true;
     }
     else {
+      if (myFeature->firstResult().get() && myFeature->firstResult()->hasTextureFile())
+      {
+        PartSet_Module::setTexture( myFeature->firstResult()->getTextureFile(), aPresentation);
+      }
       anOperationPrs->Redisplay();
       isModified = true;
       aRedisplayed = true;
index d867bf881ff171e24164a97668e0430062abc963..8f79985da4975fab68bec9d75d03bbdb5808805b 100644 (file)
@@ -1421,6 +1421,46 @@ double getResultTransparency(const ResultPtr& theResult)
 }
 
 
+//******************************************************
+void PartSet_Module::setTexture(const std::string & theTextureFile, const AISObjectPtr& thePrs)
+{
+  Handle(AIS_InteractiveObject) anAIS = thePrs->impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull())
+  {
+    /// set color to white and change material aspect,
+    /// in order to keep a natural apect of the image.
+    thePrs->setColor(255, 255, 255);
+    Quantity_Color myShadingColor(NCollection_Vec3<float>(1.,  1., 1.));
+    Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+    if (!anAISShape.IsNull())
+    {
+      auto myDrawer = anAISShape->Attributes();
+
+      myDrawer->ShadingAspect()->SetColor(myShadingColor);
+      myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
+      Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
+      aMatAspect.SetTransparency(0.0);
+      myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
+      myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
+
+      Handle(Image_PixMap) aPixmap;
+      QPixmap px(theTextureFile.c_str());
+
+      if (!px.isNull() )
+        aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage());
+
+      anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap
+          (new Graphic3d_Texture2Dmanual(aPixmap));
+      anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
+
+      anAISShape->SetDisplayMode(AIS_Shaded);
+    }
+  }
+
+}
+
+
+
 //******************************************************
 void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
                                            const AISObjectPtr& thePrs) const
@@ -1452,38 +1492,7 @@ void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
       /// set texture  parameters
       if(aResult->hasTextureFile())
       {
-        Handle(AIS_InteractiveObject) anAIS = thePrs->impl<Handle(AIS_InteractiveObject)>();
-        if (!anAIS.IsNull())
-        {
-          /// set color to white and change material aspect,
-          /// in order to keep a natural apect of the image.
-          thePrs->setColor(255, 255, 255);
-          Quantity_Color myShadingColor(NCollection_Vec3<float>(1.,  1., 1.));
-          Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
-          if (!anAISShape.IsNull())
-          {
-            auto myDrawer = anAISShape->Attributes();
-
-            myDrawer->ShadingAspect()->SetColor(myShadingColor);
-            myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
-            Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
-            aMatAspect.SetTransparency(0.0);
-            myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
-            myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
-
-            Handle(Image_PixMap) aPixmap;
-            QPixmap px(aResult->getTextureFile().c_str());
-
-            if (!px.isNull() )
-              aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage());
-
-            anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap
-                (new Graphic3d_Texture2Dmanual(aPixmap));
-            anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
-
-            anAISShape->SetDisplayMode(AIS_Shaded);
-          }
-        }
+        setTexture(aResult->getTextureFile(), thePrs);
       }
     }
     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
index 1cf8750e8847b55dea908c16928949a9bc450862..ced4f93256dc95690016f6cf4c369507e7fd6982 100644 (file)
@@ -399,6 +399,9 @@ public:
   /// Reads description of features from XML file
   virtual void createFeatures();
 
+  /// add texture
+  PARTSET_EXPORT static void setTexture(const std::string &theTextureFile, const AISObjectPtr& thePrs);
+
 public slots:
   /// Slolt called on object display
   /// \param theObject a data object