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>
78 #include <QApplication>
82 #include <QListWidget>
83 #include <QPushButton>
84 #include <QRadioButton>
86 #include <QHBoxLayout>
87 #include <QVBoxLayout>
88 #include <QGridLayout>
90 #include <QButtonGroup>
98 { // to display in the viewer IDs of the selected elements
99 SVTK_ViewWindow* myViewWindow;
101 vtkUnstructuredGrid* myIdGrid;
102 SALOME_Actor* myIdActor;
104 vtkUnstructuredGrid* myPointsNumDataSet;
105 vtkMaskPoints* myPtsMaskPoints;
106 vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
107 vtkLabeledDataMapper* myPtsLabeledDataMapper;
108 vtkTextProperty* aPtsTextProp;
109 bool myIsPointsLabeled;
110 vtkActor2D* myPointLabels;
112 std::vector<int> myIDs;
115 TIdPreview(SVTK_ViewWindow* theViewWindow):
116 myViewWindow(theViewWindow)
118 myIdGrid = vtkUnstructuredGrid::New();
120 // Create and display actor
121 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
122 aMapper->SetInput( myIdGrid );
124 myIdActor = SALOME_Actor::New();
125 myIdActor->SetInfinitive(true);
126 myIdActor->VisibilityOff();
127 myIdActor->PickableOff();
129 myIdActor->SetMapper( aMapper );
132 myViewWindow->AddActor(myIdActor);
134 //Definition of points numbering pipeline
135 myPointsNumDataSet = vtkUnstructuredGrid::New();
137 myPtsMaskPoints = vtkMaskPoints::New();
138 myPtsMaskPoints->SetInput(myPointsNumDataSet);
139 myPtsMaskPoints->SetOnRatio(1);
141 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
142 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
143 myPtsSelectVisiblePoints->SelectInvisibleOff();
144 myPtsSelectVisiblePoints->SetTolerance(0.1);
146 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
147 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
148 myPtsLabeledDataMapper->SetLabelFormat("%g");
149 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
151 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
152 aPtsTextProp->SetFontFamilyToTimes();
153 static int aPointsFontSize = 12;
154 aPtsTextProp->SetFontSize(aPointsFontSize);
155 aPtsTextProp->SetBold(1);
156 aPtsTextProp->SetItalic(0);
157 aPtsTextProp->SetShadow(0);
158 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
159 aPtsTextProp->Delete();
161 myIsPointsLabeled = false;
163 myPointLabels = vtkActor2D::New();
164 myPointLabels->SetMapper(myPtsLabeledDataMapper);
165 myPointLabels->GetProperty()->SetColor(1,1,1);
166 myPointLabels->SetVisibility(myIsPointsLabeled);
168 AddToRender(myViewWindow->getRenderer());
171 void SetPointsData ( SMDS_Mesh* theMesh,
172 TColStd_MapOfInteger & theNodesIdMap )
174 vtkPoints* aPoints = vtkPoints::New();
175 aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
178 TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
179 for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
180 const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
181 aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
182 myIDs.push_back(idIter.Key());
185 myIdGrid->SetPoints(aPoints);
189 myIdActor->GetMapper()->Update();
192 void SetElemsData( TColStd_MapOfInteger & theElemsIdMap,
193 std::list<gp_XYZ> & aGrCentersXYZ )
195 vtkPoints* aPoints = vtkPoints::New();
196 aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
199 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
200 for( ; idIter.More(); idIter.Next() ) {
201 myIDs.push_back(idIter.Key());
205 std::list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
206 for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
208 aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
210 myIdGrid->SetPoints(aPoints);
213 myIdActor->GetMapper()->Update();
216 void AddToRender(vtkRenderer* theRenderer)
218 myIdActor->AddToRender(theRenderer);
220 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
221 theRenderer->AddActor2D(myPointLabels);
224 void RemoveFromRender(vtkRenderer* theRenderer)
226 myIdActor->RemoveFromRender(theRenderer);
228 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
229 theRenderer->RemoveActor(myPointLabels);
232 void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
234 myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
236 if ( myIsPointsLabeled ) {
237 myPointsNumDataSet->ShallowCopy(myIdGrid);
238 vtkDataSet *aDataSet = myPointsNumDataSet;
239 int aNbElem = myIDs.size();
240 vtkIntArray *anArray = vtkIntArray::New();
241 anArray->SetNumberOfValues( aNbElem );
242 for ( int i = 0; i < aNbElem; i++ )
243 anArray->SetValue( i, myIDs[i] );
244 aDataSet->GetPointData()->SetScalars( anArray );
246 myPtsMaskPoints->SetInput( aDataSet );
247 myPointLabels->SetVisibility( theIsActorVisible );
250 myPointLabels->SetVisibility( false );
256 RemoveFromRender(myViewWindow->getRenderer());
260 myViewWindow->RemoveActor(myIdActor);
263 //Deleting of points numbering pipeline
264 //---------------------------------------
265 myPointsNumDataSet->Delete();
267 //myPtsLabeledDataMapper->RemoveAllInputs(); //vtk 5.0 porting
268 myPtsLabeledDataMapper->Delete();
270 //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
271 myPtsSelectVisiblePoints->Delete();
273 //myPtsMaskPoints->UnRegisterAllOutputs(); //vtk 5.0 porting
274 myPtsMaskPoints->Delete();
276 myPointLabels->Delete();
278 // myTimeStamp->Delete();
283 static const char * IconFirst[] = {
298 //=================================================================================
299 // class : SMESHGUI_EditMeshDlg()
301 //=================================================================================
302 SMESHGUI_EditMeshDlg::SMESHGUI_EditMeshDlg (SMESHGUI* theModule,
304 : QDialog(SMESH::GetDesktop(theModule)),
305 mySMESHGUI(theModule),
306 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
310 setAttribute(Qt::WA_DeleteOnClose, true);
311 setWindowTitle(myAction == 1 ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
313 myIdPreview = new SMESH::TIdPreview(SMESH::GetViewWindow( mySMESHGUI ));
315 SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
316 QPixmap IconMergeNodes (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
317 QPixmap IconMergeElems (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_MERGE_ELEMENTS")));
318 QPixmap IconSelect (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
319 QPixmap IconAdd (aResMgr->loadPixmap("SMESH", tr("ICON_APPEND")));
320 QPixmap IconRemove (aResMgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
322 setSizeGripEnabled(true);
324 QVBoxLayout* DlgLayout = new QVBoxLayout(this);
325 DlgLayout->setSpacing(SPACING);
326 DlgLayout->setMargin(MARGIN);
328 /***************************************************************/
329 GroupConstructors = new QGroupBox(myAction == 1 ?
330 tr("SMESH_MERGE_ELEMENTS") :
331 tr("SMESH_MERGE_NODES"),
334 QButtonGroup* ButtonGroup = new QButtonGroup(this);
335 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
336 GroupConstructorsLayout->setSpacing(SPACING);
337 GroupConstructorsLayout->setMargin(MARGIN);
339 RadioButton = new QRadioButton(GroupConstructors);
340 RadioButton->setIcon(myAction == 1 ? IconMergeElems : IconMergeNodes);
341 RadioButton->setChecked(true);
342 GroupConstructorsLayout->addWidget(RadioButton);
343 ButtonGroup->addButton(RadioButton, 0);
345 /***************************************************************/
346 // Controls for mesh defining
347 GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
348 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
349 GroupMeshLayout->setSpacing(SPACING);
350 GroupMeshLayout->setMargin(MARGIN);
352 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupMesh);
353 SelectMeshButton = new QPushButton(GroupMesh);
354 SelectMeshButton->setIcon(IconSelect);
355 LineEditMesh = new QLineEdit(GroupMesh);
356 LineEditMesh->setReadOnly(true);
358 GroupMeshLayout->addWidget(TextLabelName);
359 GroupMeshLayout->addWidget(SelectMeshButton);
360 GroupMeshLayout->addWidget(LineEditMesh);
362 /***************************************************************/
363 // Controls for coincident elements detecting
364 GroupCoincident = new QGroupBox(myAction == 1 ?
365 tr("COINCIDENT_ELEMENTS") :
366 tr("COINCIDENT_NODES"),
369 QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincident);
370 GroupCoincidentLayout->setSpacing(SPACING);
371 GroupCoincidentLayout->setMargin(MARGIN);
373 if (myAction == 0) { // case merge nodes
374 TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), GroupCoincident);
375 SpinBoxTolerance = new SMESHGUI_SpinBox(GroupCoincident);
376 SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
378 GroupCoincidentLayout->addWidget(TextLabelTolerance, 0, 0);
379 GroupCoincidentLayout->addWidget(SpinBoxTolerance, 0, 1);
382 TextLabelTolerance = 0;
383 SpinBoxTolerance = 0;
386 int row = GroupCoincidentLayout->rowCount();
388 ListCoincident = new QListWidget(GroupCoincident);
389 ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
391 DetectButton = new QPushButton(tr("DETECT"), GroupCoincident);
392 AddGroupButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupCoincident);
393 RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincident);
395 SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincident);
397 GroupCoincidentLayout->addWidget(ListCoincident, row, 0, 4, 2);
398 GroupCoincidentLayout->addWidget(DetectButton, row, 2);
399 GroupCoincidentLayout->addWidget(AddGroupButton, row+2, 2);
400 GroupCoincidentLayout->addWidget(RemoveGroupButton, row+3, 2);
401 GroupCoincidentLayout->addWidget(SelectAllCB, row+4, 0, 1, 3);
402 GroupCoincidentLayout->setRowMinimumHeight(row+1, 10);
403 GroupCoincidentLayout->setRowStretch(row+1, 5);
405 /***************************************************************/
406 // Controls for editing the selected group
407 GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
408 QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
409 GroupEditLayout->setSpacing(SPACING);
410 GroupEditLayout->setMargin(MARGIN);
412 ListEdit = new QListWidget(GroupEdit);
413 //ListEdit->setRowMode(QListBox::FixedNumber);
414 //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
415 //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
416 ListEdit->setFlow( QListView::LeftToRight );
417 ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
419 AddElemButton = new QPushButton(GroupEdit);
420 AddElemButton->setIcon(IconAdd);
421 RemoveElemButton = new QPushButton(GroupEdit);
422 RemoveElemButton->setIcon(IconRemove);
423 SetFirstButton = new QPushButton(GroupEdit);
424 SetFirstButton->setIcon(QPixmap(IconFirst));
426 GroupEditLayout->addWidget(ListEdit, 0, 0, 2, 1);
427 GroupEditLayout->addWidget(AddElemButton, 0, 1);
428 GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
429 GroupEditLayout->addWidget(SetFirstButton, 1, 1, 1, 2);
431 /***************************************************************/
432 GroupButtons = new QGroupBox(this);
433 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
434 GroupButtonsLayout->setSpacing(SPACING);
435 GroupButtonsLayout->setMargin(MARGIN);
437 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
438 buttonOk->setAutoDefault(true);
439 buttonOk->setDefault(true);
440 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
441 buttonApply->setAutoDefault(true);
442 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
443 buttonCancel->setAutoDefault(true);
444 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
445 buttonHelp->setAutoDefault(true);
447 GroupButtonsLayout->addWidget(buttonOk);
448 GroupButtonsLayout->addSpacing(10);
449 GroupButtonsLayout->addWidget(buttonApply);
450 GroupButtonsLayout->addSpacing(10);
451 GroupButtonsLayout->addStretch();
452 GroupButtonsLayout->addWidget(buttonCancel);
453 GroupButtonsLayout->addWidget(buttonHelp);
455 /***************************************************************/
456 DlgLayout->addWidget(GroupConstructors);
457 DlgLayout->addWidget(GroupMesh);
458 DlgLayout->addWidget(GroupCoincident);
459 DlgLayout->addWidget(GroupEdit);
460 DlgLayout->addWidget(GroupButtons);
462 Init(); // Initialisations
465 //=================================================================================
466 // function : ~SMESHGUI_EditMeshDlg()
467 // purpose : Destroys the object and frees any allocated resources
468 //=================================================================================
469 SMESHGUI_EditMeshDlg::~SMESHGUI_EditMeshDlg()
474 //=================================================================================
477 //=================================================================================
478 void SMESHGUI_EditMeshDlg::Init()
481 SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, 5);
482 SpinBoxTolerance->SetValue(1e-05);
485 RadioButton->setChecked(true);
487 myEditCurrentArgument = (QWidget*)LineEditMesh;
490 mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
492 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
494 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
497 // Costruction of the logical filter
498 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
499 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
501 QList<SUIT_SelectionFilter*> aListOfFilters;
502 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
503 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
505 myMeshOrSubMeshOrGroupFilter =
506 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
508 /* signals and slots connections */
509 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
510 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
511 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
512 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
514 connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
515 connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
516 connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
517 connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
518 connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
519 connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
520 connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
521 connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
522 connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
523 connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
525 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
526 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
527 /* to close dialog if study change */
528 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
530 SetFirstButton->setEnabled(false);
531 buttonOk->setEnabled(false);
532 buttonApply->setEnabled(false);
534 // Init Mesh field from selection
535 SelectionIntoArgument();
537 myHelpFileName = "merging_elements_page.html";
540 //=================================================================================
541 // function : FindGravityCenter()
543 //=================================================================================
544 void SMESHGUI_EditMeshDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap,
545 std::list< gp_XYZ > & theGrCentersXYZ)
550 SMDS_Mesh* aMesh = 0;
551 aMesh = myActor->GetObject()->GetMesh();
557 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
558 for( ; idIter.More(); idIter.Next() ) {
559 const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
563 gp_XYZ anXYZ(0., 0., 0.);
564 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
565 for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
566 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
567 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
569 anXYZ.Divide( nbNodes );
571 theGrCentersXYZ.push_back( anXYZ );
575 //=================================================================================
576 // function : ClickOnApply()
578 //=================================================================================
579 bool SMESHGUI_EditMeshDlg::ClickOnApply()
581 if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
585 SUIT_OverrideCursor aWaitCursor;
586 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
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());
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->clearSelection();
687 selItems.first()->setText(aNewIds.join(" "));
688 selItems.first()->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 SUIT_OverrideCursor aWaitCursor;
715 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
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(" "));
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);
1071 mySelectionMgr->clearSelected();
1072 disconnect(mySelectionMgr, 0, this, 0);
1075 //=================================================================================
1076 // function : ActivateThisDialog()
1078 //=================================================================================
1079 void SMESHGUI_EditMeshDlg::ActivateThisDialog()
1081 /* Emit a signal to deactivate the active dialog */
1082 mySMESHGUI->EmitSignalDeactivateDialog();
1083 GroupConstructors->setEnabled(true);
1084 GroupMesh->setEnabled(true);
1085 GroupCoincident->setEnabled(true);
1086 GroupEdit->setEnabled(true);
1087 GroupButtons->setEnabled(true);
1089 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1090 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1091 SelectionIntoArgument();
1094 //=================================================================================
1095 // function : enterEvent()
1097 //=================================================================================
1098 void SMESHGUI_EditMeshDlg::enterEvent(QEvent*)
1100 if (!GroupConstructors->isEnabled())
1101 ActivateThisDialog();
1104 //=================================================================================
1105 // function : closeEvent()
1107 //=================================================================================
1108 void SMESHGUI_EditMeshDlg::closeEvent(QCloseEvent*)
1110 /* same than click on cancel button */
1114 //=======================================================================
1115 //function : hideEvent
1116 //purpose : caused by ESC key
1117 //=======================================================================
1118 void SMESHGUI_EditMeshDlg::hideEvent (QHideEvent *)
1124 //=================================================================================
1125 // function : keyPressEvent()
1127 //=================================================================================
1128 void SMESHGUI_EditMeshDlg::keyPressEvent( QKeyEvent* e)
1130 QDialog::keyPressEvent( e );
1131 if ( e->isAccepted() )
1134 if ( e->key() == Qt::Key_F1 ) {