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_EditMeshDlg.cxx
24 // Author : Open CASCADE S.A.S.
27 #include "SMESHGUI_EditMeshDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_SpinBox.h"
35 #include <SMESH_Actor.h>
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_LogicalFilter.hxx>
38 #include <SMDS_Mesh.hxx>
40 // SALOME GUI includes
41 #include <SUIT_Desktop.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_OverrideCursor.h>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
59 #include <SALOMEconfig.h>
60 #include CORBA_SERVER_HEADER(SMESH_Group)
61 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
64 #include <vtkUnstructuredGrid.h>
65 #include <vtkRenderer.h>
66 #include <vtkActor2D.h>
67 #include <vtkPoints.h>
68 #include <vtkDataSetMapper.h>
69 #include <vtkMaskPoints.h>
70 #include <vtkSelectVisiblePoints.h>
71 #include <vtkLabeledDataMapper.h>
72 #include <vtkTextProperty.h>
73 #include <vtkIntArray.h>
74 #include <vtkProperty2D.h>
75 #include <vtkPointData.h>
76 #include <vtkConfigure.h>
77 #if !defined(VTK_XVERSION)
78 #define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION)
82 #include <QApplication>
86 #include <QListWidget>
87 #include <QPushButton>
88 #include <QRadioButton>
90 #include <QHBoxLayout>
91 #include <QVBoxLayout>
92 #include <QGridLayout>
94 #include <QButtonGroup>
102 { // to display in the viewer IDs of the selected elements
103 SVTK_ViewWindow* myViewWindow;
105 vtkUnstructuredGrid* myIdGrid;
106 SALOME_Actor* myIdActor;
108 vtkUnstructuredGrid* myPointsNumDataSet;
109 vtkMaskPoints* myPtsMaskPoints;
110 vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
111 vtkLabeledDataMapper* myPtsLabeledDataMapper;
112 vtkTextProperty* aPtsTextProp;
113 bool myIsPointsLabeled;
114 vtkActor2D* myPointLabels;
116 std::vector<int> myIDs;
119 TIdPreview(SVTK_ViewWindow* theViewWindow):
120 myViewWindow(theViewWindow)
122 myIdGrid = vtkUnstructuredGrid::New();
124 // Create and display actor
125 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
126 aMapper->SetInput( myIdGrid );
128 myIdActor = SALOME_Actor::New();
129 myIdActor->SetInfinitive(true);
130 myIdActor->VisibilityOff();
131 myIdActor->PickableOff();
133 myIdActor->SetMapper( aMapper );
136 myViewWindow->AddActor(myIdActor);
138 //Definition of points numbering pipeline
139 myPointsNumDataSet = vtkUnstructuredGrid::New();
141 myPtsMaskPoints = vtkMaskPoints::New();
142 myPtsMaskPoints->SetInput(myPointsNumDataSet);
143 myPtsMaskPoints->SetOnRatio(1);
145 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
146 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
147 myPtsSelectVisiblePoints->SelectInvisibleOff();
148 myPtsSelectVisiblePoints->SetTolerance(0.1);
150 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
151 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
152 #if (VTK_XVERSION < 0x050200)
153 myPtsLabeledDataMapper->SetLabelFormat("%g");
155 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
157 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
158 aPtsTextProp->SetFontFamilyToTimes();
159 static int aPointsFontSize = 12;
160 aPtsTextProp->SetFontSize(aPointsFontSize);
161 aPtsTextProp->SetBold(1);
162 aPtsTextProp->SetItalic(0);
163 aPtsTextProp->SetShadow(0);
164 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
165 aPtsTextProp->Delete();
167 myIsPointsLabeled = false;
169 myPointLabels = vtkActor2D::New();
170 myPointLabels->SetMapper(myPtsLabeledDataMapper);
171 myPointLabels->GetProperty()->SetColor(1,1,1);
172 myPointLabels->SetVisibility(myIsPointsLabeled);
174 AddToRender(myViewWindow->getRenderer());
177 void SetPointsData ( SMDS_Mesh* theMesh,
178 TColStd_MapOfInteger & theNodesIdMap )
180 vtkPoints* aPoints = vtkPoints::New();
181 aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
184 TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
185 for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
186 const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
187 aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
188 myIDs.push_back(idIter.Key());
191 myIdGrid->SetPoints(aPoints);
195 myIdActor->GetMapper()->Update();
198 void SetElemsData( TColStd_MapOfInteger & theElemsIdMap,
199 std::list<gp_XYZ> & aGrCentersXYZ )
201 vtkPoints* aPoints = vtkPoints::New();
202 aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
205 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
206 for( ; idIter.More(); idIter.Next() ) {
207 myIDs.push_back(idIter.Key());
211 std::list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
212 for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
214 aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
216 myIdGrid->SetPoints(aPoints);
219 myIdActor->GetMapper()->Update();
222 void AddToRender(vtkRenderer* theRenderer)
224 myIdActor->AddToRender(theRenderer);
226 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
227 theRenderer->AddActor2D(myPointLabels);
230 void RemoveFromRender(vtkRenderer* theRenderer)
232 myIdActor->RemoveFromRender(theRenderer);
234 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
235 theRenderer->RemoveActor(myPointLabels);
238 void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
240 myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
242 if ( myIsPointsLabeled ) {
243 myPointsNumDataSet->ShallowCopy(myIdGrid);
244 vtkDataSet *aDataSet = myPointsNumDataSet;
245 int aNbElem = myIDs.size();
246 vtkIntArray *anArray = vtkIntArray::New();
247 anArray->SetNumberOfValues( aNbElem );
248 for ( int i = 0; i < aNbElem; i++ )
249 anArray->SetValue( i, myIDs[i] );
250 aDataSet->GetPointData()->SetScalars( anArray );
252 myPtsMaskPoints->SetInput( aDataSet );
253 myPointLabels->SetVisibility( theIsActorVisible );
256 myPointLabels->SetVisibility( false );
262 RemoveFromRender(myViewWindow->getRenderer());
266 myViewWindow->RemoveActor(myIdActor);
269 //Deleting of points numbering pipeline
270 //---------------------------------------
271 myPointsNumDataSet->Delete();
273 //myPtsLabeledDataMapper->RemoveAllInputs(); //vtk 5.0 porting
274 myPtsLabeledDataMapper->Delete();
276 //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
277 myPtsSelectVisiblePoints->Delete();
279 //myPtsMaskPoints->UnRegisterAllOutputs(); //vtk 5.0 porting
280 myPtsMaskPoints->Delete();
282 myPointLabels->Delete();
284 // myTimeStamp->Delete();
289 static const char * IconFirst[] = {
304 //=================================================================================
305 // class : SMESHGUI_EditMeshDlg()
307 //=================================================================================
308 SMESHGUI_EditMeshDlg::SMESHGUI_EditMeshDlg (SMESHGUI* theModule,
310 : QDialog(SMESH::GetDesktop(theModule)),
311 mySMESHGUI(theModule),
312 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
316 setAttribute(Qt::WA_DeleteOnClose, true);
317 setWindowTitle(myAction == 1 ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
319 myIdPreview = new SMESH::TIdPreview(SMESH::GetViewWindow( mySMESHGUI ));
321 SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
322 QPixmap IconMergeNodes (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
323 QPixmap IconMergeElems (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_MERGE_ELEMENTS")));
324 QPixmap IconSelect (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
325 QPixmap IconAdd (aResMgr->loadPixmap("SMESH", tr("ICON_APPEND")));
326 QPixmap IconRemove (aResMgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
328 setSizeGripEnabled(true);
330 QVBoxLayout* DlgLayout = new QVBoxLayout(this);
331 DlgLayout->setSpacing(SPACING);
332 DlgLayout->setMargin(MARGIN);
334 /***************************************************************/
335 GroupConstructors = new QGroupBox(myAction == 1 ?
336 tr("SMESH_MERGE_ELEMENTS") :
337 tr("SMESH_MERGE_NODES"),
340 QButtonGroup* ButtonGroup = new QButtonGroup(this);
341 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
342 GroupConstructorsLayout->setSpacing(SPACING);
343 GroupConstructorsLayout->setMargin(MARGIN);
345 RadioButton = new QRadioButton(GroupConstructors);
346 RadioButton->setIcon(myAction == 1 ? IconMergeElems : IconMergeNodes);
347 RadioButton->setChecked(true);
348 GroupConstructorsLayout->addWidget(RadioButton);
349 ButtonGroup->addButton(RadioButton, 0);
351 /***************************************************************/
352 // Controls for mesh defining
353 GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
354 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
355 GroupMeshLayout->setSpacing(SPACING);
356 GroupMeshLayout->setMargin(MARGIN);
358 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupMesh);
359 SelectMeshButton = new QPushButton(GroupMesh);
360 SelectMeshButton->setIcon(IconSelect);
361 LineEditMesh = new QLineEdit(GroupMesh);
362 LineEditMesh->setReadOnly(true);
364 GroupMeshLayout->addWidget(TextLabelName);
365 GroupMeshLayout->addWidget(SelectMeshButton);
366 GroupMeshLayout->addWidget(LineEditMesh);
368 /***************************************************************/
369 // Controls for coincident elements detecting
370 GroupCoincident = new QGroupBox(myAction == 1 ?
371 tr("COINCIDENT_ELEMENTS") :
372 tr("COINCIDENT_NODES"),
375 QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincident);
376 GroupCoincidentLayout->setSpacing(SPACING);
377 GroupCoincidentLayout->setMargin(MARGIN);
379 if (myAction == 0) { // case merge nodes
380 TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), GroupCoincident);
381 SpinBoxTolerance = new SMESHGUI_SpinBox(GroupCoincident);
382 SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
384 GroupCoincidentLayout->addWidget(TextLabelTolerance, 0, 0);
385 GroupCoincidentLayout->addWidget(SpinBoxTolerance, 0, 1);
388 TextLabelTolerance = 0;
389 SpinBoxTolerance = 0;
392 int row = GroupCoincidentLayout->rowCount();
394 ListCoincident = new QListWidget(GroupCoincident);
395 ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
397 DetectButton = new QPushButton(tr("DETECT"), GroupCoincident);
398 AddGroupButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupCoincident);
399 RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincident);
401 SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincident);
403 GroupCoincidentLayout->addWidget(ListCoincident, row, 0, 4, 2);
404 GroupCoincidentLayout->addWidget(DetectButton, row, 2);
405 GroupCoincidentLayout->addWidget(AddGroupButton, row+2, 2);
406 GroupCoincidentLayout->addWidget(RemoveGroupButton, row+3, 2);
407 GroupCoincidentLayout->addWidget(SelectAllCB, row+4, 0, 1, 3);
408 GroupCoincidentLayout->setRowMinimumHeight(row+1, 10);
409 GroupCoincidentLayout->setRowStretch(row+1, 5);
411 /***************************************************************/
412 // Controls for editing the selected group
413 GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
414 QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
415 GroupEditLayout->setSpacing(SPACING);
416 GroupEditLayout->setMargin(MARGIN);
418 ListEdit = new QListWidget(GroupEdit);
419 //ListEdit->setRowMode(QListBox::FixedNumber);
420 //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
421 //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
422 ListEdit->setFlow( QListView::LeftToRight );
423 ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
425 AddElemButton = new QPushButton(GroupEdit);
426 AddElemButton->setIcon(IconAdd);
427 RemoveElemButton = new QPushButton(GroupEdit);
428 RemoveElemButton->setIcon(IconRemove);
429 SetFirstButton = new QPushButton(GroupEdit);
430 SetFirstButton->setIcon(QPixmap(IconFirst));
432 GroupEditLayout->addWidget(ListEdit, 0, 0, 2, 1);
433 GroupEditLayout->addWidget(AddElemButton, 0, 1);
434 GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
435 GroupEditLayout->addWidget(SetFirstButton, 1, 1, 1, 2);
437 /***************************************************************/
438 GroupButtons = new QGroupBox(this);
439 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
440 GroupButtonsLayout->setSpacing(SPACING);
441 GroupButtonsLayout->setMargin(MARGIN);
443 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
444 buttonOk->setAutoDefault(true);
445 buttonOk->setDefault(true);
446 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
447 buttonApply->setAutoDefault(true);
448 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
449 buttonCancel->setAutoDefault(true);
450 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
451 buttonHelp->setAutoDefault(true);
453 GroupButtonsLayout->addWidget(buttonOk);
454 GroupButtonsLayout->addSpacing(10);
455 GroupButtonsLayout->addWidget(buttonApply);
456 GroupButtonsLayout->addSpacing(10);
457 GroupButtonsLayout->addStretch();
458 GroupButtonsLayout->addWidget(buttonCancel);
459 GroupButtonsLayout->addWidget(buttonHelp);
461 /***************************************************************/
462 DlgLayout->addWidget(GroupConstructors);
463 DlgLayout->addWidget(GroupMesh);
464 DlgLayout->addWidget(GroupCoincident);
465 DlgLayout->addWidget(GroupEdit);
466 DlgLayout->addWidget(GroupButtons);
468 Init(); // Initialisations
471 //=================================================================================
472 // function : ~SMESHGUI_EditMeshDlg()
473 // purpose : Destroys the object and frees any allocated resources
474 //=================================================================================
475 SMESHGUI_EditMeshDlg::~SMESHGUI_EditMeshDlg()
480 //=================================================================================
483 //=================================================================================
484 void SMESHGUI_EditMeshDlg::Init()
487 SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, 5);
488 SpinBoxTolerance->SetValue(1e-05);
491 RadioButton->setChecked(true);
493 myEditCurrentArgument = (QWidget*)LineEditMesh;
496 mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
498 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
500 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
503 // Costruction of the logical filter
504 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
505 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
507 QList<SUIT_SelectionFilter*> aListOfFilters;
508 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
509 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
511 myMeshOrSubMeshOrGroupFilter =
512 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
514 /* signals and slots connections */
515 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
516 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
517 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
518 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
520 connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
521 connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
522 connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
523 connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
524 connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
525 connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
526 connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
527 connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
528 connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
529 connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
531 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
532 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
533 /* to close dialog if study change */
534 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
536 SetFirstButton->setEnabled(false);
537 buttonOk->setEnabled(false);
538 buttonApply->setEnabled(false);
540 // Init Mesh field from selection
541 SelectionIntoArgument();
543 myHelpFileName = "merging_elements_page.html";
546 //=================================================================================
547 // function : FindGravityCenter()
549 //=================================================================================
550 void SMESHGUI_EditMeshDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap,
551 std::list< gp_XYZ > & theGrCentersXYZ)
556 SMDS_Mesh* aMesh = 0;
557 aMesh = myActor->GetObject()->GetMesh();
563 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
564 for( ; idIter.More(); idIter.Next() ) {
565 const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
569 gp_XYZ anXYZ(0., 0., 0.);
570 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
571 for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
572 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
573 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
575 anXYZ.Divide( nbNodes );
577 theGrCentersXYZ.push_back( anXYZ );
581 //=================================================================================
582 // function : ClickOnApply()
584 //=================================================================================
585 bool SMESHGUI_EditMeshDlg::ClickOnApply()
587 if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
591 SUIT_OverrideCursor aWaitCursor;
592 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
594 SMESH::long_array_var anIds = new SMESH::long_array;
595 SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
597 aGroupsOfElements->length(ListCoincident->count());
600 for (int i = 0; i < ListCoincident->count(); i++) {
601 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
603 anIds->length(aListIds.count());
604 for (int i = 0; i < aListIds.count(); i++)
605 anIds[i] = aListIds[i].toInt();
607 aGroupsOfElements[anArrayNum++] = anIds.inout();
611 aMeshEditor->MergeNodes (aGroupsOfElements.inout());
613 aMeshEditor->MergeElements (aGroupsOfElements.inout());
624 //=================================================================================
625 // function : ClickOnOk()
627 //=================================================================================
628 void SMESHGUI_EditMeshDlg::ClickOnOk()
634 //=================================================================================
635 // function : ClickOnCancel()
637 //=================================================================================
638 void SMESHGUI_EditMeshDlg::ClickOnCancel()
640 myIdPreview->SetPointsLabeled(false);
641 mySelectionMgr->clearFilters();
642 //mySelectionMgr->clearSelected();
643 SMESH::SetPointRepresentation(false);
644 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
645 aViewWindow->SetSelectionMode(ActorSelection);
646 disconnect(mySelectionMgr, 0, this, 0);
647 mySMESHGUI->ResetState();
651 //=================================================================================
652 // function : ClickOnHelp()
654 //=================================================================================
655 void SMESHGUI_EditMeshDlg::ClickOnHelp()
657 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
659 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
663 platform = "winapplication";
665 platform = "application";
667 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
668 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
669 arg(app->resourceMgr()->stringValue("ExternalBrowser",
671 arg(myHelpFileName));
675 //=================================================================================
676 // function : onEditGroup()
678 //=================================================================================
679 void SMESHGUI_EditMeshDlg::onEditGroup()
681 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
682 if ( selItems.count() != 1 ) {
689 for (int i = 0; i < ListEdit->count(); i++ )
690 aNewIds.append(ListEdit->item(i)->text());
692 ListCoincident->clearSelection();
693 selItems.first()->setText(aNewIds.join(" "));
694 selItems.first()->setSelected(true);
697 //=================================================================================
698 // function : updateControls()
700 //=================================================================================
701 void SMESHGUI_EditMeshDlg::updateControls()
703 if (ListEdit->count() == 0)
704 SetFirstButton->setEnabled(false);
705 bool enable = !(myMesh->_is_nil()) && ListCoincident->count();
706 buttonOk->setEnabled(enable);
707 buttonApply->setEnabled(enable);
710 //=================================================================================
711 // function : onDetect()
713 //=================================================================================
714 void SMESHGUI_EditMeshDlg::onDetect()
716 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
720 SUIT_OverrideCursor aWaitCursor;
721 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
723 ListCoincident->clear();
726 SMESH::array_of_long_array_var aGroupsArray;
730 if(!mySubMeshOrGroup->_is_nil())
731 aMeshEditor->FindCoincidentNodesOnPart(mySubMeshOrGroup, SpinBoxTolerance->GetValue(), aGroupsArray);
733 aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aGroupsArray);
736 if(!mySubMeshOrGroup->_is_nil())
737 aMeshEditor->FindEqualElements(mySubMeshOrGroup, aGroupsArray);
739 aMeshEditor->FindEqualElements(myMesh, aGroupsArray);
743 for (int i = 0; i < aGroupsArray->length(); i++) {
744 SMESH::long_array& aGroup = aGroupsArray[i];
747 for (int j = 0; j < aGroup.length(); j++)
748 anIDs.append(QString::number(aGroup[j]));
750 ListCoincident->addItem(anIDs.join(" "));
755 ListCoincident->selectAll();
759 //=================================================================================
760 // function : onSelectGroup()
762 //=================================================================================
763 void SMESHGUI_EditMeshDlg::onSelectGroup()
765 if (myIsBusy || !myActor)
767 myEditCurrentArgument = (QWidget*)ListCoincident;
771 TColStd_MapOfInteger anIndices;
772 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
773 QListWidgetItem* anItem;
774 QStringList aListIds;
778 foreach(anItem, selItems) {
779 aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
780 for (int i = 0; i < aListIds.count(); i++)
781 anIndices.Add(aListIds[i].toInt());
784 if (selItems.count() == 1) {
785 ListEdit->addItems(aListIds);
786 ListEdit->selectAll();
789 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
791 aList.Append(myActor->getIO());
792 mySelectionMgr->setSelectedObjects(aList,false);
795 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
796 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
799 std::list< gp_XYZ > aGrCentersXYZ;
800 FindGravityCenter(anIndices, aGrCentersXYZ);
801 myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
802 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
808 //=================================================================================
809 // function : onSelectAll()
811 //=================================================================================
812 void SMESHGUI_EditMeshDlg::onSelectAll (bool isToggled)
815 ListCoincident->selectAll();
817 ListCoincident->clearSelection();
820 //=================================================================================
821 // function : onSelectElementFromGroup()
823 //=================================================================================
824 void SMESHGUI_EditMeshDlg::onSelectElementFromGroup()
826 if (myIsBusy || !myActor)
829 TColStd_MapOfInteger anIndices;
830 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
831 QListWidgetItem* anItem;
833 foreach(anItem, selItems)
834 anIndices.Add(anItem->text().toInt());
836 SetFirstButton->setEnabled(selItems.count() == 1);
838 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
840 aList.Append(myActor->getIO());
841 mySelectionMgr->setSelectedObjects(aList);
844 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
845 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
848 std::list< gp_XYZ > aGrCentersXYZ;
849 FindGravityCenter(anIndices, aGrCentersXYZ);
850 myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
851 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
855 //=================================================================================
856 // function : onAddGroup()
858 //=================================================================================
859 void SMESHGUI_EditMeshDlg::onAddGroup()
861 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
865 SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
867 ListCoincident->clearSelection();
868 ListCoincident->addItem(anIDs);
869 int nbGroups = ListCoincident->count();
871 ListCoincident->setCurrentRow(nbGroups-1);
872 ListCoincident->item(nbGroups-1)->setSelected(true);
875 // VSR ? this code seems to be never executed!!!
876 ListCoincident->setCurrentRow(0);
877 //ListCoincident->setSelected(0, true); // VSR: no items - no selection
883 //=================================================================================
884 // function : onRemoveGroup()
886 //=================================================================================
887 void SMESHGUI_EditMeshDlg::onRemoveGroup()
889 if (myEditCurrentArgument != (QWidget*)ListCoincident)
893 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
894 QListWidgetItem* anItem;
896 foreach(anItem, selItems)
905 //=================================================================================
906 // function : onAddElement()
908 //=================================================================================
909 void SMESHGUI_EditMeshDlg::onAddElement()
915 QString aListStr = "";
918 aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
922 QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
924 for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
925 QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
926 if ( found.count() == 0 ) {
927 QListWidgetItem* anItem = new QListWidgetItem(*it);
928 ListEdit->addItem(anItem);
929 anItem->setSelected(true);
932 QListWidgetItem* anItem;
933 foreach(anItem, found) anItem->setSelected(true);
941 //=================================================================================
942 // function : onRemoveElement()
944 //=================================================================================
945 void SMESHGUI_EditMeshDlg::onRemoveElement()
947 if (myEditCurrentArgument != (QWidget*)ListCoincident)
951 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
952 QListWidgetItem* anItem;
954 foreach(anItem, selItems)
961 //=================================================================================
962 // function : onSetFirst()
964 //=================================================================================
965 void SMESHGUI_EditMeshDlg::onSetFirst()
967 if (myEditCurrentArgument != (QWidget*)ListCoincident)
971 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
972 QListWidgetItem* anItem;
974 foreach(anItem, selItems) {
975 ListEdit->takeItem(ListEdit->row(anItem));
976 ListEdit->insertItem(0, anItem);
983 //=================================================================================
984 // function : SetEditCurrentArgument()
986 //=================================================================================
987 void SMESHGUI_EditMeshDlg::SetEditCurrentArgument()
989 QPushButton* send = (QPushButton*)sender();
991 disconnect(mySelectionMgr, 0, this, 0);
992 mySelectionMgr->clearSelected();
993 mySelectionMgr->clearFilters();
995 if (send == SelectMeshButton) {
996 myEditCurrentArgument = (QWidget*)LineEditMesh;
997 SMESH::SetPointRepresentation(false);
998 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
999 aViewWindow->SetSelectionMode(ActorSelection);
1000 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1003 myEditCurrentArgument->setFocus();
1004 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1005 SelectionIntoArgument();
1008 //=================================================================================
1009 // function : SelectionIntoArgument()
1010 // purpose : Called when selection as changed or other case
1011 //=================================================================================
1012 void SMESHGUI_EditMeshDlg::SelectionIntoArgument()
1014 if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
1015 QString aString = "";
1016 LineEditMesh->setText(aString);
1018 ListCoincident->clear();
1022 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1026 SALOME_ListIO aList;
1027 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
1029 Handle(SALOME_InteractiveObject) IO = aList.First();
1030 myMesh = SMESH::GetMeshByIO(IO);
1032 if (myMesh->_is_nil())
1035 myActor = SMESH::FindActorByEntry(IO->getEntry());
1037 myActor = SMESH::FindActorByObject(myMesh);
1041 mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1043 if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1044 !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1045 !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1046 mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1048 LineEditMesh->setText(aString);
1050 if (myAction == 0) {
1051 SMESH::SetPointRepresentation(true);
1052 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1053 aViewWindow->SetSelectionMode(NodeSelection);
1056 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1057 aViewWindow->SetSelectionMode(CellSelection);
1061 //=================================================================================
1062 // function : DeactivateActiveDialog()
1064 //=================================================================================
1065 void SMESHGUI_EditMeshDlg::DeactivateActiveDialog()
1067 if (GroupConstructors->isEnabled()) {
1068 GroupConstructors->setEnabled(false);
1069 GroupMesh->setEnabled(false);
1070 GroupCoincident->setEnabled(false);
1071 GroupEdit->setEnabled(false);
1072 GroupButtons->setEnabled(false);
1073 mySMESHGUI->ResetState();
1074 mySMESHGUI->SetActiveDialogBox(0);
1077 mySelectionMgr->clearSelected();
1078 disconnect(mySelectionMgr, 0, this, 0);
1081 //=================================================================================
1082 // function : ActivateThisDialog()
1084 //=================================================================================
1085 void SMESHGUI_EditMeshDlg::ActivateThisDialog()
1087 /* Emit a signal to deactivate the active dialog */
1088 mySMESHGUI->EmitSignalDeactivateDialog();
1089 GroupConstructors->setEnabled(true);
1090 GroupMesh->setEnabled(true);
1091 GroupCoincident->setEnabled(true);
1092 GroupEdit->setEnabled(true);
1093 GroupButtons->setEnabled(true);
1095 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1096 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1097 SelectionIntoArgument();
1100 //=================================================================================
1101 // function : enterEvent()
1103 //=================================================================================
1104 void SMESHGUI_EditMeshDlg::enterEvent(QEvent*)
1106 if (!GroupConstructors->isEnabled())
1107 ActivateThisDialog();
1110 //=================================================================================
1111 // function : closeEvent()
1113 //=================================================================================
1114 void SMESHGUI_EditMeshDlg::closeEvent(QCloseEvent*)
1116 /* same than click on cancel button */
1120 //=======================================================================
1121 //function : hideEvent
1122 //purpose : caused by ESC key
1123 //=======================================================================
1124 void SMESHGUI_EditMeshDlg::hideEvent (QHideEvent *)
1130 //=================================================================================
1131 // function : keyPressEvent()
1133 //=================================================================================
1134 void SMESHGUI_EditMeshDlg::keyPressEvent( QKeyEvent* e)
1136 QDialog::keyPressEvent( e );
1137 if ( e->isAccepted() )
1140 if ( e->key() == Qt::Key_F1 ) {