+
+void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
+{
+ if( theGeomFieldStep->_is_nil() )
+ return;
+
+ GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
+ if( aGeomField->_is_nil() )
+ return;
+
+ GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
+ if( aGeomFieldShape->_is_nil() )
+ return;
+
+ TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
+ TCollection_AsciiString aFieldName( aGeomField->GetName() );
+ TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
+
+ aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
+
+ GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
+
+ int aFieldDimension = aGeomField->GetDimension();
+
+ GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
+ int aFieldNbComponents = aFieldComponents->length();
+
+ QList<QVariant> aFieldStepData;
+ if( aFieldDataType == GEOM::FDT_Bool )
+ {
+ GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
+ if ( !aGeomBoolFieldStep->_is_nil() )
+ {
+ GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
+ for( size_t i = 0, n = aValues->length(); i < n; i++ )
+ aFieldStepData << (bool)aValues[i];
+ }
+ }
+ else if( aFieldDataType == GEOM::FDT_Int )
+ {
+ GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
+ if ( !aGeomIntFieldStep->_is_nil() )
+ {
+ GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
+ for( size_t i = 0, n = aValues->length(); i < n; i++ )
+ aFieldStepData << (qlonglong)aValues[i];
+ }
+ }
+ else if( aFieldDataType == GEOM::FDT_Double )
+ {
+ GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
+ if ( !aGeomDoubleFieldStep->_is_nil() )
+ {
+ GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
+ for( size_t i = 0, n = aValues->length(); i < n; i++ )
+ aFieldStepData << (double)aValues[i];
+ }
+ }
+ else if( aFieldDataType == GEOM::FDT_String )
+ {
+ GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
+ if ( !aGeomStringFieldStep->_is_nil() )
+ {
+ GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
+ for( size_t i = 0, n = aValues->length(); i < n; i++ )
+ aFieldStepData << QString( aValues[i] );
+ }
+ }
+
+ double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
+ aFieldStepData = groupFieldData( aFieldStepData,
+ aFieldNbComponents,
+ aFieldDataType == GEOM::FDT_String,
+ aFieldStepRangeMin,
+ aFieldStepRangeMax );
+
+ setFieldStepInfo( aFieldDataType,
+ aFieldDimension,
+ aFieldStepData,
+ aFieldStepName,
+ aFieldStepRangeMin,
+ aFieldStepRangeMax );
+}
+
+QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
+ const int theFieldNbComponents,
+ const bool theIsString,
+ double& theFieldStepRangeMin,
+ double& theFieldStepRangeMax )
+{
+ QList<QVariant> aResultList;
+ theFieldStepRangeMin = 0;
+ theFieldStepRangeMax = 0;
+
+ if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
+ return aResultList;
+
+ int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
+
+ QList<QVariant> aGroupedList;
+
+ bool anIsBoolean = false;
+ for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
+ {
+ double aNorm = 0;
+ QStringList aStringList;
+
+ int aBaseIndex = aSubShape * theFieldNbComponents;
+ for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
+ {
+ int anIndex = aComponent + aBaseIndex;
+
+ const QVariant& aVariant = theFieldStepData[ anIndex ];
+ if( theIsString )
+ {
+ if( aVariant.type() == QVariant::String )
+ aStringList << aVariant.toString();
+ }
+ else
+ {
+ double aValue = 0;
+ if( aVariant.type() == QVariant::Bool )
+ {
+ aValue = aVariant.toBool() ? 1.0 : 0.0;
+ aNorm += aValue;
+ anIsBoolean = true;
+ }
+ else
+ {
+ if( aVariant.type() == QVariant::LongLong )
+ aValue = double( aVariant.toLongLong() );
+ else if( aVariant.type() == QVariant::Double )
+ aValue = aVariant.toDouble();
+ aNorm += aValue * aValue;
+ }
+ }
+ }
+
+ if( theIsString )
+ aGroupedList << aStringList.join( "\n" );
+ else
+ {
+ if( anIsBoolean )
+ aNorm /= theFieldNbComponents;
+ else
+ aNorm = pow( aNorm, 0.5 );
+
+ if( aGroupedList.isEmpty() )
+ theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
+ else
+ {
+ theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
+ theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
+ }
+
+ aGroupedList << aNorm;
+ }
+ }
+
+ if( anIsBoolean )
+ {
+ theFieldStepRangeMin = 0.0;
+ theFieldStepRangeMax = 1.0;
+ }
+
+ SUIT_Session* session = SUIT_Session::session();
+ SUIT_ResourceMgr* resMgr = session->resourceMgr();
+ Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
+
+ QListIterator<QVariant> anIter( aGroupedList );
+ while( anIter.hasNext() )
+ {
+ const QVariant& aVariant = anIter.next();
+ if( theIsString )
+ aResultList << aVariant;
+ else
+ {
+ QColor aQColor;
+ Quantity_Color aColor;
+ if( AIS_ColorScale::FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
+ aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
+ aResultList << aQColor;
+ }
+ }
+ return aResultList;
+}
+
+void GEOM_Displayer::UpdateColorScale()
+{
+ if ( !myUpdateColorScale )
+ return;
+
+ SUIT_Session* session = SUIT_Session::session();
+ SUIT_Application* app = session->activeApplication();
+ if ( !app ) return;
+
+ Handle(SALOME_InteractiveObject) io = myApp->selectionMgr()->soleSelectedObject();
+
+ QList<SUIT_ViewWindow*> windows = app->desktop()->windows();
+ foreach( SUIT_ViewWindow* window, windows )
+ {
+ OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>( window );
+ if ( !occWindow ) continue;
+ if ( !occWindow->getViewManager() ) continue;
+ if ( !window->getViewManager() ) continue;
+ if ( !window->getViewManager()->getViewModel() ) continue;
+ SOCC_Viewer* view = dynamic_cast<SOCC_Viewer*>( window->getViewManager()->getViewModel() );
+ if ( !view ) continue;
+ Handle(V3d_Viewer) viewer = view->getViewer3d();
+ if ( !io.IsNull() && view->isVisible( io ) )
+ {
+ bool visible = false;
+ SOCC_Prs* prs = dynamic_cast<SOCC_Prs*>( view->CreatePrs( io->getEntry() ) );
+ if ( prs )
+ {
+ AIS_ListOfInteractive presentations;
+ prs->GetObjects( presentations );
+ AIS_ListIteratorOfListOfInteractive iter( presentations );
+ for ( ; iter.More(); iter.Next() )
+ {
+ Handle(GEOM_AISShape) shape = Handle(GEOM_AISShape)::DownCast( iter.Value() );
+ if ( shape.IsNull() ) continue;
+ GEOM::field_data_type fieldDataType;
+ int fieldDimension;
+ QList<QVariant> fieldStepData;
+ TCollection_AsciiString fieldStepName;
+ Standard_Real fieldStepRangeMin, fieldStepRangeMax;
+ shape->getFieldStepInfo( fieldDataType, fieldDimension, fieldStepData,
+ fieldStepName, fieldStepRangeMin, fieldStepRangeMax );
+ visible = !fieldStepData.isEmpty() && fieldDataType != GEOM::FDT_String;
+ if ( visible )
+ {
+ SUIT_Session* session = SUIT_Session::session();
+ SUIT_ResourceMgr* resMgr = session->resourceMgr();
+
+ Standard_Real xPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
+ Standard_Real yPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
+ Standard_Real width = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
+ Standard_Real height = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
+ Standard_Integer textHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
+ Standard_Integer nbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
+
+ Standard_Integer viewWidth = 0, viewHeight = 0;
+ occWindow->getView(0)->getViewPort()->getView()->Window()->Size( viewWidth, viewHeight );
+
+ Handle(AIS_ColorScale) colorScale = view->getColorScale();
+
+ colorScale->SetPosition( viewWidth * xPos, viewHeight * yPos );
+ colorScale->SetBreadth( viewWidth * width );
+ colorScale->SetHeight( viewHeight * height );
+ colorScale->SetRange( fieldStepRangeMin, fieldStepRangeMax );
+ colorScale->SetNumberOfIntervals( fieldDataType == GEOM::FDT_Bool ? 2 : nbIntervals );
+ colorScale->SetTextHeight( textHeight );
+ colorScale->SetTitle( fieldStepName );
+ } // if ( visible )
+ }
+ }
+ view->setColorScaleShown( visible );
+ } // if ( view->isVisible( io ) )
+ else
+ {
+ view->setColorScaleShown( false );
+ }
+ } // foreach( SUIT_ViewWindow* window, windows )
+}
+
+bool GEOM_Displayer::SetUpdateColorScale( bool toUpdate ) // IPAL54049
+{
+ bool previous = myUpdateColorScale;
+ myUpdateColorScale = toUpdate;
+ if ( myUpdateColorScale && !previous )
+ UpdateColorScale();
+ return previous;
+}
+