]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Set colors on subshape:
authorasozinov <alexey.sozinov@opencascade.com>
Fri, 17 Feb 2023 00:16:09 +0000 (01:16 +0100)
committerasozinov <alexey.sozinov@opencascade.com>
Fri, 1 Mar 2024 13:52:52 +0000 (13:52 +0000)
- Added: Added ability to assign colors on subshape of shape. This work for Part and for PartSet
- Modified Python dump: can dump colored objects to python script:
  For object inside part: Cylinder_1.result().setColor(model.selection("FACE", "Cylinder_1_1/Face_2"), 85, 170, 0)
  For PartSet:            Part_1.result().setColor(model.selection("FACE", "Part_1/Sphere_1_1/Face_1"), 249, 225, 104)
- In Preferences -> Shaper -> Visualization: Added checkbox for enable/disable this functionality - Set color on subshape of result

36 files changed:
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportFeature.h
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.h
src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_Objects.cpp
src/Model/Model_Objects.h
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/Model/Model_ResultPart.cpp
src/Model/Model_ResultPart.h
src/ModelAPI/ModelAPI_Data.h
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_ResultBody.h
src/ModelAPI/ModelAPI_ResultPart.h
src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Tools.h
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/ModelHighAPI/ModelHighAPI_Selection.cpp
src/ModelHighAPI/ModelHighAPI_Selection.h
src/ModuleBase/ModuleBase_ISelection.h
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/ModuleBase/ModuleBase_msg_fr.ts
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Selection.cpp
src/XGUI/XGUI_Selection.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 3924fb73376db6af1bb9c53a4f193fc5a8c5b807..d4cefa983b3159d5454cc85448f0a80167ca06c6 100644 (file)
@@ -214,6 +214,9 @@ void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
   } else if (aFormatName == "STL") {
     exportSTL(theFileName);
     return;
+  }else if (aFormatName == "STEP") {
+    exportSTEP(theFileName);
+    return;
   }
 
   // make shape for export from selected shapes
@@ -249,10 +252,11 @@ void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
   bool aResult = false;
   if (aFormatName == "BREP") {
     aResult = BREPExport(theFileName, aFormatName, aShape, anError);
-  } else if (aFormatName == "STEP") {
-    aResult = STEPExport(theFileName, aShapes, aContexts, anError);
   } else if (aFormatName.substr(0, 4) == "IGES") {
     aResult = IGESExport(theFileName, aFormatName, aShape, anError);
+  } else if (aFormatName == "STEP")
+  {
+    //aResult = STEPExport(theFileName, aFormatName, aShape, anError);
   } else {
     anError = "Unsupported format: " + aFormatName;
   }
@@ -622,6 +626,49 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName,
 // LCOV_EXCL_STOP
 }
 
+void ExchangePlugin_ExportFeature::exportSTEP(const std::string & theFileName)
+{
+  AttributeSelectionListPtr aSelectionList =
+    selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
+
+  std::list<GeomShapePtr> aShapeList;
+  std::string anError;
+  std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+  for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex)
+  {
+    AttributeSelectionPtr anAttrSelection = aSelectionList->value(anIndex);
+    std::shared_ptr<GeomAPI_Shape> aCurShape = anAttrSelection->value();
+    if (!aCurShape.get())
+       aCurShape = anAttrSelection->context()->shape();
+    if (!aCurShape.get())
+       continue;
+    #ifndef HAVE_SALOME
+    ResultPtr aRes = anAttrSelection->context();
+    std::vector<int> aColor;
+    ModelAPI_Tools::getColor(aRes, aColor);
+    ModelAPI_Tools::getColoredShapes(aRes, aColoredShapes);
+    if (aColor.size() == 3)
+    {
+      aColoredShapes[aCurShape] = aColor;
+    }
+    #endif
+      aShapeList.push_back(aCurShape);
+    }
+  std::shared_ptr<GeomAPI_Shape> aShape =
+    aShapeList.size() == 1 ? aShapeList.front() : GeomAlgoAPI_CompoundBuilder::compound(aShapeList);
+  #ifndef HAVE_SALOME
+    bool aRes = true;// STEPExport(theFileName, aShape, aColoredShapes, anError);
+  #else
+    bool aRes = true;// STEPExport(theFileName, "STEP", aShape, anError);
+  #endif
+
+  if (!anError.empty() || !aRes)
+  {
+    setError("An error occurred while exporting " + theFileName + ": " + anError);
+    return;
+    }
+  }
+
 bool ExchangePlugin_ExportFeature::isMacro() const
 {
   if (!data().get() || !data()->isValid())
index a3f6fb6518c9b66ef30e5b7b778a487d4237cabb..7be361c03df3cc879067cff2d9818fcb6a6fd472 100644 (file)
@@ -201,6 +201,9 @@ protected:
 
   /// Performs export to STL file
   EXCHANGEPLUGIN_EXPORT void exportSTL(const std::string& theFileName);
+
+  /// Performs export to STEP file
+  EXCHANGEPLUGIN_EXPORT void exportSTEP(const std::string & theFileName);
 };
 
 #endif /* EXPORT_EXPORTFEATURE_H_ */
index fba0ed2ff85ca17e1c3844a3e949605b9cd8956a..3d18fb85e4766b2a51f57c3697892e9f24438033 100644 (file)
@@ -32,6 +32,7 @@
 #include <Quantity_NameOfColor.hxx>
 #include <BRepBndLib.hxx>
 
+#include <AIS_ColoredShape.hxx>
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_Shape.hxx>
@@ -387,6 +388,19 @@ bool GeomAPI_AISObject::setColor(int theR, int theG, int theB)
   return true;
 }
 
+bool GeomAPI_AISObject::setColor(const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+  int theR, int theG, int theB)
+{
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (anAIS.IsNull())
+    return false;
+  Quantity_Color aColor(theR / 255., theG / 255., theB / 255., Quantity_TOC_RGB);
+
+  Handle(AIS_ColoredShape) aShape = Handle(AIS_ColoredShape)::DownCast(anAIS);
+  aShape->SetCustomColor(theSubShape->impl<TopoDS_Shape>(), aColor);
+  return true;
+}
+
 void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB)
 {
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
index 2812845b3952ca9d77cc73074a760d6a0634a66e..7e9bd574251b25491cc0f8443abe80c64ace398c 100644 (file)
@@ -127,6 +127,16 @@ class GeomAPI_AISObject : public GeomAPI_Interface
   GEOMAPI_EXPORT
   bool setColor(int theR, int theG, int theB);
 
+  /** \brief Assigns the color for the subshape
+   *  \param[in] theSubShape subshape that belongs to shape
+   *  \param[in] theR value of the red component
+   *  \param[in] theG value of the green component
+   *  \param[in] theB value of the blue component
+  */
+  GEOMAPI_EXPORT
+    bool setColor(const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+      int theR, int theG, int theB);
+
   /** \brief Returns the color for the shape
    *  \param[in] theR value of the red component
    *  \param[in] theG value of the green component
index c3686dffd8273252a044488f2018ecfc45bca318..c779eaeb4c8667dd2b68844ad64805fd54d9b3fa 100644 (file)
@@ -33,6 +33,8 @@
 #include <STEPCAFControl_Writer.hxx>
 #include <Interface_Static.hxx>
 #include <Quantity_Color.hxx>
+#include <XSControl_WorkSession.hxx>
+#include <TopExp_Explorer.hxx>
 
 #include <Basics_OCCTVersion.hxx>
 
@@ -172,3 +174,146 @@ bool STEPExport(const std::string& theFileName,
   }
   return theError.empty();
 }
+
+bool STEPExport(const std::string& theFileName,
+  const std::shared_ptr<GeomAPI_Shape>& theShape,
+  std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes,
+  std::string& theError)
+{
+  Handle(TDocStd_Document) aDoc = new TDocStd_Document("MDTV-CAF");
+#ifdef _DEBUG
+  std::cout << "Export STEP into file " << theFileName << std::endl;
+#endif
+  GeomAlgoAPI_Tools::Localizer loc;
+
+  Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession();
+  STEPCAFControl_Writer aWriter(aWS, false);
+  aWriter.SetColorMode(true);
+  aWriter.SetNameMode(true);
+
+  IFSelect_ReturnStatus aStatus;
+  //VRV: OCC 4.0 migration
+  Interface_Static::SetCVal("xstep.cascade.unit", "M");
+  Interface_Static::SetCVal("write.step.unit", "M");
+  Interface_Static::SetIVal("write.step.nonmanifold", 1);
+
+  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+  Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
+  Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
+
+  TDF_Label aShapeLabel = aShapeTool->AddShape(aShape, false);
+  TDF_Label aRefShapeLab;
+  if (aShapeTool->GetReferredShape(aShapeLabel, aRefShapeLab))
+    aShapeLabel = aRefShapeLab;
+
+  if (theColoredShapes.find(theShape) != theColoredShapes.end())
+  {
+    std::vector<int> aColor = theColoredShapes.find(theShape)->second;
+    Quantity_Color aQColor(aColor[0] / 255.,
+      aColor[1] / 255.,
+      aColor[2] / 255.,
+      Quantity_TOC_RGB);
+    aColorTool->SetColor(aShapeLabel, aQColor, XCAFDoc_ColorGen);
+    theColoredShapes.erase(theShape);
+  }
+
+  for (std::map<GeomShapePtr, std::vector<int>>::iterator anIter(theColoredShapes.begin());
+    anIter != theColoredShapes.end(); ++anIter)
+  {
+    TopoDS_Shape aSubShape = (anIter->first)->impl<TopoDS_Shape>();
+    if (aSubShape.IsNull())
+      continue;
+    bool sub = theShape->isSubShape(anIter->first);
+    Quantity_Color aColor(anIter->second.at(0) / 255.,
+      anIter->second.at(1) / 255.,
+      anIter->second.at(2) / 255.,
+      Quantity_TOC_RGB);
+    TDF_Label aSubShapeLabel;
+    aShapeTool->Search(aShape, aSubShapeLabel);
+    if (!aSubShapeLabel.IsNull())
+    {
+      aColorTool->SetColor(aSubShapeLabel, aColor, XCAFDoc_ColorSurf);
+    }
+  }
+  /*for (TopExp_Explorer aFaceExp(aShape, TopAbs_FACE); aFaceExp.More(); aFaceExp.Next())
+  {
+    TDF_Label aSubShapeLabel;
+    std::shared_ptr<GeomAPI_Shape> aFace(new GeomAPI_Shape);
+    aFace->setImpl(new TopoDS_Shape(aFaceExp.Value()));
+    if (theColoredShapes.find(theShape) == theColoredShapes.end())
+      continue;
+    aShapeTool->Search(aFaceExp.Value(), aSubShapeLabel);
+    if (!aSubShapeLabel.IsNull())
+    {
+      std::vector<int> aColor = theColoredShapes.find(theShape)->second;
+      Quantity_Color aQColor(aColor[0] / 255.,
+                             aColor[1] / 255.,
+                             aColor[2] / 255.,
+                             Quantity_TOC_RGB);
+      aColorTool->SetColor(aSubShapeLabel, aQColor, XCAFDoc_ColorSurf);
+    }
+  }*/
+  /*for (std::map<GeomShapePtr, std::vector<int>>::const_iterator anIter(theColoredShapes.cbegin());
+       anIter != theColoredShapes.cend(); ++anIter)
+  {
+    TopoDS_Shape aSubShape = (anIter->first)->impl<TopoDS_Shape>();
+    if (aSubShape.IsNull())
+      continue;
+    bool sub = theShape->isSubShape(anIter->first);
+    Quantity_Color aColor(anIter->second.at(0) / 255.,
+                          anIter->second.at(1) / 255.,
+                          anIter->second.at(2) / 255.,
+                          Quantity_TOC_RGB);
+    //TDF_Label aColorLabel = aColorTool->AddColor(aColor);
+    TDF_Label aSubShapeLabel = aShape.IsEqual(aSubShape) ?
+      aShapeLabel : aShapeTool->AddSubShape(aShapeLabel, aSubShape);
+    aColorTool->SetColor(aSubShapeLabel, aColor,
+                         aShape.IsEqual(aSubShape) ? XCAFDoc_ColorGen : XCAFDoc_ColorSurf);
+  }*/
+
+  /////////////////
+  TDF_LabelSequence aLabels;
+  aColorTool->GetColors(aLabels);
+  Standard_Integer i, nbc = aLabels.Length();
+  for (i = 1; i <= nbc; ++i)
+  {
+    Quantity_Color aColorQ;
+    TDF_Label aLabel = aLabels.Value(i);
+    aColorTool->GetColor(aLabel, aColorQ);
+    int a = 0;
+  }
+  TDF_LabelSequence aShapesL;
+  aShapeTool->GetFreeShapes(aShapesL);
+  nbc = aShapesL.Length();
+  for (i = 1; i <= nbc; ++i)
+  {
+    Quantity_Color aColorR;
+    TDF_LabelSequence aSubShapesL;
+    TopoDS_Shape aShape2;
+    aShapeTool->GetShape(aShapesL.Value(i), aShape2);
+    TDF_Label aShapeLabel = aShapeTool->FindShape(aShape2);
+    aColorTool->GetColor(aShapeLabel, XCAFDoc_ColorGen, aColorR);
+    aShapeTool->GetSubShapes(aShapesL.Value(i), aSubShapesL);
+    for (TDF_LabelSequence::Iterator aLabIt(aSubShapesL); aLabIt.More(); aLabIt.Next())
+    {
+      const TDF_Label& aSubShapeLab = aLabIt.Value();
+      TopoDS_Shape aSubShape = aShapeTool->GetShape(aSubShapeLab);
+      aColorTool->GetColor(aSubShapeLab, XCAFDoc_ColorSurf, aColorR);
+    }
+  }
+  /////////////////////
+  bool aaaaaa = aWriter.GetColorMode();
+  if (!aWriter.Transfer(aDoc, STEPControl_AsIs))
+  {
+    theError = "Error: Failed transfer to file.";
+    return false;
+  }
+  aStatus = aWriter.Write(theFileName.c_str());
+  if (aStatus != IFSelect_RetDone)
+  {
+
+    theError = "Error: Failed write to file.";
+    return false;
+  }
+  return true;
+}
index d56d7d083deef91f529c3e9226711abceec4ec8a..ca6edab4db4570ff7f1395b9cba8938c1ed19152 100644 (file)
@@ -23,6 +23,8 @@
 #include <GeomAlgoAPI.h>
 
 #include <string>
