]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
PAL11418. fix isSubshapeOk()
authoreap <eap@opencascade.com>
Wed, 1 Feb 2006 12:09:29 +0000 (12:09 +0000)
committereap <eap@opencascade.com>
Wed, 1 Feb 2006 12:09:29 +0000 (12:09 +0000)
src/SMESHGUI/SMESHGUI_MeshOp.cxx

index 57103003df755799fd70c7b681ec80928c27e696..1bf664dfd35217daae8274445f434ecd47a45a9b 100644 (file)
@@ -297,8 +297,25 @@ bool SMESHGUI_MeshOp::isSubshapeOk() const
         TopoDS_Shape mainShape, subShape;
         if ( GEOMBase::GetShape( mainGeom, mainShape ) &&
              GEOMBase::GetShape( subGeom, subShape ) )
-          // 1 is index of mainShape itself
-          return GEOMBase::GetIndex( subShape, mainShape, 0 ) > 1;
+        {
+          int index = GEOMBase::GetIndex( subShape, mainShape, 0 );
+          if ( index > 0 ) {
+            // 1 is index of mainShape itself
+            return index > 1; // it is a subshape
+          }
+          // is it a group?
+          GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
+          _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+          if ( !geomGen->_is_nil() && aStudy ) {
+            GEOM::GEOM_IGroupOperations_var op =
+              geomGen->GetIGroupOperations( aStudy->StudyId() );
+            if ( ! op->_is_nil() ) {
+              GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom );
+              if ( !mainObj->_is_nil() )
+                return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() ));
+            }
+          }
+        }
       }
     }
   }
@@ -362,11 +379,55 @@ _PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
 //================================================================================
 void SMESHGUI_MeshOp::selectionDone()
 {
+  if ( myShapeByMeshDlg && myShapeByMeshDlg->isShown() )
+    return;
+
   SMESHGUI_SelectionOp::selectionDone();
 
   try
   {
-    if ( !myToCreate ) // edition
+    // Enable tabs according to shape dimension
+
+    int shapeDim = 3;
+
+    GEOM::GEOM_Object_var aGeomVar;
+    QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+    _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
+    if ( pGeom ) {
+      aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
+    }
+    else {
+      QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
+      _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
+      aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
+    }
+    if ( !aGeomVar->_is_nil() ) {
+      shapeDim = 0;
+      switch ( aGeomVar->GetShapeType() ) {
+      case GEOM::SOLID:
+      case GEOM::SHELL:  shapeDim = 3; break;
+      case GEOM::FACE:   shapeDim = 2; break;
+      case GEOM::WIRE:   
+      case GEOM::EDGE:   shapeDim = 1; break;
+      case GEOM::VERTEX: shapeDim = 0; break;
+      default:
+        TopoDS_Shape aShape;
+        if ( GEOMBase::GetShape(aGeomVar, aShape)) {
+          TopExp_Explorer exp( aShape, TopAbs_SHELL );
+          if ( exp.More() )
+            shapeDim = 3;
+          else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
+            shapeDim = 2;
+          else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
+            shapeDim = 1;
+          else
+            shapeDim = 0;
+        }
+      }
+    }
+    myDlg->setMaxHypoDim( shapeDim );
+
+    if ( !myToCreate ) // edition: read hypotheses
     {
       QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
       _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
@@ -400,6 +461,7 @@ void SMESHGUI_MeshOp::selectionDone()
           selectionMgr()->clearFilters();
           selectObject( pSubmesh );
           SMESHGUI::GetSMESHGUI()->switchToOperation(704);
+          return;
         }
         else
         {
@@ -407,59 +469,16 @@ void SMESHGUI_MeshOp::selectionDone()
           myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
         }
       }
-      // enable/disable popup for choice of geom selection way
-      myDlg->setGeomPopupEnabled( !myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ).isEmpty() );
-
-    }
-  }
-  catch ( const SALOME::SALOME_Exception& S_ex )
-  {
-    SalomeApp_Tools::QtCatchCorbaException( S_ex );
-  }
-  catch ( ... )
-  {
-  }
 
