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->setSelectionMode(QListWidget::ExtendedSelection);
417 AddElemButton = new QPushButton(GroupEdit);
418 AddElemButton->setIcon(IconAdd);
419 RemoveElemButton = new QPushButton(GroupEdit);
420 RemoveElemButton->setIcon(IconRemove);
421 SetFirstButton = new QPushButton(GroupEdit);
422 SetFirstButton->setIcon(QPixmap(IconFirst));
424 GroupEditLayout->addWidget(ListEdit, 0, 0, 2, 1);
425 GroupEditLayout->addWidget(AddElemButton, 0, 1);
426 GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
427 GroupEditLayout->addWidget(SetFirstButton, 1, 1, 1, 2);
429 /***************************************************************/
430 GroupButtons = new QGroupBox(this);
431 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
432 GroupButtonsLayout->setSpacing(SPACING);
433 GroupButtonsLayout->setMargin(MARGIN);
435 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
436 buttonOk->setAutoDefault(true);
437 buttonOk->setDefault(true);
438 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
439 buttonApply->setAutoDefault(true);
440 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
441 buttonCancel->setAutoDefault(true);
442 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
443 buttonHelp->setAutoDefault(true);
445 GroupButtonsLayout->addWidget(buttonOk);
446 GroupButtonsLayout->addSpacing(10);
447 GroupButtonsLayout->addWidget(buttonApply);
448 GroupButtonsLayout->addSpacing(10);
449 GroupButtonsLayout->addStretch();
450 GroupButtonsLayout->addWidget(buttonCancel);
451 GroupButtonsLayout->addWidget(buttonHelp);
453 /***************************************************************/
454 DlgLayout->addWidget(GroupConstructors);
455 DlgLayout->addWidget(GroupMesh);
456 DlgLayout->addWidget(GroupCoincident);
457 DlgLayout->addWidget(GroupEdit);
458 DlgLayout->addWidget(GroupButtons);
460 Init(); // Initialisations
463 //=================================================================================
464 // function : ~SMESHGUI_EditMeshDlg()
465 // purpose : Destroys the object and frees any allocated resources
466 //=================================================================================
467 SMESHGUI_EditMeshDlg::~SMESHGUI_EditMeshDlg()
472 //=================================================================================
475 //=================================================================================
476 void SMESHGUI_EditMeshDlg::Init()
479 SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 3);
480 SpinBoxTolerance->SetValue(1e-05);
483 RadioButton->setChecked(true);
485 myEditCurrentArgument = (QWidget*)LineEditMesh;
488 mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
490 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
492 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
495 // Costruction of the logical filter
496 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
497 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
499 QList<SUIT_SelectionFilter*> aListOfFilters;
500 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
501 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
503 myMeshOrSubMeshOrGroupFilter =
504 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
506 /* signals and slots connections */
507 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
508 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
509 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
510 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
512 connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
513 connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
514 connect(ListCoincident, SIGNAL (selectionChanged()), this, SLOT(onSelectGroup()));
515 connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
516 connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
517 connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
518 connect(ListEdit, SIGNAL (selectionChanged()), this, SLOT(onSelectElementFromGroup()));
519 connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
520 connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
521 connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
523 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
524 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
525 /* to close dialog if study change */
526 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
528 SetFirstButton->setEnabled(false);
529 buttonOk->setEnabled(false);
530 buttonApply->setEnabled(false);
532 // Init Mesh field from selection
533 SelectionIntoArgument();
535 myHelpFileName = "merging_elements_page.html";
538 //=================================================================================
539 // function : FindGravityCenter()
541 //=================================================================================
542 void SMESHGUI_EditMeshDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap,
543 std::list< gp_XYZ > & theGrCentersXYZ)
548 SMDS_Mesh* aMesh = 0;
549 aMesh = myActor->GetObject()->GetMesh();
555 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
556 for( ; idIter.More(); idIter.Next() ) {
557 const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
561 gp_XYZ anXYZ(0., 0., 0.);
562 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
563 for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
564 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
565 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
567 anXYZ.Divide( nbNodes );
569 theGrCentersXYZ.push_back( anXYZ );
573 //=================================================================================
574 // function : ClickOnApply()
576 //=================================================================================
577 bool SMESHGUI_EditMeshDlg::ClickOnApply()
579 if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
583 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
585 QApplication::setOverrideCursor(Qt::WaitCursor);
587 SMESH::long_array_var anIds = new SMESH::long_array;
588 SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
590 aGroupsOfElements->length(ListCoincident->count());
593 for (int i = 0; i < ListCoincident->count(); i++) {
594 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
596 anIds->length(aListIds.count());
597 for (int i = 0; i < aListIds.count(); i++)
598 anIds[i] = aListIds[i].toInt();
600 aGroupsOfElements[anArrayNum++] = anIds.inout();
604 aMeshEditor->MergeNodes (aGroupsOfElements.inout());
606 aMeshEditor->MergeElements (aGroupsOfElements.inout());
608 QApplication::restoreOverrideCursor();
618 //=================================================================================
619 // function : ClickOnOk()
621 //=================================================================================
622 void SMESHGUI_EditMeshDlg::ClickOnOk()
628 //=================================================================================
629 // function : ClickOnCancel()
631 //=================================================================================
632 void SMESHGUI_EditMeshDlg::ClickOnCancel()
634 myIdPreview->SetPointsLabeled(false);
635 mySelectionMgr->clearFilters();
636 //mySelectionMgr->clearSelected();
637 SMESH::SetPointRepresentation(false);
638 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
639 aViewWindow->SetSelectionMode(ActorSelection);
640 disconnect(mySelectionMgr, 0, this, 0);
641 mySMESHGUI->ResetState();
645 //=================================================================================
646 // function : ClickOnHelp()
648 //=================================================================================
649 void SMESHGUI_EditMeshDlg::ClickOnHelp()
651 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
653 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
657 platform = "winapplication";
659 platform = "application";
661 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
662 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
663 arg(app->resourceMgr()->stringValue("ExternalBrowser",
665 arg(myHelpFileName));
669 //=================================================================================
670 // function : onEditGroup()
672 //=================================================================================
673 void SMESHGUI_EditMeshDlg::onEditGroup()
675 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
676 if ( selItems.count() != 1 ) {
683 for (int i = 0; i < ListEdit->count(); i++ )
684 aNewIds.append(ListEdit->item(i)->text());
686 ListCoincident->currentItem()->setText(aNewIds.join(" "));
687 ListCoincident->currentItem()->setSelected(true);
690 //=================================================================================
691 // function : updateControls()
693 //=================================================================================
694 void SMESHGUI_EditMeshDlg::updateControls()
696 if (ListEdit->count() == 0)
697 SetFirstButton->setEnabled(false);
698 bool enable = !(myMesh->_is_nil()) && ListCoincident->count();
699 buttonOk->setEnabled(enable);
700 buttonApply->setEnabled(enable);
703 //=================================================================================
704 // function : onDetect()
706 //=================================================================================
707 void SMESHGUI_EditMeshDlg::onDetect()
709 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
713 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
715 QApplication::setOverrideCursor(Qt::WaitCursor);
716 ListCoincident->clear();
719 SMESH::array_of_long_array_var aGroupsArray;
723 if(!mySubMeshOrGroup->_is_nil())
724 aMeshEditor->FindCoincidentNodesOnPart(mySubMeshOrGroup, SpinBoxTolerance->GetValue(), aGroupsArray);
726 aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aGroupsArray);
729 if(!mySubMeshOrGroup->_is_nil())
730 aMeshEditor->FindEqualElements(mySubMeshOrGroup, aGroupsArray);
732 aMeshEditor->FindEqualElements(myMesh, aGroupsArray);
736 for (int i = 0; i < aGroupsArray->length(); i++) {
737 SMESH::long_array& aGroup = aGroupsArray[i];
740 for (int j = 0; j < aGroup.length(); j++)
741 anIDs.append(QString::number(aGroup[j]));
743 ListCoincident->addItem(anIDs.join(" "));
745 QApplication::restoreOverrideCursor();
749 ListCoincident->selectAll();
753 //=================================================================================
754 // function : onSelectGroup()
756 //=================================================================================
757 void SMESHGUI_EditMeshDlg::onSelectGroup()
759 if (myIsBusy || !myActor)
761 myEditCurrentArgument = (QWidget*)ListCoincident;
765 TColStd_MapOfInteger anIndices;
766 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
767 QListWidgetItem* anItem;
768 QStringList aListIds;
772 foreach(anItem, selItems) {
773 aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
774 for (int i = 0; i < aListIds.count(); i++)
775 anIndices.Add(aListIds[i].toInt());
778 if (selItems.count() == 1) {
779 ListEdit->addItems(aListIds);
780 ListEdit->selectAll();
783 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
785 aList.Append(myActor->getIO());
786 mySelectionMgr->setSelectedObjects(aList,false);
789 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
790 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
793 std::list< gp_XYZ > aGrCentersXYZ;
794 FindGravityCenter(anIndices, aGrCentersXYZ);
795 myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
796 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
802 //=================================================================================
803 // function : onSelectAll()
805 //=================================================================================
806 void SMESHGUI_EditMeshDlg::onSelectAll (bool isToggled)
809 ListCoincident->selectAll();
811 ListCoincident->clearSelection();
814 //=================================================================================
815 // function : onSelectElementFromGroup()
817 //=================================================================================
818 void SMESHGUI_EditMeshDlg::onSelectElementFromGroup()
820 if (myIsBusy || !myActor)
823 TColStd_MapOfInteger anIndices;
824 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
825 QListWidgetItem* anItem;
827 foreach(anItem, selItems)
828 anIndices.Add(anItem->text().toInt());
830 SetFirstButton->setEnabled(selItems.count() == 1);
832 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
834 aList.Append(myActor->getIO());
835 mySelectionMgr->setSelectedObjects(aList);
838 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
839 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
842 std::list< gp_XYZ > aGrCentersXYZ;
843 FindGravityCenter(anIndices, aGrCentersXYZ);
844 myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
845 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
849 //=================================================================================
850 // function : onAddGroup()
852 //=================================================================================
853 void SMESHGUI_EditMeshDlg::onAddGroup()
855 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
859 SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
861 ListCoincident->clearSelection();
862 ListCoincident->addItem(anIDs);
863 int nbGroups = ListCoincident->count();
865 ListCoincident->setCurrentRow(nbGroups-1);
866 ListCoincident->item(nbGroups-1)->setSelected(true);
869 // VSR ? this code seems to be never executed!!!
870 ListCoincident->setCurrentRow(0);
871 //ListCoincident->setSelected(0, true); // VSR: no items - no selection
877 //=================================================================================
878 // function : onRemoveGroup()
880 //=================================================================================
881 void SMESHGUI_EditMeshDlg::onRemoveGroup()
883 if (myEditCurrentArgument != (QWidget*)ListCoincident)
887 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
888 QListWidgetItem* anItem;
890 foreach(anItem, selItems)
899 //=================================================================================
900 // function : onAddElement()
902 //=================================================================================
903 void SMESHGUI_EditMeshDlg::onAddElement()
909 QString aListStr = "";
912 aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
916 QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
918 for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
919 QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
920 if ( found.count() == 0 ) {
921 QListWidgetItem* anItem = new QListWidgetItem(*it);
922 ListEdit->addItem(anItem);
923 anItem->setSelected(true);
926 QListWidgetItem* anItem;
927 foreach(anItem, found) anItem->setSelected(true);
935 //=================================================================================
936 // function : onRemoveElement()
938 //=================================================================================
939 void SMESHGUI_EditMeshDlg::onRemoveElement()
941 if (myEditCurrentArgument != (QWidget*)ListCoincident)
945 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
946 QListWidgetItem* anItem;
948 foreach(anItem, selItems)
955 //=================================================================================
956 // function : onSetFirst()
958 //=================================================================================
959 void SMESHGUI_EditMeshDlg::onSetFirst()
961 if (myEditCurrentArgument != (QWidget*)ListCoincident)
965 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
966 QListWidgetItem* anItem;
968 foreach(anItem, selItems) {
969 ListEdit->takeItem(ListEdit->row(anItem));
970 ListEdit->insertItem(0, anItem);
977 //=================================================================================
978 // function : SetEditCurrentArgument()
980 //=================================================================================
981 void SMESHGUI_EditMeshDlg::SetEditCurrentArgument()
983 QPushButton* send = (QPushButton*)sender();
985 disconnect(mySelectionMgr, 0, this, 0);
986 mySelectionMgr->clearSelected();
987 mySelectionMgr->clearFilters();
989 if (send == SelectMeshButton) {
990 myEditCurrentArgument = (QWidget*)LineEditMesh;
991 SMESH::SetPointRepresentation(false);
992 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
993 aViewWindow->SetSelectionMode(ActorSelection);
994 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
997 myEditCurrentArgument->setFocus();
998 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
999 SelectionIntoArgument();
1002 //=================================================================================
1003 // function : SelectionIntoArgument()
1004 // purpose : Called when selection as changed or other case
1005 //=================================================================================
1006 void SMESHGUI_EditMeshDlg::SelectionIntoArgument()
1008 if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
1009 QString aString = "";
1010 LineEditMesh->setText(aString);
1012 ListCoincident->clear();
1016 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1020 SALOME_ListIO aList;
1021 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
1023 Handle(SALOME_InteractiveObject) IO = aList.First();
1024 myMesh = SMESH::GetMeshByIO(IO);
1026 if (myMesh->_is_nil())
1029 myActor = SMESH::FindActorByEntry(IO->getEntry());
1031 myActor = SMESH::FindActorByObject(myMesh);
1035 mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1037 if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1038 !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1039 !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1040 mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1042 LineEditMesh->setText(aString);
1044 if (myAction == 0) {
1045 SMESH::SetPointRepresentation(true);
1046 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1047 aViewWindow->SetSelectionMode(NodeSelection);
1050 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1051 aViewWindow->SetSelectionMode(CellSelection);
1055 //=================================================================================
1056 // function : DeactivateActiveDialog()
1058 //=================================================================================
1059 void SMESHGUI_EditMeshDlg::DeactivateActiveDialog()
1061 if (GroupConstructors->isEnabled()) {
1062 GroupConstructors->setEnabled(false);
1063 GroupMesh->setEnabled(false);
1064 GroupCoincident->setEnabled(false);
1065 GroupEdit->setEnabled(false);
1066 GroupButtons->setEnabled(false);
1067 mySMESHGUI->ResetState();
1068 mySMESHGUI->SetActiveDialogBox(0);
1072 //=================================================================================
1073 // function : ActivateThisDialog()
1075 //=================================================================================
1076 void SMESHGUI_EditMeshDlg::ActivateThisDialog()
1078 /* Emit a signal to deactivate the active dialog */
1079 mySMESHGUI->EmitSignalDeactivateDialog();
1080 GroupConstructors->setEnabled(true);
1081 GroupMesh->setEnabled(true);
1082 GroupCoincident->setEnabled(true);
1083 GroupEdit->setEnabled(true);
1084 GroupButtons->setEnabled(true);
1086 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1087 SelectionIntoArgument();
1090 //=================================================================================
1091 // function : enterEvent()
1093 //=================================================================================
1094 void SMESHGUI_EditMeshDlg::enterEvent(QEvent*)
1096 if (!GroupConstructors->isEnabled())
1097 ActivateThisDialog();
1100 //=================================================================================
1101 // function : closeEvent()
1103 //=================================================================================
1104 void SMESHGUI_EditMeshDlg::closeEvent(QCloseEvent*)
1106 /* same than click on cancel button */
1110 //=======================================================================
1111 //function : hideEvent
1112 //purpose : caused by ESC key
1113 //=======================================================================
1114 void SMESHGUI_EditMeshDlg::hideEvent (QHideEvent *)
1120 //=================================================================================
1121 // function : keyPressEvent()
1123 //=================================================================================
1124 void SMESHGUI_EditMeshDlg::keyPressEvent( QKeyEvent* e)
1126 QDialog::keyPressEvent( e );
1127 if ( e->isAccepted() )
1130 if ( e->key() == Qt::Key_F1 ) {