+#include <map>
+#include <vector>
 #include <list>
 #include <memory>
 
@@ -38,4 +40,10 @@ bool STEPExport(const std::string& theFileName,
                 const std::list<std::shared_ptr<ModelAPI_Result> >& theResults,
                 std::string& theError);
 
+GEOMALGOAPI_EXPORT
+bool STEPExport(const std::string& theFileName,
+                const std::shared_ptr<GeomAPI_Shape>& theShape,
+                std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes,
+                std::string& theError);
+
 #endif /* GEOMALGOAPI_STEPEXPORT_H_ */
index f6dc6595d8422883d6f170dc4727a4cf9261c0a1..714625517a03413700e336c709401c2fd13985f7 100644 (file)
@@ -111,6 +111,33 @@ std::shared_ptr<GeomAPI_Shape> readAttributes(STEPCAFControl_Reader &theReader,
   Handle_XCAFDoc_ShapeTool shapeTool = XCAFDoc_DocumentTool::ShapeTool(mainLabel);
   Handle_XCAFDoc_ColorTool colorTool = XCAFDoc_DocumentTool::ColorTool(mainLabel);
   Handle(XCAFDoc_MaterialTool) materialTool = XCAFDoc_DocumentTool::MaterialTool(mainLabel);
+  TDF_LabelSequence aLabels, aLabelSS;
+  colorTool->GetColors(aLabels);
+  Standard_Integer i, nbc = aLabels.Length();
+  for (i = 1; i <= nbc; ++i)
+  {
+    Quantity_Color aColorQ;
+    TDF_Label aLabel = aLabels.Value(i);
+    colorTool->GetColor(aLabel, aColorQ);
+    int a = 0;
+  }
+  shapeTool->GetShapes(aLabels);
+  Quantity_Color aColorR;
+  for (TDF_LabelSequence::Iterator aLabIt(aLabels); aLabIt.More(); aLabIt.Next())
+  {
+    const TDF_Label& aShapeLabel = aLabIt.Value();
+    TopoDS_Shape aSubShape = shapeTool->GetShape(aShapeLabel);
+    shapeTool->GetSubShapes(aShapeLabel, aLabelSS);
+    colorTool->GetColor(aShapeLabel, XCAFDoc_ColorGen, aColorR);
+    for (TDF_LabelSequence::Iterator aLabIt2(aLabelSS); aLabIt2.More(); aLabIt2.Next())
+    {
+      const TDF_Label& aSubShapeLab = aLabIt.Value();
+      TopoDS_Shape aSubShape = shapeTool->GetShape(aSubShapeLab);
+      colorTool->GetColor(aSubShapeLab, XCAFDoc_ColorSurf, aColorR);
+    }
+
+  }
+
   // traverse the labels recursively to set attributes on shapes
   setShapeAttributes(shapeTool, colorTool, materialTool, mainLabel,
                      TopLoc_Location(),theResultBody,theMaterialShape,false);
index 28237c24e897b1958993d31f2ca4156525d35dcd..9feeb22395c0be681ccf0c0029edd2ef5a023511 100644 (file)
@@ -121,6 +121,29 @@ std::wstring Model_Data::name()
   return L"";  // not defined
 }
 
+std::wstring Model_Data::name(std::shared_ptr<GeomAPI_Shape> theSubShape)
+{
+  std::wstring aShapeName = L"";
+  std::wstring aResultName = name();
+  if (aResultName == L"")
+    return aShapeName;
+
+  AttributeSelectionPtr aSelectionAttribute;
+  ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
+  if (aResBody.get())
+    aSelectionAttribute = aResBody->selection();
+  else
+  {
+    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(myObject);
+    aSelectionAttribute = aPart->selection();
+  }
+  aSelectionAttribute->setValue(myObject, theSubShape);
+  aShapeName = aSelectionAttribute->namingName();
+  aSelectionAttribute->reset();
+
+  return aShapeName;
+}
+
 void Model_Data::setName(const std::wstring& theName)
 {
   bool isModified = false;
index 82703d70c0a54357bbf37cdcb4d114df1e5f83fc..241bf1d3b89908b8df93e993e3dc0215b840ff83 100644 (file)
@@ -47,6 +47,7 @@
 #include <map>
 #include <list>
 #include <string>
+#include <vector>
 #include <set>
 
 class ModelAPI_Attribute;
@@ -104,6 +105,8 @@ class Model_Data : public ModelAPI_Data
   Model_Data();
   /// Returns the name of the feature visible by the user in the object browser
   MODEL_EXPORT virtual std::wstring name();
+  /// Returns the name of the shape
+  MODEL_EXPORT virtual std::wstring name(std::shared_ptr<GeomAPI_Shape> theSubShape);
   /// Defines the name of the feature visible by the user in the object browser
   MODEL_EXPORT virtual void setName(const std::wstring& theName);
   /// Return \c true if the object has been renamed by the user
index 1927466b408559dc09e5cd4acaa5963af7e787bd..5b1bf546e679ca27a67f1e636a81d95a70dfcfe0 100644 (file)
@@ -50,6 +50,7 @@
 #include <TDF_Delta.hxx>
 #include <TDF_AttributeDelta.hxx>
 #include <TDF_AttributeDeltaList.hxx>
+#include <TDF_AttributeIterator.hxx>
 #include <TDF_ListIteratorOfAttributeDeltaList.hxx>
 #include <TDF_ListIteratorOfLabelList.hxx>
 #include <TDF_LabelMap.hxx>
@@ -1374,6 +1375,13 @@ const int Model_Document::index(std::shared_ptr<ModelAPI_Object> theObject,
   return myObjs->index(theObject, theAllowFolder);
 }
 
+const int Model_Document::index(std::shared_ptr<ModelAPI_Result> theResult,
+  std::shared_ptr<GeomAPI_Shape> theShape,
+  const bool theAllowFolder)
+{
+  return myObjs->index(theResult, theShape, theAllowFolder);
+}
+
 int Model_Document::size(const std::string& theGroupID, const bool theAllowFolder)
 {
   if (myObjs == 0) // may be on close
@@ -2119,6 +2127,47 @@ AttributeSelectionListPtr Model_Document::selectionInPartFeature()
   return mySelectionFeature->selectionList("selection");
 }
 
+/// Feature that is used for use selection attribute
+class Model_SelectionInResult : public ModelAPI_Feature
+{
+public:
+  /// Nothing to do in constructor
+  Model_SelectionInResult() : ModelAPI_Feature() {}
+
+  /// Returns the unique kind of a feature
+  virtual const std::string& getKind()
+  {
+    static std::string MY_KIND("InternalSelectionInResult");
+    return MY_KIND;
+  }
+  /// Request for initialization of data model of the object: adding all attributes
+  virtual void initAttributes()
+  {
+    data()->addAttribute("selection", ModelAPI_AttributeSelection::typeId());
+  }
+  /// Nothing to do in the execution function
+  virtual void execute() {}
+};
+
+AttributeSelectionPtr Model_Document::selectionInResult()
+{
+  FeaturePtr aFeatureNameGen = FeaturePtr(new Model_SelectionInResult);
+
+  TDF_Label aFeatureLab = generalLabel().FindChild(TAG_SELECTION_FEATURE);
+  std::shared_ptr<Model_Data> aData(new Model_Data);
+  aData->setLabel(aFeatureLab.FindChild(1));
+  aData->setObject(aFeatureNameGen);
+  aFeatureNameGen->setDoc(myObjs->owner());
+  aFeatureNameGen->setData(aData);
+  std::wstring aName = id() + L"_Part";
+  aFeatureNameGen->data()->setName(aName);
+  aFeatureNameGen->setDoc(myObjs->owner());
+  aFeatureNameGen->initAttributes();
+  aFeatureNameGen->init();
+
+  return aFeatureNameGen->selection("selection");
+}
+
 FeaturePtr Model_Document::lastFeature()
 {
   if (myObjs)
@@ -2289,6 +2338,17 @@ void Model_Document::storeNodesState(const std::list<bool>& theStates)
   }
 }
 
