Salome HOME
bos #35165 [CEA] Clear the mesh when an hypothesis is added to an algorithm
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
index 68791630a070bacdbb64d2f1fe3a7a8ea4f50350..21e94744375d8fa4e7b5d267c1e7b952187f2fdb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -37,6 +37,7 @@
 #include "SMESH_NumberFilter.hxx"
 #include "SMESH_TypeDefs.hxx"
 #include "SMESH_TypeFilter.hxx"
+#include "SMESH_Gen_i.hxx"
 
 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
 
@@ -157,7 +158,7 @@ bool SMESHGUI_MeshOp::onApply()
     if (( myToCreate && !myIsMesh ) || myIsInvalidSubMesh )
       aResult = createSubMesh( aMess, anEntryList );
     else if ( !myToCreate )
-      aResult = editMeshOrSubMesh( aMess );
+      aResult = editMeshOrSubMesh( aMess, anEntryList );
     if ( aResult )
     {
       SMESHGUI::Modified();
@@ -319,25 +320,6 @@ SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const
     return 0;
 }
 
-//================================================================================
-/*!
- * \brief Return type of shape contained in a group
- */
-//================================================================================
-
-TopAbs_ShapeEnum getGroupType(const TopoDS_Shape& group)
-{
-  if ( group.ShapeType() != TopAbs_COMPOUND )
-    return group.ShapeType();
-
-  // iterate on a compound
-  TopoDS_Iterator it( group );
-  if ( it.More() )
-    return getGroupType( it.Value() );
-
-  return TopAbs_SHAPE;
-}
-
 //================================================================================
 /*!
  * \brief check if selected shape is a sub-shape of the shape to mesh
@@ -365,60 +347,17 @@ bool SMESHGUI_MeshOp::isSubshapeOk() const
   QStringList aGEOMs;
   myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
 
-  if (aGEOMs.count() > 0) {
-    GEOM::GEOM_Gen_var geomGen = mainGeom->GetGen();
-    if (geomGen->_is_nil()) return false;
+  // check all selected shapes
+  for ( QString& aSubGeomEntry : aGEOMs )
+  {
+    _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID( aSubGeomEntry.toUtf8().data() );
+    if ( !pSubGeom ) return false;
 
-    GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
-    if (op->_is_nil()) return false;
+    GEOM::GEOM_Object_var subGeom =
+      GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
 
-    // check all selected shapes
-    QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
-    for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++)
-    {
-      QString aSubGeomEntry = (*aSubShapesIter);
-      _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
-      if (!pSubGeom) return false;
-
-      GEOM::GEOM_Object_var aSubGeomVar =
-        GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
-      if (aSubGeomVar->_is_nil()) return false;
-
-      // skl for NPAL14695 - implementation of searching of mainObj
-      GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
-                                                                        mainObj already exists! */
-      while( !mainObj->_is_nil())
-      {
-        CORBA::String_var entry1 = mainObj->GetEntry();
-        CORBA::String_var entry2 = mainGeom->GetEntry();
-        if (std::string( entry1.in() ) == entry2.in() )
-          return true;
-        mainObj = op->GetMainShape(mainObj);
-      }
-      if ( aSubGeomVar->GetShapeType() == GEOM::COMPOUND )
-      {
-        // is aSubGeomVar a compound of sub-shapes?
-        GEOM::GEOM_IShapesOperations_wrap sop = geomGen->GetIShapesOperations();
-        if (sop->_is_nil()) return false;
-        GEOM::ListOfLong_var ids = sop->GetAllSubShapesIDs( aSubGeomVar,
-                                                            GEOM::SHAPE,/*sorted=*/false);
-        if ( ids->length() > 0 )
-        {
-          GEOM_Client geomClient;
-          TopoDS_Shape  subShape = geomClient.GetShape( geomGen, aSubGeomVar );
-          TopoDS_Shape mainShape = geomClient.GetShape( geomGen, mainGeom );
-          if ( subShape.IsNull() || mainShape.IsNull() )
-            return false;
-
-          TopAbs_ShapeEnum subType = getGroupType( subShape );
-          TopTools_IndexedMapOfShape subMap;
-          TopExp::MapShapes( subShape, subType, subMap );
-          for ( TopExp_Explorer exp( mainShape, subType ); exp.More(); exp.Next() )
-            if ( subMap.Contains( exp.Current() ))
-              return true;
-        }
-      }
-    }
+    if ( SMESH::ContainsSubShape( mainGeom, subGeom, false ))
+      return true;
   }
 
   return false;
@@ -2100,7 +2039,10 @@ bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
           elemType = SMESH::NODE;
 
         CORBA::String_var name = geomGroups[ iG ]->GetName();
-        meshGroup = aMesh->CreateGroupFromGEOM( elemType, name, geomGroups[ iG ]);
+
+        SALOMEDS::SObject_wrap groupSO = SMESH_Gen_i::GetSMESHGen()->ObjectToSObject( geomGroups[iG] );
+        if (!groupSO->_is_nil())
+          meshGroup = aMesh->CreateGroupFromGEOM( elemType, name, geomGroups[ iG ]);
         // if ( elemType != SMESH::NODE )
         //   meshGroup = aMesh->CreateGroupFromGEOM( SMESH::NODE, name, geomGroups[ iG ]);
       }
@@ -2635,13 +2577,14 @@ int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
 //================================================================================
 /*!
  * \brief Edits mesh or sub-mesh
-  * \param theMess - Output parameter intended for returning error message
-  * \retval bool  - TRUE if mesh is edited successfully, FALSE otherwise
+  * \param theMess      - Output parameter intended for returning error message
+ *  \param theEntryList - List of entries of published objects
+  * \retval bool        - TRUE if mesh is edited successfully, FALSE otherwise
  *
  * Assigns new name hypotheses and algorithms to the mesh or sub-mesh
  */
 //================================================================================
-bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
+bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess, QStringList& theEntryList)
 {
   theMess = "";
 
@@ -2686,6 +2629,12 @@ bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
   if ( !isMesh && !aSubMeshVar->_is_nil() )
     aMesh = aSubMeshVar->GetFather();
 
+  _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh.in());
+  if (aMeshSO) {
+    SMESH::SetName(aMeshSO, myDlg->objectText(SMESHGUI_MeshDlg::Obj));
+    theEntryList.append(aMeshSO->GetID().c_str());
+  }
+
   // Assign new algorithms and hypotheses
   for ( int dim = aDim; dim <= SMESH::DIM_3D; dim++ )
   {