Mesh module improvement related to selection of geometrical objects in mesh group and sub-mesh creation GUI.

This commit is contained in:
mzn 2006-11-30 07:48:32 +00:00
parent ac1bc3bab0
commit 158db6afbf
7 changed files with 486 additions and 122 deletions

View File

@ -187,6 +187,14 @@ module SMESH
in string theGeomName) in string theGeomName)
raises ( SALOME::SALOME_Exception ); raises ( SALOME::SALOME_Exception );
/*!
* Return geometrical object the given element is built on.
* The returned geometrical object not published in study by this method.
*/
GEOM::GEOM_Object FindGeometryByMeshElement( in SMESH_Mesh theMesh,
in long theElementID)
raises ( SALOME::SALOME_Exception );
}; };
}; };

View File

@ -28,6 +28,7 @@
#include "SMESHGUI_GroupDlg.h" #include "SMESHGUI_GroupDlg.h"
#include "SMESHGUI_FilterDlg.h" #include "SMESHGUI_FilterDlg.h"
#include "SMESHGUI_ShapeByMeshDlg.h"
#include "SMESHGUI.h" #include "SMESHGUI.h"
#include "SMESHGUI_Utils.h" #include "SMESHGUI_Utils.h"
@ -39,7 +40,9 @@
#include "SMESH_TypeFilter.hxx" #include "SMESH_TypeFilter.hxx"
#include "SMESH_Actor.h" #include "SMESH_Actor.h"
#include "GEOMBase.h" #include "GEOMBase.h"
#include "GEOM_SelectionFilter.h"
#include "SUIT_Desktop.h" #include "SUIT_Desktop.h"
#include "SUIT_ResourceMgr.h" #include "SUIT_ResourceMgr.h"
@ -47,6 +50,8 @@
#include "SUIT_MessageBox.h" #include "SUIT_MessageBox.h"
#include "SalomeApp_Tools.h" #include "SalomeApp_Tools.h"
#include "SalomeApp_Application.h"
#include "SalomeApp_Study.h"
#include "LightApp_Application.h" #include "LightApp_Application.h"
#include "SALOMEDSClient_Study.hxx" #include "SALOMEDSClient_Study.hxx"
#include "SALOME_ListIO.hxx" #include "SALOME_ListIO.hxx"
@ -62,11 +67,13 @@
// QT Includes // QT Includes
#include <qbuttongroup.h> #include <qbuttongroup.h>
#include <qcursor.h>
#include <qgroupbox.h> #include <qgroupbox.h>
#include <qhbox.h> #include <qhbox.h>
#include <qlabel.h> #include <qlabel.h>
#include <qlineedit.h> #include <qlineedit.h>
#include <qpushbutton.h> #include <qpushbutton.h>
#include <qtoolbutton.h>
#include <qradiobutton.h> #include <qradiobutton.h>
#include <qcheckbox.h> #include <qcheckbox.h>
#include <qlayout.h> #include <qlayout.h>
@ -147,6 +154,11 @@ void SMESHGUI_GroupDlg::initDialog(bool create)
myCreate = create; myCreate = create;
myCurrentLineEdit = 0; myCurrentLineEdit = 0;
myShapeByMeshOp = 0;
myGeomPopup = 0;
myGeomObjects = new GEOM::ListOfGO();
myGeomObjects->length(0);
QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT"))); QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
if (create) { if (create) {
@ -278,9 +290,9 @@ void SMESHGUI_GroupDlg::initDialog(bool create)
/***************************************************************/ /***************************************************************/
QLabel* geomObject = new QLabel(wg2, "geometry object label"); QLabel* geomObject = new QLabel(wg2, "geometry object label");
geomObject->setText(tr("SMESH_OBJECT_GEOM")); geomObject->setText(tr("SMESH_OBJECT_GEOM"));
myGeomGroupBtn = new QPushButton(wg2, "geometry group button"); myGeomGroupBtn = new QToolButton(wg2, "geometry group button");
myGeomGroupBtn->setText(""); myGeomGroupBtn->setIconSet( QIconSet(image0) );
myGeomGroupBtn->setPixmap(image0); myGeomGroupBtn->setToggleButton(true);
myGeomGroupLine = new QLineEdit(wg2, "geometry group line"); myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
myGeomGroupLine->setReadOnly(true); //VSR ??? myGeomGroupLine->setReadOnly(true); //VSR ???
onSelectGeomGroup(false); onSelectGeomGroup(false);
@ -378,7 +390,7 @@ void SMESHGUI_GroupDlg::initDialog(bool create)
connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool))); connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
connect(myGeomGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
connect(mySelectColorGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectColorGroup(bool))); connect(mySelectColorGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectColorGroup(bool)));
connect(myColorSpinBox, SIGNAL(valueChanged(const QString&)), this, SLOT(onNbColorsChanged(const QString&))); connect(myColorSpinBox, SIGNAL(valueChanged(const QString&)), this, SLOT(onNbColorsChanged(const QString&)));
@ -395,6 +407,8 @@ void SMESHGUI_GroupDlg::initDialog(bool create)
myMeshFilter = new SMESH_TypeFilter(MESH); myMeshFilter = new SMESH_TypeFilter(MESH);
mySubMeshFilter = new SMESH_TypeFilter(SUBMESH); mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
myGroupFilter = new SMESH_TypeFilter(GROUP); myGroupFilter = new SMESH_TypeFilter(GROUP);
SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate())); connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose())); connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
@ -546,7 +560,7 @@ void SMESHGUI_GroupDlg::updateButtons()
else if (myGrpTypeId == 1) else if (myGrpTypeId == 1)
{ {
bool isEditMode = !CORBA::is_nil( myGroupOnGeom ); bool isEditMode = !CORBA::is_nil( myGroupOnGeom );
enable = !myName->text().stripWhiteSpace().isEmpty() && (!CORBA::is_nil( myGeomGroup ) || isEditMode); enable = !myName->text().stripWhiteSpace().isEmpty() && (myGeomObjects->length() > 0 || isEditMode);
} }
QPushButton* aBtn; QPushButton* aBtn;
aBtn = (QPushButton*) child("ok", "QPushButton"); aBtn = (QPushButton*) child("ok", "QPushButton");
@ -609,10 +623,12 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
// PAL7314 // PAL7314
if (myMesh->_is_nil()) if (myMesh->_is_nil())
return; return;
if (mySelectionMode != theMode) { if (mySelectionMode != theMode) {
// [PAL10408] mySelectionMgr->clearSelected(); // [PAL10408] mySelectionMgr->clearSelected();
mySelectionMgr->clearFilters(); mySelectionMgr->clearFilters();
if (myActor)
myActor->SetPointRepresentation(false);
else
SMESH::SetPointRepresentation(false); SMESH::SetPointRepresentation(false);
if (theMode < 4) { if (theMode < 4) {
switch (theMode) { switch (theMode) {
@ -643,6 +659,9 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
mySelectionMgr->installFilter(myGroupFilter); mySelectionMgr->installFilter(myGroupFilter);
else if (theMode == 6) else if (theMode == 6)
mySelectionMgr->installFilter(myMeshFilter); mySelectionMgr->installFilter(myMeshFilter);
else if (theMode == 7)
mySelectionMgr->installFilter(myGeomFilter);
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode(ActorSelection); aViewWindow->SetSelectionMode(ActorSelection);
} }
@ -742,7 +761,7 @@ bool SMESHGUI_GroupDlg::onApply()
return true; return true;
} else if (myGrpTypeId == 1 && } else if (myGrpTypeId == 1 &&
!myName->text().stripWhiteSpace().isEmpty() && !myName->text().stripWhiteSpace().isEmpty() &&
(!CORBA::is_nil(myGeomGroup) || !CORBA::is_nil(myGroupOnGeom))) (myGeomObjects->length() > 0 || !CORBA::is_nil(myGroupOnGeom)))
{ {
if (myGroupOnGeom->_is_nil()) { if (myGroupOnGeom->_is_nil()) {
SMESH::ElementType aType = SMESH::ALL; SMESH::ElementType aType = SMESH::ALL;
@ -757,7 +776,55 @@ bool SMESHGUI_GroupDlg::onApply()
GEOM::GEOM_IGroupOperations_var aGroupOp = GEOM::GEOM_IGroupOperations_var aGroupOp =
SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomGroup); if (myGeomObjects->length() == 1)
myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
else
{
SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
if ( aSMESHGen->_is_nil() )
return false;
// create a geometry group
GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
if (geomGen->_is_nil() || !aStudy)
return false;
GEOM::GEOM_IGroupOperations_var op =
geomGen->GetIGroupOperations(aStudy->StudyId());
if (op->_is_nil())
return false;
// check and add all selected GEOM objects: they must be
// a sub-shapes of the main GEOM and must be of one type
TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
for ( int i =0; i < myGeomObjects->length(); i++)
{
TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
if (i == 0)
aGroupType = aSubShapeType;
else if (aSubShapeType != aGroupType)
{
aGroupType = TopAbs_SHAPE;
break;
}
}
GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
op->UnionList(aGroupVar, myGeomObjects);
if (op->IsDone()) {
// publish the GEOM group in study
QString aNewGeomGroupName ("Auto_group_for_");
aNewGeomGroupName += myName->text();
SALOMEDS::SObject_var aNewGroupSO =
geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
}
myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
}
int aColorNumber = myColorSpinBox->value(); int aColorNumber = myColorSpinBox->value();
myGroupOnGeom->SetColorNumber(aColorNumber); myGroupOnGeom->SetColorNumber(aColorNumber);
@ -834,6 +901,8 @@ void SMESHGUI_GroupDlg::onListSelectionChanged()
void SMESHGUI_GroupDlg::onObjectSelectionChanged() void SMESHGUI_GroupDlg::onObjectSelectionChanged()
{ {
if ( myIsBusy || !isEnabled()) return; if ( myIsBusy || !isEnabled()) return;
if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
myIsBusy = true; myIsBusy = true;
SALOME_ListIO aList; SALOME_ListIO aList;
@ -855,6 +924,8 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
myGeomGroupBtn->setEnabled(false); myGeomGroupBtn->setEnabled(false);
myGeomGroupLine->setEnabled(false); myGeomGroupLine->setEnabled(false);
myGeomGroupLine->setText(""); myGeomGroupLine->setText("");
if (myGeomGroupBtn->isOn())
myGeomGroupBtn->setOn(false);
if (!myCreate) if (!myCreate)
myName->setText(""); myName->setText("");
@ -864,6 +935,7 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
myGroup = SMESH::SMESH_Group::_nil(); myGroup = SMESH::SMESH_Group::_nil();
myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
myMesh = SMESH::SMESH_Mesh::_nil(); myMesh = SMESH::SMESH_Mesh::_nil();
updateGeomPopup();
myIsBusy = false; myIsBusy = false;
return; return;
} }
@ -871,6 +943,7 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
if (myCreate) { if (myCreate) {
myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO); myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
updateGeomPopup();
if (myMesh->_is_nil()) if (myMesh->_is_nil())
{ {
myIsBusy = false; myIsBusy = false;
@ -913,32 +986,51 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
if (!myCreate) if (!myCreate)
return; return;
if (myGrpTypeId == 0)
{
if (myTypeId == -1) if (myTypeId == -1)
onTypeChanged(0); onTypeChanged(0);
else { else
{
myElements->clear(); myElements->clear();
setSelectionMode(myTypeId); setSelectionMode(myTypeId);
} }
}
myIsBusy = false; myIsBusy = false;
return; return;
} else if (myCurrentLineEdit == myGeomGroupLine) { } else if (myCurrentLineEdit == myGeomGroupLine) {
if (aNbSel != 1) {
myGeomGroup = GEOM::GEOM_Object::_nil(); myGeomObjects = new GEOM::ListOfGO();
// The mesh SObject
_PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
if (aNbSel == 0 || !aMeshSO)
{
myGeomObjects->length(0);
myIsBusy = false; myIsBusy = false;
return; return;
} }
Standard_Boolean testResult = Standard_False; myGeomObjects->length(aNbSel);
myGeomGroup = GEOMBase::ConvertIOinGEOMObject(aList.First(), testResult);
GEOM::GEOM_Object_var aGeomGroup;
Standard_Boolean testResult;
int i = 0;
SALOME_ListIteratorOfListIO anIt (aList);
for (; anIt.More(); anIt.Next()) {
testResult = Standard_False;
aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
// Check if the object is a geometry group // Check if the object is a geometry group
if (!testResult || CORBA::is_nil(myGeomGroup)) { if (!testResult || CORBA::is_nil(aGeomGroup))
myGeomGroup = GEOM::GEOM_Object::_nil(); continue;
myIsBusy = false;
return;
}
// Check if group constructed on the same shape as a mesh or on its child // Check if group constructed on the same shape as a mesh or on its child
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations_var anOp =
@ -946,21 +1038,14 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
// The main shape of the group // The main shape of the group
GEOM::GEOM_Object_var aGroupMainShape; GEOM::GEOM_Object_var aGroupMainShape;
if (myGeomGroup->GetType() == 37) if (aGeomGroup->GetType() == 37)
aGroupMainShape = anOp->GetMainShape(myGeomGroup); aGroupMainShape = anOp->GetMainShape(aGeomGroup);
else else
aGroupMainShape = GEOM::GEOM_Object::_duplicate(myGeomGroup); aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
_PTR(SObject) aGroupMainShapeSO = _PTR(SObject) aGroupMainShapeSO =
//aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape)); //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
aStudy->FindObjectID(aGroupMainShape->GetStudyEntry()); aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
// The mesh SObject
_PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
if (!aMeshSO) {
myGeomGroup = GEOM::GEOM_Object::_nil();
myIsBusy = false;
return;
}
_PTR(SObject) anObj, aRef; _PTR(SObject) anObj, aRef;
bool isRefOrSubShape = false; bool isRefOrSubShape = false;
if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) { if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
@ -980,19 +1065,28 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
} }
} }
} }
if (!isRefOrSubShape) { if (isRefOrSubShape)
myGeomGroup = GEOM::GEOM_Object::_nil(); myGeomObjects[i++] = aGeomGroup;
}
myGeomObjects->length(i);
if ( i == 0 )
{
myIsBusy = false; myIsBusy = false;
return; return;
} }
aNbSel = i;
} }
if(aNbSel >= 1) { if(aNbSel >= 1) {
if(aNbSel > 1) { if(aNbSel > 1) {
if(myCurrentLineEdit == mySubMeshLine) if(myCurrentLineEdit == mySubMeshLine)
aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel); aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
else if(myCurrentLineEdit == myGroupLine || myCurrentLineEdit == myGeomGroupLine) else if(myCurrentLineEdit == myGroupLine)
aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel); aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
else if(myCurrentLineEdit == myGeomGroupLine)
aString = tr("%1 Objects").arg(aNbSel);
} else { } else {
aString = aList.First()->getName(); aString = aList.First()->getName();
} }
@ -1100,9 +1194,12 @@ void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
mySelectGroup->setChecked(false); mySelectGroup->setChecked(false);
} }
myCurrentLineEdit = myGeomGroupLine; myCurrentLineEdit = myGeomGroupLine;
setSelectionMode(7); updateGeomPopup();
setSelectionMode(8);
} }
else { else {
myGeomGroupBtn->setOn(false);
myGeomObjects->length(0);
myGeomGroupLine->setText(""); myGeomGroupLine->setText("");
myCurrentLineEdit = 0; myCurrentLineEdit = 0;
if (myTypeId != -1) if (myTypeId != -1)
@ -1146,11 +1243,6 @@ void SMESHGUI_GroupDlg::setCurrentSelection()
myCurrentLineEdit = myGroupLine; myCurrentLineEdit = myGroupLine;
onObjectSelectionChanged(); onObjectSelectionChanged();
} }
else if (send == myGeomGroupBtn) {
myCurrentLineEdit = myGeomGroupLine;
setSelectionMode(7);
onObjectSelectionChanged();
}
} }
@ -1328,13 +1420,13 @@ void SMESHGUI_GroupDlg::onAdd()
myIsBusy = false; myIsBusy = false;
onListSelectionChanged(); onListSelectionChanged();
} else if (myCurrentLineEdit == myGeomGroupLine && !CORBA::is_nil(myGeomGroup)) { } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
GEOM::GEOM_IGroupOperations_var aGroupOp = GEOM::GEOM_IGroupOperations_var aGroupOp =
SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
SMESH::ElementType aGroupType = SMESH::ALL; SMESH::ElementType aGroupType = SMESH::ALL;
switch(aGroupOp->GetType(myGeomGroup)) { switch(aGroupOp->GetType(myGeomObjects[0])) {
case 7: aGroupType = SMESH::NODE; break; case 7: aGroupType = SMESH::NODE; break;
case 6: aGroupType = SMESH::EDGE; break; case 6: aGroupType = SMESH::EDGE; break;
case 4: aGroupType = SMESH::FACE; break; case 4: aGroupType = SMESH::FACE; break;
@ -1345,12 +1437,12 @@ void SMESHGUI_GroupDlg::onAdd()
if (aGroupType == aType) { if (aGroupType == aType) {
_PTR(SObject) aGroupSO = _PTR(SObject) aGroupSO =
//aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup)); //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
aStudy->FindObjectID(myGeomGroup->GetStudyEntry()); aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
// Construct filter // Construct filter
SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager(); SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
SMESH::Filter_var aFilter = aFilterMgr->CreateFilter(); SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();; SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
aBelongToGeom->SetGeom(myGeomGroup); aBelongToGeom->SetGeom(myGeomObjects[0]);
aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str()); aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
aBelongToGeom->SetElementType(aType); aBelongToGeom->SetElementType(aType);
aFilter->SetPredicate(aBelongToGeom); aFilter->SetPredicate(aBelongToGeom);
@ -1596,7 +1688,7 @@ void SMESHGUI_GroupDlg::enterEvent (QEvent*)
//================================================================================= //=================================================================================
void SMESHGUI_GroupDlg::hideEvent (QHideEvent*) void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
{ {
if (!isMinimized()) if (!isMinimized() && !myIsBusy)
onClose(); onClose();
} }
@ -1616,3 +1708,128 @@ void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
onHelp(); onHelp();
} }
} }
//================================================================================
/*!
* \brief Enable showing of the popup when Geometry selection btn is clicked
* \param enable - true to enable
*/
//================================================================================
enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
void SMESHGUI_GroupDlg::updateGeomPopup()
{
bool enable = false;
if ( !myMesh->_is_nil() )
enable = myMesh->NbEdges() > 0;
if ( myGeomGroupBtn )
{
disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
if ( enable ) {
if ( !myGeomPopup ) {
myGeomPopup = new QPopupMenu();
myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
}
connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
}
}
}
//=================================================================================
// function : onGeomSelectionButton()
// purpose :
//=================================================================================
void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
{
if ( myGeomPopup && isBtnOn )
{
myCurrentLineEdit = myGeomGroupLine;
int id = myGeomPopup->exec( QCursor::pos() );
if (id == DIRECT_GEOM_INDEX || id == -1)
setSelectionMode(7);
}
else if (!isBtnOn)
{
myCurrentLineEdit = 0;
setSelectionMode(8);
}
}
//=================================================================================
// function : onGeomPopup()
// purpose :
//=================================================================================
void SMESHGUI_GroupDlg::onGeomPopup( int index )
{
if ( index == GEOM_BY_MESH_INDEX )
{
mySelectionMode = -1;
if ( !myShapeByMeshOp ) {
myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
}
// set mesh object to SMESHGUI_ShapeByMeshOp and start it
if ( !myMesh->_is_nil() ) {
myIsBusy = true;
hide(); // stop processing selection
myIsBusy = false;
myShapeByMeshOp->setModule( mySMESHGUI );
myShapeByMeshOp->setStudy( 0 ); // it's really necessary
myShapeByMeshOp->SetMesh( myMesh );
myShapeByMeshOp->start();
}
}
}
//================================================================================
/*!
* \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
*/
//================================================================================
void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
{
if ( myShapeByMeshOp == op ) {
mySMESHGUI->getApp()->updateObjectBrowser();
show();
// Select a found geometry object
GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
if ( !aGeomVar->_is_nil() )
{
QString ID = aGeomVar->GetStudyEntry();
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
SALOME_ListIO anIOList;
Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
anIOList.Append( anIO );
mySelectionMgr->setSelectedObjects( anIOList, false );
onObjectSelectionChanged();
}
}
}
}
//================================================================================
/*!
* \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
*/
//================================================================================
void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
{
if ( myShapeByMeshOp == op )
{
show();
setSelectionMode(7);
}
}

