Salome HOME
#16522 [CEA 7599] Viscous layers hypothesis: extract layers as a group
authoreap <eap@opencascade.com>
Fri, 7 Feb 2020 13:57:31 +0000 (16:57 +0300)
committereap <eap@opencascade.com>
Fri, 14 Feb 2020 15:11:57 +0000 (18:11 +0300)
1) Fix invalid python dump (missing Compute() before GetGroups())
2) Remove a group if group name changes
3) Remove an actor of a removed group

src/SMESHGUI/SMESHGUI.cxx
src/SMESHGUI/SMESHGUI_Hypotheses.cxx
src/SMESHGUI/SMESHGUI_VTKUtils.cxx
src/SMESHGUI/SMESHGUI_VTKUtils.h
src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_Group_i.cxx
src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx
src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h

index deb3711c98137118d89efaf5052d15fffff3b381..8eb92b364dac31a780f967abd152bfd5e83e20d2 100644 (file)
@@ -4930,7 +4930,14 @@ bool SMESHGUI::activateModule( SUIT_Study* study )
     QList<SUIT_ViewWindow*> wndList = aDesk->windows();
     SUIT_ViewWindow* wnd;
     foreach ( wnd, wndList )
     QList<SUIT_ViewWindow*> wndList = aDesk->windows();
     SUIT_ViewWindow* wnd;
     foreach ( wnd, wndList )
+    {
       connectView( wnd );
       connectView( wnd );
+
+      // remove actors whose objects are removed in GetSMESHGen()->UpdateStudy()
+      SMESH::UpdateActorsAfterUpdateStudy(wnd);
+
+      wnd->update();
+    }
   }
 
   Py_XDECREF(pluginsmanager);
   }
 
   Py_XDECREF(pluginsmanager);
index 521966bf7980d3941279a6ad2247371e311f3b28..b2e1e2496f0a27467720213ee1ed6152dfe603fd 100644 (file)
@@ -340,6 +340,8 @@ void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result )
   myDlg->close();
   //delete myDlg; since WA_DeleteOnClose==true
   myDlg = 0;
   myDlg->close();
   //delete myDlg; since WA_DeleteOnClose==true
   myDlg = 0;
+
+  SMESH::UpdateActorsAfterUpdateStudy();// remove actors of removed groups (#16522)
   if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView()) {
     vf->Repaint();
   }
   if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView()) {
     vf->Repaint();
   }
index d6251e7d6d64c3fa60c0c52c395868d425a02d76..f0ef5750d733f49ce670d4834bca29ee279561ef 100644 (file)
@@ -232,6 +232,86 @@ namespace SMESH
     }
   }
 
     }
   }
 
