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>
96 { // to display in the viewer IDs of the selected elements
97 SVTK_ViewWindow* myViewWindow;
99 vtkUnstructuredGrid* myIdGrid;
100 SALOME_Actor* myIdActor;
102 vtkUnstructuredGrid* myPointsNumDataSet;
103 vtkMaskPoints* myPtsMaskPoints;
104 vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
105 vtkLabeledDataMapper* myPtsLabeledDataMapper;
106 vtkTextProperty* aPtsTextProp;
107 bool myIsPointsLabeled;
108 vtkActor2D* myPointLabels;
113 TIdPreview(SVTK_ViewWindow* theViewWindow):
114 myViewWindow(theViewWindow)
116 myIdGrid = vtkUnstructuredGrid::New();
118 // Create and display actor
119 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
120 aMapper->SetInput( myIdGrid );
122 myIdActor = SALOME_Actor::New();
123 myIdActor->SetInfinitive(true);
124 myIdActor->VisibilityOff();
125 myIdActor->PickableOff();
127 myIdActor->SetMapper( aMapper );
130 myViewWindow->AddActor(myIdActor);
132 //Definition of points numbering pipeline
133 myPointsNumDataSet = vtkUnstructuredGrid::New();
135 myPtsMaskPoints = vtkMaskPoints::New();
136 myPtsMaskPoints->SetInput(myPointsNumDataSet);
137 myPtsMaskPoints->SetOnRatio(1);
139 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
140 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
141 myPtsSelectVisiblePoints->SelectInvisibleOff();
142 myPtsSelectVisiblePoints->SetTolerance(0.1);
144 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
145 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
146 myPtsLabeledDataMapper->SetLabelFormat("%g");
147 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
149 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
150 aPtsTextProp->SetFontFamilyToTimes();
151 static int aPointsFontSize = 12;
152 aPtsTextProp->SetFontSize(aPointsFontSize);
153 aPtsTextProp->SetBold(1);
154 aPtsTextProp->SetItalic(0);
155 aPtsTextProp->SetShadow(0);
156 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
157 aPtsTextProp->Delete();
159 myIsPointsLabeled = false;
161 myPointLabels = vtkActor2D::New();
162 myPointLabels->SetMapper(myPtsLabeledDataMapper);
163 myPointLabels->GetProperty()->SetColor(1,1,1);
164 myPointLabels->SetVisibility(myIsPointsLabeled);
166 AddToRender(myViewWindow->getRenderer());
169 void SetPointsData ( SMDS_Mesh* theMesh,
170 TColStd_MapOfInteger & theNodesIdMap )
172 vtkPoints* aPoints = vtkPoints::New();
173 aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
176 TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
177 for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
178 const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
179 aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
180 myIDs.push_back(idIter.Key());
183 myIdGrid->SetPoints(aPoints);
187 myIdActor->GetMapper()->Update();
190 void SetElemsData( TColStd_MapOfInteger & theElemsIdMap,
191 list<gp_XYZ> & aGrCentersXYZ )
193 vtkPoints* aPoints = vtkPoints::New();
194 aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
197 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
198 for( ; idIter.More(); idIter.Next() ) {
199 myIDs.push_back(idIter.Key());
203 list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
204 for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
206 aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
208 myIdGrid->SetPoints(aPoints);
211 myIdActor->GetMapper()->Update();
214 void AddToRender(vtkRenderer* theRenderer)
216 myIdActor->AddToRender(theRenderer);
218 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
219 theRenderer->AddActor2D(myPointLabels);
222 void RemoveFromRender(vtkRenderer* theRenderer)
224 myIdActor->RemoveFromRender(theRenderer);
226 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
227 theRenderer->RemoveActor(myPointLabels);
230 void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
232 myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
234 if ( myIsPointsLabeled ) {
235 myPointsNumDataSet->ShallowCopy(myIdGrid);
236 vtkDataSet *aDataSet = myPointsNumDataSet;
237 int aNbElem = myIDs.size();
238 vtkIntArray *anArray = vtkIntArray::New();
239 anArray->SetNumberOfValues( aNbElem );
240 for ( int i = 0; i < aNbElem; i++ )
241 anArray->SetValue( i, myIDs[i] );
242 aDataSet->GetPointData()->SetScalars( anArray );
244 myPtsMaskPoints->SetInput( aDataSet );
245 myPointLabels->SetVisibility( theIsActorVisible );
248 myPointLabels->SetVisibility( false );
254 RemoveFromRender(myViewWindow->getRenderer());
258 myViewWindow->RemoveActor(myIdActor);
261 //Deleting of points numbering pipeline
262 //---------------------------------------
263 myPointsNumDataSet->Delete();
265 //myPtsLabeledDataMapper->RemoveAllInputs(); //vtk 5.0 porting
266 myPtsLabeledDataMapper->Delete();
268 //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
269 myPtsSelectVisiblePoints->Delete();
271 //myPtsMaskPoints->UnRegisterAllOutputs(); //vtk 5.0 porting
272 myPtsMaskPoints->Delete();
274 myPointLabels->Delete();
276 // myTimeStamp->Delete();
281 static const char * IconFirst[] = {
296 //=================================================================================
297 // class : SMESHGUI_EditMeshDlg()
299 //=================================================================================
300 SMESHGUI_EditMeshDlg::SMESHGUI_EditMeshDlg (SMESHGUI* theModule,
302 : QDialog(SMESH::GetDesktop(theModule)),
303 mySMESHGUI(theModule),
304 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
308 setAttribute(Qt::WA_DeleteOnClose, true);
309 setWindowTitle(myAction == 1 ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
311 myIdPreview = new SMESH::TIdPreview(SMESH::GetViewWindow( mySMESHGUI ));
313 SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
314 QPixmap IconMergeNodes (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
315 QPixmap IconMergeElems (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_MERGE_ELEMENTS")));
316 QPixmap IconSelect (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
317 QPixmap IconAdd (aResMgr->loadPixmap("SMESH", tr("ICON_APPEND")));
318 QPixmap IconRemove (aResMgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
320 setSizeGripEnabled(true);
322 QVBoxLayout* DlgLayout = new QVBoxLayout(this);
323 DlgLayout->setSpacing(SPACING);
324 DlgLayout->setMargin(MARGIN);
326 /***************************************************************/
327 GroupConstructors = new QGroupBox(myAction == 1 ?
328 tr("SMESH_MERGE_ELEMENTS") :
329 tr("SMESH_MERGE_NODES"),
332 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
333 GroupConstructorsLayout->setSpacing(SPACING);
334 GroupConstructorsLayout->setMargin(MARGIN);
336 RadioButton = new QRadioButton(GroupConstructors);
337 RadioButton->setIcon(myAction == 1 ? IconMergeElems : IconMergeNodes);
338 RadioButton->setChecked(true);
339 GroupConstructorsLayout->addWidget(RadioButton);
340 GroupConstructorsLayout->addStretch();
342 /***************************************************************/
343 // Controls for mesh defining
344 GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
345 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
346 GroupMeshLayout->setSpacing(SPACING);
347 GroupMeshLayout->setMargin(MARGIN);
349 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupMesh);
350 SelectMeshButton = new QPushButton(GroupMesh);
351 SelectMeshButton->setIcon(IconSelect);
352 LineEditMesh = new QLineEdit(GroupMesh);
353 LineEditMesh->setReadOnly(true);
355 GroupMeshLayout->addWidget(TextLabelName);
356 GroupMeshLayout->addWidget(SelectMeshButton);
357 GroupMeshLayout->addWidget(LineEditMesh);
359 /***************************************************************/
360 // Controls for coincident elements detecting
361 GroupCoincident = new QGroupBox(myAction == 1 ?
362 tr("COINCIDENT_ELEMENTS") :
363 tr("COINCIDENT_NODES"),
366 QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincident);
367 GroupCoincidentLayout->setSpacing(SPACING);
368 GroupCoincidentLayout->setMargin(MARGIN);
370 if (myAction == 0) { // case merge nodes
371 TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), GroupCoincident);
372 SpinBoxTolerance = new SMESHGUI_SpinBox(GroupCoincident);
373 SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
375 GroupCoincidentLayout->addWidget(TextLabelTolerance, 0, 0);
376 GroupCoincidentLayout->addWidget(SpinBoxTolerance, 0, 1);
379 TextLabelTolerance = 0;
380 SpinBoxTolerance = 0;
383 int row = GroupCoincidentLayout->rowCount();
385 ListCoincident = new QListWidget(GroupCoincident);
386 ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
388 DetectButton = new QPushButton(tr("DETECT"), GroupCoincident);
389 AddGroupButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupCoincident);
390 RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincident);
392 SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincident);
394 GroupCoincidentLayout->addWidget(ListCoincident, row, 0, 4, 2);
395 GroupCoincidentLayout->addWidget(DetectButton, row, 2);
396 GroupCoincidentLayout->addWidget(AddGroupButton, row+2, 2);
397 GroupCoincidentLayout->addWidget(RemoveGroupButton, row+3, 2);
398 GroupCoincidentLayout->addWidget(SelectAllCB, row+4, 0, 1, 3);
399 GroupCoincidentLayout->setRowMinimumHeight(row+1, 10);
400 GroupCoincidentLayout->setRowStretch(row+1, 5);
402 /***************************************************************/
403 // Controls for editing the selected group
404 GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
405 QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
406 GroupEditLayout->setSpacing(SPACING);
407 GroupEditLayout->setMargin(MARGIN);
409 ListEdit = new QListWidget(GroupEdit);
410 //ListEdit->setRowMode(QListBox::FixedNumber);
411 //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
412 //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
413 ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
415 AddElemButton = new QPushButton(GroupEdit);
416 AddElemButton->setIcon(IconAdd);
417 RemoveElemButton = new QPushButton(GroupEdit);
418 RemoveElemButton->setIcon(IconRemove);
419 SetFirstButton = new QPushButton(GroupEdit);
420 SetFirstButton->setIcon(QPixmap(IconFirst));
422 GroupEditLayout->addWidget(ListEdit, 0, 0, 2, 1);
423 GroupEditLayout->addWidget(AddElemButton, 0, 1);
424 GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
425 GroupEditLayout->addWidget(SetFirstButton, 1, 1, 1, 2);
427 /***************************************************************/
428 GroupButtons = new QGroupBox(this);
429 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
430 GroupButtonsLayout->setSpacing(SPACING);
431 GroupButtonsLayout->setMargin(MARGIN);
433 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
434 buttonOk->setAutoDefault(true);
435 buttonOk->setDefault(true);
436 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
437 buttonApply->setAutoDefault(true);
438 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
439 buttonCancel->setAutoDefault(true);
440 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
441 buttonHelp->setAutoDefault(true);
443 GroupButtonsLayout->addWidget(buttonOk);
444 GroupButtonsLayout->addSpacing(10);
445 GroupButtonsLayout->addWidget(buttonApply);
446 GroupButtonsLayout->addSpacing(10);
447 GroupButtonsLayout->addStretch();
448 GroupButtonsLayout->addWidget(buttonCancel);
449 GroupButtonsLayout->addWidget(buttonHelp);
451 /***************************************************************/
452 DlgLayout->addWidget(GroupConstructors);
453 DlgLayout->addWidget(GroupMesh);
454 DlgLayout->addWidget(GroupCoincident);
455 DlgLayout->addWidget(GroupEdit);
456 DlgLayout->addWidget(GroupButtons);
458 Init(); // Initialisations
461 //=================================================================================
462 // function : ~SMESHGUI_EditMeshDlg()
463 // purpose : Destroys the object and frees any allocated resources
464 //=================================================================================
465 SMESHGUI_EditMeshDlg::~SMESHGUI_EditMeshDlg()
470 //=================================================================================
473 //=================================================================================
474 void SMESHGUI_EditMeshDlg::Init()
477 SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 3);
478 SpinBoxTolerance->SetValue(1e-05);
481 RadioButton->setChecked(true);
483 myEditCurrentArgument = (QWidget*)LineEditMesh;
486 mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
488 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
490 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
493 // Costruction of the logical filter
494 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
495 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
497 QList<SUIT_SelectionFilter*> aListOfFilters;
498 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
499 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
501 myMeshOrSubMeshOrGroupFilter =
502 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
504 /* signals and slots connections */
505 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
506 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
507 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
508 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
510 connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
511 connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
512 connect(ListCoincident, SIGNAL (selectionChanged()), this, SLOT(onSelectGroup()));
513 connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
514 connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
515 connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
516 connect(ListEdit, SIGNAL (selectionChanged()), this, SLOT(onSelectElementFromGroup()));
517 connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
518 connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
519 connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
521 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
522 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
523 /* to close dialog if study change */
524 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
526 SetFirstButton->setEnabled(false);
527 buttonOk->setEnabled(false);
528 buttonApply->setEnabled(false);
530 // Init Mesh field from selection
531 SelectionIntoArgument();
533 myHelpFileName = "merging_elements_page.html";
536 //=================================================================================
537 // function : FindGravityCenter()
539 //=================================================================================
540 void SMESHGUI_EditMeshDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap,
541 std::list< gp_XYZ > & theGrCentersXYZ)
546 SMDS_Mesh* aMesh = 0;
547 aMesh = myActor->GetObject()->GetMesh();
553 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
554 for( ; idIter.More(); idIter.Next() ) {
555 const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
559 gp_XYZ anXYZ(0., 0., 0.);
560 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
561 for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
562 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
563 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
565 anXYZ.Divide( nbNodes );
567 theGrCentersXYZ.push_back( anXYZ );
571 //=================================================================================
572 // function : ClickOnApply()
574 //=================================================================================
575 bool SMESHGUI_EditMeshDlg::ClickOnApply()
577 if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
581 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
583 QApplication::setOverrideCursor(Qt::WaitCursor);
585 SMESH::long_array_var anIds = new SMESH::long_array;
586 SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
588 aGroupsOfElements->length(ListCoincident->count());
591 for (int i = 0; i < ListCoincident->count(); i++) {
592 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
594 anIds->length(aListIds.count());
595 for (int i = 0; i < aListIds.count(); i++)
596 anIds[i] = aListIds[i].toInt();
598 aGroupsOfElements[anArrayNum++] = anIds.inout();
602 aMeshEditor->MergeNodes (aGroupsOfElements.inout());
604 aMeshEditor->MergeElements (aGroupsOfElements.inout());
606 QApplication::restoreOverrideCursor();
616 //=================================================================================
617 // function : ClickOnOk()
619 //=================================================================================
620 void SMESHGUI_EditMeshDlg::ClickOnOk()
626 //=================================================================================
627 // function : ClickOnCancel()
629 //=================================================================================
630 void SMESHGUI_EditMeshDlg::ClickOnCancel()
632 myIdPreview->SetPointsLabeled(false);
633 mySelectionMgr->clearFilters();
634 //mySelectionMgr->clearSelected();
635 SMESH::SetPointRepresentation(false);
636 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
637 aViewWindow->SetSelectionMode(ActorSelection);
638 disconnect(mySelectionMgr, 0, this, 0);
639 mySMESHGUI->ResetState();
643 //=================================================================================
644 // function : ClickOnHelp()
646 //=================================================================================
647 void SMESHGUI_EditMeshDlg::ClickOnHelp()
649 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
651 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
655 platform = "winapplication";
657 platform = "application";
659 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
660 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
661 arg(app->resourceMgr()->stringValue("ExternalBrowser",
663 arg(myHelpFileName));
667 //=================================================================================
668 // function : onEditGroup()
670 //=================================================================================
671 void SMESHGUI_EditMeshDlg::onEditGroup()
673 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
674 if ( selItems.count() != 1 ) {
681 for (int i = 0; i < ListEdit->count(); i++ )
682 aNewIds.append(ListEdit->item(i)->text());
684 ListCoincident->currentItem()->setText(aNewIds.join(" "));
685 ListCoincident->currentItem()->setSelected(true);
688 //=================================================================================
689 // function : updateControls()
691 //=================================================================================
692 void SMESHGUI_EditMeshDlg::updateControls()
694 if (ListEdit->count() == 0)
695 SetFirstButton->setEnabled(false);
696 bool enable = !(myMesh->_is_nil()) && ListCoincident->count();
697 buttonOk->setEnabled(enable);
698 buttonApply->setEnabled(enable);
701 //=================================================================================
702 // function : onDetect()
704 //=================================================================================
705 void SMESHGUI_EditMeshDlg::onDetect()
707 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
711 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
713 QApplication::setOverrideCursor(Qt::WaitCursor);
714 ListCoincident->clear();
717 SMESH::array_of_long_array_var aGroupsArray;
721 if(!mySubMeshOrGroup->_is_nil())
722 aMeshEditor->FindCoincidentNodesOnPart(mySubMeshOrGroup, SpinBoxTolerance->GetValue(), aGroupsArray);
724 aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aGroupsArray);
727 if(!mySubMeshOrGroup->_is_nil())
728 aMeshEditor->FindEqualElements(mySubMeshOrGroup, aGroupsArray);
730 aMeshEditor->FindEqualElements(myMesh, aGroupsArray);
734 for (int i = 0; i < aGroupsArray->length(); i++) {
735 SMESH::long_array& aGroup = aGroupsArray[i];
738 for (int j = 0; j < aGroup.length(); j++)
739 anIDs.append(QString::number(aGroup[j]));
741 ListCoincident->addItem(anIDs.join(" "));
743 QApplication::restoreOverrideCursor();
747 ListCoincident->selectAll();
751 //=================================================================================
752 // function : onSelectGroup()
754 //=================================================================================
755 void SMESHGUI_EditMeshDlg::onSelectGroup()
757 if (myIsBusy || !myActor)
759 myEditCurrentArgument = (QWidget*)ListCoincident;
763 TColStd_MapOfInteger anIndices;
764 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
765 QListWidgetItem* anItem;
766 QStringList aListIds;
770 foreach(anItem, selItems) {
771 aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
772 for (int i = 0; i < aListIds.count(); i++)
773 anIndices.Add(aListIds[i].toInt());
776 if (selItems.count() == 1) {
777 ListEdit->addItems(aListIds);
778 ListEdit->selectAll();
781 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
783 aList.Append(myActor->getIO());
784 mySelectionMgr->setSelectedObjects(aList,false);
787 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
788 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
791 list< gp_XYZ > aGrCentersXYZ;
792 FindGravityCenter(anIndices, aGrCentersXYZ);
793 myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
794 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
800 //=================================================================================
801 // function : onSelectAll()
803 //=================================================================================
804 void SMESHGUI_EditMeshDlg::onSelectAll (bool isToggled)
807 ListCoincident->selectAll();
809 ListCoincident->clearSelection();
812 //=================================================================================
813 // function : onSelectElementFromGroup()
815 //=================================================================================
816 void SMESHGUI_EditMeshDlg::onSelectElementFromGroup()
818 if (myIsBusy || !myActor)
821 TColStd_MapOfInteger anIndices;
822 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
823 QListWidgetItem* anItem;
825 foreach(anItem, selItems)
826 anIndices.Add(anItem->text().toInt());
828 SetFirstButton->setEnabled(selItems.count() == 1);
830 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
832 aList.Append(myActor->getIO());
833 mySelectionMgr->setSelectedObjects(aList);
836 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
837 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
840 list< gp_XYZ > aGrCentersXYZ;
841 FindGravityCenter(anIndices, aGrCentersXYZ);
842 myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
843 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
847 //=================================================================================
848 // function : onAddGroup()
850 //=================================================================================
851 void SMESHGUI_EditMeshDlg::onAddGroup()
853 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
857 SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
859 ListCoincident->clearSelection();
860 ListCoincident->addItem(anIDs);
861 int nbGroups = ListCoincident->count();
863 ListCoincident->setCurrentRow(nbGroups-1);
864 ListCoincident->item(nbGroups-1)->setSelected(true);
867 // VSR ? this code seems to be never executed!!!
868 ListCoincident->setCurrentRow(0);
869 //ListCoincident->setSelected(0, true); // VSR: no items - no selection
875 //=================================================================================
876 // function : onRemoveGroup()
878 //=================================================================================
879 void SMESHGUI_EditMeshDlg::onRemoveGroup()
881 if (myEditCurrentArgument != (QWidget*)ListCoincident)
885 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
886 QListWidgetItem* anItem;
888 foreach(anItem, selItems)
897 //=================================================================================
898 // function : onAddElement()
900 //=================================================================================
901 void SMESHGUI_EditMeshDlg::onAddElement()
907 QString aListStr = "";
910 aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
914 QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
916 for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
917 QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
918 if ( found.count() == 0 ) {
919 QListWidgetItem* anItem = new QListWidgetItem(*it);
920 ListEdit->addItem(anItem);
921 anItem->setSelected(true);
924 QListWidgetItem* anItem;
925 foreach(anItem, found) anItem->setSelected(true);
933 //=================================================================================
934 // function : onRemoveElement()
936 //=================================================================================
937 void SMESHGUI_EditMeshDlg::onRemoveElement()
939 if (myEditCurrentArgument != (QWidget*)ListCoincident)
943 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
944 QListWidgetItem* anItem;
946 foreach(anItem, selItems)
953 //=================================================================================
954 // function : onSetFirst()
956 //=================================================================================
957 void SMESHGUI_EditMeshDlg::onSetFirst()
959 if (myEditCurrentArgument != (QWidget*)ListCoincident)
963 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
964 QListWidgetItem* anItem;
966 foreach(anItem, selItems) {
967 ListEdit->takeItem(ListEdit->row(anItem));
968 ListEdit->insertItem(0, anItem);
975 //=================================================================================
976 // function : SetEditCurrentArgument()
978 //=================================================================================
979 void SMESHGUI_EditMeshDlg::SetEditCurrentArgument()
981 QPushButton* send = (QPushButton*)sender();
983 disconnect(mySelectionMgr, 0, this, 0);
984 mySelectionMgr->clearSelected();
985 mySelectionMgr->clearFilters();
987 if (send == SelectMeshButton) {
988 myEditCurrentArgument = (QWidget*)LineEditMesh;
989 SMESH::SetPointRepresentation(false);
990 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
991 aViewWindow->SetSelectionMode(ActorSelection);
992 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
995 myEditCurrentArgument->setFocus();
996 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
997 SelectionIntoArgument();
1000 //=================================================================================
1001 // function : SelectionIntoArgument()
1002 // purpose : Called when selection as changed or other case
1003 //=================================================================================
1004 void SMESHGUI_EditMeshDlg::SelectionIntoArgument()
1006 if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
1007 QString aString = "";
1008 LineEditMesh->setText(aString);
1010 ListCoincident->clear();
1014 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1018 SALOME_ListIO aList;
1019 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
1021 Handle(SALOME_InteractiveObject) IO = aList.First();
1022 myMesh = SMESH::GetMeshByIO(IO);
1024 if (myMesh->_is_nil())
1027 myActor = SMESH::FindActorByEntry(IO->getEntry());
1029 myActor = SMESH::FindActorByObject(myMesh);
1033 mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1035 if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1036 !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1037 !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1038 mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1040 LineEditMesh->setText(aString);
1042 if (myAction == 0) {
1043 SMESH::SetPointRepresentation(true);
1044 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1045 aViewWindow->SetSelectionMode(NodeSelection);
1048 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1049 aViewWindow->SetSelectionMode(CellSelection);
1053 //=================================================================================
1054 // function : DeactivateActiveDialog()
1056 //=================================================================================
1057 void SMESHGUI_EditMeshDlg::DeactivateActiveDialog()
1059 if (GroupConstructors->isEnabled()) {
1060 GroupConstructors->setEnabled(false);
1061 GroupMesh->setEnabled(false);
1062 GroupCoincident->setEnabled(false);
1063 GroupEdit->setEnabled(false);
1064 GroupButtons->setEnabled(false);
1065 mySMESHGUI->ResetState();
1066 mySMESHGUI->SetActiveDialogBox(0);
1070 //=================================================================================
1071 // function : ActivateThisDialog()
1073 //=================================================================================
1074 void SMESHGUI_EditMeshDlg::ActivateThisDialog()
1076 /* Emit a signal to deactivate the active dialog */
1077 mySMESHGUI->EmitSignalDeactivateDialog();
1078 GroupConstructors->setEnabled(true);
1079 GroupMesh->setEnabled(true);
1080 GroupCoincident->setEnabled(true);
1081 GroupEdit->setEnabled(true);
1082 GroupButtons->setEnabled(true);
1084 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1085 SelectionIntoArgument();
1088 //=================================================================================
1089 // function : enterEvent()
1091 //=================================================================================
1092 void SMESHGUI_EditMeshDlg::enterEvent(QEvent*)
1094 if (!GroupConstructors->isEnabled())
1095 ActivateThisDialog();
1098 //=================================================================================
1099 // function : closeEvent()
1101 //=================================================================================
1102 void SMESHGUI_EditMeshDlg::closeEvent(QCloseEvent*)
1104 /* same than click on cancel button */
1108 //=======================================================================
1109 //function : hideEvent
1110 //purpose : caused by ESC key
1111 //=======================================================================
1112 void SMESHGUI_EditMeshDlg::hideEvent (QHideEvent *)
1118 //=================================================================================
1119 // function : keyPressEvent()
1121 //=================================================================================
1122 void SMESHGUI_EditMeshDlg::keyPressEvent( QKeyEvent* e)
1124 QDialog::keyPressEvent( e );
1125 if ( e->isAccepted() )
1128 if ( e->key() == Qt::Key_F1 ) {