Salome HOME
updated copyright message
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Selection.cpp
index cb74050bce40a957fa16dba8abc967a06f830736..5c8bf3e4cb1095463d4255dfaa21990f2cf6e2fe 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  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
@@ -25,7 +25,7 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultBody.h>
-
+#include <ModelAPI_Tools.h>
 
 #include <GeomAPI_Pnt.h>
 //--------------------------------------------------------------------------------------
@@ -44,7 +44,7 @@ ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Re
 }
 
 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
-                                               const std::string& theSubShapeName)
+                                               const std::wstring& theSubShapeName)
 : myVariantType(VT_TypeSubShapeNamePair)
 , myTypeSubShapeNamePair(theType, theSubShapeName)
 {
@@ -72,9 +72,9 @@ ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
 }
 
 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
-  const std::string& theContextName, const int theIndex)
-  : myVariantType(VT_WeakNamingPair)
-  , myWeakNamingPair(theType, std::pair<std::string, int>(theContextName, theIndex))
+  const std::wstring& theContextName, const int theIndex)
+  : myVariantType(VT_WeakNamingPair),
+  myWeakNamingPair(theType, std::pair<std::wstring, int>(theContextName, theIndex))
 {
 }
 
@@ -102,6 +102,8 @@ void ModelHighAPI_Selection::fillAttribute(
       theAttribute->selectSubShape(
         myWeakNamingPair.first, myWeakNamingPair.second.first, myWeakNamingPair.second.second);
       break;
+    case VT_Filtering:
+      break; // do nothing [to avoid compilation warning]
   }
 
   if (theAttribute->isInvalid()) {
@@ -133,6 +135,9 @@ void ModelHighAPI_Selection::appendToList(
       theAttribute->append(
         myWeakNamingPair.first, myWeakNamingPair.second.first, myWeakNamingPair.second.second);
       return;
+    case VT_Filtering:
+      theAttribute->setFilters(myFilterFeature);
+      return;
   }
 }
 
@@ -175,13 +180,15 @@ std::string ModelHighAPI_Selection::shapeType() const
                                                myResultSubShapePair.first->shape()->shapeTypeStr();
   case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first;
   case VT_TypeInnerPointPair: return myTypeInnerPointPair.first;
+  default:
+    break; // do nothing [to avoid compilation warning]
   }
 
   return "SHAPE";
 }
 
 //==================================================================================================
-void ModelHighAPI_Selection::setName(const std::string& theName)
+void ModelHighAPI_Selection::setName(const std::wstring& theName)
 {
   if (myVariantType == VT_ResultSubShapePair) {
     std::shared_ptr<ModelAPI_Result> aResult = myResultSubShapePair.first;
@@ -192,17 +199,17 @@ void ModelHighAPI_Selection::setName(const std::string& theName)
   }
 }
 
-std::string ModelHighAPI_Selection::name() const
+std::wstring ModelHighAPI_Selection::name() const
 {
   if (myVariantType == VT_ResultSubShapePair) {
     std::shared_ptr<ModelAPI_Result> aResult = myResultSubShapePair.first;
     if (aResult.get())
       return aResult->data()->name();
   }
-  return std::string();
+  return std::wstring();
 }
 
-void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
+void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue, bool random)
 {
   if (myVariantType != VT_ResultSubShapePair || !myResultSubShapePair.first.get())
     return;
@@ -210,14 +217,25 @@ void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
   AttributeIntArrayPtr aColor =
       myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
   aColor->setSize(3);
-  aColor->setValue(0, theRed);
-  aColor->setValue(1, theGreen);
-  aColor->setValue(2, theBlue);
+
+  if (random)
+  {
+    std::vector<int> aValues;
+    ModelAPI_Tools::findRandomColor(aValues);
+    for (int anIndex = 0; anIndex < 3; ++anIndex)
+      aColor->setValue(anIndex, aValues[anIndex]);
+  }
+  else
+  {
+    aColor->setValue(0, theRed);
+    aColor->setValue(1, theGreen);
+    aColor->setValue(2, theBlue);
+  }
 }
 
 void ModelHighAPI_Selection::setDeflection(double theValue)
 {
-  if (myVariantType != VT_ResultSubShapePair)
+  if (myVariantType != VT_ResultSubShapePair || !myResultSubShapePair.first.get())
     return;
 
   AttributeDoublePtr aDeflectionAttr =
@@ -229,7 +247,7 @@ void ModelHighAPI_Selection::setDeflection(double theValue)
 // LCOV_EXCL_START
 void ModelHighAPI_Selection::setTransparency(double theValue)
 {
-  if (myVariantType != VT_ResultSubShapePair)
+  if (myVariantType != VT_ResultSubShapePair || !myResultSubShapePair.first.get())
     return;
 
   AttributeDoublePtr aTransparencyAttr =