+  //================================================================================
+  /*!
+   * \brief Remove/update actors while module activation
+   *  \param [in] wnd - window
+   *
+   * At module activation, groups and sub-meshes can be removed on engine side due
+   * to modification of meshed geometry, while their actors can remain.
+   * Here we remove/update SMESH_Actor's of changed objects. State (emptiness) of objects
+   * is defined by their icons in the Object Browser
+   */
+  //================================================================================
+
+  void UpdateActorsAfterUpdateStudy( SUIT_ViewWindow* theWindow )
+  {
+    const char* emptyIcon = "ICON_SMESH_TREE_MESH_WARN";
+    _PTR(Study) aStudy = SMESH::getStudy();
+
+    if ( SVTK_ViewWindow* aViewWindow = GetVtkViewWindow( theWindow ))
+    {
+      vtkRenderer *aRenderer = aViewWindow->getRenderer();
+      VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
+      vtkActorCollection *aCollection = aCopy.GetActors();
+      aCollection->InitTraversal();
+      while ( vtkActor *actor = aCollection->GetNextActor() ) {
+        if ( SMESH_Actor *smeshActor = dynamic_cast<SMESH_Actor*>( actor ))
+        {
+          if ( !smeshActor->hasIO() )
+            continue;
+          Handle(SALOME_InteractiveObject) io = smeshActor->getIO();
+          if ( !io->hasEntry() )
+            continue;
+          _PTR(SObject) so = aStudy->FindObjectID( io->getEntry() );
+          if ( !so )
+            continue; // seems impossible
+
+          CORBA::Object_var obj = SMESH::SObjectToObject( so );
+          if ( CORBA::is_nil( obj )) // removed object
+          {
+            RemoveActor( theWindow, smeshActor );
+            continue;
+          }
+
+          bool toShow = smeshActor->GetVisibility();
+          _PTR(GenericAttribute) attr;
+          if ( toShow && so->FindAttribute( attr, "AttributePixMap" )) // check emptiness
+          {
+            _PTR(AttributePixMap) pixMap = attr;
+            toShow = ( pixMap->GetPixMap() != emptyIcon );
+          }
+          smeshActor->Update();
+          UpdateView( theWindow, toShow ? eDisplay : eErase, io->getEntry() );
+        }
+      }
+    }
+    return;
+  }
+
+  //================================================================================
+  /*!
+   * \brief Remove/update actors while module activation
+   *
+   * At module activation, groups and sub-meshes can be removed on engine side due
+   * to modification of meshed geometry, while their actors can remain.
+   * Here we remove/update SMESH_Actor's of changed objects. State (emptiness) of objects
+   * is defined by their icons in the Object Browser
+   */
+  //================================================================================
+
+  void UpdateActorsAfterUpdateStudy()
+  {
+    SUIT_Study* study = SMESH::GetActiveStudy();
+    if ( SUIT_Desktop* desk = study->application()->desktop() )
+    {
+      QList<SUIT_ViewWindow*> wndList = desk->windows();
+      SUIT_ViewWindow* wnd;
+      foreach ( wnd, wndList )
+        SMESH::UpdateActorsAfterUpdateStudy(wnd);
+    }
+  }
+
   //================================================================================
   /*!
    * \brief Notify the user on problems during visualization
   //================================================================================
   /*!
    * \brief Notify the user on problems during visualization
index 52919afad6a7a3a778b4245b8cc9df8426e0df48..8874d1a80e9b6c5a623a0c867aad603013184909 100644 (file)
@@ -216,6 +216,12 @@ SMESHGUI_EXPORT
                            double& theDist );
  SMESHGUI_EXPORT
    void RemoveVisualObjectWithActors( const char* theEntry, bool fromAllViews = false );
                            double& theDist );
  SMESHGUI_EXPORT
    void RemoveVisualObjectWithActors( const char* theEntry, bool fromAllViews = false );
+
+  SMESHGUI_EXPORT
+  void UpdateActorsAfterUpdateStudy( SUIT_ViewWindow* wnd );
+
+  SMESHGUI_EXPORT
+  void UpdateActorsAfterUpdateStudy();
 };
 
 #endif // SMESHGUI_VTKUTILS_H
 };
 
 #endif // SMESHGUI_VTKUTILS_H
index b22af73ebdb34d756c8a7364e697759a19b80f68..c0e892d204c6f275b9458d3a8ff9d22e9423cc32 100644 (file)
@@ -1827,7 +1827,7 @@ _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd, const _pyID& meshId):
 
 void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
 {
 
 void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
 {
-  // some methods of SMESH_Mesh interface needs special conversion
+  // some methods of SMESH_Mesh interface need special conversion
   // to methods of Mesh python class
   //
   // 1. GetSubMesh(geom, name) + AddHypothesis(geom, algo)
   // to methods of Mesh python class
   //
   // 1. GetSubMesh(geom, name) + AddHypothesis(geom, algo)
@@ -1980,7 +1980,7 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
       // if GetGroups() is just after Compute(), this can mean that the groups
       // were created by some algorithm and hence Compute() should not be discarded
       std::list< Handle(_pyCommand) >& cmdList = theGen->GetCommands();
       // if GetGroups() is just after Compute(), this can mean that the groups
       // were created by some algorithm and hence Compute() should not be discarded
       std::list< Handle(_pyCommand) >& cmdList = theGen->GetCommands();
-      std::list< Handle(_pyCommand) >::iterator cmd = cmdList.begin();
+      std::list< Handle(_pyCommand) >::reverse_iterator cmd = cmdList.rbegin();
       while ( (*cmd)->GetMethod() == "GetGroups" )
         ++cmd;
       if ( myLastComputeCmd == (*cmd))
       while ( (*cmd)->GetMethod() == "GetGroups" )
         ++cmd;
       if ( myLastComputeCmd == (*cmd))
@@ -3158,8 +3158,7 @@ void _pyHypothesis::ComputeDiscarded( const Handle(_pyCommand)& theComputeCmd )
       continue;
     // check if a cmd is a sole command setting its parameter;
     // don't use method name for search as it can change
       continue;
     // check if a cmd is a sole command setting its parameter;
     // don't use method name for search as it can change
-    map<TCollection_AsciiString, list<Handle(_pyCommand)> >::iterator
-      m2cmds = myMeth2Commands.begin();
+    map<_AString, list<Handle(_pyCommand)> >::iterator m2cmds = myMeth2Commands.begin();
     for ( ; m2cmds != myMeth2Commands.end(); ++m2cmds )
     {
       list< Handle(_pyCommand)>& cmds = m2cmds->second;
     for ( ; m2cmds != myMeth2Commands.end(); ++m2cmds )
     {
       list< Handle(_pyCommand)>& cmds = m2cmds->second;
index a2dac404ce7426600a13c05db7fedacbe5b4e726..a7a7e45eb69e223adbe6b7a7f2193139f2efcbe8 100644 (file)
@@ -171,13 +171,13 @@ char* SMESH_GroupBase_i::GetName()
 {
   ::SMESH_Group* aGroup = GetSmeshGroup();
   if (aGroup)
 {
   ::SMESH_Group* aGroup = GetSmeshGroup();
   if (aGroup)
-    return CORBA::string_dup (aGroup->GetName());
+    return CORBA::string_dup( aGroup->GetName() );
   return CORBA::string_dup( "NO_NAME" );
 }
 
 //=============================================================================
 /*!
   return CORBA::string_dup( "NO_NAME" );
 }
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
  */
 //=============================================================================
 
