]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
current state
authorasozinov <alexey.sozinov@opencascade.com>
Mon, 15 Apr 2024 14:16:10 +0000 (15:16 +0100)
committermbs <martin.bernhard@opencascade.com>
Thu, 6 Jun 2024 15:01:00 +0000 (16:01 +0100)
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h
src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp
src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h
src/Model/Model_ResultBody.cpp

index cb40214a6f78e6b0dd81000aaac8f07604d7f85b..4e70bd86eeb5506fcacdd443f5106e800721e532 100644 (file)
@@ -67,6 +67,7 @@
 
 #include <ExchangePlugin_Tools.h>
 
+#include <iostream>
 #include <QPixmap>
 
 /*
@@ -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<ModelAPI_ResultBody> 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)
index ae8038066a96450c9d1cb87237ae9c9bcf768683..99b9fdab1f9ead947505bde4d2376d805d05dd64 100644 (file)
@@ -268,3 +268,8 @@ GeomShapePtr STEPImportAttributs(const std::string& theFileName,
     return STEPImport(theFileName, "", theScalInterUnits, theError);
   }
 }
+
+void TEST(std::shared_ptr<ModelAPI_ResultBody> theResultBody)
+{
+  setColors(theResultBody);
+}
index f20b6b9a03ba7ad400cad9d7c6669c338d4ee524..a54897648ff56ea48065dfc845c12787b0742f7c 100644 (file)
@@ -46,4 +46,6 @@ GeomShapePtr  STEPImportAttributs(const std::string& theFileName,
                                   std::list<std::wstring>>& theMaterialShape,
                                   std::string& theError);
 
+GEOMALGOAPI_EXPORT
+void TEST(std::shared_ptr<ModelAPI_ResultBody> theResultBody);
 #endif /* GEOMALGOAPI_STEPIMPORT_H_ */
index bb44bb7a0cf65cde3fd8777410cd69fc59c7c855..b8b6021be3d88883721e9dfe5ccb0addd1ccb0a6 100644 (file)
@@ -170,6 +170,32 @@ std::shared_ptr<GeomAPI_Shape> readAttributes(STEPCAFControl_Reader &theReader,
   return ageom;
 }
 
+void setColors(std::shared_ptr<ModelAPI_ResultBody> theResultBody)
+{
+  TopoDS_Shape aShape = theResultBody->shape()->impl<TopoDS_Shape>();
+  TopExp_Explorer anExp(aShape, TopAbs_SOLID);
+  while (anExp.More())
+  {
+    auto aFace = anExp.Current();
+
+    std::shared_ptr<GeomAPI_Shape> 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<GeomAPI_Shape> 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<int> aColRGB = {int(aR*255),int(aG*255),int(aB*255)};
-          std::wstringstream aNameFace;
+          //TopoDS_Face aFace = TopoDS::Face(aXp2.Current());
+          std::vector<int> 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<GeomAPI_Shape> aFaceGeom(new GeomAPI_Shape);
+          aFaceGeom->setImpl(new TopoDS_Shape(aShapeface));
+          theResultBody->addShapeColor(theResultBody->addShapeName(aFaceGeom, aNameFace), aColRGB);
         }
         aXp2.Next();
       }
index a0bed29e4de93cf2f8dad96fa3d4f0c1fd0fbec1..d8674a6966c0cfba6fe4588e371bc1e7e00f2fc7 100644 (file)
@@ -33,4 +33,5 @@ std::shared_ptr<GeomAPI_Shape>  readAttributes(STEPCAFControl_Reader &theReader,
                                  std::map< std::wstring,std::list<std::wstring>> &theMaterialShape,
                                  std::string& theError);
 
+GEOMALGOAPI_EXPORT void setColors(std::shared_ptr<ModelAPI_ResultBody> theResultBody);
 #endif /* GEOMALGOAPI_STEPIMPORTXCAF_H_ */
index 52869c664a394db83003ff2ae80d103df7887210..9b1459445501695bf0139ab6fab709370f86c0ea 100644 (file)
@@ -43,6 +43,8 @@
 #include <TNaming_Tool.hxx>
 #include <TDF_Reference.hxx>
 
+#include <BRepTools.hxx>
+
 // 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<GeomAPI_Shape> 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<GeomAPI_Shape>& theThisS
         }
         ///
         if (!aName.empty()) {
-          const std::vector<int> &aColor = findShapeColor(aName);
+          const std::vector<int>& aColor = findShapeColor(aName);
+          std::vector<int> 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;
           }
         }
       }