Salome HOME
add Picture import
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index d9648b56e5c585b514c19a3813ed039fcaf2b2fa..64b63156be7cad4c15df08ccbea2c19cf2b807b1 100644 (file)
 #include <GeomDataAPI_Dir.h>
 
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+#include <Graphic3d_Texture2Dmanual.hxx>
+#include <OCCViewer_Utilities.h>
+
 
 #define FEATURE_ITEM_COLOR "0,0,225"
 
@@ -1445,6 +1448,41 @@ void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
       thePrs->setDeflection(getResultDeflection(aResult));
 
       thePrs->setTransparency(getResultTransparency(aResult));
+
+      /// set texture  parameters
+      if(aResult->hasTextureFile())
+      {
+        Handle(AIS_InteractiveObject) anAIS = thePrs->impl<Handle(AIS_InteractiveObject)>();
+        if (!anAIS.IsNull())
+        {
+          std::vector<int> aColor = {167, 167, 167 };
+          thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+          Quantity_Color myShadingColor(NCollection_Vec3<float>(aColor[0]/255.,  aColor[1]/255., aColor[2]/255.));
+
+          Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+          if (!anAISShape.IsNull())
+          {
+            auto myDrawer = new Prs3d_ShadingAspect();
+            if (!anAISShape->Attributes()->HasOwnShadingAspect())
+            {
+              anAISShape->Attributes()->SetShadingAspect (myDrawer);
+            }
+
+            myDrawer->SetColor(myShadingColor);
+
+            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);
+          }
+        }
+      }
     }
     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
     if (aFeature.get()) {