index f16b06011819e3d5c59ec359aed926e3fa3de51e..1a749bef81405fb4a02b6b7a6704ab746964d390 100644 (file)
@@ -378,10 +378,51 @@ namespace {
   }
 }
 
   }
 }
 
+//================================================================================
+/*!
+ * \brief Remove a group, whose name is stored by hypothesis, upon group name modification
+ *  \param [in] oldName - old group name
+ *  \param [in] newName - new group name
+ *  \param [in] type - group type
+ */
+//================================================================================
+
+void StdMeshersGUI_StdHypothesisCreator::
+removeOldGroup(const char* oldName, const char* newName, SMESH::ElementType type) const
+{
+  if ( !oldName || !oldName[0] )
+    return; // old name undefined
+  if ( newName && strcmp( oldName, newName ) == 0 )
+    return; // same name
+
+  SMESH::SMESH_Hypothesis_var h = hypothesis();
+  SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( h );
+  for ( size_t i = 0; i < listSOmesh.size(); i++ )
+  {
+    _PTR(SObject) submSO = listSOmesh[i];
+    SMESH::SMESH_Mesh_var       mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
+    SMESH::SMESH_subMesh_var subMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
+    if( !subMesh->_is_nil() )
+      mesh = subMesh->GetFather();
+    if ( mesh->_is_nil() )
+      continue;
+    SMESH::ListOfGroups_var groups = mesh->GetGroups();
+    for ( CORBA::ULong iG = 0; iG < groups->length(); iG++ )
+    {
+      if ( groups[iG]->GetType() != type )
+        continue;
+      CORBA::String_var name = groups[iG]->GetName();
+      if ( strcmp( name.in(), oldName ))
+        continue;
+      mesh->RemoveGroup( groups[iG] );
+    }
+  }
+}
+
 //================================================================================
 /*!
  * \brief Check parameter values before accept()
 //================================================================================
 /*!
  * \brief Check parameter values before accept()
 * \retval bool - true if OK
 \retval bool - true if OK
  */
 //================================================================================
 
  */
 //================================================================================
 
@@ -733,7 +774,10 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
       if ( StdMeshersGUI_NameCheckableGrpWdg* nameWg =
            widget< StdMeshersGUI_NameCheckableGrpWdg >( 6 ))
       {
       if ( StdMeshersGUI_NameCheckableGrpWdg* nameWg =
            widget< StdMeshersGUI_NameCheckableGrpWdg >( 6 ))
       {
+        CORBA::String_var oldName = h->GetGroupName();
         h->SetGroupName( nameWg->getName().toUtf8().data() );
         h->SetGroupName( nameWg->getName().toUtf8().data() );
+        CORBA::String_var newName = h->GetGroupName();
+        removeOldGroup( oldName, newName, SMESH::VOLUME );
       }
     }
     else if( hypType()=="ViscousLayers2D" )
       }
     }
     else if( hypType()=="ViscousLayers2D" )
@@ -757,7 +801,10 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
       if ( StdMeshersGUI_NameCheckableGrpWdg* nameWg =
            widget< StdMeshersGUI_NameCheckableGrpWdg >( 5 ))
       {
       if ( StdMeshersGUI_NameCheckableGrpWdg* nameWg =
            widget< StdMeshersGUI_NameCheckableGrpWdg >( 5 ))
       {
+        CORBA::String_var oldName = h->GetGroupName();
         h->SetGroupName( nameWg->getName().toUtf8().data() );
         h->SetGroupName( nameWg->getName().toUtf8().data() );
+        CORBA::String_var newName = h->GetGroupName();
+        removeOldGroup( oldName, newName, SMESH::FACE );
       }
     }
     // else if( hypType()=="QuadrangleParams" )
       }
     }
     // else if( hypType()=="QuadrangleParams" )
index 7e382ed3d51c4df4fcda1f3bf001b779547a54f4..0e984e4d27638eb98b02b1a06f50df6476930118 100644 (file)
@@ -66,6 +66,9 @@ protected:
   bool             initVariableName(SMESH::SMESH_Hypothesis_var theHyp, StdParam& theParams, const char* theMethod) const;
   QWidget*         makeReverseEdgesWdg( SMESH::long_array_var edgeIDs,
                                         CORBA::String_var     shapeEntry) const;
   bool             initVariableName(SMESH::SMESH_Hypothesis_var theHyp, StdParam& theParams, const char* theMethod) const;
   QWidget*         makeReverseEdgesWdg( SMESH::long_array_var edgeIDs,
                                         CORBA::String_var     shapeEntry) const;
+  void             removeOldGroup(const char*        oldName,
+                                  const char*        newName,
+                                  SMESH::ElementType type) const;