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);
563 if ( grpType == 0 ) {
564 myCurrentLineEdit = 0;
566 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 switch ( myTypeId ) {
802 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
803 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
805 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
811 int i, total = myElements->count();
812 for (i = 0; i < total; i++) {
813 int anId = myElements->item(i)->text().toInt();
814 int idx = myIdList.indexOf(anId);
816 aAddList.append(anId);
818 myIdList.removeAt(idx);
820 if (!aAddList.empty()) {
821 SMESH::long_array_var anIdList = new SMESH::long_array;
822 int added = aAddList.count();
823 anIdList->length(added);
824 for (i = 0; i < added; i++)
825 anIdList[i] = aAddList[i];
826 myGroup->Add(anIdList.inout());
828 if (!myIdList.empty()) {
829 SMESH::long_array_var anIdList = new SMESH::long_array;
830 int removed = myIdList.count();
831 anIdList->length(removed);
832 for (i = 0; i < removed; i++)
833 anIdList[i] = myIdList[i];
834 myGroup->Remove(anIdList.inout());
836 /* init for next operation */
838 for (i = 0; i < total; i++) {
839 myIdList.append(myElements->item(i)->text().toInt());
843 mySMESHGUI->updateObjBrowser(true);
844 SMESH::UpdateView(); // asv: fix of BUG PAL5515
845 mySelectionMgr->clearSelected();
848 else if (myGrpTypeId == 1) { // on geom object
849 if (CORBA::is_nil(myGroupOnGeom)) { // creation
850 if (myMesh->_is_nil() || !myGeomObjects->length())
853 SMESH::ElementType aType = SMESH::ALL;
855 case 0: aType = SMESH::NODE; break;
856 case 1: aType = SMESH::EDGE; break;
857 case 2: aType = SMESH::FACE; break;
858 case 3: aType = SMESH::VOLUME; break;
861 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
862 GEOM::GEOM_IGroupOperations_var aGroupOp =
863 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
865 if (myGeomObjects->length() == 1) {
866 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
867 myName->text().toLatin1().data(),
871 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
872 if ( aSMESHGen->_is_nil() )
875 // create a geometry group
876 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
877 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
879 if (geomGen->_is_nil() || !aStudy)
882 GEOM::GEOM_IGroupOperations_var op =
883 geomGen->GetIGroupOperations(aStudy->StudyId());
887 // check and add all selected GEOM objects: they must be
888 // a sub-shapes of the main GEOM and must be of one type
889 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
890 for ( int i =0; i < myGeomObjects->length(); i++) {
891 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
893 aGroupType = aSubShapeType;
894 else if (aSubShapeType != aGroupType) {
895 aGroupType = TopAbs_SHAPE;
900 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
901 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
902 op->UnionList(aGroupVar, myGeomObjects);
905 // publish the GEOM group in study
906 QString aNewGeomGroupName ( "Auto_group_for_" );
907 aNewGeomGroupName += myName->text();
908 SALOMEDS::SObject_var aNewGroupSO =
909 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
910 aNewGeomGroupName.toLatin1().data(), aMeshShape);
913 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
914 myName->text().toLatin1().data(),
918 SALOMEDS::Color aColor = getGroupColor();
919 myGroupOnGeom->SetColor(aColor);
921 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
923 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
924 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
926 /* init for next operation */
927 myName->setText( "" );
928 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
931 myGroupOnGeom->SetName(myName->text().toLatin1().data());
933 SALOMEDS::Color aColor = getGroupColor();
934 myGroupOnGeom->SetColor(aColor);
936 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
937 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
938 switch ( myTypeId ) {
939 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
940 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
942 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
947 mySMESHGUI->updateObjBrowser(true);
948 mySelectionMgr->clearSelected();
955 //=================================================================================
958 //=================================================================================
959 void SMESHGUI_GroupDlg::onOK()
965 //=================================================================================
966 // function : onListSelectionChanged()
967 // purpose : Called when selection in element list is changed
968 //=================================================================================
969 void SMESHGUI_GroupDlg::onListSelectionChanged()
971 // MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
972 if( myIsBusy || !myActor) return;
975 if (myCurrentLineEdit == 0) {
976 mySelectionMgr->clearSelected();
977 TColStd_MapOfInteger aIndexes;
978 QList<QListWidgetItem*> selItems = myElements->selectedItems();
979 QListWidgetItem* anItem;
980 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
981 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
983 aList.Append(myActor->getIO());
984 mySelectionMgr->setSelectedObjects(aList,false);
989 //=================================================================================
990 // function : onObjectSelectionChanged()
991 // purpose : Called when selection in 3D view or ObjectBrowser is changed
992 //=================================================================================
993 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
995 if ( myIsBusy || !isEnabled()) return;
996 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1000 SALOME_ListIO aList;
1001 mySelectionMgr->selectedObjects( aList );
1003 int aNbSel = aList.Extent();
1004 myElements->clearSelection();
1006 if (myCurrentLineEdit)
1008 myCurrentLineEdit->setText( "" );
1009 QString aString = "";
1011 if (myCurrentLineEdit == myMeshGroupLine)
1013 mySelectSubMesh->setEnabled(false);
1014 mySelectGroup->setEnabled(false);
1015 myGroupLine->setText( "" );
1016 mySubMeshLine->setText( "" );
1018 myGeomGroupBtn->setEnabled(false);
1019 myGeomGroupLine->setEnabled(false);
1020 myGeomGroupLine->setText( "" );
1021 myGeomObjects = new GEOM::ListOfGO();
1022 myGeomObjects->length(0);
1024 if (myGeomGroupBtn->isChecked())
1025 myGeomGroupBtn->setChecked(false);
1027 myName->setText( "" );
1029 myElements->clear();
1032 myGroup = SMESH::SMESH_Group::_nil();
1033 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1034 restoreShowEntityMode();
1035 myMesh = SMESH::SMESH_Mesh::_nil();
1041 Handle(SALOME_InteractiveObject) IO = aList.First();
1044 restoreShowEntityMode();
1045 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1046 setShowEntityMode();
1048 if (myMesh->_is_nil())
1054 myGroup = SMESH::SMESH_Group::_nil();
1056 // NPAL19389: create a group with a selection in another group
1057 // set actor of myMesh, if it is visible, else try
1058 // any visible actor of group or submesh of myMesh
1059 SetAppropriateActor();
1061 aString = aList.First()->getName();
1062 myMeshGroupLine->setText(aString);
1063 myMeshGroupLine->home( false );
1065 mySelectSubMesh->setEnabled(true);
1066 mySelectGroup->setEnabled(true);
1067 myGeomGroupBtn->setEnabled(true);
1068 myGeomGroupLine->setEnabled(true);
1072 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1073 if (aGroup->_is_nil())
1079 myCurrentLineEdit = 0;
1081 myGroup = SMESH::SMESH_Group::_nil();
1082 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1086 mySelectSubMesh->setEnabled(true);
1087 mySelectGroup->setEnabled(true);
1089 myCurrentLineEdit = 0;
1094 if (myGrpTypeId == 0)
1100 myElements->clear();
1101 setSelectionMode(myTypeId);
1109 else if (myCurrentLineEdit == myGeomGroupLine)
1111 myGeomObjects = new GEOM::ListOfGO();
1114 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1116 if (aNbSel == 0 || !aMeshSO)
1118 myGeomObjects->length(0);
1124 myGeomObjects->length(aNbSel);
1126 GEOM::GEOM_Object_var aGeomGroup;
1127 Standard_Boolean testResult;
1130 SALOME_ListIteratorOfListIO anIt (aList);
1131 for (; anIt.More(); anIt.Next())
1133 testResult = Standard_False;
1134 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1136 // Check if the object is a geometry group
1137 if (!testResult || CORBA::is_nil(aGeomGroup))
1140 // Check if group constructed on the same shape as a mesh or on its child
1141 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1142 GEOM::GEOM_IGroupOperations_var anOp =
1143 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1145 // The main shape of the group
1146 GEOM::GEOM_Object_var aGroupMainShape;
1147 if (aGeomGroup->GetType() == 37)
1148 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1150 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1151 _PTR(SObject) aGroupMainShapeSO =
1152 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1153 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1155 _PTR(SObject) anObj, aRef;
1156 bool isRefOrSubShape = false;
1157 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1158 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1159 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1160 isRefOrSubShape = true;
1162 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1163 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1164 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1165 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1166 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1167 if (aRef->GetID() == aFather->GetID())
1168 isRefOrSubShape = true;
1170 aFather = aFather->GetFather();
1174 if (isRefOrSubShape)
1175 myGeomObjects[i++] = aGeomGroup;
1178 myGeomObjects->length(i);
1190 if (myCurrentLineEdit == mySubMeshLine)
1191 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1192 else if (myCurrentLineEdit == myGroupLine)
1193 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1194 else if (myCurrentLineEdit == myGeomGroupLine)
1195 aString = tr( "%1 Objects" ).arg(aNbSel);
1198 aString = aList.First()->getName();
1202 myCurrentLineEdit->setText(aString);
1203 myCurrentLineEdit->home(false);
1204 // 07.06.2008 skl for IPAL19574:
1205 // change name of group only if it is empty
1206 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1207 myOldName = myName->text();
1208 myName->blockSignals(true);
1209 myName->setText(aString);
1210 myName->blockSignals(false);
1215 else // !myCurrentLineEdit: local selection of nodes or elements
1217 if (aNbSel == 1 && myActor && myActor->hasIO())
1219 #ifdef ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1220 // NPAL19389: create a group with a selection in another group
1221 // Switch myActor to the newly selected one, if the last
1222 // is visible and belongs to group or submesh of myMesh
1223 Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1224 Handle(SALOME_InteractiveObject) selIO = aList.First();
1225 if (curIO->hasEntry() && selIO->hasEntry()) {
1226 const char* selEntry = selIO->getEntry();
1227 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1228 // different objects: selected and myActor
1229 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1230 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1231 // newly selected actor is visible
1234 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1236 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1237 int len = strlen(meshEntry);
1239 if (strncmp(selEntry, meshEntry, len) == 0) {
1240 // selected object is myMesh or a part of it
1241 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1244 SMESH::SetPickable(myActor);
1252 #endif // ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1254 QString aListStr = "";
1256 if (myTypeId == 0) {
1257 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1259 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1262 QListWidgetItem* anItem;
1263 QList<QListWidgetItem*> listItemsToSel;
1264 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1265 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1266 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1267 foreach(anItem, found)
1268 if (!anItem->isSelected())
1269 listItemsToSel.push_back(anItem);
1271 bool blocked = myElements->signalsBlocked();
1272 myElements->blockSignals(true);
1273 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1274 myElements->blockSignals(blocked);
1275 onListSelectionChanged();
1276 listItemsToSel.clear();
1282 if (!myGroup->_is_nil())
1283 myActor = SMESH::FindActorByObject(myGroup);
1284 else if(!myGroupOnGeom->_is_nil())
1285 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1287 myActor = SMESH::FindActorByObject(myMesh);
1290 // somehow, if we display the mesh, while selecting from another actor,
1291 // the mesh becomes pickable, and there is no way to select any element
1293 SMESH::SetPickable(myActor);
1298 //=================================================================================
1299 // function : onSelectSubMesh()
1300 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1301 //=================================================================================
1302 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1305 if (mySelectGroup->isChecked()) {
1306 mySelectGroup->setChecked(false);
1308 //VSR: else if (mySelectGeomGroup->isChecked()) {
1309 //VSR: mySelectGeomGroup->setChecked(false);
1311 myCurrentLineEdit = mySubMeshLine;
1312 setSelectionMode(4);
1315 mySubMeshLine->setText( "" );
1316 myCurrentLineEdit = 0;
1318 setSelectionMode(myTypeId);
1320 mySubMeshBtn->setEnabled(on);
1321 mySubMeshLine->setEnabled(on);
1325 //=================================================================================
1326 // function : (onSelectGroup)
1327 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1328 //=================================================================================
1329 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1332 if (mySelectSubMesh->isChecked()) {
1333 mySelectSubMesh->setChecked(false);
1335 myCurrentLineEdit = myGroupLine;
1336 setSelectionMode(5);
1339 myGroupLine->setText( "" );
1340 myCurrentLineEdit = 0;
1342 setSelectionMode(myTypeId);
1344 myGroupBtn->setEnabled(on);
1345 myGroupLine->setEnabled(on);
1349 //=================================================================================
1350 // function : (onSelectGeomGroup)
1351 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1352 //=================================================================================
1353 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1356 if (mySelectSubMesh->isChecked()) {
1357 mySelectSubMesh->setChecked(false);
1359 else if (mySelectGroup->isChecked()) {
1360 mySelectGroup->setChecked(false);
1362 myCurrentLineEdit = myGeomGroupLine;
1364 setSelectionMode(8);
1367 myGeomGroupBtn->setChecked(false);
1368 myGeomObjects->length(0);
1369 myGeomGroupLine->setText( "" );
1370 myCurrentLineEdit = 0;
1372 setSelectionMode(myTypeId);
1377 //=================================================================================
1378 // function : setCurrentSelection()
1380 //=================================================================================
1381 void SMESHGUI_GroupDlg::setCurrentSelection()
1383 QPushButton* send = (QPushButton*)sender();
1384 myCurrentLineEdit = 0;
1385 if (send == myMeshGroupBtn) {
1386 myCurrentLineEdit = myMeshGroupLine;
1388 setSelectionMode(6);
1390 setSelectionMode(5);
1391 onObjectSelectionChanged();
1393 else if (send == mySubMeshBtn) {
1394 myCurrentLineEdit = mySubMeshLine;
1395 onObjectSelectionChanged();
1397 else if (send == myGroupBtn) {
1398 myCurrentLineEdit = myGroupLine;
1399 onObjectSelectionChanged();
1404 //=================================================================================
1405 // function : setFilters()
1406 // purpose : SLOT. Called when "Filter" button pressed.
1407 //=================================================================================
1408 void SMESHGUI_GroupDlg::setFilters()
1410 if(myMesh->_is_nil()) {
1411 SUIT_MessageBox::critical(this,
1413 tr("NO_MESH_SELECTED"));
1417 SMESH::ElementType aType = SMESH::ALL;
1420 case 0 : aType = SMESH::NODE; break;
1421 case 1 : aType = SMESH::EDGE; break;
1422 case 2 : aType = SMESH::FACE; break;
1423 case 3 : aType = SMESH::VOLUME; break;
1427 if ( myFilterDlg == 0 )
1429 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1430 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1433 myFilterDlg->Init( aType );
1435 myFilterDlg->SetSelection();
1436 myFilterDlg->SetMesh( myMesh );
1437 myFilterDlg->SetSourceWg( myElements, false );
1439 myFilterDlg->show();
1442 //=================================================================================
1443 // function : onFilterAccepted()
1444 // purpose : SLOT. Called when Filter dlg closed with OK button.
1445 // Uncheck "Select submesh" and "Select group" checkboxes
1446 //=================================================================================
1447 void SMESHGUI_GroupDlg::onFilterAccepted()
1449 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1451 mySelectionMode = myTypeId;
1452 mySelectSubMesh->setChecked( false );
1453 mySelectGroup->setChecked( false );
1457 //=================================================================================
1458 // function : onAdd()
1460 //=================================================================================
1461 void SMESHGUI_GroupDlg::onAdd()
1463 SALOME_ListIO aList;
1464 mySelectionMgr->selectedObjects( aList );
1466 int aNbSel = aList.Extent();
1468 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1472 SMESH::ElementType aType = SMESH::ALL;
1475 aType = SMESH::NODE;
1476 mySelector->SetSelectionMode(NodeSelection);
1479 aType = SMESH::EDGE;
1480 mySelector->SetSelectionMode(EdgeSelection);
1483 aType = SMESH::FACE;
1484 mySelector->SetSelectionMode(FaceSelection);
1487 aType = SMESH::VOLUME;
1488 mySelector->SetSelectionMode(VolumeSelection);
1491 mySelector->SetSelectionMode(ActorSelection);
1494 QListWidgetItem* anItem = 0;
1495 QList<QListWidgetItem*> listItemsToSel;
1497 if (myCurrentLineEdit == 0) {
1498 //if (aNbSel != 1) { myIsBusy = false; return; }
1499 QString aListStr = "";
1501 if (myTypeId == 0) {
1502 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1505 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1508 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1509 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1510 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1511 if (found.count() == 0) {
1512 anItem = new QListWidgetItem(*it);
1513 myElements->addItem(anItem);
1514 if (!anItem->isSelected())
1515 listItemsToSel.push_back(anItem);
1518 foreach(anItem, found)
1519 if (!anItem->isSelected())
1520 listItemsToSel.push_back(anItem);
1523 bool blocked = myElements->signalsBlocked();
1524 myElements->blockSignals(true);
1525 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1526 myElements->blockSignals(blocked);
1527 onListSelectionChanged();
1528 listItemsToSel.clear();
1530 } else if (myCurrentLineEdit == mySubMeshLine) {
1531 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1533 SALOME_ListIO aList;
1534 mySelectionMgr->selectedObjects( aList );
1536 SALOME_ListIteratorOfListIO anIt (aList);
1537 for ( ; anIt.More(); anIt.Next()) {
1538 SMESH::SMESH_subMesh_var aSubMesh =
1539 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1540 if (!aSubMesh->_is_nil()) {
1541 // check if mesh is the same
1542 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1544 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1545 int k = anElements->length();
1546 for (int i = 0; i < k; i++) {
1547 QString aText = QString::number(anElements[i]);
1548 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1549 if (found.count() == 0) {
1550 anItem = new QListWidgetItem(aText);
1551 myElements->addItem(anItem);
1552 if (!anItem->isSelected())
1553 listItemsToSel.push_back(anItem);
1556 foreach(anItem, found)
1557 if (!anItem->isSelected())
1558 listItemsToSel.push_back(anItem);
1561 bool blocked = myElements->signalsBlocked();
1562 myElements->blockSignals(true);
1563 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1564 myElements->blockSignals(blocked);
1565 onListSelectionChanged();
1566 listItemsToSel.clear();
1568 catch (const SALOME::SALOME_Exception& ex) {
1569 SalomeApp_Tools::QtCatchCorbaException(ex);
1574 mySelectSubMesh->setChecked(false);
1576 onListSelectionChanged();
1578 } else if (myCurrentLineEdit == myGroupLine) {
1579 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1580 SALOME_ListIO aList;
1581 mySelectionMgr->selectedObjects( aList );
1583 SALOME_ListIteratorOfListIO anIt (aList);
1584 for ( ; anIt.More(); anIt.Next()) {
1585 SMESH::SMESH_GroupBase_var aGroup =
1586 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1587 if (!aGroup->_is_nil()) {
1588 // check if mesh is the same
1589 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1590 SMESH::long_array_var anElements = aGroup->GetListOfID();
1591 int k = anElements->length();
1592 for (int i = 0; i < k; i++) {
1593 QString aText = QString::number(anElements[i]);
1594 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1595 if (found.count() == 0) {
1596 anItem = new QListWidgetItem(aText);
1597 myElements->addItem(anItem);
1598 if (!anItem->isSelected())
1599 listItemsToSel.push_back(anItem);
1602 foreach(anItem, found)
1603 if (!anItem->isSelected())
1604 listItemsToSel.push_back(anItem);
1607 bool blocked = myElements->signalsBlocked();
1608 myElements->blockSignals(true);
1609 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1610 myElements->blockSignals(blocked);
1611 onListSelectionChanged();
1612 listItemsToSel.clear();
1616 mySelectGroup->setChecked(false);
1618 onListSelectionChanged();
1620 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1621 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1622 GEOM::GEOM_IGroupOperations_var aGroupOp =
1623 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1625 SMESH::ElementType aGroupType = SMESH::ALL;
1626 switch(aGroupOp->GetType(myGeomObjects[0])) {
1627 case 7: aGroupType = SMESH::NODE; break;
1628 case 6: aGroupType = SMESH::EDGE; break;
1629 case 4: aGroupType = SMESH::FACE; break;
1630 case 2: aGroupType = SMESH::VOLUME; break;
1631 default: myIsBusy = false; return;
1634 if (aGroupType == aType) {
1635 _PTR(SObject) aGroupSO =
1636 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1637 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1639 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1640 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1641 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1642 aBelongToGeom->SetGeom(myGeomObjects[0]);
1643 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1644 aBelongToGeom->SetElementType(aType);
1645 aFilter->SetPredicate(aBelongToGeom);
1647 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1649 int k = anElements->length();
1650 for (int i = 0; i < k; i++) {
1651 QString aText = QString::number(anElements[i]);
1652 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1653 if (found.count() == 0) {
1654 anItem = new QListWidgetItem(aText);
1655 myElements->addItem(anItem);
1656 if (!anItem->isSelected())
1657 listItemsToSel.push_back(anItem);
1660 foreach(anItem, found)
1661 if (!anItem->isSelected())
1662 listItemsToSel.push_back(anItem);
1665 bool blocked = myElements->signalsBlocked();
1666 myElements->blockSignals(true);
1667 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1668 myElements->blockSignals(blocked);
1669 onListSelectionChanged();
1670 listItemsToSel.clear();
1673 //VSR: mySelectGeomGroup->setChecked(false);
1675 onListSelectionChanged();
1678 // mySelectionMgr->clearSelected();
1682 //=================================================================================
1683 // function : onRemove()
1685 //=================================================================================
1686 void SMESHGUI_GroupDlg::onRemove()
1689 if (myCurrentLineEdit == 0) {
1690 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1691 QListWidgetItem* item;
1692 foreach(item, selItems) delete item;
1694 SALOME_ListIO aList;
1695 mySelectionMgr->selectedObjects( aList );
1697 int aNbSel = aList.Extent();
1699 if (aNbSel == 0) { myIsBusy = false; return; }
1701 SMESH::ElementType aType = SMESH::ALL;
1703 case 0: aType = SMESH::NODE; break;
1704 case 1: aType = SMESH::EDGE; break;
1705 case 2: aType = SMESH::FACE; break;
1706 case 3: aType = SMESH::VOLUME; break;
1709 if (myCurrentLineEdit == mySubMeshLine) {
1710 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1711 SALOME_ListIO aList;
1712 mySelectionMgr->selectedObjects( aList );
1714 SALOME_ListIteratorOfListIO anIt (aList);
1715 for ( ; anIt.More(); anIt.Next()) {
1716 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1717 if (!aSubMesh->_is_nil()) {
1718 // check if mesh is the same
1719 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1720 if (aType == SMESH::NODE) {
1722 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1723 int k = anElements->length();
1724 for (int i = 0; i < k; i++) {
1725 QList<QListWidgetItem*> found =
1726 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1727 QListWidgetItem* anItem;
1728 foreach(anItem, found) delete anItem;
1731 catch (const SALOME::SALOME_Exception& ex) {
1732 SalomeApp_Tools::QtCatchCorbaException(ex);
1737 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1738 int k = anElements->length();
1739 for (int i = 0; i < k; i++) {
1740 QList<QListWidgetItem*> found =
1741 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1742 QListWidgetItem* anItem;
1743 foreach(anItem, found) delete anItem;
1746 catch (const SALOME::SALOME_Exception& ex) {
1747 SalomeApp_Tools::QtCatchCorbaException(ex);
1754 else if (myCurrentLineEdit == myGroupLine) {
1755 Standard_Boolean aRes;
1756 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1757 SALOME_ListIO aList;
1758 mySelectionMgr->selectedObjects( aList );
1760 SALOME_ListIteratorOfListIO anIt (aList);
1761 for ( ; anIt.More(); anIt.Next()) {
1762 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1763 if (aRes && !aGroup->_is_nil()) {
1764 // check if mesh is the same
1765 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1766 SMESH::long_array_var anElements = aGroup->GetListOfID();
1767 int k = anElements->length();
1768 for (int i = 0; i < k; i++) {
1769 QList<QListWidgetItem*> found =
1770 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1771 QListWidgetItem* anItem;
1772 foreach(anItem, found) delete anItem;
1783 //=================================================================================
1784 // function : onSort()
1786 //=================================================================================
1787 void SMESHGUI_GroupDlg::onSort()
1789 // PAL5412: sorts items in ascending by "string" value
1790 // myElements->sort(true);
1791 // myElements->update();
1792 int i, k = myElements->count();
1795 QList<int> aSelected;
1796 std::vector<int> anArray(k);
1797 // QMemArray<int> anArray(k);
1799 for (i = 0; i < k; i++) {
1800 int id = myElements->item(i)->text().toInt();
1802 if (myElements->item(i)->isSelected())
1803 aSelected.append(id);
1805 // sort & update list
1806 std::sort(anArray.begin(), anArray.end());
1808 myElements->clear();
1809 QListWidgetItem* anItem;
1810 QList<QListWidgetItem*> listItemsToSel;
1811 for (i = 0; i < k; i++) {
1812 anItem = new QListWidgetItem(QString::number(anArray[i]));
1813 myElements->addItem(anItem);
1814 if (aSelected.contains(anArray[i]))
1815 listItemsToSel.push_back(anItem);
1817 bool blocked = myElements->signalsBlocked();
1818 myElements->blockSignals(true);
1819 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1820 myElements->blockSignals(blocked);
1821 listItemsToSel.clear();
1826 //=================================================================================
1827 // function : closeEvent()
1829 //=================================================================================
1830 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1835 //=================================================================================
1836 // function : SMESHGUI_GroupDlg::onClose
1837 // purpose : SLOT called when "Close" button pressed. Close dialog
1838 //=================================================================================
1839 void SMESHGUI_GroupDlg::onClose()
1841 if (SMESH::GetCurrentVtkView()) {
1842 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1843 SMESH::SetPointRepresentation(false);
1844 SMESH::SetPickable();
1845 restoreShowEntityMode();
1848 mySelectionMgr->clearSelected();
1849 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1850 aViewWindow->SetSelectionMode(ActorSelection);
1851 mySelectionMgr->clearFilters();
1852 mySMESHGUI->ResetState();
1857 //=================================================================================
1858 // function : onHelp()
1860 //=================================================================================
1861 void SMESHGUI_GroupDlg::onHelp()
1863 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1865 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1869 platform = "winapplication";
1871 platform = "application";
1873 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1874 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1875 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1877 arg(myHelpFileName));
1881 //=================================================================================
1882 // function : SMESHGUI_GroupDlg::onDeactivate
1883 // purpose : SLOT called when dialog must be deativated
1884 //=================================================================================
1885 void SMESHGUI_GroupDlg::onDeactivate()
1887 mySMESHGUI->ResetState();
1891 //=================================================================================
1892 // function : SMESHGUI_GroupDlg::enterEvent
1893 // purpose : Event filter
1894 //=================================================================================
1895 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1898 mySMESHGUI->EmitSignalDeactivateDialog();
1900 mySelectionMode = -1;
1901 setSelectionMode(myTypeId);
1902 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1903 mySMESHGUI->SetActiveDialogBox(this);
1904 mySMESHGUI->SetState(800);
1908 //=================================================================================
1909 // function : hideEvent
1910 // purpose : caused by ESC key
1911 //=================================================================================
1912 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1914 if (!isMinimized() && !myIsBusy)
1918 //=================================================================================
1919 // function : keyPressEvent()
1921 //=================================================================================
1922 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1924 QDialog::keyPressEvent( e );
1925 if ( e->isAccepted() )
1928 if ( e->key() == Qt::Key_F1 )
1935 //================================================================================
1937 * \brief Enable showing of the popup when Geometry selection btn is clicked
1938 * \param enable - true to enable
1940 //================================================================================
1942 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1944 void SMESHGUI_GroupDlg::updateGeomPopup()
1946 bool enable = false;
1948 if ( !myMesh->_is_nil() )
1949 enable = myMesh->NbEdges() > 0;
1951 if ( myGeomGroupBtn )
1953 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1955 if ( !myGeomPopup ) {
1956 myGeomPopup = new QMenu(this);
1957 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
1958 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
1959 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
1961 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1967 //=================================================================================
1968 // function : onGeomSelectionButton()
1970 //=================================================================================
1971 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1973 if ( myGeomPopup && isBtnOn )
1975 myCurrentLineEdit = myGeomGroupLine;
1976 QAction* a = myGeomPopup->exec( QCursor::pos() );
1977 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
1978 setSelectionMode(7);
1982 myCurrentLineEdit = 0;
1983 setSelectionMode(8);
1987 //=================================================================================
1988 // function : onGeomPopup()
1990 //=================================================================================
1991 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
1993 int index = myActions[a];
1994 if ( index == GEOM_BY_MESH_INDEX )
1996 mySelectionMode = -1;
1997 if ( !myShapeByMeshOp ) {
1998 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1999 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2000 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2001 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2002 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2004 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2005 if ( !myMesh->_is_nil() ) {
2007 hide(); // stop processing selection
2009 myShapeByMeshOp->setModule( mySMESHGUI );
2010 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2011 myShapeByMeshOp->SetMesh( myMesh );
2012 myShapeByMeshOp->start();
2017 //================================================================================
2019 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2021 //================================================================================
2023 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2025 if ( myShapeByMeshOp == op ) {
2026 mySMESHGUI->getApp()->updateObjectBrowser();
2028 // Select a found geometry object
2029 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2030 if ( !aGeomVar->_is_nil() )
2032 QString ID = aGeomVar->GetStudyEntry();
2033 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2034 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2035 SALOME_ListIO anIOList;
2036 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2037 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2038 anIOList.Append( anIO );
2039 mySelectionMgr->setSelectedObjects( anIOList, false );
2040 onObjectSelectionChanged();
2046 //================================================================================
2048 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2050 //================================================================================
2052 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2054 if ( myShapeByMeshOp == op )
2057 setSelectionMode(7);
2061 //=================================================================================
2062 // function : setGroupColor()
2064 //=================================================================================
2065 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2067 QColor aQColor( (int)( theColor.R * 255.0 ),
2068 (int)( theColor.G * 255.0 ),
2069 (int)( theColor.B * 255.0 ) );
2070 setGroupQColor( aQColor );
2073 //=================================================================================
2074 // function : getGroupColor()
2076 //=================================================================================
2077 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2079 QColor aQColor = getGroupQColor();
2081 SALOMEDS::Color aColor;
2082 aColor.R = (float)aQColor.red() / 255.0;
2083 aColor.G = (float)aQColor.green() / 255.0;
2084 aColor.B = (float)aQColor.blue() / 255.0;
2089 //=================================================================================
2090 // function : setGroupQColor()
2092 //=================================================================================
2093 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2095 if( theColor.isValid() )
2096 myColorBtn->setColor( theColor );
2099 //=================================================================================
2100 // function : getGroupQColor()
2102 //=================================================================================
2103 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2105 return myColorBtn->color();
2108 //=================================================================================
2109 // function : setDefaultGroupColor()
2111 //=================================================================================
2112 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2114 if( myMesh->_is_nil() )
2117 bool isAutoColor = myMesh->GetAutoColor();
2122 int r = 0, g = 0, b = 0;
2123 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2124 aQColor.setRgb( r, g, b );
2128 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2130 QList<SALOMEDS::Color> aReservedColors;
2131 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2133 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2134 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2135 aReservedColors.append( aReservedColor );
2138 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2139 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2140 (int)( aColor.G * 255.0 ),
2141 (int)( aColor.B * 255.0 ) );
2145 setGroupQColor( aQColor );
2148 //=================================================================================
2149 // function : SetAppropriateActor()
2150 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2151 // NPAL19389: create a group with a selection in another group.
2152 // if mesh actor is not visible - find any first visible group or submesh
2153 //=================================================================================
2154 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2156 bool isActor = false;
2158 if (myMesh->_is_nil()) return false;
2160 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2163 myActor = SMESH::FindActorByObject(myMesh);
2164 if (myActor && myActor->hasIO())
2167 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2171 // try current group actor
2173 if (!myGroup->_is_nil()) {
2174 myActor = SMESH::FindActorByObject(myGroup);
2175 if (myActor && myActor->hasIO())
2178 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2184 // try current group on geometry actor
2186 if (!myGroupOnGeom->_is_nil()) {
2187 myActor = SMESH::FindActorByObject(myGroupOnGeom);
2188 if (myActor && myActor->hasIO())
2191 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2197 // try any visible actor of group or submesh of current mesh
2198 if (!isActor && aViewWindow) {
2200 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2202 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2203 int len = strlen(meshEntry);
2205 // iterate on all actors in current view window, search for
2206 // any visible actor, that belongs to group or submesh of current mesh
2207 vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
2208 int nbItems = aCollection->GetNumberOfItems();
2209 for (int i=0; i<nbItems && !isActor; i++)
2211 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2212 if (anActor && anActor->hasIO()) {
2213 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2214 if (aViewWindow->isVisible(anIO)) {
2215 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0) {
2226 SMESH::SetPickable(myActor);
2231 //=======================================================================
2232 //function : setShowEntityMode
2233 //purpose : make shown only entity corresponding to my type
2234 //=======================================================================
2235 void SMESHGUI_GroupDlg::setShowEntityMode()
2237 if ( !myMesh->_is_nil() ) {
2238 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2239 if (!myStoredShownEntity)
2240 myStoredShownEntity = actor->GetEntityMode();
2241 switch ( myTypeId ) {
2242 case 0: restoreShowEntityMode(); break;
2243 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2244 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2245 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2251 //=======================================================================
2252 //function : restoreShowEntityMode
2253 //purpose : restore ShowEntity mode of myActor
2254 //=======================================================================
2255 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2257 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2258 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2259 actor->SetEntityMode(myStoredShownEntity);
2262 myStoredShownEntity = 0;