Salome HOME
PR: synchro V7_main tag mergefrom_V6_main_06Mar13
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index a6f7cc0e2fa113433f91fedd3e3e88b14874571f..826100787b18af03e99618a3138a6821f29391a8 100644 (file)
     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
       anInitialPath = QDir::currentPath();
 
-    QStringList filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
-                                                            anInitialPath,
-                                                            filter,
-                                                            QObject::tr( "SMESH_IMPORT_MESH" ) );
+    QStringList filenames;
+    bool toCreateGroups = true;
+
+    // if ( theCommandID == 118 ) { // GMF
+    //   SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
+    //     ( SMESHGUI::desktop(), true, QObject::tr("SMESH_REQUIRED_GROUPS"), true, true );
+    //   fd->setWindowTitle( QObject::tr( "SMESH_IMPORT_MESH" ) );
+    //   fd->setNameFilters( filter );
+    //   fd->SetChecked( true );
+    //   if ( fd->exec() )
+    //     filenames << fd->selectedFile();
+    //   toCreateGroups = fd->IsChecked();
+
+    //   delete fd;
+    // }
+    // else
+    {
+      filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
+                                                  anInitialPath,
+                                                  filter,
+                                                  QObject::tr( "SMESH_IMPORT_MESH" ) );
+    }
     if ( filenames.count() > 0 ) {
       SUIT_OverrideCursor wc;
       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
               // GMF format
               SMESH::ComputeError_var res;
               aMeshes->length( 1 );
-              aMeshes[0] = theComponentMesh->CreateMeshesFromGMF( filename.toLatin1().constData(), res.out() );
+              aMeshes[0] = theComponentMesh->CreateMeshesFromGMF( filename.toLatin1().constData(),
+                                                                  toCreateGroups,
+                                                                  res.out() );
               if ( res->code != SMESH::DRS_OK ) {
                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res->code ).toLatin1().data() ) ) );
 
             anEntryList.append( aMeshSO->GetID().c_str() );
 
-#ifdef WITHGENERICOBJ
             // obj has been published in study. Its refcount has been incremented.
             // It is safe to decrement its refcount
             // so that it will be destroyed when the entry in study will be removed
             aMeshes[i]->UnRegister();
-#endif
           }
           else {
             isEmpty = true;
     {
       format = "GMF";
       notSupportedElemTypes.push_back( SMESH::Entity_0D );
-      notSupportedElemTypes.push_back( SMESH::Entity_Quad_Quadrangle );
       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Pyramid );
-      notSupportedElemTypes.push_back( SMESH::Entity_Quad_Hexa );
       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Penta );
       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
       else if ( isGMF )
         aFilter = QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)" +
           ";;" +  QObject::tr( "GMF_BINARY_FILES_FILTER" )  + " (*.meshb)";
-      if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
+     if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
       aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
                                             anInitialPath + QString("/") + aMeshName,
                                             aFilter, aTitle, false);
     }
+    // else if ( isGMF )// Export to GMF
+    // {
+      // SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
+      //   ( SMESHGUI::desktop(), false, QObject::tr("SMESH_REQUIRED_GROUPS"), true, true );
+      // QStringList filters;
+      // filters << QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)"
+      //         << QObject::tr( "GMF_BINARY_FILES_FILTER" )  + " (*.meshb)";
+      // fd->setWindowTitle( aTitle );
+      // fd->setNameFilters( filters );
+
+      // if ( !aMeshOrGroup->_is_equivalent( aMesh ))
+      //   toCreateGroups = false;
+      // else
+      //   toCreateGroups = ( aMesh->NbGroups() > 0 );
+
+      // fd->SetChecked( true );
+      // if ( !anInitialPath.isEmpty() )
+      //   fd->setDirectory( anInitialPath );
+      // fd->selectFile(aMeshName);
+
+      // if ( fd->exec() )
+      //   aFilename = fd->selectedFile();
+      // toCreateGroups = fd->IsChecked();
+
+      // delete fd;
+    // }
     else if ( isCGNS )// Export to CGNS
     {
       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
         }
         else if ( isGMF )
         {
-          aMesh->ExportGMF( aMeshOrGroup, aFilename.toLatin1().data() );
+          toCreateGroups = true;
+          aMesh->ExportGMF( aMeshOrGroup, aFilename.toLatin1().data(), toCreateGroups );
         }
       }
       catch (const SALOME::SALOME_Exception& S_ex){
               vtkLookupTable* lookupTable =
                 static_cast<vtkLookupTable*>(aScalarBarActor->GetLookupTable());
               double * minmax = lookupTable->GetRange();
+              bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
               std::vector<int>    nbEvents;
               std::vector<double> funValues;
-              aNumFun->GetHistogram( nbIntervals, nbEvents, funValues, elements, minmax );
+              aNumFun->GetHistogram( nbIntervals, nbEvents, funValues, elements, minmax, isLogarithmic );
               QString anInitialPath = "";
               if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
                 anInitialPath = QDir::currentPath();
         return;
       }
       case 1132: {
-        vtkFloatingPointType color[3];
+        double color[3];
         QColor faceColor, edgeColor, nodeColor, elem0dColor, ballColor;
         QColor orientationColor, outlineColor, volumeColor;
         int deltaF = 0, deltaV = 0;
         int ballSize     = 1;
         int edgeWidth    = 1;
         int outlineWidth = 1;
-        vtkFloatingPointType shrinkCoef = 0.0;
-        vtkFloatingPointType orientationScale = 0.0;
+        double shrinkCoef = 0.0;
+        double orientationScale = 0.0;
         bool orientation3d = false;
         VTK::MarkerType markerType = VTK::MT_NONE;
         VTK::MarkerScale markerScale = VTK::MS_NONE;
             aControl = SMESH_Actor::eCoincidentElems3D;
             break;
           }
