From: rraphael Date: Sun, 13 Dec 2020 13:44:54 +0000 (+0100) Subject: import image: add texture to transformations X-Git-Tag: V9_7_0a1~13^2~16 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4462c8acab55ab702986f63117666aa6dea3aa3c;p=modules%2Fshaper.git import image: add texture to transformations --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp index 1fb43b872..45796ddd3 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp @@ -166,8 +166,9 @@ void FeaturesPlugin_MultiRotation::performRotation1D() GeomAPI_ShapeHierarchy anObjects; std::list 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++); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp index bf8f9a06e..e9f29c0dd 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp @@ -91,8 +91,9 @@ void FeaturesPlugin_MultiTranslation::execute() GeomAPI_ShapeHierarchy anObjects; std::list aParts; + std::string theTextureFile; if (!FeaturesPlugin_Tools::shapesFromSelectionList( - anObjectsSelList, isKeepSubShapes, anObjects, aParts)) + anObjectsSelList, isKeepSubShapes, anObjects, aParts, theTextureFile)) return; std::shared_ptr 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++); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp index 248b0a1a6..fbda5b8f9 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp @@ -71,9 +71,10 @@ void FeaturesPlugin_Placement::execute() // Getting objects. GeomAPI_ShapeHierarchy anObjects; std::list 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++); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp index 61692d2bd..63ce379a4 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp @@ -184,9 +184,10 @@ void FeaturesPlugin_Rotation::performRotation(const GeomTrsfPtr& theTrsf) // Getting objects. GeomAPI_ShapeHierarchy anObjects; std::list 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++); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp b/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp index 91dabbe37..7992c7c81 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp @@ -92,9 +92,10 @@ void FeaturesPlugin_Scale::performScaleByFactor() // Getting objects. GeomAPI_ShapeHierarchy anObjects; std::list 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 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++); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp index f399746b0..6dce5b6c8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp @@ -203,12 +203,13 @@ GeomTrsfPtr FeaturesPlugin_Symmetry::symmetryByPlane() void FeaturesPlugin_Symmetry::buildResult( const std::shared_ptr& theAlgo, const std::list >& theOriginalShapes, - std::shared_ptr theTargetShape, int& theResultIndex) + std::shared_ptr 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 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); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.h b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.h index b0756ec56..da4392899 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.h @@ -137,7 +137,7 @@ private: void buildResult(const std::shared_ptr& theAlgo, const std::list >& theOriginalShapes, std::shared_ptr theTargetShape, - int& theResultIndex); + int& theResultIndex, std::string &theTextureFile); /// Create new result for the given part and transformation void buildResult(std::shared_ptr theOriginal, diff --git a/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp b/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp index 44068e383..29654258c 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp @@ -259,13 +259,35 @@ bool FeaturesPlugin_Tools::getShape(const AttributeSelectionListPtr theSelection } //================================================================================================== -bool FeaturesPlugin_Tools::shapesFromSelectionList( - const std::shared_ptr theSelectionList, +bool FeaturesPlugin_Tools::shapesFromSelectionList(const std::shared_ptr theSelectionList, const bool theStoreFullHierarchy, GeomAPI_ShapeHierarchy& theHierarchy, - std::list& theParts) + std::list& 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 anObject = anObjectAttr->value(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Tools.h b/src/FeaturesPlugin/FeaturesPlugin_Tools.h index 5b5a6d922..6f77dc4af 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Tools.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Tools.h @@ -69,7 +69,7 @@ public: const std::shared_ptr theSelectionList, const bool theStoreFullHierarchy, GeomAPI_ShapeHierarchy& theHierarchy, - std::list& theParts); + std::list& theParts, std::string& theTextureFile); }; #endif /* FeaturesPlugin_Tools_H_ */ diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp index 37695957d..c419d2ea8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp @@ -197,9 +197,10 @@ void FeaturesPlugin_Translation::performTranslation(const GeomTrsfPtr& theTrsf) // Getting objects. GeomAPI_ShapeHierarchy anObjects; std::list 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++); } diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index c58ed7b06..df4a8d4ce 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -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() { diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index fff856c5f..93b6a0ad6 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -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(); diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index a8b08adc6..92022cb2f 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -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; } diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index fc0fb74d4..e425d6a6b 100644 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -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; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index d867bf881..8f79985da 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -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(); + 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(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(); - 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(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); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 1cf8750e8..ced4f9325 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -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