1 // Copyright (C) 2007-2010 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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_EditMeshDlg.cxx
25 // Author : Open CASCADE S.A.S.
28 #include "SMESHGUI_EditMeshDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_SpinBox.h"
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_OverrideCursor.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
56 #include <TColStd_MapOfInteger.hxx>
57 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
60 #include <SALOMEconfig.h>
61 #include CORBA_SERVER_HEADER(SMESH_Group)
62 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
65 #include <vtkUnstructuredGrid.h>
66 #include <vtkRenderer.h>
67 #include <vtkActor2D.h>
68 #include <vtkPoints.h>
69 #include <vtkDataSetMapper.h>
70 #include <vtkMaskPoints.h>
71 #include <vtkSelectVisiblePoints.h>
72 #include <vtkLabeledDataMapper.h>
73 #include <vtkTextProperty.h>
74 #include <vtkIntArray.h>
75 #include <vtkProperty2D.h>
76 #include <vtkPointData.h>
77 #include <vtkConfigure.h>
78 #if !defined(VTK_XVERSION)
79 #define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION)
83 #include <QApplication>
87 #include <QListWidget>
88 #include <QPushButton>
89 #include <QRadioButton>
91 #include <QHBoxLayout>
92 #include <QVBoxLayout>
93 #include <QGridLayout>
95 #include <QButtonGroup>
103 { // to display in the viewer IDs of the selected elements
104 SVTK_ViewWindow* myViewWindow;
106 vtkUnstructuredGrid* myIdGrid;
107 SALOME_Actor* myIdActor;
109 vtkUnstructuredGrid* myPointsNumDataSet;
110 vtkMaskPoints* myPtsMaskPoints;
111 vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
112 vtkLabeledDataMapper* myPtsLabeledDataMapper;
113 vtkTextProperty* aPtsTextProp;
114 bool myIsPointsLabeled;
115 vtkActor2D* myPointLabels;
117 std::vector<int> myIDs;
120 TIdPreview(SVTK_ViewWindow* theViewWindow):
121 myViewWindow(theViewWindow)
123 myIdGrid = vtkUnstructuredGrid::New();
125 // Create and display actor
126 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
127 aMapper->SetInput( myIdGrid );
129 myIdActor = SALOME_Actor::New();
130 myIdActor->SetInfinitive(true);
131 myIdActor->VisibilityOff();
132 myIdActor->PickableOff();
134 myIdActor->SetMapper( aMapper );
137 myViewWindow->AddActor(myIdActor);
139 //Definition of points numbering pipeline
140 myPointsNumDataSet = vtkUnstructuredGrid::New();
142 myPtsMaskPoints = vtkMaskPoints::New();
143 myPtsMaskPoints->SetInput(myPointsNumDataSet);
144 myPtsMaskPoints->SetOnRatio(1);
146 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
147 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
148 myPtsSelectVisiblePoints->SelectInvisibleOff();
149 myPtsSelectVisiblePoints->SetTolerance(0.1);
151 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
152 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
153 #if (VTK_XVERSION < 0x050200)
154 myPtsLabeledDataMapper->SetLabelFormat("%g");
156 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
158 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
159 aPtsTextProp->SetFontFamilyToTimes();
160 static int aPointsFontSize = 12;
161 aPtsTextProp->SetFontSize(aPointsFontSize);
162 aPtsTextProp->SetBold(1);
163 aPtsTextProp->SetItalic(0);
164 aPtsTextProp->SetShadow(0);
165 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
166 aPtsTextProp->Delete();
168 myIsPointsLabeled = false;
170 myPointLabels = vtkActor2D::New();
171 myPointLabels->SetMapper(myPtsLabeledDataMapper);
172 myPointLabels->GetProperty()->SetColor(1,1,1);
173 myPointLabels->SetVisibility(myIsPointsLabeled);
175 AddToRender(myViewWindow->getRenderer());
178 void SetPointsData ( SMDS_Mesh* theMesh,
179 TColStd_MapOfInteger & theNodesIdMap )
181 vtkPoints* aPoints = vtkPoints::New();
182 aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
185 TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
186 for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
187 const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
188 aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
189 myIDs.push_back(idIter.Key());
192 myIdGrid->SetPoints(aPoints);
196 myIdActor->GetMapper()->Update();
199 void SetElemsData( TColStd_MapOfInteger & theElemsIdMap,
200 std::list<gp_XYZ> & aGrCentersXYZ )
202 vtkPoints* aPoints = vtkPoints::New();
203 aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
206 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
207 for( ; idIter.More(); idIter.Next() ) {
208 myIDs.push_back(idIter.Key());
212 std::list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
213 for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
215 aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
217 myIdGrid->SetPoints(aPoints);
220 myIdActor->GetMapper()->Update();
223 void AddToRender(vtkRenderer* theRenderer)
225 myIdActor->AddToRender(theRenderer);
227 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
228 theRenderer->AddActor2D(myPointLabels);
231 void RemoveFromRender(vtkRenderer* theRenderer)
233 myIdActor->RemoveFromRender(theRenderer);
235 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
236 theRenderer->RemoveActor(myPointLabels);
239 void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
241 myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
243 if ( myIsPointsLabeled ) {
244 myPointsNumDataSet->ShallowCopy(myIdGrid);
245 vtkDataSet *aDataSet = myPointsNumDataSet;
246 int aNbElem = myIDs.size();
247 vtkIntArray *anArray = vtkIntArray::New();
248 anArray->SetNumberOfValues( aNbElem );
249 for ( int i = 0; i < aNbElem; i++ )
250 anArray->SetValue( i, myIDs[i] );
251 aDataSet->GetPointData()->SetScalars( anArray );
253 myPtsMaskPoints->SetInput( aDataSet );
254 myPointLabels->SetVisibility( theIsActorVisible );
257 myPointLabels->SetVisibility( false );
263 RemoveFromRender(myViewWindow->getRenderer());
267 myViewWindow->RemoveActor(myIdActor);
270 //Deleting of points numbering pipeline
271 //---------------------------------------
272 myPointsNumDataSet->Delete();
274 //myPtsLabeledDataMapper->RemoveAllInputs(); //vtk 5.0 porting
275 myPtsLabeledDataMapper->Delete();
277 //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
278 myPtsSelectVisiblePoints->Delete();
280 //myPtsMaskPoints->UnRegisterAllOutputs(); //vtk 5.0 porting
281 myPtsMaskPoints->Delete();
283 myPointLabels->Delete();
285 // myTimeStamp->Delete();
290 static const char * IconFirst[] = {
305 //=================================================================================
306 // class : SMESHGUI_EditMeshDlg()
308 //=================================================================================
309 SMESHGUI_EditMeshDlg::SMESHGUI_EditMeshDlg (SMESHGUI* theModule,
311 : QDialog(SMESH::GetDesktop(theModule)),
312 mySMESHGUI(theModule),
313 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
317 setAttribute(Qt::WA_DeleteOnClose, true);
318 setWindowTitle(myAction == 1 ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
320 myIdPreview = new SMESH::TIdPreview(SMESH::GetViewWindow( mySMESHGUI ));
322 SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
323 QPixmap IconMergeNodes (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
324 QPixmap IconMergeElems (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_MERGE_ELEMENTS")));
325 QPixmap IconSelect (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
326 QPixmap IconAdd (aResMgr->loadPixmap("SMESH", tr("ICON_APPEND")));
327 QPixmap IconRemove (aResMgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
329 setSizeGripEnabled(true);
331 QVBoxLayout* DlgLayout = new QVBoxLayout(this);
332 DlgLayout->setSpacing(SPACING);
333 DlgLayout->setMargin(MARGIN);
335 /***************************************************************/
336 GroupConstructors = new QGroupBox(myAction == 1 ?
337 tr("SMESH_MERGE_ELEMENTS") :
338 tr("SMESH_MERGE_NODES"),
341 QButtonGroup* ButtonGroup = new QButtonGroup(this);
342 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
343 GroupConstructorsLayout->setSpacing(SPACING);
344 GroupConstructorsLayout->setMargin(MARGIN);
346 RadioButton = new QRadioButton(GroupConstructors);
347 RadioButton->setIcon(myAction == 1 ? IconMergeElems : IconMergeNodes);
348 RadioButton->setChecked(true);
349 GroupConstructorsLayout->addWidget(RadioButton);
350 ButtonGroup->addButton(RadioButton, 0);
352 /***************************************************************/
353 // Controls for mesh defining
354 GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
355 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
356 GroupMeshLayout->setSpacing(SPACING);
357 GroupMeshLayout->setMargin(MARGIN);
359 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupMesh);
360 SelectMeshButton = new QPushButton(GroupMesh);
361 SelectMeshButton->setIcon(IconSelect);
362 LineEditMesh = new QLineEdit(GroupMesh);
363 LineEditMesh->setReadOnly(true);
365 GroupMeshLayout->addWidget(TextLabelName);
366 GroupMeshLayout->addWidget(SelectMeshButton);
367 GroupMeshLayout->addWidget(LineEditMesh);
369 /***************************************************************/
370 // Controls for switch dialog behaviour
372 TypeBox = new QGroupBox( tr( "SMESH_MODE" ), this );
373 GroupType = new QButtonGroup( this );
374 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( TypeBox );
375 aTypeBoxLayout->setMargin( MARGIN );
376 aTypeBoxLayout->setSpacing( SPACING );
378 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_AUTOMATIC" ), TypeBox );
379 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_MANUAL" ), TypeBox );
380 GroupType->addButton( rb1, 0 );
381 GroupType->addButton( rb2, 1 );
382 aTypeBoxLayout->addWidget( rb1 );
383 aTypeBoxLayout->addWidget( rb2 );
387 /***************************************************************/
388 // Controls for coincident elements detecting
389 GroupCoincident = new QGroupBox(myAction == 1 ?
390 tr("COINCIDENT_ELEMENTS") :
391 tr("COINCIDENT_NODES"),
394 QVBoxLayout* aCoincidentLayout = new QVBoxLayout(GroupCoincident);
396 GroupCoincident->setLayout(aCoincidentLayout);
398 QHBoxLayout* aSpinBoxLayout = new QHBoxLayout( GroupCoincident );
400 if (myAction == 0) { // case merge nodes
401 TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), GroupCoincident);
402 SpinBoxTolerance = new SMESHGUI_SpinBox(GroupCoincident);
403 SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
405 aSpinBoxLayout->addWidget(TextLabelTolerance);
406 aSpinBoxLayout->addWidget(SpinBoxTolerance);
407 aCoincidentLayout->addLayout(aSpinBoxLayout);
410 TextLabelTolerance = 0;
411 SpinBoxTolerance = 0;
414 GroupCoincidentWidget = new QWidget(GroupCoincident);
415 QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincidentWidget);
416 GroupCoincidentLayout->setSpacing(SPACING);
417 GroupCoincidentLayout->setMargin(MARGIN);
419 ListCoincident = new QListWidget(GroupCoincidentWidget);
420 ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
422 DetectButton = new QPushButton(tr("DETECT"), GroupCoincidentWidget);
423 AddGroupButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupCoincidentWidget);
424 RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincidentWidget);
426 SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincidentWidget);
429 GroupCoincidentWidget->hide();
431 GroupCoincident->hide();
433 GroupCoincidentLayout->addWidget(ListCoincident, 0, 0, 4, 2);
434 GroupCoincidentLayout->addWidget(DetectButton, 0, 2);
435 GroupCoincidentLayout->addWidget(AddGroupButton, 2, 2);
436 GroupCoincidentLayout->addWidget(RemoveGroupButton, 3, 2);
437 GroupCoincidentLayout->addWidget(SelectAllCB, 4, 0, 1, 3);
438 GroupCoincidentLayout->setRowMinimumHeight(1, 10);
439 GroupCoincidentLayout->setRowStretch(1, 5);
441 aCoincidentLayout->addWidget(GroupCoincidentWidget);
443 /***************************************************************/
444 // Controls for editing the selected group
445 GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
446 QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
447 GroupEditLayout->setSpacing(SPACING);
448 GroupEditLayout->setMargin(MARGIN);
450 ListEdit = new QListWidget(GroupEdit);
451 //ListEdit->setRowMode(QListBox::FixedNumber);
452 //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
453 //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
454 ListEdit->setFlow( QListView::LeftToRight );
455 ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
457 AddElemButton = new QPushButton(GroupEdit);
458 AddElemButton->setIcon(IconAdd);
459 RemoveElemButton = new QPushButton(GroupEdit);
460 RemoveElemButton->setIcon(IconRemove);
461 SetFirstButton = new QPushButton(GroupEdit);
462 SetFirstButton->setIcon(QPixmap(IconFirst));
464 GroupEditLayout->addWidget(ListEdit, 0, 0, 2, 1);
465 GroupEditLayout->addWidget(AddElemButton, 0, 1);
466 GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
467 GroupEditLayout->addWidget(SetFirstButton, 1, 1, 1, 2);
471 /***************************************************************/
472 GroupButtons = new QGroupBox(this);
473 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
474 GroupButtonsLayout->setSpacing(SPACING);
475 GroupButtonsLayout->setMargin(MARGIN);
477 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
478 buttonOk->setAutoDefault(true);
479 buttonOk->setDefault(true);
480 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
481 buttonApply->setAutoDefault(true);
482 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
483 buttonCancel->setAutoDefault(true);
484 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
485 buttonHelp->setAutoDefault(true);
487 GroupButtonsLayout->addWidget(buttonOk);
488 GroupButtonsLayout->addSpacing(10);
489 GroupButtonsLayout->addWidget(buttonApply);
490 GroupButtonsLayout->addSpacing(10);
491 GroupButtonsLayout->addStretch();
492 GroupButtonsLayout->addWidget(buttonCancel);
493 GroupButtonsLayout->addWidget(buttonHelp);
495 /***************************************************************/
496 DlgLayout->addWidget(GroupConstructors);
497 DlgLayout->addWidget(GroupMesh);
498 DlgLayout->addWidget(TypeBox);
499 DlgLayout->addWidget(GroupCoincident);
500 DlgLayout->addWidget(GroupEdit);
501 DlgLayout->addWidget(GroupButtons);
505 Init(); // Initialisations
508 //=================================================================================
509 // function : ~SMESHGUI_EditMeshDlg()
510 // purpose : Destroys the object and frees any allocated resources
511 //=================================================================================
512 SMESHGUI_EditMeshDlg::~SMESHGUI_EditMeshDlg()
517 //=================================================================================
520 //=================================================================================
521 void SMESHGUI_EditMeshDlg::Init()
524 SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision");
525 SpinBoxTolerance->SetValue(1e-05);
528 RadioButton->setChecked(true);
530 GroupType->button(0)->setChecked(true);
532 myEditCurrentArgument = (QWidget*)LineEditMesh;
535 mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
537 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
539 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
542 /* signals and slots connections */
543 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
544 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
545 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
546 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
548 connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
549 connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
550 connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
551 connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
552 connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
553 connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
554 connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
555 connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
556 connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
557 connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
558 connect(GroupType, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
560 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
561 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
562 /* to close dialog if study change */
563 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
565 // Init Mesh field from selection
566 SelectionIntoArgument();
572 myHelpFileName = "merging_nodes_page.html";
574 myHelpFileName = "merging_elements_page.html";
577 //=================================================================================
578 // function : FindGravityCenter()
580 //=================================================================================
581 void SMESHGUI_EditMeshDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap,
582 std::list< gp_XYZ > & theGrCentersXYZ)
587 SMDS_Mesh* aMesh = 0;
588 aMesh = myActor->GetObject()->GetMesh();
594 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
595 for( ; idIter.More(); idIter.Next() ) {
596 const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
600 gp_XYZ anXYZ(0., 0., 0.);
601 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
602 for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
603 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
604 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
606 anXYZ.Divide( nbNodes );
608 theGrCentersXYZ.push_back( anXYZ );
612 //=================================================================================
613 // function : ClickOnApply()
615 //=================================================================================
616 bool SMESHGUI_EditMeshDlg::ClickOnApply()
618 if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
625 SUIT_OverrideCursor aWaitCursor;
626 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
628 SMESH::long_array_var anIds = new SMESH::long_array;
629 SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
631 if ( ListCoincident->count() == 0) {
633 SUIT_MessageBox::warning(this,
635 tr("SMESH_NO_NODES_DETECTED"));
637 SUIT_MessageBox::warning(this,
639 tr("SMESH_NO_ELEMENTS_DETECTED"));
643 aGroupsOfElements->length(ListCoincident->count());
646 for (int i = 0; i < ListCoincident->count(); i++) {
647 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
649 anIds->length(aListIds.count());
650 for (int i = 0; i < aListIds.count(); i++)
651 anIds[i] = aListIds[i].toInt();
653 aGroupsOfElements[anArrayNum++] = anIds.inout();
657 aMeshEditor->MergeNodes (aGroupsOfElements.inout());
659 aMeshEditor->MergeElements (aGroupsOfElements.inout());
661 if ( myTypeId == 0 ) {
663 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
664 tr("SMESH_MERGED_NODES").arg(QString::number(ListCoincident->count()).toLatin1().data()));
666 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
667 tr("SMESH_MERGED_ELEMENTS").arg(QString::number(ListCoincident->count()).toLatin1().data()));
679 //=================================================================================
680 // function : ClickOnOk()
682 //=================================================================================
683 void SMESHGUI_EditMeshDlg::ClickOnOk()
689 //=================================================================================
690 // function : ClickOnCancel()
692 //=================================================================================
693 void SMESHGUI_EditMeshDlg::ClickOnCancel()
695 myIdPreview->SetPointsLabeled(false);
696 SMESH::SetPointRepresentation(false);
697 disconnect(mySelectionMgr, 0, this, 0);
698 disconnect(mySMESHGUI, 0, this, 0);
699 mySMESHGUI->ResetState();
701 mySelectionMgr->clearFilters();
702 //mySelectionMgr->clearSelected();
704 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
705 aViewWindow->SetSelectionMode(ActorSelection);
710 //=================================================================================
711 // function : ClickOnHelp()
713 //=================================================================================
714 void SMESHGUI_EditMeshDlg::ClickOnHelp()
716 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
718 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
722 platform = "winapplication";
724 platform = "application";
726 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
727 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
728 arg(app->resourceMgr()->stringValue("ExternalBrowser",
730 arg(myHelpFileName));
734 //=================================================================================
735 // function : onEditGroup()
737 //=================================================================================
738 void SMESHGUI_EditMeshDlg::onEditGroup()
740 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
741 if ( selItems.count() != 1 ) {
748 for (int i = 0; i < ListEdit->count(); i++ )
749 aNewIds.append(ListEdit->item(i)->text());
751 ListCoincident->clearSelection();
752 selItems.first()->setText(aNewIds.join(" "));
753 selItems.first()->setSelected(true);
756 //=================================================================================
757 // function : updateControls()
759 //=================================================================================
760 void SMESHGUI_EditMeshDlg::updateControls()
762 if (ListEdit->count() == 0)
763 SetFirstButton->setEnabled(false);
764 bool enable = !(myMesh->_is_nil()) && (ListCoincident->count() || (myTypeId == 0));
765 buttonOk->setEnabled(enable);
766 buttonApply->setEnabled(enable);
769 //=================================================================================
770 // function : onDetect()
772 //=================================================================================
773 void SMESHGUI_EditMeshDlg::onDetect()
775 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
779 SUIT_OverrideCursor aWaitCursor;
780 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
782 ListCoincident->clear();
785 SMESH::array_of_long_array_var aGroupsArray;
789 if(!mySubMeshOrGroup->_is_nil())
790 aMeshEditor->FindCoincidentNodesOnPart(mySubMeshOrGroup, SpinBoxTolerance->GetValue(), aGroupsArray);
792 aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aGroupsArray);
795 if(!mySubMeshOrGroup->_is_nil())
796 aMeshEditor->FindEqualElements(mySubMeshOrGroup, aGroupsArray);
798 aMeshEditor->FindEqualElements(myMesh, aGroupsArray);
802 for (int i = 0; i < aGroupsArray->length(); i++) {
803 SMESH::long_array& aGroup = aGroupsArray[i];
806 for (int j = 0; j < aGroup.length(); j++)
807 anIDs.append(QString::number(aGroup[j]));
809 ListCoincident->addItem(anIDs.join(" "));
814 ListCoincident->selectAll();
818 //=================================================================================
819 // function : onSelectGroup()
821 //=================================================================================
822 void SMESHGUI_EditMeshDlg::onSelectGroup()
824 if (myIsBusy || !myActor)
826 myEditCurrentArgument = (QWidget*)ListCoincident;
830 TColStd_MapOfInteger anIndices;
831 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
832 QListWidgetItem* anItem;
833 QStringList aListIds;
837 foreach(anItem, selItems) {
838 aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
839 for (int i = 0; i < aListIds.count(); i++)
840 anIndices.Add(aListIds[i].toInt());
843 if (selItems.count() == 1) {
844 ListEdit->addItems(aListIds);
845 ListEdit->selectAll();
848 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
850 aList.Append(myActor->getIO());
851 mySelectionMgr->setSelectedObjects(aList,false);
854 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
855 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
858 std::list< gp_XYZ > aGrCentersXYZ;
859 FindGravityCenter(anIndices, aGrCentersXYZ);
860 myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
861 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
867 //=================================================================================
868 // function : onSelectAll()
870 //=================================================================================
871 void SMESHGUI_EditMeshDlg::onSelectAll (bool isToggled)
874 ListCoincident->selectAll();
876 ListCoincident->clearSelection();
879 //=================================================================================
880 // function : onSelectElementFromGroup()
882 //=================================================================================
883 void SMESHGUI_EditMeshDlg::onSelectElementFromGroup()
885 if (myIsBusy || !myActor)
888 TColStd_MapOfInteger anIndices;
889 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
890 QListWidgetItem* anItem;
892 foreach(anItem, selItems)
893 anIndices.Add(anItem->text().toInt());
895 SetFirstButton->setEnabled(selItems.count() == 1);
897 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
899 aList.Append(myActor->getIO());
900 mySelectionMgr->setSelectedObjects(aList);
903 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
904 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
907 std::list< gp_XYZ > aGrCentersXYZ;
908 FindGravityCenter(anIndices, aGrCentersXYZ);
909 myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
910 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
914 //=================================================================================
915 // function : onAddGroup()
917 //=================================================================================
918 void SMESHGUI_EditMeshDlg::onAddGroup()
920 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
925 aNbElements = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
930 ListCoincident->clearSelection();
931 ListCoincident->addItem(anIDs);
932 int nbGroups = ListCoincident->count();
934 ListCoincident->setCurrentRow(nbGroups-1);
935 ListCoincident->item(nbGroups-1)->setSelected(true);
938 // VSR ? this code seems to be never executed!!!
939 ListCoincident->setCurrentRow(0);
940 //ListCoincident->setSelected(0, true); // VSR: no items - no selection
946 //=================================================================================
947 // function : onRemoveGroup()
949 //=================================================================================
950 void SMESHGUI_EditMeshDlg::onRemoveGroup()
952 if (myEditCurrentArgument != (QWidget*)ListCoincident)
956 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
957 QListWidgetItem* anItem;
959 foreach(anItem, selItems)
968 //=================================================================================
969 // function : onAddElement()
971 //=================================================================================
972 void SMESHGUI_EditMeshDlg::onAddElement()
978 QString aListStr = "";
981 aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
985 QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
987 for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
988 QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
989 if ( found.count() == 0 ) {
990 QListWidgetItem* anItem = new QListWidgetItem(*it);
991 ListEdit->addItem(anItem);
992 anItem->setSelected(true);
995 QListWidgetItem* anItem;
996 foreach(anItem, found) anItem->setSelected(true);
1004 //=================================================================================
1005 // function : onRemoveElement()
1007 //=================================================================================
1008 void SMESHGUI_EditMeshDlg::onRemoveElement()
1010 if (myEditCurrentArgument != (QWidget*)ListCoincident)
1014 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1015 QListWidgetItem* anItem;
1017 foreach(anItem, selItems)
1024 //=================================================================================
1025 // function : onSetFirst()
1027 //=================================================================================
1028 void SMESHGUI_EditMeshDlg::onSetFirst()
1030 if (myEditCurrentArgument != (QWidget*)ListCoincident)
1034 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1035 QListWidgetItem* anItem;
1037 foreach(anItem, selItems) {
1038 ListEdit->takeItem(ListEdit->row(anItem));
1039 ListEdit->insertItem(0, anItem);
1046 //=================================================================================
1047 // function : SetEditCurrentArgument()
1049 //=================================================================================
1050 void SMESHGUI_EditMeshDlg::SetEditCurrentArgument()
1052 QPushButton* send = (QPushButton*)sender();
1054 disconnect(mySelectionMgr, 0, this, 0);
1055 mySelectionMgr->clearSelected();
1056 mySelectionMgr->clearFilters();
1058 if (send == SelectMeshButton) {
1059 myEditCurrentArgument = (QWidget*)LineEditMesh;
1060 SMESH::SetPointRepresentation(false);
1061 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1062 aViewWindow->SetSelectionMode(ActorSelection);
1064 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1067 myEditCurrentArgument->setFocus();
1068 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1069 SelectionIntoArgument();
1072 //=================================================================================
1073 // function : SelectionIntoArgument()
1074 // purpose : Called when selection as changed or other case
1075 //=================================================================================
1076 void SMESHGUI_EditMeshDlg::SelectionIntoArgument()
1078 if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
1079 QString aString = "";
1080 LineEditMesh->setText(aString);
1082 ListCoincident->clear();
1086 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1088 myIdPreview->SetPointsLabeled(false);
1089 SMESH::SetPointRepresentation(false);
1090 mySelectionMgr->clearFilters();
1091 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1092 aViewWindow->SetSelectionMode(ActorSelection);
1096 SALOME_ListIO aList;
1097 mySelectionMgr->selectedObjects(aList);
1099 Handle(SALOME_InteractiveObject) IO = aList.First();
1100 myMesh = SMESH::GetMeshByIO(IO);
1102 if (myMesh->_is_nil())
1105 LineEditMesh->setText(aString);
1107 myActor = SMESH::FindActorByEntry(IO->getEntry());
1109 myActor = SMESH::FindActorByObject(myMesh);
1111 if ( myActor && myTypeId ==1 ) {
1112 mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1113 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1115 if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1116 !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1117 !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1118 mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1120 if (myAction == 0) {
1121 SMESH::SetPointRepresentation(true);
1122 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1123 aViewWindow->SetSelectionMode(NodeSelection);
1126 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1127 aViewWindow->SetSelectionMode(CellSelection);
1134 //=================================================================================
1135 // function : DeactivateActiveDialog()
1137 //=================================================================================
1138 void SMESHGUI_EditMeshDlg::DeactivateActiveDialog()
1140 if (GroupConstructors->isEnabled()) {
1141 GroupConstructors->setEnabled(false);
1142 TypeBox->setEnabled(false);
1143 GroupMesh->setEnabled(false);
1144 GroupCoincident->setEnabled(false);
1145 GroupEdit->setEnabled(false);
1146 GroupButtons->setEnabled(false);
1147 mySMESHGUI->ResetState();
1148 mySMESHGUI->SetActiveDialogBox(0);
1151 mySelectionMgr->clearSelected();
1152 disconnect(mySelectionMgr, 0, this, 0);
1155 //=================================================================================
1156 // function : ActivateThisDialog()
1158 //=================================================================================
1159 void SMESHGUI_EditMeshDlg::ActivateThisDialog()
1161 /* Emit a signal to deactivate the active dialog */
1162 mySMESHGUI->EmitSignalDeactivateDialog();
1163 GroupConstructors->setEnabled(true);
1164 TypeBox->setEnabled(true);
1165 GroupMesh->setEnabled(true);
1166 GroupCoincident->setEnabled(true);
1167 GroupEdit->setEnabled(true);
1168 GroupButtons->setEnabled(true);
1170 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1171 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1172 SelectionIntoArgument();
1175 //=================================================================================
1176 // function : enterEvent()
1178 //=================================================================================
1179 void SMESHGUI_EditMeshDlg::enterEvent(QEvent*)
1181 if (!GroupConstructors->isEnabled())
1182 ActivateThisDialog();
1185 //=================================================================================
1186 // function : closeEvent()
1188 //=================================================================================
1189 void SMESHGUI_EditMeshDlg::closeEvent(QCloseEvent*)
1191 /* same than click on cancel button */
1195 //=======================================================================
1196 //function : hideEvent
1197 //purpose : caused by ESC key
1198 //=======================================================================
1199 void SMESHGUI_EditMeshDlg::hideEvent (QHideEvent *)
1205 //=================================================================================
1206 // function : keyPressEvent()
1208 //=================================================================================
1209 void SMESHGUI_EditMeshDlg::keyPressEvent( QKeyEvent* e)
1211 QDialog::keyPressEvent( e );
1212 if ( e->isAccepted() )
1215 if ( e->key() == Qt::Key_F1 ) {
1221 //=================================================================================
1222 // function : onTypeChanged()
1223 // purpose : the type radio button management
1224 //=================================================================================
1225 void SMESHGUI_EditMeshDlg::onTypeChanged (int id)
1233 myIdPreview->SetPointsLabeled(false);
1234 SMESH::SetPointRepresentation(false);
1235 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1236 aViewWindow->SetSelectionMode(ActorSelection);
1237 mySelectionMgr->clearFilters();
1239 GroupCoincidentWidget->hide();
1241 GroupCoincident->hide();
1245 SMESH::UpdateView();
1247 // Costruction of the logical filter
1248 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
1249 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
1251 QList<SUIT_SelectionFilter*> aListOfFilters;
1252 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
1253 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
1255 myMeshOrSubMeshOrGroupFilter =
1256 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
1258 if (myAction == 0) {
1259 GroupCoincidentWidget->show();
1260 SMESH::SetPointRepresentation(true);
1261 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1262 aViewWindow->SetSelectionMode(NodeSelection);
1265 GroupCoincident->show();
1266 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1267 aViewWindow->SetSelectionMode(CellSelection);
1274 qApp->processEvents();
1278 SelectionIntoArgument();