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 SMESH::SetPointRepresentation(false);
642 disconnect(mySelectionMgr, 0, this, 0);
643 disconnect(mySMESHGUI, 0, this, 0);
644 mySMESHGUI->ResetState();
646 mySelectionMgr->clearFilters();
647 //mySelectionMgr->clearSelected();
649 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
650 aViewWindow->SetSelectionMode(ActorSelection);
655 //=================================================================================
656 // function : ClickOnHelp()
658 //=================================================================================
659 void SMESHGUI_EditMeshDlg::ClickOnHelp()
661 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
663 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
667 platform = "winapplication";
669 platform = "application";
671 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
672 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
673 arg(app->resourceMgr()->stringValue("ExternalBrowser",
675 arg(myHelpFileName));
679 //=================================================================================
680 // function : onEditGroup()
682 //=================================================================================
683 void SMESHGUI_EditMeshDlg::onEditGroup()
685 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
686 if ( selItems.count() != 1 ) {
693 for (int i = 0; i < ListEdit->count(); i++ )
694 aNewIds.append(ListEdit->item(i)->text());
696 ListCoincident->clearSelection();
697 selItems.first()->setText(aNewIds.join(" "));
698 selItems.first()->setSelected(true);
701 //=================================================================================
702 // function : updateControls()
704 //=================================================================================
705 void SMESHGUI_EditMeshDlg::updateControls()
707 if (ListEdit->count() == 0)
708 SetFirstButton->setEnabled(false);
709 bool enable = !(myMesh->_is_nil()) && ListCoincident->count();
710 buttonOk->setEnabled(enable);
711 buttonApply->setEnabled(enable);
714 //=================================================================================
715 // function : onDetect()
717 //=================================================================================
718 void SMESHGUI_EditMeshDlg::onDetect()
720 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
724 SUIT_OverrideCursor aWaitCursor;
725 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
727 ListCoincident->clear();
730 SMESH::array_of_long_array_var aGroupsArray;
734 if(!mySubMeshOrGroup->_is_nil())
735 aMeshEditor->FindCoincidentNodesOnPart(mySubMeshOrGroup, SpinBoxTolerance->GetValue(), aGroupsArray);
737 aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aGroupsArray);
740 if(!mySubMeshOrGroup->_is_nil())
741 aMeshEditor->FindEqualElements(mySubMeshOrGroup, aGroupsArray);
743 aMeshEditor->FindEqualElements(myMesh, aGroupsArray);
747 for (int i = 0; i < aGroupsArray->length(); i++) {
748 SMESH::long_array& aGroup = aGroupsArray[i];
751 for (int j = 0; j < aGroup.length(); j++)
752 anIDs.append(QString::number(aGroup[j]));
754 ListCoincident->addItem(anIDs.join(" "));
759 ListCoincident->selectAll();
763 //=================================================================================
764 // function : onSelectGroup()
766 //=================================================================================
767 void SMESHGUI_EditMeshDlg::onSelectGroup()
769 if (myIsBusy || !myActor)
771 myEditCurrentArgument = (QWidget*)ListCoincident;
775 TColStd_MapOfInteger anIndices;
776 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
777 QListWidgetItem* anItem;
778 QStringList aListIds;
782 foreach(anItem, selItems) {
783 aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
784 for (int i = 0; i < aListIds.count(); i++)
785 anIndices.Add(aListIds[i].toInt());
788 if (selItems.count() == 1) {
789 ListEdit->addItems(aListIds);
790 ListEdit->selectAll();
793 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
795 aList.Append(myActor->getIO());
796 mySelectionMgr->setSelectedObjects(aList,false);
799 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
800 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
803 std::list< gp_XYZ > aGrCentersXYZ;
804 FindGravityCenter(anIndices, aGrCentersXYZ);
805 myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
806 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
812 //=================================================================================
813 // function : onSelectAll()
815 //=================================================================================
816 void SMESHGUI_EditMeshDlg::onSelectAll (bool isToggled)
819 ListCoincident->selectAll();
821 ListCoincident->clearSelection();
824 //=================================================================================
825 // function : onSelectElementFromGroup()
827 //=================================================================================
828 void SMESHGUI_EditMeshDlg::onSelectElementFromGroup()
830 if (myIsBusy || !myActor)
833 TColStd_MapOfInteger anIndices;
834 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
835 QListWidgetItem* anItem;
837 foreach(anItem, selItems)
838 anIndices.Add(anItem->text().toInt());
840 SetFirstButton->setEnabled(selItems.count() == 1);
842 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
844 aList.Append(myActor->getIO());
845 mySelectionMgr->setSelectedObjects(aList);
848 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
849 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
852 std::list< gp_XYZ > aGrCentersXYZ;
853 FindGravityCenter(anIndices, aGrCentersXYZ);
854 myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
855 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
859 //=================================================================================
860 // function : onAddGroup()
862 //=================================================================================
863 void SMESHGUI_EditMeshDlg::onAddGroup()
865 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
870 aNbElements = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
875 ListCoincident->clearSelection();
876 ListCoincident->addItem(anIDs);
877 int nbGroups = ListCoincident->count();
879 ListCoincident->setCurrentRow(nbGroups-1);
880 ListCoincident->item(nbGroups-1)->setSelected(true);
883 // VSR ? this code seems to be never executed!!!
884 ListCoincident->setCurrentRow(0);
885 //ListCoincident->setSelected(0, true); // VSR: no items - no selection
891 //=================================================================================
892 // function : onRemoveGroup()
894 //=================================================================================
895 void SMESHGUI_EditMeshDlg::onRemoveGroup()
897 if (myEditCurrentArgument != (QWidget*)ListCoincident)
901 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
902 QListWidgetItem* anItem;
904 foreach(anItem, selItems)
913 //=================================================================================
914 // function : onAddElement()
916 //=================================================================================
917 void SMESHGUI_EditMeshDlg::onAddElement()
923 QString aListStr = "";
926 aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
930 QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
932 for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
933 QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
934 if ( found.count() == 0 ) {
935 QListWidgetItem* anItem = new QListWidgetItem(*it);
936 ListEdit->addItem(anItem);
937 anItem->setSelected(true);
940 QListWidgetItem* anItem;
941 foreach(anItem, found) anItem->setSelected(true);
949 //=================================================================================
950 // function : onRemoveElement()
952 //=================================================================================
953 void SMESHGUI_EditMeshDlg::onRemoveElement()
955 if (myEditCurrentArgument != (QWidget*)ListCoincident)
959 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
960 QListWidgetItem* anItem;
962 foreach(anItem, selItems)
969 //=================================================================================
970 // function : onSetFirst()
972 //=================================================================================
973 void SMESHGUI_EditMeshDlg::onSetFirst()
975 if (myEditCurrentArgument != (QWidget*)ListCoincident)
979 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
980 QListWidgetItem* anItem;
982 foreach(anItem, selItems) {
983 ListEdit->takeItem(ListEdit->row(anItem));
984 ListEdit->insertItem(0, anItem);
991 //=================================================================================
992 // function : SetEditCurrentArgument()
994 //=================================================================================
995 void SMESHGUI_EditMeshDlg::SetEditCurrentArgument()
997 QPushButton* send = (QPushButton*)sender();
999 disconnect(mySelectionMgr, 0, this, 0);
1000 mySelectionMgr->clearSelected();
1001 mySelectionMgr->clearFilters();
1003 if (send == SelectMeshButton) {
1004 myEditCurrentArgument = (QWidget*)LineEditMesh;
1005 SMESH::SetPointRepresentation(false);
1006 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1007 aViewWindow->SetSelectionMode(ActorSelection);
1008 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1011 myEditCurrentArgument->setFocus();
1012 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1013 SelectionIntoArgument();
1016 //=================================================================================
1017 // function : SelectionIntoArgument()
1018 // purpose : Called when selection as changed or other case
1019 //=================================================================================
1020 void SMESHGUI_EditMeshDlg::SelectionIntoArgument()
1022 if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
1023 QString aString = "";
1024 LineEditMesh->setText(aString);
1026 ListCoincident->clear();
1030 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1034 SALOME_ListIO aList;
1035 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
1037 Handle(SALOME_InteractiveObject) IO = aList.First();
1038 myMesh = SMESH::GetMeshByIO(IO);
1040 if (myMesh->_is_nil())
1043 myActor = SMESH::FindActorByEntry(IO->getEntry());
1045 myActor = SMESH::FindActorByObject(myMesh);
1049 mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1051 if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1052 !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1053 !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1054 mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1056 LineEditMesh->setText(aString);
1058 if (myAction == 0) {
1059 SMESH::SetPointRepresentation(true);
1060 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1061 aViewWindow->SetSelectionMode(NodeSelection);
1064 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1065 aViewWindow->SetSelectionMode(CellSelection);
1069 //=================================================================================
1070 // function : DeactivateActiveDialog()
1072 //=================================================================================
1073 void SMESHGUI_EditMeshDlg::DeactivateActiveDialog()
1075 if (GroupConstructors->isEnabled()) {
1076 GroupConstructors->setEnabled(false);
1077 GroupMesh->setEnabled(false);
1078 GroupCoincident->setEnabled(false);
1079 GroupEdit->setEnabled(false);
1080 GroupButtons->setEnabled(false);
1081 mySMESHGUI->ResetState();
1082 mySMESHGUI->SetActiveDialogBox(0);
1085 mySelectionMgr->clearSelected();
1086 disconnect(mySelectionMgr, 0, this, 0);
1089 //=================================================================================
1090 // function : ActivateThisDialog()
1092 //=================================================================================
1093 void SMESHGUI_EditMeshDlg::ActivateThisDialog()
1095 /* Emit a signal to deactivate the active dialog */
1096 mySMESHGUI->EmitSignalDeactivateDialog();
1097 GroupConstructors->setEnabled(true);
1098 GroupMesh->setEnabled(true);
1099 GroupCoincident->setEnabled(true);
1100 GroupEdit->setEnabled(true);
1101 GroupButtons->setEnabled(true);
1103 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1104 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1105 SelectionIntoArgument();
1108 //=================================================================================
1109 // function : enterEvent()
1111 //=================================================================================
1112 void SMESHGUI_EditMeshDlg::enterEvent(QEvent*)
1114 if (!GroupConstructors->isEnabled())
1115 ActivateThisDialog();
1118 //=================================================================================
1119 // function : closeEvent()
1121 //=================================================================================
1122 void SMESHGUI_EditMeshDlg::closeEvent(QCloseEvent*)
1124 /* same than click on cancel button */
1128 //=======================================================================
1129 //function : hideEvent
1130 //purpose : caused by ESC key
1131 //=======================================================================
1132 void SMESHGUI_EditMeshDlg::hideEvent (QHideEvent *)
1138 //=================================================================================
1139 // function : keyPressEvent()
1141 //=================================================================================
1142 void SMESHGUI_EditMeshDlg::keyPressEvent( QKeyEvent* e)
1144 QDialog::keyPressEvent( e );
1145 if ( e->isAccepted() )
1148 if ( e->key() == Qt::Key_F1 ) {