1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
28 #include "SMESHGUI_GroupDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_GroupUtils.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
36 #include "SMESHGUI_FilterDlg.h"
37 #include "SMESHGUI_ShapeByMeshDlg.h"
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_Actor.h>
41 #include <SMESH_ActorUtils.h>
43 // SALOME GEOM includes
45 #include <GEOM_SelectionFilter.h>
47 // SALOME GUI includes
48 #include <QtxColorButton.h>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_MessageBox.h>
55 #include <SalomeApp_Tools.h>
56 #include <SalomeApp_Application.h>
57 #include <SalomeApp_Study.h>
58 #include <LightApp_SelectionMgr.h>
60 #include <SALOME_ListIO.hxx>
61 #include <SALOME_ListIteratorOfListIO.hxx>
63 #include <SVTK_ViewWindow.h>
65 #include <VTKViewer_Algorithm.h>
67 // SALOME KERNEL includes
68 #include <SALOMEDSClient_Study.hxx>
71 #include <vtkRenderer.h>
72 #include <vtkActorCollection.h>
75 #include <TColStd_MapOfInteger.hxx>
78 #include <QButtonGroup>
82 #include <QPushButton>
83 #include <QToolButton>
84 #include <QRadioButton>
86 #include <QGridLayout>
87 #include <QHBoxLayout>
88 #include <QVBoxLayout>
89 #include <QListWidget>
90 #include <QStackedWidget>
102 enum grpSelectionMode {
104 grpNodeSelection = 0,
105 grpEdgeSelection = 1,
106 grpFaceSelection = 2,
107 grpVolumeSelection = 3,
108 grpSubMeshSelection = 4,
109 grpGroupSelection = 5,
110 grpMeshSelection = 6,
111 grpGeomSelection = 7,
115 //=================================================================================
116 // function : SMESHGUI_GroupDlg()
118 //=================================================================================
119 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
120 SMESH::SMESH_Mesh_ptr theMesh )
121 : QDialog( SMESH::GetDesktop( theModule ) ),
122 mySMESHGUI( theModule ),
123 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
124 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
126 myNameChanged( false ),
127 myIsApplyAndClose( false )
130 if ( !theMesh->_is_nil() )
134 mySelectSubMesh->setEnabled( false );
135 mySelectGroup->setEnabled( false );
136 myGeomGroupBtn->setEnabled( false );
137 myGeomGroupLine->setEnabled( false );
141 //=================================================================================
142 // function : SMESHGUI_GroupDlg()
144 //=================================================================================
145 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
146 SMESH::SMESH_GroupBase_ptr theGroup,
147 const bool theIsConvert )
148 : QDialog( SMESH::GetDesktop( theModule ) ),
149 mySMESHGUI( theModule ),
150 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
151 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
153 myNameChanged( false )
156 if ( !theGroup->_is_nil() )
157 init( theGroup, theIsConvert );
160 mySelectSubMesh->setEnabled( false );
161 mySelectGroup->setEnabled( false );
163 myCurrentLineEdit = myMeshGroupLine;
164 setSelectionMode( grpGroupSelection );
168 //=================================================================================
169 // function : SMESHGUI_GroupDlg()
171 //=================================================================================
172 void SMESHGUI_GroupDlg::initDialog( bool create)
175 setAttribute( Qt::WA_DeleteOnClose, true );
179 myCurrentLineEdit = 0;
183 myGeomObjects = new GEOM::ListOfGO();
184 myGeomObjects->length( 0 );
186 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
188 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
189 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
191 setSizeGripEnabled( true);
193 QGridLayout* aMainLayout = new QGridLayout( this );
194 aMainLayout->setMargin( MARGIN );
195 aMainLayout->setSpacing( SPACING );
197 /***************************************************************/
198 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
199 myMeshGroupBtn = new QPushButton( this );
200 myMeshGroupBtn->setIcon( image0 );
201 myMeshGroupLine = new QLineEdit( this );
202 myMeshGroupLine->setReadOnly( true );
204 /***************************************************************/
205 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
206 myTypeGroup = new QButtonGroup( this );
207 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
208 aTypeBoxLayout->setMargin( MARGIN );
209 aTypeBoxLayout->setSpacing( SPACING );
212 types.append( tr( "MESH_NODE" ) );
213 types.append( tr( "SMESH_EDGE" ) );
214 types.append( tr( "SMESH_FACE" ) );
215 types.append( tr( "SMESH_VOLUME" ) );
217 for ( int i = 0; i < types.count(); i++ )
219 rb = new QRadioButton( types[i], aTypeBox );
220 myTypeGroup->addButton( rb, i );
221 aTypeBoxLayout->addWidget( rb );
223 aTypeBox->setEnabled( create );
226 /***************************************************************/
227 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
228 aName->setMinimumWidth( 50 );
229 myName = new QLineEdit( this );
231 /***************************************************************/
232 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
233 myGrpTypeGroup = new QButtonGroup( this );
234 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
235 aGrpTypeBoxLayout->setMargin( MARGIN );
236 aGrpTypeBoxLayout->setSpacing( SPACING );
238 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
239 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
240 myGrpTypeGroup->addButton( rb1, 0 );
241 myGrpTypeGroup->addButton( rb2, 1 );
242 aGrpTypeBoxLayout->addWidget( rb1 );
243 aGrpTypeBoxLayout->addWidget( rb2 );
244 aGrpTypeBox->setEnabled( create );
247 /***************************************************************/
248 myWGStack = new QStackedWidget( this );
249 QWidget* wg1 = new QWidget( myWGStack );
250 QWidget* wg2 = new QWidget( myWGStack );
252 /***************************************************************/
253 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
254 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
255 aContentBoxLayout->setMargin( MARGIN );
256 aContentBoxLayout->setSpacing( SPACING );
258 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
260 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
261 myElements = new QListWidget( aContentBox );
262 myElements->setSelectionMode( QListWidget::ExtendedSelection );
264 myFilter = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
265 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
266 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
267 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
269 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
270 aContentBoxLayout->addWidget( myElementsLab, 1, 0 );
271 aContentBoxLayout->addWidget( myElements, 2, 0, 6, 1 );
272 aContentBoxLayout->addWidget( myFilter, 2, 1 );
273 aContentBoxLayout->addWidget( myAddBtn, 4, 1 );
274 aContentBoxLayout->addWidget( myRemoveBtn, 5, 1 );
275 aContentBoxLayout->addWidget( mySortBtn, 7, 1 );
277 aContentBoxLayout->setColumnStretch( 0, 1 );
278 aContentBoxLayout->setRowStretch( 3, 1 );
279 aContentBoxLayout->setRowStretch( 6, 1 );
281 /***************************************************************/
282 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
283 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
284 mySelectBoxLayout->setMargin( MARGIN );
285 mySelectBoxLayout->setSpacing( SPACING );
287 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
288 mySubMeshBtn = new QPushButton( mySelectBox );
289 mySubMeshBtn->setIcon( image0 );
290 mySubMeshLine = new QLineEdit( mySelectBox );
291 mySubMeshLine->setReadOnly( true );
292 onSelectSubMesh( false );
294 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
295 myGroupBtn = new QPushButton( mySelectBox );
296 myGroupBtn->setIcon( image0 );
297 myGroupLine = new QLineEdit( mySelectBox );
298 myGroupLine->setReadOnly( true );
299 onSelectGroup( false );
301 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
302 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
303 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
304 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
305 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
306 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
308 /***************************************************************/
309 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
310 wg1Layout->setMargin( 0 );
311 wg1Layout->setSpacing( SPACING );
312 wg1Layout->addWidget( aContentBox );
313 wg1Layout->addWidget( mySelectBox );
314 wg1Layout->setStretchFactor( aContentBox, 10 );
316 /***************************************************************/
317 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
318 myGeomGroupBtn = new QToolButton( wg2 );
319 myGeomGroupBtn->setIcon( image0 );
320 myGeomGroupBtn->setCheckable( true );
321 myGeomGroupLine = new QLineEdit( wg2 );
322 myGeomGroupLine->setReadOnly( true ); //VSR ???
323 onSelectGeomGroup( false );
325 myGeomGroupBtn->setEnabled( create );
326 myGeomGroupLine->setEnabled( create );
328 /***************************************************************/
329 QGridLayout* wg2Layout = new QGridLayout( wg2 );
330 wg2Layout->setMargin( 0 );
331 wg1Layout->setSpacing( SPACING );
332 wg2Layout->addWidget( geomObject, 0, 0 );
333 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
334 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
335 wg2Layout->setRowStretch( 1, 5 );
337 /***************************************************************/
338 myWGStack->insertWidget( 0, wg1 );
339 myWGStack->insertWidget( 1, wg2 );
341 /***************************************************************/
342 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
343 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
344 aColorBoxLayout->setMargin(MARGIN);
345 aColorBoxLayout->setSpacing(SPACING);
347 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
348 myColorBtn = new QtxColorButton(aColorBox);
349 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
350 myColorBtn->sizePolicy().verticalPolicy() );
352 aColorBoxLayout->addWidget(aColorLab);
353 aColorBoxLayout->addWidget(myColorBtn);
355 /***************************************************************/
357 QFrame* aButtons = new QFrame(this);
358 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
359 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
360 aBtnLayout->setMargin(MARGIN);
361 aBtnLayout->setSpacing(SPACING);
363 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
364 myOKBtn->setAutoDefault(true);
365 myOKBtn->setDefault(true);
366 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
367 myApplyBtn->setAutoDefault(true);
368 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
369 myCloseBtn->setAutoDefault(true);
370 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
371 myHelpBtn->setAutoDefault(true);
373 aBtnLayout->addWidget(myOKBtn);
374 aBtnLayout->addSpacing(10);
375 aBtnLayout->addWidget(myApplyBtn);
376 aBtnLayout->addSpacing(10);
377 aBtnLayout->addStretch();
378 aBtnLayout->addWidget(myCloseBtn);
379 aBtnLayout->addWidget(myHelpBtn);
381 /***************************************************************/
382 aMainLayout->addWidget(meshGroupLab, 0, 0);
383 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
384 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
385 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
386 aMainLayout->addWidget(aName, 2, 0);
387 aMainLayout->addWidget(myName, 2, 2);
388 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
389 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
390 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
391 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
393 /* signals and slots connections */
394 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
395 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
396 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
398 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
399 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
401 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
402 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
403 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
404 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
405 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
407 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
408 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
409 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
410 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
411 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
413 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
415 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
416 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
417 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
418 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
421 mySMESHGUI->SetActiveDialogBox(this);
422 mySMESHGUI->SetState(800);
424 mySelectionMode = grpNoSelection;
425 myMeshFilter = new SMESH_TypeFilter(MESH);
426 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
427 myGroupFilter = new SMESH_TypeFilter(GROUP);
428 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
429 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
431 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
432 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
433 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
434 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
436 rb1->setChecked(true); // VSR !!!
437 onGrpTypeChanged(0); // VSR!!!
439 if (myMesh->_is_nil() )
440 myTypeGroup->button(0)->setChecked(true);
443 //myName->setText(GetDefaultName(tr( "SMESH_GROUP" )));
446 //=================================================================================
447 // function : ~SMESHGUI_GroupDlg()
448 // purpose : Destroys the object and frees any allocated resources
449 //=================================================================================
450 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
452 // no need to delete child widgets, Qt does it all for us
453 if ( myFilterDlg != 0 ) {
454 myFilterDlg->setParent( 0 );
459 //=================================================================================
460 // function : GetDefaultName()
461 // purpose : Get the Group Name if Create new Group
462 //=================================================================================
463 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
467 // collect all object names of SMESH component
468 SalomeApp_Study* appStudy =
469 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
470 if ( !appStudy ) return aName;
471 _PTR(Study) aStudy = appStudy->studyDS();
473 std::set<std::string> aSet;
474 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
476 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
478 for (it->InitEx(true); it->More(); it->Next()) {
480 aSet.insert(obj->GetName());
484 // build a unique name
486 bool isUnique = false;
488 aName = theOperation + "_" + QString::number(++aNumber);
489 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
495 //=================================================================================
498 //=================================================================================
499 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
501 mySelectionMgr->installFilter(myMeshFilter);
503 /* init data from current selection */
504 restoreShowEntityMode();
505 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
507 myGroup = SMESH::SMESH_Group::_nil();
508 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
510 // NPAL19389: create a group with a selection in another group
511 // set actor of myMesh, if it is visible, else try
512 // any visible actor of group or submesh of myMesh
513 SetAppropriateActor();
515 setDefaultGroupColor();
518 mySelectionMgr->selectedObjects( aList );
519 if( !aList.IsEmpty() )
521 QString aName = aList.First()->getName();
522 myMeshGroupLine->setText(aName);
523 myMeshGroupLine->home( false );
526 myCurrentLineEdit = 0;
528 myTypeGroup->button(0)->setChecked(true);
532 //=================================================================================
535 //=================================================================================
536 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
537 const bool theIsConvert)
539 restoreShowEntityMode();
540 myMesh = theGroup->GetMesh();
543 myNameChanged = true;
544 myName->blockSignals(true);
545 myName->setText(theGroup->GetName());
546 myName->blockSignals(false);
549 SALOMEDS::Color aColor = theGroup->GetColor();
550 setGroupColor( aColor );
552 myMeshGroupLine->setText(theGroup->GetName());
555 switch(theGroup->GetType()) {
556 case SMESH::NODE: aType= 0; break;
557 case SMESH::EDGE: aType = 1; break;
558 case SMESH::FACE: aType = 2; break;
559 case SMESH::VOLUME: aType = 3; break;
561 myTypeGroup->button(aType)->setChecked(true);
563 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
564 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
566 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil())
569 // NPAL19389: create a group with a selection in another group
570 // set actor of myMesh, if it is visible, else set
571 // actor of theGroup, if it is visible, else try
572 // any visible actor of group or submesh of myMesh
573 // commented, because an attempt to set selection on not displayed cells leads to error
574 SetAppropriateActor();
576 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
578 anActor = SMESH::FindActorByObject(theGroup);
579 SMESH::SetPickable(anActor);*/
581 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : 1));
582 myGrpTypeGroup->button(grpType)->setChecked(true);
583 onGrpTypeChanged(grpType);
586 if ( grpType == 0 ) {
587 myCurrentLineEdit = 0;
589 setSelectionMode(aType);
591 setShowEntityMode(); // depends on myTypeId
594 if (!theGroup->IsEmpty()) {
595 SMESH::long_array_var anElements = theGroup->GetListOfID();
596 int k = anElements->length();
597 for (int i = 0; i < k; i++) {
598 myIdList.append(anElements[i]);
599 myElements->addItem(QString::number(anElements[i]));
601 myElements->selectAll();
606 QString aShapeName( "" );
607 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
608 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
609 if (!aGroupShape->_is_nil())
611 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
613 aShapeName = aGroupShapeSO->GetName().c_str();
615 myGeomGroupLine->setText( aShapeName );
616 myNameChanged = true;
617 myName->blockSignals(true);
618 myName->setText(theGroup->GetName());
619 myName->blockSignals(false);
624 //=================================================================================
625 // function : updateButtons()
627 //=================================================================================
628 void SMESHGUI_GroupDlg::updateButtons()
630 bool enable = !myName->text().trimmed().isEmpty();
632 if (myGrpTypeId == 0) {
633 enable = enable && (mySelectAll->isChecked() || myElements->count() > 0);
634 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
636 else if (myGrpTypeId == 1) {
637 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
638 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
642 myOKBtn->setEnabled(enable);
643 myApplyBtn->setEnabled(enable);
646 //=================================================================================
647 // function : onNameChanged()
649 //=================================================================================
650 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
652 myOldName = myName->text();
654 myNameChanged = !myName->text().trimmed().isEmpty();
657 //=================================================================================
658 // function : onTypeChanged()
659 // purpose : Group elements type radio button management
660 //=================================================================================
661 void SMESHGUI_GroupDlg::onTypeChanged (int id)
663 if (myTypeId != id) {
665 if (myCurrentLineEdit == 0)
666 setSelectionMode(id);
672 //=================================================================================
673 // function : onGrpTypeChanged()
674 // purpose : Group type radio button management
675 //=================================================================================
676 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
678 if (myGrpTypeId != id) {
679 myWGStack->setCurrentIndex( id );
680 myName->blockSignals(true);
681 myName->setText(myOldName);
682 myName->blockSignals(false);
683 onSelectGeomGroup(id == 1);
688 //=================================================================================
689 // function : onColorChanged()
690 // purpose : Color button management
691 //=================================================================================
692 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
697 //=================================================================================
698 // function : setSelectionMode()
699 // purpose : Radio button management
700 //=================================================================================
701 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
704 if (myMesh->_is_nil())
706 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
707 bool isSelectAll = mySelectAll->isChecked();
708 if (mySelectionMode != theMode) {
709 // [PAL10408] mySelectionMgr->clearSelected();
710 mySelectionMgr->clearFilters();
711 if (myActorsList.count() > 0) {
712 QListIterator<SMESH_Actor*> it( myActorsList );
713 while ( it.hasNext() )
714 it.next()->SetPointRepresentation(false);
717 SMESH::SetPointRepresentation(false);
720 case grpNodeSelection:
721 if (myActorsList.count() > 0) {
722 QListIterator<SMESH_Actor*> it( myActorsList );
723 while ( it.hasNext() )
724 it.next()->SetPointRepresentation(true);
727 SMESH::SetPointRepresentation(true);
729 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
731 case grpEdgeSelection:
732 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
734 case grpFaceSelection:
735 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
737 case grpVolumeSelection:
738 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
740 case grpSubMeshSelection:
741 mySelectionMgr->installFilter(mySubMeshFilter);
742 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
744 case grpGroupSelection:
745 mySelectionMgr->installFilter(myGroupFilter);
746 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
748 case grpMeshSelection:
749 mySelectionMgr->installFilter(myMeshFilter);
750 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
752 case grpGeomSelection:
753 mySelectionMgr->installFilter(myGeomFilter);
754 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
757 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
760 if ( aViewWindow ) aViewWindow->Repaint();
761 mySelectionMode = theMode;
765 //=================================================================================
766 // function : onApply()
768 //=================================================================================
769 bool SMESHGUI_GroupDlg::onApply()
771 if (mySMESHGUI->isActiveStudyLocked())
774 if (myName->text().trimmed().isEmpty())
778 QStringList anEntryList;
779 if (myGrpTypeId == 0) { // on mesh elements
780 if (!mySelectAll->isChecked() && !myElements->count())
783 mySelectionMgr->clearSelected();
785 if (myGroup->_is_nil()) { // creation or conversion
786 // check if group on geometry is not null
787 if (!CORBA::is_nil(myGroupOnGeom)) {
788 if (myMesh->_is_nil())
790 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
791 // nullify pointer, because object become dead
792 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
796 if (myGroup->_is_nil()) { // creation
797 if (myMesh->_is_nil())
800 SMESH::ElementType aType = SMESH::ALL;
802 case 0: aType = SMESH::NODE; break;
803 case 1: aType = SMESH::EDGE; break;
804 case 2: aType = SMESH::FACE; break;
805 case 3: aType = SMESH::VOLUME; break;
808 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
810 if ( mySelectAll->isChecked() ) {
812 myGroup->AddFrom(myMesh.in());
816 SMESH::long_array_var anIdList = new SMESH::long_array;
817 int i, k = myElements->count();
819 for (i = 0; i < k; i++) {
820 anIdList[i] = myElements->item(i)->text().toInt();
823 myGroup->Add(anIdList.inout());
826 SALOMEDS::Color aColor = getGroupColor();
827 myGroup->SetColor(aColor);
829 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
831 anEntryList.append( aMeshGroupSO->GetID().c_str() );
833 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
834 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
836 /* init for next operation */
837 myName->setText( "" );
839 myGroup = SMESH::SMESH_Group::_nil();
842 myGroup->SetName(myName->text().toLatin1().data());
844 SALOMEDS::Color aColor = getGroupColor();
845 myGroup->SetColor(aColor);
847 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
848 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
849 anActor->setName(myName->text().toLatin1().data());
850 switch ( myTypeId ) {
851 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
852 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
854 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
858 if ( mySelectAll->isChecked() ) {
861 myGroup->AddFrom(myMesh.in());
866 int i, total = myElements->count();
867 for (i = 0; i < total; i++) {
868 int anId = myElements->item(i)->text().toInt();
869 int idx = myIdList.indexOf(anId);
871 aAddList.append(anId);
873 myIdList.removeAt(idx);
875 if (!aAddList.empty()) {
876 SMESH::long_array_var anIdList = new SMESH::long_array;
877 int added = aAddList.count();
878 anIdList->length(added);
879 for (i = 0; i < added; i++)
880 anIdList[i] = aAddList[i];
881 myGroup->Add(anIdList.inout());
883 if (!myIdList.empty()) {
884 SMESH::long_array_var anIdList = new SMESH::long_array;
885 int removed = myIdList.count();
886 anIdList->length(removed);
887 for (i = 0; i < removed; i++)
888 anIdList[i] = myIdList[i];
889 myGroup->Remove(anIdList.inout());
891 /* init for next operation */
893 for (i = 0; i < total; i++) {
894 myIdList.append(myElements->item(i)->text().toInt());
899 SMESHGUI::Modified();
900 mySMESHGUI->updateObjBrowser(true);
901 SMESH::UpdateView(); // asv: fix of BUG PAL5515
902 mySelectionMgr->clearSelected();
905 else if (myGrpTypeId == 1) { // on geom object
906 if (CORBA::is_nil(myGroupOnGeom)) { // creation
907 if (myMesh->_is_nil() || !myGeomObjects->length())
910 SMESH::ElementType aType = SMESH::ALL;
912 case 0: aType = SMESH::NODE; break;
913 case 1: aType = SMESH::EDGE; break;
914 case 2: aType = SMESH::FACE; break;
915 case 3: aType = SMESH::VOLUME; break;
918 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
919 GEOM::GEOM_IGroupOperations_var aGroupOp =
920 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
922 if (myGeomObjects->length() == 1) {
923 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
924 myName->text().toLatin1().data(),
928 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
929 if ( aSMESHGen->_is_nil() )
932 // create a geometry group
933 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
934 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
936 if (geomGen->_is_nil() || !aStudy)
939 GEOM::GEOM_IGroupOperations_var op =
940 geomGen->GetIGroupOperations(aStudy->StudyId());
944 // check and add all selected GEOM objects: they must be
945 // a sub-shapes of the main GEOM and must be of one type
946 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
947 for ( int i =0; i < myGeomObjects->length(); i++) {
948 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
950 aGroupType = aSubShapeType;
951 else if (aSubShapeType != aGroupType) {
952 aGroupType = TopAbs_SHAPE;
957 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
958 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
959 op->UnionList(aGroupVar, myGeomObjects);
962 // publish the GEOM group in study
963 QString aNewGeomGroupName ( "Auto_group_for_" );
964 aNewGeomGroupName += myName->text();
965 SALOMEDS::SObject_var aNewGroupSO =
966 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
967 aNewGeomGroupName.toLatin1().data(), aMeshShape);
970 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
971 myName->text().toLatin1().data(),
975 SALOMEDS::Color aColor = getGroupColor();
976 myGroupOnGeom->SetColor(aColor);
978 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
980 anEntryList.append( aMeshGroupSO->GetID().c_str() );
982 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
983 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
985 /* init for next operation */
986 myName->setText( "" );
987 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
990 myGroupOnGeom->SetName(myName->text().toLatin1().data());
992 SALOMEDS::Color aColor = getGroupColor();
993 myGroupOnGeom->SetColor(aColor);
995 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
996 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
997 anActor->setName(myName->text().toLatin1().data());
998 switch ( myTypeId ) {
999 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1000 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1002 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
1007 SMESHGUI::Modified();
1008 mySMESHGUI->updateObjBrowser(true);
1009 mySelectionMgr->clearSelected();
1014 if( LightApp_Application* anApp =
1015 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1016 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1021 //=================================================================================
1022 // function : onOK()
1024 //=================================================================================
1025 void SMESHGUI_GroupDlg::onOK()
1027 setIsApplyAndClose( true );
1030 setIsApplyAndClose( false );
1033 //=================================================================================
1034 // function : onListSelectionChanged()
1035 // purpose : Called when selection in element list is changed
1036 //=================================================================================
1037 void SMESHGUI_GroupDlg::onListSelectionChanged()
1039 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1040 if( myIsBusy || myActorsList.count() == 0 ) return;
1043 if (myCurrentLineEdit == 0) {
1044 mySelectionMgr->clearSelected();
1045 TColStd_MapOfInteger aIndexes;
1046 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1047 QListWidgetItem* anItem;
1048 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1049 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1050 SALOME_ListIO aList;
1051 aList.Append(myActorsList.first()->getIO());
1052 mySelectionMgr->setSelectedObjects(aList,false);
1057 //=================================================================================
1058 // function : onObjectSelectionChanged()
1059 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1060 //=================================================================================
1061 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1063 if ( myIsBusy || !isEnabled()) return;
1064 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1068 SALOME_ListIO aList;
1069 mySelectionMgr->selectedObjects( aList );
1071 int aNbSel = aList.Extent();
1072 myElements->clearSelection();
1074 if (myCurrentLineEdit)
1076 myCurrentLineEdit->setText( "" );
1077 QString aString = "";
1079 if (myCurrentLineEdit == myMeshGroupLine)
1081 mySelectSubMesh->setEnabled(false);
1082 mySelectGroup->setEnabled(false);
1083 myGroupLine->setText( "" );
1084 mySubMeshLine->setText( "" );
1086 myGeomGroupBtn->setEnabled(false);
1087 myGeomGroupLine->setEnabled(false);
1088 myGeomGroupLine->setText( "" );
1089 myGeomObjects = new GEOM::ListOfGO();
1090 myGeomObjects->length(0);
1092 if (myGeomGroupBtn->isChecked())
1093 myGeomGroupBtn->setChecked(false);
1095 myName->setText( "" );
1097 myElements->clear();
1100 myGroup = SMESH::SMESH_Group::_nil();
1101 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1102 restoreShowEntityMode();
1103 myMesh = SMESH::SMESH_Mesh::_nil();
1109 Handle(SALOME_InteractiveObject) IO = aList.First();
1112 restoreShowEntityMode();
1113 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1114 setShowEntityMode();
1116 if (myMesh->_is_nil())
1123 if ( myFilterDlg && !myMesh->_is_nil()){
1124 myFilterDlg->SetMesh( myMesh );
1126 myGroup = SMESH::SMESH_Group::_nil();
1128 // NPAL19389: create a group with a selection in another group
1129 // set actor of myMesh, if it is visible, else try
1130 // any visible actor of group or submesh of myMesh
1131 SetAppropriateActor();
1133 aString = aList.First()->getName();
1134 myMeshGroupLine->setText(aString);
1135 myMeshGroupLine->home( false );
1137 mySelectSubMesh->setEnabled(true);
1138 mySelectGroup->setEnabled(true);
1139 myGeomGroupBtn->setEnabled(true);
1140 myGeomGroupLine->setEnabled(true);
1144 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1145 if (aGroup->_is_nil())
1152 myGroup = SMESH::SMESH_Group::_nil();
1153 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1157 mySelectSubMesh->setEnabled(true);
1158 mySelectGroup->setEnabled(true);
1160 myCurrentLineEdit = 0;
1165 if (myGrpTypeId == 0)
1171 myElements->clear();
1172 setSelectionMode(myTypeId);
1180 else if (myCurrentLineEdit == myGeomGroupLine)
1182 myGeomObjects = new GEOM::ListOfGO();
1185 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1187 if (aNbSel == 0 || !aMeshSO)
1189 myGeomObjects->length(0);
1195 myGeomObjects->length(aNbSel);
1197 GEOM::GEOM_Object_var aGeomGroup;
1200 SALOME_ListIteratorOfListIO anIt (aList);
1201 for (; anIt.More(); anIt.Next())
1203 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1205 // Check if the object is a geometry group
1206 if (CORBA::is_nil(aGeomGroup))
1209 // Check if group constructed on the same shape as a mesh or on its child
1210 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1211 GEOM::GEOM_IGroupOperations_var anOp =
1212 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1214 // The main shape of the group
1215 GEOM::GEOM_Object_var aGroupMainShape;
1216 if (aGeomGroup->GetType() == 37)
1217 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1219 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1220 _PTR(SObject) aGroupMainShapeSO =
1221 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1222 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1224 _PTR(SObject) anObj, aRef;
1225 bool isRefOrSubShape = false;
1226 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1227 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1228 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1229 isRefOrSubShape = true;
1231 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1232 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1233 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1234 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1235 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1236 if (aRef->GetID() == aFather->GetID())
1237 isRefOrSubShape = true;
1239 aFather = aFather->GetFather();
1243 if (isRefOrSubShape)
1244 myGeomObjects[i++] = aGeomGroup;
1247 myGeomObjects->length(i);
1259 if (myCurrentLineEdit == mySubMeshLine)
1260 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1261 else if (myCurrentLineEdit == myGroupLine)
1262 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1263 else if (myCurrentLineEdit == myGeomGroupLine)
1264 aString = tr( "%1 Objects" ).arg(aNbSel);
1267 aString = aList.First()->getName();
1271 myCurrentLineEdit->setText(aString);
1272 myCurrentLineEdit->home(false);
1273 // 07.06.2008 skl for IPAL19574:
1274 // change name of group only if it is empty
1275 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1276 myOldName = myName->text();
1277 myName->blockSignals(true);
1278 myName->setText(aString);
1279 myName->blockSignals(false);
1284 else // !myCurrentLineEdit: local selection of nodes or elements
1286 if (aNbSel == 1 && myActorsList.count() > 0 )
1288 // NPAL19389: create a group with a selection in another group
1289 // Switch myActor to the newly selected one, if the last
1290 // is visible and belongs to group or submesh of myMesh
1291 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1292 Handle(SALOME_InteractiveObject) selIO = aList.First();
1293 if (curIO->hasEntry() && selIO->hasEntry()) {
1294 const char* selEntry = selIO->getEntry();
1295 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1296 // different objects: selected and myActor
1297 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1298 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1299 // newly selected actor is visible
1302 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1304 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1305 int len = strlen(meshEntry);
1307 if (strncmp(selEntry, meshEntry, len) == 0) {
1308 // selected object is myMesh or a part of it
1309 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1312 SMESH::SetPickable(myActor);
1321 QString aListStr = "";
1323 if (myTypeId == 0) {
1324 QListIterator<SMESH_Actor*> it( myActorsList );
1325 while ( it.hasNext() ) {
1327 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1331 QListIterator<SMESH_Actor*> it( myActorsList );
1332 while ( it.hasNext() ) {
1334 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1339 QListWidgetItem* anItem;
1340 QList<QListWidgetItem*> listItemsToSel;
1341 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1342 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1343 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1344 foreach(anItem, found)
1345 if (!anItem->isSelected())
1346 listItemsToSel.push_back(anItem);
1348 bool blocked = myElements->signalsBlocked();
1349 myElements->blockSignals(true);
1350 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1351 myElements->blockSignals(blocked);
1352 onListSelectionChanged();
1353 listItemsToSel.clear();
1358 if (myActorsList.count() == 0) {
1359 if (!myGroup->_is_nil()) {
1360 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1362 myActorsList.append( anActor );
1364 else if(!myGroupOnGeom->_is_nil()) {
1365 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1367 myActorsList.append( anActor );
1370 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1372 myActorsList.append( anActor );
1376 // somehow, if we display the mesh, while selecting from another actor,
1377 // the mesh becomes pickable, and there is no way to select any element
1378 if (myActorsList.count() > 0) {
1379 QListIterator<SMESH_Actor*> it( myActorsList );
1380 while ( it.hasNext() ) {
1381 SMESH_Actor* anActor = it.next();
1382 if ( IsActorVisible(anActor) )
1383 anActor->SetPickable(true);
1390 //=================================================================================
1391 // function : onSelectSubMesh()
1392 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1393 //=================================================================================
1394 void SMESHGUI_GroupDlg::onSelectAll()
1396 myElementsLab->setEnabled( !mySelectAll->isChecked() );
1397 myElements->setEnabled( !mySelectAll->isChecked() );
1398 myFilter->setEnabled( !mySelectAll->isChecked() );
1399 myAddBtn->setEnabled( !mySelectAll->isChecked() );
1400 myRemoveBtn->setEnabled( !mySelectAll->isChecked() );
1401 mySortBtn->setEnabled( !mySelectAll->isChecked() );
1402 mySelectBox->setEnabled( !mySelectAll->isChecked() );
1403 int selMode = mySelectionMode;
1404 mySelectionMode = grpNoSelection;
1405 setSelectionMode( selMode );
1408 //=================================================================================
1409 // function : onSelectSubMesh()
1410 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1411 //=================================================================================
1412 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1415 if (mySelectGroup->isChecked()) {
1416 mySelectGroup->setChecked(false);
1418 //VSR: else if (mySelectGeomGroup->isChecked()) {
1419 //VSR: mySelectGeomGroup->setChecked(false);
1421 myCurrentLineEdit = mySubMeshLine;
1422 setSelectionMode(grpSubMeshSelection);
1425 mySubMeshLine->setText( "" );
1426 myCurrentLineEdit = 0;
1428 setSelectionMode(myTypeId);
1430 mySubMeshBtn->setEnabled(on);
1431 mySubMeshLine->setEnabled(on);
1435 //=================================================================================
1436 // function : (onSelectGroup)
1437 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1438 //=================================================================================
1439 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1442 if (mySelectSubMesh->isChecked()) {
1443 mySelectSubMesh->setChecked(false);
1445 myCurrentLineEdit = myGroupLine;
1446 setSelectionMode(grpGroupSelection);
1449 myGroupLine->setText( "" );
1450 myCurrentLineEdit = 0;
1452 setSelectionMode(myTypeId);
1454 myGroupBtn->setEnabled(on);
1455 myGroupLine->setEnabled(on);
1459 //=================================================================================
1460 // function : (onSelectGeomGroup)
1461 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1462 //=================================================================================
1463 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1466 if (mySelectSubMesh->isChecked()) {
1467 mySelectSubMesh->setChecked(false);
1469 else if (mySelectGroup->isChecked()) {
1470 mySelectGroup->setChecked(false);
1472 myCurrentLineEdit = myGeomGroupLine;
1474 setSelectionMode(grpAllSelection);
1477 myGeomGroupBtn->setChecked(false);
1478 myGeomObjects->length(0);
1479 myGeomGroupLine->setText( "" );
1480 myCurrentLineEdit = 0;
1482 setSelectionMode(myTypeId);
1487 //=================================================================================
1488 // function : setCurrentSelection()
1490 //=================================================================================
1491 void SMESHGUI_GroupDlg::setCurrentSelection()
1493 QPushButton* send = (QPushButton*)sender();
1494 myCurrentLineEdit = 0;
1495 if (send == myMeshGroupBtn) {
1496 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1497 mySelectionMgr->clearSelected();
1499 setSelectionMode(grpMeshSelection);
1501 setSelectionMode(grpGroupSelection);
1502 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1503 myCurrentLineEdit = myMeshGroupLine;
1504 onObjectSelectionChanged();
1506 else if (send == mySubMeshBtn) {
1507 myCurrentLineEdit = mySubMeshLine;
1508 onObjectSelectionChanged();
1510 else if (send == myGroupBtn) {
1511 myCurrentLineEdit = myGroupLine;
1512 onObjectSelectionChanged();
1517 //=================================================================================
1518 // function : setFilters()
1519 // purpose : SLOT. Called when "Filter" button pressed.
1520 //=================================================================================
1521 void SMESHGUI_GroupDlg::setFilters()
1523 if(myMesh->_is_nil()) {
1524 SUIT_MessageBox::critical(this,
1526 tr("NO_MESH_SELECTED"));
1530 SMESH::ElementType aType = SMESH::ALL;
1533 case 0 : aType = SMESH::NODE; break;
1534 case 1 : aType = SMESH::EDGE; break;
1535 case 2 : aType = SMESH::FACE; break;
1536 case 3 : aType = SMESH::VOLUME; break;
1540 if ( myFilterDlg == 0 )
1542 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1543 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1546 myFilterDlg->Init( aType );
1548 myFilterDlg->SetSelection();
1549 myFilterDlg->SetMesh( myMesh );
1550 myFilterDlg->SetSourceWg( myElements, false );
1552 myFilterDlg->show();
1555 //=================================================================================
1556 // function : onFilterAccepted()
1557 // purpose : SLOT. Called when Filter dlg closed with OK button.
1558 // Uncheck "Select submesh" and "Select group" checkboxes
1559 //=================================================================================
1560 void SMESHGUI_GroupDlg::onFilterAccepted()
1562 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1564 mySelectionMode = myTypeId;
1565 mySelectSubMesh->setChecked( false );
1566 mySelectGroup->setChecked( false );
1570 //=================================================================================
1571 // function : onAdd()
1573 //=================================================================================
1574 void SMESHGUI_GroupDlg::onAdd()
1576 SALOME_ListIO aList;
1577 mySelectionMgr->selectedObjects( aList );
1579 int aNbSel = aList.Extent();
1581 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1585 SMESH::ElementType aType = SMESH::ALL;
1588 aType = SMESH::NODE;
1589 mySelector->SetSelectionMode(NodeSelection);
1592 aType = SMESH::EDGE;
1593 mySelector->SetSelectionMode(EdgeSelection);
1596 aType = SMESH::FACE;
1597 mySelector->SetSelectionMode(FaceSelection);
1600 aType = SMESH::VOLUME;
1601 mySelector->SetSelectionMode(VolumeSelection);
1604 mySelector->SetSelectionMode(ActorSelection);
1607 QListWidgetItem* anItem = 0;
1608 QList<QListWidgetItem*> listItemsToSel;
1610 if (myCurrentLineEdit == 0) {
1611 //if (aNbSel != 1) { myIsBusy = false; return; }
1612 QString aListStr = "";
1614 if (myTypeId == 0) {
1615 QListIterator<SMESH_Actor*> it( myActorsList );
1616 while ( it.hasNext() ) {
1618 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1623 QListIterator<SMESH_Actor*> it( myActorsList );
1624 while ( it.hasNext() ) {
1626 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1631 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1632 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1633 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1634 if (found.count() == 0) {
1635 anItem = new QListWidgetItem(*it);
1636 myElements->addItem(anItem);
1637 if (!anItem->isSelected())
1638 listItemsToSel.push_back(anItem);
1641 foreach(anItem, found)
1642 if (!anItem->isSelected())
1643 listItemsToSel.push_back(anItem);
1646 bool blocked = myElements->signalsBlocked();
1647 myElements->blockSignals(true);
1648 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1649 myElements->blockSignals(blocked);
1650 onListSelectionChanged();
1651 listItemsToSel.clear();
1653 } else if (myCurrentLineEdit == mySubMeshLine) {
1654 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1656 SALOME_ListIO aList;
1657 mySelectionMgr->selectedObjects( aList );
1659 SALOME_ListIteratorOfListIO anIt (aList);
1660 for ( ; anIt.More(); anIt.Next()) {
1661 SMESH::SMESH_subMesh_var aSubMesh =
1662 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1663 if (!aSubMesh->_is_nil()) {
1664 // check if mesh is the same
1665 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1667 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1668 int k = anElements->length();
1669 for (int i = 0; i < k; i++) {
1670 QString aText = QString::number(anElements[i]);
1671 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1672 if (found.count() == 0) {
1673 anItem = new QListWidgetItem(aText);
1674 myElements->addItem(anItem);
1675 if (!anItem->isSelected())
1676 listItemsToSel.push_back(anItem);
1679 foreach(anItem, found)
1680 if (!anItem->isSelected())
1681 listItemsToSel.push_back(anItem);
1684 bool blocked = myElements->signalsBlocked();
1685 myElements->blockSignals(true);
1686 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1687 myElements->blockSignals(blocked);
1688 onListSelectionChanged();
1689 listItemsToSel.clear();
1691 catch (const SALOME::SALOME_Exception& ex) {
1692 SalomeApp_Tools::QtCatchCorbaException(ex);
1697 mySelectSubMesh->setChecked(false);
1699 onListSelectionChanged();
1701 } else if (myCurrentLineEdit == myGroupLine) {
1702 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1703 SALOME_ListIO aList;
1704 mySelectionMgr->selectedObjects( aList );
1706 SALOME_ListIteratorOfListIO anIt (aList);
1707 for ( ; anIt.More(); anIt.Next()) {
1708 SMESH::SMESH_GroupBase_var aGroup =
1709 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1710 if (!aGroup->_is_nil()) {
1711 // check if mesh is the same
1712 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1713 SMESH::long_array_var anElements = aGroup->GetListOfID();
1714 int k = anElements->length();
1715 for (int i = 0; i < k; i++) {
1716 QString aText = QString::number(anElements[i]);
1717 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1718 if (found.count() == 0) {
1719 anItem = new QListWidgetItem(aText);
1720 myElements->addItem(anItem);
1721 if (!anItem->isSelected())
1722 listItemsToSel.push_back(anItem);
1725 foreach(anItem, found)
1726 if (!anItem->isSelected())
1727 listItemsToSel.push_back(anItem);
1730 bool blocked = myElements->signalsBlocked();
1731 myElements->blockSignals(true);
1732 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1733 myElements->blockSignals(blocked);
1734 onListSelectionChanged();
1735 listItemsToSel.clear();
1739 mySelectGroup->setChecked(false);
1741 onListSelectionChanged();
1743 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1744 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1745 GEOM::GEOM_IGroupOperations_var aGroupOp =
1746 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1748 SMESH::ElementType aGroupType = SMESH::ALL;
1749 switch(aGroupOp->GetType(myGeomObjects[0])) {
1750 case 7: aGroupType = SMESH::NODE; break;
1751 case 6: aGroupType = SMESH::EDGE; break;
1752 case 4: aGroupType = SMESH::FACE; break;
1753 case 2: aGroupType = SMESH::VOLUME; break;
1754 default: myIsBusy = false; return;
1757 if (aGroupType == aType) {
1758 _PTR(SObject) aGroupSO =
1759 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1760 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1762 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1763 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1764 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1765 aBelongToGeom->SetGeom(myGeomObjects[0]);
1766 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1767 aBelongToGeom->SetElementType(aType);
1768 aFilter->SetPredicate(aBelongToGeom);
1770 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1772 int k = anElements->length();
1773 for (int i = 0; i < k; i++) {
1774 QString aText = QString::number(anElements[i]);
1775 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1776 if (found.count() == 0) {
1777 anItem = new QListWidgetItem(aText);
1778 myElements->addItem(anItem);
1779 if (!anItem->isSelected())
1780 listItemsToSel.push_back(anItem);
1783 foreach(anItem, found)
1784 if (!anItem->isSelected())
1785 listItemsToSel.push_back(anItem);
1788 bool blocked = myElements->signalsBlocked();
1789 myElements->blockSignals(true);
1790 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1791 myElements->blockSignals(blocked);
1792 onListSelectionChanged();
1793 listItemsToSel.clear();
1796 //VSR: mySelectGeomGroup->setChecked(false);
1798 onListSelectionChanged();
1801 // mySelectionMgr->clearSelected();
1805 //=================================================================================
1806 // function : onRemove()
1808 //=================================================================================
1809 void SMESHGUI_GroupDlg::onRemove()
1812 if (myCurrentLineEdit == 0) {
1813 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1814 QListWidgetItem* item;
1815 foreach(item, selItems) delete item;
1817 SALOME_ListIO aList;
1818 mySelectionMgr->selectedObjects( aList );
1820 int aNbSel = aList.Extent();
1822 if (aNbSel == 0) { myIsBusy = false; return; }
1824 SMESH::ElementType aType = SMESH::ALL;
1826 case 0: aType = SMESH::NODE; break;
1827 case 1: aType = SMESH::EDGE; break;
1828 case 2: aType = SMESH::FACE; break;
1829 case 3: aType = SMESH::VOLUME; break;
1832 if (myCurrentLineEdit == mySubMeshLine) {
1833 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1834 SALOME_ListIO aList;
1835 mySelectionMgr->selectedObjects( aList );
1837 SALOME_ListIteratorOfListIO anIt (aList);
1838 for ( ; anIt.More(); anIt.Next()) {
1839 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1840 if (!aSubMesh->_is_nil()) {
1841 // check if mesh is the same
1842 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1843 if (aType == SMESH::NODE) {
1845 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1846 int k = anElements->length();
1847 for (int i = 0; i < k; i++) {
1848 QList<QListWidgetItem*> found =
1849 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1850 QListWidgetItem* anItem;
1851 foreach(anItem, found) delete anItem;
1854 catch (const SALOME::SALOME_Exception& ex) {
1855 SalomeApp_Tools::QtCatchCorbaException(ex);
1860 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1861 int k = anElements->length();
1862 for (int i = 0; i < k; i++) {
1863 QList<QListWidgetItem*> found =
1864 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1865 QListWidgetItem* anItem;
1866 foreach(anItem, found) delete anItem;
1869 catch (const SALOME::SALOME_Exception& ex) {
1870 SalomeApp_Tools::QtCatchCorbaException(ex);
1877 else if (myCurrentLineEdit == myGroupLine) {
1878 Standard_Boolean aRes;
1879 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1880 SALOME_ListIO aList;
1881 mySelectionMgr->selectedObjects( aList );
1883 SALOME_ListIteratorOfListIO anIt (aList);
1884 for ( ; anIt.More(); anIt.Next()) {
1885 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1886 if (aRes && !aGroup->_is_nil()) {
1887 // check if mesh is the same
1888 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1889 SMESH::long_array_var anElements = aGroup->GetListOfID();
1890 int k = anElements->length();
1891 for (int i = 0; i < k; i++) {
1892 QList<QListWidgetItem*> found =
1893 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1894 QListWidgetItem* anItem;
1895 foreach(anItem, found) delete anItem;
1906 //=================================================================================
1907 // function : onSort()
1909 //=================================================================================
1910 void SMESHGUI_GroupDlg::onSort()
1912 // PAL5412: sorts items in ascending by "string" value
1913 // myElements->sort(true);
1914 // myElements->update();
1915 int i, k = myElements->count();
1918 QList<int> aSelected;
1919 std::vector<int> anArray(k);
1920 // QMemArray<int> anArray(k);
1922 for (i = 0; i < k; i++) {
1923 int id = myElements->item(i)->text().toInt();
1925 if (myElements->item(i)->isSelected())
1926 aSelected.append(id);
1928 // sort & update list
1929 std::sort(anArray.begin(), anArray.end());
1931 myElements->clear();
1932 QListWidgetItem* anItem;
1933 QList<QListWidgetItem*> listItemsToSel;
1934 for (i = 0; i < k; i++) {
1935 anItem = new QListWidgetItem(QString::number(anArray[i]));
1936 myElements->addItem(anItem);
1937 if (aSelected.contains(anArray[i]))
1938 listItemsToSel.push_back(anItem);
1940 bool blocked = myElements->signalsBlocked();
1941 myElements->blockSignals(true);
1942 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1943 myElements->blockSignals(blocked);
1944 listItemsToSel.clear();
1949 //=================================================================================
1950 // function : closeEvent()
1952 //=================================================================================
1953 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1958 //=================================================================================
1959 // function : onVisibilityChanged()
1961 //=================================================================================
1962 void SMESHGUI_GroupDlg::onVisibilityChanged()
1964 SetAppropriateActor();
1967 //=================================================================================
1968 // function : SMESHGUI_GroupDlg::onClose
1969 // purpose : SLOT called when "Close" button pressed. Close dialog
1970 //=================================================================================
1971 void SMESHGUI_GroupDlg::onClose()
1973 if (SMESH::GetCurrentVtkView()) {
1974 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1975 SMESH::SetPointRepresentation(false);
1976 SMESH::SetPickable();
1977 restoreShowEntityMode();
1980 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
1981 SUIT_DataOwnerPtrList aList;
1982 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
1983 mySelectionMgr->setSelected( aList );
1986 mySelectionMgr->clearSelected();
1987 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1988 aViewWindow->SetSelectionMode(ActorSelection);
1989 mySelectionMgr->clearFilters();
1990 mySMESHGUI->ResetState();
1995 //=================================================================================
1996 // function : onHelp()
1998 //=================================================================================
1999 void SMESHGUI_GroupDlg::onHelp()
2001 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2003 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2007 platform = "winapplication";
2009 platform = "application";
2011 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2012 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2013 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2015 arg(myHelpFileName));
2019 //=================================================================================
2020 // function : SMESHGUI_GroupDlg::onDeactivate
2021 // purpose : SLOT called when dialog must be deativated
2022 //=================================================================================
2023 void SMESHGUI_GroupDlg::onDeactivate()
2025 mySMESHGUI->ResetState();
2029 //=================================================================================
2030 // function : SMESHGUI_GroupDlg::enterEvent
2031 // purpose : Event filter
2032 //=================================================================================
2033 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2036 mySMESHGUI->EmitSignalDeactivateDialog();
2038 mySelectionMode = grpNoSelection;
2039 setSelectionMode(myTypeId);
2040 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2041 mySMESHGUI->SetActiveDialogBox(this);
2042 mySMESHGUI->SetState(800);
2046 //=================================================================================
2047 // function : hideEvent
2048 // purpose : caused by ESC key
2049 //=================================================================================
2050 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
2052 if (!isMinimized() && !myIsBusy)
2056 //=================================================================================
2057 // function : keyPressEvent()
2059 //=================================================================================
2060 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2062 QDialog::keyPressEvent( e );
2063 if ( e->isAccepted() )
2066 if ( e->key() == Qt::Key_F1 )
2073 //================================================================================
2075 * \brief Enable showing of the popup when Geometry selection btn is clicked
2076 * \param enable - true to enable
2078 //================================================================================
2080 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2082 void SMESHGUI_GroupDlg::updateGeomPopup()
2084 bool enable = false;
2086 if ( !myMesh->_is_nil() )
2087 enable = myMesh->NbEdges() > 0;
2089 if ( myGeomGroupBtn )
2091 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2093 if ( !myGeomPopup ) {
2094 myGeomPopup = new QMenu(this);
2095 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2096 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2097 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2099 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2105 //=================================================================================
2106 // function : onGeomSelectionButton()
2108 //=================================================================================
2109 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2111 if ( myGeomPopup && isBtnOn )
2113 myCurrentLineEdit = myGeomGroupLine;
2114 QAction* a = myGeomPopup->exec( QCursor::pos() );
2115 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2116 setSelectionMode(grpGeomSelection);
2120 myCurrentLineEdit = 0;
2121 setSelectionMode(grpAllSelection);
2125 //=================================================================================
2126 // function : onGeomPopup()
2128 //=================================================================================
2129 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2131 int index = myActions[a];
2132 if ( index == GEOM_BY_MESH_INDEX )
2134 mySelectionMode = grpNoSelection;
2135 if ( !myShapeByMeshOp ) {
2136 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2137 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2138 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2139 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2140 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2142 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2143 if ( !myMesh->_is_nil() ) {
2145 hide(); // stop processing selection
2147 myShapeByMeshOp->setModule( mySMESHGUI );
2148 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2149 myShapeByMeshOp->SetMesh( myMesh );
2150 myShapeByMeshOp->start();
2155 //================================================================================
2157 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2159 //================================================================================
2161 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2163 if ( myShapeByMeshOp == op ) {
2164 mySMESHGUI->getApp()->updateObjectBrowser();
2166 // Select a found geometry object
2167 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2168 if ( !aGeomVar->_is_nil() )
2170 QString ID = aGeomVar->GetStudyEntry();
2171 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2172 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2173 SALOME_ListIO anIOList;
2174 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2175 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2176 anIOList.Append( anIO );
2177 mySelectionMgr->setSelectedObjects( anIOList, false );
2178 onObjectSelectionChanged();
2184 //================================================================================
2186 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2188 //================================================================================
2190 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2192 if ( myShapeByMeshOp == op )
2195 setSelectionMode(grpGeomSelection);
2199 //=================================================================================
2200 // function : setGroupColor()
2202 //=================================================================================
2203 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2205 QColor aQColor( (int)( theColor.R * 255.0 ),
2206 (int)( theColor.G * 255.0 ),
2207 (int)( theColor.B * 255.0 ) );
2208 setGroupQColor( aQColor );
2211 //=================================================================================
2212 // function : getGroupColor()
2214 //=================================================================================
2215 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2217 QColor aQColor = getGroupQColor();
2219 SALOMEDS::Color aColor;
2220 aColor.R = (float)aQColor.red() / 255.0;
2221 aColor.G = (float)aQColor.green() / 255.0;
2222 aColor.B = (float)aQColor.blue() / 255.0;
2227 //=================================================================================
2228 // function : setGroupQColor()
2230 //=================================================================================
2231 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2233 if( theColor.isValid() )
2234 myColorBtn->setColor( theColor );
2237 //=================================================================================
2238 // function : getGroupQColor()
2240 //=================================================================================
2241 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2243 return myColorBtn->color();
2246 //=================================================================================
2247 // function : setDefaultGroupColor()
2249 //=================================================================================
2250 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2252 if( myMesh->_is_nil() )
2255 bool isAutoColor = myMesh->GetAutoColor();
2260 int r = 0, g = 0, b = 0;
2261 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2262 aQColor.setRgb( r, g, b );
2266 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2268 QList<SALOMEDS::Color> aReservedColors;
2269 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2271 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2272 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2273 aReservedColors.append( aReservedColor );
2276 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2277 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2278 (int)( aColor.G * 255.0 ),
2279 (int)( aColor.B * 255.0 ) );
2283 setGroupQColor( aQColor );
2286 //=================================================================================
2287 // function : SetAppropriateActor()
2288 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2289 // NPAL19389: create a group with a selection in another group.
2290 // if mesh actor is not visible - find any first visible group or submesh
2291 //=================================================================================
2292 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2294 bool isActor = false;
2295 myActorsList.clear();
2297 if (myMesh->_is_nil()) return false;
2299 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2301 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2303 if (!myGroupOnGeom->_is_nil()) {
2304 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2305 if (anActor && anActor->hasIO())
2308 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2311 myActorsList.append(anActor);
2317 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2318 if (anActor && anActor->hasIO()) {
2320 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2323 myActorsList.append(anActor);
2327 if (!isActor && !myGroup->_is_nil()) {
2328 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2329 if (anActor && anActor->hasIO())
2330 myActorsList.append(anActor);
2333 // try any visible actor of group or submesh of current mesh
2336 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2338 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2339 int len = strlen(meshEntry);
2341 // iterate on all actors in current view window, search for
2342 // any visible actor, that belongs to group or submesh of current mesh
2343 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2344 vtkActorCollection *aCollection = aCopy.GetActors();
2345 int nbItems = aCollection->GetNumberOfItems();
2346 for (int i=0; i<nbItems && !isActor; i++)
2348 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2349 if (anActor && anActor->hasIO()) {
2350 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2351 if (aViewWindow->isVisible(anIO)) {
2352 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2353 myActorsList.append(anActor);
2361 if (myActorsList.count() > 0) {
2362 QListIterator<SMESH_Actor*> it( myActorsList );
2363 while ( it.hasNext() ) {
2364 SMESH_Actor* anActor = it.next();
2365 if ( IsActorVisible(anActor) )
2366 anActor->SetPickable(true);
2370 return ( isActor || (myActorsList.count() > 0) );
2373 //=======================================================================
2374 //function : setShowEntityMode
2375 //purpose : make shown only entity corresponding to my type
2376 //=======================================================================
2377 void SMESHGUI_GroupDlg::setShowEntityMode()
2379 if ( !myMesh->_is_nil() ) {
2380 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2381 if (!myStoredShownEntity)
2382 myStoredShownEntity = actor->GetEntityMode();
2383 switch ( myTypeId ) {
2384 case 0: restoreShowEntityMode(); break;
2385 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2386 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2387 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2393 //=======================================================================
2394 //function : restoreShowEntityMode
2395 //purpose : restore ShowEntity mode of myActor
2396 //=======================================================================
2397 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2399 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2400 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2401 actor->SetEntityMode(myStoredShownEntity);
2404 myStoredShownEntity = 0;
2407 //=======================================================================
2408 //function : IsActorVisible
2409 //purpose : return visibility of the actor
2410 //=======================================================================
2411 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2413 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2414 if (theActor && aViewWindow)
2415 return aViewWindow->isVisible(theActor->getIO());
2419 //================================================================
2420 //function : setIsApplyAndClose
2421 //purpose : Set value of the flag indicating that the dialog is
2422 // accepted by Apply & Close button
2423 //================================================================
2424 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2426 myIsApplyAndClose = theFlag;
2429 //================================================================
2430 //function : isApplyAndClose
2431 //purpose : Get value of the flag indicating that the dialog is
2432 // accepted by Apply & Close button
2433 //================================================================
2434 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2436 return myIsApplyAndClose;