Salome HOME
Fix for the issue Crash on export file if name of resulting file contain the name...
[modules/shaper.git] / src / PartSet / PartSet_FieldStepPrs.cpp
index 04d74504eb84f1e1d1714795e2b6e240bfbf4a66..20dd7ca9864d522eb2dabf1c723d781c6092fa30 100644 (file)
@@ -73,12 +73,6 @@ PartSet_FieldStepPrs::PartSet_FieldStepPrs(FieldStepPtr theStep)
       aDrawer->SetPointAspect(
         new Prs3d_PointAspect(Aspect_TOM_POINT, Quantity_NOC_YELLOW, POINT_SIZE));
   }
-  SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
-  QColor aQColor = aResMgr->colorValue("Viewer", "scalar_bar_text_color", Qt::black);
-
-  myLabelColor = Quantity_Color(aQColor.redF(), aQColor.greenF(), aQColor.blueF(),
-    Quantity_TOC_RGB);
-
   SetMaterial(Graphic3d_NOM_PLASTIC);
 }
 
@@ -104,13 +98,17 @@ QList<double> PartSet_FieldStepPrs::range(double& theMin, double& theMax) const
 {
   ModelAPI_AttributeTables::ValueType aType = dataType();
   DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelList = aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
+  std::string aTypeStr = aSelList->selectionType();
+
   int aStep = myStep->id();
   AttributeTablesPtr aTablesAttr = aData->tables(CollectionPlugin_Field::VALUES_ID());
   int aRows = aTablesAttr->rows();
   int aCols = aTablesAttr->columns();
 
   QList<double> aFieldStepData;
-  for (int k = 1; k < aRows; k++) { // Do not use default values
+  int aStart = (aTypeStr == "part")? 0:1;
+  for (int k = aStart; k < aRows; k++) { // Do not use default values
     for (int j = 0; j < aCols; j++) {
       ModelAPI_AttributeTables::Value aVal = aTablesAttr->value(k, j, aStep);
       switch (aType) {
@@ -125,7 +123,7 @@ QList<double> PartSet_FieldStepPrs::range(double& theMin, double& theMax) const
   }
   QList<double> aShapeData;
   double aRangeMin = aFieldStepData.first(), aRangeMax = aFieldStepData.last();
-  for (int aRow = 0; aRow < aRows - 1; aRow++) {
+  for (int aRow = 0; aRow < aRows - aStart; aRow++) {
     double aNorm = 0;
     int aBaseIndex = aRow * aCols;
     for (int aCol = 0; aCol < aCols; aCol++) {
@@ -148,6 +146,10 @@ void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
   const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode)
 {
   SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
+  QColor aQColor = aResMgr->colorValue("Viewer", "scalar_bar_text_color", Qt::black);
+  Quantity_Color aLabelColor = Quantity_Color(aQColor.redF(), aQColor.greenF(), aQColor.blueF(),
+    Quantity_TOC_RGB);
+
   ModelAPI_AttributeTables::ValueType aType = dataType();
   DataPtr aData = myFeature->data();
   switch (aType) {
@@ -156,17 +158,27 @@ void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
   {
     double aMin, aMax;
     QList<double> aShapeData = range(aMin, aMax);
-    int aNbIntertvals = aResMgr->integerValue("Viewer", "scalar_bar_nb_intervals", 20);
 
-    AttributeSelectionListPtr aSelList = aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
-    for (int i = 0; i < aSelList->size(); i++) {
-      AttributeSelectionPtr aSelection = aSelList->value(i);
-      GeomShapePtr aShapePtr = aSelection->value();
-      TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
-      double aValue = aShapeData.at(i);
+    AttributeSelectionListPtr aSelList =
+      aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
+    std::string aTypeStr = aSelList->selectionType();
+    if (aTypeStr == "part") {
       Quantity_Color aColor;
-      if (AIS_ColorScale::FindColor(aValue, aMin, aMax, aNbIntertvals, aColor))
-        SetCustomColor(aShape, aColor);
+      if (AIS_ColorScale::FindColor(aMin, aMin, aMax, 1, aColor)) {
+        SetColor(aColor);
+      }
+    }
+    else {
+      int aNbIntertvals = aResMgr->integerValue("Viewer", "scalar_bar_nb_intervals", 20);
+      for (int i = 0; i < aSelList->size(); i++) {
+        AttributeSelectionPtr aSelection = aSelList->value(i);
+        GeomShapePtr aShapePtr = aSelection->value();
+        TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+        double aValue = aShapeData.at(i);
+        Quantity_Color aColor;
+        if (AIS_ColorScale::FindColor(aValue, aMin, aMax, aNbIntertvals, aColor))
+          SetCustomColor(aShape, aColor);
+      }
     }
   }
   break;
@@ -174,7 +186,8 @@ void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
   {
     QList<double> aShapeData = booleanValues();
 
-    AttributeSelectionListPtr aSelList = aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
+    AttributeSelectionListPtr aSelList =
+      aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
     for (int i = 0; i < aSelList->size(); i++) {
       AttributeSelectionPtr aSelection = aSelList->value(i);
       GeomShapePtr aShapePtr = aSelection->value();
@@ -189,7 +202,8 @@ void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
   case ModelAPI_AttributeTables::STRING:
   {
     QStringList aValues = strings();
-    AttributeSelectionListPtr aSelList = aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
+    AttributeSelectionListPtr aSelList =
+      aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
     Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
     for (int i = 0; i < aSelList->size(); i++) {
       AttributeSelectionPtr aSelection = aSelList->value(i);
@@ -201,7 +215,7 @@ void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
 
         Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
         anAspectText3d->SetStyle(Aspect_TOST_ANNOTATION);
-        anAspectText3d->SetColor(myLabelColor);
+        anAspectText3d->SetColor(aLabelColor);
         aGroup->SetPrimitivesAspect(anAspectText3d);
 
         int aT = aResMgr->integerValue("Viewer", "scalar_bar_text_height", 14);