-
-  // Enable tabs according to shape dimension
-
-  int shapeDim = 3;
-  try
-  {
-    GEOM::GEOM_Object_var aGeomVar;
-    QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
-    _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
-    if ( pGeom ) {
-      aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
-    }
-    else {
-      QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
-      _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
-      aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
-    }
-    if ( !aGeomVar->_is_nil() ) {
-      shapeDim = 0;
-      switch ( aGeomVar->GetShapeType() ) {
-      case GEOM::SOLID:
-      case GEOM::SHELL:  shapeDim = 3; break;
-      case GEOM::FACE:   shapeDim = 2; break;
-      case GEOM::WIRE:   
-      case GEOM::EDGE:   shapeDim = 1; break;
-      case GEOM::VERTEX: shapeDim = 0; break;
-      default:
-        TopoDS_Shape aShape;
-        if ( GEOMBase::GetShape(aGeomVar, aShape)) {
-          TopExp_Explorer exp( aShape, TopAbs_SHELL );
-          if ( exp.More() )
-            shapeDim = 3;
-          else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
-            shapeDim = 2;
-          else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
-            shapeDim = 1;
-          else
-            shapeDim = 0;
-        }
-      }
+      // enable/disable popup for choice of geom selection way
+      bool enable = false;
+      QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
+      if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) {
+        SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
+        if ( !mesh->_is_nil() )
+          enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 );
+      }            
+      myDlg->setGeomPopupEnabled( enable );
     }
   }
   catch ( const SALOME::SALOME_Exception& S_ex )
@@ -469,7 +488,6 @@ void SMESHGUI_MeshOp::selectionDone()
   catch ( ... )
   {
   }
-  myDlg->setMaxHypoDim( shapeDim );
 }
 
 //================================================================================
@@ -1460,6 +1478,7 @@ void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
         SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
       if ( !aMeshVar->_is_nil() ) {
         myDlg->hide();
+        myDlg->activateObject( SMESHGUI_MeshDlg::Mesh );
         myShapeByMeshDlg->Init();
         myShapeByMeshDlg->SetMesh( aMeshVar );
         myShapeByMeshDlg->show();
@@ -1476,8 +1495,6 @@ void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
 
 void SMESHGUI_MeshOp::onPublishShapeByMeshDlg()
 {
-  onCloseShapeByMeshDlg();
-
   if ( myShapeByMeshDlg ) {
     // Select a found geometry object
     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshDlg->GetShape();
@@ -1485,16 +1502,28 @@ void SMESHGUI_MeshOp::onPublishShapeByMeshDlg()
     {
       QString ID = aGeomVar->GetStudyEntry();
       if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID )) {
+        SMESH::SMESH_Mesh_ptr aMeshPtr = myShapeByMeshDlg->GetMesh();
+        if ( !CORBA::is_nil( aMeshPtr )) {
+          if (_PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshPtr )) {
+            myDlg->activateObject( SMESHGUI_MeshDlg::Mesh );
+            myDlg->selectObject( aMeshSO->GetName(), SMESHGUI_MeshDlg::Mesh, aMeshSO->GetID() );
+          }
+        }
+        myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
         selectObject( aGeomSO );
-        selectionDone();
+        //selectionDone();
       }
     }
+    else {
+      onCloseShapeByMeshDlg();
+    }
   }
+  myDlg->show();
 }
 
 //================================================================================
 /*!
- * \brief SLOT. Is called Close Ok is pressed in SMESHGUI_ShapeByMeshDlg
+ * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
  */
 //================================================================================
 
@@ -1502,8 +1531,8 @@ void SMESHGUI_MeshOp::onCloseShapeByMeshDlg()
 {
   if ( myDlg ) {
     myDlg->show();
-    myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
     myDlg->activateObject( SMESHGUI_MeshDlg::Geom );
+    myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
   }
 }