Salome HOME
PAL20948 EDF 1468 SMESH: Histogram of the quality controls
authorvsr <vsr@opencascade.com>
Wed, 20 Oct 2010 20:13:44 +0000 (20:13 +0000)
committervsr <vsr@opencascade.com>
Wed, 20 Oct 2010 20:13:44 +0000 (20:13 +0000)
src/SMESHGUI/SMESHGUI.cxx
src/SMESHGUI/SMESHGUI_Selection.cxx
src/SMESHGUI/SMESHGUI_Selection.h
src/SMESHGUI/SMESH_msg_en.ts

index e21f33a97b054af6416395f4802dacaa36fd1bba..f766be62e12e820a3b5c8d9756f289440d352f14 100644 (file)
@@ -84,6 +84,7 @@
 #include <SMESH_Client.hxx>
 #include <SMESH_Actor.h>
 #include <SMESH_TypeFilter.hxx>
+#include "SMESH_ControlsDef.hxx"
 
 // SALOME GUI includes
 #include <SalomeApp_Tools.h>
 // Qt includes
 // #define       INCLUDE_MENUITEM_DEF // VSR commented ????????
 #include <QMenu>
+#include <QTextStream>
 
 // BOOST includes
 #include <boost/shared_ptr.hpp>
     std::string myExtension;
 
     if ( theCommandID == 113 ) {
-      filter.append( QObject::tr( "MED files (*.med)" ) );
-      filter.append( QObject::tr( "All files (*)" ) );
+      filter.append( QObject::tr( "MED_FILES_FILTER" ) + " (*.med)" );
+      filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
     }
     else if ( theCommandID == 112 ) {
-      filter.append( QObject::tr( "IDEAS files (*.unv)" ) );
+      filter.append( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
     }
     else if ( theCommandID == 111 ) {
-      filter.append( QObject::tr( "DAT files (*.dat)" ) );
+      filter.append( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
     }
 
     QString anInitialPath = "";
 
     QList<SALOMEDS::Color> aReservedColors;
 
-    QString aFilter, aTitle = QObject::tr("Export mesh");
+    QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
     QMap<QString, SMESH::MED_VERSION> aFilterMap;
     QMap<QString, int> aFilterMapSTL;
     switch ( theCommandID ) {
         // PAL18696
         QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
         QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
-        aFilterMap.insert( QString("MED ") +  v21 + " (*.med)", SMESH::MED_V2_1 );
-        aFilterMap.insert( QString("MED ") +  v22 + " (*.med)", SMESH::MED_V2_2 );
+        aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v21 ) + " (*.med)", SMESH::MED_V2_1 );
+        aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v22 ) + " (*.med)", SMESH::MED_V2_2 );
       }
       break;
     case 124:
     case 121:
-      aFilter = QObject::tr("DAT files (*.dat)");
+      aFilter = QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)";
       break;
     case 126:
     case 123:
           if (aRet != 0)
             return;
         }
-        aFilter = QObject::tr("IDEAS files (*.unv)");
+        aFilter = QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)";
       }
       break;
     case 140:
             return;
         }
 
-        aFilterMapSTL.insert( QObject::tr("STL ASCII (*.stl)"), 1 ); // 1 - ASCII mode
-        aFilterMapSTL.insert( QObject::tr("STL Binary (*.stl)"), 0 ); // 0 - Binary mode
+        aFilterMapSTL.insert( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)", 1 ); // 1 - ASCII mode
+        aFilterMapSTL.insert( QObject::tr( "STL_BIN_FILES_FILTER" )   + " (*.stl)", 0 ); // 0 - Binary mode
       }
       break;
     default:
       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
       fd->setWindowTitle( aTitle );
       fd->setNameFilters( filters );
-      fd->selectNameFilter( QObject::tr("STL ASCII (*.stl)") );
+      fd->selectNameFilter( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
       if ( !anInitialPath.isEmpty() )
         fd->setDirectory( anInitialPath );
       fd->selectFile(aMeshName);
     SMESH::RepaintCurrentView();
   }
 