+void Model_Document::storeShape(const std::shared_ptr<ModelAPI_Data> theData,
+  const std::shared_ptr<ModelAPI_Result> theResult,
+  const std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  if (index(theData->owner()) == -1)
+    return;
+  int anIndex = index(theResult, theShape);
+  if (anIndex == -1)
+    myObjs->storeShape(theData, theResult, theShape);
+}
+
 void Model_Document::restoreNodesState(std::list<bool>& theStates) const
 {
   TDF_Label aLab = generalLabel().FindChild(TAG_NODES_STATE);
index 0017589196a7ca69e9475d5951634b6c60e8169b..f8e40c76076aac92441d99c5273f1f23bad4b39a 100644 (file)
@@ -33,6 +33,7 @@
 class Handle_Model_Document;
 class Model_Objects;
 class ModelAPI_AttributeSelectionList;
+class TopoDS_Shape;
 
 /**\class Model_Document
  * \ingroup DataModel
@@ -145,6 +146,13 @@ class Model_Document : public ModelAPI_Document
   //! \returns index started from zero, or -1 if object is invisible or belongs to another document
   MODEL_EXPORT virtual const int index(std::shared_ptr<ModelAPI_Object> theObject,
                                        const bool theAllowFolder = false);
+  //! Returns the shape index in the result.
+  //! \param theResult result
+  //! \param theShape result subshape
+  //! \returns index started from zero, or -1 if shape is not stored or is not a subshape of the result
+  MODEL_EXPORT virtual const int index(std::shared_ptr<ModelAPI_Result> theResult,
+    std::shared_ptr<GeomAPI_Shape> theShape,
+    const bool theAllowFolder = false);
 
   //! Internal sub-document by ID
   MODEL_EXPORT virtual std::shared_ptr<Model_Document> subDoc(int theDocID);
@@ -385,10 +393,18 @@ class Model_Document : public ModelAPI_Document
   //! for calculation of selection externally from the document
   std::shared_ptr<ModelAPI_AttributeSelectionList> selectionInPartFeature();
 
+  //! Returns the selection attribute that is used
+  std::shared_ptr<ModelAPI_AttributeSelection> selectionInResult();
+
   /// Stores in the document boolean flags: states of the nodes in the object browser.
   /// Normally is called outside of the transaction, just before "save".
   virtual void storeNodesState(const std::list<bool>& theStates);
 
+  /// Store Shape from Result to document
+  virtual void storeShape(const std::shared_ptr<ModelAPI_Data> theData,
+    const std::shared_ptr<ModelAPI_Result> theResult,
+    const std::shared_ptr<GeomAPI_Shape> theShape);
+
   /// Returns the stored nodes states. Normally it is called just after "open".
   /// Appends the values to theStates list.
   virtual void restoreNodesState(std::list<bool>& theStates) const;
@@ -424,6 +440,7 @@ class Model_Document : public ModelAPI_Document
   friend class Model_ResultPart;
   friend class Model_ResultBody;
   friend class Model_ResultConstruction;
+  friend class Model_SelectionInResult;
   friend class Model_SelectionNaming;
   friend class Model_BodyBuilder;
   friend class DFBrowser;
index 7aa4407bfc13dc8c022856f0dee1fc5054c5cb8c..53d14af2e0f476bcdb9ac2a887a80d14e1d8ec1b 100644 (file)
 #include <TDataStd_Integer.hxx>
 #include <TDataStd_Comment.hxx>
 #include <TDF_ChildIDIterator.hxx>
+#include <TDataStd_IntegerArray.hxx>
 #include <TDataStd_ReferenceArray.hxx>
 #include <TDataStd_HLabelArray1.hxx>
 #include <TDF_Reference.hxx>
 #include <TDF_ChildIDIterator.hxx>
 #include <TDF_LabelMapHasher.hxx>
 #include <TDF_LabelMap.hxx>
+#include <TDF_CopyLabel.hxx>
 #include <TDF_ListIteratorOfLabelList.hxx>
 
+// relocate to other file
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+
+
 // for TDF_Label map usage
 static Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper);
 static Standard_Boolean IsEqual(const TDF_Label& theLab1, const TDF_Label& theLab2);
@@ -90,11 +97,13 @@ static const int TAG_OBJECTS = 2;  // tag of the objects sub-tree (features, res
 // feature sub-labels
 static const int TAG_FEATURE_ARGUMENTS = 1;  ///< where the arguments are located
 static const int TAG_FEATURE_RESULTS = 2;  ///< where the results are located
+static const int TAG_RESULT_SHAPES = 2;  ///< where the shapes are located
 
 ///
 /// 0:1:2 - where features are located
 /// 0:1:2:N:1 - data of the feature N
 /// 0:1:2:N:2:K:1 - data of the K result of the feature N
+/// 0:1:2:N:2:K:2:M:1 - data of the M shape of the K result of the feature N
 
 Model_Objects::Model_Objects(TDF_Label theMainLab) : myMain(theMainLab)
 {
@@ -682,6 +691,39 @@ const int Model_Objects::index(std::shared_ptr<ModelAPI_Object> theObject,
   return -1;
 }
 
+const int Model_Objects::index(std::shared_ptr<ModelAPI_Result> theResult,
+  std::shared_ptr<GeomAPI_Shape> theShape,
+  const bool theAllowFolder)
+{
+  ResultBodyPtr aMain = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  aMain = ModelAPI_Tools::mainBody(aMain);
+
+  int anIndex = -1;
+  if (aMain.get())
+    anIndex = index(aMain, theAllowFolder);
+  else
+    anIndex = index(theResult, theAllowFolder);
+
+  if (anIndex == -1)
+    return -1; // Object not store to document
+  TDF_Label aShapesLabel = shapesFromResult(resultLabel(theResult->data(), anIndex));
+
+  int aShapesIndex = 0;
+  for (TDF_ChildIterator anIt(aShapesLabel); anIt.More(); anIt.Next(), ++aShapesIndex)
+  {
+    Handle(TNaming_NamedShape) aCurShape;
+    if (anIt.Value().FindAttribute(TNaming_NamedShape::GetID(), aCurShape))
+    {
+      if (aCurShape->Get().IsSame(theShape->impl<TopoDS_Shape>()))
+      {
+        return aShapesIndex;
+      }
+    }
+  }
+  //not found
+  return -1;
+}
+
 int Model_Objects::size(const std::string& theGroupID, const bool theAllowFolder)
 {
   createHistory(theGroupID);
@@ -733,6 +775,127 @@ TDF_Label Model_Objects::featuresLabel() const
   return myMain.FindChild(TAG_OBJECTS);
 }
 
+TDF_Label Model_Objects::shapesFromResult(TDF_Label theResult) const
+{
+  return theResult.Father().FindChild(TAG_RESULT_SHAPES);
+}
+
+void Model_Objects::setAttribute(const Handle(TDF_Attribute)& theAttribute,
+  std::shared_ptr<ModelAPI_Result> theResult,
+  std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  ResultBodyPtr aMain = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  aMain = ModelAPI_Tools::mainBody(aMain);
+  TDF_Label aResultLabel;
+  if (aMain.get())
+    aResultLabel = resultLabel(theResult->data(), index(aMain));
+  else
+    aResultLabel = resultLabel(theResult->data(), index(theResult));
+  TDF_Label anAttributeLabel = subShapeLabel(aResultLabel, index(theResult, theShape)).FindChild(TAG_FEATURE_ARGUMENTS);
+
+  if (Standard_GUID::IsEqual(theAttribute->ID(), TDataStd_IntegerArray::GetID()))
+  {
+    Handle(TDataStd_IntegerArray) anColor;
+    Handle(TDataStd_IntegerArray) anAttr =
+      Handle(TDataStd_IntegerArray)::DownCast(theAttribute);
+
+    if (anAttributeLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anColor))
+    {
+      anAttributeLabel.ForgetAttribute(TDataStd_IntegerArray::GetID());
+    }
+    anAttributeLabel.AddAttribute(anAttr);
+    static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+    ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent);
+  }
+}
+
+Handle(TDF_Attribute) Model_Objects::getAttribute(const Standard_GUID& theID,
+  std::shared_ptr<ModelAPI_Result> theResult,
+  std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  ResultBodyPtr aMain = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  aMain = ModelAPI_Tools::mainBody(aMain);
+
+  int anIndex = index(theResult, theShape);
+  Handle(TDataStd_IntegerArray) anColor;
+
+  if (anIndex != -1)
+  {
+    TDF_Label aResultLabel;
+    if (aMain.get())
+      aResultLabel = resultLabel(theResult->data(), index(aMain));
+    else
+      aResultLabel = resultLabel(theResult->data(), index(theResult));
+
+    TDF_Label anAttributeLabel = subShapeLabel(aResultLabel, anIndex).FindChild(TAG_FEATURE_ARGUMENTS);
+    anAttributeLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anColor);
+  }
+  return anColor;
+}
+
+void Model_Objects::getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+  std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes)
+{
+  ResultBodyPtr aMainBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  aMainBody = ModelAPI_Tools::mainBody(aMainBody);
+  TDF_Label aShapesLabel;
+  if (aMainBody.get())
+    aShapesLabel = shapesFromResult(resultLabel(theResult->data(), index(aMainBody)));
+  else
+    aShapesLabel = shapesFromResult(resultLabel(theResult->data(), index(theResult)));
+
+  for (TDF_ChildIterator aChilds(aShapesLabel); aChilds.More(); aChilds.Next())
+  {
+    TDF_Label aCurSubShape = aChilds.Value();
+    Handle(TNaming_NamedShape) aNamedShape;
+    aCurSubShape.FindAttribute(TNaming_NamedShape::GetID(), aNamedShape);
+    if (aNamedShape.IsNull())
+      continue;
+
+    std::shared_ptr<GeomAPI_Shape> aSub(new GeomAPI_Shape);
+    aSub->setImpl(new TopoDS_Shape(aNamedShape->Get()));
+
+    Handle(TDataStd_IntegerArray) aColorAttr;
+    std::vector<int> aColor;
+    aCurSubShape.FindChild(TAG_FEATURE_ARGUMENTS).FindAttribute(TDataStd_IntegerArray::GetID(), aColorAttr);
+    if (aColorAttr.IsNull())
+      continue;
+    for (int anIndex = aColorAttr->Lower(); anIndex <= aColorAttr->Upper(); ++anIndex)
+      aColor.push_back(aColorAttr->Value(anIndex));
+    if (aColor.size() != 3)
+      continue;
+
+    theColoredShapes[aSub] = aColor;
+  }
+}
+
+void Model_Objects::removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult)
+{
+  ResultBodyPtr aMainBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  aMainBody = ModelAPI_Tools::mainBody(aMainBody);
+
+  TDF_Label aShapesLabel;
+  if (aMainBody.get())
+    aShapesLabel = shapesFromResult(resultLabel(theResult->data(), index(aMainBody)));
+  else
+  {
+    ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theResult);
+    if (!aResPart.get())
+      return;
+    aShapesLabel = shapesFromResult(resultLabel(theResult->data(), index(aResPart)));
+  }
+  for (TDF_ChildIterator aChilds(aShapesLabel); aChilds.More(); aChilds.Next())
+  {
+    TDF_Label aCurSubShape = aChilds.Value();
+    Handle(TNaming_NamedShape) aNamedShape;
+    aCurSubShape.FindAttribute(TNaming_NamedShape::GetID(), aNamedShape);
+    if (aNamedShape.IsNull())
+      continue;
+
+    aCurSubShape.FindChild(TAG_FEATURE_ARGUMENTS).ForgetAttribute(TDataStd_IntegerArray::GetID());
+  }
+}
+
 static std::wstring composeName(const std::string& theFeatureKind, const int theIndex)
 {
   std::stringstream aNameStream;
@@ -1187,6 +1350,12 @@ TDF_Label Model_Objects::resultLabel(
   return aData->label().Father().FindChild(TAG_FEATURE_RESULTS).FindChild(theResultIndex + 1);
 }
 
+TDF_Label Model_Objects::subShapeLabel(TDF_Label& theResultLabel,
+  const int theResultIndex)
+{
+  return theResultLabel.Father().FindChild(TAG_RESULT_SHAPES).FindChild(theResultIndex + 1);
+}
+
 bool Model_Objects::hasCustomName(DataPtr theFeatureData,
                                   ResultPtr theResult,
                                   int /*theResultIndex*/,
@@ -1256,6 +1425,28 @@ void Model_Objects::storeResult(std::shared_ptr<ModelAPI_Data> theFeatureData,
   }
 }
 
