Bug 0019389: Impossible to create a group with a selection in another group.

This commit is contained in:
jfa 2008-07-03 07:33:37 +00:00
parent 4324ec1b43
commit c174b59dd5
2 changed files with 492 additions and 342 deletions

View File

@ -63,6 +63,10 @@
#include "utilities.h"
// VTK Includes
#include <vtkRenderer.h>
#include <vtkActorCollection.h>
// OCCT Includes
#include <TColStd_MapOfInteger.hxx>
@ -485,17 +489,19 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
myGroup = SMESH::SMESH_Group::_nil();
myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
myActor = SMESH::FindActorByObject(myMesh);
SMESH::SetPickable(myActor);
// NPAL19389: create a group with a selection in another group
// set actor of myMesh, if it is visible, else try
// any visible actor of group or submesh of myMesh
SetAppropriateActor();
setDefaultGroupColor();
SALOME_ListIO aList;
mySelectionMgr->selectedObjects( aList );
if( !aList.IsEmpty() )
if ( !aList.IsEmpty() )
{
QString aName = aList.First()->getName();
myMeshGroupLine->setText(aName) ;
myMeshGroupLine->setText(aName);
myMeshGroupLine->home( false );
}
@ -534,8 +540,14 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
myGroup = SMESH::SMESH_Group::_narrow( theGroup );
if ( !myGroup->_is_nil() )
if (!myGroup->_is_nil())
{
// NPAL19389: create a group with a selection in another group
// set actor of myMesh, if it is visible, else set
// actor of myGroup, if it is visible, else try
// any visible actor of group or submesh of myMesh
// commented, because an attempt to set selection on not displayed cells leads to error
//SetAppropriateActor();
myActor = SMESH::FindActorByObject(myMesh);
if ( !myActor )
myActor = SMESH::FindActorByObject(myGroup);
@ -549,6 +561,8 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
setSelectionMode(aType);
myTypeId = aType;
setShowEntityMode(); // depends on myTypeId
myIdList.clear();
if (!myGroup->IsEmpty()) {
SMESH::long_array_var anElements = myGroup->GetListOfID();
@ -566,9 +580,15 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
if ( !myGroupOnGeom->_is_nil() )
{
// NPAL19389: create a group with a selection in another group
// set actor of myMesh, if it is visible, else set
// actor of myGroupOnGeom, if it is visible, else try
// any visible actor of group or submesh of myMesh
// commented, because an attempt to set selection on not displayed cells leads to error
//SetAppropriateActor();
myActor = SMESH::FindActorByObject(myMesh);
if ( !myActor )
myActor = SMESH::FindActorByObject(myGroup);
myActor = SMESH::FindActorByObject(myGroupOnGeom);
SMESH::SetPickable(myActor);
myGrpTypeGroup->setButton(1);
@ -781,7 +801,7 @@ bool SMESHGUI_GroupDlg::onApply()
myGroup->SetColor(aColor);
_PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
if (SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
QValueList<int> aAddList;
@ -906,7 +926,7 @@ bool SMESHGUI_GroupDlg::onApply()
myGroupOnGeom->SetColor(aColor);
_PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
if (SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
}
@ -935,7 +955,7 @@ void SMESHGUI_GroupDlg::onOK()
void SMESHGUI_GroupDlg::onListSelectionChanged()
{
// MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
if( myIsBusy || !myActor) return;
if ( myIsBusy || !myActor) return;
myIsBusy = true;
if (myCurrentLineEdit == 0) {
@ -962,7 +982,7 @@ void SMESHGUI_GroupDlg::onListSelectionChanged()
//=================================================================================
void SMESHGUI_GroupDlg::onObjectSelectionChanged()
{
if ( myIsBusy || !isEnabled()) return;
if (myIsBusy || !isEnabled()) return;
if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
myIsBusy = true;
@ -973,11 +993,13 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
int aNbSel = aList.Extent();
myElements->clearSelection();
if (myCurrentLineEdit) {
if (myCurrentLineEdit)
{
myCurrentLineEdit->setText("");
QString aString = "";
if (myCurrentLineEdit == myMeshGroupLine) {
if (myCurrentLineEdit == myMeshGroupLine)
{
mySelectSubMesh->setEnabled(false);
mySelectGroup->setEnabled(false);
myGroupLine->setText("");
@ -1021,11 +1043,13 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
}
myGroup = SMESH::SMESH_Group::_nil();
myActor = SMESH::FindActorByObject(myMesh);
SMESH::SetPickable(myActor);
// NPAL19389: create a group with a selection in another group
// set actor of myMesh, if it is visible, else try
// any visible actor of group or submesh of myMesh
SetAppropriateActor();
aString = aList.First()->getName();
myMeshGroupLine->setText(aString) ;
myMeshGroupLine->setText(aString);
myMeshGroupLine->home( false );
mySelectSubMesh->setEnabled(true);
@ -1069,9 +1093,9 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
myIsBusy = false;
return;
} else if (myCurrentLineEdit == myGeomGroupLine) {
}
else if (myCurrentLineEdit == myGeomGroupLine)
{
myGeomObjects = new GEOM::ListOfGO();
// The mesh SObject
@ -1092,8 +1116,8 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
int i = 0;
SALOME_ListIteratorOfListIO anIt (aList);
for (; anIt.More(); anIt.Next()) {
for (; anIt.More(); anIt.Next())
{
testResult = Standard_False;
aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
@ -1101,7 +1125,6 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
if (!testResult || CORBA::is_nil(aGeomGroup))
continue;
// Check if group constructed on the same shape as a mesh or on its child
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
GEOM::GEOM_IGroupOperations_var anOp =
@ -1150,13 +1173,13 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
aNbSel = i;
}
if(aNbSel >= 1) {
if(aNbSel > 1) {
if(myCurrentLineEdit == mySubMeshLine)
if (aNbSel >= 1) {
if (aNbSel > 1) {
if (myCurrentLineEdit == mySubMeshLine)
aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
else if(myCurrentLineEdit == myGroupLine)
else if (myCurrentLineEdit == myGroupLine)
aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
else if(myCurrentLineEdit == myGeomGroupLine)
else if (myCurrentLineEdit == myGeomGroupLine)
aString = tr("%1 Objects").arg(aNbSel);
}
else {
@ -1176,9 +1199,46 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
}
updateButtons();
}
else // !myCurrentLineEdit: local selection of nodes or elements
{
if (aNbSel == 1 && myActor && myActor->hasIO())
{
#ifdef ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
// NPAL19389: create a group with a selection in another group
// Switch myActor to the newly selected one, if the last
// is visible and belongs to group or submesh of myMesh
Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
Handle(SALOME_InteractiveObject) selIO = aList.First();
if (curIO->hasEntry() && selIO->hasEntry()) {
const char* selEntry = selIO->getEntry();
if (strcmp(curIO->getEntry(), selEntry) != 0) {
// different objects: selected and myActor
SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
if (aViewWindow && aViewWindow->isVisible(selIO)) {
// newly selected actor is visible
// mesh entry
_PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
if (aSObject) {
CORBA::String_var meshEntry = aSObject->GetID().c_str();
int len = strlen(meshEntry);
if (strncmp(selEntry, meshEntry, len) == 0) {
// selected object is myMesh or a part of it
SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
if (anActor) {
myActor = anActor;
SMESH::SetPickable(myActor);
}
}
}
}
}
}
// NPAL19389 END
#endif // ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
} else {
if (aNbSel == 1 && myActor ) {
QString aListStr = "";
int aNbItems = 0;
if (myTypeId == 0) {
@ -1200,12 +1260,17 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
if (!myActor) {
if (!myGroup->_is_nil())
myActor = SMESH::FindActorByObject(myGroup);
else if(!myGroupOnGeom->_is_nil())
else if (!myGroupOnGeom->_is_nil())
myActor = SMESH::FindActorByObject(myGroupOnGeom);
else
myActor = SMESH::FindActorByObject(myMesh);
}
// somehow, if we display the mesh, while selecting from another actor,
// the mesh becomes pickable, and there is no way to select any element
if (myActor)
SMESH::SetPickable(myActor);
myIsBusy = false;
}
@ -1398,7 +1463,6 @@ void SMESHGUI_GroupDlg::onAdd()
mySelector->SetSelectionMode(ActorSelection);
}
if (myCurrentLineEdit == 0) {
//if (aNbSel != 1) { myIsBusy = false; return; }
QString aListStr = "";
@ -1716,7 +1780,8 @@ void SMESHGUI_GroupDlg::onHelp()
{
LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
if (app)
app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""),
myHelpFileName);
else {
QString platform;
#ifdef WIN32
@ -1724,7 +1789,8 @@ void SMESHGUI_GroupDlg::onHelp()
#else
platform = "application";
#endif
SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
SUIT_MessageBox::warn1
(0, QObject::tr("WRN_WARNING"),
QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
QObject::tr("BUT_OK"));
@ -1944,7 +2010,7 @@ SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
//=================================================================================
void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
{
if( theColor.isValid() )
if ( theColor.isValid() )
{
QPalette pal = myColorBtn->palette();
pal.setColor(QColorGroup::Button, theColor);
@ -1968,13 +2034,13 @@ QColor SMESHGUI_GroupDlg::getGroupQColor() const
//=================================================================================
void SMESHGUI_GroupDlg::setDefaultGroupColor()
{
if( myMesh->_is_nil() )
if ( myMesh->_is_nil() )
return;
bool isAutoColor = myMesh->GetAutoColor();
QColor aQColor;
if( !isAutoColor )
if ( !isAutoColor )
{
int r = 0, g = 0, b = 0;
SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
@ -1985,7 +2051,7 @@ void SMESHGUI_GroupDlg::setDefaultGroupColor()
SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
QValueList<SALOMEDS::Color> aReservedColors;
for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
for ( int i = 0, n = aListOfGroups.length(); i < n; i++ )
{
SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
@ -2002,11 +2068,95 @@ void SMESHGUI_GroupDlg::setDefaultGroupColor()
setGroupQColor( aQColor );
}
//=================================================================================
// function : SetAppropriateActor()
// purpose : Find more appropriate of visible actors, set it to myActor, allow picking
// NPAL19389: create a group with a selection in another group.
// if mesh actor is not visible - find any first visible group or submesh
//=================================================================================
bool SMESHGUI_GroupDlg::SetAppropriateActor()
{
bool isActor = false;
if (myMesh->_is_nil()) return false;
SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
// try mesh actor
myActor = SMESH::FindActorByObject(myMesh);
if (myActor && myActor->hasIO())
{
isActor = true;
if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
isActor = false;
}
// try current group actor
if (!isActor) {
if (!myGroup->_is_nil()) {
myActor = SMESH::FindActorByObject(myGroup);
if (myActor && myActor->hasIO())
{
isActor = true;
if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
isActor = false;
}
}
}
// try current group on geometry actor
if (!isActor) {
if (!myGroupOnGeom->_is_nil()) {
myActor = SMESH::FindActorByObject(myGroupOnGeom);
if (myActor && myActor->hasIO())
{
isActor = true;
if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
isActor = false;
}
}
}
// try any visible actor of group or submesh of current mesh
if (!isActor && aViewWindow) {
// mesh entry
_PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
if (aSObject) {
CORBA::String_var meshEntry = aSObject->GetID().c_str();
int len = strlen(meshEntry);
// iterate on all actors in current view window, search for
// any visible actor, that belongs to group or submesh of current mesh
vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
aCollection->InitTraversal();
for (vtkActor *anAct = aCollection->GetNextActor();
anAct && !isActor;
anAct = aCollection->GetNextActor())
{
SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct);
if (anActor && anActor->hasIO()) {
Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
if (aViewWindow->isVisible(anIO)) {
if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0) {
myActor = anActor;
isActor = true;
}
}
}
}
}
}
if (isActor)
SMESH::SetPickable(myActor);
return isActor;
}
//=======================================================================
//function : setShowEntityMode
//purpose : make shown only entity corresponding to my type
//=======================================================================
void SMESHGUI_GroupDlg::setShowEntityMode()
{
if ( !myMesh->_is_nil() ) {
@ -2027,7 +2177,6 @@ void SMESHGUI_GroupDlg::setShowEntityMode()
//function : restoreShowEntityMode
//purpose : restore ShowEntity mode of myActor
//=======================================================================
void SMESHGUI_GroupDlg::restoreShowEntityMode()
{
if ( myStoredShownEntity && !myMesh->_is_nil() ) {

View File

@ -132,6 +132,7 @@ private:
void setSelectionMode(int theMode);
void updateButtons();
void updateGeomPopup();
bool SetAppropriateActor();
void setShowEntityMode();
void restoreShowEntityMode();