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"
37 #include "SMESHGUI_MeshEditPreview.h"
39 #include <SMESH_Actor.h>
40 #include <SMESH_TypeFilter.hxx>
41 #include <SMDS_Mesh.hxx>
43 // SALOME GUI includes
44 #include <SUIT_Desktop.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_OverrideCursor.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_Session.h>
50 #include <LightApp_SelectionMgr.h>
51 #include <LightApp_Application.h>
52 #include <SALOME_ListIO.hxx>
53 #include <SALOME_ListIteratorOfListIO.hxx>
54 #include <SalomeApp_Tools.h>
56 #include <SVTK_Selector.h>
57 #include <SVTK_ViewWindow.h>
58 #include <VTKViewer_CellLocationsArray.h>
61 #include <TColStd_IndexedMapOfInteger.hxx>
62 #include <TColStd_DataMapOfIntegerInteger.hxx>
63 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
66 #include <vtkIdList.h>
67 #include <vtkCellArray.h>
68 #include <vtkUnsignedCharArray.h>
69 #include <vtkUnstructuredGrid.h>
70 #include <vtkDataSetMapper.h>
71 #include <vtkProperty.h>
75 #include <QVBoxLayout>
76 #include <QHBoxLayout>
77 #include <QGridLayout>
78 #include <QListWidget>
83 #include <QPushButton>
84 #include <QButtonGroup>
85 #include <QRadioButton>
89 #include <SALOMEconfig.h>
90 #include CORBA_SERVER_HEADER(SMESH_Group)
96 * Class : SMESHGUI_MultiEditDlg
97 * Description : Description : Inversion of the diagonal of a pseudo-quadrangle formed by
98 * 2 neighboring triangles with 1 common edge
101 //=======================================================================
102 // name : SMESHGUI_MultiEditDlg::SMESHGUI_MultiEditDlg
103 // Purpose : Constructor
104 //=======================================================================
105 SMESHGUI_MultiEditDlg
106 ::SMESHGUI_MultiEditDlg(SMESHGUI* theModule,
109 SMESHGUI_PreviewDlg(theModule),
110 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
111 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
112 mySMESHGUI(theModule)
115 setAttribute(Qt::WA_DeleteOnClose, true);
120 myFilterType = theMode;
121 QVBoxLayout* aDlgLay = new QVBoxLayout(this);
122 aDlgLay->setMargin(MARGIN);
123 aDlgLay->setSpacing(SPACING);
125 QWidget* aMainFrame = createMainFrame (this, the3d2d);
126 QWidget* aBtnFrame = createButtonFrame(this);
128 aDlgLay->addWidget(aMainFrame);
129 aDlgLay->addWidget(aBtnFrame);
134 //=======================================================================
135 // name : SMESHGUI_MultiEditDlg::createMainFrame
136 // Purpose : Create frame containing dialog's input fields
137 //=======================================================================
138 QWidget* SMESHGUI_MultiEditDlg::createMainFrame (QWidget* theParent, const bool the3d2d)
140 QWidget* aMainGrp = new QWidget(theParent);
141 QVBoxLayout* aMainGrpLayout = new QVBoxLayout(aMainGrp);
142 aMainGrpLayout->setMargin(0);
143 aMainGrpLayout->setSpacing(SPACING);
145 QPixmap aPix (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
147 // "Selected cells" group
148 mySelGrp = new QGroupBox(aMainGrp);
150 QGridLayout* mySelGrpLayout = new QGridLayout(mySelGrp);
151 mySelGrpLayout->setMargin(MARGIN);
152 mySelGrpLayout->setSpacing(SPACING);
156 QGroupBox* aEntityTypeGrp = new QGroupBox(tr("SMESH_ELEMENTS_TYPE"), mySelGrp);
157 myEntityTypeGrp = new QButtonGroup(mySelGrp);
158 QHBoxLayout* aEntityLayout = new QHBoxLayout(aEntityTypeGrp);
159 aEntityLayout->setMargin(MARGIN);
160 aEntityLayout->setSpacing(SPACING);
162 QRadioButton* aFaceRb = new QRadioButton(tr("SMESH_FACE"), aEntityTypeGrp);
163 QRadioButton* aVolumeRb = new QRadioButton(tr("SMESH_VOLUME"), aEntityTypeGrp);
165 aEntityLayout->addWidget(aFaceRb);
166 aEntityLayout->addWidget(aVolumeRb);
168 myEntityTypeGrp->addButton(aFaceRb, 0);
169 myEntityTypeGrp->addButton(aVolumeRb, 1);
170 aFaceRb->setChecked(true);
171 myEntityType = myEntityTypeGrp->checkedId();
173 mySelGrpLayout->addWidget(aEntityTypeGrp, 0, 0, 1, 2);
176 myListBox = new QListWidget(mySelGrp);
177 myListBox->setSelectionMode(QListWidget::ExtendedSelection);
178 myListBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
179 myListBox->installEventFilter(this);
181 myFilterBtn = new QPushButton(tr("FILTER"), mySelGrp);
182 myAddBtn = new QPushButton(tr("ADD"), mySelGrp);
183 myRemoveBtn = new QPushButton(tr("REMOVE"), mySelGrp);
184 mySortBtn = new QPushButton(tr("SORT_LIST"), mySelGrp);
186 int row = mySelGrpLayout->rowCount();
187 mySelGrpLayout->addWidget(myListBox, row, 0, 6, 1);
188 mySelGrpLayout->addWidget(myFilterBtn, row, 1);
189 mySelGrpLayout->addWidget(myAddBtn, row+2, 1);
190 mySelGrpLayout->addWidget(myRemoveBtn, row+3, 1);
191 mySelGrpLayout->addWidget(mySortBtn, row+5, 1);
192 mySelGrpLayout->setRowMinimumHeight(row+1, 10);
193 mySelGrpLayout->setRowMinimumHeight(row+4, 10);
194 mySelGrpLayout->setRowStretch(row+1, 5);
195 mySelGrpLayout->setRowStretch(row+4, 5);
197 myToAllChk = new QCheckBox(tr("TO_ALL"), mySelGrp);
198 mySelGrpLayout->addWidget(myToAllChk, mySelGrpLayout->rowCount(), 0,
199 1, mySelGrpLayout->columnCount());
201 // Split/Join criterion group
202 myCriterionGrp = new QGroupBox(tr("SPLIT_JOIN_CRITERION"), aMainGrp);
203 QVBoxLayout* aCriterionLayout = new QVBoxLayout(myCriterionGrp);
204 aCriterionLayout->setMargin(MARGIN);
205 aCriterionLayout->setSpacing(SPACING);
207 myChoiceWidget = new QWidget(myCriterionGrp);
208 myGroupChoice = new QButtonGroup(myChoiceWidget);
209 QVBoxLayout* aGroupChoiceLayout = new QVBoxLayout(myChoiceWidget);
210 aGroupChoiceLayout->setMargin(0);
211 aGroupChoiceLayout->setSpacing(SPACING);
213 QRadioButton* aDiag13RB = new QRadioButton(tr("USE_DIAGONAL_1_3"), myChoiceWidget);
214 QRadioButton* aDiag24RB = new QRadioButton(tr("USE_DIAGONAL_2_4"), myChoiceWidget);
215 QRadioButton* aNumFuncRB = new QRadioButton(tr("USE_NUMERIC_FUNC"), myChoiceWidget);
217 aGroupChoiceLayout->addWidget(aDiag13RB);
218 aGroupChoiceLayout->addWidget(aDiag24RB);
219 aGroupChoiceLayout->addWidget(aNumFuncRB);
220 myGroupChoice->addButton(aDiag13RB, 0);
221 myGroupChoice->addButton(aDiag24RB, 1);
222 myGroupChoice->addButton(aNumFuncRB, 2);
223 aDiag13RB->setChecked(true);
225 myComboBoxFunctor = new QComboBox(myCriterionGrp);
226 myComboBoxFunctor->addItem(tr("ASPECTRATIO_ELEMENTS"));
227 myComboBoxFunctor->addItem(tr("MINIMUMANGLE_ELEMENTS"));
228 myComboBoxFunctor->addItem(tr("SKEW_ELEMENTS"));
229 //myComboBoxFunctor->addItem(tr("AREA_ELEMENTS"));
230 //myComboBoxFunctor->addItem(tr("LENGTH2D_EDGES")); // for existing elements only
231 //myComboBoxFunctor->addItem(tr("MULTI2D_BORDERS")); // for existing elements only
232 myComboBoxFunctor->setCurrentIndex(0);
234 aCriterionLayout->addWidget(myChoiceWidget);
235 aCriterionLayout->addWidget(myComboBoxFunctor);
237 myCriterionGrp->hide();
238 myChoiceWidget->hide();
239 myComboBoxFunctor->setEnabled(false);
241 // "Select from" group
242 QGroupBox* aGrp = new QGroupBox(tr("SELECT_FROM"), aMainGrp);
243 QGridLayout* aGrpLayout = new QGridLayout(aGrp);
244 aGrpLayout->setMargin(MARGIN);
245 aGrpLayout->setSpacing(SPACING);
247 mySubmeshChk = new QCheckBox(tr("SMESH_SUBMESH"), aGrp);
248 mySubmeshBtn = new QPushButton(aGrp);
249 mySubmesh = new QLineEdit(aGrp);
250 mySubmesh->setReadOnly(true);
251 mySubmeshBtn->setIcon(aPix);
253 myGroupChk = new QCheckBox(tr("SMESH_GROUP"), aGrp);
254 myGroupBtn = new QPushButton(aGrp);
255 myGroup = new QLineEdit(aGrp);
256 myGroup->setReadOnly(true);
257 myGroupBtn->setIcon(aPix);
259 aGrpLayout->addWidget(mySubmeshChk,0,0);
260 aGrpLayout->addWidget(mySubmeshBtn,0,1);
261 aGrpLayout->addWidget(mySubmesh,0,2);
262 aGrpLayout->addWidget(myGroupChk,1,0);
263 aGrpLayout->addWidget(myGroupBtn,1,1);
264 aGrpLayout->addWidget(myGroup,1,2);
266 aMainGrpLayout->addWidget(mySelGrp);
267 aMainGrpLayout->addWidget(myCriterionGrp);
268 aMainGrpLayout->addWidget(aGrp);
273 //=======================================================================
274 // name : SMESHGUI_MultiEditDlg::createButtonFrame
275 // Purpose : Create frame containing buttons
276 //=======================================================================
277 QWidget* SMESHGUI_MultiEditDlg::createButtonFrame (QWidget* theParent)
279 QGroupBox* aFrame = new QGroupBox(theParent);
281 myOkBtn = new QPushButton (tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
282 myApplyBtn = new QPushButton (tr("SMESH_BUT_APPLY"), aFrame);
283 myCloseBtn = new QPushButton (tr("SMESH_BUT_CLOSE"), aFrame);
284 myHelpBtn = new QPushButton (tr("SMESH_BUT_HELP"), aFrame);
286 QHBoxLayout* aLay = new QHBoxLayout (aFrame);
287 aLay->setMargin(MARGIN);
288 aLay->setSpacing(SPACING);
290 aLay->addWidget(myOkBtn);
291 aLay->addSpacing(10);
292 aLay->addWidget(myApplyBtn);
293 aLay->addSpacing(10);
295 aLay->addWidget(myCloseBtn);
296 aLay->addWidget(myHelpBtn);
301 //=======================================================================
302 // name : SMESHGUI_MultiEditDlg::isValid
303 // Purpose : Verify validity of input data
304 //=======================================================================
305 bool SMESHGUI_MultiEditDlg::isValid (const bool /*theMess*/)
307 return (!myMesh->_is_nil() &&
308 (myListBox->count() > 0 || (myToAllChk->isChecked()/* && myActor*/)));
311 //=======================================================================
312 // name : SMESHGUI_MultiEditDlg::~SMESHGUI_MultiEditDlg
313 // Purpose : Destructor
314 //=======================================================================
315 SMESHGUI_MultiEditDlg::~SMESHGUI_MultiEditDlg()
317 if (myFilterDlg != 0)
319 myFilterDlg->setParent(0);
324 //=======================================================================
325 // name : SMESHGUI_MultiEditDlg::eventFilter
326 // Purpose : event filter
327 //=======================================================================
328 bool SMESHGUI_MultiEditDlg::eventFilter (QObject* object, QEvent* event)
330 if (object == myListBox && event->type() == QEvent::KeyPress) {
331 QKeyEvent* ke = (QKeyEvent*)event;
332 if (ke->key() == Qt::Key_Delete)
335 return QDialog::eventFilter(object, event);
338 //=======================================================================
339 // name : SMESHGUI_MultiEditDlg::getNumericalFunctor
341 //=======================================================================
342 SMESH::NumericalFunctor_ptr SMESHGUI_MultiEditDlg::getNumericalFunctor()
344 SMESH::NumericalFunctor_var aNF = SMESH::NumericalFunctor::_nil();
346 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
347 if (aFilterMgr->_is_nil())
350 if (myComboBoxFunctor->currentText() == tr("ASPECTRATIO_ELEMENTS"))
351 aNF = aFilterMgr->CreateAspectRatio();
352 else if (myComboBoxFunctor->currentText() == tr("WARP_ELEMENTS"))
353 aNF = aFilterMgr->CreateWarping();
354 else if (myComboBoxFunctor->currentText() == tr("MINIMUMANGLE_ELEMENTS"))
355 aNF = aFilterMgr->CreateMinimumAngle();
356 else if (myComboBoxFunctor->currentText() == tr("TAPER_ELEMENTS"))
357 aNF = aFilterMgr->CreateTaper();
358 else if (myComboBoxFunctor->currentText() == tr("SKEW_ELEMENTS"))
359 aNF = aFilterMgr->CreateSkew();
360 else if (myComboBoxFunctor->currentText() == tr("AREA_ELEMENTS"))
361 aNF = aFilterMgr->CreateArea();
362 else if (myComboBoxFunctor->currentText() == tr("LENGTH2D_EDGES"))
363 aNF = aFilterMgr->CreateLength2D();
364 else if (myComboBoxFunctor->currentText() == tr("MULTI2D_BORDERS"))
365 aNF = aFilterMgr->CreateMultiConnection2D();
366 else if (myComboBoxFunctor->currentText() == tr("MIN_DIAG_ELEMENTS"))
367 aNF = aFilterMgr->CreateMaxElementLength2D();
373 //=======================================================================
374 // name : SMESHGUI_MultiEditDlg::Init
375 // Purpose : Init dialog fields, connect signals and slots, show dialog
376 //=======================================================================
377 void SMESHGUI_MultiEditDlg::Init()
379 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
384 emit ListContensChanged();
387 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
388 connect(myCloseBtn, SIGNAL(clicked()), SLOT(reject()));
389 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
390 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
392 // selection and SMESHGUI
393 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
394 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
395 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
398 connect(myFilterBtn, SIGNAL(clicked()), SLOT(onFilterBtn() ));
399 connect(myAddBtn, SIGNAL(clicked()), SLOT(onAddBtn() ));
400 connect(myRemoveBtn, SIGNAL(clicked()), SLOT(onRemoveBtn() ));
401 connect(mySortBtn, SIGNAL(clicked()), SLOT(onSortListBtn()));
403 connect(mySubmeshChk, SIGNAL(stateChanged(int)), SLOT(onSubmeshChk()));
404 connect(myGroupChk, SIGNAL(stateChanged(int)), SLOT(onGroupChk() ));
405 connect(myToAllChk, SIGNAL(stateChanged(int)), SLOT(onToAllChk() ));
408 connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), SLOT(on3d2dChanged(int)));
410 connect(myListBox, SIGNAL(itemSelectionChanged()), SLOT(onListSelectionChanged()));
414 // set selection mode
419 //=======================================================================
420 // name : SMESHGUI_MultiEditDlg::onOk
421 // Purpose : SLOT called when "Ok" button pressed.
422 // Assign filters VTK viewer and close dialog
423 //=======================================================================
424 void SMESHGUI_MultiEditDlg::onOk()
430 //=======================================================================
431 // name : SMESHGUI_MultiEditDlg::getIds
432 // Purpose : Retrive identifiers from list box or the whole object
433 //=======================================================================
435 SMESH::long_array_var SMESHGUI_MultiEditDlg::getIds(SMESH::SMESH_IDSource_var& obj)
437 SMESH::long_array_var anIds = new SMESH::long_array;
439 if (myToAllChk->isChecked())
442 obj = SMESH::SMESH_IDSource::_narrow( myMesh );
445 anIds->length(myIds.Extent());
446 TColStd_MapIteratorOfMapOfInteger anIter(myIds);
447 for (int i = 0; anIter.More(); anIter.Next() )
449 anIds[ i++ ] = anIter.Key();
451 return anIds._retn();
454 //=======================================================================
455 // name : SMESHGUI_MultiEditDlg::reject
456 // Purpose : SLOT called when "Close" button pressed. Close dialog
457 //=======================================================================
458 void SMESHGUI_MultiEditDlg::reject()
460 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
461 aViewWindow->SetSelectionMode(ActorSelection);
462 disconnect(mySelectionMgr, 0, this, 0);
463 disconnect(mySMESHGUI, 0, this, 0);
464 mySMESHGUI->ResetState();
466 SMESH::RemoveFilters();
467 SMESH::SetPickable();
469 //mySelectionMgr->clearSelected();
470 mySelectionMgr->clearFilters();
475 //=================================================================================
476 // function : onHelp()
478 //=================================================================================
479 void SMESHGUI_MultiEditDlg::onHelp()
481 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
483 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
487 platform = "winapplication";
489 platform = "application";
491 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
492 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
493 arg(app->resourceMgr()->stringValue("ExternalBrowser",
495 arg(myHelpFileName));
499 //=======================================================================
500 // name : SMESHGUI_MultiEditDlg::onSelectionDone
501 // Purpose : SLOT called when selection changed
502 //=======================================================================
503 void SMESHGUI_MultiEditDlg::onSelectionDone()
505 if (myBusy || !isEnabled()) return;
508 const SALOME_ListIO& aList = mySelector->StoredIObjects();
510 int nbSel = aList.Extent();
511 myListBox->clearSelection();
513 if (mySubmeshChk->isChecked() || myGroupChk->isChecked()) {
514 QLineEdit* aNameEdit = mySubmeshChk->isChecked() ? mySubmesh : myGroup;
516 Handle(SALOME_InteractiveObject) anIO = aList.First();
518 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
519 anIO.IsNull() ? aNameEdit->clear() : aNameEdit->setText(aName);
521 if (mySubmeshChk->isChecked()) {
522 SMESH::SMESH_subMesh_var aSubMesh =
523 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIO);
524 if (!aSubMesh->_is_nil())
525 myMesh = aSubMesh->GetFather();
527 SMESH::SMESH_GroupBase_var aGroup =
528 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIO);
529 if (!aGroup->_is_nil())
530 myMesh = aGroup->GetMesh();
532 } else if (nbSel > 1) {
533 QString aStr = mySubmeshChk->isChecked() ?
534 tr("SMESH_SUBMESH_SELECTED") : tr("SMESH_GROUP_SELECTED");
535 aNameEdit->setText(aStr.arg(nbSel));
539 } else if (nbSel > 0) {
540 QString aListStr = "";
541 Handle(SALOME_InteractiveObject) anIO = aList.First();
542 int aNbItems = SMESH::GetNameOfSelectedElements(mySelector,anIO,aListStr);
544 QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
545 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
546 QList<QListWidgetItem*> items = myListBox->findItems(*it, Qt::MatchExactly);
547 QListWidgetItem* anItem;
548 foreach(anItem, items)
549 anItem->setSelected(true);
552 SMESH::SMESH_Mesh_var aSelMesh = SMESH::GetMeshByIO(anIO);
553 if (!aSelMesh->_is_nil())
558 myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
560 myActor = SMESH::FindActorByObject(myMesh);
561 SVTK_Selector* aSelector = SMESH::GetSelector();
562 Handle(VTKViewer_Filter) aFilter = aSelector->GetFilter(myFilterType);
563 if (!aFilter.IsNull())
564 aFilter->SetActor(myActor);
571 //=======================================================================
572 // name : SMESHGUI_MultiEditDlg::onDeactivate
573 // Purpose : SLOT called when dialog must be deativated
574 //=======================================================================
575 void SMESHGUI_MultiEditDlg::onDeactivate()
580 //=======================================================================
581 // name : SMESHGUI_MultiEditDlg::enterEvent
582 // Purpose : Event filter
583 //=======================================================================
584 void SMESHGUI_MultiEditDlg::enterEvent (QEvent*)
587 mySMESHGUI->EmitSignalDeactivateDialog();
593 //=======================================================================
594 // name : SMESHGUI_MultiEditDlg::onFilterBtn
595 // Purpose : SLOT. Called when "Filter" button pressed.
596 // Start "Selection filters" dialog
597 //=======================================================================
598 void SMESHGUI_MultiEditDlg::onFilterBtn()
600 if (myFilterDlg == 0) {
601 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, entityType() ? SMESH::VOLUME : SMESH::FACE);
602 connect(myFilterDlg, SIGNAL(Accepted()), SLOT(onFilterAccepted()));
604 myFilterDlg->Init(entityType() ? SMESH::VOLUME : SMESH::FACE);
607 myFilterDlg->SetSelection();
608 myFilterDlg->SetMesh(myMesh);
609 myFilterDlg->SetSourceWg(myListBox, false);
614 //=======================================================================
615 // name : onFilterAccepted()
616 // Purpose : SLOT. Called when Filter dlg closed with OK button.
617 // Uncheck "Select submesh" and "Select group" checkboxes
618 //=======================================================================
619 void SMESHGUI_MultiEditDlg::onFilterAccepted()
622 for (int i = 0, n = myListBox->count(); i < n; i++)
623 myIds.Add(myListBox->item(i)->text().toInt());
625 emit ListContensChanged();
627 if (mySubmeshChk->isChecked() || myGroupChk->isChecked()) {
628 mySubmeshChk->blockSignals(true);
629 myGroupChk->blockSignals(true);
630 mySubmeshChk->setChecked(false);
631 myGroupChk->setChecked(false);
632 mySubmeshChk->blockSignals(false);
633 myGroupChk->blockSignals(false);
638 //=======================================================================
639 // name : SMESHGUI_MultiEditDlg::isIdValid
640 // Purpose : Verify whether Id of element satisfies to filters from viewer
641 //=======================================================================
642 bool SMESHGUI_MultiEditDlg::isIdValid (const int theId) const
644 SVTK_Selector* aSelector = SMESH::GetSelector();
645 Handle(SMESHGUI_Filter) aFilter =
646 Handle(SMESHGUI_Filter)::DownCast(aSelector->GetFilter(myFilterType));
648 return (!aFilter.IsNull() && aFilter->IsObjValid(theId));
651 //=======================================================================
652 // name : SMESHGUI_MultiEditDlg::onAddBtn
653 // Purpose : SLOT. Called when "Add" button pressed.
654 // Add selected in viewer entities in list box
655 //=======================================================================
656 void SMESHGUI_MultiEditDlg::onAddBtn()
658 const SALOME_ListIO& aList = mySelector->StoredIObjects();
660 int nbSelected = aList.Extent();
664 TColStd_IndexedMapOfInteger toBeAdded;
666 if (!mySubmeshChk->isChecked() && !myGroupChk->isChecked()) {
668 mySelector->GetIndex(aList.First(),toBeAdded);
669 } else if (mySubmeshChk->isChecked()) {
670 SALOME_ListIteratorOfListIO anIter(aList);
671 for ( ; anIter.More(); anIter.Next()) {
672 SMESH::SMESH_subMesh_var aSubMesh =
673 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Value());
674 if (!aSubMesh->_is_nil()) {
675 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
676 SMESH::long_array_var anIds = aSubMesh->GetElementsId();
677 for (int i = 0, n = anIds->length(); i < n; i++) {
678 if (isIdValid(anIds[ i ]))
679 toBeAdded.Add(anIds[ i ]);
684 } else if (myGroupChk->isChecked()) {
685 SALOME_ListIteratorOfListIO anIter(aList);
686 for ( ; anIter.More(); anIter.Next()) {
687 SMESH::SMESH_GroupBase_var aGroup =
688 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
689 if (!aGroup->_is_nil() && ((aGroup->GetType() == SMESH::FACE && entityType() == 0) ||
690 (aGroup->GetType() == SMESH::VOLUME && entityType() == 1))) {
691 if (aGroup->GetMesh()->GetId() == myMesh->GetId()) {
692 SMESH::long_array_var anIds = aGroup->GetListOfID();
693 for (int i = 0, n = anIds->length(); i < n; i++) {
694 if (isIdValid(anIds[ i ]))
695 toBeAdded.Add(anIds[ i ]);
704 bool isGroupOrSubmesh = (mySubmeshChk->isChecked() || myGroupChk->isChecked());
705 mySubmeshChk->setChecked(false);
706 myGroupChk->setChecked(false);
708 for(int i = 1; i <= toBeAdded.Extent(); i++)
709 if (myIds.Add(toBeAdded(i))) {
710 items.append(QString("%1").arg(toBeAdded(i)));
712 myListBox->addItems(items);
713 myListBox->selectAll();
716 emit ListContensChanged();
718 if (isGroupOrSubmesh)
719 onListSelectionChanged();
724 //=======================================================================
725 // name : SMESHGUI_MultiEditDlg::updateButtons
726 // Purpose : Enable/disable buttons of dialog in accordance with current state
727 //=======================================================================
728 void SMESHGUI_MultiEditDlg::updateButtons()
730 bool isOk = isValid(false);
731 myOkBtn->setEnabled(isOk);
732 myApplyBtn->setEnabled(isOk);
734 bool isListBoxNonEmpty = myListBox->count() > 0;
735 bool isToAll = myToAllChk->isChecked();
736 myFilterBtn->setEnabled(!isToAll);
737 myRemoveBtn->setEnabled(isListBoxNonEmpty && !isToAll);
738 mySortBtn->setEnabled(isListBoxNonEmpty &&!isToAll);
740 const SALOME_ListIO& aList = mySelector->StoredIObjects();
744 aList.Extent() < 1 ||
745 (SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(aList.First())->_is_nil() &&
746 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(aList.First())->_is_nil() &&
747 SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First())->_is_nil()))
748 myAddBtn->setEnabled(false);
750 myAddBtn->setEnabled(true);
752 mySubmeshChk->setEnabled(!isToAll);
753 mySubmeshBtn->setEnabled(mySubmeshChk->isChecked());
754 mySubmesh->setEnabled(mySubmeshChk->isChecked());
756 myGroupChk->setEnabled(!isToAll);
757 myGroupBtn->setEnabled(myGroupChk->isChecked());
758 myGroup->setEnabled(myGroupChk->isChecked());
760 if (!mySubmeshChk->isChecked())
762 if (!myGroupChk->isChecked())
767 //=======================================================================
768 // name : SMESHGUI_MultiEditDlg::onRemoveBtn
769 // Purpose : SLOT. Called when "Remove" button pressed.
770 // Remove selected in list box entities
771 //=======================================================================
772 void SMESHGUI_MultiEditDlg::onRemoveBtn()
776 QList<QListWidgetItem*> selItems = myListBox->selectedItems();
777 QListWidgetItem* item;
778 foreach(item, selItems)
780 myIds.Remove(item->text().toInt());
786 emit ListContensChanged();
790 //=======================================================================
791 // name : SMESHGUI_MultiEditDlg::onSortListBtn
792 // Purpose : SLOT. Called when "Sort list" button pressed.
793 // Sort entities of list box
794 //=======================================================================
795 void SMESHGUI_MultiEditDlg::onSortListBtn()
799 int i, k = myListBox->count();
802 QList<int> aSelected;
803 std::vector<int> anArray(k);
804 for (i = 0; i < k; i++)
806 int id = myListBox->item(i)->text().toInt();
808 if (myListBox->item(i)->isSelected())
809 aSelected.append(id);
812 std::sort(anArray.begin(), anArray.end());
815 for (i = 0; i < k; i++) {
816 QListWidgetItem* item = new QListWidgetItem(QString::number(anArray[i]));
817 myListBox->addItem(item);
818 item->setSelected(aSelected.contains(anArray[i]));
824 //=======================================================================
825 // name : SMESHGUI_MultiEditDlg::onListSelectionChanged
826 // Purpose : SLOT. Called when selection in list box changed.
827 // Highlight in selected entities
828 //=======================================================================
829 void SMESHGUI_MultiEditDlg::onListSelectionChanged()
831 if (myActor == 0 || myBusy)
834 if (mySubmeshChk->isChecked() || myGroupChk->isChecked())
837 SMESH_Actor * anActor = SMESH::FindActorByObject(myMesh);
840 TVisualObjPtr anObj = anActor->GetObject();
842 TColStd_MapOfInteger anIndexes;
843 int total = myListBox->count();
844 for (int i = 0; i < total; i++)
846 if (myListBox->item(i)->isSelected())
848 int anId = myListBox->item(i)->text().toInt();
849 if (anObj->GetElemVTKId(anId) >= 0) // avoid exception in hilight
854 mySelector->AddOrRemoveIndex(anActor->getIO(),anIndexes,false);
855 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
856 aViewWindow->highlight(anActor->getIO(),true,true);
859 //=======================================================================
860 // name : SMESHGUI_MultiEditDlg::onSubmeshChk
861 // Purpose : SLOT. Called when state of "SubMesh" check box changed.
862 // Activate/deactivate selection of submeshes
863 //=======================================================================
864 void SMESHGUI_MultiEditDlg::onSubmeshChk()
866 bool isChecked = mySubmeshChk->isChecked();
867 mySubmeshBtn->setEnabled(isChecked);
868 mySubmesh->setEnabled(isChecked);
871 if (isChecked && myGroupChk->isChecked())
872 myGroupChk->setChecked(false);
877 //=======================================================================
878 // name : SMESHGUI_MultiEditDlg::onGroupChk
879 // Purpose : SLOT. Called when state of "Group" check box changed.
880 // Activate/deactivate selection of groupes
881 //=======================================================================
882 void SMESHGUI_MultiEditDlg::onGroupChk()
884 bool isChecked = myGroupChk->isChecked();
885 myGroupBtn->setEnabled(isChecked);
886 myGroup->setEnabled(isChecked);
889 if (isChecked && mySubmeshChk->isChecked())
890 mySubmeshChk->setChecked(false);
895 //=======================================================================
896 // name : SMESHGUI_MultiEditDlg::onToAllChk
897 // Purpose : SLOT. Called when state of "Apply to all" check box changed.
898 // Activate/deactivate selection
899 //=======================================================================
900 void SMESHGUI_MultiEditDlg::onToAllChk()
902 bool isChecked = myToAllChk->isChecked();
909 emit ListContensChanged();
915 //=======================================================================
916 // name : SMESHGUI_MultiEditDlg::setSelectionMode
917 // Purpose : Set selection mode
918 //=======================================================================
919 void SMESHGUI_MultiEditDlg::setSelectionMode()
921 SMESH::RemoveFilters();
923 // mySelectionMgr->clearSelected();
924 mySelectionMgr->clearFilters();
926 if (mySubmeshChk->isChecked()) {
927 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928 aViewWindow->SetSelectionMode(ActorSelection);
929 mySelectionMgr->installFilter(new SMESH_TypeFilter(SMESH::SUBMESH));
931 else if (myGroupChk->isChecked()) {
932 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
933 aViewWindow->SetSelectionMode(ActorSelection);
934 mySelectionMgr->installFilter(new SMESH_TypeFilter(SMESH::GROUP));
938 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
939 aViewWindow->SetSelectionMode(VolumeSelection);
940 SMESH::SetFilter(new SMESHGUI_VolumesFilter());
942 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
943 aViewWindow->SetSelectionMode(FaceSelection);
944 if (myFilterType == SMESH::TriaFilter)
945 SMESH::SetFilter(new SMESHGUI_TriangleFilter());
946 else if (myFilterType == SMESH::QuadFilter)
947 SMESH::SetFilter(new SMESHGUI_QuadrangleFilter());
949 SMESH::SetFilter(new SMESHGUI_FacesFilter());
953 //=======================================================================
954 // name : SMESHGUI_MultiEditDlg::onApply
955 // Purpose : SLOT. Called when "Apply" button clicked.
956 //=======================================================================
957 bool SMESHGUI_MultiEditDlg::onApply()
959 if (mySMESHGUI->isActiveStudyLocked())
964 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
965 if (aMeshEditor->_is_nil())
970 SUIT_OverrideCursor aWaitCursor;
972 SMESH::SMESH_IDSource_var obj;
973 SMESH::long_array_var anIds = getIds(obj);
975 bool aResult = process(aMeshEditor, anIds.inout(), obj);
979 mySelectionMgr->selectedObjects( sel );
980 mySelector->ClearIndex();
981 mySelectionMgr->setSelectedObjects( sel );
983 SMESHGUI::Modified();
988 emit ListContensChanged();
992 obj._retn(); // else myMesh is deleted by ~obj
998 //=======================================================================
999 // name : SMESHGUI_MultiEditDlg::on3d2dChanged
1001 //=======================================================================
1002 void SMESHGUI_MultiEditDlg::on3d2dChanged (int type)
1004 if (myEntityType != type) {
1005 myEntityType = type;
1010 emit ListContensChanged();
1013 myFilterType = SMESH::VolumeFilter;
1015 myFilterType = SMESH::FaceFilter;
1022 //=======================================================================
1023 // name : SMESHGUI_MultiEditDlg::entityType
1025 //=======================================================================
1026 int SMESHGUI_MultiEditDlg::entityType()
1028 return myEntityType;
1031 //=================================================================================
1032 // function : keyPressEvent()
1034 //=================================================================================
1035 void SMESHGUI_MultiEditDlg::keyPressEvent( QKeyEvent* e )
1037 QDialog::keyPressEvent( e );
1038 if ( e->isAccepted() )
1041 if ( e->key() == Qt::Key_F1 ) {
1048 * Class : SMESHGUI_ChangeOrientationDlg
1049 * Description : Modification of orientation of faces
1052 SMESHGUI_ChangeOrientationDlg
1053 ::SMESHGUI_ChangeOrientationDlg(SMESHGUI* theModule):
1054 SMESHGUI_MultiEditDlg(theModule, SMESH::FaceFilter, true)
1056 setWindowTitle(tr("CAPTION"));
1057 myHelpFileName = "changing_orientation_of_elements_page.html";
1060 SMESHGUI_ChangeOrientationDlg::~SMESHGUI_ChangeOrientationDlg()
1064 bool SMESHGUI_ChangeOrientationDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
1065 const SMESH::long_array& theIds,
1066 SMESH::SMESH_IDSource_ptr obj)
1068 if ( CORBA::is_nil( obj ))
1069 return theEditor->Reorient(theIds);
1071 return theEditor->ReorientObject( obj );
1075 * Class : SMESHGUI_UnionOfTrianglesDlg
1076 * Description : Construction of quadrangles by automatic association of triangles
1079 SMESHGUI_UnionOfTrianglesDlg
1080 ::SMESHGUI_UnionOfTrianglesDlg(SMESHGUI* theModule):
1081 SMESHGUI_MultiEditDlg(theModule, SMESH::TriaFilter, false)
1083 setWindowTitle(tr("CAPTION"));
1086 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), mySelGrp);
1087 QGridLayout* aLay = (QGridLayout*)(mySelGrp->layout());
1088 aLay->addWidget(myPreviewCheckBox, aLay->rowCount(), 0, 1, aLay->columnCount());
1090 myComboBoxFunctor->setEnabled(true);
1091 myComboBoxFunctor->addItem(tr("AREA_ELEMENTS"));
1092 myComboBoxFunctor->addItem(tr("WARP_ELEMENTS")); // for quadrangles only
1093 myComboBoxFunctor->addItem(tr("TAPER_ELEMENTS")); // for quadrangles only
1096 QWidget* aMaxAngleGrp = new QWidget(myCriterionGrp);
1097 QHBoxLayout* aMaxAngleGrpLayout = new QHBoxLayout(aMaxAngleGrp);
1098 aMaxAngleGrpLayout->setMargin(0);
1099 aMaxAngleGrpLayout->setSpacing(SPACING);
1101 QLabel* aLab = new QLabel (tr("MAXIMUM_ANGLE"), aMaxAngleGrp);
1102 myMaxAngleSpin = new SMESHGUI_SpinBox (aMaxAngleGrp);
1103 myMaxAngleSpin->RangeStepAndValidator(0, 180.0, 1.0, "angle_precision");
1104 myMaxAngleSpin->SetValue(30.0);
1106 aMaxAngleGrpLayout->addWidget(aLab);
1107 aMaxAngleGrpLayout->addWidget(myMaxAngleSpin);
1109 ((QVBoxLayout*)(myCriterionGrp->layout()))->addWidget(aMaxAngleGrp);
1110 myCriterionGrp->show();
1112 connect(myComboBoxFunctor, SIGNAL(activated(int)), this, SLOT(toDisplaySimulation()));
1113 connect(myMaxAngleSpin, SIGNAL(valueChanged(int)), this, SLOT(toDisplaySimulation()));
1114 connect(this, SIGNAL(ListContensChanged()), this, SLOT(toDisplaySimulation()));
1115 connectPreviewControl(); //To Connect preview check box
1117 myPreviewCheckBox->setChecked(false);
1118 onDisplaySimulation(false);
1120 myHelpFileName = "uniting_set_of_triangles_page.html";
1123 SMESHGUI_UnionOfTrianglesDlg::~SMESHGUI_UnionOfTrianglesDlg()
1127 bool SMESHGUI_UnionOfTrianglesDlg::isValid (const bool theMess)
1129 bool ok = SMESHGUI_MultiEditDlg::isValid( theMess );
1134 ok = myMaxAngleSpin->isValid( msg, theMess );
1137 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1138 if ( !msg.isEmpty() )
1140 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1148 bool SMESHGUI_UnionOfTrianglesDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
1149 const SMESH::long_array& theIds,
1150 SMESH::SMESH_IDSource_ptr obj)
1153 QStringList aParameters;
1154 aParameters << myMaxAngleSpin->text();
1155 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
1157 SMESH::NumericalFunctor_var aCriterion = getNumericalFunctor();
1158 double aMaxAngle = myMaxAngleSpin->GetValue() * M_PI / 180.0;
1160 if ( CORBA::is_nil( obj ))
1161 ok = theEditor->TriToQuad(theIds, aCriterion, aMaxAngle);
1163 ok = theEditor->TriToQuadObject(obj, aCriterion, aMaxAngle);
1167 void SMESHGUI_UnionOfTrianglesDlg::onDisplaySimulation( bool toDisplayPreview )
1169 if ( myPreviewCheckBox->isChecked() && toDisplayPreview ) {
1170 if ( isValid( true ) ) {
1172 SUIT_OverrideCursor aWaitCursor;
1173 // get Ids of elements
1174 SMESH::SMESH_IDSource_var obj;
1175 SMESH::long_array_var anElemIds = getIds( obj );
1177 SMESH::NumericalFunctor_var aCriterion = getNumericalFunctor();
1178 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1180 double aMaxAngle = myMaxAngleSpin->GetValue() * M_PI / 180.0;
1182 if ( CORBA::is_nil( obj ) )
1183 aMeshEditor->TriToQuad( anElemIds.inout(), aCriterion, aMaxAngle );
1185 aMeshEditor->TriToQuadObject( obj, aCriterion, aMaxAngle );
1187 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1189 vtkProperty* aProp = vtkProperty::New();
1190 aProp->SetRepresentationToWireframe();
1191 aProp->SetColor( 250, 0, 250 );
1192 aProp->SetLineWidth( SMESH::GetFloat( "SMESH:element_width", 1 ) + 3 );
1193 mySimulation->GetActor()->SetProperty( aProp );
1196 mySimulation->SetData( aMeshPreviewStruct._retn() );
1209 * Class : SMESHGUI_CuttingOfQuadsDlg
1210 * Description : Automatic splitting of quadrangles into triangles
1213 SMESHGUI_CuttingOfQuadsDlg
1214 ::SMESHGUI_CuttingOfQuadsDlg(SMESHGUI* theModule):
1215 SMESHGUI_MultiEditDlg(theModule, SMESH::QuadFilter, false)
1217 setWindowTitle(tr("CAPTION"));
1220 myPreviewChk = new QCheckBox (tr("PREVIEW"), mySelGrp);
1221 QGridLayout* aLay = (QGridLayout*)(mySelGrp->layout());
1222 aLay->addWidget(myPreviewChk, aLay->rowCount(), 0, 1, aLay->columnCount());
1224 // "split to 4 tria" option
1226 QRadioButton* to4TriaRB = new QRadioButton(tr("TO_4_TRIA"), myChoiceWidget);
1227 ((QVBoxLayout*)(myCriterionGrp->layout()))->insertWidget(0, to4TriaRB);
1228 myGroupChoice->addButton(to4TriaRB, 3);
1229 to4TriaRB->setChecked(true);
1232 myCriterionGrp->show();
1233 myChoiceWidget->show();
1234 myComboBoxFunctor->insertItem(0, tr("MIN_DIAG_ELEMENTS"));
1235 myComboBoxFunctor->setCurrentIndex(0);
1236 myComboBoxFunctor->setEnabled(false);
1238 connect(myPreviewChk, SIGNAL(stateChanged(int)), this, SLOT(onPreviewChk()));
1239 connect(myGroupChoice, SIGNAL(buttonClicked(int)), this, SLOT(onCriterionRB()));
1240 connect(myComboBoxFunctor, SIGNAL(activated(int)), this, SLOT(onPreviewChk()));
1241 connect(this, SIGNAL(ListContensChanged()), this, SLOT(onPreviewChk()));
1243 myHelpFileName = "cutting_quadrangles_page.html";
1246 SMESHGUI_CuttingOfQuadsDlg::~SMESHGUI_CuttingOfQuadsDlg()
1250 void SMESHGUI_CuttingOfQuadsDlg::reject()
1253 SMESHGUI_MultiEditDlg::reject();
1256 bool SMESHGUI_CuttingOfQuadsDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
1257 const SMESH::long_array& theIds,
1258 SMESH::SMESH_IDSource_ptr obj)
1260 bool hasObj = (! CORBA::is_nil( obj ));
1261 switch (myGroupChoice->checkedId()) {
1262 case 0: // use diagonal 1-3
1263 return hasObj ? theEditor->SplitQuadObject(obj, true) : theEditor->SplitQuad(theIds, true);
1264 case 1: // use diagonal 2-4
1265 return hasObj ? theEditor->SplitQuadObject(obj, false) : theEditor->SplitQuad(theIds, false);
1266 case 3: // split to 4 tria
1269 return theEditor->QuadTo4Tri( obj ), true;
1270 SMESH::SMESH_IDSource_wrap elems = theEditor->MakeIDSource( theIds, SMESH::FACE );
1271 theEditor->QuadTo4Tri( elems );
1274 default: // use numeric functor
1278 SMESH::NumericalFunctor_var aCrit = getNumericalFunctor();
1279 return hasObj ? theEditor->QuadToTriObject(obj, aCrit) : theEditor->QuadToTri(theIds, aCrit);
1282 void SMESHGUI_CuttingOfQuadsDlg::onCriterionRB()
1284 if (myGroupChoice->checkedId() == 2) // Use numeric functor
1285 myComboBoxFunctor->setEnabled(true);
1287 myComboBoxFunctor->setEnabled(false);
1289 if (myGroupChoice->checkedId() == 3) // To 4 tria
1291 if ( myPreviewChk->isChecked() )
1292 myPreviewChk->setChecked( false );
1293 myPreviewChk->setEnabled( false );
1297 myPreviewChk->setEnabled( true );
1302 void SMESHGUI_CuttingOfQuadsDlg::onPreviewChk()
1304 myPreviewChk->isChecked() ? displayPreview() : erasePreview();
1307 void SMESHGUI_CuttingOfQuadsDlg::erasePreview()
1309 if (myPreviewActor == 0)
1312 if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView()) {
1313 vf->RemoveActor(myPreviewActor);
1316 myPreviewActor->Delete();
1320 void SMESHGUI_CuttingOfQuadsDlg::displayPreview()
1325 if (myPreviewActor != 0)
1328 SUIT_OverrideCursor aWaitCursor;
1329 // get Ids of elements
1330 SMESH::SMESH_IDSource_var obj;
1331 SMESH::long_array_var anElemIds = getIds(obj);
1332 if (anElemIds->length() == 0 && obj->_is_nil() )
1335 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
1339 // 0 - use diagonal 1-3, 1 - use diagonal 2-4, 2 - use numerical functor
1340 int aChoice = myGroupChoice->checkedId();
1341 SMESH::NumericalFunctor_var aCriterion = SMESH::NumericalFunctor::_nil();
1342 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH::SMESH_MeshEditor::_nil();
1344 aCriterion = getNumericalFunctor();
1345 aMeshEditor = myMesh->GetMeshEditor();
1346 if (aMeshEditor->_is_nil())
1350 if ( anElemIds->length() == 0 ) {
1351 anElemIds = obj->GetIDs();
1355 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
1357 vtkIdType aNbCells = anElemIds->length() * 2;
1358 vtkIdType aCellsSize = 4 * aNbCells;
1359 vtkCellArray* aConnectivity = vtkCellArray::New();
1360 aConnectivity->Allocate(aCellsSize, 0);
1362 vtkPoints* aPoints = vtkPoints::New();
1363 aPoints->SetNumberOfPoints(anElemIds->length() * 4);
1365 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
1366 aCellTypesArray->SetNumberOfComponents(1);
1367 aCellTypesArray->Allocate(aNbCells * aCellTypesArray->GetNumberOfComponents());
1369 vtkIdList *anIdList = vtkIdList::New();
1370 anIdList->SetNumberOfIds(3);
1372 TColStd_DataMapOfIntegerInteger anIdToVtk;
1376 for (int i = 0, n = anElemIds->length(); i < n; i++)
1378 const SMDS_MeshElement* anElem = aMesh->FindElement(anElemIds[ i ]);
1379 if (anElem == 0 || anElem->NbNodes() != 4)
1382 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
1384 while (anIter->more()) {
1385 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIter->next());
1388 if (!anIdToVtk.IsBound(aNode->GetID()))
1390 aPoints->SetPoint(++nbPoints, aNode->X(), aNode->Y(), aNode->Z());
1391 anIdToVtk.Bind(aNode->GetID(), nbPoints);
1394 aNodes[ k++ ] = aNode->GetID();
1401 bool isDiag13 = true;
1402 if (aChoice == 0) // use diagonal 1-3
1406 else if (aChoice == 1) // use diagonal 2-4
1410 else // use numerical functor
1412 // compare two sets of possible triangles
1413 int diag = aMeshEditor->BestSplit(anElemIds[i], aCriterion);
1414 if (diag == 1) // 1-3
1416 else if (diag == 2) // 2-4
1424 anIdList->SetId(0, anIdToVtk(aNodes[ 0 ]));
1425 anIdList->SetId(1, anIdToVtk(aNodes[ 1 ]));
1426 anIdList->SetId(2, anIdToVtk(aNodes[ 2 ]));
1427 aConnectivity->InsertNextCell(anIdList);
1428 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1430 anIdList->SetId(0, anIdToVtk(aNodes[ 2 ]));
1431 anIdList->SetId(1, anIdToVtk(aNodes[ 3 ]));
1432 anIdList->SetId(2, anIdToVtk(aNodes[ 0 ]));
1433 aConnectivity->InsertNextCell(anIdList);
1434 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1438 anIdList->SetId(0, anIdToVtk(aNodes[ 1 ]));
1439 anIdList->SetId(1, anIdToVtk(aNodes[ 2 ]));
1440 anIdList->SetId(2, anIdToVtk(aNodes[ 3 ]));
1441 aConnectivity->InsertNextCell(anIdList);
1442 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1444 anIdList->SetId(0, anIdToVtk(aNodes[ 3 ]));
1445 anIdList->SetId(1, anIdToVtk(aNodes[ 0 ]));
1446 anIdList->SetId(2, anIdToVtk(aNodes[ 1 ]));
1447 aConnectivity->InsertNextCell(anIdList);
1448 aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1452 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
1453 aCellLocationsArray->SetNumberOfComponents(1);
1454 aCellLocationsArray->SetNumberOfTuples(aNbCells);
1456 aConnectivity->InitTraversal();
1457 for(vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell(npts, pts); idType++)
1458 aCellLocationsArray->SetValue(idType, aConnectivity->GetTraversalLocation(npts));
1460 aGrid->SetPoints(aPoints);
1461 aGrid->SetCells(aCellTypesArray, aCellLocationsArray,aConnectivity);
1463 // Create and display actor
1464 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
1465 aMapper->SetInputData(aGrid);
1467 myPreviewActor = SALOME_Actor::New();
1468 myPreviewActor->PickableOff();
1469 myPreviewActor->SetMapper(aMapper);
1471 vtkProperty* aProp = vtkProperty::New();
1472 aProp->SetRepresentationToWireframe();
1473 aProp->SetColor(250, 0, 250);
1474 aProp->SetLineWidth(myActor->GetLineWidth() + 1);
1475 myPreviewActor->SetProperty(aProp);
1477 SMESH::GetCurrentVtkView()->AddActor(myPreviewActor);
1478 SMESH::GetCurrentVtkView()->Repaint();
1482 aConnectivity->Delete();
1486 aCellTypesArray->Delete();
1487 aCellLocationsArray->Delete();
1491 * Class : SMESHGUI_CuttingIntoTetraDlg
1492 * Description : Modification of orientation of faces
1495 SMESHGUI_CuttingIntoTetraDlg::SMESHGUI_CuttingIntoTetraDlg(SMESHGUI* theModule)
1496 : SMESHGUI_MultiEditDlg(theModule, SMESH::VolumeFilter, false)
1498 setWindowTitle(tr("CAPTION"));
1499 myHelpFileName = "split_to_tetra_page.html";
1502 myToAllChk->setChecked( true ); //aplly to the whole mesh by default
1504 bool hasHexa = true;//myMesh->_is_nil() ? false : myMesh->NbHexas();
1508 myGroupChoice->button(0)->setText( tr("SPLIT_HEX_TO_5_TETRA"));
1509 myGroupChoice->button(1)->setText( tr("SPLIT_HEX_TO_6_TETRA"));
1510 myGroupChoice->button(2)->setText( tr("SPLIT_HEX_TO_24_TETRA"));
1512 myCriterionGrp->setTitle( tr("SPLIT_METHOD"));
1513 myCriterionGrp->show();
1514 myComboBoxFunctor->hide();
1515 myChoiceWidget->show();
1521 SMESHGUI_CuttingIntoTetraDlg::~SMESHGUI_CuttingIntoTetraDlg()
1525 bool SMESHGUI_CuttingIntoTetraDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
1526 const SMESH::long_array& theIds,
1527 SMESH::SMESH_IDSource_ptr theObj)
1529 SMESH::SMESH_IDSource_wrap obj = theObj;
1530 if ( CORBA::is_nil( obj ))
1531 obj = theEditor->MakeIDSource( theIds, myEntityType ? SMESH::VOLUME : SMESH::FACE );
1535 theEditor->SplitVolumesIntoTetra( obj, myGroupChoice->checkedId()+1 );
1537 catch ( const SALOME::SALOME_Exception& S_ex ) {
1538 SalomeApp_Tools::QtCatchCorbaException( S_ex );