+  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 ) {
+         vtkScalarBarActor* 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 DisableAutoColor(){
     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
     SALOME_ListIO selected;
     if( !selected.IsEmpty() ){
       Handle(SALOME_InteractiveObject) anIO = selected.First();
       if(!anIO.IsNull()){
-        QString aTitle;
         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
           switch ( theCommandID ){
           case 6001:
-            aTitle = QObject::tr( "LENGTH_EDGES" );
             aControl = SMESH_Actor::eLength;
             break;
           case 6018:
-            aTitle = QObject::tr( "LENGTH2D_EDGES" );
             aControl = SMESH_Actor::eLength2D;
             break;
           case 6002:
-            aTitle = QObject::tr( "FREE_EDGES" );
             aControl = SMESH_Actor::eFreeEdges;
             break;
           case 6003:
-            aTitle = QObject::tr( "FREE_BORDERS" );
             aControl = SMESH_Actor::eFreeBorders;
             break;
           case 6004:
-            aTitle = QObject::tr( "MULTI_BORDERS" );
             aControl = SMESH_Actor::eMultiConnection;
             break;
           case 6005:
-            aTitle = QObject::tr( "FREE_NODES" );
             aControl = SMESH_Actor::eFreeNodes;
             break;
           case 6019:
-            aTitle = QObject::tr( "MULTI2D_BORDERS" );
             aControl = SMESH_Actor::eMultiConnection2D;
             break;
           case 6011:
-            aTitle = QObject::tr( "AREA_ELEMENTS" );
             aControl = SMESH_Actor::eArea;
             break;
           case 6012:
-            aTitle = QObject::tr( "TAPER_ELEMENTS" );
             aControl = SMESH_Actor::eTaper;
             break;
           case 6013:
-            aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
             aControl = SMESH_Actor::eAspectRatio;
             break;
           case 6017:
-            aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
             aControl = SMESH_Actor::eAspectRatio3D;
             break;
           case 6014:
-            aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
             aControl = SMESH_Actor::eMinimumAngle;
             break;
           case 6015:
-            aTitle = QObject::tr( "WARP_ELEMENTS" );
             aControl = SMESH_Actor::eWarping;
             break;
           case 6016:
-            aTitle = QObject::tr( "SKEW_ELEMENTS" );
             aControl = SMESH_Actor::eSkew;
             break;
           case 6009:
-            aTitle = QObject::tr( "SMESH_VOLUME" );
             aControl = SMESH_Actor::eVolume3D;
             break;
           case 6021:
-            aTitle = QObject::tr( "FREE_FACES" );
             aControl = SMESH_Actor::eFreeFaces;
             break;
           case 6022:
-            aTitle = QObject::tr( "MAX_ELEMENT_LENGTH_2D" );
             aControl = SMESH_Actor::eMaxElementLength2D;
             break;
           case 6023:
-            aTitle = QObject::tr( "MAX_ELEMENT_LENGTH_3D" );
             aControl = SMESH_Actor::eMaxElementLength3D;
             break;
           }
           anActor->SetControlMode(aControl);
-          anActor->GetScalarBarActor()->SetTitle(aTitle.toLatin1().data());
+          anActor->GetScalarBarActor()->SetTitle( functorToString( anActor->GetFunctor() ).toLatin1().constData() );
           SMESH::RepaintCurrentView();
         }
       }
@@ -1694,6 +1774,12 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
       break;
     }
+  case 202:
+    {
+      // dump control distribution data to the text file
+      ::SaveDistribution();
+      break;
+    }
 
     // Auto-color
   case 1136:
@@ -3105,6 +3191,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction(  419, "SPLIT_TO_TETRA",  "ICON_SPLIT_TO_TETRA" );
   createSMESHAction(  200, "RESET" );
   createSMESHAction(  201, "SCALAR_BAR_PROP" );
+  createSMESHAction(  202, "SAVE_DISTRIBUTION" );
   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
@@ -3705,6 +3792,11 @@ void SMESHGUI::initialize( CAM_Application* app )
   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
 
+  popupMgr()->insert( separator(), anId, -1 );
+
+  popupMgr()->insert( action( 202 ), anId, -1 ); // SAVE_DISTRIBUTION
+  popupMgr()->setRule( action( 202 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
+
   popupMgr()->insert( separator(), -1, -1 );
 
   //-------------------------------------------------
index 15ca322b5e9b8a922a57b695bc46030d0df5aa85..2d923a91dc8679a1ba06f7b29446ac9ef951ba36 100644 (file)
@@ -114,6 +114,7 @@ QVariant SMESHGUI_Selection::parameter( const int ind, const QString& p ) const
   else if ( p=="shrinkMode" )    val = QVariant( shrinkMode( ind ) );
   else if ( p=="entityMode" )    val = QVariant( entityMode( ind ) );
   else if ( p=="controlMode" )   val = QVariant( controlMode( ind ) );
+  else if ( p=="isNumFunctor" )  val = QVariant( isNumFunctor( ind ) );
   else if ( p=="displayMode" )   val = QVariant( displayMode( ind ) );
   else if ( p=="isComputable" )  val = QVariant( isComputable( ind ) );
   else if ( p=="isPreComputable" )  val = QVariant( isPreComputable( ind ) );
@@ -285,6 +286,35 @@ QString SMESHGUI_Selection::controlMode( int ind ) const
   return "eNone";
 }
 
+bool SMESHGUI_Selection::isNumFunctor( int ind ) const
+{
+  bool result = false;
+  SMESH_Actor* actor = getActor( ind );
+  if ( actor ) {
+    switch( actor->GetControlMode() ) {
+    case SMESH_Actor::eLength:
+    case SMESH_Actor::eLength2D:
+    case SMESH_Actor::eMultiConnection:
+    case SMESH_Actor::eMultiConnection2D:
+    case SMESH_Actor::eArea:
+    case SMESH_Actor::eVolume3D:
+    case SMESH_Actor::eMaxElementLength2D:
+    case SMESH_Actor::eMaxElementLength3D:
+    case SMESH_Actor::eTaper:
+    case SMESH_Actor::eAspectRatio:
+    case SMESH_Actor::eAspectRatio3D:
+    case SMESH_Actor::eMinimumAngle:
+    case SMESH_Actor::eWarping:
+    case SMESH_Actor::eSkew:
+      result = true;
+      break;
+    default:
+      break;
+    }
+  }
+  return result;
+}
+
 //=======================================================================
 //function : facesOrientationMode
 //purpose  : 
index 2320041def32adb2f85a442f745ebffab518f7f0..2ad94150fca70311a2725da33ac6b176638b4160 100644 (file)
@@ -68,6 +68,7 @@ public:
   virtual QString         shrinkMode( int ) const;
   virtual QList<QVariant> entityMode( int ) const;
   virtual QString         controlMode( int ) const;
+  virtual bool            isNumFunctor( int ) const;
   virtual QString         facesOrientationMode( int ) const;
   virtual QString         groupType( int ) const;
   
index ef56941d2a0f80148217ea3d58a7ab04c256b3f2..efa0f7aa45300bd9368eb835fc63b15eae1b1ad2 100644 (file)
@@ -3,6 +3,42 @@
 <TS version="2.0" language="en_US">
 <context>
     <name>@default</name>
+    <message>
+        <source>SMESH_EXPORT_MESH</source>
+        <translation>Export mesh</translation>
+    </message>
+    <message>
+        <source>MED_FILES_FILTER</source>
+        <translation>MED files</translation>
+    </message>
+    <message>
+        <source>IDEAS_FILES_FILTER</source>
+        <translation>IDEAS files</translation>
+    </message>
+    <message>
+        <source>DAT_FILES_FILTER</source>
+        <translation>DAT files</translation>
+    </message>
+    <message>
+        <source>TEXT_FILES_FILTER</source>
+        <translation>TXT files</translation>
+    </message>
+    <message>
+        <source>MED_VX_FILES_FILTER</source>
+        <translation>MED %1 files</translation>
+    </message>
+    <message>
+        <source>STL_ASCII_FILES_FILTER</source>
+        <translation>STL ASCII files</translation>
+    </message>
+    <message>
+        <source>STL_BIN_FILES_FILTER</source>
+        <translation>STL binary files</translation>
+    </message>
+    <message>
+        <source>ALL_FILES_FILTER</source>
+        <translation>All files</translation>
+    </message>
     <message>
         <source>AREA_ELEMENTS</source>
         <translation>Area</translation>
         <source>MEN_RESET</source>
         <translation>Reset</translation>
     </message>
+    <message>
+        <source>MEN_SAVE_DISTRIBUTION</source>
+        <translation>Export Distribution...</translation>
+    </message>
     <message>
         <source>MEN_REVOLUTION</source>
         <translation>Revolution</translation>
@@ -2504,6 +2544,10 @@ Consider saving your work before application crash</translation>
         <source>STB_RESET</source>
         <translation>Reset</translation>
     </message>
+    <message>
+        <source>STB_SAVE_DISTRIBUTION</source>
+        <translation>Save distribution to the file</translation>
+    </message>
     <message>
         <source>STB_REVOLUTION</source>
         <translation>Revolution</translation>
@@ -3032,6 +3076,10 @@ Consider saving your work before application crash</translation>
         <source>TOP_RESET</source>
         <translation>Reset</translation>
     </message>
+    <message>
+        <source>TOP_SAVE_DISTRIBUTION</source>
+        <translation>Export distribution</translation>
+    </message>
     <message>
         <source>TOP_REVOLUTION</source>
         <translation>Revolution</translation>
@@ -3164,9 +3212,13 @@ Consider saving your work before application crash</translation>
         <source>TOP_WIRE</source>
         <translation>Wireframe</translation>
     </message>
+    <message>
+        <source>UNKNOWN_CONTROL</source>
+        <translation>Unknown</translation>
+    </message>
     <message>
         <source>VOLUME_3D_ELEMENTS</source>
-        <translation>Area</translation>
+        <translation>Volume</translation>
     </message>
     <message>
         <source>WARP_ELEMENTS</source>
@@ -3266,6 +3318,10 @@ Input value precision can be adjusted using
         <source>NB_NODES_REMOVED</source>
         <translation>Removed %1 node(s).</translation>
     </message>
+    <message>
+        <source>SMESH_SAVE_DISTRIBUTION</source>
+        <translation>Export Distribution</translation>
+    </message>
 </context>
 <context>
     <name>SMESHGUI</name>