+void Model_Objects::storeShape(std::shared_ptr<ModelAPI_Data> theData,
+  std::shared_ptr<ModelAPI_Result> theResult,
+  std::shared_ptr<GeomAPI_Shape> theShape,
+  const int theResultIndex)
+{
+  std::shared_ptr<Model_Data> aResultData =
+    std::dynamic_pointer_cast<Model_Data>(theResult->data());
+  TDF_Label aResultLabel = resultLabel(aResultData, index(theData->owner()));
+  TDF_Label aShapesLabel = shapesFromResult(aResultLabel);
+
+  int anIndex = aShapesLabel.NbChildren();
+  TDF_Label aSubShapeLabel = subShapeLabel(aResultLabel, anIndex);
+
+  Handle(TNaming_NamedShape) aNS;
+  if (aSubShapeLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS))
+    return;
+
+  // GeomAPI_Shape -> TNaming_NamedShape
+  TNaming_Builder aBuilder(aSubShapeLabel);
+  aBuilder.Select(theShape->impl<TopoDS_Shape>(), theShape->impl<TopoDS_Shape>());
+}
+
 std::shared_ptr<ModelAPI_ResultConstruction> Model_Objects::createConstruction(
     const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
 {
@@ -2039,7 +2230,7 @@ FeaturePtr Model_Objects::lastFeature()
 
 bool Model_Objects::isLater(FeaturePtr theLater, FeaturePtr theCurrent) const
 {
-  if (theLater->getKind() == "InternalSelectionInPartFeature")
+  if (theLater->getKind() == "InternalSelectionInPartFeature" || theLater->getKind() == "InternalSelectionInResult")
     return true;
   std::shared_ptr<Model_Data> aLaterD = std::static_pointer_cast<Model_Data>(theLater->data());
   std::shared_ptr<Model_Data> aCurrentD = std::static_pointer_cast<Model_Data>(theCurrent->data());
index e810e10add7338a202a31f488b2cc9361e0bb17c..364a3dddd3e66f6d7209a5b9334728c478667ca6 100644 (file)
@@ -92,6 +92,14 @@ class Model_Objects
   const int index(std::shared_ptr<ModelAPI_Object> theObject,
                   const bool theAllowFolder = false);
 
+  //! Returns the shape index in the result.
+  //! \param theResult result
+  //! \param theShape result subshape
+  //! \returns index started from zero, or -1 if shape is not stored or is not a subshape of the result
+  const int index(std::shared_ptr<ModelAPI_Result> theResult,
+    std::shared_ptr<GeomAPI_Shape> theShape,
+    const bool theAllowFolder = false);
+
   //! Returns the feature in the group by the index (started from zero)
   //! \param theGroupID group that contains a feature
   //! \param theIndex zero-based index of feature in the group
@@ -181,6 +189,23 @@ class Model_Objects
   bool removeFromFolder(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
                         const bool theBefore = true);
 
+  //! set attribute to subShape
+  void setAttribute(const Handle(TDF_Attribute)& theAttribute,
+    std::shared_ptr<ModelAPI_Result> theResult,
+    std::shared_ptr<GeomAPI_Shape> theShape);
+
+  //! get attribute from subshape
+  Handle(TDF_Attribute) getAttribute(const Standard_GUID& theID,
+    std::shared_ptr<ModelAPI_Result> theResult,
+    std::shared_ptr<GeomAPI_Shape> theShape);
+
+  //! Get colored shapes from result
+  void getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+    std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes);
+
+  //! Forget subshape colors
+  void removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult);
+
   //! Sets the owner of this manager
   void setOwner(DocumentPtr theDoc);
 
@@ -195,6 +220,9 @@ class Model_Objects
   //! Returns (creates if needed) the features label
   TDF_Label featuresLabel() const;
 
+  //! Returns (creates if needed) the shapes label from result label
+  TDF_Label shapesFromResult(TDF_Label theResult) const;
+
   //! Initializes feature with a unique name in this group (unique name is generated as
   //! feature type + "_" + index
   void setUniqueName(FeaturePtr theFeature);
@@ -227,10 +255,20 @@ class Model_Objects
                    const int theResultIndex = 0,
                    const std::wstring& theNameShape = L"");
 
+  //! Allows to store the shape from result in the data tree of the document
+  void storeShape(std::shared_ptr<ModelAPI_Data> theData,
+    std::shared_ptr<ModelAPI_Result> theResult,
+    std::shared_ptr<GeomAPI_Shape> theShape,
+    const int theResultIndex = 0);
+
   //! returns the label of result by index; creates this label if it was not created before
   TDF_Label resultLabel(const std::shared_ptr<ModelAPI_Data>& theFeatureData,
                         const int theResultIndex);
 
+  //! Returns the label of result subshapes by index; creates this label if it was not created before
+  TDF_Label subShapeLabel(TDF_Label& theResultLabel,
+    const int theResultIndex);
+
   //! Updates the results list of the feature basing on the current data tree
   //! theProcessed is used to avoid update twice (since the function is recursive)
   void updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& theProcessed);
index 5b2d769ee48aceb7cd418a6ed1bab964f53b13cd..3475b42512ce6070dd509629b136845a77e7fdc9 100644 (file)
@@ -26,6 +26,7 @@
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeImage.h>
 #include <Model_Data.h>
 #include <Events_Loop.h>
@@ -38,6 +39,9 @@
 #include <TopExp_Explorer.hxx>
 #include <TopTools_MapOfShape.hxx>
 #include <TDataStd_UAttribute.hxx>
+#include <TDataStd_IntegerArray.hxx>
+#include <TNaming_Tool.hxx>
+#include <TDF_Reference.hxx>
 
 // if this attribute exists, the shape is connected topology
 Standard_GUID kIsConnectedTopology("e51392e0-3a4d-405d-8e36-bbfe19858ef5");
@@ -249,6 +253,64 @@ void Model_ResultBody::addShapeColor( const std::wstring& theName,std::vector<in
     myColorsShape[ theName ] =  color;
 }
 
+void Model_ResultBody::setSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult,
+  const std::shared_ptr<GeomAPI_Shape> theShape,
+  const std::vector<int>& theColor)
+{
+  TopoDS_Shape aShape = this->shape()->impl<TopoDS_Shape>();
+  TopoDS_Shape aSubShape = theShape->impl<TopoDS_Shape>();
+  if (!this->shape()->isSubShape(theShape))
+    return;
+
+  Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+  document()->storeShape(data(), theResult, theShape);
+
+  Handle(TDataStd_IntegerArray) aColor = new TDataStd_IntegerArray();
+  aColor->Init(0, 2);
+  aColor->SetValue(0, theColor[0]);
+  aColor->SetValue(1, theColor[1]);
+  aColor->SetValue(2, theColor[2]);
+  anObjects->setAttribute(aColor, theResult, theShape);
+}
+
+void Model_ResultBody::getSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult, const std::shared_ptr<GeomAPI_Shape> theShape, std::vector<int>& theColor)
+{
+  TopoDS_Shape aShape = this->shape()->impl<TopoDS_Shape>();
+  TopoDS_Shape aSubShape = theShape->impl<TopoDS_Shape>();
+  if (!this->shape()->isSubShape(theShape))
+    return;
+
+  Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+  Handle(TDataStd_IntegerArray) anAttr = Handle(TDataStd_IntegerArray)::DownCast(
+    anObjects->getAttribute(TDataStd_IntegerArray::GetID(), theResult, theShape));
+  if (anAttr.IsNull())
+    return;
+  for (int anIndex = anAttr->Lower(); anIndex <= anAttr->Upper(); ++anIndex)
+    theColor.push_back(anAttr->Value(anIndex));
+  if (theColor.size() != 3)
+    theColor.clear();
+}
+
+void Model_ResultBody::getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+  std::map<GeomShapePtr, std::vector<int>>& theColoredShapes)
+{
+  Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+  anObjects->getColoredShapes(theResult, theColoredShapes);
+}
+
+void Model_ResultBody::removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult)
+{
+  Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+  anObjects->removeShapeColors(theResult);
+}
+
+std::shared_ptr<ModelAPI_AttributeSelection> Model_ResultBody::selection()
+{
+  AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<Model_Document>
+    (document())->selectionInResult();
+  return aSelAttr;
+}
+
 std::wstring Model_ResultBody::addShapeName(std::shared_ptr<GeomAPI_Shape> theshape,
                                             const std::wstring& theName ){
 
index bda42cdf5a33b8be02050ab5df5c295b84086aa1..3f5727e5d6af28f5dcd4cede7a1dd96265ed6989 100644 (file)
@@ -151,12 +151,32 @@ protected:
   /// Add color for shape Name read shape in step file
   void addShapeColor( const std::wstring& theName,std::vector<int>& color) override;
 
+  /// Add color to sub shape
+  void setSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult,
+    const std::shared_ptr<GeomAPI_Shape> theShape,
+    const std::vector<int>& theColor);
+
+  /// Get color from sub shape
+  void getSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult,
+    const std::shared_ptr<GeomAPI_Shape> theShape,
+    std::vector<int>& theColor);
+
+  /// Get colored shapes from result
+  void getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+    std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes);
+
+  /// Forget subshape colors
+  void removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult);
+
   /// Set the map of name and color read shape in step file
   void setShapeName(std::map< std::wstring,
                               std::shared_ptr<GeomAPI_Shape>>& theShapeName,
                               std::map< std::wstring,
                               std::vector<int>>& theColorsShape) override;
 
