1 // Copyright (C) 2007-2013 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 // File : SMESHGUI_MultiEditDlg.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_MultiEditDlg.h"
30 #include "SMESHGUI_Filter.h"
31 #include "SMESHGUI_FilterDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_FilterUtils.h"
36 #include "SMESHGUI_SpinBox.h"
38 #include <SMESH_Actor.h>
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_OverrideCursor.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_Session.h>
49 #include <LightApp_SelectionMgr.h>
50 #include <LightApp_Application.h>
51 #include <SALOME_ListIO.hxx>
52 #include <SALOME_ListIteratorOfListIO.hxx>
53 #include <SalomeApp_Tools.h>
55 #include <SVTK_Selector.h>
56 #include <SVTK_ViewWindow.h>
57 #include <VTKViewer_CellLocationsArray.h>
60 #include <TColStd_IndexedMapOfInteger.hxx>
61 #include <TColStd_DataMapOfIntegerInteger.hxx>
62 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
65 #include <vtkIdList.h>
66 #include <vtkCellArray.h>
67 #include <vtkUnsignedCharArray.h>
68 #include <vtkUnstructuredGrid.h>
69 #include <vtkDataSetMapper.h>
70 #include <vtkProperty.h>
74 #include <QVBoxLayout>
75 #include <QHBoxLayout>
76 #include <QGridLayout>
77 #include <QListWidget>
82 #include <QPushButton>
83 #include <QButtonGroup>
84 #include <QRadioButton>
88 #include <SALOMEconfig.h>
89 #include CORBA_SERVER_HEADER(SMESH_Group)
95 * Class : SMESHGUI_MultiEditDlg
96 * Description : Description : Inversion of the diagonal of a pseudo-quadrangle formed by
97 * 2 neighboring triangles with 1 common edge
100 //=======================================================================
101 // name : SMESHGUI_MultiEditDlg::SMESHGUI_MultiEditDlg
102 // Purpose : Constructor
103 //=======================================================================
104 SMESHGUI_MultiEditDlg
105 ::SMESHGUI_MultiEditDlg(SMESHGUI* theModule,
108 QDialog(SMESH::GetDesktop(theModule)),
109 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
110 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
111 mySMESHGUI(theModule)
114 setAttribute(Qt::WA_DeleteOnClose, true);
119 myFilterType = theMode;
120 QVBoxLayout* aDlgLay = new QVBoxLayout(this);
121 aDlgLay->setMargin(MARGIN);
122 aDlgLay->setSpacing(SPACING);
124 QWidget* aMainFrame = createMainFrame (this, the3d2d);
125 QWidget* aBtnFrame = createButtonFrame(this);
127 aDlgLay->addWidget(aMainFrame);
128 aDlgLay->addWidget(aBtnFrame);
133 //=======================================================================
134 // name : SMESHGUI_MultiEditDlg::createMainFrame
135 // Purpose : Create frame containing dialog's input fields
136 //=======================================================================
137 QWidget* SMESHGUI_MultiEditDlg::createMainFrame (QWidget* theParent, const bool the3d2d)
139 QWidget* aMainGrp = new QWidget(theParent);
140 QVBoxLayout* aMainGrpLayout = new QVBoxLayout(aMainGrp);
141 aMainGrpLayout->setMargin(0);
142 aMainGrpLayout->setSpacing(SPACING);
144 QPixmap aPix (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
146 // "Selected cells" group
147 mySelGrp = new QGroupBox(aMainGrp);
149 QGridLayout* mySelGrpLayout = new QGridLayout(mySelGrp);
150 mySelGrpLayout->setMargin(MARGIN);
151 mySelGrpLayout->setSpacing(SPACING);
155 QGroupBox* aEntityTypeGrp = new QGroupBox(tr("SMESH_ELEMENTS_TYPE"), mySelGrp);
156 myEntityTypeGrp = new QButtonGroup(mySelGrp);
157 QHBoxLayout* aEntityLayout = new QHBoxLayout(aEntityTypeGrp);
158 aEntityLayout->setMargin(MARGIN);
159 aEntityLayout->setSpacing(SPACING);
161 QRadioButton* aFaceRb = new QRadioButton(tr("SMESH_FACE"), aEntityTypeGrp);
162 QRadioButton* aVolumeRb = new QRadioButton(tr("SMESH_VOLUME"), aEntityTypeGrp);
164 aEntityLayout->addWidget(aFaceRb);
165 aEntityLayout->addWidget(aVolumeRb);
167 myEntityTypeGrp->addButton(aFaceRb, 0);
168 myEntityTypeGrp->addButton(aVolumeRb, 1);
169 aFaceRb->setChecked(true);
170 myEntityType = myEntityTypeGrp->checkedId();
172 mySelGrpLayout->addWidget(aEntityTypeGrp, 0, 0, 1, 2);
175 myListBox = new QListWidget(mySelGrp);
176 myListBox->setSelectionMode(QListWidget::ExtendedSelection);
177 myListBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
178 myListBox->installEventFilter(this);
180 myFilterBtn = new QPushButton(tr("FILTER"), mySelGrp);
181 myAddBtn = new QPushButton(tr("ADD"), mySelGrp);
182 myRemoveBtn = new QPushButton(tr("REMOVE"), mySelGrp);
183 mySortBtn = new QPushButton(tr("SORT_LIST"), mySelGrp);
185 int row = mySelGrpLayout->rowCount();
186 mySelGrpLayout->addWidget(myListBox, row, 0, 6, 1);
187 mySelGrpLayout->addWidget(myFilterBtn, row, 1);
188 mySelGrpLayout->addWidget(myAddBtn, row+2, 1);
189 mySelGrpLayout->addWidget(myRemoveBtn, row+3, 1);
190 mySelGrpLayout->addWidget(mySortBtn, row+5, 1);
191 mySelGrpLayout->setRowMinimumHeight(row+1, 10);
192 mySelGrpLayout->setRowMinimumHeight(row+4, 10);
193 mySelGrpLayout->setRowStretch(row+1, 5);
194 mySelGrpLayout->setRowStretch(row+4, 5);
196 myToAllChk = new QCheckBox(tr("TO_ALL"), mySelGrp);
197 mySelGrpLayout->addWidget(myToAllChk, mySelGrpLayout->rowCount(), 0,
198 1, mySelGrpLayout->columnCount());
200 // Split/Join criterion group
201 myCriterionGrp = new QGroupBox(tr("SPLIT_JOIN_CRITERION"), aMainGrp);
202 QVBoxLayout* aCriterionLayout = new QVBoxLayout(myCriterionGrp);
203 aCriterionLayout->setMargin(MARGIN);
204 aCriterionLayout->setSpacing(SPACING);
206 myChoiceWidget = new QWidget(myCriterionGrp);
207 myGroupChoice = new QButtonGroup(myChoiceWidget);
208 QVBoxLayout* aGroupChoiceLayout = new QVBoxLayout(myChoiceWidget);
209 aGroupChoiceLayout->setMargin(0);
210 aGroupChoiceLayout->setSpacing(SPACING);
212 QRadioButton* aDiag13RB = new QRadioButton(tr("USE_DIAGONAL_1_3"), myChoiceWidget);
213 QRadioButton* aDiag24RB = new QRadioButton(tr("USE_DIAGONAL_2_4"), myChoiceWidget);
214 QRadioButton* aNumFuncRB = new QRadioButton(tr("USE_NUMERIC_FUNC"), myChoiceWidget);
216 aGroupChoiceLayout->addWidget(aDiag13RB);
217 aGroupChoiceLayout->addWidget(aDiag24RB);
218 aGroupChoiceLayout->addWidget(aNumFuncRB);
219 myGroupChoice->addButton(aDiag13RB, 0);
220 myGroupChoice->addButton(aDiag24RB, 1);
221 myGroupChoice->addButton(aNumFuncRB, 2);
222 aDiag13RB->setChecked(true);
224 myComboBoxFunctor = new QComboBox(myCriterionGrp);
225 myComboBoxFunctor->addItem(tr("ASPECTRATIO_ELEMENTS"));
226 myComboBoxFunctor->addItem(tr("MINIMUMANGLE_ELEMENTS"));
227 myComboBoxFunctor->addItem(tr("SKEW_ELEMENTS"));
228 //myComboBoxFunctor->addItem(tr("AREA_ELEMENTS"));
229 //myComboBoxFunctor->addItem(tr("LENGTH2D_EDGES")); // for existing elements only
230 //myComboBoxFunctor->addItem(tr("MULTI2D_BORDERS")); // for existing elements only
231 myComboBoxFunctor->setCurrentIndex(0);
233 aCriterionLayout->addWidget(myChoiceWidget);
234 aCriterionLayout->addWidget(myComboBoxFunctor);
236 myCriterionGrp->hide();
237 myChoiceWidget->hide();
238 myComboBoxFunctor->setEnabled(false);
240 // "Select from" group
241 QGroupBox* aGrp = new QGroupBox(tr("SELECT_FROM"), aMainGrp);
242 QGridLayout* aGrpLayout = new QGridLayout(aGrp);
243 aGrpLayout->setMargin(MARGIN);
244 aGrpLayout->setSpacing(SPACING);
246 mySubmeshChk = new QCheckBox(tr("SMESH_SUBMESH"), aGrp);
247 mySubmeshBtn = new QPushButton(aGrp);
248 mySubmesh = new QLineEdit(aGrp);
249 mySubmesh->setReadOnly(true);
250 mySubmeshBtn->setIcon(aPix);
252 myGroupChk = new QCheckBox(tr("SMESH_GROUP"), aGrp);
253 myGroupBtn = new QPushButton(aGrp);
254 myGroup = new QLineEdit(aGrp);
255 myGroup->setReadOnly(true);
256 myGroupBtn->setIcon(aPix);
258 aGrpLayout->addWidget(mySubmeshChk,0,0);
259 aGrpLayout->addWidget(mySubmeshBtn,0,1);
260 aGrpLayout->addWidget(mySubmesh,0,2);
261 aGrpLayout->addWidget(myGroupChk,1,0);
262 aGrpLayout->addWidget(myGroupBtn,1,1);
263 aGrpLayout->addWidget(myGroup,1,2);
265 aMainGrpLayout->addWidget(mySelGrp);
266 aMainGrpLayout->addWidget(myCriterionGrp);
267 aMainGrpLayout->addWidget(aGrp);
272 //=======================================================================
273 // name : SMESHGUI_MultiEditDlg::createButtonFrame
274 // Purpose : Create frame containing buttons
275 //=======================================================================
276 QWidget* SMESHGUI_MultiEditDlg::createButtonFrame (QWidget* theParent)
278 QGroupBox* aFrame = new QGroupBox(theParent);
280 myOkBtn = new QPushButton (tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
281 myApplyBtn = new QPushButton (tr("SMESH_BUT_APPLY"), aFrame);
282 myCloseBtn = new QPushButton (tr("SMESH_BUT_CLOSE"), aFrame);
283 myHelpBtn = new QPushButton (tr("SMESH_BUT_HELP"), aFrame);
285 QHBoxLayout* aLay = new QHBoxLayout (aFrame);
286 aLay->setMargin(MARGIN);
287 aLay->setSpacing(SPACING);
289 aLay->addWidget(myOkBtn);
290 aLay->addSpacing(10);
291 aLay->addWidget(myApplyBtn);
292 aLay->addSpacing(10);
294 aLay->addWidget(myCloseBtn);
295 aLay->addWidget(myHelpBtn);
300 //=======================================================================
301 // name : SMESHGUI_MultiEditDlg::isValid
302 // Purpose : Verify validity of input data
303 //=======================================================================
304 bool SMESHGUI_MultiEditDlg::isValid (const bool /*theMess*/)
306 return (!myMesh->_is_nil() &&
307 (myListBox->count() > 0 || (myToAllChk->isChecked()/* && myActor*/)));
310 //=======================================================================
311 // name : SMESHGUI_MultiEditDlg::~SMESHGUI_MultiEditDlg
312 // Purpose : Destructor
313 //=======================================================================
314 SMESHGUI_MultiEditDlg::~SMESHGUI_MultiEditDlg()
316 if (myFilterDlg != 0)
318 myFilterDlg->setParent(0);
323 //=======================================================================
324 // name : SMESHGUI_MultiEditDlg::eventFilter
325 // Purpose : event filter
326 //=======================================================================
327 bool SMESHGUI_MultiEditDlg::eventFilter (QObject* object, QEvent* event)
329 if (object == myListBox && event->type() == QEvent::KeyPress) {
330 QKeyEvent* ke = (QKeyEvent*)event;
331 if (ke->key() == Qt::Key_Delete)
334 return QDialog::eventFilter(object, event);
337 //=======================================================================
338 // name : SMESHGUI_MultiEditDlg::getNumericalFunctor
340 //=======================================================================
341 SMESH::NumericalFunctor_ptr SMESHGUI_MultiEditDlg::getNumericalFunctor()
343 SMESH::NumericalFunctor_var aNF = SMESH::NumericalFunctor::_nil();
345 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
346 if (aFilterMgr->_is_nil())
349 if (myComboBoxFunctor->currentText() == tr("ASPECTRATIO_ELEMENTS"))
350 aNF = aFilterMgr->CreateAspectRatio();
351 else if (myComboBoxFunctor->currentText() == tr("WARP_ELEMENTS"))
352 aNF = aFilterMgr->CreateWarping();
353 else if (myComboBoxFunctor->currentText() == tr("MINIMUMANGLE_ELEMENTS"))
354 aNF = aFilterMgr->CreateMinimumAngle();
355 else if (myComboBoxFunctor->currentText() == tr("TAPER_ELEMENTS"))
356 aNF = aFilterMgr->CreateTaper();
357 else if (myComboBoxFunctor->currentText() == tr("SKEW_ELEMENTS"))
358 aNF = aFilterMgr->CreateSkew();
359 else if (myComboBoxFunctor->currentText() == tr("AREA_ELEMENTS"))
360 aNF = aFilterMgr->CreateArea();
361 else if (myComboBoxFunctor->currentText() == tr("LENGTH2D_EDGES"))
362 aNF = aFilterMgr->CreateLength2D();
363 else if (myComboBoxFunctor->currentText() == tr("MULTI2D_BORDERS"))
364 aNF = aFilterMgr->CreateMultiConnection2D();
365 else if (myComboBoxFunctor->currentText() == tr("MIN_DIAG_ELEMENTS"))
366 aNF = aFilterMgr->CreateMaxElementLength2D();
372 //=======================================================================
373 // name : SMESHGUI_MultiEditDlg::Init
374 // Purpose : Init dialog fields, connect signals and slots, show dialog
375 //=======================================================================
376 void SMESHGUI_MultiEditDlg::Init()
378 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
383 emit ListContensChanged();
386 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
387 connect(myCloseBtn, SIGNAL(clicked()), SLOT(reject()));
388 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
389 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
391 // selection and SMESHGUI
392 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
393 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
394 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
397 connect(myFilterBtn, SIGNAL(clicked()), SLOT(onFilterBtn() ));
398 connect(myAddBtn, SIGNAL(clicked()), SLOT(onAddBtn() ));
399 connect(myRemoveBtn, SIGNAL(clicked()), SLOT(onRemoveBtn() ));
400 connect(mySortBtn, SIGNAL(clicked()), SLOT(onSortListBtn()));
402 connect(mySubmeshChk, SIGNAL(stateChanged(int)), SLOT(onSubmeshChk()));
403 connect(myGroupChk, SIGNAL(stateChanged(int)), SLOT(onGroupChk() ));
404 connect(myToAllChk, SIGNAL(stateChanged(int)), SLOT(onToAllChk() ));
407 connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), SLOT(on3d2dChanged(int)));
409 connect(myListBox, SIGNAL(itemSelectionChanged()), SLOT(onListSelectionChanged()));
413 // set selection mode
418 //=======================================================================
419 // name : SMESHGUI_MultiEditDlg::onOk
420 // Purpose : SLOT called when "Ok" button pressed.
421 // Assign filters VTK viewer and close dialog
422 //=======================================================================
423 void SMESHGUI_MultiEditDlg::onOk()
429 //=======================================================================
430 // name : SMESHGUI_MultiEditDlg::getIds
431 // Purpose : Retrive identifiers from list box or the whole object
432 //=======================================================================
434 SMESH::long_array_var SMESHGUI_MultiEditDlg::getIds(SMESH::SMESH_IDSource_var& obj)
436 SMESH::long_array_var anIds = new SMESH::long_array;
438 if (myToAllChk->isChecked())
441 obj = SMESH::SMESH_IDSource::_narrow( myMesh );
442 // SMESH_Actor * anActor = SMESH::FindActorByObject(myMesh);
444 // anActor = myActor;
448 // SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
449 // if( myFilterType == SMESH::TriaFilter ||
450 // myFilterType == SMESH::QuadFilter ||
451 // myFilterType == SMESH::FaceFilter ) {
452 // SMDS_FaceIteratorPtr it = aMesh->facesIterator();
453 // while(it->more()) {
454 // const SMDS_MeshFace* f = it->next();
455 // if(myFilterType == SMESH::FaceFilter) {
456 // myIds.Add(f->GetID());
458 // else if( myFilterType==SMESH::TriaFilter &&
459 // ( f->NbNodes()==3 || f->NbNodes()==6 ) ) {
460 // myIds.Add(f->GetID());
462 // else if( myFilterType==SMESH::QuadFilter &&
463 // ( f->NbNodes()==4 || f->NbNodes()==8 ) ) {
464 // myIds.Add(f->GetID());
468 // else if(myFilterType == SMESH::VolumeFilter) {
469 // SMDS_VolumeIteratorPtr it = aMesh->volumesIterator();
470 // while(it->more()) {
471 // const SMDS_MeshVolume* f = it->next();
472 // myIds.Add(f->GetID());
475 /* commented by skl 07.02.2006 - to work with quadratic elements
476 TVisualObjPtr aVisualObj = anActor->GetObject();
477 vtkUnstructuredGrid* aGrid = aVisualObj->GetUnstructuredGrid();
479 for (int i = 0, n = aGrid->GetNumberOfCells(); i < n; i++) {
480 vtkCell* aCell = aGrid->GetCell(i);
482 vtkTriangle* aTri = vtkTriangle::SafeDownCast(aCell);
483 vtkQuad* aQua = vtkQuad::SafeDownCast(aCell);
484 vtkPolygon* aPG = vtkPolygon::SafeDownCast(aCell);
486 vtkCell3D* a3d = vtkCell3D::SafeDownCast(aCell);
487 vtkConvexPointSet* aPH = vtkConvexPointSet::SafeDownCast(aCell);
489 if (aTri && myFilterType == SMESHGUI_TriaFilter ||
490 aQua && myFilterType == SMESHGUI_QuadFilter ||
491 (aTri || aQua || aPG) && myFilterType == SMESHGUI_FaceFilter ||
492 (a3d || aPH) && myFilterType == SMESHGUI_VolumeFilter) {
493 int anObjId = aVisualObj->GetElemObjId(i);
503 anIds->length(myIds.Extent());
504 TColStd_MapIteratorOfMapOfInteger anIter(myIds);
505 for (int i = 0; anIter.More(); anIter.Next() )
507 anIds[ i++ ] = anIter.Key();
509 return anIds._retn();
512 //=======================================================================
513 // name : SMESHGUI_MultiEditDlg::reject
514 // Purpose : SLOT called when "Close" button pressed. Close dialog
515 //=======================================================================
516 void SMESHGUI_MultiEditDlg::reject()
518 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
519 aViewWindow->SetSelectionMode(ActorSelection);
520 disconnect(mySelectionMgr, 0, this, 0);
521 disconnect(mySMESHGUI, 0, this, 0);
522 mySMESHGUI->ResetState();
524 SMESH::RemoveFilters();
525 SMESH::SetPickable();
527 //mySelectionMgr->clearSelected();
528 mySelectionMgr->clearFilters();
533 //=================================================================================
534 // function : onHelp()
536 //=================================================================================
537 void SMESHGUI_MultiEditDlg::onHelp()
539 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
541 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
545 platform = "winapplication";
547 platform = "application";
549 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
550 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
551 arg(app->resourceMgr()->stringValue("ExternalBrowser",
553 arg(myHelpFileName));
557 //=======================================================================
558 // name : SMESHGUI_MultiEditDlg::onSelectionDone
559 // Purpose : SLOT called when selection changed
560 //=======================================================================
561 void SMESHGUI_MultiEditDlg::onSelectionDone()
563 if (myBusy || !isEnabled()) return;
566 const SALOME_ListIO& aList = mySelector->StoredIObjects();
568 int nbSel = aList.Extent();
569 myListBox->clearSelection();
571 if (mySubmeshChk->isChecked() || myGroupChk->isChecked()) {
572 QLineEdit* aNameEdit = mySubmeshChk->isChecked() ? mySubmesh : myGroup;
574 Handle(SALOME_InteractiveObject) anIO = aList.First();
576 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
577 anIO.IsNull() ? aNameEdit->clear() : aNameEdit->setText(aName);
579 if (mySubmeshChk->isChecked()) {
580 SMESH::SMESH_subMesh_var aSubMesh =
581 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIO);
582 if (!aSubMesh->_is_nil())
583 myMesh = aSubMesh->GetFather();
585 SMESH::SMESH_GroupBase_var aGroup =
586 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIO);
587 if (!aGroup->_is_nil())
588 myMesh = aGroup->GetMesh();
590 } else if (nbSel > 1) {
591 QString aStr = mySubmeshChk->isChecked() ?
592 tr("SMESH_SUBMESH_SELECTED") : tr("SMESH_GROUP_SELECTED");
593 aNameEdit->setText(aStr.arg(nbSel));
597 } else if (nbSel > 0) {
598 QString aListStr = "";
599 Handle(SALOME_InteractiveObject) anIO = aList.First();
600 int aNbItems = SMESH::GetNameOfSelectedElements(mySelector,anIO,aListStr);
602 QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
603 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
604 QList<QListWidgetItem*> items = myListBox->findItems(*it, Qt::MatchExactly);
605 QListWidgetItem* anItem;
606 foreach(anItem, items)
607 anItem->setSelected(true);
610 myMesh = SMESH::GetMeshByIO(anIO);
614 myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
616 myActor = SMESH::FindActorByObject(myMesh);
617 SVTK_Selector* aSelector = SMESH::GetSelector();
618 Handle(VTKViewer_Filter) aFilter = aSelector->GetFilter(myFilterType);
619 if (!aFilter.IsNull())
620 aFilter->SetActor(myActor);
627 //=======================================================================
628 // name : SMESHGUI_MultiEditDlg::onDeactivate
629 // Purpose : SLOT called when dialog must be deativated
630 //=======================================================================
631 void SMESHGUI_MultiEditDlg::onDeactivate()
636 //=======================================================================
637 // name : SMESHGUI_MultiEditDlg::enterEvent
638 // Purpose : Event filter
639 //=======================================================================
640 void SMESHGUI_MultiEditDlg::enterEvent (QEvent*)
643 mySMESHGUI->EmitSignalDeactivateDialog();
649 //=======================================================================
650 // name : SMESHGUI_MultiEditDlg::onFilterBtn
651 // Purpose : SLOT. Called when "Filter" button pressed.
652 // Start "Selection filters" dialog
653 //=======================================================================
654 void SMESHGUI_MultiEditDlg::onFilterBtn()
656 if (myFilterDlg == 0) {
657 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, entityType() ? SMESH::VOLUME : SMESH::FACE);
658 connect(myFilterDlg, SIGNAL(Accepted()), SLOT(onFilterAccepted()));
660 myFilterDlg->Init(entityType() ? SMESH::VOLUME : SMESH::FACE);
663 myFilterDlg->SetSelection();
664 myFilterDlg->SetMesh(myMesh);
665 myFilterDlg->SetSourceWg(myListBox);
670 //=======================================================================
671 // name : onFilterAccepted()
672 // Purpose : SLOT. Called when Filter dlg closed with OK button.
673 // Uncheck "Select submesh" and "Select group" checkboxes
674 //=======================================================================
675 void SMESHGUI_MultiEditDlg::onFilterAccepted()
678 for (int i = 0, n = myListBox->count(); i < n; i++)
679 myIds.Add(myListBox->item(i)->text().toInt());
681 emit ListContensChanged();
683 if (mySubmeshChk->isChecked() || myGroupChk->isChecked()) {
684 mySubmeshChk->blockSignals(true);
685 myGroupChk->blockSignals(true);
686 mySubmeshChk->setChecked(false);
687 myGroupChk->setChecked(false);
688 mySubmeshChk->blockSignals(false);
689 myGroupChk->blockSignals(false);
694 //=======================================================================
695 // name : SMESHGUI_MultiEditDlg::isIdValid
696 // Purpose : Verify whether Id of element satisfies to filters from viewer
697 //=======================================================================
698 bool SMESHGUI_MultiEditDlg::isIdValid (const int theId) const
700 SVTK_Selector* aSelector = SMESH::GetSelector();
701 Handle(SMESHGUI_Filter) aFilter =
702 Handle(SMESHGUI_Filter)::DownCast(aSelector->GetFilter(myFilterType));
704 return (!aFilter.IsNull() && aFilter->IsObjValid(theId));
707 //=======================================================================
708 // name : SMESHGUI_MultiEditDlg::onAddBtn
709 // Purpose : SLOT. Called when "Add" button pressed.
710 // Add selected in viewer entities in list box
711 //=======================================================================
712 void SMESHGUI_MultiEditDlg::onAddBtn()
714 const SALOME_ListIO& aList = mySelector->StoredIObjects();
716 int nbSelected = aList.Extent();
720 TColStd_IndexedMapOfInteger toBeAdded;
722 if (!mySubmeshChk->isChecked() && !myGroupChk->isChecked()) {
724 mySelector->GetIndex(aList.First(),toBeAdded);
725 } else if (mySubmeshChk->isChecked()) {
726 SALOME_ListIteratorOfListIO anIter(aList);
727 for ( ; anIter.More(); anIter.Next()) {
728 SMESH::SMESH_subMesh_var aSubMesh =
729 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Value());
730 if (!aSubMesh->_is_nil()) {
731 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
732 SMESH::long_array_var anIds = aSubMesh->GetElementsId();
733 for (int i = 0, n = anIds->length(); i < n; i++) {
734 if (isIdValid(anIds[ i ]))
735 toBeAdded.Add(anIds[ i ]);
740 } else if (myGroupChk->isChecked()) {
741 SALOME_ListIteratorOfListIO anIter(aList);
742 for ( ; anIter.More(); anIter.Next()) {
743 SMESH::SMESH_GroupBase_var aGroup =
744 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
745 if (!aGroup->_is_nil() && ((aGroup->GetType() == SMESH::FACE && entityType() == 0) ||
746 (aGroup->GetType() == SMESH::VOLUME && entityType() == 1))) {
747 if (aGroup->GetMesh()->GetId() == myMesh->GetId()) {
748 SMESH::long_array_var anIds = aGroup->GetListOfID();
749 for (int i = 0, n = anIds->length(); i < n; i++) {
750 if (isIdValid(anIds[ i ]))
751 toBeAdded.Add(anIds[ i ]);
760 bool isGroupOrSubmesh = (mySubmeshChk->isChecked() || myGroupChk->isChecked());
761 mySubmeshChk->setChecked(false);
762 myGroupChk->setChecked(false);
764 for(int i = 1; i <= toBeAdded.Extent(); i++)
765 if (myIds.Add(toBeAdded(i))) {
766 items.append(QString("%1").arg(toBeAdded(i)));
768 myListBox->addItems(items);
769 myListBox->selectAll();
772 emit ListContensChanged();
774 if (isGroupOrSubmesh)
775 onListSelectionChanged();
780 //=======================================================================
781 // name : SMESHGUI_MultiEditDlg::updateButtons
782 // Purpose : Enable/disable buttons of dialog in accordance with current state
783 //=======================================================================
784 void SMESHGUI_MultiEditDlg::updateButtons()
786 bool isOk = isValid(false);
787 myOkBtn->setEnabled(isOk);
788 myApplyBtn->setEnabled(isOk);
790 bool isListBoxNonEmpty = myListBox->count() > 0;
791 bool isToAll = myToAllChk->isChecked();
792 myFilterBtn->setEnabled(!isToAll);
793 myRemoveBtn->setEnabled(isListBoxNonEmpty && !isToAll);
794 mySortBtn->setEnabled(isListBoxNonEmpty &&!isToAll);
796 const SALOME_ListIO& aList = mySelector->StoredIObjects();
800 aList.Extent() < 1 ||
801 (SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(aList.First())->_is_nil() &&
802 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(aList.First())->_is_nil() &&
803 SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First())->_is_nil()))
804 myAddBtn->setEnabled(false);
806 myAddBtn->setEnabled(true);
808 mySubmeshChk->setEnabled(!isToAll);
809 mySubmeshBtn->setEnabled(mySubmeshChk->isChecked());
810 mySubmesh->setEnabled(mySubmeshChk->isChecked());
812 myGroupChk->setEnabled(!isToAll);
813 myGroupBtn->setEnabled(myGroupChk->isChecked());
814 myGroup->setEnabled(myGroupChk->isChecked());
816 if (!mySubmeshChk->isChecked())
818 if (!myGroupChk->isChecked())
823 //=======================================================================
824 // name : SMESHGUI_MultiEditDlg::onRemoveBtn
825 // Purpose : SLOT. Called when "Remove" button pressed.
826 // Remove selected in list box entities
827 //=======================================================================
828 void SMESHGUI_MultiEditDlg::onRemoveBtn()
832 QList<QListWidgetItem*> selItems = myListBox->selectedItems();
833 QListWidgetItem* item;
834 foreach(item, selItems)
836 myIds.Remove(item->text().toInt());
842 emit ListContensChanged();
846 //=======================================================================
847 // name : SMESHGUI_MultiEditDlg::onSortListBtn
848 // Purpose : SLOT. Called when "Sort list" button pressed.
849 // Sort entities of list box
850 //=======================================================================
851 void SMESHGUI_MultiEditDlg::onSortListBtn()
855 int i, k = myListBox->count();
858 QList<int> aSelected;
859 std::vector<int> anArray(k);
860 for (i = 0; i < k; i++)
862 int id = myListBox->item(i)->text().toInt();
864 if (myListBox->item(i)->isSelected())
865 aSelected.append(id);
868 std::sort(anArray.begin(), anArray.end());
871 for (i = 0; i < k; i++) {
872 QListWidgetItem* item = new QListWidgetItem(QString::number(anArray[i]));
873 myListBox->addItem(item);
874 item->setSelected(aSelected.contains(anArray[i]));
880 //=======================================================================
881 // name : SMESHGUI_MultiEditDlg::onListSelectionChanged
882 // Purpose : SLOT. Called when selection in list box changed.
883 // Highlight in selected entities
884 //=======================================================================
885 void SMESHGUI_MultiEditDlg::onListSelectionChanged()
887 if (myActor == 0 || myBusy)
890 if (mySubmeshChk->isChecked() || myGroupChk->isChecked())
893 SMESH_Actor * anActor = SMESH::FindActorByObject(myMesh);
896 TVisualObjPtr anObj = anActor->GetObject();
898 TColStd_MapOfInteger anIndexes;
899 int total = myListBox->count();
900 for (int i = 0; i < total; i++)
902 if (myListBox->item(i)->isSelected())
904 int anId = myListBox->item(i)->text().toInt();
905 if (anObj->GetElemVTKId(anId) >= 0) // avoid exception in hilight
910 mySelector->AddOrRemoveIndex(anActor->getIO(),anIndexes,false);
911 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
912 aViewWindow->highlight(anActor->getIO(),true,true);
915 //=======================================================================
916 // name : SMESHGUI_MultiEditDlg::onSubmeshChk
917 // Purpose : SLOT. Called when state of "SubMesh" check box changed.
918 // Activate/deactivate selection of submeshes
919 //=======================================================================
920 void SMESHGUI_MultiEditDlg::onSubmeshChk()
922 bool isChecked = mySubmeshChk->isChecked();
923 mySubmeshBtn->setEnabled(isChecked);
924 mySubmesh->setEnabled(isChecked);
927 if (isChecked && myGroupChk->isChecked())
928 myGroupChk->setChecked(false);
933 //=======================================================================
934 // name : SMESHGUI_MultiEditDlg::onGroupChk
935 // Purpose : SLOT. Called when state of "Group" check box changed.
936 // Activate/deactivate selection of groupes
937 //=======================================================================
938 void SMESHGUI_MultiEditDlg::onGroupChk()
940 bool isChecked = myGroupChk->isChecked();
941 myGroupBtn->setEnabled(isChecked);
942 myGroup->setEnabled(isChecked);
945 if (isChecked && mySubmeshChk->isChecked())
946 mySubmeshChk->setChecked(false);
951 //=======================================================================
952 // name : SMESHGUI_MultiEditDlg::onToAllChk
953 // Purpose : SLOT. Called when state of "Apply to all" check box changed.
954 // Activate/deactivate selection
955 //=======================================================================
956 void SMESHGUI_MultiEditDlg::onToAllChk()
958 bool isChecked = myToAllChk->isChecked();
965 emit ListContensChanged();
971 //=======================================================================
972 // name : SMESHGUI_MultiEditDlg::setSelectionMode
973 // Purpose : Set selection mode
974 //=======================================================================
975 void SMESHGUI_MultiEditDlg::setSelectionMode()
977 SMESH::RemoveFilters();
979 mySelectionMgr->clearSelected();
980 mySelectionMgr->clearFilters();
982 if (mySubmeshChk->isChecked()) {
983 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
984 aViewWindow->SetSelectionMode(ActorSelection);
985 mySelectionMgr->installFilter(new SMESH_TypeFilter(SMESH::SUBMESH));
987 else if (myGroupChk->isChecked()) {
988 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
989 aViewWindow->SetSelectionMode(ActorSelection);
990 mySelectionMgr->installFilter(new SMESH_TypeFilter(SMESH::GROUP));
994 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
995 aViewWindow->SetSelectionMode(VolumeSelection);
996 SMESH::SetFilter(new SMESHGUI_VolumesFilter());
998 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
999 aViewWindow->SetSelectionMode(FaceSelection);
1000 if (myFilterType == SMESH::TriaFilter)
1001 SMESH::SetFilter(new SMESHGUI_TriangleFilter());
1002 else if (myFilterType == SMESH::QuadFilter)
1003 SMESH::SetFilter(new SMESHGUI_QuadrangleFilter());
1005 SMESH::SetFilter(new SMESHGUI_FacesFilter());
1009 //=======================================================================
1010 // name : SMESHGUI_MultiEditDlg::onApply
1011 // Purpose : SLOT. Called when "Apply" button clicked.
1012 //=======================================================================
1013 bool SMESHGUI_MultiEditDlg::onApply()
1015 if (mySMESHGUI->isActiveStudyLocked())
1020 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
1021 if (aMeshEditor->_is_nil())
1026 SUIT_OverrideCursor aWaitCursor;
1028 SMESH::SMESH_IDSource_var obj;
1029 SMESH::long_array_var anIds = getIds(obj);
1031 bool aResult = process(aMeshEditor, anIds.inout(), obj);
1035 mySelectionMgr->selectedObjects( sel );
1036 mySelector->ClearIndex();
1037 mySelectionMgr->setSelectedObjects( sel );
1038 SMESH::UpdateView();
1039 SMESHGUI::Modified();
1044 emit ListContensChanged();
1053 //=======================================================================
1054 // name : SMESHGUI_MultiEditDlg::on3d2dChanged
1056 //=======================================================================
1057 void SMESHGUI_MultiEditDlg::on3d2dChanged (int type)
1059 if (myEntityType != type) {
1060 myEntityType = type;
1065 emit ListContensChanged();
1068 myFilterType = SMESH::VolumeFilter;
1070 myFilterType = SMESH::FaceFilter;
1077 //=======================================================================
1078 // name : SMESHGUI_MultiEditDlg::entityType
1080 //=======================================================================
1081 int SMESHGUI_MultiEditDlg::entityType()
1083 return myEntityType;
1086 //=================================================================================
1087 // function : keyPressEvent()
1089 //=================================================================================
1090 void SMESHGUI_MultiEditDlg::keyPressEvent( QKeyEvent* e )
1092 QDialog::keyPressEvent( e );
1093 if ( e->isAccepted() )
1096 if ( e->key() == Qt::Key_F1 ) {
1103 * Class : SMESHGUI_ChangeOrientationDlg
1104 * Description : Modification of orientation of faces
1107 SMESHGUI_ChangeOrientationDlg
1108 ::SMESHGUI_ChangeOrientationDlg(SMESHGUI* theModule):
1109 SMESHGUI_MultiEditDlg(theModule, SMESH::FaceFilter, true)
1111 setWindowTitle(tr("CAPTION"));
1112 myHelpFileName = "changing_orientation_of_elements_page.html";
1115 SMESHGUI_ChangeOrientationDlg::~SMESHGUI_ChangeOrientationDlg()
1119 bool SMESHGUI_ChangeOrientationDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
1120 const SMESH::long_array& theIds,
1121 SMESH::SMESH_IDSource_ptr obj)
1123 if ( CORBA::is_nil( obj ))
1124 return theEditor->Reorient(theIds);
1126 return theEditor->ReorientObject( obj );
1130 * Class : SMESHGUI_UnionOfTrianglesDlg
1131 * Description : Construction of quadrangles by automatic association of triangles
1134 SMESHGUI_UnionOfTrianglesDlg
1135 ::SMESHGUI_UnionOfTrianglesDlg(SMESHGUI* theModule):
1136 SMESHGUI_MultiEditDlg(theModule, SMESH::TriaFilter, false)
1138 setWindowTitle(tr("CAPTION"));
1140 myComboBoxFunctor->setEnabled(true);
1141 myComboBoxFunctor->addItem(tr("AREA_ELEMENTS"));
1142 myComboBoxFunctor->addItem(tr("WARP_ELEMENTS")); // for quadrangles only
1143 myComboBoxFunctor->addItem(tr("TAPER_ELEMENTS")); // for quadrangles only
1146 QWidget* aMaxAngleGrp = new QWidget(myCriterionGrp);
1147 QHBoxLayout* aMaxAngleGrpLayout = new QHBoxLayout(aMaxAngleGrp);
1148 aMaxAngleGrpLayout->setMargin(0);
1149 aMaxAngleGrpLayout->setSpacing(SPACING);
1151 QLabel* aLab = new QLabel (tr("MAXIMUM_ANGLE"), aMaxAngleGrp);
1152 myMaxAngleSpin = new SMESHGUI_SpinBox (aMaxAngleGrp);
1153 myMaxAngleSpin->RangeStepAndValidator(0, 180.0, 1.0, "angle_precision");
1154 myMaxAngleSpin->SetValue(30.0);
1156 aMaxAngleGrpLayout->addWidget(aLab);
1157 aMaxAngleGrpLayout->addWidget(myMaxAngleSpin);
1159 ((QVBoxLayout*)(myCriterionGrp->layout()))->addWidget(aMaxAngleGrp);
1160 myCriterionGrp->show();
1162 myHelpFileName = "uniting_set_of_triangles_page.html";
1165 SMESHGUI_UnionOfTrianglesDlg::~SMESHGUI_UnionOfTrianglesDlg()
1169 bool SMESHGUI_UnionOfTrianglesDlg::isValid (const bool theMess)
1171 bool ok = SMESHGUI_MultiEditDlg::isValid( theMess );
1176 ok = myMaxAngleSpin->isValid( msg, theMess );
1179 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1180 if ( !msg.isEmpty() )
1182 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1190 bool SMESHGUI_UnionOfTrianglesDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
1191 const SMESH::long_array& theIds,
1192 SMESH::SMESH_IDSource_ptr obj)
1195 QStringList aParameters;
1196 aParameters << myMaxAngleSpin->text();
1197 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
1199 SMESH::NumericalFunctor_var aCriterion = getNumericalFunctor();
1200 double aMaxAngle = myMaxAngleSpin->GetValue() * M_PI / 180.0;
1202 if ( CORBA::is_nil( obj ))
1203 ok = theEditor->TriToQuad(theIds, aCriterion, aMaxAngle);
1205 ok = theEditor->TriToQuadObject(obj, aCriterion, aMaxAngle);
1211 * Class : SMESHGUI_CuttingOfQuadsDlg
1212 * Description : Automatic splitting of quadrangles into triangles
1215 SMESHGUI_CuttingOfQuadsDlg
1216 ::SMESHGUI_CuttingOfQuadsDlg(SMESHGUI* theModule):
1217 SMESHGUI_MultiEditDlg(theModule, SMESH::QuadFilter, false)
1219 setWindowTitle(tr("CAPTION"));
1222 myPreviewChk = new QCheckBox (tr("PREVIEW"), mySelGrp);
1223 QGridLayout* aLay = (QGridLayout*)(mySelGrp->layout());
1224 aLay->addWidget(myPreviewChk, aLay->rowCount(), 0, 1, aLay->columnCount());
1226 myCriterionGrp->show();
1227 myChoiceWidget->show();
1228 myComboBoxFunctor->insertItem(0, tr("MIN_DIAG_ELEMENTS"));
1229 myComboBoxFunctor->setCurrentIndex(0);
1230 myComboBoxFunctor->setEnabled(false);
1232 connect(myPreviewChk, SIGNAL(stateChanged(int)), this, SLOT(onPreviewChk()));
1233 connect(myGroupChoice, SIGNAL(buttonClicked(int)), this, SLOT(onCriterionRB()));
1234 connect(myComboBoxFunctor, SIGNAL(activated(int)), this, SLOT(onPreviewChk()));
1235 connect(this, SIGNAL(ListContensChanged()), this, SLOT(onPreviewChk()));
1237 myHelpFileName = "cutting_quadrangles_page.html";
1240 SMESHGUI_CuttingOfQuadsDlg::~SMESHGUI_CuttingOfQuadsDlg()
1244 void SMESHGUI_CuttingOfQuadsDlg::reject()
1247 SMESHGUI_MultiEditDlg::reject();
1250 bool SMESHGUI_CuttingOfQuadsDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
1251 const SMESH::long_array& theIds,
1252 SMESH::SMESH_IDSource_ptr obj)
1254 bool hasObj = (! CORBA::is_nil( obj ));
1255 switch (myGroupChoice->checkedId()) {
1256 case 0: // use diagonal 1-3
1257 return hasObj ? theEditor->SplitQuadObject(obj, true) : theEditor->SplitQuad(theIds, true);
1258 case 1: // use diagonal 2-4
1259 return hasObj ? theEditor->SplitQuadObject(obj, false) : theEditor->SplitQuad(theIds, false);
1260 default: // use numeric functor
1264 SMESH::NumericalFunctor_var aCrit = getNumericalFunctor();
1265 return hasObj ? theEditor->QuadToTriObject(obj, aCrit) : theEditor->QuadToTri(theIds, aCrit);
1268 void SMESHGUI_CuttingOfQuadsDlg::onCriterionRB()
1270 if (myGroupChoice->checkedId() == 2) // Use numeric functor
1271 myComboBoxFunctor->setEnabled(true);
1273 myComboBoxFunctor->setEnabled(false);
1278 void SMESHGUI_CuttingOfQuadsDlg::onPreviewChk()
1280 myPreviewChk->isChecked() ? displayPreview() : erasePreview();
1283 void SMESHGUI_CuttingOfQuadsDlg::erasePreview()
1285 if (myPreviewActor == 0)
1288 if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView()) {
1289 vf->RemoveActor(myPreviewActor);
1292 myPreviewActor->Delete();
1296 void SMESHGUI_CuttingOfQuadsDlg::displayPreview()
1301 if (myPreviewActor != 0)
1304 // get Ids of elements
1305 SMESH::SMESH_IDSource_var obj;
1306 SMESH::long_array_var anElemIds = getIds(obj);
1307 if (anElemIds->length() == 0 && obj->_is_nil() )
1310 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
1314 // 0 - use diagonal 1-3, 1 - use diagonal 2-4, 2 - use numerical functor
1315 int aChoice = myGroupChoice->checkedId();
1316 SMESH::NumericalFunctor_var aCriterion = SMESH::NumericalFunctor::_nil();
1317 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH::SMESH_MeshEditor::_nil();
1319 aCriterion = getNumericalFunctor();
1320 aMeshEditor = myMesh->GetMeshEditor();
1321 if (aMeshEditor->_is_nil())
1326 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
1328 vtkIdType aNbCells = anElemIds->length() * 2;
1329 vtkIdType aCellsSize = 4 * aNbCells;
1330 vtkCellArray* aConnectivity = vtkCellArray::New();
1331 aConnectivity->Allocate(aCellsSize, 0);
1333 vtkPoints* aPoints = vtkPoints::New();
1334 aPoints->SetNumberOfPoints(anElemIds->length() * 4);
1336 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
1337 aCellTypesArray->SetNumberOfComponents(1);
1338 aCellTypesArray->Allocate(aNbCells * aCellTypesArray->GetNumberOfComponents());
1340 vtkIdList *anIdList = vtkIdList::New();
1341 anIdList->SetNumberOfIds(3);
1343 TColStd_DataMapOfIntegerInteger anIdToVtk;
1347 for (int i = 0, n = anElemIds->length(); i < n; i++)
1349 const SMDS_MeshElement* anElem = aMesh->FindElement(anElemIds[ i ]);
1350 if (anElem == 0 || anElem->NbNodes() != 4)
1353 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
1355 while (anIter->more()) {
1356 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIter->next());
1359 if (!anIdToVtk.IsBound(aNode->GetID()))
1361 aPoints->SetPoint(++nbPoints, aNode->X(), aNode->Y(), aNode->Z());
1362 anIdToVtk.Bind(aNode->GetID(), nbPoints);
1365 aNodes[ k++ ] = aNode->GetID();
1372 bool isDiag13 = true;
1373 if (aChoice == 0) // use diagonal 1-3
1377 else if (aChoice == 1) // use diagonal 2-4
1381 else // use numerical functor
1383 // compare two sets of possible triangles
1384 int diag = aMeshEditor->BestSplit(anElemIds[i], aCriterion);
1385 if (diag == 1) // 1-3
1387 else if (diag == 2) // 2-4
1395 anIdList->SetId(0, anIdToVtk(aNodes[ 0 ]));
1396 anIdList->SetId(1, anIdToVtk(aNodes[ 1 ]));
1397 anIdList->SetId(2, anIdToVtk(aNodes[ 2 ]));
1398 aConnectivity->InsertNextCell(anIdList);
1399 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1401 anIdList->SetId(0, anIdToVtk(aNodes[ 2 ]));
1402 anIdList->SetId(1, anIdToVtk(aNodes[ 3 ]));
1403 anIdList->SetId(2, anIdToVtk(aNodes[ 0 ]));
1404 aConnectivity->InsertNextCell(anIdList);
1405 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1409 anIdList->SetId(0, anIdToVtk(aNodes[ 1 ]));
1410 anIdList->SetId(1, anIdToVtk(aNodes[ 2 ]));
1411 anIdList->SetId(2, anIdToVtk(aNodes[ 3 ]));
1412 aConnectivity->InsertNextCell(anIdList);
1413 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1415 anIdList->SetId(0, anIdToVtk(aNodes[ 3 ]));
1416 anIdList->SetId(1, anIdToVtk(aNodes[ 0 ]));
1417 anIdList->SetId(2, anIdToVtk(aNodes[ 1 ]));
1418 aConnectivity->InsertNextCell(anIdList);
1419 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1423 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
1424 aCellLocationsArray->SetNumberOfComponents(1);
1425 aCellLocationsArray->SetNumberOfTuples(aNbCells);
1427 aConnectivity->InitTraversal();
1428 for(vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell(npts, pts); idType++)
1429 aCellLocationsArray->SetValue(idType, aConnectivity->GetTraversalLocation(npts));
1431 aGrid->SetPoints(aPoints);
1432 aGrid->SetCells(aCellTypesArray, aCellLocationsArray,aConnectivity);
1434 // Create and display actor
1435 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
1436 aMapper->SetInput(aGrid);
1438 myPreviewActor = SALOME_Actor::New();
1439 myPreviewActor->PickableOff();
1440 myPreviewActor->SetMapper(aMapper);
1442 vtkProperty* aProp = vtkProperty::New();
1443 aProp->SetRepresentationToWireframe();
1444 aProp->SetColor(250, 0, 250);
1445 aProp->SetLineWidth(myActor->GetLineWidth() + 1);
1446 myPreviewActor->SetProperty(aProp);
1448 SMESH::GetCurrentVtkView()->AddActor(myPreviewActor);
1449 SMESH::GetCurrentVtkView()->Repaint();
1453 aConnectivity->Delete();
1457 aCellTypesArray->Delete();
1458 aCellLocationsArray->Delete();
1462 * Class : SMESHGUI_CuttingIntoTetraDlg
1463 * Description : Modification of orientation of faces
1466 SMESHGUI_CuttingIntoTetraDlg::SMESHGUI_CuttingIntoTetraDlg(SMESHGUI* theModule)
1467 : SMESHGUI_MultiEditDlg(theModule, SMESH::VolumeFilter, false)
1469 setWindowTitle(tr("CAPTION"));
1470 myHelpFileName = "split_to_tetra_page.html";
1473 myToAllChk->setChecked( true ); //aplly to the whole mesh by default
1475 bool hasHexa = true;//myMesh->_is_nil() ? false : myMesh->NbHexas();
1479 myGroupChoice->button(0)->setText( tr("SPLIT_HEX_TO_5_TETRA"));
1480 myGroupChoice->button(1)->setText( tr("SPLIT_HEX_TO_6_TETRA"));
1481 myGroupChoice->button(2)->setText( tr("SPLIT_HEX_TO_24_TETRA"));
1483 myCriterionGrp->setTitle( tr("SPLIT_METHOD"));
1484 myCriterionGrp->show();
1485 myComboBoxFunctor->hide();
1486 myChoiceWidget->show();
1492 SMESHGUI_CuttingIntoTetraDlg::~SMESHGUI_CuttingIntoTetraDlg()
1496 bool SMESHGUI_CuttingIntoTetraDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
1497 const SMESH::long_array& theIds,
1498 SMESH::SMESH_IDSource_ptr theObj)
1500 SMESH::SMESH_IDSource_var obj = theObj;
1501 if ( CORBA::is_nil( obj ))
1502 obj = theEditor->MakeIDSource( theIds, myEntityType ? SMESH::VOLUME : SMESH::FACE );
1504 theEditor->SplitVolumesIntoTetra( obj, myGroupChoice->checkedId()+1 );
1506 catch ( const SALOME::SALOME_Exception& S_ex ) {
1507 SalomeApp_Tools::QtCatchCorbaException( S_ex );