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 );
1409 //=================================================================================
1410 // function : onSelectSubMesh()
1411 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1412 //=================================================================================
1413 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1416 if (mySelectGroup->isChecked()) {
1417 mySelectGroup->setChecked(false);
1419 //VSR: else if (mySelectGeomGroup->isChecked()) {
1420 //VSR: mySelectGeomGroup->setChecked(false);
1422 myCurrentLineEdit = mySubMeshLine;
1423 setSelectionMode(grpSubMeshSelection);
1426 mySubMeshLine->setText( "" );
1427 myCurrentLineEdit = 0;
1429 setSelectionMode(myTypeId);
1431 mySubMeshBtn->setEnabled(on);
1432 mySubMeshLine->setEnabled(on);
1436 //=================================================================================
1437 // function : (onSelectGroup)
1438 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1439 //=================================================================================
1440 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1443 if (mySelectSubMesh->isChecked()) {
1444 mySelectSubMesh->setChecked(false);
1446 myCurrentLineEdit = myGroupLine;
1447 setSelectionMode(grpGroupSelection);
1450 myGroupLine->setText( "" );
1451 myCurrentLineEdit = 0;
1453 setSelectionMode(myTypeId);
1455 myGroupBtn->setEnabled(on);
1456 myGroupLine->setEnabled(on);
1460 //=================================================================================
1461 // function : (onSelectGeomGroup)
1462 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1463 //=================================================================================
1464 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1467 if (mySelectSubMesh->isChecked()) {
1468 mySelectSubMesh->setChecked(false);
1470 else if (mySelectGroup->isChecked()) {
1471 mySelectGroup->setChecked(false);
1473 myCurrentLineEdit = myGeomGroupLine;
1475 setSelectionMode(grpAllSelection);
1478 myGeomGroupBtn->setChecked(false);
1479 myGeomObjects->length(0);
1480 myGeomGroupLine->setText( "" );
1481 myCurrentLineEdit = 0;
1483 setSelectionMode(myTypeId);
1488 //=================================================================================
1489 // function : setCurrentSelection()
1491 //=================================================================================
1492 void SMESHGUI_GroupDlg::setCurrentSelection()
1494 QPushButton* send = (QPushButton*)sender();
1495 myCurrentLineEdit = 0;
1496 if (send == myMeshGroupBtn) {
1497 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1498 mySelectionMgr->clearSelected();
1500 setSelectionMode(grpMeshSelection);
1502 setSelectionMode(grpGroupSelection);
1503 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1504 myCurrentLineEdit = myMeshGroupLine;
1505 onObjectSelectionChanged();
1507 else if (send == mySubMeshBtn) {
1508 myCurrentLineEdit = mySubMeshLine;
1509 onObjectSelectionChanged();
1511 else if (send == myGroupBtn) {
1512 myCurrentLineEdit = myGroupLine;
1513 onObjectSelectionChanged();
1518 //=================================================================================
1519 // function : setFilters()
1520 // purpose : SLOT. Called when "Filter" button pressed.
1521 //=================================================================================
1522 void SMESHGUI_GroupDlg::setFilters()
1524 if(myMesh->_is_nil()) {
1525 SUIT_MessageBox::critical(this,
1527 tr("NO_MESH_SELECTED"));
1531 SMESH::ElementType aType = SMESH::ALL;
1534 case 0 : aType = SMESH::NODE; break;
1535 case 1 : aType = SMESH::EDGE; break;
1536 case 2 : aType = SMESH::FACE; break;
1537 case 3 : aType = SMESH::VOLUME; break;
1541 if ( myFilterDlg == 0 )
1543 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1544 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1547 myFilterDlg->Init( aType );
1549 myFilterDlg->SetSelection();
1550 myFilterDlg->SetMesh( myMesh );
1551 myFilterDlg->SetSourceWg( myElements, false );
1553 myFilterDlg->show();
1556 //=================================================================================
1557 // function : onFilterAccepted()
1558 // purpose : SLOT. Called when Filter dlg closed with OK button.
1559 // Uncheck "Select submesh" and "Select group" checkboxes
1560 //=================================================================================
1561 void SMESHGUI_GroupDlg::onFilterAccepted()
1563 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1565 mySelectionMode = myTypeId;
1566 mySelectSubMesh->setChecked( false );
1567 mySelectGroup->setChecked( false );
1571 //=================================================================================
1572 // function : onAdd()
1574 //=================================================================================
1575 void SMESHGUI_GroupDlg::onAdd()
1577 SALOME_ListIO aList;
1578 mySelectionMgr->selectedObjects( aList );
1580 int aNbSel = aList.Extent();
1582 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1586 SMESH::ElementType aType = SMESH::ALL;
1589 aType = SMESH::NODE;
1590 mySelector->SetSelectionMode(NodeSelection);
1593 aType = SMESH::EDGE;
1594 mySelector->SetSelectionMode(EdgeSelection);
1597 aType = SMESH::FACE;
1598 mySelector->SetSelectionMode(FaceSelection);
1601 aType = SMESH::VOLUME;
1602 mySelector->SetSelectionMode(VolumeSelection);
1605 mySelector->SetSelectionMode(ActorSelection);
1608 QListWidgetItem* anItem = 0;
1609 QList<QListWidgetItem*> listItemsToSel;
1611 if (myCurrentLineEdit == 0) {
1612 //if (aNbSel != 1) { myIsBusy = false; return; }
1613 QString aListStr = "";
1615 if (myTypeId == 0) {
1616 QListIterator<SMESH_Actor*> it( myActorsList );
1617 while ( it.hasNext() ) {
1619 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1624 QListIterator<SMESH_Actor*> it( myActorsList );
1625 while ( it.hasNext() ) {
1627 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1632 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1633 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1634 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1635 if (found.count() == 0) {
1636 anItem = new QListWidgetItem(*it);
1637 myElements->addItem(anItem);
1638 if (!anItem->isSelected())
1639 listItemsToSel.push_back(anItem);
1642 foreach(anItem, found)
1643 if (!anItem->isSelected())
1644 listItemsToSel.push_back(anItem);
1647 bool blocked = myElements->signalsBlocked();
1648 myElements->blockSignals(true);
1649 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1650 myElements->blockSignals(blocked);
1651 onListSelectionChanged();
1652 listItemsToSel.clear();
1654 } else if (myCurrentLineEdit == mySubMeshLine) {
1655 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1657 SALOME_ListIO aList;
1658 mySelectionMgr->selectedObjects( aList );
1660 SALOME_ListIteratorOfListIO anIt (aList);
1661 for ( ; anIt.More(); anIt.Next()) {
1662 SMESH::SMESH_subMesh_var aSubMesh =
1663 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1664 if (!aSubMesh->_is_nil()) {
1665 // check if mesh is the same
1666 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1668 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1669 int k = anElements->length();
1670 for (int i = 0; i < k; i++) {
1671 QString aText = QString::number(anElements[i]);
1672 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1673 if (found.count() == 0) {
1674 anItem = new QListWidgetItem(aText);
1675 myElements->addItem(anItem);
1676 if (!anItem->isSelected())
1677 listItemsToSel.push_back(anItem);
1680 foreach(anItem, found)
1681 if (!anItem->isSelected())
1682 listItemsToSel.push_back(anItem);
1685 bool blocked = myElements->signalsBlocked();
1686 myElements->blockSignals(true);
1687 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1688 myElements->blockSignals(blocked);
1689 onListSelectionChanged();
1690 listItemsToSel.clear();
1692 catch (const SALOME::SALOME_Exception& ex) {
1693 SalomeApp_Tools::QtCatchCorbaException(ex);
1698 mySelectSubMesh->setChecked(false);
1700 onListSelectionChanged();
1702 } else if (myCurrentLineEdit == myGroupLine) {
1703 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1704 SALOME_ListIO aList;
1705 mySelectionMgr->selectedObjects( aList );
1707 SALOME_ListIteratorOfListIO anIt (aList);
1708 for ( ; anIt.More(); anIt.Next()) {
1709 SMESH::SMESH_GroupBase_var aGroup =
1710 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1711 if (!aGroup->_is_nil()) {
1712 // check if mesh is the same
1713 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1714 SMESH::long_array_var anElements = aGroup->GetListOfID();
1715 int k = anElements->length();
1716 for (int i = 0; i < k; i++) {
1717 QString aText = QString::number(anElements[i]);
1718 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1719 if (found.count() == 0) {
1720 anItem = new QListWidgetItem(aText);
1721 myElements->addItem(anItem);
1722 if (!anItem->isSelected())
1723 listItemsToSel.push_back(anItem);
1726 foreach(anItem, found)
1727 if (!anItem->isSelected())
1728 listItemsToSel.push_back(anItem);
1731 bool blocked = myElements->signalsBlocked();
1732 myElements->blockSignals(true);
1733 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1734 myElements->blockSignals(blocked);
1735 onListSelectionChanged();
1736 listItemsToSel.clear();
1740 mySelectGroup->setChecked(false);
1742 onListSelectionChanged();
1744 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1745 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1746 GEOM::GEOM_IGroupOperations_var aGroupOp =
1747 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1749 SMESH::ElementType aGroupType = SMESH::ALL;
1750 switch(aGroupOp->GetType(myGeomObjects[0])) {
1751 case 7: aGroupType = SMESH::NODE; break;
1752 case 6: aGroupType = SMESH::EDGE; break;
1753 case 4: aGroupType = SMESH::FACE; break;
1754 case 2: aGroupType = SMESH::VOLUME; break;
1755 default: myIsBusy = false; return;
1758 if (aGroupType == aType) {
1759 _PTR(SObject) aGroupSO =
1760 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1761 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1763 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1764 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1765 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1766 aBelongToGeom->SetGeom(myGeomObjects[0]);
1767 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1768 aBelongToGeom->SetElementType(aType);
1769 aFilter->SetPredicate(aBelongToGeom);
1771 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1773 int k = anElements->length();
1774 for (int i = 0; i < k; i++) {
1775 QString aText = QString::number(anElements[i]);
1776 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1777 if (found.count() == 0) {
1778 anItem = new QListWidgetItem(aText);
1779 myElements->addItem(anItem);
1780 if (!anItem->isSelected())
1781 listItemsToSel.push_back(anItem);
1784 foreach(anItem, found)
1785 if (!anItem->isSelected())
1786 listItemsToSel.push_back(anItem);
1789 bool blocked = myElements->signalsBlocked();
1790 myElements->blockSignals(true);
1791 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1792 myElements->blockSignals(blocked);
1793 onListSelectionChanged();
1794 listItemsToSel.clear();
1797 //VSR: mySelectGeomGroup->setChecked(false);
1799 onListSelectionChanged();
1802 // mySelectionMgr->clearSelected();
1806 //=================================================================================
1807 // function : onRemove()
1809 //=================================================================================
1810 void SMESHGUI_GroupDlg::onRemove()
1813 if (myCurrentLineEdit == 0) {
1814 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1815 QListWidgetItem* item;
1816 foreach(item, selItems) delete item;
1818 SALOME_ListIO aList;
1819 mySelectionMgr->selectedObjects( aList );
1821 int aNbSel = aList.Extent();
1823 if (aNbSel == 0) { myIsBusy = false; return; }
1825 SMESH::ElementType aType = SMESH::ALL;
1827 case 0: aType = SMESH::NODE; break;
1828 case 1: aType = SMESH::EDGE; break;
1829 case 2: aType = SMESH::FACE; break;
1830 case 3: aType = SMESH::VOLUME; break;
1833 if (myCurrentLineEdit == mySubMeshLine) {
1834 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1835 SALOME_ListIO aList;
1836 mySelectionMgr->selectedObjects( aList );
1838 SALOME_ListIteratorOfListIO anIt (aList);
1839 for ( ; anIt.More(); anIt.Next()) {
1840 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1841 if (!aSubMesh->_is_nil()) {
1842 // check if mesh is the same
1843 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1844 if (aType == SMESH::NODE) {
1846 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1847 int k = anElements->length();
1848 for (int i = 0; i < k; i++) {
1849 QList<QListWidgetItem*> found =
1850 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1851 QListWidgetItem* anItem;
1852 foreach(anItem, found) delete anItem;
1855 catch (const SALOME::SALOME_Exception& ex) {
1856 SalomeApp_Tools::QtCatchCorbaException(ex);
1861 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1862 int k = anElements->length();
1863 for (int i = 0; i < k; i++) {
1864 QList<QListWidgetItem*> found =
1865 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1866 QListWidgetItem* anItem;
1867 foreach(anItem, found) delete anItem;
1870 catch (const SALOME::SALOME_Exception& ex) {
1871 SalomeApp_Tools::QtCatchCorbaException(ex);
1878 else if (myCurrentLineEdit == myGroupLine) {
1879 Standard_Boolean aRes;
1880 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1881 SALOME_ListIO aList;
1882 mySelectionMgr->selectedObjects( aList );
1884 SALOME_ListIteratorOfListIO anIt (aList);
1885 for ( ; anIt.More(); anIt.Next()) {
1886 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1887 if (aRes && !aGroup->_is_nil()) {
1888 // check if mesh is the same
1889 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1890 SMESH::long_array_var anElements = aGroup->GetListOfID();
1891 int k = anElements->length();
1892 for (int i = 0; i < k; i++) {
1893 QList<QListWidgetItem*> found =
1894 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1895 QListWidgetItem* anItem;
1896 foreach(anItem, found) delete anItem;
1907 //=================================================================================
1908 // function : onSort()
1910 //=================================================================================
1911 void SMESHGUI_GroupDlg::onSort()
1913 // PAL5412: sorts items in ascending by "string" value
1914 // myElements->sort(true);
1915 // myElements->update();
1916 int i, k = myElements->count();
1919 QList<int> aSelected;
1920 std::vector<int> anArray(k);
1921 // QMemArray<int> anArray(k);
1923 for (i = 0; i < k; i++) {
1924 int id = myElements->item(i)->text().toInt();
1926 if (myElements->item(i)->isSelected())
1927 aSelected.append(id);
1929 // sort & update list
1930 std::sort(anArray.begin(), anArray.end());
1932 myElements->clear();
1933 QListWidgetItem* anItem;
1934 QList<QListWidgetItem*> listItemsToSel;
1935 for (i = 0; i < k; i++) {
1936 anItem = new QListWidgetItem(QString::number(anArray[i]));
1937 myElements->addItem(anItem);
1938 if (aSelected.contains(anArray[i]))
1939 listItemsToSel.push_back(anItem);
1941 bool blocked = myElements->signalsBlocked();
1942 myElements->blockSignals(true);
1943 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1944 myElements->blockSignals(blocked);
1945 listItemsToSel.clear();
1950 //=================================================================================
1951 // function : closeEvent()
1953 //=================================================================================
1954 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1959 //=================================================================================
1960 // function : onVisibilityChanged()
1962 //=================================================================================
1963 void SMESHGUI_GroupDlg::onVisibilityChanged()
1965 SetAppropriateActor();
1968 //=================================================================================
1969 // function : SMESHGUI_GroupDlg::onClose
1970 // purpose : SLOT called when "Close" button pressed. Close dialog
1971 //=================================================================================
1972 void SMESHGUI_GroupDlg::onClose()
1974 if (SMESH::GetCurrentVtkView()) {
1975 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1976 SMESH::SetPointRepresentation(false);
1977 SMESH::SetPickable();
1978 restoreShowEntityMode();
1981 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
1982 SUIT_DataOwnerPtrList aList;
1983 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
1984 mySelectionMgr->setSelected( aList );
1987 mySelectionMgr->clearSelected();
1988 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1989 aViewWindow->SetSelectionMode(ActorSelection);
1990 mySelectionMgr->clearFilters();
1991 mySMESHGUI->ResetState();
1996 //=================================================================================
1997 // function : onHelp()
1999 //=================================================================================
2000 void SMESHGUI_GroupDlg::onHelp()
2002 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2004 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2008 platform = "winapplication";
2010 platform = "application";
2012 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2013 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2014 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2016 arg(myHelpFileName));
2020 //=================================================================================
2021 // function : SMESHGUI_GroupDlg::onDeactivate
2022 // purpose : SLOT called when dialog must be deativated
2023 //=================================================================================
2024 void SMESHGUI_GroupDlg::onDeactivate()
2026 mySMESHGUI->ResetState();
2030 //=================================================================================
2031 // function : SMESHGUI_GroupDlg::enterEvent
2032 // purpose : Event filter
2033 //=================================================================================
2034 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2037 mySMESHGUI->EmitSignalDeactivateDialog();
2039 mySelectionMode = grpNoSelection;
2040 setSelectionMode(myTypeId);
2041 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2042 mySMESHGUI->SetActiveDialogBox(this);
2043 mySMESHGUI->SetState(800);
2047 //=================================================================================
2048 // function : hideEvent
2049 // purpose : caused by ESC key
2050 //=================================================================================
2051 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
2053 if (!isMinimized() && !myIsBusy)
2057 //=================================================================================
2058 // function : keyPressEvent()
2060 //=================================================================================
2061 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2063 QDialog::keyPressEvent( e );
2064 if ( e->isAccepted() )
2067 if ( e->key() == Qt::Key_F1 )
2074 //================================================================================
2076 * \brief Enable showing of the popup when Geometry selection btn is clicked
2077 * \param enable - true to enable
2079 //================================================================================
2081 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2083 void SMESHGUI_GroupDlg::updateGeomPopup()
2085 bool enable = false;
2087 if ( !myMesh->_is_nil() )
2088 enable = myMesh->NbEdges() > 0;
2090 if ( myGeomGroupBtn )
2092 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2094 if ( !myGeomPopup ) {
2095 myGeomPopup = new QMenu(this);
2096 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2097 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2098 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2100 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2106 //=================================================================================
2107 // function : onGeomSelectionButton()
2109 //=================================================================================
2110 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2112 if ( myGeomPopup && isBtnOn )
2114 myCurrentLineEdit = myGeomGroupLine;
2115 QAction* a = myGeomPopup->exec( QCursor::pos() );
2116 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2117 setSelectionMode(grpGeomSelection);
2121 myCurrentLineEdit = 0;
2122 setSelectionMode(grpAllSelection);
2126 //=================================================================================
2127 // function : onGeomPopup()
2129 //=================================================================================
2130 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2132 int index = myActions[a];
2133 if ( index == GEOM_BY_MESH_INDEX )
2135 mySelectionMode = grpNoSelection;
2136 if ( !myShapeByMeshOp ) {
2137 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2138 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2139 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2140 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2141 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2143 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2144 if ( !myMesh->_is_nil() ) {
2146 hide(); // stop processing selection
2148 myShapeByMeshOp->setModule( mySMESHGUI );
2149 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2150 myShapeByMeshOp->SetMesh( myMesh );
2151 myShapeByMeshOp->start();
2156 //================================================================================
2158 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2160 //================================================================================
2162 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2164 if ( myShapeByMeshOp == op ) {
2165 mySMESHGUI->getApp()->updateObjectBrowser();
2167 // Select a found geometry object
2168 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2169 if ( !aGeomVar->_is_nil() )
2171 QString ID = aGeomVar->GetStudyEntry();
2172 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2173 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2174 SALOME_ListIO anIOList;
2175 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2176 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2177 anIOList.Append( anIO );
2178 mySelectionMgr->setSelectedObjects( anIOList, false );
2179 onObjectSelectionChanged();
2185 //================================================================================
2187 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2189 //================================================================================
2191 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2193 if ( myShapeByMeshOp == op )
2196 setSelectionMode(grpGeomSelection);
2200 //=================================================================================
2201 // function : setGroupColor()
2203 //=================================================================================
2204 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2206 QColor aQColor( (int)( theColor.R * 255.0 ),
2207 (int)( theColor.G * 255.0 ),
2208 (int)( theColor.B * 255.0 ) );
2209 setGroupQColor( aQColor );
2212 //=================================================================================
2213 // function : getGroupColor()
2215 //=================================================================================
2216 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2218 QColor aQColor = getGroupQColor();
2220 SALOMEDS::Color aColor;
2221 aColor.R = (float)aQColor.red() / 255.0;
2222 aColor.G = (float)aQColor.green() / 255.0;
2223 aColor.B = (float)aQColor.blue() / 255.0;
2228 //=================================================================================
2229 // function : setGroupQColor()
2231 //=================================================================================
2232 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2234 if( theColor.isValid() )
2235 myColorBtn->setColor( theColor );
2238 //=================================================================================
2239 // function : getGroupQColor()
2241 //=================================================================================
2242 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2244 return myColorBtn->color();
2247 //=================================================================================
2248 // function : setDefaultGroupColor()
2250 //=================================================================================
2251 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2253 if( myMesh->_is_nil() )
2256 bool isAutoColor = myMesh->GetAutoColor();
2261 int r = 0, g = 0, b = 0;
2262 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2263 aQColor.setRgb( r, g, b );
2267 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2269 QList<SALOMEDS::Color> aReservedColors;
2270 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2272 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2273 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2274 aReservedColors.append( aReservedColor );
2277 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2278 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2279 (int)( aColor.G * 255.0 ),
2280 (int)( aColor.B * 255.0 ) );
2284 setGroupQColor( aQColor );
2287 //=================================================================================
2288 // function : SetAppropriateActor()
2289 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2290 // NPAL19389: create a group with a selection in another group.
2291 // if mesh actor is not visible - find any first visible group or submesh
2292 //=================================================================================
2293 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2295 bool isActor = false;
2296 myActorsList.clear();
2298 if (myMesh->_is_nil()) return false;
2300 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2302 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2304 if (!myGroupOnGeom->_is_nil()) {
2305 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2306 if (anActor && anActor->hasIO())
2309 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2312 myActorsList.append(anActor);
2318 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2319 if (anActor && anActor->hasIO()) {
2321 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2324 myActorsList.append(anActor);
2328 if (!isActor && !myGroup->_is_nil()) {
2329 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2330 if (anActor && anActor->hasIO())
2331 myActorsList.append(anActor);
2334 // try any visible actor of group or submesh of current mesh
2337 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2339 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2340 int len = strlen(meshEntry);
2342 // iterate on all actors in current view window, search for
2343 // any visible actor, that belongs to group or submesh of current mesh
2344 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2345 vtkActorCollection *aCollection = aCopy.GetActors();
2346 int nbItems = aCollection->GetNumberOfItems();
2347 for (int i=0; i<nbItems && !isActor; i++)
2349 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2350 if (anActor && anActor->hasIO()) {
2351 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2352 if (aViewWindow->isVisible(anIO)) {
2353 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2354 myActorsList.append(anActor);
2362 if (myActorsList.count() > 0) {
2363 QListIterator<SMESH_Actor*> it( myActorsList );
2364 while ( it.hasNext() ) {
2365 SMESH_Actor* anActor = it.next();
2366 if ( IsActorVisible(anActor) )
2367 anActor->SetPickable(true);
2371 return ( isActor || (myActorsList.count() > 0) );
2374 //=======================================================================
2375 //function : setShowEntityMode
2376 //purpose : make shown only entity corresponding to my type
2377 //=======================================================================
2378 void SMESHGUI_GroupDlg::setShowEntityMode()
2380 if ( !myMesh->_is_nil() ) {
2381 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2382 if (!myStoredShownEntity)
2383 myStoredShownEntity = actor->GetEntityMode();
2384 switch ( myTypeId ) {
2385 case 0: restoreShowEntityMode(); break;
2386 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2387 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2388 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2394 //=======================================================================
2395 //function : restoreShowEntityMode
2396 //purpose : restore ShowEntity mode of myActor
2397 //=======================================================================
2398 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2400 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2401 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2402 actor->SetEntityMode(myStoredShownEntity);
2405 myStoredShownEntity = 0;
2408 //=======================================================================
2409 //function : IsActorVisible
2410 //purpose : return visibility of the actor
2411 //=======================================================================
2412 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2414 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2415 if (theActor && aViewWindow)
2416 return aViewWindow->isVisible(theActor->getIO());
2420 //================================================================
2421 //function : setIsApplyAndClose
2422 //purpose : Set value of the flag indicating that the dialog is
2423 // accepted by Apply & Close button
2424 //================================================================
2425 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2427 myIsApplyAndClose = theFlag;
2430 //================================================================
2431 //function : isApplyAndClose
2432 //purpose : Get value of the flag indicating that the dialog is
2433 // accepted by Apply & Close button
2434 //================================================================
2435 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2437 return myIsApplyAndClose;