Salome HOME
using a better solution to do compare doubles for shape physical properties
[modules/shaper.git] / src / PartSet / PartSet_FieldStepPrs.cpp
index 8bf365e67bd462dbae0502aa0adaf7a4b2bf38fb..a29c12c33c51c279cedbb54ffac482c5e7269f36 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include <TopoDS.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <TopExp_Explorer.hxx>
-#include <Prs3d_Root.hxx>
-
+#include <Graphic3d_Text.hxx>
+#include <Graphic3d_AspectText3d.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(PartSet_FieldStepPrs, ViewerData_AISShape);
 
 #define POINT_SIZE 8
 
 
-void emptyDeleter(ModelAPI_ResultField* theF)
+void emptyDeleter(ModelAPI_ResultField* /*theF*/)
 {
   // Do nothing
 }
@@ -118,6 +118,8 @@ QList<double> PartSet_FieldStepPrs::range(double& theMin, double& theMax) const
       case ModelAPI_AttributeTables::INTEGER:
         aFieldStepData << aVal.myInt;
         break;
+      default: // [to avoid compilation warning]
+        break;
       }
     }
   }
@@ -214,15 +216,13 @@ void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
     QStringList aValues = strings();
     AttributeSelectionListPtr aSelList =
       aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
-    Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
+    Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
     for (int i = 0; i < aSelList->size(); i++) {
       AttributeSelectionPtr aSelection = aSelList->value(i);
       GeomShapePtr aShapePtr = aSelection->value();
       TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
       gp_Pnt aCenter;
       if (computeMassCenter(aShape, aCenter)) {
-        Graphic3d_Vertex aVertex(aCenter.X(), aCenter.Y(), aCenter.Z());
-
         Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
         anAspectText3d->SetStyle(Aspect_TOST_ANNOTATION);
         anAspectText3d->SetColor(aLabelColor);
@@ -230,7 +230,10 @@ void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
 
         int aT = aResMgr->integerValue("Viewer", "scalar_bar_text_height", 14);
         QString aString = aValues.at(i);
-        aGroup->Text(aString.toUtf8().constData(), aVertex, aT);
+        Handle(Graphic3d_Text) aText = new Graphic3d_Text(aT);
+        aText->SetText(aString.toUtf8().constData());
+        aText->SetPosition(aCenter);
+        aGroup->AddText(aText);
       }
     }
   }
@@ -254,7 +257,6 @@ QList<double> PartSet_FieldStepPrs::booleanValues() const
     }
   }
   QList<double> aShapeData;
-  double aRangeMin = aFieldStepData.first(), aRangeMax = aFieldStepData.last();
   for (int aRow = 0; aRow < aRows - 1; aRow++) {
     double aNorm = 0;
     int aBaseIndex = aRow * aCols;
@@ -316,14 +318,12 @@ bool PartSet_FieldStepPrs::computeMassCenter(const TopoDS_Shape& theShape, gp_Pn
     if (!triangulation.IsNull() && triangulation->HasUVNodes()) {
       gp_XY C(0, 0);
       double A = 0;
-      const TColgp_Array1OfPnt2d& uvArray = triangulation->UVNodes();
-      const Poly_Array1OfTriangle&  trias = triangulation->Triangles();
       int n1, n2, n3;
-      for (int iT = trias.Lower(); iT <= trias.Upper(); ++iT) {
-        trias(iT).Get(n1, n2, n3);
-        const gp_Pnt2d& uv1 = uvArray(n1);
-        const gp_Pnt2d& uv2 = uvArray(n2);
-        const gp_Pnt2d& uv3 = uvArray(n3);
+      for (int iT = 1; iT <= triangulation->NbTriangles(); ++iT) {
+        triangulation->Triangle(iT).Get(n1, n2, n3);
+        const gp_Pnt2d& uv1 = triangulation->UVNode(n1);
+        const gp_Pnt2d& uv2 = triangulation->UVNode(n2);
+        const gp_Pnt2d& uv3 = triangulation->UVNode(n3);
         double a = 0.5 * sqrt((uv1.X() - uv3.X()) * (uv2.Y() - uv1.Y()) -
           (uv1.X() - uv2.X()) * (uv3.Y() - uv1.Y()));
         C += (uv1.XY() + uv2.XY() + uv3.XY()) / 3. * a;