X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_GroupDlg.cxx;h=7e363302206258e55448c551484b1f5d6c366e5f;hb=a3511231dcd9eb444465166298ddc0fb39a4056d;hp=b9396313bb87e81b284c3e58874978770855a78d;hpb=d0f366c4a3a66a71b0be94f7a6e2d146f80a94c4;p=modules%2Fsmesh.git diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx index b9396313b..7e3633022 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx @@ -17,7 +17,7 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org or email : webmaster.salome@opencascade.org +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // // @@ -28,6 +28,7 @@ #include "SMESHGUI_GroupDlg.h" #include "SMESHGUI_FilterDlg.h" +#include "SMESHGUI_ShapeByMeshDlg.h" #include "SMESHGUI.h" #include "SMESHGUI_Utils.h" @@ -39,12 +40,20 @@ #include "SMESH_TypeFilter.hxx" #include "SMESH_Actor.h" +#include "SMESH_ActorUtils.h" + #include "GEOMBase.h" +#include "GEOM_SelectionFilter.h" #include "SUIT_Desktop.h" #include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" +#include "SUIT_MessageBox.h" #include "SalomeApp_Tools.h" +#include "SalomeApp_Application.h" +#include "SalomeApp_Study.h" +#include "LightApp_Application.h" #include "SALOMEDSClient_Study.hxx" #include "SALOME_ListIO.hxx" #include "SALOME_ListIteratorOfListIO.hxx" @@ -59,11 +68,13 @@ // QT Includes #include +#include #include #include #include #include #include +#include #include #include #include @@ -72,6 +83,9 @@ #include #include #include +#include + +#include // STL includes #include @@ -103,12 +117,6 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name, myGeomGroupBtn->setEnabled(false); myGeomGroupLine->setEnabled(false); } - - - /* Move widget on the botton right corner of main widget */ - int x, y ; - mySMESHGUI->DefineDlgPosition(this, x, y); - this->move(x, y); } //================================================================================= @@ -116,7 +124,7 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name, // purpose : //================================================================================= SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name, - SMESH::SMESH_Group_ptr theGroup, bool modal, WFlags fl) + SMESH::SMESH_GroupBase_ptr theGroup, bool modal, WFlags fl) : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), mySMESHGUI( theModule ), @@ -136,11 +144,6 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name, myCurrentLineEdit = myMeshGroupLine; setSelectionMode(5); } - - /* Move widget on the botton right corner of main widget */ - int x, y ; - mySMESHGUI->DefineDlgPosition(this, x, y); - this->move(x, y); } //================================================================================= @@ -153,12 +156,21 @@ void SMESHGUI_GroupDlg::initDialog(bool create) myCreate = create; myCurrentLineEdit = 0; + myShapeByMeshOp = 0; + myGeomPopup = 0; + myGeomObjects = new GEOM::ListOfGO(); + myGeomObjects->length(0); + QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT"))); - if (create) + if (create) { setCaption(tr("SMESH_CREATE_GROUP_TITLE")); - else + myHelpFileName = "creating_groups_page.html"; + } + else { setCaption(tr("SMESH_EDIT_GROUP_TITLE")); + myHelpFileName = "editing_groups_page.html"; + } setSizeGripEnabled(TRUE); @@ -270,7 +282,7 @@ void SMESHGUI_GroupDlg::initDialog(bool create) myGroupLine = new QLineEdit(aSelectBox, "group line"); myGroupLine->setReadOnly(true); onSelectGroup(false); - + /***************************************************************/ QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 ); wg1Layout->addWidget(aContentBox, 0, 0); @@ -280,13 +292,19 @@ void SMESHGUI_GroupDlg::initDialog(bool create) /***************************************************************/ QLabel* geomObject = new QLabel(wg2, "geometry object label"); geomObject->setText(tr("SMESH_OBJECT_GEOM")); - myGeomGroupBtn = new QPushButton(wg2, "geometry group button"); - myGeomGroupBtn->setText(""); - myGeomGroupBtn->setPixmap(image0); + myGeomGroupBtn = new QToolButton(wg2, "geometry group button"); + myGeomGroupBtn->setIconSet( QIconSet(image0) ); + myGeomGroupBtn->setToggleButton(true); myGeomGroupLine = new QLineEdit(wg2, "geometry group line"); myGeomGroupLine->setReadOnly(true); //VSR ??? onSelectGeomGroup(false); - + + if (!create) + { + myGeomGroupBtn->setEnabled(false); + myGeomGroupLine->setEnabled(false); + } + /***************************************************************/ QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 ); wg2Layout->addWidget(geomObject, 0, 0); @@ -302,6 +320,15 @@ void SMESHGUI_GroupDlg::initDialog(bool create) myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) ); /***************************************************************/ + QGroupBox* aColorBox = new QGroupBox(2, Qt::Horizontal, this, "color box"); + aColorBox->setTitle(tr("SMESH_SET_COLOR")); + + new QLabel( tr("SMESH_CHECK_COLOR"), aColorBox, "color label" ); + myColorBtn = new QPushButton(aColorBox, "color button"); + myColorBtn->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + + /***************************************************************/ + QFrame* aButtons = new QFrame(this, "button box"); aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken); QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6); @@ -317,11 +344,15 @@ void SMESHGUI_GroupDlg::initDialog(bool create) QPushButton* aCloseBtn = new QPushButton(aButtons, "close"); aCloseBtn->setText(tr("SMESH_BUT_CLOSE")); aCloseBtn->setAutoDefault(true); + QPushButton* aHelpBtn = new QPushButton(aButtons, "help"); + aHelpBtn->setText(tr("SMESH_BUT_HELP")); + aHelpBtn->setAutoDefault(true); aBtnLayout->addWidget(aOKBtn); aBtnLayout->addWidget(aApplyBtn); aBtnLayout->addStretch(); aBtnLayout->addWidget(aCloseBtn); + aBtnLayout->addWidget(aHelpBtn); /***************************************************************/ aMainLayout->addWidget(meshGroupLab, 0, 0); @@ -333,7 +364,8 @@ void SMESHGUI_GroupDlg::initDialog(bool create) aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2); aMainLayout->addMultiCellWidget(myWGStack, 4, 4, 0, 2); aMainLayout->setRowStretch( 5, 5 ); - aMainLayout->addMultiCellWidget(aButtons, 6, 6, 0, 2); + aMainLayout->addMultiCellWidget(aColorBox, 6, 6, 0, 2); + aMainLayout->addMultiCellWidget(aButtons, 7, 7, 0, 2); /* signals and slots connections */ connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection())); @@ -354,11 +386,13 @@ void SMESHGUI_GroupDlg::initDialog(bool create) connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool))); connect(mySubMeshBtn, 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(myColorBtn, SIGNAL(clicked()), this, SLOT(onSelectColor())); + connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK())); connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply())); connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose())); + connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp())); /* Init selection */ mySMESHGUI->SetActiveDialogBox(this); @@ -368,7 +402,9 @@ void SMESHGUI_GroupDlg::initDialog(bool create) myMeshFilter = new SMESH_TypeFilter(MESH); mySubMeshFilter = new SMESH_TypeFilter(SUBMESH); myGroupFilter = new SMESH_TypeFilter(GROUP); - + SalomeApp_Study* aStudy = dynamic_cast( mySMESHGUI->application()->activeStudy() ); + myGeomFilter = new GEOM_SelectionFilter( aStudy, true ); + connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate())); connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose())); connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged())); @@ -407,10 +443,13 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh) /* init data from current selection */ myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh); myGroup = SMESH::SMESH_Group::_nil(); + myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); myActor = SMESH::FindActorByObject(myMesh); SMESH::SetPickable(myActor); + setDefaultGroupColor(); + SALOME_ListIO aList; mySelectionMgr->selectedObjects( aList ); if( !aList.IsEmpty() ) @@ -430,15 +469,17 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh) // function : Init() // purpose : //================================================================================= -void SMESHGUI_GroupDlg::init (SMESH::SMESH_Group_ptr theGroup) +void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup) { myMesh = theGroup->GetMesh(); - myGroup = SMESH::SMESH_Group::_duplicate(theGroup); + + myName->setText(theGroup->GetName()); + myName->home(false); - myActor = SMESH::FindActorByObject(myMesh); - if ( !myActor ) - myActor = SMESH::FindActorByObject(myGroup); - SMESH::SetPickable(myActor); + SALOMEDS::Color aColor = theGroup->GetColor(); + setGroupColor( aColor ); + + myMeshGroupLine->setText(theGroup->GetName()); int aType = 0; switch(theGroup->GetType()) { @@ -447,27 +488,61 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Group_ptr theGroup) case SMESH::FACE: aType = 2; break; case SMESH::VOLUME: aType = 3; break; } + myTypeGroup->setButton(aType); + + myGroup = SMESH::SMESH_Group::_narrow( theGroup ); - myName->setText(myGroup->GetName()); - myName->home(false); - myMeshGroupLine->setText(myGroup->GetName()); + if ( !myGroup->_is_nil() ) + { + myActor = SMESH::FindActorByObject(myMesh); + if ( !myActor ) + myActor = SMESH::FindActorByObject(myGroup); + SMESH::SetPickable(myActor); - myCurrentLineEdit = 0; - myTypeGroup->setButton(aType); - myElements->clear(); - setSelectionMode(aType); - myTypeId = aType; - - myIdList.clear(); - if (!theGroup->IsEmpty()) { - SMESH::long_array_var anElements = myGroup->GetListOfID(); - int k = anElements->length(); - for (int i = 0; i < k; i++) { - myIdList.append(anElements[i]); - myElements->insertItem(QString::number(anElements[i])); + myGrpTypeGroup->setButton(0); + onGrpTypeChanged(0); + + myCurrentLineEdit = 0; + myElements->clear(); + setSelectionMode(aType); + myTypeId = aType; + + myIdList.clear(); + if (!myGroup->IsEmpty()) { + SMESH::long_array_var anElements = myGroup->GetListOfID(); + int k = anElements->length(); + for (int i = 0; i < k; i++) { + myIdList.append(anElements[i]); + myElements->insertItem(QString::number(anElements[i])); + } + myElements->selectAll(true); + } + } + else + { + myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup ); + + if ( !myGroupOnGeom->_is_nil() ) + { + myActor = SMESH::FindActorByObject(myMesh); + if ( !myActor ) + myActor = SMESH::FindActorByObject(myGroup); + SMESH::SetPickable(myActor); + + myGrpTypeGroup->setButton(1); + onGrpTypeChanged(1); + + QString aShapeName(""); + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape(); + if (!aGroupShape->_is_nil()) + { + _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry()); + aShapeName = aGroupShapeSO->GetName().c_str(); + } + myGeomGroupLine->setText( aShapeName ); + } } - myElements->selectAll(true); - } } //================================================================================= @@ -476,12 +551,18 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Group_ptr theGroup) //================================================================================= void SMESHGUI_GroupDlg::updateButtons() { - bool enable; + bool enable = !myName->text().stripWhiteSpace().isEmpty(); + + if (myGrpTypeId == 0) { + enable = enable && myElements->count() > 0; + enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil()); + } + else if (myGrpTypeId == 1) { + if (CORBA::is_nil(myGroupOnGeom)) { // creation mode + enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil(); + } + } - if (myGrpTypeId == 0) - enable = !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0; - else if (myGrpTypeId == 1) - enable = !myName->text().stripWhiteSpace().isEmpty() && !CORBA::is_nil( myGeomGroup ); QPushButton* aBtn; aBtn = (QPushButton*) child("ok", "QPushButton"); if (aBtn) aBtn->setEnabled(enable); @@ -525,6 +606,19 @@ void SMESHGUI_GroupDlg::onGrpTypeChanged (int id) myGrpTypeId = id; } +//================================================================================= +// function : onSelectColor() +// purpose : +//================================================================================= +void SMESHGUI_GroupDlg::onSelectColor() +{ + QColor color = getGroupQColor(); + color = QColorDialog::getColor( color ); + setGroupQColor( color ); + + updateButtons(); +} + //================================================================================= // function : setSelectionMode() // purpose : Radio button management @@ -534,19 +628,21 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode) // PAL7314 if (myMesh->_is_nil()) return; - if (mySelectionMode != theMode) { // [PAL10408] mySelectionMgr->clearSelected(); mySelectionMgr->clearFilters(); - SMESH::SetPointRepresentation(false); + if (myActor) + myActor->SetPointRepresentation(false); + else + SMESH::SetPointRepresentation(false); if (theMode < 4) { switch (theMode) { case 0: if (myActor) - myActor->SetPointRepresentation(true); - else - SMESH::SetPointRepresentation(true); - if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) + myActor->SetPointRepresentation(true); + else + SMESH::SetPointRepresentation(true); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) aViewWindow->SetSelectionMode(NodeSelection); break; case 1: @@ -568,11 +664,14 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode) mySelectionMgr->installFilter(myGroupFilter); else if (theMode == 6) mySelectionMgr->installFilter(myMeshFilter); + else if (theMode == 7) + mySelectionMgr->installFilter(myGeomFilter); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) aViewWindow->SetSelectionMode(ActorSelection); } mySelectionMode = theMode; - } + } } //================================================================================= @@ -584,18 +683,27 @@ bool SMESHGUI_GroupDlg::onApply() if (mySMESHGUI->isActiveStudyLocked()) return false; - if (myGrpTypeId == 0 && - !myName->text().stripWhiteSpace().isEmpty() && - myElements->count() > 0) { + if (myName->text().stripWhiteSpace().isEmpty()) + return false; + + if (myGrpTypeId == 0) { // on mesh elements + if (!myElements->count()) + return false; + mySelectionMgr->clearSelected(); - if (myGroup->_is_nil()) { + + if (myGroup->_is_nil()) { // creation + if (myMesh->_is_nil()) + return false; + SMESH::ElementType aType = SMESH::ALL; - switch(myTypeId) { + switch (myTypeId) { case 0: aType = SMESH::NODE; break; case 1: aType = SMESH::EDGE; break; case 2: aType = SMESH::FACE; break; case 3: aType = SMESH::VOLUME; break; } + SMESH::long_array_var anIdList = new SMESH::long_array; int i, k = myElements->count(); anIdList->length(k); @@ -607,13 +715,28 @@ bool SMESHGUI_GroupDlg::onApply() myGroup = SMESH::AddGroup(myMesh, aType, myName->text()); myGroup->Add(anIdList.inout()); + SALOMEDS::Color aColor = getGroupColor(); + myGroup->SetColor(aColor); + + _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup); + + //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) ); + SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" ); + /* init for next operation */ myName->setText(""); myElements->clear(); myGroup = SMESH::SMESH_Group::_nil(); - } else { + } else { // edition myGroup->SetName(myName->text()); + + SALOMEDS::Color aColor = getGroupColor(); + myGroup->SetColor(aColor); + + _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup); + if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) + anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); QValueList aAddList; QValueList::iterator anIt; @@ -652,29 +775,97 @@ bool SMESHGUI_GroupDlg::onApply() SMESH::UpdateView(); // asv: fix of BUG PAL5515 mySelectionMgr->clearSelected(); return true; - } else if (myGrpTypeId == 1 && - !myName->text().stripWhiteSpace().isEmpty() && - !CORBA::is_nil(myGeomGroup)) - { - SMESH::ElementType aType = SMESH::ALL; - switch (myTypeId) { - case 0: aType = SMESH::NODE; break; - case 1: aType = SMESH::EDGE; break; - case 2: aType = SMESH::FACE; break; - case 3: aType = SMESH::VOLUME; break; + } + else if (myGrpTypeId == 1) { // on geom object + if (CORBA::is_nil(myGroupOnGeom)) { // creation + if (myMesh->_is_nil() || !myGeomObjects->length()) + return false; + + SMESH::ElementType aType = SMESH::ALL; + switch (myTypeId) { + case 0: aType = SMESH::NODE; break; + case 1: aType = SMESH::EDGE; break; + case 2: aType = SMESH::FACE; break; + case 3: aType = SMESH::VOLUME; break; + } + + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + GEOM::GEOM_IGroupOperations_var aGroupOp = + SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); + + 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); + } + + SALOMEDS::Color aColor = getGroupColor(); + myGroupOnGeom->SetColor(aColor); + + _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom); + + //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) ); + SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" ); + + /* init for next operation */ + myName->setText(""); + myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); } + else { // edition + myGroupOnGeom->SetName(myName->text()); - _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - GEOM::GEOM_IGroupOperations_var aGroupOp = - SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); + SALOMEDS::Color aColor = getGroupColor(); + myGroupOnGeom->SetColor(aColor); - SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = - myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomGroup); + _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom); + if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) + anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); + } mySMESHGUI->updateObjBrowser(true); mySelectionMgr->clearSelected(); - /* init for next operation */ - myName->setText(""); return true; } @@ -726,7 +917,9 @@ void SMESHGUI_GroupDlg::onListSelectionChanged() void SMESHGUI_GroupDlg::onObjectSelectionChanged() { if ( myIsBusy || !isEnabled()) return; - myIsBusy = true; + if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return; + + myIsBusy = true; SALOME_ListIO aList; mySelectionMgr->selectedObjects( aList ); @@ -747,6 +940,11 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() myGeomGroupBtn->setEnabled(false); myGeomGroupLine->setEnabled(false); myGeomGroupLine->setText(""); + myGeomObjects = new GEOM::ListOfGO(); + myGeomObjects->length(0); + + if (myGeomGroupBtn->isOn()) + myGeomGroupBtn->setOn(false); if (!myCreate) myName->setText(""); @@ -754,7 +952,10 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() if (aNbSel != 1 ) { myGroup = SMESH::SMESH_Group::_nil(); + myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); myMesh = SMESH::SMESH_Mesh::_nil(); + updateGeomPopup(); + updateButtons(); myIsBusy = false; return; } @@ -762,10 +963,12 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() if (myCreate) { myMesh = SMESH::IObjectToInterface(IO); + updateGeomPopup(); if (myMesh->_is_nil()) { + updateButtons(); myIsBusy = false; - return; + return; } myGroup = SMESH::SMESH_Group::_nil(); @@ -782,7 +985,7 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() myGeomGroupLine->setEnabled(true); updateButtons(); } else { - SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface(IO); + SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface(IO); if (aGroup->_is_nil()) { myIsBusy = false; @@ -790,98 +993,122 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() } myIsBusy = false; myCurrentLineEdit = 0; + + myGroup = SMESH::SMESH_Group::_nil(); + myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); + init(aGroup); myIsBusy = true; mySelectSubMesh->setEnabled(true); mySelectGroup->setEnabled(true); - myGeomGroupBtn->setEnabled(true); - myGeomGroupLine->setEnabled(true); } myCurrentLineEdit = 0; myIsBusy = false; if (!myCreate) return; - if (myTypeId == -1) - onTypeChanged(0); - else { - myElements->clear(); - setSelectionMode(myTypeId); - } + if (myGrpTypeId == 0) + { + if (myTypeId == -1) + onTypeChanged(0); + else + { + myElements->clear(); + setSelectionMode(myTypeId); + } + } myIsBusy = false; return; } else if (myCurrentLineEdit == myGeomGroupLine) { - if (aNbSel != 1) { - myGeomGroup = GEOM::GEOM_Object::_nil(); - myIsBusy = false; - return; - } - Standard_Boolean testResult = Standard_False; - myGeomGroup = GEOMBase::ConvertIOinGEOMObject(aList.First(), testResult); - - // Check if the object is a geometry group - if (!testResult || CORBA::is_nil(myGeomGroup)) { - myGeomGroup = GEOM::GEOM_Object::_nil(); - myIsBusy = false; - return; - } - // 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 = - SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); - - // The main shape of the group - GEOM::GEOM_Object_var aGroupMainShape; - if (myGeomGroup->GetType() == 37) - aGroupMainShape = anOp->GetMainShape(myGeomGroup); - else - aGroupMainShape = GEOM::GEOM_Object::_duplicate(myGeomGroup); - _PTR(SObject) aGroupMainShapeSO = - //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape)); - aStudy->FindObjectID(aGroupMainShape->GetStudyEntry()); + myGeomObjects = new GEOM::ListOfGO(); // The mesh SObject _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh); - if (!aMeshSO) { - myGeomGroup = GEOM::GEOM_Object::_nil(); - myIsBusy = false; - return; - } - _PTR(SObject) anObj, aRef; - bool isRefOrSubShape = false; - if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) { - //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) { - if (aRef->GetID() == aGroupMainShapeSO->GetID()) { - isRefOrSubShape = true; - } else { - _PTR(SObject) aFather = aGroupMainShapeSO->GetFather(); - _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent(); - //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) { - while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) { - //if (strcmp(aRef->GetID(), aFather->GetID()) == 0) - if (aRef->GetID() == aFather->GetID()) - isRefOrSubShape = true; - else - aFather = aFather->GetFather(); - } + + if (aNbSel == 0 || !aMeshSO) + { + myGeomObjects->length(0); + updateButtons(); + myIsBusy = false; + return; } + + myGeomObjects->length(aNbSel); + + 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 + 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 = + SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); + + // The main shape of the group + GEOM::GEOM_Object_var aGroupMainShape; + if (aGeomGroup->GetType() == 37) + aGroupMainShape = anOp->GetMainShape(aGeomGroup); + else + aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup); + _PTR(SObject) aGroupMainShapeSO = + //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape)); + aStudy->FindObjectID(aGroupMainShape->GetStudyEntry()); + + _PTR(SObject) anObj, aRef; + bool isRefOrSubShape = false; + if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) { + //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) { + if (aRef->GetID() == aGroupMainShapeSO->GetID()) { + isRefOrSubShape = true; + } else { + _PTR(SObject) aFather = aGroupMainShapeSO->GetFather(); + _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent(); + //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) { + while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) { + //if (strcmp(aRef->GetID(), aFather->GetID()) == 0) + if (aRef->GetID() == aFather->GetID()) + isRefOrSubShape = true; + else + aFather = aFather->GetFather(); + } + } + } + if (isRefOrSubShape) + myGeomObjects[i++] = aGeomGroup; } - if (!isRefOrSubShape) { - myGeomGroup = GEOM::GEOM_Object::_nil(); - myIsBusy = false; - return; - } + + myGeomObjects->length(i); + if ( i == 0 ) + { + myIsBusy = false; + return; + } + + aNbSel = i; } if(aNbSel >= 1) { if(aNbSel > 1) { if(myCurrentLineEdit == mySubMeshLine) aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel); - else if(myCurrentLineEdit == myGroupLine || myCurrentLineEdit == myGeomGroupLine) + else if(myCurrentLineEdit == myGroupLine) aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel); + else if(myCurrentLineEdit == myGeomGroupLine) + aString = tr("%1 Objects").arg(aNbSel); } else { aString = aList.First()->getName(); } @@ -915,6 +1142,8 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() if (!myActor) { if (!myGroup->_is_nil()) myActor = SMESH::FindActorByObject(myGroup); + else if(!myGroupOnGeom->_is_nil()) + myActor = SMESH::FindActorByObject(myGroupOnGeom); else myActor = SMESH::FindActorByObject(myMesh); } @@ -987,9 +1216,12 @@ void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on) mySelectGroup->setChecked(false); } myCurrentLineEdit = myGeomGroupLine; - setSelectionMode(7); + updateGeomPopup(); + setSelectionMode(8); } else { + myGeomGroupBtn->setOn(false); + myGeomObjects->length(0); myGeomGroupLine->setText(""); myCurrentLineEdit = 0; if (myTypeId != -1) @@ -1022,11 +1254,6 @@ void SMESHGUI_GroupDlg::setCurrentSelection() myCurrentLineEdit = myGroupLine; onObjectSelectionChanged(); } - else if (send == myGeomGroupBtn) { - myCurrentLineEdit = myGeomGroupLine; - setSelectionMode(7); - onObjectSelectionChanged(); - } } @@ -1204,13 +1431,13 @@ void SMESHGUI_GroupDlg::onAdd() myIsBusy = false; onListSelectionChanged(); - } else if (myCurrentLineEdit == myGeomGroupLine && !CORBA::is_nil(myGeomGroup)) { + } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) { _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); GEOM::GEOM_IGroupOperations_var aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); SMESH::ElementType aGroupType = SMESH::ALL; - switch(aGroupOp->GetType(myGeomGroup)) { + switch(aGroupOp->GetType(myGeomObjects[0])) { case 7: aGroupType = SMESH::NODE; break; case 6: aGroupType = SMESH::EDGE; break; case 4: aGroupType = SMESH::FACE; break; @@ -1221,12 +1448,12 @@ void SMESHGUI_GroupDlg::onAdd() if (aGroupType == aType) { _PTR(SObject) aGroupSO = //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup)); - aStudy->FindObjectID(myGeomGroup->GetStudyEntry()); + aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry()); // Construct filter SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager(); SMESH::Filter_var aFilter = aFilterMgr->CreateFilter(); SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();; - aBelongToGeom->SetGeom(myGeomGroup); + aBelongToGeom->SetGeom(myGeomObjects[0]); aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str()); aBelongToGeom->SetElementType(aType); aFilter->SetPredicate(aBelongToGeom); @@ -1422,6 +1649,29 @@ void SMESHGUI_GroupDlg::onClose() reject(); } +//================================================================================= +// function : onHelp() +// purpose : +//================================================================================= +void SMESHGUI_GroupDlg::onHelp() +{ + LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication()); + if (app) + app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName); + else { + QString platform; +#ifdef WIN32 + platform = "winapplication"; +#else + platform = "application"; +#endif + 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")); + } +} + //================================================================================= // function : SMESHGUI_GroupDlg::onDeactivate // purpose : SLOT called when dialog must be deativated @@ -1455,6 +1705,240 @@ void SMESHGUI_GroupDlg::enterEvent (QEvent*) //================================================================================= void SMESHGUI_GroupDlg::hideEvent (QHideEvent*) { - if (!isMinimized()) + if (!isMinimized() && !myIsBusy) onClose(); } + +//================================================================================= +// function : keyPressEvent() +// purpose : +//================================================================================= +void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e ) +{ + QDialog::keyPressEvent( e ); + if ( e->isAccepted() ) + return; + + if ( e->key() == Key_F1 ) + { + e->accept(); + 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); + } +} + +//================================================================================= +// function : setGroupColor() +// purpose : +//================================================================================= +void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor ) +{ + QColor aQColor( (int)( theColor.R * 255.0 ), + (int)( theColor.G * 255.0 ), + (int)( theColor.B * 255.0 ) ); + setGroupQColor( aQColor ); +} + +//================================================================================= +// function : getGroupColor() +// purpose : +//================================================================================= +SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const +{ + QColor aQColor = getGroupQColor(); + + SALOMEDS::Color aColor; + aColor.R = (float)aQColor.red() / 255.0; + aColor.G = (float)aQColor.green() / 255.0; + aColor.B = (float)aQColor.blue() / 255.0; + + return aColor; +} + +//================================================================================= +// function : setGroupQColor() +// purpose : +//================================================================================= +void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor ) +{ + if( theColor.isValid() ) + { + QPalette pal = myColorBtn->palette(); + pal.setColor(QColorGroup::Button, theColor); + myColorBtn->setPalette(pal); + } +} + +//================================================================================= +// function : getGroupQColor() +// purpose : +//================================================================================= +QColor SMESHGUI_GroupDlg::getGroupQColor() const +{ + QColor aColor = myColorBtn->palette().active().button(); + return aColor; +} + +//================================================================================= +// function : setDefaultGroupColor() +// purpose : +//================================================================================= +void SMESHGUI_GroupDlg::setDefaultGroupColor() +{ + if( myMesh->_is_nil() ) + return; + + bool isAutoColor = myMesh->GetAutoColor(); + + QColor aQColor; + if( !isAutoColor ) + { + int r = 0, g = 0, b = 0; + SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) ); + aQColor.setRgb( r, g, b ); + } + else + { + SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups(); + + QValueList aReservedColors; + for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) + { + SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i]; + SALOMEDS::Color aReservedColor = aGroupObject->GetColor(); + aReservedColors.append( aReservedColor ); + } + + SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors ); + aQColor.setRgb( (int)( aColor.R * 255.0 ), + (int)( aColor.G * 255.0 ), + (int)( aColor.B * 255.0 ) ); + + } + + setGroupQColor( aQColor ); +}