1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2005 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 // File : SMESHGUI_EditMeshDlg.cxx
23 // 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>
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
49 #include <SVTK_ViewModel.h>
50 #include <SVTK_ViewWindow.h>
51 #include <SALOME_ListIO.hxx>
54 #include <TColStd_MapOfInteger.hxx>
55 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
58 #include <SALOMEconfig.h>
59 #include CORBA_SERVER_HEADER(SMESH_Group)
60 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
63 #include <vtkUnstructuredGrid.h>
64 #include <vtkRenderer.h>
65 #include <vtkActor2D.h>
66 #include <vtkPoints.h>
67 #include <vtkDataSetMapper.h>
68 #include <vtkMaskPoints.h>
69 #include <vtkSelectVisiblePoints.h>
70 #include <vtkLabeledDataMapper.h>
71 #include <vtkTextProperty.h>
72 #include <vtkIntArray.h>
73 #include <vtkProperty2D.h>
74 #include <vtkPointData.h>
77 #include <QApplication>
81 #include <QListWidget>
82 #include <QPushButton>
83 #include <QRadioButton>
85 #include <QHBoxLayout>
86 #include <QVBoxLayout>
87 #include <QGridLayout>
89 #include <QButtonGroup>
97 { // to display in the viewer IDs of the selected elements
98 SVTK_ViewWindow* myViewWindow;
100 vtkUnstructuredGrid* myIdGrid;
101 SALOME_Actor* myIdActor;
103 vtkUnstructuredGrid* myPointsNumDataSet;
104 vtkMaskPoints* myPtsMaskPoints;
105 vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
106 vtkLabeledDataMapper* myPtsLabeledDataMapper;
107 vtkTextProperty* aPtsTextProp;
108 bool myIsPointsLabeled;
109 vtkActor2D* myPointLabels;
111 std::vector<int> myIDs;
114 TIdPreview(SVTK_ViewWindow* theViewWindow):
115 myViewWindow(theViewWindow)
117 myIdGrid = vtkUnstructuredGrid::New();
119 // Create and display actor
120 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
121 aMapper->SetInput( myIdGrid );
123 myIdActor = SALOME_Actor::New();
124 myIdActor->SetInfinitive(true);
125 myIdActor->VisibilityOff();
126 myIdActor->PickableOff();
128 myIdActor->SetMapper( aMapper );
131 myViewWindow->AddActor(myIdActor);
133 //Definition of points numbering pipeline
134 myPointsNumDataSet = vtkUnstructuredGrid::New();
136 myPtsMaskPoints = vtkMaskPoints::New();
137 myPtsMaskPoints->SetInput(myPointsNumDataSet);
138 myPtsMaskPoints->SetOnRatio(1);
140 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
141 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
142 myPtsSelectVisiblePoints->SelectInvisibleOff();
143 myPtsSelectVisiblePoints->SetTolerance(0.1);
145 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
146 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
147 myPtsLabeledDataMapper->SetLabelFormat("%g");
148 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
150 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
151 aPtsTextProp->SetFontFamilyToTimes();
152 static int aPointsFontSize = 12;
153 aPtsTextProp->SetFontSize(aPointsFontSize);
154 aPtsTextProp->SetBold(1);
155 aPtsTextProp->SetItalic(0);
156 aPtsTextProp->SetShadow(0);
157 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
158 aPtsTextProp->Delete();
160 myIsPointsLabeled = false;
162 myPointLabels = vtkActor2D::New();
163 myPointLabels->SetMapper(myPtsLabeledDataMapper);
164 myPointLabels->GetProperty()->SetColor(1,1,1);
165 myPointLabels->SetVisibility(myIsPointsLabeled);
167 AddToRender(myViewWindow->getRenderer());
170 void SetPointsData ( SMDS_Mesh* theMesh,
171 TColStd_MapOfInteger & theNodesIdMap )
173 vtkPoints* aPoints = vtkPoints::New();
174 aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
177 TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
178 for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
179 const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
180 aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
181 myIDs.push_back(idIter.Key());
184 myIdGrid->SetPoints(aPoints);
188 myIdActor->GetMapper()->Update();
191 void SetElemsData( TColStd_MapOfInteger & theElemsIdMap,
192 std::list<gp_XYZ> & aGrCentersXYZ )
194 vtkPoints* aPoints = vtkPoints::New();
195 aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
198 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
199 for( ; idIter.More(); idIter.Next() ) {
200 myIDs.push_back(idIter.Key());
204 std::list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
205 for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
207 aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
209 myIdGrid->SetPoints(aPoints);
212 myIdActor->GetMapper()->Update();
215 void AddToRender(vtkRenderer* theRenderer)
217 myIdActor->AddToRender(theRenderer);
219 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
220 theRenderer->AddActor2D(myPointLabels);
223 void RemoveFromRender(vtkRenderer* theRenderer)
225 myIdActor->RemoveFromRender(theRenderer);
227 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
228 theRenderer->RemoveActor(myPointLabels);
231 void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
233 myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
235 if ( myIsPointsLabeled ) {
236 myPointsNumDataSet->ShallowCopy(myIdGrid);
237 vtkDataSet *aDataSet = myPointsNumDataSet;
238 int aNbElem = myIDs.size();
239 vtkIntArray *anArray = vtkIntArray::New();
240 anArray->SetNumberOfValues( aNbElem );
241 for ( int i = 0; i < aNbElem; i++ )
242 anArray->SetValue( i, myIDs[i] );
243 aDataSet->GetPointData()->SetScalars( anArray );
245 myPtsMaskPoints->SetInput( aDataSet );
246 myPointLabels->SetVisibility( theIsActorVisible );
249 myPointLabels->SetVisibility( false );
255 RemoveFromRender(myViewWindow->getRenderer());
259 myViewWindow->RemoveActor(myIdActor);
262 //Deleting of points numbering pipeline
263 //---------------------------------------
264 myPointsNumDataSet->Delete();
266 //myPtsLabeledDataMapper->RemoveAllInputs(); //vtk 5.0 porting
267 myPtsLabeledDataMapper->Delete();
269 //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
270 myPtsSelectVisiblePoints->Delete();
272 //myPtsMaskPoints->UnRegisterAllOutputs(); //vtk 5.0 porting
273 myPtsMaskPoints->Delete();
275 myPointLabels->Delete();
277 // myTimeStamp->Delete();
282 static const char * IconFirst[] = {
297 //=================================================================================
298 // class : SMESHGUI_EditMeshDlg()
300 //=================================================================================
301 SMESHGUI_EditMeshDlg::SMESHGUI_EditMeshDlg (SMESHGUI* theModule,
303 : QDialog(SMESH::GetDesktop(theModule)),
304 mySMESHGUI(theModule),
305 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
309 setAttribute(Qt::WA_DeleteOnClose, true);
310 setWindowTitle(myAction == 1 ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
312 myIdPreview = new SMESH::TIdPreview(SMESH::GetViewWindow( mySMESHGUI ));
314 SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
315 QPixmap IconMergeNodes (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
316 QPixmap IconMergeElems (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_MERGE_ELEMENTS")));
317 QPixmap IconSelect (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
318 QPixmap IconAdd (aResMgr->loadPixmap("SMESH", tr("ICON_APPEND")));
319 QPixmap IconRemove (aResMgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
321 setSizeGripEnabled(true);
323 QVBoxLayout* DlgLayout = new QVBoxLayout(this);
324 DlgLayout->setSpacing(SPACING);
325 DlgLayout->setMargin(MARGIN);
327 /***************************************************************/
328 GroupConstructors = new QGroupBox(myAction == 1 ?
329 tr("SMESH_MERGE_ELEMENTS") :
330 tr("SMESH_MERGE_NODES"),
333 QButtonGroup* ButtonGroup = new QButtonGroup(this);
334 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
335 GroupConstructorsLayout->setSpacing(SPACING);
336 GroupConstructorsLayout->setMargin(MARGIN);
338 RadioButton = new QRadioButton(GroupConstructors);
339 RadioButton->setIcon(myAction == 1 ? IconMergeElems : IconMergeNodes);
340 RadioButton->setChecked(true);
341 GroupConstructorsLayout->addWidget(RadioButton);
342 ButtonGroup->addButton(RadioButton, 0);
344 /***************************************************************/
345 // Controls for mesh defining
346 GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
347 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
348 GroupMeshLayout->setSpacing(SPACING);
349 GroupMeshLayout->setMargin(MARGIN);
351 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupMesh);
352 SelectMeshButton = new QPushButton(GroupMesh);
353 SelectMeshButton->setIcon(IconSelect);
354 LineEditMesh = new QLineEdit(GroupMesh);
355 LineEditMesh->setReadOnly(true);
357 GroupMeshLayout->addWidget(TextLabelName);
358 GroupMeshLayout->addWidget(SelectMeshButton);
359 GroupMeshLayout->addWidget(LineEditMesh);
361 /***************************************************************/
362 // Controls for coincident elements detecting
363 GroupCoincident = new QGroupBox(myAction == 1 ?
364 tr("COINCIDENT_ELEMENTS") :
365 tr("COINCIDENT_NODES"),
368 QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincident);
369 GroupCoincidentLayout->setSpacing(SPACING);
370 GroupCoincidentLayout->setMargin(MARGIN);
372 if (myAction == 0) { // case merge nodes
373 TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), GroupCoincident);
374 SpinBoxTolerance = new SMESHGUI_SpinBox(GroupCoincident);
375 SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
377 GroupCoincidentLayout->addWidget(TextLabelTolerance, 0, 0);
378 GroupCoincidentLayout->addWidget(SpinBoxTolerance, 0, 1);
381 TextLabelTolerance = 0;
382 SpinBoxTolerance = 0;
385 int row = GroupCoincidentLayout->rowCount();
387 ListCoincident = new QListWidget(GroupCoincident);
388 ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
390 DetectButton = new QPushButton(tr("DETECT"), GroupCoincident);
391 AddGroupButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupCoincident);
392 RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincident);
394 SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincident);
396 GroupCoincidentLayout->addWidget(ListCoincident, row, 0, 4, 2);
397 GroupCoincidentLayout->addWidget(DetectButton, row, 2);
398 GroupCoincidentLayout->addWidget(AddGroupButton, row+2, 2);
399 GroupCoincidentLayout->addWidget(RemoveGroupButton, row+3, 2);
400 GroupCoincidentLayout->addWidget(SelectAllCB, row+4, 0, 1, 3);
401 GroupCoincidentLayout->setRowMinimumHeight(row+1, 10);
402 GroupCoincidentLayout->setRowStretch(row+1, 5);
404 /***************************************************************/
405 // Controls for editing the selected group
406 GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
407 QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
408 GroupEditLayout->setSpacing(SPACING);
409 GroupEditLayout->setMargin(MARGIN);
411 ListEdit = new QListWidget(GroupEdit);
412 //ListEdit->setRowMode(QListBox::FixedNumber);
413 //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
414 //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
415 ListEdit->setFlow( QListView::LeftToRight );
416 ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
418 AddElemButton = new QPushButton(GroupEdit);
419 AddElemButton->setIcon(IconAdd);
420 RemoveElemButton = new QPushButton(GroupEdit);
421 RemoveElemButton->setIcon(IconRemove);
422 SetFirstButton = new QPushButton(GroupEdit);
423 SetFirstButton->setIcon(QPixmap(IconFirst));
425 GroupEditLayout->addWidget(ListEdit, 0, 0, 2, 1);
426 GroupEditLayout->addWidget(AddElemButton, 0, 1);
427 GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
428 GroupEditLayout->addWidget(SetFirstButton, 1, 1, 1, 2);
430 /***************************************************************/
431 GroupButtons = new QGroupBox(this);
432 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
433 GroupButtonsLayout->setSpacing(SPACING);
434 GroupButtonsLayout->setMargin(MARGIN);
436 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
437 buttonOk->setAutoDefault(true);
438 buttonOk->setDefault(true);
439 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
440 buttonApply->setAutoDefault(true);
441 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
442 buttonCancel->setAutoDefault(true);
443 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
444 buttonHelp->setAutoDefault(true);
446 GroupButtonsLayout->addWidget(buttonOk);
447 GroupButtonsLayout->addSpacing(10);
448 GroupButtonsLayout->addWidget(buttonApply);
449 GroupButtonsLayout->addSpacing(10);
450 GroupButtonsLayout->addStretch();
451 GroupButtonsLayout->addWidget(buttonCancel);
452 GroupButtonsLayout->addWidget(buttonHelp);
454 /***************************************************************/
455 DlgLayout->addWidget(GroupConstructors);
456 DlgLayout->addWidget(GroupMesh);
457 DlgLayout->addWidget(GroupCoincident);
458 DlgLayout->addWidget(GroupEdit);
459 DlgLayout->addWidget(GroupButtons);
461 Init(); // Initialisations
464 //=================================================================================
465 // function : ~SMESHGUI_EditMeshDlg()
466 // purpose : Destroys the object and frees any allocated resources
467 //=================================================================================
468 SMESHGUI_EditMeshDlg::~SMESHGUI_EditMeshDlg()
473 //=================================================================================
476 //=================================================================================
477 void SMESHGUI_EditMeshDlg::Init()
480 SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 5);
481 SpinBoxTolerance->SetValue(1e-05);
484 RadioButton->setChecked(true);
486 myEditCurrentArgument = (QWidget*)LineEditMesh;
489 mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
491 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
493 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
496 // Costruction of the logical filter
497 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
498 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
500 QList<SUIT_SelectionFilter*> aListOfFilters;
501 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
502 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
504 myMeshOrSubMeshOrGroupFilter =
505 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
507 /* signals and slots connections */
508 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
509 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
510 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
511 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
513 connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
514 connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
515 connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
516 connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
517 connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
518 connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
519 connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
520 connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
521 connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
522 connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
524 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
525 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
526 /* to close dialog if study change */
527 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
529 SetFirstButton->setEnabled(false);
530 buttonOk->setEnabled(false);
531 buttonApply->setEnabled(false);
533 // Init Mesh field from selection
534 SelectionIntoArgument();
536 myHelpFileName = "merging_elements_page.html";
539 //=================================================================================
540 // function : FindGravityCenter()
542 //=================================================================================
543 void SMESHGUI_EditMeshDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap,
544 std::list< gp_XYZ > & theGrCentersXYZ)
549 SMDS_Mesh* aMesh = 0;
550 aMesh = myActor->GetObject()->GetMesh();
556 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
557 for( ; idIter.More(); idIter.Next() ) {
558 const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
562 gp_XYZ anXYZ(0., 0., 0.);
563 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
564 for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
565 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
566 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
568 anXYZ.Divide( nbNodes );
570 theGrCentersXYZ.push_back( anXYZ );
574 //=================================================================================
575 // function : ClickOnApply()
577 //=================================================================================
578 bool SMESHGUI_EditMeshDlg::ClickOnApply()
580 if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
584 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
586 QApplication::setOverrideCursor(Qt::WaitCursor);
588 SMESH::long_array_var anIds = new SMESH::long_array;
589 SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
591 aGroupsOfElements->length(ListCoincident->count());
594 for (int i = 0; i < ListCoincident->count(); i++) {
595 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
597 anIds->length(aListIds.count());
598 for (int i = 0; i < aListIds.count(); i++)
599 anIds[i] = aListIds[i].toInt();
601 aGroupsOfElements[anArrayNum++] = anIds.inout();
605 aMeshEditor->MergeNodes (aGroupsOfElements.inout());
607 aMeshEditor->MergeElements (aGroupsOfElements.inout());
609 QApplication::restoreOverrideCursor();
619 //=================================================================================
620 // function : ClickOnOk()
622 //=================================================================================
623 void SMESHGUI_EditMeshDlg::ClickOnOk()
629 //=================================================================================
630 // function : ClickOnCancel()
632 //=================================================================================
633 void SMESHGUI_EditMeshDlg::ClickOnCancel()
635 myIdPreview->SetPointsLabeled(false);
636 mySelectionMgr->clearFilters();
637 //mySelectionMgr->clearSelected();
638 SMESH::SetPointRepresentation(false);
639 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
640 aViewWindow->SetSelectionMode(ActorSelection);
641 disconnect(mySelectionMgr, 0, this, 0);
642 mySMESHGUI->ResetState();
646 //=================================================================================
647 // function : ClickOnHelp()
649 //=================================================================================
650 void SMESHGUI_EditMeshDlg::ClickOnHelp()
652 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
654 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
658 platform = "winapplication";
660 platform = "application";
662 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
663 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
664 arg(app->resourceMgr()->stringValue("ExternalBrowser",
666 arg(myHelpFileName));
670 //=================================================================================
671 // function : onEditGroup()
673 //=================================================================================
674 void SMESHGUI_EditMeshDlg::onEditGroup()
676 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
677 if ( selItems.count() != 1 ) {
684 for (int i = 0; i < ListEdit->count(); i++ )
685 aNewIds.append(ListEdit->item(i)->text());
687 ListCoincident->currentItem()->setText(aNewIds.join(" "));
688 ListCoincident->currentItem()->setSelected(true);
691 //=================================================================================
692 // function : updateControls()
694 //=================================================================================
695 void SMESHGUI_EditMeshDlg::updateControls()
697 if (ListEdit->count() == 0)
698 SetFirstButton->setEnabled(false);
699 bool enable = !(myMesh->_is_nil()) && ListCoincident->count();
700 buttonOk->setEnabled(enable);
701 buttonApply->setEnabled(enable);
704 //=================================================================================
705 // function : onDetect()
707 //=================================================================================
708 void SMESHGUI_EditMeshDlg::onDetect()
710 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
714 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
716 QApplication::setOverrideCursor(Qt::WaitCursor);
717 ListCoincident->clear();
720 SMESH::array_of_long_array_var aGroupsArray;
724 if(!mySubMeshOrGroup->_is_nil())
725 aMeshEditor->FindCoincidentNodesOnPart(mySubMeshOrGroup, SpinBoxTolerance->GetValue(), aGroupsArray);
727 aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aGroupsArray);
730 if(!mySubMeshOrGroup->_is_nil())
731 aMeshEditor->FindEqualElements(mySubMeshOrGroup, aGroupsArray);
733 aMeshEditor->FindEqualElements(myMesh, aGroupsArray);
737 for (int i = 0; i < aGroupsArray->length(); i++) {
738 SMESH::long_array& aGroup = aGroupsArray[i];
741 for (int j = 0; j < aGroup.length(); j++)
742 anIDs.append(QString::number(aGroup[j]));
744 ListCoincident->addItem(anIDs.join(" "));
746 QApplication::restoreOverrideCursor();
750 ListCoincident->selectAll();
754 //=================================================================================
755 // function : onSelectGroup()
757 //=================================================================================
758 void SMESHGUI_EditMeshDlg::onSelectGroup()
760 if (myIsBusy || !myActor)
762 myEditCurrentArgument = (QWidget*)ListCoincident;
766 TColStd_MapOfInteger anIndices;
767 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
768 QListWidgetItem* anItem;
769 QStringList aListIds;
773 foreach(anItem, selItems) {
774 aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
775 for (int i = 0; i < aListIds.count(); i++)
776 anIndices.Add(aListIds[i].toInt());
779 if (selItems.count() == 1) {
780 ListEdit->addItems(aListIds);
781 ListEdit->selectAll();
784 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
786 aList.Append(myActor->getIO());
787 mySelectionMgr->setSelectedObjects(aList,false);
790 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
791 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
794 std::list< gp_XYZ > aGrCentersXYZ;
795 FindGravityCenter(anIndices, aGrCentersXYZ);
796 myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
797 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
803 //=================================================================================
804 // function : onSelectAll()
806 //=================================================================================
807 void SMESHGUI_EditMeshDlg::onSelectAll (bool isToggled)
810 ListCoincident->selectAll();
812 ListCoincident->clearSelection();
815 //=================================================================================
816 // function : onSelectElementFromGroup()
818 //=================================================================================
819 void SMESHGUI_EditMeshDlg::onSelectElementFromGroup()
821 if (myIsBusy || !myActor)
824 TColStd_MapOfInteger anIndices;
825 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
826 QListWidgetItem* anItem;
828 foreach(anItem, selItems)
829 anIndices.Add(anItem->text().toInt());
831 SetFirstButton->setEnabled(selItems.count() == 1);
833 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
835 aList.Append(myActor->getIO());
836 mySelectionMgr->setSelectedObjects(aList);
839 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
840 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
843 std::list< gp_XYZ > aGrCentersXYZ;
844 FindGravityCenter(anIndices, aGrCentersXYZ);
845 myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
846 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
850 //=================================================================================
851 // function : onAddGroup()
853 //=================================================================================
854 void SMESHGUI_EditMeshDlg::onAddGroup()
856 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
860 SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
862 ListCoincident->clearSelection();
863 ListCoincident->addItem(anIDs);
864 int nbGroups = ListCoincident->count();
866 ListCoincident->setCurrentRow(nbGroups-1);
867 ListCoincident->item(nbGroups-1)->setSelected(true);
870 // VSR ? this code seems to be never executed!!!
871 ListCoincident->setCurrentRow(0);
872 //ListCoincident->setSelected(0, true); // VSR: no items - no selection
878 //=================================================================================
879 // function : onRemoveGroup()
881 //=================================================================================
882 void SMESHGUI_EditMeshDlg::onRemoveGroup()
884 if (myEditCurrentArgument != (QWidget*)ListCoincident)
888 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
889 QListWidgetItem* anItem;
891 foreach(anItem, selItems)
900 //=================================================================================
901 // function : onAddElement()
903 //=================================================================================
904 void SMESHGUI_EditMeshDlg::onAddElement()
910 QString aListStr = "";
913 aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
917 QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
919 for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
920 QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
921 if ( found.count() == 0 ) {
922 QListWidgetItem* anItem = new QListWidgetItem(*it);
923 ListEdit->addItem(anItem);
924 anItem->setSelected(true);
927 QListWidgetItem* anItem;
928 foreach(anItem, found) anItem->setSelected(true);
936 //=================================================================================
937 // function : onRemoveElement()
939 //=================================================================================
940 void SMESHGUI_EditMeshDlg::onRemoveElement()
942 if (myEditCurrentArgument != (QWidget*)ListCoincident)
946 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
947 QListWidgetItem* anItem;
949 foreach(anItem, selItems)
956 //=================================================================================
957 // function : onSetFirst()
959 //=================================================================================
960 void SMESHGUI_EditMeshDlg::onSetFirst()
962 if (myEditCurrentArgument != (QWidget*)ListCoincident)
966 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
967 QListWidgetItem* anItem;
969 foreach(anItem, selItems) {
970 ListEdit->takeItem(ListEdit->row(anItem));
971 ListEdit->insertItem(0, anItem);
978 //=================================================================================
979 // function : SetEditCurrentArgument()
981 //=================================================================================
982 void SMESHGUI_EditMeshDlg::SetEditCurrentArgument()
984 QPushButton* send = (QPushButton*)sender();
986 disconnect(mySelectionMgr, 0, this, 0);
987 mySelectionMgr->clearSelected();
988 mySelectionMgr->clearFilters();
990 if (send == SelectMeshButton) {
991 myEditCurrentArgument = (QWidget*)LineEditMesh;
992 SMESH::SetPointRepresentation(false);
993 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
994 aViewWindow->SetSelectionMode(ActorSelection);
995 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
998 myEditCurrentArgument->setFocus();
999 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1000 SelectionIntoArgument();
1003 //=================================================================================
1004 // function : SelectionIntoArgument()
1005 // purpose : Called when selection as changed or other case
1006 //=================================================================================
1007 void SMESHGUI_EditMeshDlg::SelectionIntoArgument()
1009 if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
1010 QString aString = "";
1011 LineEditMesh->setText(aString);
1013 ListCoincident->clear();
1017 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1021 SALOME_ListIO aList;
1022 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
1024 Handle(SALOME_InteractiveObject) IO = aList.First();
1025 myMesh = SMESH::GetMeshByIO(IO);
1027 if (myMesh->_is_nil())
1030 myActor = SMESH::FindActorByEntry(IO->getEntry());
1032 myActor = SMESH::FindActorByObject(myMesh);
1036 mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1038 if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1039 !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1040 !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1041 mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1043 LineEditMesh->setText(aString);
1045 if (myAction == 0) {
1046 SMESH::SetPointRepresentation(true);
1047 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1048 aViewWindow->SetSelectionMode(NodeSelection);
1051 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1052 aViewWindow->SetSelectionMode(CellSelection);
1056 //=================================================================================
1057 // function : DeactivateActiveDialog()
1059 //=================================================================================
1060 void SMESHGUI_EditMeshDlg::DeactivateActiveDialog()
1062 if (GroupConstructors->isEnabled()) {
1063 GroupConstructors->setEnabled(false);
1064 GroupMesh->setEnabled(false);
1065 GroupCoincident->setEnabled(false);
1066 GroupEdit->setEnabled(false);
1067 GroupButtons->setEnabled(false);
1068 mySMESHGUI->ResetState();
1069 mySMESHGUI->SetActiveDialogBox(0);
1073 //=================================================================================
1074 // function : ActivateThisDialog()
1076 //=================================================================================
1077 void SMESHGUI_EditMeshDlg::ActivateThisDialog()
1079 /* Emit a signal to deactivate the active dialog */
1080 mySMESHGUI->EmitSignalDeactivateDialog();
1081 GroupConstructors->setEnabled(true);
1082 GroupMesh->setEnabled(true);
1083 GroupCoincident->setEnabled(true);
1084 GroupEdit->setEnabled(true);
1085 GroupButtons->setEnabled(true);
1087 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1088 SelectionIntoArgument();
1091 //=================================================================================
1092 // function : enterEvent()
1094 //=================================================================================
1095 void SMESHGUI_EditMeshDlg::enterEvent(QEvent*)
1097 if (!GroupConstructors->isEnabled())
1098 ActivateThisDialog();
1101 //=================================================================================
1102 // function : closeEvent()
1104 //=================================================================================
1105 void SMESHGUI_EditMeshDlg::closeEvent(QCloseEvent*)
1107 /* same than click on cancel button */
1111 //=======================================================================
1112 //function : hideEvent
1113 //purpose : caused by ESC key
1114 //=======================================================================
1115 void SMESHGUI_EditMeshDlg::hideEvent (QHideEvent *)
1121 //=================================================================================
1122 // function : keyPressEvent()
1124 //=================================================================================
1125 void SMESHGUI_EditMeshDlg::keyPressEvent( QKeyEvent* e)
1127 QDialog::keyPressEvent( e );
1128 if ( e->isAccepted() )
1131 if ( e->key() == Qt::Key_F1 ) {