-            
+
           anActor->SetControlMode(aControl);
           anActor->GetScalarBarActor()->SetTitle( functorToString( anActor->GetFunctor() ).toLatin1().constData() );
           SMESH::RepaintCurrentView();
       std::string anEntry = SO->GetID();
 
       /** Erase graphical object **/
-      if(SO->FindAttribute(anAttr, "AttributeIOR")){
-        ViewManagerList aViewMenegers = anApp->viewManagers();
-        ViewManagerList::const_iterator it = aViewMenegers.begin();
-        for( ; it != aViewMenegers.end(); it++) {         
-          SUIT_ViewManager* vm = *it;
-          int nbSf = vm ? vm->getViewsCount() : 0;
-          if(vm) {
-            QVector<SUIT_ViewWindow*> aViews = vm->getViews();
-            for(int i = 0; i < nbSf; i++){
-              SUIT_ViewWindow *sf = aViews[i];
-              if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
-                SMESH::RemoveActor(sf,anActor);
-              }
-            }
-          }
-        }
+      if(SO->FindAttribute(anAttr, "AttributeIOR")) {
+        SMESH::RemoveVisualObjectWithActors( anEntry.c_str(), true);
+        // ViewManagerList aViewMenegers = anApp->viewManagers();
+        // ViewManagerList::const_iterator it = aViewMenegers.begin();
+        // for( ; it != aViewMenegers.end(); it++) {         
+        //   SUIT_ViewManager* vm = *it;
+        //   int nbSf = vm ? vm->getViewsCount() : 0;
+        //   if(vm) {
+        //     QVector<SUIT_ViewWindow*> aViews = vm->getViews();
+        //     for(int i = 0; i < nbSf; i++){
+        //       SUIT_ViewWindow *sf = aViews[i];
+        //       if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
+        //         SMESH::RemoveActor(sf,anActor);
+        //       }
+        //     }
+        //   }
+        // }
       }
       /** Remove an object from data structures **/
       SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
@@ -1844,8 +1889,7 @@ SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
  */
 //=============================================================================
 SMESHGUI::SMESHGUI() :
-SalomeApp_Module( "SMESH" ),
-LightApp_Module( "SMESH" )
+SalomeApp_Module( "SMESH" )
 {
   if ( CORBA::is_nil( myComponentSMESH ) )
   {
@@ -1880,10 +1924,6 @@ LightApp_Module( "SMESH" )
   myEventCallbackCommand->SetCallback( SMESHGUI::ProcessEvents );
   myPriority = 0.0;
 
-  SMESH::GetFilterManager();
-  SMESH::GetPattern();
-  SMESH::GetMeasurements();
-
   /* load resources for all available meshers */
   SMESH::InitAvailableHypotheses();
 }
@@ -1895,12 +1935,6 @@ LightApp_Module( "SMESH" )
 //=============================================================================
 SMESHGUI::~SMESHGUI()
 {
-#ifdef WITHGENERICOBJ
-  SMESH::GetFilterManager()->UnRegister();
-  SMESH::GetMeasurements()->UnRegister();
-#endif
-  SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
-  SMESH::GetMeasurements() = SMESH::Measurements::_nil();
 }
 
 //=============================================================================
@@ -3046,8 +3080,8 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
           type = SMDSEntity_TriQuad_Hexa; break;
         default: break;
         }
