From 1ffcd9300536d0d92a807fca109b1f133eba02a0 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 20 Jun 2022 13:03:24 +0300 Subject: [PATCH] Fixed the problem of imported color of higher level STEP shape. --- src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp | 11 ++++++++++- src/Model/Model_ResultBody.cpp | 9 +++++++++ src/Model/Model_ResultBody.h | 7 +++++-- src/ModelAPI/ModelAPI_ResultBody.h | 11 ++++++++--- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index 91c6c188a..e73ccfbe3 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -214,7 +214,7 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) setColorGroups(aResult); } - // create Materiel group + // create Material group if (anMaterialsGroupSelected){ setMaterielGroup(aResult,theMaterialShape); } @@ -628,6 +628,15 @@ void ExchangePlugin_ImportFeatureBase::loadNamingDS( //load result theResultBody->store(theGeomShape); + // to store color of higher-level shape + std::wstring aName = theResultBody->findShapeName(theGeomShape); + if (!aName.empty()) + { + std::vector aColor = theResultBody->findShapeColor(aName); + if (!aColor.empty()) + ModelAPI_Tools::setColor(theResultBody, aColor); + } + std::string aNameMS = "Shape"; theResultBody->loadFirstLevel(theGeomShape, aNameMS); } diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 5cbc3e419..96f2aad2e 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -281,6 +281,15 @@ std::wstring Model_ResultBody::findShapeName(std::shared_ptr theS return L"material not found" ; } +const std::vector& Model_ResultBody::findShapeColor(const std::wstring& theShapeName) +{ + std::map >::iterator aColor = myColorsShape.find(theShapeName); + if (aColor != myColorsShape.end()) + return aColor->second; + static std::vector anEmptyVector; + return anEmptyVector; +} + void Model_ResultBody::setShapeName( std::map< std::wstring, std::shared_ptr>& theShapeName, std::map< std::wstring, std::vector>& theColorsShape) diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index 467eaebec..b6b88af23 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -119,6 +119,9 @@ public: /// sets the texture file MODEL_EXPORT virtual bool hasTexture() override; + /// Find the imported color by the construction name of a shape. + /// Returns empty vector if not found. + MODEL_EXPORT virtual const std::vector& findShapeColor(const std::wstring& theShapeName); protected: /// Makes a body on the given feature @@ -154,7 +157,7 @@ protected: std::map< std::wstring, std::vector>& theColorsShape) override; - /// find the name of shapp read in step file + /// Find the name of shape read in step file std::wstring findShapeName(std::shared_ptr theShape) override; /// Clear the map of name and color read shape in step file @@ -163,7 +166,7 @@ protected: /// map with the name read in step file and shape std::map< std::wstring, std::shared_ptr > myNamesShape; - /// map with the name contruct and color read + /// map from the construction name to the imported color std::map< std::wstring, std::vector> myColorsShape; }; diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index f0263d41f..b6c0e126f 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -194,11 +194,11 @@ public: /// Add shape Name for read shape in step file MODELAPI_EXPORT virtual std::wstring addShapeName - (std::shared_ptr,const std::wstring& theName) = 0; + (std::shared_ptr, const std::wstring& theName) = 0; /// Add color for shape Name read shape in step file MODELAPI_EXPORT virtual void addShapeColor - (const std::wstring& theName,std::vector& theColor) = 0; + (const std::wstring& theName, std::vector& theColor) = 0; /// Set the map of name and color read shape in step file MODELAPI_EXPORT virtual void setShapeName @@ -208,9 +208,14 @@ public: /// Clear the map of name and color read shape in step file MODELAPI_EXPORT virtual void clearShapeNameAndColor() = 0; - /// find the name of shapp read in step file + /// Find the name of shape read in step file MODELAPI_EXPORT virtual std::wstring findShapeName(std::shared_ptr theShape) = 0; + /// Find the imported color by the construction name of a shape. + /// Returns empty vector if not found. + MODELAPI_EXPORT virtual const std::vector& findShapeColor( + const std::wstring& theShapeName) = 0; + protected: /// Default constructor accessible only from Model_Objects -- 2.39.2