From 98d2ada2266f6f33a153beb8230b98435066d9b8 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 26 Jun 2019 18:51:34 +0300 Subject: [PATCH] Provide presentation for boolean values --- src/PartSet/PartSet_FieldStepPrs.cpp | 57 +++++++++++++++++++++++++++- src/PartSet/PartSet_FieldStepPrs.h | 1 + src/XGUI/XGUI_SelectionMgr.cpp | 2 +- src/XGUI/XGUI_ViewerProxy.cpp | 4 +- 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/PartSet/PartSet_FieldStepPrs.cpp b/src/PartSet/PartSet_FieldStepPrs.cpp index c699c8ed1..f616fabce 100644 --- a/src/PartSet/PartSet_FieldStepPrs.cpp +++ b/src/PartSet/PartSet_FieldStepPrs.cpp @@ -26,10 +26,14 @@ #include #include +#include +#include IMPLEMENT_STANDARD_RTTIEXT(PartSet_FieldStepPrs, ViewerData_AISShape); +#define POINT_SIZE 8 + void emptyDeleter(ModelAPI_ResultField* theF) { @@ -48,6 +52,15 @@ PartSet_FieldStepPrs::PartSet_FieldStepPrs(FieldStepPtr theStep) // Make shared_ptr which will not delete original pointer after exit std::shared_ptr aFieldPtr(aField, emptyDeleter); myFeature = ModelAPI_Feature::feature(aFieldPtr); + + Handle(Prs3d_Drawer) aDrawer = Attributes(); + if (aDrawer->HasOwnPointAspect()) { + aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_POINT); + aDrawer->PointAspect()->SetScale(POINT_SIZE); + } + else + aDrawer->SetPointAspect( + new Prs3d_PointAspect(Aspect_TOM_POINT, Quantity_NOC_YELLOW, POINT_SIZE)); } @@ -116,13 +129,13 @@ void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) { ModelAPI_AttributeTables::ValueType aType = dataType(); + DataPtr aData = myFeature->data(); if ((aType == ModelAPI_AttributeTables::DOUBLE) || (aType == ModelAPI_AttributeTables::INTEGER)) { double aMin, aMax; QList aShapeData = range(aMin, aMax); int aNbIntertvals = 20; - DataPtr aData = myFeature->data(); AttributeSelectionListPtr aSelList = aData->selectionList(CollectionPlugin_Field::SELECTED_ID()); for (int i = 0; i < aSelList->size(); i++) { AttributeSelectionPtr aSelection = aSelList->value(i); @@ -134,5 +147,47 @@ void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t SetCustomColor(aShape, aColor); } } + else if (aType == ModelAPI_AttributeTables::BOOLEAN) { + QList aShapeData = booleanValues(); + + 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(); + double aValue = aShapeData.at(i); + Quantity_Color aColor; + if (AIS_ColorScale::FindColor(aValue, 0., 1. + Precision::Confusion(), 2, aColor)) + SetCustomColor(aShape, aColor); + } + } ViewerData_AISShape::Compute(thePrsMgr, thePrs, theMode); } + +QList PartSet_FieldStepPrs::booleanValues() const +{ + DataPtr aData = myFeature->data(); + int aStep = myStep->id(); + AttributeTablesPtr aTablesAttr = aData->tables(CollectionPlugin_Field::VALUES_ID()); + int aRows = aTablesAttr->rows(); + int aCols = aTablesAttr->columns(); + QList aFieldStepData; + for (int j = 0; j < aCols; j++) { + for (int k = 1; k < aRows; k++) { // Do not use default values + ModelAPI_AttributeTables::Value aVal = aTablesAttr->value(k, j, aStep); + aFieldStepData << (aVal.myBool ? 1 : 0); + } + } + QList aShapeData; + double aRangeMin = aFieldStepData.first(), aRangeMax = aFieldStepData.last(); + for (int aRow = 0; aRow < aRows - 1; aRow++) { + double aNorm = 0; + int aBaseIndex = aRow * aCols; + for (int aCol = 0; aCol < aCols; aCol++) { + aNorm += aFieldStepData.at(aCol + aBaseIndex); + } + aNorm /= aCols; + aShapeData << aNorm; + } + return aShapeData; +} diff --git a/src/PartSet/PartSet_FieldStepPrs.h b/src/PartSet/PartSet_FieldStepPrs.h index 9aa671fc8..f6d8ebae5 100644 --- a/src/PartSet/PartSet_FieldStepPrs.h +++ b/src/PartSet/PartSet_FieldStepPrs.h @@ -57,6 +57,7 @@ protected: private: QList range(double& theMin, double& theMax) const; + QList booleanValues() const; FieldStepPtr myStep; FeaturePtr myFeature; diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index ba0129566..bfca5d72c 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -151,7 +151,7 @@ void XGUI_SelectionMgr::onObjectBrowserSelection() aViewer->setupColorScale(); if (aType == ModelAPI_AttributeTables::BOOLEAN) { aViewer->setColorScaleIntervals(2); - aViewer->setColorScaleRange(0, 1); + aViewer->setColorScaleRange(0., 1.); } else { double aMin, aMax; diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index 43890885b..753a07d98 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -596,8 +596,7 @@ void XGUI_ViewerProxy::setColorScaleSize(double theW, double theH) myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); #else Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); - aColorScale->SetWidth(aWindow->width() * theW); - aColorScale->SetHeight(aWindow->height() * theH); + aColorScale->SetSize(aWindow->width() * theW, aWindow->height() * theH); #endif } @@ -649,6 +648,7 @@ void XGUI_ViewerProxy::setupColorScale() setColorScaleSize(0.2, 0.5); setColorScaleTextHeigth(14); setColorScaleIntervals(20); + Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); } -- 2.39.2