View File

@ -45,13 +45,17 @@ class QLineEdit;
class QButtonGroup; class QButtonGroup;
class QGroupBox; class QGroupBox;
class QListBox; class QListBox;
class QPopupMenu;
class QPushButton; class QPushButton;
class QToolButton;
class QCheckBox; class QCheckBox;
class QWidgetStack; class QWidgetStack;
class QtxIntSpinBox; class QtxIntSpinBox;
class SMESHGUI; class SMESHGUI;
class SMESH_Actor; class SMESH_Actor;
class SMESHGUI_FilterDlg; class SMESHGUI_FilterDlg;
class SMESHGUI_ShapeByMeshOp;
class SUIT_Operation;
class SVTK_Selector; class SVTK_Selector;
class SVTK_ViewWindow; class SVTK_ViewWindow;
@ -107,6 +111,12 @@ private slots:
void onNbColorsChanged(const QString& text); void onNbColorsChanged(const QString& text);
void onFilterAccepted(); void onFilterAccepted();
void onGeomPopup( int );
void onGeomSelectionButton( bool );
void onPublishShapeByMeshDlg(SUIT_Operation*);
void onCloseShapeByMeshDlg(SUIT_Operation*);
private: private:
void initDialog(bool create); void initDialog(bool create);
void init(SMESH::SMESH_Mesh_ptr theMesh); void init(SMESH::SMESH_Mesh_ptr theMesh);
@ -117,6 +127,7 @@ private:
void keyPressEvent(QKeyEvent*); void keyPressEvent(QKeyEvent*);
void setSelectionMode(int theMode); void setSelectionMode(int theMode);
void updateButtons(); void updateButtons();
void updateGeomPopup();
SMESHGUI* mySMESHGUI; /* Current SMESHGUI object */ SMESHGUI* mySMESHGUI; /* Current SMESHGUI object */
LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */ LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */
@ -150,14 +161,17 @@ private:
QtxIntSpinBox* myColorSpinBox; QtxIntSpinBox* myColorSpinBox;
QCheckBox* mySelectGeomGroup; QCheckBox* mySelectGeomGroup;
QPushButton* myGeomGroupBtn; QToolButton* myGeomGroupBtn;
QLineEdit* myGeomGroupLine; QLineEdit* myGeomGroupLine;
QPopupMenu* myGeomPopup;
SMESHGUI_ShapeByMeshOp* myShapeByMeshOp;
SMESH::SMESH_Mesh_var myMesh; SMESH::SMESH_Mesh_var myMesh;
SMESH::SMESH_Group_var myGroup; SMESH::SMESH_Group_var myGroup;
SMESH::SMESH_GroupOnGeom_var myGroupOnGeom; SMESH::SMESH_GroupOnGeom_var myGroupOnGeom;
QValueList<int> myIdList; QValueList<int> myIdList;
GEOM::GEOM_Object_var myGeomGroup; GEOM::ListOfGO_var myGeomObjects;
int mySelectionMode; int mySelectionMode;
//Handle(SMESH_TypeFilter) myMeshFilter; //Handle(SMESH_TypeFilter) myMeshFilter;
@ -166,6 +180,7 @@ private:
SUIT_SelectionFilter* myMeshFilter; SUIT_SelectionFilter* myMeshFilter;
SUIT_SelectionFilter* mySubMeshFilter; SUIT_SelectionFilter* mySubMeshFilter;
SUIT_SelectionFilter* myGroupFilter; SUIT_SelectionFilter* myGroupFilter;
SUIT_SelectionFilter* myGeomFilter;
SMESHGUI_FilterDlg* myFilterDlg; SMESHGUI_FilterDlg* myFilterDlg;

