From 7c8fca873e94f56416a3a4267d8f0c6f8fc27026 Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 7 Feb 2020 16:57:31 +0300 Subject: [PATCH] #16522 [CEA 7599] Viscous layers hypothesis: extract layers as a group 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 | 7 ++ src/SMESHGUI/SMESHGUI_Hypotheses.cxx | 2 + src/SMESHGUI/SMESHGUI_VTKUtils.cxx | 80 +++++++++++++++++++ src/SMESHGUI/SMESHGUI_VTKUtils.h | 6 ++ src/SMESH_I/SMESH_2smeshpy.cxx | 7 +- src/SMESH_I/SMESH_Group_i.cxx | 4 +- .../StdMeshersGUI_StdHypothesisCreator.cxx | 49 +++++++++++- .../StdMeshersGUI_StdHypothesisCreator.h | 3 + 8 files changed, 151 insertions(+), 7 deletions(-) diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 82d159350..7a4ad570d 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -4930,7 +4930,14 @@ bool SMESHGUI::activateModule( SUIT_Study* study ) QList wndList = aDesk->windows(); SUIT_ViewWindow* wnd; foreach ( wnd, wndList ) + { connectView( wnd ); + + // remove actors whose objects are removed in GetSMESHGen()->UpdateStudy() + SMESH::UpdateActorsAfterUpdateStudy(wnd); + + wnd->update(); + } } Py_XDECREF(pluginsmanager); diff --git a/src/SMESHGUI/SMESHGUI_Hypotheses.cxx b/src/SMESHGUI/SMESHGUI_Hypotheses.cxx index e9ec762ba..a9ac7f852 100644 --- a/src/SMESHGUI/SMESHGUI_Hypotheses.cxx +++ b/src/SMESHGUI/SMESHGUI_Hypotheses.cxx @@ -335,6 +335,8 @@ void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result ) 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(); } diff --git a/src/SMESHGUI/SMESHGUI_VTKUtils.cxx b/src/SMESHGUI/SMESHGUI_VTKUtils.cxx index d6251e7d6..f0ef5750d 100644 --- a/src/SMESHGUI/SMESHGUI_VTKUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_VTKUtils.cxx @@ -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( 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 wndList = desk->windows(); + SUIT_ViewWindow* wnd; + foreach ( wnd, wndList ) + SMESH::UpdateActorsAfterUpdateStudy(wnd); + } + } + //================================================================================ /*! * \brief Notify the user on problems during visualization diff --git a/src/SMESHGUI/SMESHGUI_VTKUtils.h b/src/SMESHGUI/SMESHGUI_VTKUtils.h index 52919afad..8874d1a80 100644 --- a/src/SMESHGUI/SMESHGUI_VTKUtils.h +++ b/src/SMESHGUI/SMESHGUI_VTKUtils.h @@ -216,6 +216,12 @@ SMESHGUI_EXPORT 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 diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index b22af73eb..c0e892d20 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -1827,7 +1827,7 @@ _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd, const _pyID& meshId): 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) @@ -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(); - 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)) @@ -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 - map >::iterator - m2cmds = myMeth2Commands.begin(); + map<_AString, list >::iterator m2cmds = myMeth2Commands.begin(); for ( ; m2cmds != myMeth2Commands.end(); ++m2cmds ) { list< Handle(_pyCommand)>& cmds = m2cmds->second; diff --git a/src/SMESH_I/SMESH_Group_i.cxx b/src/SMESH_I/SMESH_Group_i.cxx index a2dac404c..a7a7e45eb 100644 --- a/src/SMESH_I/SMESH_Group_i.cxx +++ b/src/SMESH_I/SMESH_Group_i.cxx @@ -171,13 +171,13 @@ char* SMESH_GroupBase_i::GetName() { ::SMESH_Group* aGroup = GetSmeshGroup(); if (aGroup) - return CORBA::string_dup (aGroup->GetName()); + return CORBA::string_dup( aGroup->GetName() ); return CORBA::string_dup( "NO_NAME" ); } //============================================================================= /*! - * + * */ //============================================================================= diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx index 87e9eebe1..be7362b7c 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx @@ -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( submSO ); + SMESH::SMESH_subMesh_var subMesh = SMESH::SObjectToInterface( 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() - * \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 )) { + CORBA::String_var oldName = h->GetGroupName(); h->SetGroupName( nameWg->getName().toUtf8().data() ); + CORBA::String_var newName = h->GetGroupName(); + removeOldGroup( oldName, newName, SMESH::VOLUME ); } } else if( hypType()=="ViscousLayers2D" ) @@ -757,7 +801,10 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const if ( StdMeshersGUI_NameCheckableGrpWdg* nameWg = widget< StdMeshersGUI_NameCheckableGrpWdg >( 5 )) { + CORBA::String_var oldName = h->GetGroupName(); h->SetGroupName( nameWg->getName().toUtf8().data() ); + CORBA::String_var newName = h->GetGroupName(); + removeOldGroup( oldName, newName, SMESH::FACE ); } } // else if( hypType()=="QuadrangleParams" ) diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h index 7e382ed3d..0e984e4d2 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h @@ -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; + void removeOldGroup(const char* oldName, + const char* newName, + SMESH::ElementType type) const; -- 2.39.2