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>
29 #include <Prs3d_Drawer.hxx>
30 #include <Prs3d_PointAspect.hxx>
33 IMPLEMENT_STANDARD_RTTIEXT(PartSet_FieldStepPrs, ViewerData_AISShape);
38 void emptyDeleter(ModelAPI_ResultField* theF)
43 PartSet_FieldStepPrs::PartSet_FieldStepPrs(FieldStepPtr theStep)
44 : ViewerData_AISShape(TopoDS_Shape()), myStep(theStep)
46 ModelAPI_ResultField* aField = theStep->field();
47 GeomShapePtr aShapePtr = aField->shape();
48 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
51 // Get parameters of the Field
52 // Make shared_ptr which will not delete original pointer after exit
53 std::shared_ptr<ModelAPI_ResultField> aFieldPtr(aField, emptyDeleter);
54 myFeature = ModelAPI_Feature::feature(aFieldPtr);
56 Handle(Prs3d_Drawer) aDrawer = Attributes();
57 if (aDrawer->HasOwnPointAspect()) {
58 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_POINT);
59 aDrawer->PointAspect()->SetScale(POINT_SIZE);
62 aDrawer->SetPointAspect(
63 new Prs3d_PointAspect(Aspect_TOM_POINT, Quantity_NOC_YELLOW, POINT_SIZE));
67 ModelAPI_AttributeTables::ValueType PartSet_FieldStepPrs::dataType() const
69 DataPtr aData = myFeature->data();
70 AttributeTablesPtr aTablesAttr = aData->tables(CollectionPlugin_Field::VALUES_ID());
71 return aTablesAttr->type();
74 bool PartSet_FieldStepPrs::dataRange(double& theMin, double& theMax) const
76 ModelAPI_AttributeTables::ValueType aType = dataType();
77 if ((aType == ModelAPI_AttributeTables::DOUBLE) || (aType == ModelAPI_AttributeTables::INTEGER)) {
78 range(theMin, theMax);
84 QList<double> PartSet_FieldStepPrs::range(double& theMin, double& theMax) const
86 ModelAPI_AttributeTables::ValueType aType = dataType();
87 DataPtr aData = myFeature->data();
88 int aStep = myStep->id();
89 AttributeTablesPtr aTablesAttr = aData->tables(CollectionPlugin_Field::VALUES_ID());
90 int aRows = aTablesAttr->rows();
91 int aCols = aTablesAttr->columns();
93 QList<double> aFieldStepData;
94 for (int j = 0; j < aCols; j++) {
95 for (int k = 1; k < aRows; k++) { // Do not use default values
96 ModelAPI_AttributeTables::Value aVal = aTablesAttr->value(k, j, aStep);
98 case ModelAPI_AttributeTables::DOUBLE:
99 aFieldStepData << aVal.myDouble;
101 case ModelAPI_AttributeTables::INTEGER:
102 aFieldStepData << aVal.myInt;
107 QList<double> aShapeData;
108 double aRangeMin = aFieldStepData.first(), aRangeMax = aFieldStepData.last();
109 for (int aRow = 0; aRow < aRows - 1; aRow++) {
111 int aBaseIndex = aRow * aCols;
112 for (int aCol = 0; aCol < aCols; aCol++) {
113 int anIndex = aCol + aBaseIndex;
114 double aValue = aFieldStepData.at(anIndex);
115 aNorm += aValue * aValue;
117 aNorm = pow(aNorm, 0.5);
118 aRangeMin = Min(aRangeMin, aNorm);
119 aRangeMax = Max(aRangeMax, aNorm);
128 void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
129 const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode)
131 ModelAPI_AttributeTables::ValueType aType = dataType();
132 DataPtr aData = myFeature->data();
133 if ((aType == ModelAPI_AttributeTables::DOUBLE) ||
134 (aType == ModelAPI_AttributeTables::INTEGER)) {
136 QList<double> aShapeData = range(aMin, aMax);
137 int aNbIntertvals = 20;
139 AttributeSelectionListPtr aSelList = aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
140 for (int i = 0; i < aSelList->size(); i++) {
141 AttributeSelectionPtr aSelection = aSelList->value(i);
142 GeomShapePtr aShapePtr = aSelection->value();
143 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
144 double aValue = aShapeData.at(i);
145 Quantity_Color aColor;
146 if (AIS_ColorScale::FindColor(aValue, aMin, aMax, aNbIntertvals, aColor))
147 SetCustomColor(aShape, aColor);
150 else if (aType == ModelAPI_AttributeTables::BOOLEAN) {
151 QList<double> aShapeData = booleanValues();
153 AttributeSelectionListPtr aSelList = aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
154 for (int i = 0; i < aSelList->size(); i++) {
155 AttributeSelectionPtr aSelection = aSelList->value(i);
156 GeomShapePtr aShapePtr = aSelection->value();
157 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
158 double aValue = aShapeData.at(i);
159 Quantity_Color aColor;
160 if (AIS_ColorScale::FindColor(aValue, 0., 1. + Precision::Confusion(), 2, aColor))
161 SetCustomColor(aShape, aColor);
164 ViewerData_AISShape::Compute(thePrsMgr, thePrs, theMode);
167 QList<double> PartSet_FieldStepPrs::booleanValues() const
169 DataPtr aData = myFeature->data();
170 int aStep = myStep->id();
171 AttributeTablesPtr aTablesAttr = aData->tables(CollectionPlugin_Field::VALUES_ID());
172 int aRows = aTablesAttr->rows();
173 int aCols = aTablesAttr->columns();
174 QList<int> aFieldStepData;
175 for (int j = 0; j < aCols; j++) {
176 for (int k = 1; k < aRows; k++) { // Do not use default values
177 ModelAPI_AttributeTables::Value aVal = aTablesAttr->value(k, j, aStep);
178 aFieldStepData << (aVal.myBool ? 1 : 0);
181 QList<double> aShapeData;
182 double aRangeMin = aFieldStepData.first(), aRangeMax = aFieldStepData.last();
183 for (int aRow = 0; aRow < aRows - 1; aRow++) {
185 int aBaseIndex = aRow * aCols;
186 for (int aCol = 0; aCol < aCols; aCol++) {
187 aNorm += aFieldStepData.at(aCol + aBaseIndex);