Salome HOME
[bos #40653][CEA] New mesh import export formats with meshio.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupOnShapeDlg.cxx
index c31a07c449810fb5e3026b632a83119023b997f6..746adb9941ca9dc3e280161a1dcfc92d60b275bd 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -77,7 +77,8 @@ SMESHGUI_GroupOnShapeDlg::SMESHGUI_GroupOnShapeDlg()
 
   // Elem geom
 
-  QGroupBox* elemsGrp = new QGroupBox( tr( "SMESH_ELEMENTS" ), mainFrame() );
+  QGroupBox* elemsGrp = new QGroupBox( tr( "ELEMENTS" ), mainFrame() );
+  elemsGrp->setToolTip( tr("ELEMENTS_TOOLTIP") );
   QLabel* label = new QLabel( tr( "SMESH_GEOM" ), elemsGrp );
   myElemGeomBtn = new QPushButton( elemsGrp );
   myElemGeomBtn->setCheckable(true);
@@ -133,7 +134,7 @@ SMESHGUI_GroupOnShapeDlg::~SMESHGUI_GroupOnShapeDlg()
 
 //================================================================================
 /*!
- * \brief slot to enable/diable [Apply]
+ * \brief slot to enable/disable [Apply]
  */
 //================================================================================
 
@@ -179,7 +180,7 @@ SMESHGUI_GroupOnShapeOp::SMESHGUI_GroupOnShapeOp()
   : SMESHGUI_SelectionOp(ActorSelection),
     myDlg( 0 )
 {
-  myHelpFileName = "create_groups_from_geometry_page.html";
+  myHelpFileName = "create_groups_from_geometry.html";
 }
 
 SMESHGUI_GroupOnShapeOp::~SMESHGUI_GroupOnShapeOp()
@@ -205,11 +206,11 @@ LightApp_Dialog* SMESHGUI_GroupOnShapeOp::dlg() const
  */
 //================================================================================
 
-static SMESH::ElementType elementType(GEOM::GEOM_Object_var geom)
+SMESH::ElementType SMESHGUI_GroupOnShapeOp::ElementType(GEOM::GEOM_Object_var geom)
 {
   if ( !geom->_is_nil() ) {
     switch ( geom->GetShapeType() ) {
-    case GEOM::VERTEX:   return SMESH::NODE;
+    case GEOM::VERTEX:   return SMESH::ELEM0D; // NODE; -- 0023613
     case GEOM::EDGE:     return SMESH::EDGE;
     case GEOM::WIRE:     return SMESH::EDGE;
     case GEOM::FACE:     return SMESH::FACE;
@@ -219,28 +220,28 @@ static SMESH::ElementType elementType(GEOM::GEOM_Object_var geom)
     case GEOM::COMPOUND: break;
     default:             return SMESH::ALL;
     }
-    _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-    GEOM::GEOM_IShapesOperations_wrap aShapeOp =
-      SMESH::GetGEOMGen()->GetIShapesOperations(aStudy->StudyId());
+    GEOM::GEOM_Gen_var                 geomGen = SMESH::GetGEOMGen( geom );
+    GEOM::GEOM_IShapesOperations_wrap aShapeOp = geomGen->GetIShapesOperations();
 
-    if ( geom->GetType() == 37 ) // geom group
-      GEOM::GEOM_IGroupOperations_wrap aGroupOp =
-        SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
+    if ( geom->GetType() == 37 ) // geom group
+    {
+      GEOM::GEOM_IGroupOperations_wrap aGroupOp = geomGen->GetIGroupOperations();
       if ( !aGroupOp->_is_nil() ) {
         // mainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
         GEOM::GEOM_Object_var mainShape = aGroupOp->GetMainShape( geom );
         GEOM::ListOfLong_var        ids = aGroupOp->GetObjects( geom );
         if ( ids->length() && !mainShape->_is_nil() && !aShapeOp->_is_nil() ) {
           GEOM::GEOM_Object_wrap member = aShapeOp->GetSubShape( mainShape, ids[0] );
-          return elementType( member );
+          return ElementType( member );
         }
       }
     }
-    else if ( !aShapeOp->_is_nil() ) { // just a compoud shape
+    else if ( !aShapeOp->_is_nil() ) // just a compoud shape
+    {
       GEOM::ListOfLong_var ids = aShapeOp->SubShapeAllIDs( geom, GEOM::SHAPE, false );
       if ( ids->length() ) {
         GEOM::GEOM_Object_wrap member = aShapeOp->GetSubShape( geom, ids[0] );
-        return elementType( member );
+        return ElementType( member );
       }
     }
   }
@@ -296,15 +297,15 @@ bool SMESHGUI_GroupOnShapeOp::onApply()
 {
   SUIT_OverrideCursor aWaitCursor;
 
-  if (isStudyLocked())
+  if (SMESHGUI::isStudyLocked())
     return false;
 
   // study
-  _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+  _PTR(Study) aStudy = SMESH::getStudy();
   if ( !aStudy ) return false;
 
   // mesh
-  _PTR(SObject) meshSO = aStudy->FindObjectID( myMeshID.toLatin1().data() );
+  _PTR(SObject) meshSO = aStudy->FindObjectID( myMeshID.toUtf8().data() );
   SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( meshSO );
   if ( mesh->_is_nil() ) return false;
 
@@ -330,12 +331,12 @@ bool SMESHGUI_GroupOnShapeOp::onApply()
     for ( int i = 0; geomID != geomEnd; ++geomID, ++i )
     {
       // selected geom
-      _PTR(SObject) geomSO = aStudy->FindObjectID( geomID->toLatin1().data() );
+      _PTR(SObject) geomSO = aStudy->FindObjectID( geomID->toUtf8().data() );
       GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>(geomSO);
       if ( geom->_is_nil() ) continue;
 
       // group type
-      SMESH::ElementType elemType = isNode ? SMESH::NODE : elementType( geom );
+      SMESH::ElementType elemType = isNode ? SMESH::NODE : ElementType( geom );
       if ( elemType == SMESH::ALL )
         continue;
 
@@ -349,7 +350,7 @@ bool SMESHGUI_GroupOnShapeOp::onApply()
 //       groupNames.append( name );
 
       //printf( "apply() %s %s\n", (*geomID).latin1(), name.latin1() );
-      group = mesh->CreateGroupFromGEOM( elemType, name.toLatin1().data(), geom );
+      group = mesh->CreateGroupFromGEOM( elemType, name.toUtf8().data(), geom );
       if( !group->_is_nil() )
         if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( group ) )
           anEntryList.append( aSObject->GetID().c_str() );
@@ -460,31 +461,25 @@ void SMESHGUI_GroupOnShapeOp::selectionDone()
   QStringList goodNames, goodIds;
   if (nbSelected > 0) {
     // study
-    if (_PTR(Study) aStudy = SMESH::GetActiveStudyDocument()) {
+    if (_PTR(Study) aStudy = SMESH::getStudy()) {
       // mesh
-      if (_PTR(SObject)  meshSO = aStudy->FindObjectID( myMeshID.toLatin1().data() )) {
+      if (_PTR(SObject) meshSO = aStudy->FindObjectID( myMeshID.toUtf8().data() ))
+      {
         // shape to mesh
-        _PTR(SObject) anObj, shapeToMesh;
-        if (meshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(shapeToMesh)) {
-          // loop on selected
-          QStringList::iterator name = names.begin(), id = ids.begin(), idEnd = ids.end();
-          for (; id != idEnd; ++id, ++name ) {
-            // shape SO
-            if (_PTR(SObject) shapeSO = aStudy->FindObjectID( id->toLatin1().data() )) {
-            // check if shape SO is a child of shape to mesh 
-              while ( shapeSO && shapeSO->GetID() != shapeToMesh->GetID() )
-                if  ( shapeSO->Depth() < 2 )
-                  shapeSO.reset();
-                else
-                  shapeSO = shapeSO->GetFather();
-              if ( shapeSO ) {
-                //printf( "selectionDone() %s %s\n", (*id).latin1(), (*name).latin1() );
-                if ( !goodIds.contains( *id )) {
-                  goodIds.append( *id );
-                  goodNames.append( *name );
-                }
-              }
-            }
+        GEOM::GEOM_Object_var mainGeom = SMESH::GetGeom( meshSO );
+        // loop on selected
+        QStringList::iterator name = names.begin(), id = ids.begin(), idEnd = ids.end();
+        for (; id != idEnd; ++id, ++name )
+        {
+          if ( goodIds.contains( *id ))
+            continue;
+          // shape SO
+          _PTR(SObject) shapeSO = aStudy->FindObjectID( id->toUtf8().data() );
+          GEOM::GEOM_Object_var subGeom = SMESH::GetGeom( shapeSO );
+          if ( SMESH::ContainsSubShape( mainGeom, subGeom ))
+          {
+            goodIds.append( *id );
+            goodNames.append( *name );
           }
         }
       }
@@ -504,6 +499,6 @@ void SMESHGUI_GroupOnShapeOp::selectionDone()
     myNodeGeoIDs = goodIds;
   }
 
-  // enable/diable Apply, which can change at selection
+  // enable/disable Apply, which can change at selection
   myDlg->updateButtons();
 }