1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "PartSet_FieldStepPrs.h"
22 #include <CollectionPlugin_Field.h>
24 #include <ModelAPI_AttributeSelectionList.h>
25 #include <ModelAPI_AttributeIntArray.h>
26 #include <ModelAPI_AttributeStringArray.h>
28 #include <AIS_ColorScale.hxx>
31 IMPLEMENT_STANDARD_RTTIEXT(PartSet_FieldStepPrs, ViewerData_AISShape);
34 void emptyDeleter(ModelAPI_ResultField* theF)
39 PartSet_FieldStepPrs::PartSet_FieldStepPrs(FieldStepPtr theStep)
40 : ViewerData_AISShape(TopoDS_Shape()), myStep(theStep)
42 ModelAPI_ResultField* aField = theStep->field();
43 GeomShapePtr aShapePtr = aField->shape();
44 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
47 // Get parameters of the Field
48 // Make shared_ptr which will not delete original pointer after exit
49 std::shared_ptr<ModelAPI_ResultField> aFieldPtr(aField, emptyDeleter);
50 myFeature = ModelAPI_Feature::feature(aFieldPtr);
54 ModelAPI_AttributeTables::ValueType PartSet_FieldStepPrs::dataType() const
56 DataPtr aData = myFeature->data();
57 AttributeTablesPtr aTablesAttr = aData->tables(CollectionPlugin_Field::VALUES_ID());
58 return aTablesAttr->type();
61 bool PartSet_FieldStepPrs::dataRange(double& theMin, double& theMax) const
63 ModelAPI_AttributeTables::ValueType aType = dataType();
64 if ((aType == ModelAPI_AttributeTables::DOUBLE) || (aType == ModelAPI_AttributeTables::INTEGER)) {
65 range(theMin, theMax);
71 QList<double> PartSet_FieldStepPrs::range(double& theMin, double& theMax) const
73 ModelAPI_AttributeTables::ValueType aType = dataType();
74 DataPtr aData = myFeature->data();
75 int aStep = myStep->id();
76 AttributeTablesPtr aTablesAttr = aData->tables(CollectionPlugin_Field::VALUES_ID());
77 int aRows = aTablesAttr->rows();
78 int aCols = aTablesAttr->columns();
80 QList<double> aFieldStepData;
81 for (int j = 0; j < aCols; j++) {
82 for (int k = 1; k < aRows; k++) { // Do not use default values
83 ModelAPI_AttributeTables::Value aVal = aTablesAttr->value(k, j, aStep);
85 case ModelAPI_AttributeTables::DOUBLE:
86 aFieldStepData << aVal.myDouble;
88 case ModelAPI_AttributeTables::INTEGER:
89 aFieldStepData << aVal.myInt;
94 QList<double> aShapeData;
95 double aRangeMin = aFieldStepData.first(), aRangeMax = aFieldStepData.last();
96 for (int aRow = 0; aRow < aRows - 1; aRow++) {
98 int aBaseIndex = aRow * aCols;
99 for (int aCol = 0; aCol < aCols; aCol++) {
100 int anIndex = aCol + aBaseIndex;
101 double aValue = aFieldStepData.at(anIndex);
102 aNorm += aValue * aValue;
104 aNorm = pow(aNorm, 0.5);
105 aRangeMin = Min(aRangeMin, aNorm);
106 aRangeMax = Max(aRangeMax, aNorm);
115 void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
116 const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode)
118 ModelAPI_AttributeTables::ValueType aType = dataType();
119 if ((aType == ModelAPI_AttributeTables::DOUBLE) ||
120 (aType == ModelAPI_AttributeTables::INTEGER)) {
122 QList<double> aShapeData = range(aMin, aMax);
123 int aNbIntertvals = 20;
125 DataPtr aData = myFeature->data();
126 AttributeSelectionListPtr aSelList = aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
127 for (int i = 0; i < aSelList->size(); i++) {
128 AttributeSelectionPtr aSelection = aSelList->value(i);
129 GeomShapePtr aShapePtr = aSelection->value();
130 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
131 double aValue = aShapeData.at(i);
132 Quantity_Color aColor;
133 if (AIS_ColorScale::FindColor(aValue, aMin, aMax, aNbIntertvals, aColor))
134 SetCustomColor(aShape, aColor);
137 ViewerData_AISShape::Compute(thePrsMgr, thePrs, theMode);