+ QString functorToString( SMESH::Controls::FunctorPtr f )
+ {
+ QString type = QObject::tr( "UNKNOWN_CONTROL" );
+ if ( dynamic_cast< SMESH::Controls::Volume* >( f.get() ) )
+ type = QObject::tr( "VOLUME_3D_ELEMENTS" );
+ else if ( dynamic_cast< SMESH::Controls::MaxElementLength2D* >( f.get() ) )
+ type = QObject::tr( "MAX_ELEMENT_LENGTH_2D" );
+ else if ( dynamic_cast< SMESH::Controls::MaxElementLength3D* >( f.get() ) )
+ type = QObject::tr( "MAX_ELEMENT_LENGTH_3D" );
+ else if ( dynamic_cast< SMESH::Controls::MinimumAngle* >( f.get() ) )
+ type = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
+ else if ( dynamic_cast< SMESH::Controls::AspectRatio* >( f.get() ) )
+ type = QObject::tr( "ASPECTRATIO_ELEMENTS" );
+ else if ( dynamic_cast< SMESH::Controls::AspectRatio3D* >( f.get() ) )
+ type = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
+ else if ( dynamic_cast< SMESH::Controls::Warping* >( f.get() ) )
+ type = QObject::tr( "WARP_ELEMENTS" );
+ else if ( dynamic_cast< SMESH::Controls::Taper* >( f.get() ) )
+ type = QObject::tr( "TAPER_ELEMENTS" );
+ else if ( dynamic_cast< SMESH::Controls::Skew* >( f.get() ) )
+ type = QObject::tr( "SKEW_ELEMENTS" );
+ else if ( dynamic_cast< SMESH::Controls::Area* >( f.get() ) )
+ type = QObject::tr( "AREA_ELEMENTS" );
+ else if ( dynamic_cast< SMESH::Controls::Length* >( f.get() ) )
+ type = QObject::tr( "LENGTH_EDGES" );
+ else if ( dynamic_cast< SMESH::Controls::Length2D* >( f.get() ) )
+ type = QObject::tr( "LENGTH2D_EDGES" );
+ else if ( dynamic_cast< SMESH::Controls::MultiConnection* >( f.get() ) )
+ type = QObject::tr( "MULTI_BORDERS" );
+ else if ( dynamic_cast< SMESH::Controls::MultiConnection2D* >( f.get() ) )
+ type = QObject::tr( "MULTI2D_BORDERS" );
+ else if ( dynamic_cast< SMESH::Controls::FreeNodes* >( f.get() ) )
+ type = QObject::tr( "FREE_NODES" );
+ else if ( dynamic_cast< SMESH::Controls::FreeEdges* >( f.get() ) )
+ type = QObject::tr( "FREE_EDGES" );
+ else if ( dynamic_cast< SMESH::Controls::FreeBorders* >( f.get() ) )
+ type = QObject::tr( "FREE_BORDERS" );
+ else if ( dynamic_cast< SMESH::Controls::FreeFaces* >( f.get() ) )
+ type = QObject::tr( "FREE_FACES" );
+ return type;
+ }
+
+ void SaveDistribution()
+ {
+ LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
+ SALOME_ListIO selected;
+ if ( aSel )
+ aSel->selectedObjects( selected );
+
+ if ( selected.Extent() == 1 ) {
+ Handle(SALOME_InteractiveObject) anIO = selected.First();
+ if ( anIO->hasEntry() ) {
+ SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
+ if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
+ SMESH_ScalarBarActor* aScalarBarActor = anActor->GetScalarBarActor();
+ SMESH::Controls::FunctorPtr aFunctor = anActor->GetFunctor();
+ if ( aScalarBarActor && aFunctor ) {
+ SMESH::Controls::NumericalFunctor* aNumFun = dynamic_cast<SMESH::Controls::NumericalFunctor*>( aFunctor.get() );
+ if ( aNumFun ) {
+ int nbRanges = aScalarBarActor->GetMaximumNumberOfColors();
+ std::vector<int> nbEvents;
+ std::vector<double> funValues;
+ aNumFun->GetHistogram( nbRanges, nbEvents, funValues );
+ QString anInitialPath = "";
+ if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
+ anInitialPath = QDir::currentPath();
+ QString aMeshName = anIO->getName();
+ QStringList filter;
+ filter.append( QObject::tr( "TEXT_FILES_FILTER" ) + " (*.txt)" );
+ filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
+ QString aFilename = anInitialPath + "/" + aMeshName + "_" +
+ functorToString( aFunctor ).toLower().simplified().replace( QRegExp( " |-" ), "_" ) + ".txt";
+ aFilename = SUIT_FileDlg::getFileName( SMESHGUI::desktop(),
+ aFilename,
+ filter,
+ QObject::tr( "SMESH_SAVE_DISTRIBUTION" ),
+ false );
+ if ( !aFilename.isEmpty() ) {
+ QFile f( aFilename );
+ if ( f.open( QFile::WriteOnly | QFile::Truncate ) ) {
+ QTextStream out( &f );
+ out << "# Mesh: " << aMeshName << endl;
+ out << "# Control: " << functorToString( aFunctor ) << endl;
+ out << "#" << endl;
+ out.setFieldWidth( 10 );
+ for ( int i = 0; i < qMin( nbEvents.size(), funValues.size()-1 ); i++ )
+ out << funValues[i] << "\t" << funValues[i+1] << "\t" << nbEvents[i] << endl;
+ f.close();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ void ShowDistribution() {
+ LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
+ SALOME_ListIO selected;
+ if ( aSel )
+ aSel->selectedObjects( selected );
+
+ if ( selected.Extent() == 1 ) {
+ Handle(SALOME_InteractiveObject) anIO = selected.First();
+ if ( anIO->hasEntry() ) {
+ SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
+ if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
+ SMESH_ScalarBarActor *aScalarBarActor = anActor->GetScalarBarActor();
+ aScalarBarActor->SetDistributionVisibility(!aScalarBarActor->GetDistributionVisibility());
+ }
+ }
+ }
+ }
+