-       if ( type != SMDSEntity_Last )
-       ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
+        if ( type != SMDSEntity_Last )
+          ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
       }
       else {
         SUIT_MessageBox::warning(SMESHGUI::desktop(),
@@ -4700,7 +4734,7 @@ void SMESHGUI::createPreferences()
   setPreferenceProperty( notifyMode, "indexes", indices );
 
   int infoGroup = addPreference( tr( "PREF_GROUP_INFO" ), genTab );
-  setPreferenceProperty( infoGroup, "columns", 4 );
+  setPreferenceProperty( infoGroup, "columns", 2 );
   int elemInfo = addPreference( tr( "PREF_ELEM_INFO" ), infoGroup, LightApp_Preferences::Selector, "SMESH", "mesh_elem_info" );
   modes.clear();
   modes.append( tr( "PREF_ELEM_INFO_SIMPLE" ) );
@@ -4715,6 +4749,10 @@ void SMESHGUI::createPreferences()
   setPreferenceProperty( nodesLim, "max", 10000000 );
   setPreferenceProperty( nodesLim, "step", 10000 );
   setPreferenceProperty( nodesLim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
+  addPreference( tr( "PREF_ELEM_INFO_GRP_DETAILS" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "elem_info_grp_details" );
+  addPreference( tr( "PREF_DUMP_BASE_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_base" );
+  addPreference( tr( "PREF_DUMP_ELEM_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_elem" );
+  addPreference( tr( "PREF_DUMP_ADD_INFO"  ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_add" );
 
   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
   setPreferenceProperty( segGroup, "columns", 2 );
@@ -4845,6 +4883,15 @@ void SMESHGUI::createPreferences()
   setPreferenceProperty( shrink, "min", 0 );
   setPreferenceProperty( shrink, "max", 100 );
 
+  int numGroup = addPreference( tr( "PREF_GROUP_NUMBERING" ), meshTab );
+  setPreferenceProperty( numGroup, "columns", 2 );
+  
+  addPreference( tr( "PREF_NUMBERING_NODE" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_node_color" );
+  addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_node_font", true );
+
+  addPreference( tr( "PREF_NUMBERING_ELEM" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_elem_color" );
+  addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_elem_font", true );
+
   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
   setPreferenceProperty( orientGroup, "columns", 1 );
 
@@ -5031,6 +5078,12 @@ void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
       QString val = aResourceMgr->stringValue( "SMESH", name );
       myComponentSMESH->SetOption( name.toLatin1().constData(), val.toLatin1().constData() );
     }
+    else if ( name == QString( "numbering_node_color" ) || name == QString( "numbering_node_font" ) ) {
+      SMESH::UpdateFontProp( this );    
+    }
+    else if ( name == QString( "numbering_elem_color" ) || name == QString( "numbering_elem_font" ) ) {
+      SMESH::UpdateFontProp( this );
+    }
 
     if(aWarning.size() != 0){
       aWarning += "The default values are applied instead.";
@@ -5403,7 +5456,7 @@ void SMESHGUI::storeVisualParameters (int savePoint)
                   ip->setParameter(entry, param, modeStr.toLatin1().data());
 
                   // Colors
-                  vtkFloatingPointType r, g, b;
+                  double r, g, b;
                   int delta;
 
                   aSmeshActor->GetSufaceColor(r, g, b, delta);
@@ -5542,8 +5595,8 @@ void SMESHGUI::storeVisualParameters (int savePoint)
 typedef struct {
   int Id;
   vtkIdType Orientation;
-  vtkFloatingPointType Distance;
-  vtkFloatingPointType Angle[2];
+  double Distance;
+  double Angle[2];
 } TPlaneData;
 typedef std::list<TPlaneData>         TPlaneDataList;
 typedef std::map<int, TPlaneDataList> TPlaneDataMap;
@@ -6118,7 +6171,7 @@ void SMESHGUI::restoreVisualParameters (int savePoint)
                 if (val != "Off") {
                   SMESH::Orientation anOrientation = (SMESH::Orientation)vals[0].toInt();
                   double aDistance = vals[1].toFloat();
-                  vtkFloatingPointType anAngle[2];
+                  double anAngle[2];
                   anAngle[0] = vals[2].toFloat();
                   anAngle[1] = vals[3].toFloat();
 
@@ -6298,7 +6351,7 @@ void SMESHGUI::restoreVisualParameters (int savePoint)
   \param param parameter
   \return identifier of preferences
 */
-int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param )
+int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param, const bool needSize )
 {
   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "SMESH", param );
 
@@ -6312,6 +6365,7 @@ int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString
   setPreferenceProperty( tfont, "fonts", fam );
 
   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
+  if ( needSize ) f = f | QtxFontEdit::Size;
   setPreferenceProperty( tfont, "features", f );
 
   return tfont;