1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_GroupDlg.cxx
24 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
27 #include "SMESHGUI_GroupDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_GroupUtils.h"
33 #include "SMESHGUI_FilterUtils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
35 #include "SMESHGUI_FilterDlg.h"
36 #include "SMESHGUI_ShapeByMeshDlg.h"
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_Actor.h>
40 #include <SMESH_ActorUtils.h>
42 // SALOME GEOM includes
44 #include <GEOM_SelectionFilter.h>
46 // SALOME GUI includes
47 #include <QtxColorButton.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_MessageBox.h>
54 #include <SalomeApp_Tools.h>
55 #include <SalomeApp_Application.h>
56 #include <SalomeApp_Study.h>
57 #include <LightApp_SelectionMgr.h>
59 #include <SALOME_ListIO.hxx>
60 #include <SALOME_ListIteratorOfListIO.hxx>
62 #include <SVTK_ViewWindow.h>
64 // SALOME KERNEL includes
65 #include <SALOMEDSClient_Study.hxx>
68 #include <vtkRenderer.h>
69 #include <vtkActorCollection.h>
72 #include <TColStd_MapOfInteger.hxx>
75 #include <QButtonGroup>
79 #include <QPushButton>
80 #include <QToolButton>
81 #include <QRadioButton>
83 #include <QGridLayout>
84 #include <QHBoxLayout>
85 #include <QVBoxLayout>
86 #include <QListWidget>
87 #include <QStackedWidget>
99 //=================================================================================
100 // function : SMESHGUI_GroupDlg()
102 //=================================================================================
103 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
104 SMESH::SMESH_Mesh_ptr theMesh )
105 : QDialog( SMESH::GetDesktop( theModule ) ),
106 mySMESHGUI( theModule ),
107 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
108 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
110 myNameChanged( false ),
114 if ( !theMesh->_is_nil() )
118 mySelectSubMesh->setEnabled( false );
119 mySelectGroup->setEnabled( false );
120 myGeomGroupBtn->setEnabled( false );
121 myGeomGroupLine->setEnabled( false );
125 //=================================================================================
126 // function : SMESHGUI_GroupDlg()
128 //=================================================================================
129 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
130 SMESH::SMESH_GroupBase_ptr theGroup,
131 const bool theIsConvert )
132 : QDialog( SMESH::GetDesktop( theModule ) ),
133 mySMESHGUI( theModule ),
134 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
135 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
137 myNameChanged( false )
140 if ( !theGroup->_is_nil() )
141 init( theGroup, theIsConvert );
144 mySelectSubMesh->setEnabled( false );
145 mySelectGroup->setEnabled( false );
147 myCurrentLineEdit = myMeshGroupLine;
148 setSelectionMode( 5 );
152 //=================================================================================
153 // function : SMESHGUI_GroupDlg()
155 //=================================================================================
156 void SMESHGUI_GroupDlg::initDialog( bool create)
159 setAttribute( Qt::WA_DeleteOnClose, true );
163 myCurrentLineEdit = 0;
167 myGeomObjects = new GEOM::ListOfGO();
168 myGeomObjects->length( 0 );
170 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
172 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
173 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
175 setSizeGripEnabled( true);
177 QGridLayout* aMainLayout = new QGridLayout( this );
178 aMainLayout->setMargin( MARGIN );
179 aMainLayout->setSpacing( SPACING );
181 /***************************************************************/
182 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
183 myMeshGroupBtn = new QPushButton( this );
184 myMeshGroupBtn->setIcon( image0 );
185 myMeshGroupLine = new QLineEdit( this );
186 myMeshGroupLine->setReadOnly( true );
188 /***************************************************************/
189 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
190 myTypeGroup = new QButtonGroup( this );
191 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
192 aTypeBoxLayout->setMargin( MARGIN );
193 aTypeBoxLayout->setSpacing( SPACING );
196 types.append( tr( "MESH_NODE" ) );
197 types.append( tr( "SMESH_EDGE" ) );
198 types.append( tr( "SMESH_FACE" ) );
199 types.append( tr( "SMESH_VOLUME" ) );
201 for ( int i = 0; i < types.count(); i++ )
203 rb = new QRadioButton( types[i], aTypeBox );
204 myTypeGroup->addButton( rb, i );
205 aTypeBoxLayout->addWidget( rb );
207 aTypeBox->setEnabled( create );
210 /***************************************************************/
211 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
212 aName->setMinimumWidth( 50 );
213 myName = new QLineEdit( this );
215 /***************************************************************/
216 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
217 myGrpTypeGroup = new QButtonGroup( this );
218 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
219 aGrpTypeBoxLayout->setMargin( MARGIN );
220 aGrpTypeBoxLayout->setSpacing( SPACING );
222 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
223 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
224 myGrpTypeGroup->addButton( rb1, 0 );
225 myGrpTypeGroup->addButton( rb2, 1 );
226 aGrpTypeBoxLayout->addWidget( rb1 );
227 aGrpTypeBoxLayout->addWidget( rb2 );
228 aGrpTypeBox->setEnabled( create );
231 /***************************************************************/
232 myWGStack = new QStackedWidget( this );
233 QWidget* wg1 = new QWidget( myWGStack );
234 QWidget* wg2 = new QWidget( myWGStack );
236 /***************************************************************/
237 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
238 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
239 aContentBoxLayout->setMargin( MARGIN );
240 aContentBoxLayout->setSpacing( SPACING );
242 QLabel* aLabel = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
243 myElements = new QListWidget( aContentBox );
244 myElements->setSelectionMode( QListWidget::ExtendedSelection );
246 myFilter = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
247 QPushButton* aAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
248 QPushButton* aRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
249 QPushButton* aSortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
251 aContentBoxLayout->addWidget( aLabel, 0, 0 );
252 aContentBoxLayout->addWidget( myElements, 1, 0, 6, 1 );
253 aContentBoxLayout->addWidget( myFilter, 1, 1 );
254 aContentBoxLayout->addWidget( aAddBtn, 3, 1 );
255 aContentBoxLayout->addWidget( aRemoveBtn, 4, 1 );
256 aContentBoxLayout->addWidget( aSortBtn, 6, 1 );
258 aContentBoxLayout->setColumnStretch( 0, 1 );
259 aContentBoxLayout->setRowStretch( 2, 1 );
260 aContentBoxLayout->setRowStretch( 5, 1 );
262 /***************************************************************/
263 QGroupBox* aSelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
264 QGridLayout* aSelectBoxLayout = new QGridLayout( aSelectBox );
265 aSelectBoxLayout->setMargin( MARGIN );
266 aSelectBoxLayout->setSpacing( SPACING );
268 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), aSelectBox );
269 mySubMeshBtn = new QPushButton( aSelectBox );
270 mySubMeshBtn->setIcon( image0 );
271 mySubMeshLine = new QLineEdit( aSelectBox );
272 mySubMeshLine->setReadOnly( true );
273 onSelectSubMesh( false );
275 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), aSelectBox );
276 myGroupBtn = new QPushButton( aSelectBox );
277 myGroupBtn->setIcon( image0 );
278 myGroupLine = new QLineEdit( aSelectBox );
279 myGroupLine->setReadOnly( true );
280 onSelectGroup( false );
282 aSelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
283 aSelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
284 aSelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
285 aSelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
286 aSelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
287 aSelectBoxLayout->addWidget( myGroupLine, 1, 2 );
289 /***************************************************************/
290 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
291 wg1Layout->setMargin( 0 );
292 wg1Layout->setSpacing( SPACING );
293 wg1Layout->addWidget( aContentBox );
294 wg1Layout->addWidget( aSelectBox );
295 wg1Layout->setStretchFactor( aContentBox, 10 );
297 /***************************************************************/
298 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
299 myGeomGroupBtn = new QToolButton( wg2 );
300 myGeomGroupBtn->setIcon( image0 );
301 myGeomGroupBtn->setCheckable( true );
302 myGeomGroupLine = new QLineEdit( wg2 );
303 myGeomGroupLine->setReadOnly( true ); //VSR ???
304 onSelectGeomGroup( false );
306 myGeomGroupBtn->setEnabled( create );
307 myGeomGroupLine->setEnabled( create );
309 /***************************************************************/
310 QGridLayout* wg2Layout = new QGridLayout( wg2 );
311 wg2Layout->setMargin( 0 );
312 wg1Layout->setSpacing( SPACING );
313 wg2Layout->addWidget( geomObject, 0, 0 );
314 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
315 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
316 wg2Layout->setRowStretch( 1, 5 );
318 /***************************************************************/
319 myWGStack->insertWidget( 0, wg1 );
320 myWGStack->insertWidget( 1, wg2 );
322 /***************************************************************/
323 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
324 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
325 aColorBoxLayout->setMargin(MARGIN);
326 aColorBoxLayout->setSpacing(SPACING);
328 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
329 myColorBtn = new QtxColorButton(aColorBox);
330 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
331 myColorBtn->sizePolicy().verticalPolicy() );
333 aColorBoxLayout->addWidget(aColorLab);
334 aColorBoxLayout->addWidget(myColorBtn);
336 /***************************************************************/
338 QFrame* aButtons = new QFrame(this);
339 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
340 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
341 aBtnLayout->setMargin(MARGIN);
342 aBtnLayout->setSpacing(SPACING);
344 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
345 myOKBtn->setAutoDefault(true);
346 myOKBtn->setDefault(true);
347 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
348 myApplyBtn->setAutoDefault(true);
349 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
350 myCloseBtn->setAutoDefault(true);
351 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
352 myHelpBtn->setAutoDefault(true);
354 aBtnLayout->addWidget(myOKBtn);
355 aBtnLayout->addSpacing(10);
356 aBtnLayout->addWidget(myApplyBtn);
357 aBtnLayout->addSpacing(10);
358 aBtnLayout->addStretch();
359 aBtnLayout->addWidget(myCloseBtn);
360 aBtnLayout->addWidget(myHelpBtn);
362 /***************************************************************/
363 aMainLayout->addWidget(meshGroupLab, 0, 0);
364 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
365 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
366 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
367 aMainLayout->addWidget(aName, 2, 0);
368 aMainLayout->addWidget(myName, 2, 2);
369 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
370 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
371 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
372 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
374 /* signals and slots connections */
375 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
376 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
377 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
379 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
380 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
382 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
383 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
384 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
385 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
387 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
388 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
389 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
390 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
391 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
393 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
395 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
396 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
397 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
398 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
401 mySMESHGUI->SetActiveDialogBox(this);
402 mySMESHGUI->SetState(800);
404 mySelectionMode = -1;
405 myMeshFilter = new SMESH_TypeFilter(MESH);
406 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
407 myGroupFilter = new SMESH_TypeFilter(GROUP);
408 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
409 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
411 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
412 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
413 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
415 rb1->setChecked(true); // VSR !!!
416 onGrpTypeChanged(0); // VSR!!!
418 if (myMesh->_is_nil() )
419 myTypeGroup->button(0)->setChecked(true);
422 //myName->setText(GetDefaultName(tr( "SMESH_GROUP" )));
425 //=================================================================================
426 // function : ~SMESHGUI_GroupDlg()
427 // purpose : Destroys the object and frees any allocated resources
428 //=================================================================================
429 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
431 // no need to delete child widgets, Qt does it all for us
432 if ( myFilterDlg != 0 ) {
433 myFilterDlg->setParent( 0 );
438 //=================================================================================
439 // function : GetDefaultName()
440 // purpose : Get the Group Name if Create new Group
441 //=================================================================================
442 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
446 // collect all object names of SMESH component
447 SalomeApp_Study* appStudy =
448 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
449 if ( !appStudy ) return aName;
450 _PTR(Study) aStudy = appStudy->studyDS();
452 std::set<std::string> aSet;
453 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
455 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
457 for (it->InitEx(true); it->More(); it->Next()) {
459 aSet.insert(obj->GetName());
463 // build a unique name
465 bool isUnique = false;
467 aName = theOperation + "_" + QString::number(++aNumber);
468 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
474 //=================================================================================
477 //=================================================================================
478 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
480 mySelectionMgr->installFilter(myMeshFilter);
482 /* init data from current selection */
483 restoreShowEntityMode();
484 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
486 myGroup = SMESH::SMESH_Group::_nil();
487 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
489 // NPAL19389: create a group with a selection in another group
490 // set actor of myMesh, if it is visible, else try
491 // any visible actor of group or submesh of myMesh
492 SetAppropriateActor();
494 setDefaultGroupColor();
497 mySelectionMgr->selectedObjects( aList );
498 if( !aList.IsEmpty() )
500 QString aName = aList.First()->getName();
501 myMeshGroupLine->setText(aName);
502 myMeshGroupLine->home( false );
505 myCurrentLineEdit = 0;
507 myTypeGroup->button(0)->setChecked(true);
511 //=================================================================================
514 //=================================================================================
515 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
516 const bool theIsConvert)
518 restoreShowEntityMode();
519 myMesh = theGroup->GetMesh();
522 myNameChanged = true;
523 myName->blockSignals(true);
524 myName->setText(theGroup->GetName());
525 myName->blockSignals(false);
528 SALOMEDS::Color aColor = theGroup->GetColor();
529 setGroupColor( aColor );
531 myMeshGroupLine->setText(theGroup->GetName());
534 switch(theGroup->GetType()) {
535 case SMESH::NODE: aType= 0; break;
536 case SMESH::EDGE: aType = 1; break;
537 case SMESH::FACE: aType = 2; break;
538 case SMESH::VOLUME: aType = 3; break;
540 myTypeGroup->button(aType)->setChecked(true);
542 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
543 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
545 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil())
548 // NPAL19389: create a group with a selection in another group
549 // set actor of myMesh, if it is visible, else set
550 // actor of theGroup, if it is visible, else try
551 // any visible actor of group or submesh of myMesh
552 // commented, because an attempt to set selection on not displayed cells leads to error
553 //SetAppropriateActor();
554 myActor = SMESH::FindActorByObject(myMesh);
556 myActor = SMESH::FindActorByObject(theGroup);
557 SMESH::SetPickable(myActor);
559 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : 1));
560 myGrpTypeGroup->button(grpType)->setChecked(true);
561 onGrpTypeChanged(grpType);
564 if ( grpType == 0 ) {
565 myCurrentLineEdit = 0;
567 setSelectionMode(aType);
569 setShowEntityMode(); // depends on myTypeId
572 if (!theGroup->IsEmpty()) {
573 SMESH::long_array_var anElements = theGroup->GetListOfID();
574 int k = anElements->length();
575 for (int i = 0; i < k; i++) {
576 myIdList.append(anElements[i]);
577 myElements->addItem(QString::number(anElements[i]));
579 myElements->selectAll();
584 QString aShapeName( "" );
585 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
586 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
587 if (!aGroupShape->_is_nil())
589 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
590 aShapeName = aGroupShapeSO->GetName().c_str();
592 myGeomGroupLine->setText( aShapeName );
593 myNameChanged = true;
594 myName->blockSignals(true);
595 myName->setText(theGroup->GetName());
596 myName->blockSignals(false);
601 //=================================================================================
602 // function : updateButtons()
604 //=================================================================================
605 void SMESHGUI_GroupDlg::updateButtons()
607 bool enable = !myName->text().trimmed().isEmpty();
609 if (myGrpTypeId == 0) {
610 enable = enable && myElements->count() > 0;
611 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
613 else if (myGrpTypeId == 1) {
614 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
615 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
619 myOKBtn->setEnabled(enable);
620 myApplyBtn->setEnabled(enable);
623 //=================================================================================
624 // function : onNameChanged()
626 //=================================================================================
627 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
629 myOldName = myName->text();
631 myNameChanged = !myName->text().trimmed().isEmpty();
634 //=================================================================================
635 // function : onTypeChanged()
636 // purpose : Group elements type radio button management
637 //=================================================================================
638 void SMESHGUI_GroupDlg::onTypeChanged (int id)
640 if (myTypeId != id) {
642 if (myCurrentLineEdit == 0)
643 setSelectionMode(id);
649 //=================================================================================
650 // function : onGrpTypeChanged()
651 // purpose : Group type radio button management
652 //=================================================================================
653 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
655 if (myGrpTypeId != id) {
656 myWGStack->setCurrentIndex( id );
657 myName->blockSignals(true);
658 myName->setText(myOldName);
659 myName->blockSignals(false);
660 onSelectGeomGroup(id == 1);
665 //=================================================================================
666 // function : onColorChanged()
667 // purpose : Color button management
668 //=================================================================================
669 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
674 //=================================================================================
675 // function : setSelectionMode()
676 // purpose : Radio button management
677 //=================================================================================
678 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
681 if (myMesh->_is_nil())
683 if (mySelectionMode != theMode) {
684 // [PAL10408] mySelectionMgr->clearSelected();
685 mySelectionMgr->clearFilters();
687 myActor->SetPointRepresentation(false);
689 SMESH::SetPointRepresentation(false);
694 myActor->SetPointRepresentation(true);
696 SMESH::SetPointRepresentation(true);
697 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
698 aViewWindow->SetSelectionMode(NodeSelection);
701 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
702 aViewWindow->SetSelectionMode(EdgeSelection);
705 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
706 aViewWindow->SetSelectionMode(FaceSelection);
709 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
710 aViewWindow->SetSelectionMode(VolumeSelection);
714 mySelectionMgr->installFilter(mySubMeshFilter);
715 else if (theMode == 5)
716 mySelectionMgr->installFilter(myGroupFilter);
717 else if (theMode == 6)
718 mySelectionMgr->installFilter(myMeshFilter);
719 else if (theMode == 7)
720 mySelectionMgr->installFilter(myGeomFilter);
722 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
723 aViewWindow->SetSelectionMode(ActorSelection);
725 mySelectionMode = theMode;
729 //=================================================================================
730 // function : onApply()
732 //=================================================================================
733 bool SMESHGUI_GroupDlg::onApply()
735 if (mySMESHGUI->isActiveStudyLocked())
738 if (myName->text().trimmed().isEmpty())
741 if (myGrpTypeId == 0) { // on mesh elements
742 if (!myElements->count())
745 mySelectionMgr->clearSelected();
747 if (myGroup->_is_nil()) { // creation or conversion
748 // check if group on geometry is not null
749 if (!CORBA::is_nil(myGroupOnGeom)) {
750 if (myMesh->_is_nil())
752 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
753 // nullify pointer, because object become dead
754 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
758 if (myGroup->_is_nil()) { // creation
759 if (myMesh->_is_nil())
762 SMESH::ElementType aType = SMESH::ALL;
764 case 0: aType = SMESH::NODE; break;
765 case 1: aType = SMESH::EDGE; break;
766 case 2: aType = SMESH::FACE; break;
767 case 3: aType = SMESH::VOLUME; break;
770 SMESH::long_array_var anIdList = new SMESH::long_array;
771 int i, k = myElements->count();
773 for (i = 0; i < k; i++) {
774 anIdList[i] = myElements->item(i)->text().toInt();
777 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
778 myGroup->Add(anIdList.inout());
780 SALOMEDS::Color aColor = getGroupColor();
781 myGroup->SetColor(aColor);
783 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
785 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
786 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
788 /* init for next operation */
789 myName->setText( "" );
791 myGroup = SMESH::SMESH_Group::_nil();
794 myGroup->SetName(myName->text().toLatin1().data());
796 SALOMEDS::Color aColor = getGroupColor();
797 myGroup->SetColor(aColor);
799 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
800 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
801 anActor->setName(myName->text().toLatin1().data());
802 switch ( myTypeId ) {
803 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
804 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
806 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
812 int i, total = myElements->count();
813 for (i = 0; i < total; i++) {
814 int anId = myElements->item(i)->text().toInt();
815 int idx = myIdList.indexOf(anId);
817 aAddList.append(anId);
819 myIdList.removeAt(idx);
821 if (!aAddList.empty()) {
822 SMESH::long_array_var anIdList = new SMESH::long_array;
823 int added = aAddList.count();
824 anIdList->length(added);
825 for (i = 0; i < added; i++)
826 anIdList[i] = aAddList[i];
827 myGroup->Add(anIdList.inout());
829 if (!myIdList.empty()) {
830 SMESH::long_array_var anIdList = new SMESH::long_array;
831 int removed = myIdList.count();
832 anIdList->length(removed);
833 for (i = 0; i < removed; i++)
834 anIdList[i] = myIdList[i];
835 myGroup->Remove(anIdList.inout());
837 /* init for next operation */
839 for (i = 0; i < total; i++) {
840 myIdList.append(myElements->item(i)->text().toInt());
844 mySMESHGUI->updateObjBrowser(true);
845 SMESH::UpdateView(); // asv: fix of BUG PAL5515
846 mySelectionMgr->clearSelected();
849 else if (myGrpTypeId == 1) { // on geom object
850 if (CORBA::is_nil(myGroupOnGeom)) { // creation
851 if (myMesh->_is_nil() || !myGeomObjects->length())
854 SMESH::ElementType aType = SMESH::ALL;
856 case 0: aType = SMESH::NODE; break;
857 case 1: aType = SMESH::EDGE; break;
858 case 2: aType = SMESH::FACE; break;
859 case 3: aType = SMESH::VOLUME; break;
862 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
863 GEOM::GEOM_IGroupOperations_var aGroupOp =
864 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
866 if (myGeomObjects->length() == 1) {
867 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
868 myName->text().toLatin1().data(),
872 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
873 if ( aSMESHGen->_is_nil() )
876 // create a geometry group
877 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
878 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
880 if (geomGen->_is_nil() || !aStudy)
883 GEOM::GEOM_IGroupOperations_var op =
884 geomGen->GetIGroupOperations(aStudy->StudyId());
888 // check and add all selected GEOM objects: they must be
889 // a sub-shapes of the main GEOM and must be of one type
890 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
891 for ( int i =0; i < myGeomObjects->length(); i++) {
892 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
894 aGroupType = aSubShapeType;
895 else if (aSubShapeType != aGroupType) {
896 aGroupType = TopAbs_SHAPE;
901 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
902 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
903 op->UnionList(aGroupVar, myGeomObjects);
906 // publish the GEOM group in study
907 QString aNewGeomGroupName ( "Auto_group_for_" );
908 aNewGeomGroupName += myName->text();
909 SALOMEDS::SObject_var aNewGroupSO =
910 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
911 aNewGeomGroupName.toLatin1().data(), aMeshShape);
914 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
915 myName->text().toLatin1().data(),
919 SALOMEDS::Color aColor = getGroupColor();
920 myGroupOnGeom->SetColor(aColor);
922 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
924 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
925 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
927 /* init for next operation */
928 myName->setText( "" );
929 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
932 myGroupOnGeom->SetName(myName->text().toLatin1().data());
934 SALOMEDS::Color aColor = getGroupColor();
935 myGroupOnGeom->SetColor(aColor);
937 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
938 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
939 anActor->setName(myName->text().toLatin1().data());
940 switch ( myTypeId ) {
941 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
942 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
944 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
949 mySMESHGUI->updateObjBrowser(true);
950 mySelectionMgr->clearSelected();
957 //=================================================================================
960 //=================================================================================
961 void SMESHGUI_GroupDlg::onOK()
967 //=================================================================================
968 // function : onListSelectionChanged()
969 // purpose : Called when selection in element list is changed
970 //=================================================================================
971 void SMESHGUI_GroupDlg::onListSelectionChanged()
973 // MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
974 if( myIsBusy || !myActor) return;
977 if (myCurrentLineEdit == 0) {
978 mySelectionMgr->clearSelected();
979 TColStd_MapOfInteger aIndexes;
980 QList<QListWidgetItem*> selItems = myElements->selectedItems();
981 QListWidgetItem* anItem;
982 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
983 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
985 aList.Append(myActor->getIO());
986 mySelectionMgr->setSelectedObjects(aList,false);
991 //=================================================================================
992 // function : onObjectSelectionChanged()
993 // purpose : Called when selection in 3D view or ObjectBrowser is changed
994 //=================================================================================
995 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
997 if ( myIsBusy || !isEnabled()) return;
998 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1002 SALOME_ListIO aList;
1003 mySelectionMgr->selectedObjects( aList );
1005 int aNbSel = aList.Extent();
1006 myElements->clearSelection();
1008 if (myCurrentLineEdit)
1010 myCurrentLineEdit->setText( "" );
1011 QString aString = "";
1013 if (myCurrentLineEdit == myMeshGroupLine)
1015 mySelectSubMesh->setEnabled(false);
1016 mySelectGroup->setEnabled(false);
1017 myGroupLine->setText( "" );
1018 mySubMeshLine->setText( "" );
1020 myGeomGroupBtn->setEnabled(false);
1021 myGeomGroupLine->setEnabled(false);
1022 myGeomGroupLine->setText( "" );
1023 myGeomObjects = new GEOM::ListOfGO();
1024 myGeomObjects->length(0);
1026 if (myGeomGroupBtn->isChecked())
1027 myGeomGroupBtn->setChecked(false);
1029 myName->setText( "" );
1031 myElements->clear();
1034 myGroup = SMESH::SMESH_Group::_nil();
1035 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1036 restoreShowEntityMode();
1037 myMesh = SMESH::SMESH_Mesh::_nil();
1043 Handle(SALOME_InteractiveObject) IO = aList.First();
1046 restoreShowEntityMode();
1047 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1048 setShowEntityMode();
1050 if (myMesh->_is_nil())
1056 myGroup = SMESH::SMESH_Group::_nil();
1058 // NPAL19389: create a group with a selection in another group
1059 // set actor of myMesh, if it is visible, else try
1060 // any visible actor of group or submesh of myMesh
1061 SetAppropriateActor();
1063 aString = aList.First()->getName();
1064 myMeshGroupLine->setText(aString);
1065 myMeshGroupLine->home( false );
1067 mySelectSubMesh->setEnabled(true);
1068 mySelectGroup->setEnabled(true);
1069 myGeomGroupBtn->setEnabled(true);
1070 myGeomGroupLine->setEnabled(true);
1074 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1075 if (aGroup->_is_nil())
1081 myCurrentLineEdit = 0;
1083 myGroup = SMESH::SMESH_Group::_nil();
1084 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1088 mySelectSubMesh->setEnabled(true);
1089 mySelectGroup->setEnabled(true);
1091 myCurrentLineEdit = 0;
1096 if (myGrpTypeId == 0)
1102 myElements->clear();
1103 setSelectionMode(myTypeId);
1111 else if (myCurrentLineEdit == myGeomGroupLine)
1113 myGeomObjects = new GEOM::ListOfGO();
1116 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1118 if (aNbSel == 0 || !aMeshSO)
1120 myGeomObjects->length(0);
1126 myGeomObjects->length(aNbSel);
1128 GEOM::GEOM_Object_var aGeomGroup;
1129 Standard_Boolean testResult;
1132 SALOME_ListIteratorOfListIO anIt (aList);
1133 for (; anIt.More(); anIt.Next())
1135 testResult = Standard_False;
1136 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1138 // Check if the object is a geometry group
1139 if (!testResult || CORBA::is_nil(aGeomGroup))
1142 // Check if group constructed on the same shape as a mesh or on its child
1143 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1144 GEOM::GEOM_IGroupOperations_var anOp =
1145 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1147 // The main shape of the group
1148 GEOM::GEOM_Object_var aGroupMainShape;
1149 if (aGeomGroup->GetType() == 37)
1150 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1152 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1153 _PTR(SObject) aGroupMainShapeSO =
1154 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1155 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1157 _PTR(SObject) anObj, aRef;
1158 bool isRefOrSubShape = false;
1159 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1160 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1161 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1162 isRefOrSubShape = true;
1164 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1165 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1166 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1167 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1168 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1169 if (aRef->GetID() == aFather->GetID())
1170 isRefOrSubShape = true;
1172 aFather = aFather->GetFather();
1176 if (isRefOrSubShape)
1177 myGeomObjects[i++] = aGeomGroup;
1180 myGeomObjects->length(i);
1192 if (myCurrentLineEdit == mySubMeshLine)
1193 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1194 else if (myCurrentLineEdit == myGroupLine)
1195 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1196 else if (myCurrentLineEdit == myGeomGroupLine)
1197 aString = tr( "%1 Objects" ).arg(aNbSel);
1200 aString = aList.First()->getName();
1204 myCurrentLineEdit->setText(aString);
1205 myCurrentLineEdit->home(false);
1206 // 07.06.2008 skl for IPAL19574:
1207 // change name of group only if it is empty
1208 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1209 myOldName = myName->text();
1210 myName->blockSignals(true);
1211 myName->setText(aString);
1212 myName->blockSignals(false);
1217 else // !myCurrentLineEdit: local selection of nodes or elements
1219 if (aNbSel == 1 && myActor && myActor->hasIO())
1221 #ifdef ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1222 // NPAL19389: create a group with a selection in another group
1223 // Switch myActor to the newly selected one, if the last
1224 // is visible and belongs to group or submesh of myMesh
1225 Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1226 Handle(SALOME_InteractiveObject) selIO = aList.First();
1227 if (curIO->hasEntry() && selIO->hasEntry()) {
1228 const char* selEntry = selIO->getEntry();
1229 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1230 // different objects: selected and myActor
1231 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1232 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1233 // newly selected actor is visible
1236 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1238 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1239 int len = strlen(meshEntry);
1241 if (strncmp(selEntry, meshEntry, len) == 0) {
1242 // selected object is myMesh or a part of it
1243 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1246 SMESH::SetPickable(myActor);
1254 #endif // ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1256 QString aListStr = "";
1258 if (myTypeId == 0) {
1259 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1261 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1264 QListWidgetItem* anItem;
1265 QList<QListWidgetItem*> listItemsToSel;
1266 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1267 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1268 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1269 foreach(anItem, found)
1270 if (!anItem->isSelected())
1271 listItemsToSel.push_back(anItem);
1273 bool blocked = myElements->signalsBlocked();
1274 myElements->blockSignals(true);
1275 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1276 myElements->blockSignals(blocked);
1277 onListSelectionChanged();
1278 listItemsToSel.clear();
1284 if (!myGroup->_is_nil())
1285 myActor = SMESH::FindActorByObject(myGroup);
1286 else if(!myGroupOnGeom->_is_nil())
1287 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1289 myActor = SMESH::FindActorByObject(myMesh);
1292 // somehow, if we display the mesh, while selecting from another actor,
1293 // the mesh becomes pickable, and there is no way to select any element
1295 SMESH::SetPickable(myActor);
1300 //=================================================================================
1301 // function : onSelectSubMesh()
1302 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1303 //=================================================================================
1304 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1307 if (mySelectGroup->isChecked()) {
1308 mySelectGroup->setChecked(false);
1310 //VSR: else if (mySelectGeomGroup->isChecked()) {
1311 //VSR: mySelectGeomGroup->setChecked(false);
1313 myCurrentLineEdit = mySubMeshLine;
1314 setSelectionMode(4);
1317 mySubMeshLine->setText( "" );
1318 myCurrentLineEdit = 0;
1320 setSelectionMode(myTypeId);
1322 mySubMeshBtn->setEnabled(on);
1323 mySubMeshLine->setEnabled(on);
1327 //=================================================================================
1328 // function : (onSelectGroup)
1329 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1330 //=================================================================================
1331 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1334 if (mySelectSubMesh->isChecked()) {
1335 mySelectSubMesh->setChecked(false);
1337 myCurrentLineEdit = myGroupLine;
1338 setSelectionMode(5);
1341 myGroupLine->setText( "" );
1342 myCurrentLineEdit = 0;
1344 setSelectionMode(myTypeId);
1346 myGroupBtn->setEnabled(on);
1347 myGroupLine->setEnabled(on);
1351 //=================================================================================
1352 // function : (onSelectGeomGroup)
1353 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1354 //=================================================================================
1355 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1358 if (mySelectSubMesh->isChecked()) {
1359 mySelectSubMesh->setChecked(false);
1361 else if (mySelectGroup->isChecked()) {
1362 mySelectGroup->setChecked(false);
1364 myCurrentLineEdit = myGeomGroupLine;
1366 setSelectionMode(8);
1369 myGeomGroupBtn->setChecked(false);
1370 myGeomObjects->length(0);
1371 myGeomGroupLine->setText( "" );
1372 myCurrentLineEdit = 0;
1374 setSelectionMode(myTypeId);
1379 //=================================================================================
1380 // function : setCurrentSelection()
1382 //=================================================================================
1383 void SMESHGUI_GroupDlg::setCurrentSelection()
1385 QPushButton* send = (QPushButton*)sender();
1386 myCurrentLineEdit = 0;
1387 if (send == myMeshGroupBtn) {
1388 myCurrentLineEdit = myMeshGroupLine;
1390 setSelectionMode(6);
1392 setSelectionMode(5);
1393 onObjectSelectionChanged();
1395 else if (send == mySubMeshBtn) {
1396 myCurrentLineEdit = mySubMeshLine;
1397 onObjectSelectionChanged();
1399 else if (send == myGroupBtn) {
1400 myCurrentLineEdit = myGroupLine;
1401 onObjectSelectionChanged();
1406 //=================================================================================
1407 // function : setFilters()
1408 // purpose : SLOT. Called when "Filter" button pressed.
1409 //=================================================================================
1410 void SMESHGUI_GroupDlg::setFilters()
1412 if(myMesh->_is_nil()) {
1413 SUIT_MessageBox::critical(this,
1415 tr("NO_MESH_SELECTED"));
1419 SMESH::ElementType aType = SMESH::ALL;
1422 case 0 : aType = SMESH::NODE; break;
1423 case 1 : aType = SMESH::EDGE; break;
1424 case 2 : aType = SMESH::FACE; break;
1425 case 3 : aType = SMESH::VOLUME; break;
1429 if ( myFilterDlg == 0 )
1431 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1432 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1435 myFilterDlg->Init( aType );
1437 myFilterDlg->SetSelection();
1438 myFilterDlg->SetMesh( myMesh );
1439 myFilterDlg->SetSourceWg( myElements, false );
1441 myFilterDlg->show();
1444 //=================================================================================
1445 // function : onFilterAccepted()
1446 // purpose : SLOT. Called when Filter dlg closed with OK button.
1447 // Uncheck "Select submesh" and "Select group" checkboxes
1448 //=================================================================================
1449 void SMESHGUI_GroupDlg::onFilterAccepted()
1451 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1453 mySelectionMode = myTypeId;
1454 mySelectSubMesh->setChecked( false );
1455 mySelectGroup->setChecked( false );
1459 //=================================================================================
1460 // function : onAdd()
1462 //=================================================================================
1463 void SMESHGUI_GroupDlg::onAdd()
1465 SALOME_ListIO aList;
1466 mySelectionMgr->selectedObjects( aList );
1468 int aNbSel = aList.Extent();
1470 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1474 SMESH::ElementType aType = SMESH::ALL;
1477 aType = SMESH::NODE;
1478 mySelector->SetSelectionMode(NodeSelection);
1481 aType = SMESH::EDGE;
1482 mySelector->SetSelectionMode(EdgeSelection);
1485 aType = SMESH::FACE;
1486 mySelector->SetSelectionMode(FaceSelection);
1489 aType = SMESH::VOLUME;
1490 mySelector->SetSelectionMode(VolumeSelection);
1493 mySelector->SetSelectionMode(ActorSelection);
1496 QListWidgetItem* anItem = 0;
1497 QList<QListWidgetItem*> listItemsToSel;
1499 if (myCurrentLineEdit == 0) {
1500 //if (aNbSel != 1) { myIsBusy = false; return; }
1501 QString aListStr = "";
1503 if (myTypeId == 0) {
1504 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1507 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1510 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1511 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1512 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1513 if (found.count() == 0) {
1514 anItem = new QListWidgetItem(*it);
1515 myElements->addItem(anItem);
1516 if (!anItem->isSelected())
1517 listItemsToSel.push_back(anItem);
1520 foreach(anItem, found)
1521 if (!anItem->isSelected())
1522 listItemsToSel.push_back(anItem);
1525 bool blocked = myElements->signalsBlocked();
1526 myElements->blockSignals(true);
1527 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1528 myElements->blockSignals(blocked);
1529 onListSelectionChanged();
1530 listItemsToSel.clear();
1532 } else if (myCurrentLineEdit == mySubMeshLine) {
1533 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1535 SALOME_ListIO aList;
1536 mySelectionMgr->selectedObjects( aList );
1538 SALOME_ListIteratorOfListIO anIt (aList);
1539 for ( ; anIt.More(); anIt.Next()) {
1540 SMESH::SMESH_subMesh_var aSubMesh =
1541 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1542 if (!aSubMesh->_is_nil()) {
1543 // check if mesh is the same
1544 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1546 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1547 int k = anElements->length();
1548 for (int i = 0; i < k; i++) {
1549 QString aText = QString::number(anElements[i]);
1550 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1551 if (found.count() == 0) {
1552 anItem = new QListWidgetItem(aText);
1553 myElements->addItem(anItem);
1554 if (!anItem->isSelected())
1555 listItemsToSel.push_back(anItem);
1558 foreach(anItem, found)
1559 if (!anItem->isSelected())
1560 listItemsToSel.push_back(anItem);
1563 bool blocked = myElements->signalsBlocked();
1564 myElements->blockSignals(true);
1565 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1566 myElements->blockSignals(blocked);
1567 onListSelectionChanged();
1568 listItemsToSel.clear();
1570 catch (const SALOME::SALOME_Exception& ex) {
1571 SalomeApp_Tools::QtCatchCorbaException(ex);
1576 mySelectSubMesh->setChecked(false);
1578 onListSelectionChanged();
1580 } else if (myCurrentLineEdit == myGroupLine) {
1581 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1582 SALOME_ListIO aList;
1583 mySelectionMgr->selectedObjects( aList );
1585 SALOME_ListIteratorOfListIO anIt (aList);
1586 for ( ; anIt.More(); anIt.Next()) {
1587 SMESH::SMESH_GroupBase_var aGroup =
1588 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1589 if (!aGroup->_is_nil()) {
1590 // check if mesh is the same
1591 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1592 SMESH::long_array_var anElements = aGroup->GetListOfID();
1593 int k = anElements->length();
1594 for (int i = 0; i < k; i++) {
1595 QString aText = QString::number(anElements[i]);
1596 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1597 if (found.count() == 0) {
1598 anItem = new QListWidgetItem(aText);
1599 myElements->addItem(anItem);
1600 if (!anItem->isSelected())
1601 listItemsToSel.push_back(anItem);
1604 foreach(anItem, found)
1605 if (!anItem->isSelected())
1606 listItemsToSel.push_back(anItem);
1609 bool blocked = myElements->signalsBlocked();
1610 myElements->blockSignals(true);
1611 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1612 myElements->blockSignals(blocked);
1613 onListSelectionChanged();
1614 listItemsToSel.clear();
1618 mySelectGroup->setChecked(false);
1620 onListSelectionChanged();
1622 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1623 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1624 GEOM::GEOM_IGroupOperations_var aGroupOp =
1625 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1627 SMESH::ElementType aGroupType = SMESH::ALL;
1628 switch(aGroupOp->GetType(myGeomObjects[0])) {
1629 case 7: aGroupType = SMESH::NODE; break;
1630 case 6: aGroupType = SMESH::EDGE; break;
1631 case 4: aGroupType = SMESH::FACE; break;
1632 case 2: aGroupType = SMESH::VOLUME; break;
1633 default: myIsBusy = false; return;
1636 if (aGroupType == aType) {
1637 _PTR(SObject) aGroupSO =
1638 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1639 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1641 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1642 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1643 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1644 aBelongToGeom->SetGeom(myGeomObjects[0]);
1645 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1646 aBelongToGeom->SetElementType(aType);
1647 aFilter->SetPredicate(aBelongToGeom);
1649 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1651 int k = anElements->length();
1652 for (int i = 0; i < k; i++) {
1653 QString aText = QString::number(anElements[i]);
1654 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1655 if (found.count() == 0) {
1656 anItem = new QListWidgetItem(aText);
1657 myElements->addItem(anItem);
1658 if (!anItem->isSelected())
1659 listItemsToSel.push_back(anItem);
1662 foreach(anItem, found)
1663 if (!anItem->isSelected())
1664 listItemsToSel.push_back(anItem);
1667 bool blocked = myElements->signalsBlocked();
1668 myElements->blockSignals(true);
1669 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1670 myElements->blockSignals(blocked);
1671 onListSelectionChanged();
1672 listItemsToSel.clear();
1675 //VSR: mySelectGeomGroup->setChecked(false);
1677 onListSelectionChanged();
1680 // mySelectionMgr->clearSelected();
1684 //=================================================================================
1685 // function : onRemove()
1687 //=================================================================================
1688 void SMESHGUI_GroupDlg::onRemove()
1691 if (myCurrentLineEdit == 0) {
1692 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1693 QListWidgetItem* item;
1694 foreach(item, selItems) delete item;
1696 SALOME_ListIO aList;
1697 mySelectionMgr->selectedObjects( aList );
1699 int aNbSel = aList.Extent();
1701 if (aNbSel == 0) { myIsBusy = false; return; }
1703 SMESH::ElementType aType = SMESH::ALL;
1705 case 0: aType = SMESH::NODE; break;
1706 case 1: aType = SMESH::EDGE; break;
1707 case 2: aType = SMESH::FACE; break;
1708 case 3: aType = SMESH::VOLUME; break;
1711 if (myCurrentLineEdit == mySubMeshLine) {
1712 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1713 SALOME_ListIO aList;
1714 mySelectionMgr->selectedObjects( aList );
1716 SALOME_ListIteratorOfListIO anIt (aList);
1717 for ( ; anIt.More(); anIt.Next()) {
1718 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1719 if (!aSubMesh->_is_nil()) {
1720 // check if mesh is the same
1721 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1722 if (aType == SMESH::NODE) {
1724 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1725 int k = anElements->length();
1726 for (int i = 0; i < k; i++) {
1727 QList<QListWidgetItem*> found =
1728 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1729 QListWidgetItem* anItem;
1730 foreach(anItem, found) delete anItem;
1733 catch (const SALOME::SALOME_Exception& ex) {
1734 SalomeApp_Tools::QtCatchCorbaException(ex);
1739 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1740 int k = anElements->length();
1741 for (int i = 0; i < k; i++) {
1742 QList<QListWidgetItem*> found =
1743 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1744 QListWidgetItem* anItem;
1745 foreach(anItem, found) delete anItem;
1748 catch (const SALOME::SALOME_Exception& ex) {
1749 SalomeApp_Tools::QtCatchCorbaException(ex);
1756 else if (myCurrentLineEdit == myGroupLine) {
1757 Standard_Boolean aRes;
1758 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1759 SALOME_ListIO aList;
1760 mySelectionMgr->selectedObjects( aList );
1762 SALOME_ListIteratorOfListIO anIt (aList);
1763 for ( ; anIt.More(); anIt.Next()) {
1764 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1765 if (aRes && !aGroup->_is_nil()) {
1766 // check if mesh is the same
1767 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1768 SMESH::long_array_var anElements = aGroup->GetListOfID();
1769 int k = anElements->length();
1770 for (int i = 0; i < k; i++) {
1771 QList<QListWidgetItem*> found =
1772 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1773 QListWidgetItem* anItem;
1774 foreach(anItem, found) delete anItem;
1785 //=================================================================================
1786 // function : onSort()
1788 //=================================================================================
1789 void SMESHGUI_GroupDlg::onSort()
1791 // PAL5412: sorts items in ascending by "string" value
1792 // myElements->sort(true);
1793 // myElements->update();
1794 int i, k = myElements->count();
1797 QList<int> aSelected;
1798 std::vector<int> anArray(k);
1799 // QMemArray<int> anArray(k);
1801 for (i = 0; i < k; i++) {
1802 int id = myElements->item(i)->text().toInt();
1804 if (myElements->item(i)->isSelected())
1805 aSelected.append(id);
1807 // sort & update list
1808 std::sort(anArray.begin(), anArray.end());
1810 myElements->clear();
1811 QListWidgetItem* anItem;
1812 QList<QListWidgetItem*> listItemsToSel;
1813 for (i = 0; i < k; i++) {
1814 anItem = new QListWidgetItem(QString::number(anArray[i]));
1815 myElements->addItem(anItem);
1816 if (aSelected.contains(anArray[i]))
1817 listItemsToSel.push_back(anItem);
1819 bool blocked = myElements->signalsBlocked();
1820 myElements->blockSignals(true);
1821 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1822 myElements->blockSignals(blocked);
1823 listItemsToSel.clear();
1828 //=================================================================================
1829 // function : closeEvent()
1831 //=================================================================================
1832 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1837 //=================================================================================
1838 // function : SMESHGUI_GroupDlg::onClose
1839 // purpose : SLOT called when "Close" button pressed. Close dialog
1840 //=================================================================================
1841 void SMESHGUI_GroupDlg::onClose()
1843 if (SMESH::GetCurrentVtkView()) {
1844 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1845 SMESH::SetPointRepresentation(false);
1846 SMESH::SetPickable();
1847 restoreShowEntityMode();
1850 mySelectionMgr->clearSelected();
1851 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1852 aViewWindow->SetSelectionMode(ActorSelection);
1853 mySelectionMgr->clearFilters();
1854 mySMESHGUI->ResetState();
1859 //=================================================================================
1860 // function : onHelp()
1862 //=================================================================================
1863 void SMESHGUI_GroupDlg::onHelp()
1865 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1867 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1871 platform = "winapplication";
1873 platform = "application";
1875 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1876 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1877 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1879 arg(myHelpFileName));
1883 //=================================================================================
1884 // function : SMESHGUI_GroupDlg::onDeactivate
1885 // purpose : SLOT called when dialog must be deativated
1886 //=================================================================================
1887 void SMESHGUI_GroupDlg::onDeactivate()
1889 mySMESHGUI->ResetState();
1893 //=================================================================================
1894 // function : SMESHGUI_GroupDlg::enterEvent
1895 // purpose : Event filter
1896 //=================================================================================
1897 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1900 mySMESHGUI->EmitSignalDeactivateDialog();
1902 mySelectionMode = -1;
1903 setSelectionMode(myTypeId);
1904 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1905 mySMESHGUI->SetActiveDialogBox(this);
1906 mySMESHGUI->SetState(800);
1910 //=================================================================================
1911 // function : hideEvent
1912 // purpose : caused by ESC key
1913 //=================================================================================
1914 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1916 if (!isMinimized() && !myIsBusy)
1920 //=================================================================================
1921 // function : keyPressEvent()
1923 //=================================================================================
1924 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1926 QDialog::keyPressEvent( e );
1927 if ( e->isAccepted() )
1930 if ( e->key() == Qt::Key_F1 )
1937 //================================================================================
1939 * \brief Enable showing of the popup when Geometry selection btn is clicked
1940 * \param enable - true to enable
1942 //================================================================================
1944 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1946 void SMESHGUI_GroupDlg::updateGeomPopup()
1948 bool enable = false;
1950 if ( !myMesh->_is_nil() )
1951 enable = myMesh->NbEdges() > 0;
1953 if ( myGeomGroupBtn )
1955 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1957 if ( !myGeomPopup ) {
1958 myGeomPopup = new QMenu(this);
1959 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
1960 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
1961 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
1963 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1969 //=================================================================================
1970 // function : onGeomSelectionButton()
1972 //=================================================================================
1973 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1975 if ( myGeomPopup && isBtnOn )
1977 myCurrentLineEdit = myGeomGroupLine;
1978 QAction* a = myGeomPopup->exec( QCursor::pos() );
1979 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
1980 setSelectionMode(7);
1984 myCurrentLineEdit = 0;
1985 setSelectionMode(8);
1989 //=================================================================================
1990 // function : onGeomPopup()
1992 //=================================================================================
1993 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
1995 int index = myActions[a];
1996 if ( index == GEOM_BY_MESH_INDEX )
1998 mySelectionMode = -1;
1999 if ( !myShapeByMeshOp ) {
2000 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2001 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2002 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2003 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2004 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2006 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2007 if ( !myMesh->_is_nil() ) {
2009 hide(); // stop processing selection
2011 myShapeByMeshOp->setModule( mySMESHGUI );
2012 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2013 myShapeByMeshOp->SetMesh( myMesh );
2014 myShapeByMeshOp->start();
2019 //================================================================================
2021 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2023 //================================================================================
2025 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2027 if ( myShapeByMeshOp == op ) {
2028 mySMESHGUI->getApp()->updateObjectBrowser();
2030 // Select a found geometry object
2031 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2032 if ( !aGeomVar->_is_nil() )
2034 QString ID = aGeomVar->GetStudyEntry();
2035 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2036 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2037 SALOME_ListIO anIOList;
2038 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2039 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2040 anIOList.Append( anIO );
2041 mySelectionMgr->setSelectedObjects( anIOList, false );
2042 onObjectSelectionChanged();
2048 //================================================================================
2050 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2052 //================================================================================
2054 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2056 if ( myShapeByMeshOp == op )
2059 setSelectionMode(7);
2063 //=================================================================================
2064 // function : setGroupColor()
2066 //=================================================================================
2067 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2069 QColor aQColor( (int)( theColor.R * 255.0 ),
2070 (int)( theColor.G * 255.0 ),
2071 (int)( theColor.B * 255.0 ) );
2072 setGroupQColor( aQColor );
2075 //=================================================================================
2076 // function : getGroupColor()
2078 //=================================================================================
2079 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2081 QColor aQColor = getGroupQColor();
2083 SALOMEDS::Color aColor;
2084 aColor.R = (float)aQColor.red() / 255.0;
2085 aColor.G = (float)aQColor.green() / 255.0;
2086 aColor.B = (float)aQColor.blue() / 255.0;
2091 //=================================================================================
2092 // function : setGroupQColor()
2094 //=================================================================================
2095 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2097 if( theColor.isValid() )
2098 myColorBtn->setColor( theColor );
2101 //=================================================================================
2102 // function : getGroupQColor()
2104 //=================================================================================
2105 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2107 return myColorBtn->color();
2110 //=================================================================================
2111 // function : setDefaultGroupColor()
2113 //=================================================================================
2114 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2116 if( myMesh->_is_nil() )
2119 bool isAutoColor = myMesh->GetAutoColor();
2124 int r = 0, g = 0, b = 0;
2125 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2126 aQColor.setRgb( r, g, b );
2130 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2132 QList<SALOMEDS::Color> aReservedColors;
2133 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2135 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2136 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2137 aReservedColors.append( aReservedColor );
2140 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2141 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2142 (int)( aColor.G * 255.0 ),
2143 (int)( aColor.B * 255.0 ) );
2147 setGroupQColor( aQColor );
2150 //=================================================================================
2151 // function : SetAppropriateActor()
2152 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2153 // NPAL19389: create a group with a selection in another group.
2154 // if mesh actor is not visible - find any first visible group or submesh
2155 //=================================================================================
2156 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2158 bool isActor = false;
2160 if (myMesh->_is_nil()) return false;
2162 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2165 myActor = SMESH::FindActorByObject(myMesh);
2166 if (myActor && myActor->hasIO())
2169 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2173 // try current group actor
2175 if (!myGroup->_is_nil()) {
2176 myActor = SMESH::FindActorByObject(myGroup);
2177 if (myActor && myActor->hasIO())
2180 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2186 // try current group on geometry actor
2188 if (!myGroupOnGeom->_is_nil()) {
2189 myActor = SMESH::FindActorByObject(myGroupOnGeom);
2190 if (myActor && myActor->hasIO())
2193 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2199 // try any visible actor of group or submesh of current mesh
2200 if (!isActor && aViewWindow) {
2202 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2204 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2205 int len = strlen(meshEntry);
2207 // iterate on all actors in current view window, search for
2208 // any visible actor, that belongs to group or submesh of current mesh
2209 vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
2210 int nbItems = aCollection->GetNumberOfItems();
2211 for (int i=0; i<nbItems && !isActor; i++)
2213 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2214 if (anActor && anActor->hasIO()) {
2215 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2216 if (aViewWindow->isVisible(anIO)) {
2217 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0) {
2228 SMESH::SetPickable(myActor);
2233 //=======================================================================
2234 //function : setShowEntityMode
2235 //purpose : make shown only entity corresponding to my type
2236 //=======================================================================
2237 void SMESHGUI_GroupDlg::setShowEntityMode()
2239 if ( !myMesh->_is_nil() ) {
2240 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2241 if (!myStoredShownEntity)
2242 myStoredShownEntity = actor->GetEntityMode();
2243 switch ( myTypeId ) {
2244 case 0: restoreShowEntityMode(); break;
2245 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2246 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2247 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2253 //=======================================================================
2254 //function : restoreShowEntityMode
2255 //purpose : restore ShowEntity mode of myActor
2256 //=======================================================================
2257 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2259 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2260 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2261 actor->SetEntityMode(myStoredShownEntity);
2264 myStoredShownEntity = 0;