View File

@ -70,6 +70,7 @@
#define SPACING 5 #define SPACING 5
#define MARGIN 10 #define MARGIN 10
enum { EDGE = 0, FACE, VOLUME }; enum { EDGE = 0, FACE, VOLUME };
/*! /*!
@ -114,7 +115,10 @@ QFrame* SMESHGUI_ShapeByMeshDlg::createMainFrame (QWidget* theParent)
QLabel* anIdLabel = new QLabel( aMainGrp, "element id label"); QLabel* anIdLabel = new QLabel( aMainGrp, "element id label");
anIdLabel->setText( tr("ELEMENT_ID") ); anIdLabel->setText( tr("ELEMENT_ID") );
myElementId = new QLineEdit( aMainGrp, "element id"); myElementId = new QLineEdit( aMainGrp, "element id");
if (!myIsMultipleAllowed)
myElementId->setValidator( new SMESHGUI_IdValidator( theParent, "id validator", 1 )); myElementId->setValidator( new SMESHGUI_IdValidator( theParent, "id validator", 1 ));
else
myElementId->setValidator( new SMESHGUI_IdValidator( theParent, "id validator" ));
// shape name // shape name
QLabel* aNameLabel = new QLabel( aMainGrp, "geom name label"); QLabel* aNameLabel = new QLabel( aMainGrp, "geom name label");
@ -148,12 +152,14 @@ SMESHGUI_ShapeByMeshDlg::~SMESHGUI_ShapeByMeshDlg()
* Initialize operation * Initialize operation
*/ */
//================================================================================ //================================================================================
SMESHGUI_ShapeByMeshOp::SMESHGUI_ShapeByMeshOp() SMESHGUI_ShapeByMeshOp::SMESHGUI_ShapeByMeshOp(bool isMultipleAllowed):
myIsMultipleAllowed(isMultipleAllowed)
{ {
if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
GeometryGUI::InitGeomGen(); GeometryGUI::InitGeomGen();
myDlg = new SMESHGUI_ShapeByMeshDlg; myDlg = new SMESHGUI_ShapeByMeshDlg;
myDlg->setMultipleAllowed(myIsMultipleAllowed);
connect(myDlg->myElemTypeGroup, SIGNAL(clicked(int)), SLOT(onTypeChanged(int))); connect(myDlg->myElemTypeGroup, SIGNAL(clicked(int)), SLOT(onTypeChanged(int)));
connect(myDlg->myElementId, SIGNAL(textChanged(const QString&)), SLOT(onElemIdChanged(const QString&))); connect(myDlg->myElementId, SIGNAL(textChanged(const QString&)), SLOT(onElemIdChanged(const QString&)));
@ -282,10 +288,86 @@ void SMESHGUI_ShapeByMeshOp::commitOperation()
{ {
SMESHGUI_SelectionOp::commitOperation(); SMESHGUI_SelectionOp::commitOperation();
try { try {
int elemID = myDlg->myElementId->text().toInt(); QStringList aListId = QStringList::split( " ", myDlg->myElementId->text(), false);
if (aListId.count() == 1)
{
int elemID = (aListId.first()).toInt();
myGeomObj = SMESHGUI::GetSMESHGen()->GetGeometryByMeshElement myGeomObj = SMESHGUI::GetSMESHGen()->GetGeometryByMeshElement
( myMesh.in(), elemID, myDlg->myGeomName->text().latin1()); ( myMesh.in(), elemID, myDlg->myGeomName->text().latin1());
} }
else
{
GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
if (geomGen->_is_nil() || !aStudy)
return;
GEOM::GEOM_IShapesOperations_var aShapesOp =
geomGen->GetIShapesOperations(aStudy->StudyId());
if (aShapesOp->_is_nil() )
return;
TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
std::map<double, GEOM::GEOM_Object_var> aGeomObjectsMap;
GEOM::GEOM_Object_var aGeomObject;
GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
for ( int i = 0; i < aListId.count(); i++ )
{
aGeomObject =
SMESHGUI::GetSMESHGen()->FindGeometryByMeshElement(myMesh.in(), aListId[i].toInt());
if (aGeomObject->_is_nil()) continue;
double anId = aShapesOp->GetSubShapeIndex(aMeshShape, aGeomObject);
if (aShapesOp->IsDone() && aGeomObjectsMap.find(anId) == aGeomObjectsMap.end())
{
aGeomObjectsMap[anId] = aGeomObject;
TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aGeomObject->GetShapeType();
if (i == 0)
aGroupType = aSubShapeType;
else if (aSubShapeType != aGroupType)
aGroupType = TopAbs_SHAPE;
}
}
int aNumberOfGO = aGeomObjectsMap.size();
if (aNumberOfGO == 1)
myGeomObj = (*aGeomObjectsMap.begin()).second;
else if (aNumberOfGO > 1)
{
GEOM::GEOM_IGroupOperations_var aGroupOp =
geomGen->GetIGroupOperations(aStudy->StudyId());
if(aGroupOp->_is_nil())
return;
GEOM::ListOfGO_var aGeomObjects = new GEOM::ListOfGO();
aGeomObjects->length( aNumberOfGO );
int i = 0;
std::map<double, GEOM::GEOM_Object_var>::iterator anIter;
for (anIter = aGeomObjectsMap.begin(); anIter!=aGeomObjectsMap.end(); anIter++)
aGeomObjects[i++] = (*anIter).second;
//create geometry group
myGeomObj = aGroupOp->CreateGroup(aMeshShape, aGroupType);
aGroupOp->UnionList(myGeomObj, aGeomObjects);
if (!aGroupOp->IsDone())
return;
}
// publish the GEOM object in study
QString aNewGeomGroupName ( myDlg->myGeomName->text().latin1() );
SALOMEDS::SObject_var aNewGroupSO =
geomGen->AddInStudy(SMESHGUI::GetSMESHGen()->GetCurrentStudy(), myGeomObj, aNewGeomGroupName, aMeshShape);
}
}
catch (const SALOME::SALOME_Exception& S_ex) { catch (const SALOME::SALOME_Exception& S_ex) {
SalomeApp_Tools::QtCatchCorbaException(S_ex); SalomeApp_Tools::QtCatchCorbaException(S_ex);
} }
@ -306,7 +388,7 @@ void SMESHGUI_ShapeByMeshOp::onSelectionDone()
try { try {
SALOME_ListIO aList; SALOME_ListIO aList;
selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type()); selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type());
if (aList.Extent() != 1) if (!myIsMultipleAllowed && aList.Extent() != 1)
return; return;
SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First()); SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First());
@ -316,7 +398,9 @@ void SMESHGUI_ShapeByMeshOp::onSelectionDone()
QString aString; QString aString;
int nbElems = SMESH::GetNameOfSelectedElements(selector(),//myViewWindow->GetSelector(), int nbElems = SMESH::GetNameOfSelectedElements(selector(),//myViewWindow->GetSelector(),
aList.First(), aString); aList.First(), aString);
if ( nbElems == 1 ) { if (nbElems > 0) {
if (!myIsMultipleAllowed && nbElems != 1 )
return;
setElementID( aString ); setElementID( aString );
myDlg->setButtonEnabled( true, QtxDialog::OK ); myDlg->setButtonEnabled( true, QtxDialog::OK );
} }
@ -392,7 +476,10 @@ void SMESHGUI_ShapeByMeshOp::onElemIdChanged(const QString& theNewText)
newIndices.Add( e->GetID() ); newIndices.Add( e->GetID() );
} }
if ( !newIndices.IsEmpty() && newIndices.Extent() == 1 ) if ( !newIndices.IsEmpty() )
{
if (!myIsMultipleAllowed && newIndices.Extent() != 1)
return;
if ( SVTK_Selector* s = selector() ) { if ( SVTK_Selector* s = selector() ) {
s->AddOrRemoveIndex( actor->getIO(), newIndices, false ); s->AddOrRemoveIndex( actor->getIO(), newIndices, false );
viewWindow()->highlight( actor->getIO(), true, true ); viewWindow()->highlight( actor->getIO(), true, true );
@ -400,6 +487,7 @@ void SMESHGUI_ShapeByMeshOp::onElemIdChanged(const QString& theNewText)
} }
} }
} }
}
//======================================================================= //=======================================================================
//function : setElementID //function : setElementID

