From 18fa69be33a69e0ed59b6d790c00b8c9297ad49d Mon Sep 17 00:00:00 2001 From: asozinov Date: Mon, 15 Apr 2024 15:16:10 +0100 Subject: [PATCH] current state --- .../ExchangePlugin_ImportFeature.cpp | 12 ++++++ src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp | 5 +++ src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h | 2 + .../GeomAlgoAPI_STEPImportXCAF.cpp | 41 +++++++++++++++---- src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h | 1 + src/Model/Model_ResultBody.cpp | 11 ++++- 6 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index cb40214a6..4e70bd86e 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -67,6 +67,7 @@ #include +#include #include /* @@ -237,6 +238,10 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) // Pass the results into the model loadNamingDS(aGeomShape, aResult); + if (aResult->shape().get()) + std::cout << "5 YES\n"; + else + std::cout << "5 NO\n"; // create color group if (anColorGroupSelected) @@ -250,6 +255,7 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) } setResult(aResult); + aResult->clearShapeNameAndColor(); } @@ -670,6 +676,7 @@ void ExchangePlugin_ImportFeatureBase::loadNamingDS( std::shared_ptr theResultBody) { //load result + auto ashape = theResultBody->shape(); theResultBody->store(theGeomShape); // to store color of higher-level shape @@ -683,6 +690,11 @@ void ExchangePlugin_ImportFeatureBase::loadNamingDS( std::string aNameMS = "Shape"; theResultBody->loadFirstLevel(theGeomShape, aNameMS); + + // Block for set colors + { + //TEST(theResultBody); + } } void ExchangePlugin_Import_ImageFeature::importFile(const std::string& theFileName) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp index ae8038066..99b9fdab1 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp @@ -268,3 +268,8 @@ GeomShapePtr STEPImportAttributs(const std::string& theFileName, return STEPImport(theFileName, "", theScalInterUnits, theError); } } + +void TEST(std::shared_ptr theResultBody) +{ + setColors(theResultBody); +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h index f20b6b9a0..a54897648 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h @@ -46,4 +46,6 @@ GeomShapePtr STEPImportAttributs(const std::string& theFileName, std::list>& theMaterialShape, std::string& theError); +GEOMALGOAPI_EXPORT +void TEST(std::shared_ptr theResultBody); #endif /* GEOMALGOAPI_STEPIMPORT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp index bb44bb7a0..b8b6021be 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp @@ -170,6 +170,32 @@ std::shared_ptr readAttributes(STEPCAFControl_Reader &theReader, return ageom; } +void setColors(std::shared_ptr theResultBody) +{ + TopoDS_Shape aShape = theResultBody->shape()->impl(); + TopExp_Explorer anExp(aShape, TopAbs_SOLID); + while (anExp.More()) + { + auto aFace = anExp.Current(); + + std::shared_ptr aGeomShape(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape(aFace)); + auto aName = theResultBody->findShapeName(aGeomShape); + + if (!aName.empty()) + { + auto aColor = theResultBody->findShapeColor(aName); + + if (!aColor.empty()) + theResultBody->setSubShapeColor(theResultBody, aGeomShape, { 128, 222, 2 }); + else + theResultBody->setSubShapeColor(theResultBody, aGeomShape, { 255, 0, 0 }); + + } + anExp.Next(); + } +} + //============================================================================= std::shared_ptr setGeom(const Handle(XCAFDoc_ShapeTool) &theShapeTool, const TDF_Label& /*theLabel*/, @@ -315,15 +341,16 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool, theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorSurf, aCol) || theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorCurv, aCol)) { double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue(); - TopoDS_Face aFace = TopoDS::Face(aXp2.Current()); - std::vector aColRGB = {int(aR*255),int(aG*255),int(aB*255)}; - std::wstringstream aNameFace; + //TopoDS_Face aFace = TopoDS::Face(aXp2.Current()); + std::vector aColRGB = { int(aR * 255),int(aG * 255),int(aB * 255) }; + std::wstring aNameFace; TopoDS_Shape aShapeface = aXp2.Current(); - if (!theLoc.IsIdentity()){ - aShapeface.Move(theLoc); + if (!theLoc.IsIdentity()) { + aShapeface.Move(theLoc); } - aShapeGeom->setImpl(new TopoDS_Shape(aShapeface)); - theResultBody->addShapeColor(theResultBody->addShapeName(aShapeGeom, aNameFace.str()), aColRGB); + std::shared_ptr aFaceGeom(new GeomAPI_Shape); + aFaceGeom->setImpl(new TopoDS_Shape(aShapeface)); + theResultBody->addShapeColor(theResultBody->addShapeName(aFaceGeom, aNameFace), aColRGB); } aXp2.Next(); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h index a0bed29e4..d8674a696 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h @@ -33,4 +33,5 @@ std::shared_ptr readAttributes(STEPCAFControl_Reader &theReader, std::map< std::wstring,std::list> &theMaterialShape, std::string& theError); +GEOMALGOAPI_EXPORT void setColors(std::shared_ptr theResultBody); #endif /* GEOMALGOAPI_STEPIMPORTXCAF_H_ */ diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 52869c664..9b1459445 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -43,6 +43,8 @@ #include #include +#include + // if this attribute exists, the shape is connected topology Standard_GUID kIsConnectedTopology("e51392e0-3a4d-405d-8e36-bbfe19858ef5"); // if this attribute exists, the connected topology flag must be recomputed @@ -323,7 +325,7 @@ std::wstring Model_ResultBody::addShapeName(std::shared_ptr thesh int indice = 1; std::wstringstream aName; aName << theName; -#if 1 +#if 0 while (myNamesShape.find(aName.str()) != myNamesShape.end()) { #else while (aName.str().empty() || myNamesShape.find(aName.str()) != myNamesShape.end()) { @@ -497,9 +499,14 @@ void Model_ResultBody::updateSubs(const std::shared_ptr& theThisS } /// if (!aName.empty()) { - const std::vector &aColor = findShapeColor(aName); + const std::vector& aColor = findShapeColor(aName); + std::vector aColor2 = {}; if (!aColor.empty()) { ModelAPI_Tools::setColor(anOwner, aGeomFace, aColor); + ModelAPI_Tools::getColor(anOwner, aGeomFace, aColor2); + //std::cout << std::endl << aColor[0] << " " << aColor[1] << " " << aColor[2] << std::endl; + //if (!aColor2.empty()) + // std::cout << aColor2[0] << " " << aColor2[1] << " " << aColor2[2] << std::endl; } } } -- 2.39.2