+  /// Return Attribute selection
+  MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> selection();
+
   /// Find the name of shape read in step file
   std::wstring findShapeName(std::shared_ptr<GeomAPI_Shape> theShape) override;
 
index 4712ab625679cb8504e7d6643ed930e33c93c363..5f46da1783162885fdcd4b2fc8e8cde178c99d68 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <ModelAPI_Data.h>
 #include <Model_Data.h>
+#include <Model_Objects.h>
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Feature.h>
@@ -44,6 +45,7 @@
 #include <TNaming_Tool.hxx>
 #include <TNaming_NamedShape.hxx>
 #include <TDataStd_Name.hxx>
+#include <TDataStd_IntegerArray.hxx>
 #include <TopoDS_Compound.hxx>
 #include <BRep_Builder.hxx>
 #include <TopExp_Explorer.hxx>
@@ -369,6 +371,13 @@ bool Model_ResultPart::updateInPart(const int theIndex)
   return false; // something is wrong
 }
 
+std::shared_ptr<ModelAPI_AttributeSelection> Model_ResultPart::selection()
+{
+  AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<Model_Document>
+    (document())->selectionInResult();
+  return aSelAttr;
+}
+
 gp_Trsf Model_ResultPart::sumTrsf() {
   gp_Trsf aResult;
   if (myTrsf) {
@@ -430,6 +439,57 @@ std::shared_ptr<GeomAPI_Shape> Model_ResultPart::shapeInPart(
   return aResult;
 }
 
+void Model_ResultPart::setSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+  const std::vector<int>& theColor)
+{
+  TopoDS_Shape aShape = this->shape()->impl<TopoDS_Shape>();
+  TopoDS_Shape aSubShape = theShape->impl<TopoDS_Shape>();
+  if (!this->shape()->isSubShape(theShape))
+    return;
+
+  Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+
+  document()->storeShape(data(), original(), theShape);
+  Handle(TDataStd_IntegerArray) aColor = new TDataStd_IntegerArray();
+  aColor->Init(0, 2);
+  aColor->SetValue(0, theColor[0]);
+  aColor->SetValue(1, theColor[1]);
+  aColor->SetValue(2, theColor[2]);
+  anObjects->setAttribute(aColor, original(), theShape);
+}
+
+void Model_ResultPart::getSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+  std::vector<int>& theColor)
+{
+  TopoDS_Shape aShape = this->shape()->impl<TopoDS_Shape>();
+  TopoDS_Shape aSubShape = theShape->impl<TopoDS_Shape>();
+  if (!this->shape()->isSubShape(theShape))
+    return;
+
+  Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+  Handle(TDataStd_IntegerArray) anAttr = Handle(TDataStd_IntegerArray)::DownCast(
+    anObjects->getAttribute(TDataStd_IntegerArray::GetID(), original(), theShape));
+  if (anAttr.IsNull())
+    return;
+  for (int anIndex = anAttr->Lower(); anIndex <= anAttr->Upper(); ++anIndex)
+    theColor.push_back(anAttr->Value(anIndex));
+  if (theColor.size() != 3)
+    theColor.clear();
+}
+
+void Model_ResultPart::getColoredShapes(std::map<std::shared_ptr<GeomAPI_Shape>,
+  std::vector<int>>&theColoredShapes)
+{
+  Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+  anObjects->getColoredShapes(original(), theColoredShapes);
+}
+
+void Model_ResultPart::removeShapeColors()
+{
+  Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+  anObjects->removeShapeColors(original());
+}
+
 std::shared_ptr<GeomAPI_Shape> Model_ResultPart::selectionValue(const int theIndex)
 {
   std::shared_ptr<GeomAPI_Shape> aResult;
index 172bf8bed5ed36df08376f38e28d3790808d0000..2ba7d9ac9c427efadcc0c51e2878203edf67fe75 100644 (file)
@@ -24,6 +24,7 @@
 #include <ModelAPI_ResultPart.h>
 #include <TopoDS_Shape.hxx>
 #include <gp_Trsf.hxx>
+#include <map>
 
 /**\class Model_ResultPart
  * \ingroup DataModel
@@ -77,7 +78,21 @@ class Model_ResultPart : public ModelAPI_ResultPart
   MODEL_EXPORT virtual bool updateInPart(const int theIndex);
   /// Returns the shape by the name in the part
   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shapeInPart(
-    const std::wstring& theName, const std::string& theType, int& theIndex);
+    const std::wstring& theName, const std::string& theType, int& theIndex);  /// Set color on subshape
+  MODEL_EXPORT virtual void setSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+    const std::vector<int>& theColor);
+
+  /// Get color on subshape
+  MODEL_EXPORT virtual void getSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+    std::vector<int>& theColor);
+
+  /// Get colored shapes from result
+  MODEL_EXPORT virtual void getColoredShapes(std::map<std::shared_ptr<GeomAPI_Shape>,
+    std::vector<int>>&theColoredShapes);
+
+  /// Forget subshape colors
+  MODEL_EXPORT virtual void removeShapeColors();
+
   /// Updates the selection inside of the part as a geometrical selection
   MODEL_EXPORT virtual bool combineGeometrical(const int theIndex, std::wstring& theNewName);
   /// Updates the shape-result of the part (called on Part feature execution)
@@ -98,6 +113,9 @@ class Model_ResultPart : public ModelAPI_ResultPart
   /// Loading the part from file
   MODEL_EXPORT virtual void loadPart();
 
+  /// Return Attribute selection
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> selection();
+
 protected:
   /// makes a result on a temporary feature (an action)
   Model_ResultPart();
index 8518d284dda1c78b5f1764fd40dc63378c9cf141..09dd7343fa9340dbf59642d08fa10db44fb91668 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "ModelAPI.h"
 #include <string>
+#include <vector>
 #include <list>
 #include <set>
 #include <memory>
@@ -74,6 +75,8 @@ class MODELAPI_EXPORT ModelAPI_Data
 
   /// Returns the name of the feature visible by the user in the object browser
   virtual std::wstring name() = 0;
+  /// Returns the name of the shape
+  virtual std::wstring name(std::shared_ptr<GeomAPI_Shape> theSubShape) = 0;
   /// Defines the name of the feature visible by the user in the object browser
   virtual void setName(const std::wstring& theName) = 0;
   /// Return \c true if the object has been renamed by the user
index acec2b808c16bce4a39f42c46b9697bff251fc6e..64f638942c6ffd98d6fbade2927ac07b72f1f063 100644 (file)
@@ -28,6 +28,7 @@
 #include <vector>
 #include <list>
 #include <set>
+#include <map>
 
 class ModelAPI_Feature;
 class ModelAPI_Folder;
@@ -108,6 +109,13 @@ public:
   //! \returns index started from zero, or -1 if object is invisible or belongs to another document
   virtual const int index(std::shared_ptr<ModelAPI_Object> theObject,
                           const bool theAllowFolder = false) = 0;
+  //! Returns the shape index in the result.
+  //! \param theResult result
+  //! \param theShape result subshape
+  //! \returns index started from zero, or -1 if shape is not stored or is not a subshape of the result
+  virtual const int index(std::shared_ptr<ModelAPI_Result> theResult,
+    std::shared_ptr<GeomAPI_Shape> theShape,
+    const bool theAllowFolder = false) = 0;
 
   //! Returns the number of objects in the group of objects
   //! \param theGroupID group of objects
@@ -251,6 +259,11 @@ public:
   /// Appends the values to theStates list.
   MODELAPI_EXPORT virtual void restoreNodesState(std::list<bool>& theStates) const = 0;
 
+  /// Store Shape from Result to document
+  MODELAPI_EXPORT virtual void storeShape(const std::shared_ptr<ModelAPI_Data> theData,
+    const std::shared_ptr<ModelAPI_Result> theResult,
+    const std::shared_ptr<GeomAPI_Shape> theShape) = 0;
+
   /// Just removes all features without touching the document data (to be able undo)
   MODELAPI_EXPORT virtual void eraseAllFeatures() = 0;
 
index 223c91d55ea72936d20677622fd33d4ddf6270af..3d1df1837f3b07432c66cd51183530fdf9c2d8e3 100644 (file)
@@ -200,6 +200,26 @@ public:
   MODELAPI_EXPORT virtual void addShapeColor
                               (const std::wstring& theName, std::vector<int>& theColor) = 0;
 
+  /// Add color to sub shape
+  MODELAPI_EXPORT virtual void setSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult,
+    const std::shared_ptr<GeomAPI_Shape> theShape,
+    const std::vector<int>& theColor) = 0;
+
+  /// Get color from sub shape
+  MODELAPI_EXPORT virtual void getSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult,
+    const std::shared_ptr<GeomAPI_Shape> theShape,
+    std::vector<int>& theColor) = 0;
+
+  /// Get colored shapes from result
+  MODELAPI_EXPORT virtual void getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+    std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes) = 0;
+
+  /// Forget subshape colors
+  MODELAPI_EXPORT virtual void removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult) = 0;
+
+  /// Return Attribute selection
+  MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> selection() = 0;
+
   /// Set the map of name and color read shape in step file
   MODELAPI_EXPORT virtual void setShapeName
                           (std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> > &theShapeName,
index 148315a5f89492e837c5b597a0b30e240c8671e5..8dcd857237e356a8258db949f65668f854d1e303 100644 (file)
@@ -24,6 +24,7 @@
 class GeomAPI_Trsf;
 
 #include <string>
+#include <map>
 
 /**\class ModelAPI_ResultPart
  * \ingroup DataModel
@@ -88,6 +89,20 @@ class ModelAPI_ResultPart : public ModelAPI_Result
   /// Returns the shape by the name in the part
   virtual std::shared_ptr<GeomAPI_Shape> shapeInPart(
     const std::wstring& theName, const std::string& theType, int& theIndex) = 0;
+  /// Set color on subshape
+  virtual void setSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+    const std::vector<int>& theColor) = 0;
+
+  /// Get subshape color
+  virtual void getSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+    std::vector<int>& theColor) = 0;
+
+  /// Get colored shapes from result
+  virtual void getColoredShapes(std::map<std::shared_ptr<GeomAPI_Shape>,
+    std::vector<int>>&theColoredShapes) = 0;
+
+  /// Forget subshape colors
+  virtual void removeShapeColors() = 0;
 
   /// Updates the selection inside of the part as a geometrical selection
   virtual bool combineGeometrical(const int theIndex, std::wstring& theNewName) = 0;
@@ -98,6 +113,9 @@ class ModelAPI_ResultPart : public ModelAPI_Result
   /// Updates the shape-result of the part (called on Part feature execution)
   virtual void updateShape() = 0;
 
+  /// Return Attribute selection
+  virtual std::shared_ptr<ModelAPI_AttributeSelection> selection() = 0;
+
   /// Loading the part from file
   virtual void loadPart() = 0;
 };
index 508ca38e8ed97fcdc92c6849bb28d7086ce012bf..f7d7a5699e59fa4d59a0fdd80d052f57be6ca933 100644 (file)
@@ -518,6 +518,19 @@ ResultBodyPtr bodyOwner(const ResultPtr& theSub, const bool theRoot)
   return ResultBodyPtr(); // not found
 }
 
+ResultBodyPtr mainBody(const ResultBodyPtr theSubBody)
+{
+  ResultBodyPtr aBody = theSubBody;
+  while (aBody.get())
+  { // get the top-most main
+    ResultBodyPtr aNextBody = bodyOwner(aBody);
+    if (aNextBody.get())
+      aBody = aNextBody;
+    else break;
+  }
+  return aBody;
+}
+
 int bodyIndex(const ResultPtr& theSub)
 {
   int anIndex = -1;
@@ -1081,9 +1094,36 @@ void setColor(ResultPtr theResult, const std::vector<int>& theColor)
     aColorAttr->setValue(0, theColor[0]);
     aColorAttr->setValue(1, theColor[1]);
     aColorAttr->setValue(2, theColor[2]);
+    removeShapeColors(theResult);
   }
 }
 
+void setColor(ResultPtr theResult, GeomShapePtr theShape, const std::vector<int>& theColor)
+{
+  if (!theResult.get() || theShape->isNull())
+    return;
+  if (!theResult->shape()->isSubShape(theShape))
+    return;
+
+  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  if (aBody.get())
+  {
+    aBody = mainBody(aBody);
+    aBody->setSubShapeColor(theResult, theShape, theColor);
+  }
+  else
+  {
+    ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theResult);
+    if (!aResPart.get())
+      return;
+    aResPart->setSubShapeColor(theShape, theColor);
+  }
+
+  static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent);
+}
+
+
 void getColor(const std::shared_ptr<ModelAPI_Result>& theResult, std::vector<int>& theColor)
 {
   theColor.clear();
@@ -1099,6 +1139,84 @@ void getColor(const std::shared_ptr<ModelAPI_Result>& theResult, std::vector<int
   }
 }
 
+void getColor(const ResultPtr theResult, const GeomShapePtr theShape, std::vector<int>& theColor)
+{
+  theColor.clear();
+  if (!theResult.get() || theShape->isNull())
+    return;
+  if (!theResult->shape()->isSubShape(theShape))
+    return;
+
+  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  if (aBody.get())
+  {
+    aBody = mainBody(aBody);
+    aBody->getSubShapeColor(theResult, theShape, theColor);
+  }
+  else
+  {
+    ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theResult);
+    if (!aResPart.get())
+      return;
+    aResPart->getSubShapeColor(theShape, theColor);
+  }
+}
+
+void getColoredShapes(const ResultPtr theResult,
+  std::map<GeomShapePtr, std::vector<int>>& theColoredShapes,
+  bool theGetSubResults)
+{
+  if (!theResult.get())
+    return;
+
+  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  if (aBody.get())
+  {
+    ResultBodyPtr aMainBody = mainBody(aBody);
+    if (!aMainBody.get())
+      return;
+    if (theGetSubResults)
+    {
+      std::list<ResultPtr> aSubResults;
+      allSubs(aBody, aSubResults);
+      for (std::list<ResultPtr>::iterator anIt = aSubResults.begin();
+        anIt != aSubResults.end(); ++anIt)
+      {
+        aMainBody->getColoredShapes(*anIt, theColoredShapes);
+      }
+    }
+
+    aMainBody->getColoredShapes(theResult, theColoredShapes);
+  }
+  else
+  {
+    ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theResult);
+    if (!aResPart.get())
+      return;
+    aResPart->getColoredShapes(theColoredShapes);
+  }
+}
+
+void removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult)
+{
+  if (!theResult.get())
+    return;
+
+  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  if (aBody.get())
+  {
+    aBody = mainBody(aBody);
+    aBody->removeShapeColors(theResult);
+  }
+  else
+  {
+    ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theResult);
+    if (!aResPart.get())
+      return;
+    aResPart->removeShapeColors();
+  }
+}
+
 //******************************************************
 void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResult,
   bool& isVisible, std::vector<int>& theNbLines)
index beb380f867d783603585ba9e5107744d543283ca..dcb62e0d3b894cdfec8e3929e1180289159ca1b4 100644 (file)
@@ -139,6 +139,14 @@ MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
  */
 MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultBody>
   bodyOwner(const std::shared_ptr<ModelAPI_Result>& theSub, const bool theRoot = false);
+
+/*
+* Returns the result - main parent of this result.
+* \param theSubBody the sub-element of composit result
+* \returns Root resultBody
+*/
+MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultBody> mainBody(const std::shared_ptr<ModelAPI_ResultBody> theSubBody);
+
 /*!
  * Returns index of this result in parent (if parent exists, returned by bodyOwner)
  * \returns zero-base index, or -1 if not found
@@ -275,6 +283,31 @@ MODELAPI_EXPORT void setDeflection(std::shared_ptr<ModelAPI_Result> theResult,
 MODELAPI_EXPORT void getColor(const std::shared_ptr<ModelAPI_Result>& theResult,
   std::vector<int>& theColor);
 
+/*! Returns current color of the current subShape
+* \param[in] theResult a result object
+* \param[in] theShape a shape that belongs result object
+* \param[out] theColor a color values if it is defined
+*/
+MODELAPI_EXPORT void getColor(const std::shared_ptr<ModelAPI_Result> theResult,
+  const std::shared_ptr<GeomAPI_Shape> theShape,
+  std::vector<int>& theColor);
+
+/*! Returns colored shapes of the result
+* \param[in] theResult a result object
+* \param[out] theColoredShapes a set which contans all colored shapes of the result
+* \param[in] theSubResult true - get colored shapes from subresults,
+*                         else - get colored shaped only from result
+*/
+MODELAPI_EXPORT void getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+  std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes,
+  bool theGetSubResults = false);
+
+/*! Remove all subshape color from result
+* Need, when we set color on result
+* \param[in] theResult a result object
+*/
+MODELAPI_EXPORT void removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult);
+
 /*! Set color of the result
 * \param[in] theResult a result object
 * \param[in] theColor a color values
@@ -282,6 +315,15 @@ MODELAPI_EXPORT void getColor(const std::shared_ptr<ModelAPI_Result>& theResult,
 MODELAPI_EXPORT void setColor(std::shared_ptr<ModelAPI_Result> theResult,
   const std::vector<int>& theColor);
 
+/*! Set color of the shape from result
+* \param[in] theResult a result object
+* \param[in] theShape a shape that belongs result object
+* \param[in] theColor a color values
+*/
+MODELAPI_EXPORT void setColor(std::shared_ptr<ModelAPI_Result> theResult,
+  std::shared_ptr<GeomAPI_Shape> theShape,
+  const std::vector<int>& theColor);
+
 /*! Returns number of iso-lines of the current result
 * \param[in] theResult a result object
 * \param[out] theNbLines values of iso-lines
index cc22e0d1c828fb2afed210bb98dced0c9127e24a..f7cd5b96cd23a30ec077ce5dfe4ed2887e2abbdf 100644 (file)
@@ -782,6 +782,21 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeatur
     bool aRes = process(aSubDoc);
     if (isDumpModelDo)
       *this << "\nmodel.do()\n";
+    std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+    ModelAPI_Tools::getColoredShapes(aPartResult, aColoredShapes, true);
+    if (!aColoredShapes.empty())
+      *this << "\n";
+    for (std::map<GeomShapePtr, std::vector<int>>::const_iterator anIter(aColoredShapes.cbegin());
+      anIter != aColoredShapes.cend(); ++anIter)
+    {
+      GeomShapePtr aShape = anIter->first;
+
+      *this << aPartName << ".result()";
+      *this << ".setColor(model.selection(\"" << aShape->shapeTypeStr() << "\", \""
+        << Locale::Convert::toString((aPartResult)->data()->name(aShape)) << "\"), "
+        << anIter->second.at(0) << ", " << anIter->second.at(1)
+        << ", " << anIter->second.at(2) << ")\n";
+    }
     *this << std::endl;
     return aRes;
   }
@@ -934,6 +949,24 @@ void ModelHighAPI_Dumper::dumpEntitySetName()
                        << ", " << aColor->value(2) << ")\n";
       }
     }
+    // set subresult color
+    if ((isParentResult(*aResIt)) && hasColoredShape(*aResIt, true))
+    {
+      std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+      ModelAPI_Tools::getColoredShapes(*aResIt, aColoredShapes, true);
+
+      for (std::map<GeomShapePtr, std::vector<int>>::const_iterator anIter(aColoredShapes.cbegin());
+        anIter != aColoredShapes.cend(); ++anIter)
+      {
+        GeomShapePtr aShape = anIter->first;
+
+        *this << *aResIt;
+        *myDumpStorage << ".setColor(model.selection(\"" << aShape->shapeTypeStr() << "\", \""
+          << Locale::Convert::toString((*aResIt)->data()->name(aShape)) << "\"), "
+          << anIter->second.at(0) << ", " << anIter->second.at(1)
+          << ", " << anIter->second.at(2) << ")\n";
+      }
+    }
     // set result deflection
     if (!isDefaultDeflection(*aResIt)) {
       AttributeDoublePtr aDeflectionAttr =
@@ -1011,6 +1044,24 @@ static bool isSketchSub(const FeaturePtr& theFeature)
   return anOwner && anOwner->getKind() == SKETCH;
 }
 
+bool ModelHighAPI_Dumper::hasColoredShape(const ResultPtr& theResult, bool theGetSubResults) const
+{
+  std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+  ModelAPI_Tools::getColoredShapes(theResult, aColoredShapes, theGetSubResults);
+  return !aColoredShapes.empty();
+}
+
+bool ModelHighAPI_Dumper::isParentResult(const ResultPtr& theResult) const
+{
+  ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  ResultBodyPtr aMainBody = ModelAPI_Tools::mainBody(aResBody);
+
+  if (aMainBody.get() && aResBody == aMainBody)
+    return true;
+
+  return false;
+}
+
 bool ModelHighAPI_Dumper::isDefaultColor(const ResultPtr& theResult) const
 {
   AttributeIntArrayPtr aColor = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
@@ -1322,7 +1373,8 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity
     ModelAPI_Tools::allResults(theEntity, allRes);
     for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
       if(!myNames[*aRes].myIsDefault || !isDefaultColor(*aRes) ||
-         !isDefaultDeflection(*aRes) || !isDefaultTransparency(*aRes))
+         !isDefaultDeflection(*aRes) || !isDefaultTransparency(*aRes) ||
+        (isParentResult(*aRes) && hasColoredShape(*aRes, true)))
         aResultsWithNameOrColor.push_back(*aRes);
     }
     // store just dumped entity to stack
index c7286289c47fe8b7c9a5da2d2f0a63e095be2996..3c85b9ac10af3d1048eaabe47356239353338c94 100644 (file)
@@ -403,6 +403,12 @@ private:
   /// Stores names of results for the given feature
   void saveResultNames(const FeaturePtr& theFeature);
 
+  /// Check the result feature has colored shape
+  bool hasColoredShape(const ResultPtr& theResult, bool theGetSubResults = false) const;
+
+  /// Check the result is parent result int the feature
+  bool isParentResult(const ResultPtr& theResult) const;
+
   /// Check the result feature has default color
   bool isDefaultColor(const ResultPtr& theResult) const;
 
index 160925e8b3fbc0c98286ffa86b2dcf126d3b33d0..e2d07d5f37e1c56625ff5df1dfa9307cdcae17a6 100644 (file)
@@ -25,6 +25,7 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultPart.h>
 #include <ModelAPI_Tools.h>
 
 #include <GeomAPI_Pnt.h>
@@ -233,6 +234,37 @@ void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue, boo
   }
 }
 
+void ModelHighAPI_Selection::setColor(const ModelHighAPI_Selection& theShape,
+  int theRed, int theGreen, int theBlue)
+{
+  if (myVariantType != VT_ResultSubShapePair || !myResultSubShapePair.first.get())
+    return;
+  std::vector<int> aColor({ theRed, theGreen, theBlue });
+  std::shared_ptr<GeomAPI_Shape> aShape = myResultSubShapePair.second;
+  ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(
+    myResultSubShapePair.first);
+
+  ResultPtr aRes;
+  AttributeSelectionPtr aSelAttr;
+  if (aResBody.get())
+  {
+    aSelAttr = aResBody->selection();
+    theShape.fillAttribute(aSelAttr);
+  }
+  else
+  {
+    std::wstring aSubShapeName = theShape.myTypeSubShapeNamePair.second;
+    aSubShapeName = changePartName(theShape, aSubShapeName);
+    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(myResultSubShapePair.first);
+    aSelAttr = aPart->selection();
+    aSelAttr->selectSubShape(myTypeSubShapeNamePair.first, aSubShapeName);
+  }
+  aRes = aSelAttr->context();
+  aShape = aSelAttr->value();
+  if (aRes.get() && aShape.get() && !aShape->isNull())
+    ModelAPI_Tools::setColor(aRes, aShape, aColor);
+}
+
 void ModelHighAPI_Selection::setDeflection(double theValue)
 {
   if (myVariantType != VT_ResultSubShapePair || !myResultSubShapePair.first.get())
@@ -283,3 +315,17 @@ ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex) const
   ResultBodyPtr aResult = aBody->subResult(theIndex);
   return ModelHighAPI_Selection(aResult, aResult->shape());
 }
+
+std::wstring ModelHighAPI_Selection::changePartName(const ModelHighAPI_Selection& theShape, const std::wstring& theName)
+{
+  std::shared_ptr<GeomAPI_Shape> aShape;
+  int index;
+  ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(myResultSubShapePair.first);
+
+  std::size_t aPartEnd = theName.find(L'/');
+  if (aPartEnd == std::wstring::npos)
+    return std::wstring();
+  aShape = aPart->shapeInPart(theName.substr(aPartEnd + 1), theShape.myTypeSubShapeNamePair.first, index);
+  std::wstring name = aPart->data()->name(aShape);
+  return name;
+}
\ No newline at end of file
index dc27c474fce58e15dbb22f2446401bc859c29afe..bffa214aa6286d7b5ca1b48e8ee9859cddd9d551 100644 (file)
@@ -136,6 +136,10 @@ public:
   MODELHIGHAPI_EXPORT
   void setColor(int theRed = 0, int theGreen = 0, int theBlue = 0, bool random = false);
 
+  /// Change subShape' color
+  MODELHIGHAPI_EXPORT
+    void setColor(const ModelHighAPI_Selection& theShape, int theRed, int theGreen, int theBlue);
+
   /// Change result's deflection
   MODELHIGHAPI_EXPORT
   void setDeflection(double theValue);
@@ -152,6 +156,11 @@ public:
   MODELHIGHAPI_EXPORT
   ModelHighAPI_Selection subResult(int theIndex) const;
 
+private:
+  /// Returns new part for shape
+  MODELHIGHAPI_EXPORT
+    std::wstring changePartName(const ModelHighAPI_Selection& theShape, const std::wstring& theName);
+
 protected:
   VariantType myVariantType;
   ResultSubShapePair myResultSubShapePair;
index f816f5b7f41f209b0991bdfa21abecf221b12f02..7f0429e98b41f8cb15622854eb3a69509ddff438 100644 (file)
@@ -76,6 +76,9 @@ public:
   /// Returns list of currently selected results
   virtual QObjectPtrList selectedPresentations() const = 0;
 
+  /// Returns map of selected results and their selected subobjects
+  virtual QMap<ResultPtr, QList<GeomShapePtr>> selectedObjectsAndSubObjects() const = 0;
+
   /// Returns list of currently selected QModelIndexes
   virtual QModelIndexList selectedIndexes() const = 0;
 
index 3331b28658c613334b368d63dae0ab9599f433d1..bda0fbc825fdbc009a629652a2ab12e9d28d3e4a 100644 (file)
@@ -65,6 +65,7 @@
 #include <GeomAdaptor_Curve.hxx>
 #include <TopExp.hxx>
 #include <GCPnts_AbscissaPoint.hxx>
+#include <TopExp_Explorer.hxx>
 
 #if OCC_VERSION_HEX > 0x070400
 #include <StdPrs_ToolTriangulatedShape.hxx>
@@ -299,7 +300,7 @@ void ModuleBase_ResultPrs::Compute(
   }
   // change deviation coefficient to provide more precise circle
   try {
-    AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
+    ViewerData_AISShape::Compute(thePresentationManager, thePresentation, theMode);
   }
   catch (...) {
     return;
index ec1b6b2fde19aac8b5035f2a472da02326b4945a..be21c0eddf38e7e8af9ca24af30272436a43283c 100644 (file)
         <source>No visualization</source>
         <translation>Aucune visualisation</translation>
     </message>
+    <message>
+        <source>Set color on subshape of result</source>
+        <translation>Définir la couleur sur la sous - forme du résultat</translation>
+    </message>
 </context>
 </TS>
index 4518cc6da181d66ae51eb9a8cda41a0e68116553..825d5a2548b98fbd4a25338cb7797e9070bffe51 100644 (file)
@@ -273,6 +273,9 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   Config_PropManager::registerProp("Visualization", "axis_arrow_size",
     "Trihedron arrows constant size", Config_Prop::IntSpin, "10");
 
+  Config_PropManager::registerProp("Visualization", "color_subshape_result",
+    "Set color on subshape of result", Config_Prop::Boolean, "true");
+
   Config_PropManager::registerProp("Shortcuts", "add_parameter_shortcut",
     "Add parameter in parameters manager dialog",
     Config_Prop::Shortcut, "Ctrl+A");
@@ -1534,6 +1537,16 @@ void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
             PartSet_Tools::getDefaultColor(aResult, false, aColor);
           }
           thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+
+          std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+          ModelAPI_Tools::getColoredShapes(aResult, aColoredShapes);
+          if (!aColoredShapes.empty()) {
+            for (std::map<GeomShapePtr, std::vector<int>>::const_iterator anIter(aColoredShapes.cbegin());
+              anIter != aColoredShapes.cend(); ++anIter) {
+              thePrs->setColor(anIter->first, anIter->second.at(0),
+                anIter->second.at(1), anIter->second.at(2));
+            }
+          }
         }
       }
       else {
@@ -1557,7 +1570,6 @@ void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
   }
 }
 
-
 //******************************************************
 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
 {
index 4b99d0e15b45ef765e5edac4595d70ab2413ba41..32c649f192f85582de3505757130d7d2dfce7061 100644 (file)
@@ -86,6 +86,7 @@
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
 #include <Config_PropManager.h>
+#include <TopExp_Explorer.hxx>
 
 #include <set>
 
@@ -329,6 +330,31 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
           aCol(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
         aAISIO->SetColor(aCol);
       }
+      // Set color on subshape from result
+      std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+      ModelAPI_Tools::getColoredShapes(aResult, aColoredShapes);
+      Handle(AIS_ColoredShape) aResShape = Handle(AIS_ColoredShape)::DownCast(aAISIO);
+      Handle(ModuleBase_ResultPrs) aResPrsShape = Handle(ModuleBase_ResultPrs)::DownCast(aResShape);
+
+      if (!aColoredShapes.empty() && !aResPrsShape.IsNull())
+      {
+        for (std::map<GeomShapePtr, std::vector<int>>::const_iterator anIter(aColoredShapes.cbegin());
+          anIter != aColoredShapes.cend(); ++anIter)
+        {
+          if (aAISObj->getShape()->isSubShape(anIter->first))
+          {
+            Quantity_Color aColorQ(anIter->second.at(0) / 255.,
+              anIter->second.at(1) / 255.,
+              anIter->second.at(2) / 255.,
+              Quantity_TOC_RGB);
+            aResPrsShape->SetCustomColor(anIter->first->impl<TopoDS_Shape>(), aColorQ);
+          }
+        }
+      }
+      else
+      {
+        aResShape->ClearCustomAspects();
+      }
       // Set deflection
       double aDeflection = ModelAPI_Tools::getDeflection(aResult);
       if ((aDeflection >= 0) && (aDeflection != aAISObj->getDeflection()))
index 7a80eb0a9c8bcf3b5017ac250aa91fe19333591d..6e2ad3f7eb3768bc604c7454929afe46aa4eb896 100644 (file)
@@ -400,6 +400,46 @@ QObjectPtrList XGUI_Selection::selectedPresentations() const
   return aSelectedList;
 }
 
+QMap<ResultPtr, QList<GeomShapePtr>> XGUI_Selection::selectedObjectsAndSubObjects() const
+{
+  QMap<ResultPtr, QList<GeomShapePtr>> aSelectedObjects;
+
+  // Add all objects, which selected in Viewer
+  QList<ModuleBase_ViewerPrsPtr> aValues = getSelected(ModuleBase_ISelection::Viewer);
+  foreach(ModuleBase_ViewerPrsPtr aPrs, aValues)
+  {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
+    GeomShapePtr aShape = aPrs->shape();
+
+    aSelectedObjects[aResult].push_back(aShape);
+  }
+
+  // Add object, which selected in browser, but not selected in Viewer
+  QObjectPtrList anObjects = selectedObjects();
+  foreach(ObjectPtr anObject, anObjects)
+  {
+    ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
+    if (!aResultBody.get())
+      continue;
+    GeomShapePtr aBodyShape = aResultBody->shape();
+
+    if (aSelectedObjects.contains(aResultBody))
+      continue;
+    bool isContains = false;
+    foreach(GeomShapePtr aCurShape, aSelectedObjects[aResultBody])
+    {
+      if (aCurShape->impl<TopoDS_Shape>().IsEqual(aBodyShape->impl<TopoDS_Shape>()))
+      {
+        isContains = true;
+        break;
+      }
+    }
+    if (!isContains)
+      aSelectedObjects[aResultBody].push_back(aBodyShape);
+  }
+  return aSelectedObjects;
+}
+
 //**************************************************************
 QModelIndexList XGUI_Selection::selectedIndexes() const
 {
index 9cf5ea963e68670632a3c326082643c7706cb5d0..3dbb3ba90a771ea9d9bee5674a7d242bb68001d5 100644 (file)
@@ -66,6 +66,9 @@ class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection
   /// Returns list of currently selected results
   virtual QObjectPtrList selectedPresentations() const;
 
+  /// Returns map of selected results and their selected subobjects
+  virtual QMap<ResultPtr, QList<GeomShapePtr>> selectedObjectsAndSubObjects() const;
+
   /// Returns list of currently selected QModelIndexes
   virtual QModelIndexList selectedIndexes() const;
 
index 0df895c850db18a1e6de7e1528bcddf0d0bdf874..fea75fbf88d0ae4e1259b71668c9a86fb0a149c3 100644 (file)
@@ -1785,6 +1785,7 @@ ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
 {
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
+  QMap<ResultPtr, QList<GeomShapePtr>> aSelectedObjects = mySelector->selection()->selectedObjectsAndSubObjects();
   if (theId == "DELETE_CMD")
     deleteObjects();
   else if (theId == "CLEAN_HISTORY_CMD")
@@ -1794,9 +1795,9 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
   else if (theId == "RECOVER_CMD")
     recoverFeature();
   else if (theId == "COLOR_CMD")
-    changeColor(anObjects);
+    changeColor(aSelectedObjects);
   else if (theId == "AUTOCOLOR_CMD")
-    changeAutoColor(anObjects);
+    changeAutoColor(aSelectedObjects);
   else if (theId == "ISOLINES_CMD")
     changeIsoLines(anObjects);
   else if (theId == "SHOW_ISOLINES_CMD") {
@@ -2564,29 +2565,52 @@ void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
 }
 
 //**************************************************************
-void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
+void XGUI_Workshop::changeColor(const QMap<ResultPtr, QList<GeomShapePtr>>& theSelectedObjects)
 {
 
   AttributeIntArrayPtr aColorAttr;
   // 1. find the current color of the object. This is a color of AIS presentation
   // The objects are iterated until a first valid color is found
   std::vector<int> aColor;
-  foreach(ObjectPtr anObject, theObjects) {
-    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
-    if (aResult.get()) {
-      ModelAPI_Tools::getColor(aResult, aColor);
+  QList<ModuleBase_ViewerPrsPtr> aValues = mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer);
+  const bool isColorOnSubShape = Config_PropManager::boolean("Visualization", "color_subshape_result");
+  foreach(ResultPtr aResult, theSelectedObjects.keys())
+  {
+    if (!aResult.get())
+      continue;
+
+    foreach(GeomShapePtr aShape, theSelectedObjects[aResult])
+    {
+      if (aResult->shape()->impl<TopoDS_Shape>().IsEqual(aShape->impl<TopoDS_Shape>()) || !isColorOnSubShape)
+      {
+        ModelAPI_Tools::getColor(aResult, aColor);
+      }
+      else if (!aShape->isNull())
+      {
+        ModelAPI_Tools::getColor(aResult, aShape, aColor);
+        if (aColor.empty())
+        {
+          ModelAPI_Tools::getColor(aResult, aColor);
+        }
+      }
+
       if (aColor.empty()) {
-        AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
+        AISObjectPtr anAISObj = myDisplayer->getAISObject(aResult);
         if (anAISObj.get()) {
           aColor.resize(3);
           anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
         }
       }
-      if (aColor.empty()) {
+      if (aColor.empty())
         getDefaultColor(aResult, false, aColor);
-      }
+      if (!aColor.empty() || !isColorOnSubShape)
+        break;
     }
+
+    if (!aColor.empty())
+      break;
   }
+
   if (aColor.size() != 3)
     return;
 
@@ -2608,22 +2632,38 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
 
   aMgr->startOperation(aDescription.toStdString());
 
-  // 4. set the value to all results
+  // 4. set the value to all results and subshapes from result (if was select subshape of result)
   std::vector<int> aColorResult = aDlg->getColor();
-  foreach(ObjectPtr anObj, theObjects) {
-    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
-    if (aResult.get() != NULL) {
-      ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
-      if (aBodyResult.get() != NULL) { // change colors for all sub-solids
-        std::list<ResultPtr> allRes;
-        ModelAPI_Tools::allSubs(aBodyResult, allRes);
-        for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
-          ModelAPI_Tools::setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
+  foreach(ResultPtr aResult, theSelectedObjects.keys())
+  {
+    if (!aResult.get())
+      continue;
+    ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
+    foreach(GeomShapePtr aShape, theSelectedObjects[aResult])
+    {
+      if (aResult->shape()->impl<TopoDS_Shape>().IsEqual(aShape->impl<TopoDS_Shape>()) || !isColorOnSubShape)
+      {
+        if (aResult.get() != NULL)
+        {
+          // change colors for all sub-solids
+          std::list<ResultPtr> allRes;
+          ModelAPI_Tools::allSubs(aBodyResult, allRes);
+          for (std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++)
+          {
+            ModelAPI_Tools::setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
+          }
+          ModelAPI_Tools::setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
         }
+        if (!isColorOnSubShape)
+          break;
+      }
+      else if (!aShape->isNull())
+      {
+        ModelAPI_Tools::setColor(aResult, aShape, !isRandomColor ? aColorResult : aDlg->getRandomColor());
       }
-      ModelAPI_Tools::setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
     }
   }
+
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aMgr->finishOperation();
   updateCommandStatus();
@@ -2631,7 +2671,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
 }
 
 //**************************************************************
-void XGUI_Workshop::changeAutoColor(const QObjectPtrList& theObjects)
+void XGUI_Workshop::changeAutoColor(const QMap<ResultPtr, QList<GeomShapePtr>>& theSelectedObjects)
 {
   if (!abortAllOperations())
   return;
@@ -2648,29 +2688,40 @@ void XGUI_Workshop::changeAutoColor(const QObjectPtrList& theObjects)
       Config_PropManager::setAutoColorStatus(false);
       ModelAPI_Tools::findRandomColor(aColor, true);
     } else {
-      // set the value to all results
-      foreach (ObjectPtr anObj, theObjects) {
-        DocumentPtr aDocument = anObj->document();
+      QList<ModuleBase_ViewerPrsPtr> aValues = mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer);
+      const bool isColorOnSubShape = Config_PropManager::boolean("Visualization", "color_subshape_result");
+      foreach(ResultPtr aResult, theSelectedObjects.keys())
+      {
+        if (!aResult.get())
+          continue;
+
+        DocumentPtr aDocument = aResult->document();
         std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
-        // find the object iterator
-        std::list<FeaturePtr>::iterator anObjectIt = anAllFeatures.begin();
-        for (; anObjectIt !=  anAllFeatures.end(); ++ anObjectIt) {
-          FeaturePtr aFeature = *anObjectIt;
-          if (aFeature.get()) {
-            std::list<ResultPtr> aResults;
-            ModelAPI_Tools::allResults(aFeature, aResults);
-            std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
-            for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
-              ResultPtr aGroupResult = *aIt;
-              if (aGroupResult.get() &&
+        foreach(GeomShapePtr aShape, theSelectedObjects[aResult])
+        {
+          std::list<FeaturePtr>::iterator anObjectIt = anAllFeatures.begin();
+          for (; anObjectIt != anAllFeatures.end(); ++anObjectIt) {
+            FeaturePtr aFeature = *anObjectIt;
+            if (aFeature.get()) {
+              std::list<ResultPtr> aResults;
+              ModelAPI_Tools::allResults(aFeature, aResults);
+              std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
+              for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
+                ResultPtr aGroupResult = *aIt;
+                if (aGroupResult.get() &&
                   aGroupResult->groupName() == ModelAPI_ResultGroup::group()) {
-                ModelAPI_Tools::findRandomColor(aColor);
-                ModelAPI_Tools::setColor(aGroupResult, aColor);
+                  ModelAPI_Tools::findRandomColor(aColor);
+                  ModelAPI_Tools::setColor(aGroupResult, aColor);
+                }
               }
             }
           }
         }
+
+        if (!aColor.empty())
+          break;
       }
+
       Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
       aMgr->finishOperation();
       updateCommandStatus();
index e0d97cbae43f2f3d1d32645c17366114efe949d4..e3d949a7e6955639acbba2a75841ae4c65f02db3 100644 (file)
@@ -201,15 +201,15 @@ Q_OBJECT
   /// \return boolean value
   bool canChangeProperty(const QString& theActionName) const;
 
-  /// Change color of the results if it is possible
-  /// The operation is available for construction, body and group results
-  /// theObjects a list of selected objects
-  void changeColor(const QObjectPtrList& theObjects);
+  /// Change color of the selected objects (result and subshape of result) if it is possible
+  /// The operation is available for subshape of result, construction, body and group results
+  /// theSelectedObjects a list of selected objects
+  void changeColor(const QMap<ResultPtr, QList<GeomShapePtr>>& theSelectedObjects);
 
   /// Change Autocolor of the results if it is possible
   /// The operation is available for group results
   /// theObjects a list of selected objects
-  void changeAutoColor(const QObjectPtrList& theObjects);
+  void changeAutoColor(const QMap<ResultPtr, QList<GeomShapePtr>>& theSelectedObjects);
 
   /// Change deflection of the results if it is possible
   /// The operation is available for construction, body and group results