View File

@ -74,6 +74,10 @@ private:
QLineEdit* myElementId; QLineEdit* myElementId;
QLineEdit* myGeomName; QLineEdit* myGeomName;
private:
bool myIsMultipleAllowed;
void setMultipleAllowed(bool isAllowed) {myIsMultipleAllowed = isAllowed;};
// QPushButton* myOkBtn; // QPushButton* myOkBtn;
// QPushButton* myCloseBtn; // QPushButton* myCloseBtn;
@ -89,7 +93,7 @@ class SMESHGUI_ShapeByMeshOp: public SMESHGUI_SelectionOp
Q_OBJECT Q_OBJECT
public: public:
SMESHGUI_ShapeByMeshOp(); SMESHGUI_ShapeByMeshOp(bool isMultipleAllowed = false);
virtual ~SMESHGUI_ShapeByMeshOp(); virtual ~SMESHGUI_ShapeByMeshOp();
virtual LightApp_Dialog* dlg() const; virtual LightApp_Dialog* dlg() const;
@ -144,6 +148,7 @@ private:
bool myIsManualIdEnter; bool myIsManualIdEnter;
bool myHasSolids; bool myHasSolids;
bool myIsMultipleAllowed;
}; };
#endif #endif

View File

@ -1130,6 +1130,41 @@ SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
throw ( SALOME::SALOME_Exception ) throw ( SALOME::SALOME_Exception )
{ {
Unexpect aCatch(SALOME_SalomeException); Unexpect aCatch(SALOME_SalomeException);
GEOM::GEOM_Object_var geom = FindGeometryByMeshElement(theMesh, theElementID);
if ( !geom->_is_nil() ) {
GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
GEOM::GEOM_Gen_var geomGen = GetGeomEngine();
// try to find the corresponding SObject
GeomObjectToShape( geom ); // geom client remembers the found shape
SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
if ( SObj->_is_nil() )
// publish a new subshape
SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
// return only published geometry
if ( !SObj->_is_nil() )
return geom._retn();
}
return GEOM::GEOM_Object::_nil();
}
//================================================================================
/*!
* \brief Return geometrical object the given element is built on.
* \param theMesh - the mesh the element is in
* \param theElementID - the element ID
* \retval GEOM::GEOM_Object_ptr - the found geom object
*/
//================================================================================
GEOM::GEOM_Object_ptr
SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
CORBA::Long theElementID)
throw ( SALOME::SALOME_Exception )
{
Unexpect aCatch(SALOME_SalomeException);
if ( CORBA::is_nil( theMesh ) ) if ( CORBA::is_nil( theMesh ) )
THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM ); THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
@ -1154,19 +1189,10 @@ SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
if ( !op->_is_nil() ) if ( !op->_is_nil() )
geom = op->GetSubShape( mainShape, shapeID ); geom = op->GetSubShape( mainShape, shapeID );
} }
if ( !geom->_is_nil() ) { if ( !geom->_is_nil() )
// try to find the corresponding SObject
GeomObjectToShape( geom ); // geom client remembers the found shape
SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
if ( SObj->_is_nil() )
// publish a new subshape
SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
// return only published geometry
if ( !SObj->_is_nil() )
return geom._retn(); return geom._retn();
} }
} }
}
return GEOM::GEOM_Object::_nil(); return GEOM::GEOM_Object::_nil();
} }

View File

@ -229,12 +229,17 @@ public:
const SMESH::object_array& theListOfSubShape ) const SMESH::object_array& theListOfSubShape )
throw ( SALOME::SALOME_Exception ); throw ( SALOME::SALOME_Exception );
// Return geometrical object the given element is built on // Return geometrical object the given element is built on. Publish it in study.
GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh, GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
CORBA::Long theElementID, CORBA::Long theElementID,
const char* theGeomName) const char* theGeomName)
throw ( SALOME::SALOME_Exception ); throw ( SALOME::SALOME_Exception );
// Return geometrical object the given element is built on. Don't publish it in study.
GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
CORBA::Long theElementID)
throw ( SALOME::SALOME_Exception );
// **************************************************** // ****************************************************
// Interface inherited methods (from SALOMEDS::Driver) // Interface inherited methods (from SALOMEDS::Driver)
// **************************************************** // ****************************************************