1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_MultiEditDlg.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_MultiEditDlg.h"
29 #include "SMESHGUI_Filter.h"
30 #include "SMESHGUI_FilterDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_SpinBox.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
47 #include <LightApp_SelectionMgr.h>
48 #include <LightApp_Application.h>
49 #include <SALOME_ListIO.hxx>
50 #include <SALOME_ListIteratorOfListIO.hxx>
52 #include <SVTK_Selector.h>
53 #include <SVTK_ViewWindow.h>
54 #include <VTKViewer_CellLocationsArray.h>
57 #include <TColStd_IndexedMapOfInteger.hxx>
58 #include <TColStd_DataMapOfIntegerInteger.hxx>
59 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
62 #include <vtkIdList.h>
63 #include <vtkCellArray.h>
64 #include <vtkUnsignedCharArray.h>
65 #include <vtkUnstructuredGrid.h>
66 #include <vtkDataSetMapper.h>
67 #include <vtkProperty.h>
71 #include <QVBoxLayout>
72 #include <QHBoxLayout>
73 #include <QGridLayout>
74 #include <QListWidget>
79 #include <QPushButton>
80 #include <QButtonGroup>
81 #include <QRadioButton>
85 #include <SALOMEconfig.h>
86 #include CORBA_SERVER_HEADER(SMESH_Group)
92 * Class : SMESHGUI_MultiEditDlg
93 * Description : Description : Inversion of the diagonal of a pseudo-quadrangle formed by
94 * 2 neighboring triangles with 1 common edge
97 //=======================================================================
98 // name : SMESHGUI_MultiEditDlg::SMESHGUI_MultiEditDlg
99 // Purpose : Constructor
100 //=======================================================================
101 SMESHGUI_MultiEditDlg
102 ::SMESHGUI_MultiEditDlg(SMESHGUI* theModule,
105 QDialog(SMESH::GetDesktop(theModule)),
106 SMESHGUI_Helper(theModule),
107 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
108 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
109 mySMESHGUI(theModule)
112 setAttribute(Qt::WA_DeleteOnClose, true);
117 myFilterType = theMode;
118 QVBoxLayout* aDlgLay = new QVBoxLayout(this);
119 aDlgLay->setMargin(MARGIN);
120 aDlgLay->setSpacing(SPACING);
122 QWidget* aMainFrame = createMainFrame (this, the3d2d);
123 QWidget* aBtnFrame = createButtonFrame(this);
125 aDlgLay->addWidget(aMainFrame);
126 aDlgLay->addWidget(aBtnFrame);
131 //=======================================================================
132 // name : SMESHGUI_MultiEditDlg::createMainFrame
133 // Purpose : Create frame containing dialog's input fields
134 //=======================================================================
135 QWidget* SMESHGUI_MultiEditDlg::createMainFrame (QWidget* theParent, const bool the3d2d)
137 QWidget* aMainGrp = new QWidget(theParent);
138 QVBoxLayout* aMainGrpLayout = new QVBoxLayout(aMainGrp);
139 aMainGrpLayout->setMargin(0);
140 aMainGrpLayout->setSpacing(SPACING);
142 QPixmap aPix (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
144 // "Selected cells" group
145 mySelGrp = new QGroupBox(aMainGrp);
147 QGridLayout* mySelGrpLayout = new QGridLayout(mySelGrp);
148 mySelGrpLayout->setMargin(MARGIN);
149 mySelGrpLayout->setSpacing(SPACING);
153 QGroupBox* aEntityTypeGrp = new QGroupBox(tr("SMESH_ELEMENTS_TYPE"), mySelGrp);
154 myEntityTypeGrp = new QButtonGroup(mySelGrp);
155 QHBoxLayout* aEntityLayout = new QHBoxLayout(aEntityTypeGrp);
156 aEntityLayout->setMargin(MARGIN);
157 aEntityLayout->setSpacing(SPACING);
159 QRadioButton* aFaceRb = new QRadioButton(tr("SMESH_FACE"), aEntityTypeGrp);
160 QRadioButton* aVolumeRb = new QRadioButton(tr("SMESH_VOLUME"), aEntityTypeGrp);
162 aEntityLayout->addWidget(aFaceRb);
163 aEntityLayout->addWidget(aVolumeRb);
165 myEntityTypeGrp->addButton(aFaceRb, 0);
166 myEntityTypeGrp->addButton(aVolumeRb, 1);
167 aFaceRb->setChecked(true);
168 myEntityType = myEntityTypeGrp->checkedId();
170 mySelGrpLayout->addWidget(aEntityTypeGrp, 0, 0, 1, 2);
173 myListBox = new QListWidget(mySelGrp);
174 myListBox->setSelectionMode(QListWidget::ExtendedSelection);
175 myListBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
176 myListBox->installEventFilter(this);
178 myFilterBtn = new QPushButton(tr("FILTER"), mySelGrp);
179 myAddBtn = new QPushButton(tr("ADD"), mySelGrp);
180 myRemoveBtn = new QPushButton(tr("REMOVE"), mySelGrp);
181 mySortBtn = new QPushButton(tr("SORT_LIST"), mySelGrp);
183 int row = mySelGrpLayout->rowCount();
184 mySelGrpLayout->addWidget(myListBox, row, 0, 6, 1);
185 mySelGrpLayout->addWidget(myFilterBtn, row, 1);
186 mySelGrpLayout->addWidget(myAddBtn, row+2, 1);
187 mySelGrpLayout->addWidget(myRemoveBtn, row+3, 1);
188 mySelGrpLayout->addWidget(mySortBtn, row+5, 1);
189 mySelGrpLayout->setRowMinimumHeight(row+1, 10);
190 mySelGrpLayout->setRowMinimumHeight(row+4, 10);
191 mySelGrpLayout->setRowStretch(row+1, 5);
192 mySelGrpLayout->setRowStretch(row+4, 5);
194 myToAllChk = new QCheckBox(tr("TO_ALL"), mySelGrp);
195 mySelGrpLayout->addWidget(myToAllChk, mySelGrpLayout->rowCount(), 0,
196 1, mySelGrpLayout->columnCount());
198 // Split/Join criterion group
199 myCriterionGrp = new QGroupBox(tr("SPLIT_JOIN_CRITERION"), aMainGrp);
200 QVBoxLayout* aCriterionLayout = new QVBoxLayout(myCriterionGrp);
201 aCriterionLayout->setMargin(MARGIN);
202 aCriterionLayout->setSpacing(SPACING);
204 myChoiceWidget = new QWidget(myCriterionGrp);
205 myGroupChoice = new QButtonGroup(myChoiceWidget);
206 QVBoxLayout* aGroupChoiceLayout = new QVBoxLayout(myChoiceWidget);
207 aGroupChoiceLayout->setMargin(0);
208 aGroupChoiceLayout->setSpacing(SPACING);
210 QRadioButton* aDiag13RB = new QRadioButton(tr("USE_DIAGONAL_1_3"), myChoiceWidget);
211 QRadioButton* aDiag24RB = new QRadioButton(tr("USE_DIAGONAL_2_4"), myChoiceWidget);
212 QRadioButton* aNumFuncRB = new QRadioButton(tr("USE_NUMERIC_FUNC"), myChoiceWidget);
214 aGroupChoiceLayout->addWidget(aDiag13RB);
215 aGroupChoiceLayout->addWidget(aDiag24RB);
216 aGroupChoiceLayout->addWidget(aNumFuncRB);
217 myGroupChoice->addButton(aDiag13RB, 0);
218 myGroupChoice->addButton(aDiag24RB, 1);
219 myGroupChoice->addButton(aNumFuncRB, 2);
220 aDiag13RB->setChecked(true);
222 myComboBoxFunctor = new QComboBox(myCriterionGrp);
223 myComboBoxFunctor->addItem(tr("ASPECTRATIO_ELEMENTS"));
224 myComboBoxFunctor->addItem(tr("MINIMUMANGLE_ELEMENTS"));
225 myComboBoxFunctor->addItem(tr("SKEW_ELEMENTS"));
226 myComboBoxFunctor->addItem(tr("AREA_ELEMENTS"));
227 //myComboBoxFunctor->addItem(tr("LENGTH2D_EDGES")); // for existing elements only
228 //myComboBoxFunctor->addItem(tr("MULTI2D_BORDERS")); // for existing elements only
229 myComboBoxFunctor->setCurrentIndex(0);
231 aCriterionLayout->addWidget(myChoiceWidget);
232 aCriterionLayout->addWidget(myComboBoxFunctor);
234 myCriterionGrp->hide();
235 myChoiceWidget->hide();
236 myComboBoxFunctor->setEnabled(false);
238 // "Select from" group
239 QGroupBox* aGrp = new QGroupBox(tr("SELECT_FROM"), aMainGrp);
240 QGridLayout* aGrpLayout = new QGridLayout(aGrp);
241 aGrpLayout->setMargin(MARGIN);
242 aGrpLayout->setSpacing(SPACING);
244 mySubmeshChk = new QCheckBox(tr("SMESH_SUBMESH"), aGrp);
245 mySubmeshBtn = new QPushButton(aGrp);
246 mySubmesh = new QLineEdit(aGrp);
247 mySubmesh->setReadOnly(true);
248 mySubmeshBtn->setIcon(aPix);
250 myGroupChk = new QCheckBox(tr("SMESH_GROUP"), aGrp);
251 myGroupBtn = new QPushButton(aGrp);
252 myGroup = new QLineEdit(aGrp);
253 myGroup->setReadOnly(true);
254 myGroupBtn->setIcon(aPix);
256 aGrpLayout->addWidget(mySubmeshChk,0,0);
257 aGrpLayout->addWidget(mySubmeshBtn,0,1);
258 aGrpLayout->addWidget(mySubmesh,0,2);
259 aGrpLayout->addWidget(myGroupChk,1,0);
260 aGrpLayout->addWidget(myGroupBtn,1,1);
261 aGrpLayout->addWidget(myGroup,1,2);
263 aMainGrpLayout->addWidget(mySelGrp);
264 aMainGrpLayout->addWidget(myCriterionGrp);
265 aMainGrpLayout->addWidget(aGrp);
270 //=======================================================================
271 // name : SMESHGUI_MultiEditDlg::createButtonFrame
272 // Purpose : Create frame containing buttons
273 //=======================================================================
274 QWidget* SMESHGUI_MultiEditDlg::createButtonFrame (QWidget* theParent)
276 QGroupBox* aFrame = new QGroupBox(theParent);
278 myOkBtn = new QPushButton (tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
279 myApplyBtn = new QPushButton (tr("SMESH_BUT_APPLY"), aFrame);
280 myCloseBtn = new QPushButton (tr("SMESH_BUT_CLOSE"), aFrame);
281 myHelpBtn = new QPushButton (tr("SMESH_BUT_HELP"), aFrame);
283 QHBoxLayout* aLay = new QHBoxLayout (aFrame);
284 aLay->setMargin(MARGIN);
285 aLay->setSpacing(SPACING);
287 aLay->addWidget(myOkBtn);
288 aLay->addSpacing(10);
289 aLay->addWidget(myApplyBtn);
290 aLay->addSpacing(10);
292 aLay->addWidget(myCloseBtn);
293 aLay->addWidget(myHelpBtn);
298 //=======================================================================
299 // name : SMESHGUI_MultiEditDlg::isValid
300 // Purpose : Verify validity of input data
301 //=======================================================================
302 bool SMESHGUI_MultiEditDlg::isValid (const bool /*theMess*/)
304 return (!myMesh->_is_nil() &&
305 (myListBox->count() > 0 || (myToAllChk->isChecked() && myActor)));
308 //=======================================================================
309 // name : SMESHGUI_MultiEditDlg::~SMESHGUI_MultiEditDlg
310 // Purpose : Destructor
311 //=======================================================================
312 SMESHGUI_MultiEditDlg::~SMESHGUI_MultiEditDlg()
314 if (myFilterDlg != 0)
316 myFilterDlg->setParent(0);
321 //=======================================================================
322 // name : SMESHGUI_MultiEditDlg::eventFilter
323 // Purpose : event filter
324 //=======================================================================
325 bool SMESHGUI_MultiEditDlg::eventFilter (QObject* object, QEvent* event)
327 if (object == myListBox && event->type() == QEvent::KeyPress) {
328 QKeyEvent* ke = (QKeyEvent*)event;
329 if (ke->key() == Qt::Key_Delete)
332 return QDialog::eventFilter(object, event);
335 //=======================================================================
336 // name : SMESHGUI_MultiEditDlg::getNumericalFunctor
338 //=======================================================================
339 SMESH::NumericalFunctor_ptr SMESHGUI_MultiEditDlg::getNumericalFunctor()
341 SMESH::NumericalFunctor_var aNF = SMESH::NumericalFunctor::_nil();
343 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
344 if (aFilterMgr->_is_nil())
347 if (myComboBoxFunctor->currentText() == tr("ASPECTRATIO_ELEMENTS"))
348 aNF = aFilterMgr->CreateAspectRatio();
349 else if (myComboBoxFunctor->currentText() == tr("WARP_ELEMENTS"))
350 aNF = aFilterMgr->CreateWarping();
351 else if (myComboBoxFunctor->currentText() == tr("MINIMUMANGLE_ELEMENTS"))
352 aNF = aFilterMgr->CreateMinimumAngle();
353 else if (myComboBoxFunctor->currentText() == tr("TAPER_ELEMENTS"))
354 aNF = aFilterMgr->CreateTaper();
355 else if (myComboBoxFunctor->currentText() == tr("SKEW_ELEMENTS"))
356 aNF = aFilterMgr->CreateSkew();
357 else if (myComboBoxFunctor->currentText() == tr("AREA_ELEMENTS"))
358 aNF = aFilterMgr->CreateArea();
359 else if (myComboBoxFunctor->currentText() == tr("LENGTH2D_EDGES"))
360 aNF = aFilterMgr->CreateLength2D();
361 else if (myComboBoxFunctor->currentText() == tr("MULTI2D_BORDERS"))
362 aNF = aFilterMgr->CreateMultiConnection2D();
368 //=======================================================================
369 // name : SMESHGUI_MultiEditDlg::Init
370 // Purpose : Init dialog fields, connect signals and slots, show dialog
371 //=======================================================================
372 void SMESHGUI_MultiEditDlg::Init()
374 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
379 emit ListContensChanged();
382 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
383 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
384 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
385 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
387 // selection and SMESHGUI
388 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
389 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
390 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
393 connect(myFilterBtn, SIGNAL(clicked()), SLOT(onFilterBtn() ));
394 connect(myAddBtn, SIGNAL(clicked()), SLOT(onAddBtn() ));
395 connect(myRemoveBtn, SIGNAL(clicked()), SLOT(onRemoveBtn() ));
396 connect(mySortBtn, SIGNAL(clicked()), SLOT(onSortListBtn()));
398 connect(mySubmeshChk, SIGNAL(stateChanged(int)), SLOT(onSubmeshChk()));
399 connect(myGroupChk, SIGNAL(stateChanged(int)), SLOT(onGroupChk() ));
400 connect(myToAllChk, SIGNAL(stateChanged(int)), SLOT(onToAllChk() ));
403 connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), SLOT(on3d2dChanged(int)));
405 connect(myListBox, SIGNAL(itemSelectionChanged()), SLOT(onListSelectionChanged()));
409 // set selection mode
414 //=======================================================================
415 // name : SMESHGUI_MultiEditDlg::onOk
416 // Purpose : SLOT called when "Ok" button pressed.
417 // Assign filters VTK viewer and close dialog
418 //=======================================================================
419 void SMESHGUI_MultiEditDlg::onOk()
425 //=======================================================================
426 // name : SMESHGUI_MultiEditDlg::getIds
427 // Purpose : Retrive identifiers from list box
428 //=======================================================================
429 SMESH::long_array_var SMESHGUI_MultiEditDlg::getIds()
431 SMESH::long_array_var anIds = new SMESH::long_array;
433 if (myToAllChk->isChecked())
436 SMESH_Actor * anActor = SMESH::FindActorByObject(myMesh);
442 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
443 if( myFilterType == SMESH::TriaFilter ||
444 myFilterType == SMESH::QuadFilter ||
445 myFilterType == SMESH::FaceFilter ) {
446 SMDS_FaceIteratorPtr it = aMesh->facesIterator();
448 const SMDS_MeshFace* f = it->next();
449 if(myFilterType == SMESH::FaceFilter) {
450 myIds.Add(f->GetID());
452 else if( myFilterType==SMESH::TriaFilter &&
453 ( f->NbNodes()==3 || f->NbNodes()==6 ) ) {
454 myIds.Add(f->GetID());
456 else if( myFilterType==SMESH::QuadFilter &&
457 ( f->NbNodes()==4 || f->NbNodes()==8 ) ) {
458 myIds.Add(f->GetID());
462 else if(myFilterType == SMESH::VolumeFilter) {
463 SMDS_VolumeIteratorPtr it = aMesh->volumesIterator();
465 const SMDS_MeshVolume* f = it->next();
466 myIds.Add(f->GetID());
469 /* commented by skl 07.02.2006
470 TVisualObjPtr aVisualObj = anActor->GetObject();
471 vtkUnstructuredGrid* aGrid = aVisualObj->GetUnstructuredGrid();
473 for (int i = 0, n = aGrid->GetNumberOfCells(); i < n; i++) {
474 vtkCell* aCell = aGrid->GetCell(i);
476 vtkTriangle* aTri = vtkTriangle::SafeDownCast(aCell);
477 vtkQuad* aQua = vtkQuad::SafeDownCast(aCell);
478 vtkPolygon* aPG = vtkPolygon::SafeDownCast(aCell);
480 vtkCell3D* a3d = vtkCell3D::SafeDownCast(aCell);
481 vtkConvexPointSet* aPH = vtkConvexPointSet::SafeDownCast(aCell);
483 if (aTri && myFilterType == SMESHGUI_TriaFilter ||
484 aQua && myFilterType == SMESHGUI_QuadFilter ||
485 (aTri || aQua || aPG) && myFilterType == SMESHGUI_FaceFilter ||
486 (a3d || aPH) && myFilterType == SMESHGUI_VolumeFilter) {
487 int anObjId = aVisualObj->GetElemObjId(i);
497 anIds->length(myIds.Extent());
498 TColStd_MapIteratorOfMapOfInteger anIter(myIds);
499 for (int i = 0; anIter.More(); anIter.Next() )
501 anIds[ i++ ] = anIter.Key();
503 return anIds._retn();
506 //=======================================================================
507 // name : SMESHGUI_MultiEditDlg::onClose
508 // Purpose : SLOT called when "Close" button pressed. Close dialog
509 //=======================================================================
510 void SMESHGUI_MultiEditDlg::onClose()
512 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
513 aViewWindow->SetSelectionMode(ActorSelection);
514 disconnect(mySelectionMgr, 0, this, 0);
515 disconnect(mySMESHGUI, 0, this, 0);
516 mySMESHGUI->ResetState();
518 SMESH::RemoveFilters();
519 SMESH::SetPickable();
521 //mySelectionMgr->clearSelected();
522 mySelectionMgr->clearFilters();
527 //=================================================================================
528 // function : onHelp()
530 //=================================================================================
531 void SMESHGUI_MultiEditDlg::onHelp()
533 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
535 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
539 platform = "winapplication";
541 platform = "application";
543 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
544 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
545 arg(app->resourceMgr()->stringValue("ExternalBrowser",
547 arg(myHelpFileName));
551 //=======================================================================
552 // name : SMESHGUI_MultiEditDlg::onSelectionDone
553 // Purpose : SLOT called when selection changed
554 //=======================================================================
555 void SMESHGUI_MultiEditDlg::onSelectionDone()
557 if (myBusy || !isEnabled()) return;
560 const SALOME_ListIO& aList = mySelector->StoredIObjects();
562 int nbSel = aList.Extent();
563 myListBox->clearSelection();
565 if (mySubmeshChk->isChecked() || myGroupChk->isChecked()) {
566 QLineEdit* aNameEdit = mySubmeshChk->isChecked() ? mySubmesh : myGroup;
568 Handle(SALOME_InteractiveObject) anIO = aList.First();
570 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
571 anIO.IsNull() ? aNameEdit->clear() : aNameEdit->setText(aName);
573 if (mySubmeshChk->isChecked()) {
574 SMESH::SMESH_subMesh_var aSubMesh =
575 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIO);
576 if (!aSubMesh->_is_nil())
577 myMesh = aSubMesh->GetFather();
579 SMESH::SMESH_GroupBase_var aGroup =
580 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIO);
581 if (!aGroup->_is_nil())
582 myMesh = aGroup->GetMesh();
584 } else if (nbSel > 1) {
585 QString aStr = mySubmeshChk->isChecked() ?
586 tr("SMESH_SUBMESH_SELECTED") : tr("SMESH_GROUP_SELECTED");
587 aNameEdit->setText(aStr.arg(nbSel));
591 } else if (nbSel > 0) {
592 QString aListStr = "";
593 Handle(SALOME_InteractiveObject) anIO = aList.First();
594 int aNbItems = SMESH::GetNameOfSelectedElements(mySelector,anIO,aListStr);
596 QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
597 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
598 QList<QListWidgetItem*> items = myListBox->findItems(*it, Qt::MatchExactly);
599 QListWidgetItem* anItem;
600 foreach(anItem, items)
601 anItem->setSelected(true);
604 myMesh = SMESH::GetMeshByIO(anIO);
608 myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
610 myActor = SMESH::FindActorByObject(myMesh);
611 SVTK_Selector* aSelector = SMESH::GetSelector();
612 Handle(VTKViewer_Filter) aFilter = aSelector->GetFilter(myFilterType);
613 if (!aFilter.IsNull())
614 aFilter->SetActor(myActor);
621 //=======================================================================
622 // name : SMESHGUI_MultiEditDlg::onDeactivate
623 // Purpose : SLOT called when dialog must be deativated
624 //=======================================================================
625 void SMESHGUI_MultiEditDlg::onDeactivate()
630 //=======================================================================
631 // name : SMESHGUI_MultiEditDlg::enterEvent
632 // Purpose : Event filter
633 //=======================================================================
634 void SMESHGUI_MultiEditDlg::enterEvent (QEvent*)
637 mySMESHGUI->EmitSignalDeactivateDialog();
643 //=======================================================================
644 // name : SMESHGUI_MultiEditDlg::closeEvent
646 //=======================================================================
647 void SMESHGUI_MultiEditDlg::closeEvent (QCloseEvent*)
651 //=======================================================================
652 // name : SMESHGUI_MultiEditDlg::hideEvent
653 // Purpose : caused by ESC key
654 //=======================================================================
655 void SMESHGUI_MultiEditDlg::hideEvent (QHideEvent*)
661 //=======================================================================
662 // name : SMESHGUI_MultiEditDlg::onFilterBtn
663 // Purpose : SLOT. Called when "Filter" button pressed.
664 // Start "Selection filters" dialog
665 //=======================================================================
666 void SMESHGUI_MultiEditDlg::onFilterBtn()
668 if (myFilterDlg == 0) {
669 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, entityType() ? SMESH::VOLUME : SMESH::FACE);
670 connect(myFilterDlg, SIGNAL(Accepted()), SLOT(onFilterAccepted()));
672 myFilterDlg->Init(entityType() ? SMESH::VOLUME : SMESH::FACE);
675 myFilterDlg->SetSelection();
676 myFilterDlg->SetMesh(myMesh);
677 myFilterDlg->SetSourceWg(myListBox);
682 //=======================================================================
683 // name : onFilterAccepted()
684 // Purpose : SLOT. Called when Filter dlg closed with OK button.
685 // Uncheck "Select submesh" and "Select group" checkboxes
686 //=======================================================================
687 void SMESHGUI_MultiEditDlg::onFilterAccepted()
690 for (int i = 0, n = myListBox->count(); i < n; i++)
691 myIds.Add(myListBox->item(i)->text().toInt());
693 emit ListContensChanged();
695 if (mySubmeshChk->isChecked() || myGroupChk->isChecked()) {
696 mySubmeshChk->blockSignals(true);
697 myGroupChk->blockSignals(true);
698 mySubmeshChk->setChecked(false);
699 myGroupChk->setChecked(false);
700 mySubmeshChk->blockSignals(false);
701 myGroupChk->blockSignals(false);
706 //=======================================================================
707 // name : SMESHGUI_MultiEditDlg::isIdValid
708 // Purpose : Verify whether Id of element satisfies to filters from viewer
709 //=======================================================================
710 bool SMESHGUI_MultiEditDlg::isIdValid (const int theId) const
712 SVTK_Selector* aSelector = SMESH::GetSelector();
713 Handle(SMESHGUI_Filter) aFilter =
714 Handle(SMESHGUI_Filter)::DownCast(aSelector->GetFilter(myFilterType));
716 return (!aFilter.IsNull() && aFilter->IsObjValid(theId));
719 //=======================================================================
720 // name : SMESHGUI_MultiEditDlg::onAddBtn
721 // Purpose : SLOT. Called when "Add" button pressed.
722 // Add selected in viewer entities in list box
723 //=======================================================================
724 void SMESHGUI_MultiEditDlg::onAddBtn()
726 const SALOME_ListIO& aList = mySelector->StoredIObjects();
728 int nbSelected = aList.Extent();
732 TColStd_IndexedMapOfInteger toBeAdded;
734 if (!mySubmeshChk->isChecked() && !myGroupChk->isChecked()) {
736 mySelector->GetIndex(aList.First(),toBeAdded);
737 } else if (mySubmeshChk->isChecked()) {
738 SALOME_ListIteratorOfListIO anIter(aList);
739 for ( ; anIter.More(); anIter.Next()) {
740 SMESH::SMESH_subMesh_var aSubMesh =
741 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Value());
742 if (!aSubMesh->_is_nil()) {
743 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
744 SMESH::long_array_var anIds = aSubMesh->GetElementsId();
745 for (int i = 0, n = anIds->length(); i < n; i++) {
746 if (isIdValid(anIds[ i ]))
747 toBeAdded.Add(anIds[ i ]);
752 } else if (myGroupChk->isChecked()) {
753 SALOME_ListIteratorOfListIO anIter(aList);
754 for ( ; anIter.More(); anIter.Next()) {
755 SMESH::SMESH_GroupBase_var aGroup =
756 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
757 if (!aGroup->_is_nil() && (aGroup->GetType() == SMESH::FACE &&
758 entityType() == 0 || aGroup->GetType() == SMESH::VOLUME &&
759 entityType() == 1)) {
760 if (aGroup->GetMesh()->GetId() == myMesh->GetId()) {
761 SMESH::long_array_var anIds = aGroup->GetListOfID();
762 for (int i = 0, n = anIds->length(); i < n; i++) {
763 if (isIdValid(anIds[ i ]))
764 toBeAdded.Add(anIds[ i ]);
773 bool isGroupOrSubmesh = (mySubmeshChk->isChecked() || myGroupChk->isChecked());
774 mySubmeshChk->setChecked(false);
775 myGroupChk->setChecked(false);
776 for(int i = 1; i <= toBeAdded.Extent(); i++)
777 if (myIds.Add(toBeAdded(i))) {
778 QListWidgetItem* item = new QListWidgetItem(QString("%1").arg(toBeAdded(i)));
779 myListBox->addItem(item);
780 item->setSelected(true);
784 emit ListContensChanged();
786 if (isGroupOrSubmesh)
787 onListSelectionChanged();
792 //=======================================================================
793 // name : SMESHGUI_MultiEditDlg::updateButtons
794 // Purpose : Enable/disable buttons of dialog in accordance with current state
795 //=======================================================================
796 void SMESHGUI_MultiEditDlg::updateButtons()
798 bool isOk = isValid(false);
799 myOkBtn->setEnabled(isOk);
800 myApplyBtn->setEnabled(isOk);
802 bool isListBoxNonEmpty = myListBox->count() > 0;
803 bool isToAll = myToAllChk->isChecked();
804 myFilterBtn->setEnabled(!isToAll);
805 myRemoveBtn->setEnabled(isListBoxNonEmpty && !isToAll);
806 mySortBtn->setEnabled(isListBoxNonEmpty &&!isToAll);
808 const SALOME_ListIO& aList = mySelector->StoredIObjects();
812 aList.Extent() < 1 ||
813 (SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(aList.First())->_is_nil() &&
814 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(aList.First())->_is_nil() &&
815 SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First())->_is_nil()))
816 myAddBtn->setEnabled(false);
818 myAddBtn->setEnabled(true);
820 mySubmeshChk->setEnabled(!isToAll);
821 mySubmeshBtn->setEnabled(mySubmeshChk->isChecked());
822 mySubmesh->setEnabled(mySubmeshChk->isChecked());
824 myGroupChk->setEnabled(!isToAll);
825 myGroupBtn->setEnabled(myGroupChk->isChecked());
826 myGroup->setEnabled(myGroupChk->isChecked());
828 if (!mySubmeshChk->isChecked())
830 if (!myGroupChk->isChecked())
835 //=======================================================================
836 // name : SMESHGUI_MultiEditDlg::onRemoveBtn
837 // Purpose : SLOT. Called when "Remove" button pressed.
838 // Remove selected in list box entities
839 //=======================================================================
840 void SMESHGUI_MultiEditDlg::onRemoveBtn()
844 QList<QListWidgetItem*> selItems = myListBox->selectedItems();
845 QListWidgetItem* item;
846 foreach(item, selItems)
848 myIds.Remove(item->text().toInt());
854 emit ListContensChanged();
858 //=======================================================================
859 // name : SMESHGUI_MultiEditDlg::onSortListBtn
860 // Purpose : SLOT. Called when "Sort list" button pressed.
861 // Sort entities of list box
862 //=======================================================================
863 void SMESHGUI_MultiEditDlg::onSortListBtn()
867 int i, k = myListBox->count();
870 QList<int> aSelected;
871 std::vector<int> anArray(k);
872 for (i = 0; i < k; i++)
874 int id = myListBox->item(i)->text().toInt();
876 if (myListBox->item(i)->isSelected())
877 aSelected.append(id);
880 std::sort(anArray.begin(), anArray.end());
883 for (i = 0; i < k; i++) {
884 QListWidgetItem* item = new QListWidgetItem(QString::number(anArray[i]));
885 myListBox->addItem(item);
886 item->setSelected(aSelected.contains(anArray[i]));
892 //=======================================================================
893 // name : SMESHGUI_MultiEditDlg::onListSelectionChanged
894 // Purpose : SLOT. Called when selection in list box changed.
895 // Highlight in selected entities
896 //=======================================================================
897 void SMESHGUI_MultiEditDlg::onListSelectionChanged()
899 if (myActor == 0 || myBusy)
902 if (mySubmeshChk->isChecked() || myGroupChk->isChecked())
905 SMESH_Actor * anActor = SMESH::FindActorByObject(myMesh);
908 TVisualObjPtr anObj = anActor->GetObject();
910 TColStd_MapOfInteger anIndexes;
911 int total = myListBox->count();
912 for (int i = 0; i < total; i++)
914 if (myListBox->item(i)->isSelected())
916 int anId = myListBox->item(i)->text().toInt();
917 if (anObj->GetElemVTKId(anId) >= 0) // avoid exception in hilight
922 mySelector->AddOrRemoveIndex(anActor->getIO(),anIndexes,false);
923 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
924 aViewWindow->highlight(anActor->getIO(),true,true);
927 //=======================================================================
928 // name : SMESHGUI_MultiEditDlg::onSubmeshChk
929 // Purpose : SLOT. Called when state of "SubMesh" check box changed.
930 // Activate/deactivate selection of submeshes
931 //=======================================================================
932 void SMESHGUI_MultiEditDlg::onSubmeshChk()
934 bool isChecked = mySubmeshChk->isChecked();
935 mySubmeshBtn->setEnabled(isChecked);
936 mySubmesh->setEnabled(isChecked);
939 if (isChecked && myGroupChk->isChecked())
940 myGroupChk->setChecked(false);
945 //=======================================================================
946 // name : SMESHGUI_MultiEditDlg::onGroupChk
947 // Purpose : SLOT. Called when state of "Group" check box changed.
948 // Activate/deactivate selection of groupes
949 //=======================================================================
950 void SMESHGUI_MultiEditDlg::onGroupChk()
952 bool isChecked = myGroupChk->isChecked();
953 myGroupBtn->setEnabled(isChecked);
954 myGroup->setEnabled(isChecked);
957 if (isChecked && mySubmeshChk->isChecked())
958 mySubmeshChk->setChecked(false);
963 //=======================================================================
964 // name : SMESHGUI_MultiEditDlg::onToAllChk
965 // Purpose : SLOT. Called when state of "Apply to all" check box changed.
966 // Activate/deactivate selection
967 //=======================================================================
968 void SMESHGUI_MultiEditDlg::onToAllChk()
970 bool isChecked = myToAllChk->isChecked();
977 emit ListContensChanged();
983 //=======================================================================
984 // name : SMESHGUI_MultiEditDlg::setSelectionMode
985 // Purpose : Set selection mode
986 //=======================================================================
987 void SMESHGUI_MultiEditDlg::setSelectionMode()
989 SMESH::RemoveFilters();
991 mySelectionMgr->clearSelected();
992 mySelectionMgr->clearFilters();
994 if (mySubmeshChk->isChecked()) {
995 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
996 aViewWindow->SetSelectionMode(ActorSelection);
997 mySelectionMgr->installFilter(new SMESH_TypeFilter(SUBMESH));
999 else if (myGroupChk->isChecked()) {
1000 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1001 aViewWindow->SetSelectionMode(ActorSelection);
1002 mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
1006 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1007 aViewWindow->SetSelectionMode(VolumeSelection);
1008 SMESH::SetFilter(new SMESHGUI_VolumesFilter());
1010 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1011 aViewWindow->SetSelectionMode(FaceSelection);
1012 if (myFilterType == SMESH::TriaFilter)
1013 SMESH::SetFilter(new SMESHGUI_TriangleFilter());
1014 else if (myFilterType == SMESH::QuadFilter)
1015 SMESH::SetFilter(new SMESHGUI_QuadrangleFilter());
1017 SMESH::SetFilter(new SMESHGUI_FacesFilter());
1021 //=======================================================================
1022 // name : SMESHGUI_MultiEditDlg::onApply
1023 // Purpose : SLOT. Called when "Apply" button clicked.
1024 //=======================================================================
1025 bool SMESHGUI_MultiEditDlg::onApply()
1027 if (mySMESHGUI->isActiveStudyLocked())
1032 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
1033 if (aMeshEditor->_is_nil())
1038 SMESH::long_array_var anIds = getIds();
1040 bool aResult = process(aMeshEditor, anIds.inout());
1044 mySelectionMgr->selectedObjects( sel );
1045 mySelector->ClearIndex();
1046 mySelectionMgr->setSelectedObjects( sel );
1047 SMESH::UpdateView();
1052 emit ListContensChanged();
1061 //=======================================================================
1062 // name : SMESHGUI_MultiEditDlg::on3d2dChanged
1064 //=======================================================================
1065 void SMESHGUI_MultiEditDlg::on3d2dChanged (int type)
1067 if (myEntityType != type) {
1068 myEntityType = type;
1073 emit ListContensChanged();
1076 myFilterType = SMESH::VolumeFilter;
1078 myFilterType = SMESH::FaceFilter;
1085 //=======================================================================
1086 // name : SMESHGUI_MultiEditDlg::entityType
1088 //=======================================================================
1089 int SMESHGUI_MultiEditDlg::entityType()
1091 return myEntityType;
1094 //=================================================================================
1095 // function : keyPressEvent()
1097 //=================================================================================
1098 void SMESHGUI_MultiEditDlg::keyPressEvent( QKeyEvent* e )
1100 QDialog::keyPressEvent( e );
1101 if ( e->isAccepted() )
1104 if ( e->key() == Qt::Key_F1 ) {
1111 * Class : SMESHGUI_ChangeOrientationDlg
1112 * Description : Modification of orientation of faces
1115 SMESHGUI_ChangeOrientationDlg
1116 ::SMESHGUI_ChangeOrientationDlg(SMESHGUI* theModule):
1117 SMESHGUI_MultiEditDlg(theModule, SMESH::FaceFilter, true)
1119 setWindowTitle(tr("CAPTION"));
1120 myHelpFileName = "changing_orientation_of_elements_page.html";
1123 SMESHGUI_ChangeOrientationDlg::~SMESHGUI_ChangeOrientationDlg()
1127 bool SMESHGUI_ChangeOrientationDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
1128 const SMESH::long_array& theIds)
1130 return theEditor->Reorient(theIds);
1134 * Class : SMESHGUI_UnionOfTrianglesDlg
1135 * Description : Construction of quadrangles by automatic association of triangles
1138 SMESHGUI_UnionOfTrianglesDlg
1139 ::SMESHGUI_UnionOfTrianglesDlg(SMESHGUI* theModule):
1140 SMESHGUI_MultiEditDlg(theModule, SMESH::TriaFilter, false)
1142 setWindowTitle(tr("CAPTION"));
1144 myComboBoxFunctor->setEnabled(true);
1145 myComboBoxFunctor->addItem(tr("WARP_ELEMENTS")); // for quadrangles only
1146 myComboBoxFunctor->addItem(tr("TAPER_ELEMENTS")); // for quadrangles only
1149 QWidget* aMaxAngleGrp = new QWidget(myCriterionGrp);
1150 QHBoxLayout* aMaxAngleGrpLayout = new QHBoxLayout(aMaxAngleGrp);
1151 aMaxAngleGrpLayout->setMargin(0);
1152 aMaxAngleGrpLayout->setSpacing(SPACING);
1154 QLabel* aLab = new QLabel (tr("MAXIMUM_ANGLE"), aMaxAngleGrp);
1155 myMaxAngleSpin = new SMESHGUI_SpinBox (aMaxAngleGrp);
1156 myMaxAngleSpin->RangeStepAndValidator(0, 180.0, 1.0, 3);
1157 myMaxAngleSpin->SetValue(30.0);
1159 aMaxAngleGrpLayout->addWidget(aLab);
1160 aMaxAngleGrpLayout->addWidget(myMaxAngleSpin);
1162 ((QVBoxLayout*)(myCriterionGrp->layout()))->addWidget(aMaxAngleGrp);
1163 myCriterionGrp->show();
1165 myHelpFileName = "uniting_set_of_triangles_page.html";
1168 SMESHGUI_UnionOfTrianglesDlg::~SMESHGUI_UnionOfTrianglesDlg()
1172 bool SMESHGUI_UnionOfTrianglesDlg::isValid (const bool theMess)
1174 bool ok = SMESHGUI_MultiEditDlg::isValid( theMess );
1177 return checkParameters( theMess, 1, myMaxAngleSpin );
1180 bool SMESHGUI_UnionOfTrianglesDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
1181 const SMESH::long_array& theIds)
1183 SMESH::NumericalFunctor_var aCriterion = getNumericalFunctor();
1184 double aMaxAngle = myMaxAngleSpin->GetValue() * PI / 180.0;
1185 bool ok = theEditor->TriToQuad(theIds, aCriterion, aMaxAngle);
1187 QStringList aParameters;
1188 aParameters << myMaxAngleSpin->text();
1189 //asl: myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
1196 * Class : SMESHGUI_CuttingOfQuadsDlg
1197 * Description : Automatic splitting of quadrangles into triangles
1200 SMESHGUI_CuttingOfQuadsDlg
1201 ::SMESHGUI_CuttingOfQuadsDlg(SMESHGUI* theModule):
1202 SMESHGUI_MultiEditDlg(theModule, SMESH::QuadFilter, false)
1204 setWindowTitle(tr("CAPTION"));
1207 myPreviewChk = new QCheckBox (tr("PREVIEW"), mySelGrp);
1208 QGridLayout* aLay = (QGridLayout*)(mySelGrp->layout());
1209 aLay->addWidget(myPreviewChk, aLay->rowCount(), 0, 1, aLay->columnCount());
1211 myCriterionGrp->show();
1212 myChoiceWidget->show();
1213 myComboBoxFunctor->setEnabled(false);
1215 connect(myPreviewChk, SIGNAL(stateChanged(int)), this, SLOT(onPreviewChk()));
1216 connect(myGroupChoice, SIGNAL(buttonClicked(int)), this, SLOT(onCriterionRB()));
1217 connect(myComboBoxFunctor, SIGNAL(activated(int)), this, SLOT(onPreviewChk()));
1218 connect(this, SIGNAL(ListContensChanged()), this, SLOT(onPreviewChk()));
1220 myHelpFileName = "cutting_quadrangles_page.html";
1223 SMESHGUI_CuttingOfQuadsDlg::~SMESHGUI_CuttingOfQuadsDlg()
1227 void SMESHGUI_CuttingOfQuadsDlg::onClose()
1230 SMESHGUI_MultiEditDlg::onClose();
1233 bool SMESHGUI_CuttingOfQuadsDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
1234 const SMESH::long_array& theIds)
1236 switch (myGroupChoice->checkedId()) {
1237 case 0: // use diagonal 1-3
1238 return theEditor->SplitQuad(theIds, true);
1239 case 1: // use diagonal 2-4
1240 return theEditor->SplitQuad(theIds, false);
1241 default: // use numeric functor
1245 SMESH::NumericalFunctor_var aCriterion = getNumericalFunctor();
1246 return theEditor->QuadToTri(theIds, aCriterion);
1249 void SMESHGUI_CuttingOfQuadsDlg::onCriterionRB()
1251 if (myGroupChoice->checkedId() == 2) // Use numeric functor
1252 myComboBoxFunctor->setEnabled(true);
1254 myComboBoxFunctor->setEnabled(false);
1259 void SMESHGUI_CuttingOfQuadsDlg::onPreviewChk()
1261 myPreviewChk->isChecked() ? displayPreview() : erasePreview();
1264 void SMESHGUI_CuttingOfQuadsDlg::erasePreview()
1266 if (myPreviewActor == 0)
1269 if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView()) {
1270 vf->RemoveActor(myPreviewActor);
1273 myPreviewActor->Delete();
1277 void SMESHGUI_CuttingOfQuadsDlg::displayPreview()
1282 if (myPreviewActor != 0)
1285 // get Ids of elements
1286 SMESH::long_array_var anElemIds = getIds();
1287 if (getIds()->length() == 0)
1290 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
1294 // 0 - use diagonal 1-3, 1 - use diagonal 2-4, 2 - use numerical functor
1295 int aChoice = myGroupChoice->checkedId();
1296 SMESH::NumericalFunctor_var aCriterion = SMESH::NumericalFunctor::_nil();
1297 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH::SMESH_MeshEditor::_nil();
1299 aCriterion = getNumericalFunctor();
1300 aMeshEditor = myMesh->GetMeshEditor();
1301 if (aMeshEditor->_is_nil())
1306 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
1308 vtkIdType aNbCells = anElemIds->length() * 2;
1309 vtkIdType aCellsSize = 4 * aNbCells;
1310 vtkCellArray* aConnectivity = vtkCellArray::New();
1311 aConnectivity->Allocate(aCellsSize, 0);
1313 vtkPoints* aPoints = vtkPoints::New();
1314 aPoints->SetNumberOfPoints(anElemIds->length() * 4);
1316 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
1317 aCellTypesArray->SetNumberOfComponents(1);
1318 aCellTypesArray->Allocate(aNbCells * aCellTypesArray->GetNumberOfComponents());
1320 vtkIdList *anIdList = vtkIdList::New();
1321 anIdList->SetNumberOfIds(3);
1323 TColStd_DataMapOfIntegerInteger anIdToVtk;
1327 for (int i = 0, n = anElemIds->length(); i < n; i++)
1329 const SMDS_MeshElement* anElem = aMesh->FindElement(anElemIds[ i ]);
1330 if (anElem == 0 || anElem->NbNodes() != 4)
1333 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
1335 while (anIter->more()) {
1336 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIter->next());
1339 if (!anIdToVtk.IsBound(aNode->GetID()))
1341 aPoints->SetPoint(++nbPoints, aNode->X(), aNode->Y(), aNode->Z());
1342 anIdToVtk.Bind(aNode->GetID(), nbPoints);
1345 aNodes[ k++ ] = aNode->GetID();
1352 bool isDiag13 = true;
1353 if (aChoice == 0) // use diagonal 1-3
1357 else if (aChoice == 1) // use diagonal 2-4
1361 else // use numerical functor
1363 // compare two sets of possible triangles
1364 int diag = aMeshEditor->BestSplit(anElemIds[i], aCriterion);
1365 if (diag == 1) // 1-3
1367 else if (diag == 2) // 2-4
1375 anIdList->SetId(0, anIdToVtk(aNodes[ 0 ]));
1376 anIdList->SetId(1, anIdToVtk(aNodes[ 1 ]));
1377 anIdList->SetId(2, anIdToVtk(aNodes[ 2 ]));
1378 aConnectivity->InsertNextCell(anIdList);
1379 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1381 anIdList->SetId(0, anIdToVtk(aNodes[ 2 ]));
1382 anIdList->SetId(1, anIdToVtk(aNodes[ 3 ]));
1383 anIdList->SetId(2, anIdToVtk(aNodes[ 0 ]));
1384 aConnectivity->InsertNextCell(anIdList);
1385 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1389 anIdList->SetId(0, anIdToVtk(aNodes[ 1 ]));
1390 anIdList->SetId(1, anIdToVtk(aNodes[ 2 ]));
1391 anIdList->SetId(2, anIdToVtk(aNodes[ 3 ]));
1392 aConnectivity->InsertNextCell(anIdList);
1393 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1395 anIdList->SetId(0, anIdToVtk(aNodes[ 3 ]));
1396 anIdList->SetId(1, anIdToVtk(aNodes[ 0 ]));
1397 anIdList->SetId(2, anIdToVtk(aNodes[ 1 ]));
1398 aConnectivity->InsertNextCell(anIdList);
1399 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1403 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
1404 aCellLocationsArray->SetNumberOfComponents(1);
1405 aCellLocationsArray->SetNumberOfTuples(aNbCells);
1407 aConnectivity->InitTraversal();
1408 for(vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell(npts, pts); idType++)
1409 aCellLocationsArray->SetValue(idType, aConnectivity->GetTraversalLocation(npts));
1411 aGrid->SetPoints(aPoints);
1412 aGrid->SetCells(aCellTypesArray, aCellLocationsArray,aConnectivity);
1414 // Create and display actor
1415 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
1416 aMapper->SetInput(aGrid);
1418 myPreviewActor = SALOME_Actor::New();
1419 myPreviewActor->PickableOff();
1420 myPreviewActor->SetMapper(aMapper);
1422 vtkProperty* aProp = vtkProperty::New();
1423 aProp->SetRepresentationToWireframe();
1424 aProp->SetColor(250, 0, 250);
1425 aProp->SetLineWidth(myActor->GetLineWidth() + 1);
1426 myPreviewActor->SetProperty(aProp);
1428 SMESH::GetCurrentVtkView()->AddActor(myPreviewActor);
1429 SMESH::GetCurrentVtkView()->Repaint();
1433 aConnectivity->Delete();
1437 aCellTypesArray->Delete();
1438 aCellLocationsArray->Delete();