Salome HOME
Merge commit 'f709219506b7cd587e94abc5ebed18d629df92d8'
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_ImportFeature.cpp
index e077e4ca78a81465938ea4da770a33147170b212..e73ccfbe3070d78754b669ca7b8234a6e55029ab 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -168,19 +168,16 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
   data()->setName(Locale::Convert::toWString(anObjectName));
 
   ResultBodyPtr aResult = document()->createBody(data());
-
-  bool anColorGroupSelected = boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())->value();
-  bool anMaterialsGroupSelected =
-                        boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())->value();
+  bool anColorGroupSelected = false, anMaterialsGroupSelected = false;
   if (anExtension == "BREP" || anExtension == "BRP") {
     aGeomShape = BREPImport(theFileName, anExtension, anError);
   } else if (anExtension == "STEP" || anExtension == "STP") {
-    bool anScalInterUnits =
-            boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())->value();
+    bool anScalInterUnits = boolean(STEP_SCALE_INTER_UNITS_ID())->value();
+    anColorGroupSelected = boolean(STEP_COLORS_ID())->value();
+    anMaterialsGroupSelected = boolean(STEP_MATERIALS_ID())->value();
 
     // Process groups/fields
-    std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
-    std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
+    AttributeRefListPtr aRefListOfGroups = reflist(FEATURES_ID());
 
     // Remove previous groups/fields stored in RefList
     std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
@@ -217,7 +214,7 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
     setColorGroups(aResult);
   }
 
-  // create Materiel group
+  // create Material group
   if (anMaterialsGroupSelected){
     setMaterielGroup(aResult,theMaterialShape);
   }
@@ -341,10 +338,10 @@ void ExchangePlugin_ImportFeature::setMaterielGroup(
         if (aRes->get() && ((*aRes)->data()->name() == (*aResMat)))
         {
           if (aShape->isCompound() || aShape->isCompSolid()) {
-            GeomAPI_ShapeIterator anIt(aShape);
-            for (; anIt.more(); anIt.next()) {
-              aSelectionList->setSelectionType(anIt.current()->shapeTypeStr());
-              aSelectionList->append(theResultBody,anIt.current());
+            GeomAPI_ShapeIterator aShapeIt(aShape);
+            for (; aShapeIt.more(); aShapeIt.next()) {
+              aSelectionList->setSelectionType(aShapeIt.current()->shapeTypeStr());
+              aSelectionList->append(theResultBody, aShapeIt.current());
             }
           } else {
             aSelectionList->setSelectionType(aShape->shapeTypeStr());
@@ -631,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<int> aColor = theResultBody->findShapeColor(aName);
+    if (!aColor.empty())
+      ModelAPI_Tools::setColor(theResultBody, aColor);
+  }
+
   std::string aNameMS = "Shape";
   theResultBody->loadFirstLevel(theGeomShape, aNameMS);
 }