1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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_MeshPatternDlg.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_MeshPatternDlg.h"
30 #include "SMESHGUI_CreatePatternDlg.h"
31 #include "SMESHGUI_PatternWidget.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_PatternUtils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_ActorUtils.h>
39 #include <SMESH_NumberFilter.hxx>
41 #include <SMDS_Mesh.hxx>
42 #include <SMDS_MeshElement.hxx>
44 // SALOME GUI includes
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_FileDlg.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_MessageBox.h>
51 #include <LightApp_SelectionMgr.h>
52 #include <SalomeApp_Tools.h>
53 #include <LightApp_Application.h>
55 #include <SALOME_ListIO.hxx>
57 #include <SVTK_ViewModel.h>
58 #include <SVTK_ViewWindow.h>
59 #include <VTKViewer_CellLocationsArray.h>
61 // SALOME KERNEL includes
62 #include <SALOMEDS_SObject.hxx>
65 #include <TColStd_MapOfInteger.hxx>
69 #include <QVBoxLayout>
70 #include <QHBoxLayout>
71 #include <QGridLayout>
73 #include <QPushButton>
76 #include <QRadioButton>
78 #include <QButtonGroup>
82 #include <QFileDialog>
88 #include <vtkIdList.h>
89 #include <vtkCellArray.h>
90 #include <vtkUnsignedCharArray.h>
91 #include <vtkUnstructuredGrid.h>
92 #include <vtkDataSetMapper.h>
93 #include <vtkProperty.h>
99 * Class : SMESHGUI_MeshPatternDlg
100 * Description : Dialog to specify filters for VTK viewer
103 //=======================================================================
104 // name : SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg
105 // Purpose : Constructor
106 //=======================================================================
107 SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg( SMESHGUI* theModule )
108 : QDialog( SMESH::GetDesktop( theModule ) ),
109 mySMESHGUI( theModule ),
110 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
115 setWindowTitle( tr( "CAPTION" ) );
117 QVBoxLayout* aDlgLay = new QVBoxLayout( this );
118 aDlgLay->setMargin( MARGIN );
119 aDlgLay->setSpacing( SPACING );
121 QWidget* aMainFrame = createMainFrame ( this );
122 QWidget* aBtnFrame = createButtonFrame( this );
124 aDlgLay->addWidget( aMainFrame );
125 aDlgLay->addWidget( aBtnFrame );
127 aDlgLay->setStretchFactor( aMainFrame, 1 );
129 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
131 myHelpFileName = "pattern_mapping_page.html";
136 //=======================================================================
137 // name : SMESHGUI_MeshPatternDlg::createMainFrame
138 // Purpose : Create frame containing dialog's input fields
139 //=======================================================================
140 QWidget* SMESHGUI_MeshPatternDlg::createMainFrame (QWidget* theParent)
142 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
143 QPixmap iconSlct ( mgr->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
144 QPixmap icon2d ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) );
145 QPixmap icon3d ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) );
146 QPixmap iconOpen ( mgr->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ) );
148 QPixmap iconSample2d ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) );
149 QPixmap iconSample3d ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_3D" ) ) );
151 QWidget* aMainGrp = new QWidget( theParent );
153 QVBoxLayout* aMainGrpLayout = new QVBoxLayout( aMainGrp );
154 aMainGrpLayout->setMargin( 0 );
155 aMainGrpLayout->setSpacing( SPACING );
157 // Pattern type group
159 QGroupBox* aTypeGrp = new QGroupBox( tr( "PATTERN_TYPE" ), aMainGrp );
160 QHBoxLayout* aTypeGrpLayout = new QHBoxLayout( aTypeGrp );
161 aTypeGrpLayout->setMargin( MARGIN );
162 aTypeGrpLayout->setSpacing( SPACING );
164 mySwitch2d = new QRadioButton( aTypeGrp );
165 mySwitch3d = new QRadioButton( aTypeGrp );
166 mySwitch2d->setIcon( icon2d );
167 mySwitch3d->setIcon( icon3d );
169 myTypeGrp = new QButtonGroup( aMainGrp );
170 myTypeGrp->addButton( mySwitch2d, Type_2d );
171 myTypeGrp->addButton( mySwitch3d, Type_3d );
173 // ... layout widgets
175 aTypeGrpLayout->addWidget( mySwitch2d );
176 aTypeGrpLayout->addWidget( mySwitch3d );
180 QGroupBox* aMeshGrp = new QGroupBox( tr( "SMESH_MESH" ), aMainGrp );
181 QHBoxLayout* aMeshGrpLayout = new QHBoxLayout( aMeshGrp );
182 aMeshGrpLayout->setMargin( MARGIN );
183 aMeshGrpLayout->setSpacing( SPACING );
185 QLabel* aMeshLab = new QLabel( tr( "SMESH_MESH" ), aMeshGrp );
186 mySelBtn[ Mesh ] = new QPushButton( aMeshGrp );
187 mySelBtn[ Mesh ]->setIcon( iconSlct );
188 mySelEdit[ Mesh ] = new QLineEdit( aMeshGrp );
189 mySelEdit[ Mesh ]->setReadOnly( true );
191 // ... layout widgets
193 aMeshGrpLayout->addWidget( aMeshLab );
194 aMeshGrpLayout->addWidget( mySelBtn[ Mesh ] );
195 aMeshGrpLayout->addWidget( mySelEdit[ Mesh ] );
199 QGroupBox* aPatGrp = new QGroupBox( tr( "PATTERN" ), aMainGrp );
200 QGridLayout* aPatGrpLayout = new QGridLayout( aPatGrp );
201 aPatGrpLayout->setMargin( MARGIN );
202 aPatGrpLayout->setSpacing( SPACING );
206 QLabel* aNameLab = new QLabel( tr( "PATTERN" ), aPatGrp );
207 myName = new QLineEdit( aPatGrp );
208 myName->setReadOnly( true );
209 myOpenBtn = new QPushButton( aPatGrp );
210 myOpenBtn->setIcon( iconOpen );
211 myNewBtn = new QPushButton( tr( "NEW" ), aPatGrp );
213 // ... Mode selection check box
214 myRefine = new QCheckBox( tr( "REFINE" ), aPatGrp );
216 // ... selection widgets for Apply to geom mode
217 myGeomGrp = new QFrame( aPatGrp );
218 myGeomGrp->setFrameStyle( QFrame::NoFrame );
219 QGridLayout* myGeomGrpLayout = new QGridLayout( myGeomGrp );
220 myGeomGrpLayout->setMargin( 0 );
221 myGeomGrpLayout->setSpacing( SPACING );
223 for ( int i = Object; i <= Vertex2; i++ ) {
224 mySelLbl[ i ] = new QLabel( myGeomGrp );
225 mySelBtn[ i ] = new QPushButton( myGeomGrp );
226 mySelBtn[ i ]->setIcon( iconSlct );
227 mySelEdit[ i ] = new QLineEdit( myGeomGrp );
228 mySelEdit[ i ]->setReadOnly( true );
229 myGeomGrpLayout->addWidget( mySelLbl[ i ], i - Object, 0 );
230 myGeomGrpLayout->addWidget( mySelBtn[ i ], i - Object, 1 );
231 myGeomGrpLayout->addWidget( mySelEdit[ i ], i - Object, 2 );
234 // ... Widgets for refinement of existing mesh elements
236 myRefineGrp = new QFrame( aPatGrp );
237 myRefineGrp->setFrameStyle( QFrame::NoFrame );
239 QGridLayout* myRefineGrpLayout = new QGridLayout( myRefineGrp );
240 myRefineGrpLayout->setMargin( 0 );
241 myRefineGrpLayout->setSpacing( SPACING );
243 mySelLbl[ Ids ] = new QLabel( myRefineGrp );
244 mySelBtn[ Ids ] = new QPushButton( myRefineGrp );
245 mySelBtn[ Ids ]->setIcon( iconSlct );
246 mySelEdit[ Ids ] = new QLineEdit( myRefineGrp );
248 QLabel* aNodeLbl = new QLabel( tr( "NODE_1" ), myRefineGrp );
249 myNode1 = new QSpinBox( myRefineGrp );
250 myNode2Lbl = new QLabel( tr( "NODE_2" ), myRefineGrp );
251 myNode2 = new QSpinBox( myRefineGrp );
253 myRefineGrpLayout->addWidget( mySelLbl[ Ids ], 0, 0 );
254 myRefineGrpLayout->addWidget( mySelBtn[ Ids ], 0, 1 );
255 myRefineGrpLayout->addWidget( mySelEdit[ Ids ], 0, 2 );
256 myRefineGrpLayout->addWidget( aNodeLbl, 1, 0 );
257 myRefineGrpLayout->addWidget( myNode1, 1, 1, 1, 2 );
258 myRefineGrpLayout->addWidget( myNode2Lbl, 2, 0 );
259 myRefineGrpLayout->addWidget( myNode2, 2, 1, 1, 2 );
261 // ... reverse check box
262 myReverseChk = new QCheckBox( tr( "REVERSE" ), aPatGrp );
264 // ... CreatePoly check box
265 myCreatePolygonsChk = new QCheckBox( tr( "CREATE_POLYGONS_NEAR_BOUNDARY" ), aPatGrp );
266 myCreatePolyedrsChk = new QCheckBox( tr( "CREATE_POLYEDRS_NEAR_BOUNDARY" ), aPatGrp );
268 // ... Pictures 2d and 3d
270 myPicture2d = new SMESHGUI_PatternWidget( aPatGrp );
271 myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
273 myPicture3d = new QLabel( aPatGrp );
274 myPicture3d->setPixmap( iconSample3d );
275 myPicture3d->setScaledContents( false );
276 myPicture3d->setAlignment( Qt::AlignCenter );
277 myPicture3d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
279 // ... preview check box
281 myPreviewChk = new QCheckBox( tr( "PREVIEW" ), aPatGrp );
283 // ... layout widgets
285 aPatGrpLayout->addWidget( aNameLab, 0, 0 );
286 aPatGrpLayout->addWidget( myName, 0, 1 );
287 aPatGrpLayout->addWidget( myOpenBtn, 0, 2 );
288 aPatGrpLayout->addWidget( myNewBtn, 0, 3 );
289 aPatGrpLayout->addWidget( myRefine, 1, 0, 1, 4 );
290 aPatGrpLayout->addWidget( myRefine, 1, 0, 1, 4 );
291 aPatGrpLayout->addWidget( myGeomGrp, 2, 0, 1, 4 );
292 aPatGrpLayout->addWidget( myRefineGrp, 3, 0, 1, 4 );
293 aPatGrpLayout->addWidget( myReverseChk, 4, 0, 1, 4 );
294 aPatGrpLayout->addWidget( myCreatePolygonsChk, 5, 0, 1, 4 );
295 aPatGrpLayout->addWidget( myCreatePolyedrsChk, 6, 0, 1, 4 );
296 aPatGrpLayout->addWidget( myPicture2d, 7, 0, 1, 4 );
297 aPatGrpLayout->addWidget( myPicture3d, 8, 0, 1, 4 );
298 aPatGrpLayout->addWidget( myPreviewChk, 9, 0, 1, 4 );
302 aMainGrpLayout->addWidget( aTypeGrp );
303 aMainGrpLayout->addWidget( aMeshGrp );
304 aMainGrpLayout->addWidget( aPatGrp );
306 // Connect signals and slots
308 connect(myTypeGrp, SIGNAL(buttonClicked(int)), SLOT(onTypeChanged(int)));
309 connect(myOpenBtn, SIGNAL(clicked()), SLOT(onOpen()));
310 connect(myNewBtn, SIGNAL(clicked()), SLOT(onNew()));
312 connect(myReverseChk, SIGNAL(toggled(bool)), SLOT(onReverse(bool)));
313 connect(myPreviewChk, SIGNAL(toggled(bool)), SLOT(onPreview(bool)));
314 connect(myRefine, SIGNAL(toggled(bool)), SLOT(onModeToggled(bool)));
316 connect(myNode1, SIGNAL(valueChanged(int)), SLOT(onNodeChanged(int)));
317 connect(myNode2, SIGNAL(valueChanged(int)), SLOT(onNodeChanged(int)));
319 connect(mySelEdit[Ids], SIGNAL(textChanged(const QString&)), SLOT(onTextChanged(const QString&)));
321 QMap< int, QPushButton* >::iterator anIter;
322 for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter)
323 connect(*anIter, SIGNAL(clicked()), SLOT(onSelInputChanged()));
328 //=======================================================================
329 // name : SMESHGUI_MeshPatternDlg::createButtonFrame
330 // Purpose : Create frame containing buttons
331 //=======================================================================
332 QWidget* SMESHGUI_MeshPatternDlg::createButtonFrame (QWidget* theParent)
334 QFrame* aFrame = new QFrame(theParent);
335 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
337 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame);
338 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
339 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
340 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
342 QHBoxLayout* aLay = new QHBoxLayout( aFrame );
343 aLay->setMargin( MARGIN );
344 aLay->setSpacing( SPACING );
346 aLay->addWidget(myOkBtn);
347 aLay->addWidget(myApplyBtn);
348 aLay->addSpacing( 10 );
350 aLay->addWidget(myCloseBtn);
351 aLay->addWidget(myHelpBtn);
353 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
354 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
355 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
356 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
361 //=======================================================================
362 // name : SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg
363 // Purpose : Destructor
364 //=======================================================================
365 SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg()
369 //=======================================================================
370 // name : SMESHGUI_MeshPatternDlg::Init
371 // Purpose : Init dialog fields, connect signals and slots, show dialog
372 //=======================================================================
373 void SMESHGUI_MeshPatternDlg::Init()
375 myPattern = SMESH::GetPattern();
377 myIsCreateDlgOpen = false;
381 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
382 myMesh = SMESH::SMESH_Mesh::_nil();
384 myMeshShape = GEOM::GEOM_Object::_nil();
385 myGeomObj[ Object ] = GEOM::GEOM_Object::_nil();
386 myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();
387 myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();
389 // selection and SMESHGUI
390 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
391 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
392 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
394 myTypeGrp->button(Type_2d)->setChecked(true);
395 onTypeChanged(Type_2d);
396 onModeToggled(isRefine());
400 resize(minimumSize());
408 //=======================================================================
409 // name : SMESHGUI_MeshPatternDlg::isValid
410 // Purpose : Verify validity of entry data
411 //=======================================================================
412 bool SMESHGUI_MeshPatternDlg::isValid (const bool theMess)
416 (myMesh->_is_nil() || !getIds(ids) || getNode(false) < 0 ||
417 myType == Type_3d && (getNode(true) < 0 || getNode(false) == getNode(true))))
420 (myMesh->_is_nil() || myMeshShape->_is_nil() || myGeomObj[ Object ]->_is_nil() ||
421 myGeomObj[ Vertex1 ]->_is_nil() || myType == Type_3d && myGeomObj[ Vertex2 ]->_is_nil())))
424 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
425 tr("SMESHGUI_INVALID_PARAMETERS"));
429 if ( myName->text().isEmpty() ) {
431 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
432 tr("SMESHGUI_INVALID_PARAMETERS"));
439 //=======================================================================
440 // name : SMESHGUI_MeshPatternDlg::onApply
441 // Purpose : SLOT called when "Apply" button pressed.
442 //=======================================================================
443 bool SMESHGUI_MeshPatternDlg::onApply()
451 if (isRefine()) { // Refining existing mesh elements
454 SMESH::long_array_var varIds = new SMESH::long_array();
455 varIds->length(ids.count());
457 for (QList<int>::iterator it = ids.begin(); it != ids.end(); ++it)
460 ? myPattern->ApplyToMeshFaces (myMesh, varIds, getNode(false), myReverseChk->isChecked())
461 : myPattern->ApplyToHexahedrons(myMesh, varIds, getNode(false), getNode(true));
463 } else { // Applying a pattern to geometrical object
464 if (myType == Type_2d)
465 myPattern->ApplyToFace(myGeomObj[Object], myGeomObj[Vertex1], myReverseChk->isChecked());
467 myPattern->ApplyTo3DBlock(myGeomObj[Object], myGeomObj[Vertex1], myGeomObj[Vertex2]);
470 bool toCreatePolygons = myCreatePolygonsChk->isChecked();
471 bool toCreatePolyedrs = myCreatePolyedrsChk->isChecked();
472 if ( myPattern->MakeMesh( myMesh, toCreatePolygons, toCreatePolyedrs ) ) {
473 //mySelectionMgr->clearSelected();
474 bool autoUpdate = SMESHGUI::automaticUpdate();
475 if (!isRefine() && autoUpdate) {
476 _PTR(SObject) aSO = SMESH::FindSObject(myMesh.in());
477 SMESH_Actor* anActor = SMESH::FindActorByEntry(aSO->GetID().c_str());
479 anActor = SMESH::CreateActor(aSO->GetStudy(), aSO->GetID().c_str());
481 SMESH::DisplayActor(SMESH::GetActiveWindow(), anActor);
486 mySelectionMgr->clearSelected();
489 mySMESHGUI->updateObjBrowser(true);
491 mySelEdit[ Ids ]->setText("");
495 SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
496 tr("SMESH_OPERATION_FAILED"));
499 } catch (const SALOME::SALOME_Exception& S_ex) {
500 SalomeApp_Tools::QtCatchCorbaException(S_ex);
507 //=======================================================================
508 // name : SMESHGUI_MeshPatternDlg::onOk
509 // Purpose : SLOT called when "Ok" button pressed.
510 //=======================================================================
511 void SMESHGUI_MeshPatternDlg::onOk()
517 //=======================================================================
518 // name : SMESHGUI_MeshPatternDlg::onClose
519 // Purpose : SLOT called when "Close" button pressed. Close dialog
520 //=======================================================================
521 void SMESHGUI_MeshPatternDlg::onClose()
523 mySelectionMgr->clearFilters();
524 SMESH::SetPickable();
525 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
526 aViewWindow->SetSelectionMode(ActorSelection);
527 disconnect(mySelectionMgr, 0, this, 0);
528 disconnect(mySMESHGUI, 0, this, 0);
529 mySMESHGUI->ResetState();
534 //=================================================================================
535 // function : onHelp()
537 //=================================================================================
538 void SMESHGUI_MeshPatternDlg::onHelp()
540 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
542 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
546 platform = "winapplication";
548 platform = "application";
550 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
551 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
552 arg(app->resourceMgr()->stringValue("ExternalBrowser",
554 arg(myHelpFileName));
558 //=======================================================================
559 // name : SMESHGUI_MeshPatternDlg::onSelectionDone
560 // Purpose : SLOT called when selection changed
561 //=======================================================================
562 void SMESHGUI_MeshPatternDlg::onSelectionDone()
568 if (mySelInput == Mesh) {
570 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
571 if (aList.Extent() != 1)
574 // Retrieve mesh from selection
575 Handle(SALOME_InteractiveObject) anIO = aList.First();
576 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
577 if (aMesh->_is_nil())
580 // Get geom object corresponding to the mesh
581 _PTR(SObject) aSO = SMESH::FindSObject(aMesh.in());
582 myMeshShape = SMESH::GetGeom(aSO);
584 // Clear fields of geom objects if mesh was changed
585 if (myMesh != aMesh) {
586 for (int i = Object; i <= Ids; i++) {
587 myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
588 mySelEdit[ i ]->setText("");
594 // Set name of mesh in line edit
596 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
597 mySelEdit[ Mesh ]->setText(aName);
599 } else if (mySelInput == Ids) {
601 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
602 if (aList.Extent() != 1)
606 if (!SMESH::GetNameOfSelectedElements(mySelector, aList.First(), anIds))
610 mySelEdit[ Ids ]->setText(anIds);
615 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
616 if (aList.Extent() != 1)
619 // Get geom object from selection
620 Handle(SALOME_InteractiveObject) anIO = aList.First();
621 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
622 if (anObj->_is_nil())
625 // Clear fields of vertexes if face or 3d block was changed
626 if (anObj != myGeomObj[ mySelInput ] && mySelInput == Object) {
627 for (int i = Vertex1; i <= Vertex2; i++) {
628 myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
629 mySelEdit[ i ]->setText("");
633 myGeomObj[ mySelInput ] = anObj;
635 // Set name of geom object in line edit
637 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
638 mySelEdit[ mySelInput ]->setText(aName);
640 } catch (const SALOME::SALOME_Exception& S_ex) {
641 SalomeApp_Tools::QtCatchCorbaException(S_ex);
651 //=======================================================================
652 // name : SMESHGUI_MeshPatternDlg::resetSelInput
653 // Purpose : Reset fields corresponding to the current selection input
654 //=======================================================================
655 void SMESHGUI_MeshPatternDlg::resetSelInput()
657 if (mySelInput == Mesh)
659 myMesh = SMESH::SMESH_Mesh::_nil();
660 myMeshShape = GEOM::GEOM_Object::_nil();
664 myGeomObj[ mySelInput ] = GEOM::GEOM_Object::_nil();
666 mySelEdit[ mySelInput ]->setText("");
669 //=======================================================================
670 // name : SMESHGUI_MeshPatternDlg::onDeactivate
671 // Purpose : SLOT called when dialog must be deativated
672 //=======================================================================
673 void SMESHGUI_MeshPatternDlg::onDeactivate()
675 mySelectionMgr->clearFilters();
676 //if (myReverseChk->isChecked())
678 disconnect(mySelectionMgr, 0, this, 0);
682 //=======================================================================
683 // name : SMESHGUI_MeshPatternDlg::enterEvent
684 // Purpose : Event filter
685 //=======================================================================
686 void SMESHGUI_MeshPatternDlg::enterEvent (QEvent*)
688 if (myIsCreateDlgOpen)
691 if (myReverseChk->isChecked())
693 mySMESHGUI->EmitSignalDeactivateDialog();
696 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
697 onTextChanged(mySelEdit[Ids]->text());
700 //=======================================================================
701 // name : SMESHGUI_MeshPatternDlg::closeEvent
703 //=======================================================================
704 void SMESHGUI_MeshPatternDlg::closeEvent (QCloseEvent*)
709 //=======================================================================
710 // name : SMESHGUI_MeshPatternDlg::onSelInputChanged
711 // Purpose : SLOT. Called when -> button clicked.
712 // Change current selection input field
713 //=======================================================================
714 void SMESHGUI_MeshPatternDlg::onSelInputChanged()
716 const QObject* aSender = sender();
717 for (int i = Mesh; i <= Ids; i++)
718 if (aSender == mySelBtn[ i ])
725 //=======================================================================
726 // name : SMESHGUI_MeshPatternDlg::prepareFilters
727 // Purpose : Prepare filters for dialog
728 //=======================================================================
729 QStringList SMESHGUI_MeshPatternDlg::prepareFilters() const
731 static QStringList aList;
734 aList.append(tr("PATTERN_FILT"));
735 //aList.append(tr("ALL_FILES_FILTER"));
741 //=======================================================================
742 // name : SMESHGUI_MeshPatternDlg::autoExtension
743 // Purpose : Append extension to the file name
744 //=======================================================================
745 QString SMESHGUI_MeshPatternDlg::autoExtension (const QString& theFileName) const
747 QString anExt = theFileName.section('.', -1);
748 return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName;
751 //=======================================================================
752 // name : SMESHGUI_MeshPatternDlg::onOpen
753 // Purpose : SLOT. Called when "Open" button clicked.
754 // Displays file open dialog
755 //=======================================================================
756 void SMESHGUI_MeshPatternDlg::onOpen()
758 SUIT_FileDlg* aDlg = new SUIT_FileDlg (this, true);
759 aDlg->setWindowTitle(tr("LOAD_PATTERN"));
760 aDlg->setFileMode(QFileDialog::ExistingFile);
761 aDlg->setFilters(prepareFilters());
762 if (!myName->text().isEmpty())
763 aDlg->selectFile(myName->text() + ".smp");
764 QPushButton* anOkBtn = qFindChild<QPushButton*>( aDlg, "OK" );
766 anOkBtn->setText(tr("SMESH_BUT_OK"));
768 if (aDlg->exec() != Accepted)
771 QString fName = aDlg->selectedFile();
775 if (QFileInfo(fName).suffix().isEmpty())
776 fName = autoExtension(fName);
778 fName = QDir::convertSeparators(fName);
780 QString prev = QDir::convertSeparators(myName->text());
784 // Read string from file
786 if (!aFile.open(QIODevice::ReadOnly)) {
787 SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
788 tr("ERROR_OF_OPENING"));
792 QByteArray aDataArray = aFile.readAll();
793 if (aDataArray.size() > 0) {
794 SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
795 tr("ERROR_OF_READING"));
799 if (loadFromFile(aDataArray))
800 myName->setText(QFileInfo(fName).completeBaseName());
806 //=======================================================================
807 // name : SMESHGUI_MeshPatternDlg::onCloseCreationDlg
808 // Purpose : SLOT. Called when "Pattern creation" dialog closed with "Close"
809 //=======================================================================
810 void SMESHGUI_MeshPatternDlg::onCloseCreationDlg()
813 myIsCreateDlgOpen = false;
816 //=======================================================================
817 // name : SMESHGUI_MeshPatternDlg::onOkCreationDlg
818 // Purpose : SLOT. Called when "Pattern creation" dialog closed with OK
819 // or SAVE buttons. Initialize myPattern field. Redisplay preview
820 //=======================================================================
821 void SMESHGUI_MeshPatternDlg::onOkCreationDlg()
823 myPattern = SMESH::SMESH_Pattern::_duplicate(myCreationDlg->GetPattern());
824 myName->setText(myCreationDlg->GetPatternName());
830 myIsCreateDlgOpen = false;
833 //=======================================================================
834 // name : SMESHGUI_MeshPatternDlg::onNew
835 // Purpose : SLOT. Called when "New..." button clicked. Create new pattern
836 //=======================================================================
837 void SMESHGUI_MeshPatternDlg::onNew()
840 myIsCreateDlgOpen = true;
841 if (myCreationDlg == 0)
843 myCreationDlg = new SMESHGUI_CreatePatternDlg( mySMESHGUI, myType);
844 connect(myCreationDlg, SIGNAL(NewPattern()), SLOT(onOkCreationDlg()));
845 connect(myCreationDlg, SIGNAL(Close()), SLOT(onCloseCreationDlg()));
848 myCreationDlg->Init(myType);
850 myCreationDlg->SetMesh(myMesh);
851 myCreationDlg->show();
854 //=======================================================================
855 // name : SMESHGUI_MeshPatternDlg::onReverse
856 // Purpose : SLOT. Called when state of "Reverse order..." checkbox chaged
857 // Calculate new points of the mesh to be created. Redisplay preview
858 //=======================================================================
859 void SMESHGUI_MeshPatternDlg::onReverse (bool)
864 //=======================================================================
866 // name : SMESHGUI_MeshPatternDlg::onPreview
867 // Purpose : SLOT. Called when state of "Preview" checkbox changed
868 // Display/Erase preview
869 //=======================================================================
870 void SMESHGUI_MeshPatternDlg::onPreview (bool)
875 //=======================================================================
876 // name : SMESHGUI_MeshPatternDlg::displayPreview
877 // Purpose : Display preview
878 //=======================================================================
879 void SMESHGUI_MeshPatternDlg::displayPreview()
882 // Redisplay preview in dialog
883 SMESH::point_array_var pnts = myPattern->GetPoints();
884 SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
885 SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints(false);
887 if (pnts->length() == 0 ||
888 keyPoints->length() == 0 ||
889 elemPoints->length() == 0) {
893 PointVector aPoints(pnts->length());
894 QVector<int> aKeyPoints(keyPoints->length());
895 ConnectivityVector anElemPoints(elemPoints->length());
897 for (int i = 0, n = pnts->length(); i < n; i++)
898 aPoints[ i ] = pnts[ i ];
900 for (int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++)
901 aKeyPoints[ i2 ] = keyPoints[ i2 ];
903 for (int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++) {
904 QVector<int> aVec(elemPoints[ i3 ].length());
905 for (int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++)
906 aVec[ i4 ] = elemPoints[ i3 ][ i4 ];
908 anElemPoints[ i3 ] = aVec;
911 myPicture2d->SetPoints(aPoints, aKeyPoints, anElemPoints);
914 // Redisplay preview in 3D viewer
915 if (myPreviewActor != 0) {
916 if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView()) {
917 vf->RemoveActor(myPreviewActor);
920 myPreviewActor->Delete();
924 if (!myPreviewChk->isChecked() || !isValid(false))
927 vtkUnstructuredGrid* aGrid = getGrid();
931 // Create and display actor
932 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
933 aMapper->SetInput(aGrid);
935 myPreviewActor = SALOME_Actor::New();
936 myPreviewActor->PickableOff();
937 myPreviewActor->SetMapper(aMapper);
939 vtkProperty* aProp = vtkProperty::New();
940 aProp->SetRepresentationToWireframe();
941 aProp->SetColor(250, 0, 250);
942 if (SMESH::FindActorByObject(myMesh))
943 aProp->SetLineWidth( SMESH::GetFloat( "SMESH:element_width", 1 ) + 1 );
945 aProp->SetLineWidth(1);
946 myPreviewActor->SetProperty(aProp);
948 myPreviewActor->SetRepresentation(3);
950 SMESH::GetCurrentVtkView()->AddActor(myPreviewActor);
951 SMESH::GetCurrentVtkView()->Repaint();
955 } catch (const SALOME::SALOME_Exception& S_ex) {
956 SalomeApp_Tools::QtCatchCorbaException(S_ex);
963 //=======================================================================
964 // name : SMESHGUI_MeshPatternDlg::erasePreview
965 // Purpose : Erase preview
966 //=======================================================================
967 void SMESHGUI_MeshPatternDlg::erasePreview()
969 // Erase preview in 2D viewer
970 myPicture2d->SetPoints(PointVector(), QVector<int>(), ConnectivityVector());
972 // Erase preview in 3D viewer
973 if (myPreviewActor == 0)
977 if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView())
979 vf->RemoveActor(myPreviewActor);
982 myPreviewActor->Delete();
986 //=======================================================================
987 // name : SMESHGUI_MeshPatternDlg::updateWgState
988 // Purpose : Enable/disable selection widgets
989 //=======================================================================
990 void SMESHGUI_MeshPatternDlg::updateWgState()
992 if (myMesh->_is_nil()) {
993 for (int i = Object; i <= Ids; i++) {
994 mySelBtn [ i ]->setEnabled(false);
995 mySelEdit[ i ]->setEnabled(false);
996 mySelEdit[ i ]->setText("");
998 myNode1->setEnabled(false);
999 myNode2->setEnabled(false);
1000 myNode1->setRange(0, 0);
1001 myNode2->setRange(0, 0);
1003 mySelBtn [ Object ]->setEnabled(true);
1004 mySelEdit[ Object ]->setEnabled(true);
1005 mySelBtn [ Ids ] ->setEnabled(true);
1006 mySelEdit[ Ids ] ->setEnabled(true);
1008 if (myGeomObj[ Object ]->_is_nil()) {
1009 for (int i = Vertex1; i <= Vertex2; i++) {
1010 mySelBtn [ i ]->setEnabled(false);
1011 mySelEdit[ i ]->setEnabled(false);
1012 mySelEdit[ i ]->setText("");
1015 for (int i = Object; i <= Vertex2; i++) {
1016 mySelBtn [ i ]->setEnabled(true);
1017 mySelEdit[ i ]->setEnabled(true);
1022 if (!CORBA::is_nil(myPattern)/* && getIds(ids)*/) {
1023 SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
1024 if (keyPoints->length()) {
1025 myNode1->setEnabled(true);
1026 myNode2->setEnabled(true);
1027 myNode1->setRange(1, keyPoints->length());
1028 myNode2->setRange(1, keyPoints->length());
1033 myNode1->setEnabled(false);
1034 myNode2->setEnabled(false);
1035 myNode1->setRange(0, 0);
1036 myNode2->setRange(0, 0);
1040 //=======================================================================
1041 // name : SMESHGUI_MeshPatternDlg::activateSelection
1042 // Purpose : Activate selection in accordance with current selection input
1043 //=======================================================================
1044 void SMESHGUI_MeshPatternDlg::activateSelection()
1046 mySelectionMgr->clearFilters();
1047 if (mySelInput == Ids) {
1048 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
1050 SMESH::SetPickable(anActor);
1052 if (myType == Type_2d)
1054 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1055 aViewWindow->SetSelectionMode(FaceSelection);
1059 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1060 aViewWindow->SetSelectionMode(CellSelection);
1064 SMESH::SetPickable();
1065 //mySelectionMgr->setSelectionModes(ActorSelection);
1066 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1067 aViewWindow->SetSelectionMode(ActorSelection);
1070 if (mySelInput == Object && !myMeshShape->_is_nil()) {
1071 if (myType == Type_2d) {
1073 mySelectionMgr->installFilter
1074 (new SMESH_NumberFilter ("GEOM", TopAbs_VERTEX, myNbPoints, TopAbs_FACE, myMeshShape));
1076 mySelectionMgr->installFilter
1077 (new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, myNbPoints, TopAbs_FACE, myMeshShape));
1079 TColStd_MapOfInteger aTypes;
1080 aTypes.Add(TopAbs_SHELL);
1081 aTypes.Add(TopAbs_SOLID);
1082 mySelectionMgr->installFilter
1083 (new SMESH_NumberFilter ("GEOM", TopAbs_FACE, 6, aTypes, myMeshShape, true));
1085 } else if ((mySelInput == Vertex1 || mySelInput == Vertex2) && !myGeomObj[ Object ]->_is_nil()) {
1086 mySelectionMgr->installFilter
1087 (new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX, myGeomObj[ Object ]));
1092 //=======================================================================
1093 // name : SMESHGUI_MeshPatternDlg::loadFromFile
1094 // Purpose : Load pattern from file
1095 //=======================================================================
1096 bool SMESHGUI_MeshPatternDlg::loadFromFile (const QString& theName)
1099 SMESH::SMESH_Pattern_var aPattern = SMESH::GetPattern();
1101 if (!aPattern->LoadFromFile(theName.toLatin1().data()) ||
1102 myType == Type_2d && !aPattern->Is2D()) {
1103 SMESH::SMESH_Pattern::ErrorCode aCode = aPattern->GetErrorCode();
1105 if (aCode == SMESH::SMESH_Pattern::ERR_READ_NB_POINTS ) aMess = tr("ERR_READ_NB_POINTS");
1106 else if (aCode == SMESH::SMESH_Pattern::ERR_READ_POINT_COORDS ) aMess = tr("ERR_READ_POINT_COORDS");
1107 else if (aCode == SMESH::SMESH_Pattern::ERR_READ_TOO_FEW_POINTS) aMess = tr("ERR_READ_TOO_FEW_POINTS");
1108 else if (aCode == SMESH::SMESH_Pattern::ERR_READ_3D_COORD ) aMess = tr("ERR_READ_3D_COORD");
1109 else if (aCode == SMESH::SMESH_Pattern::ERR_READ_NO_KEYPOINT ) aMess = tr("ERR_READ_NO_KEYPOINT");
1110 else if (aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_INDEX ) aMess = tr("ERR_READ_BAD_INDEX");
1111 else if (aCode == SMESH::SMESH_Pattern::ERR_READ_ELEM_POINTS ) aMess = tr("ERR_READ_ELEM_POINTS");
1112 else if (aCode == SMESH::SMESH_Pattern::ERR_READ_NO_ELEMS ) aMess = tr("ERR_READ_NO_ELEMS");
1113 else if (aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_KEY_POINT ) aMess = tr("ERR_READ_BAD_KEY_POINT");
1114 else aMess = tr("ERROR_OF_LOADING");
1116 SUIT_MessageBox::information(this, tr("SMESH_ERROR"), aMess);
1119 myPattern = aPattern;
1122 } catch (const SALOME::SALOME_Exception& S_ex) {
1123 SalomeApp_Tools::QtCatchCorbaException(S_ex);
1124 SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
1125 tr("ERROR_OF_LOADING") );
1130 //=======================================================================
1131 // name : SMESHGUI_MeshPatternDlg::onTypeChanged
1132 // Purpose : SLOT. Called when pattern type changed.
1133 // Change dialog's look and feel
1134 //=======================================================================
1135 void SMESHGUI_MeshPatternDlg::onTypeChanged (int theType)
1137 if (myType == theType)
1143 myGeomObj[ Object ] = GEOM::GEOM_Object::_nil();
1144 myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();
1145 myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();
1146 myPattern = SMESH::GetPattern();
1148 myName->setText("");
1149 mySelEdit[ Object ]->setText("");
1150 mySelEdit[ Vertex1 ]->setText("");
1151 mySelEdit[ Vertex2 ]->setText("");
1152 mySelEdit[ Ids ] ->setText("");
1153 myCreatePolygonsChk->show();
1154 myCreatePolyedrsChk->show();
1156 if (theType == Type_2d) {
1158 mySelLbl [ Vertex2 ]->hide();
1159 mySelBtn [ Vertex2 ]->hide();
1160 mySelEdit[ Vertex2 ]->hide();
1161 myReverseChk->show();
1162 myPicture2d->show();
1163 myPicture3d->hide();
1164 mySelLbl[ Object ]->setText(tr("FACE"));
1165 mySelLbl[ Vertex1 ]->setText(tr("VERTEX"));
1167 mySelLbl[ Ids ]->setText(tr("MESH_FACES"));
1172 mySelLbl [ Vertex2 ]->show();
1173 mySelBtn [ Vertex2 ]->show();
1174 mySelEdit[ Vertex2 ]->show();
1175 myReverseChk->hide();
1176 myPicture2d->hide();
1177 myPicture3d->show();
1178 mySelLbl[ Object ]->setText(tr("3D_BLOCK"));
1179 mySelLbl[ Vertex1 ]->setText(tr("VERTEX1"));
1180 mySelLbl[ Vertex2 ]->setText(tr("VERTEX2"));
1182 mySelLbl[ Ids ]->setText(tr("MESH_VOLUMES"));
1188 activateSelection();
1193 //=======================================================================
1194 // name : SMESHGUI_MeshPatternDlg::getGrid
1195 // Purpose : Get unstructured grid for pattern
1196 //=======================================================================
1197 vtkUnstructuredGrid* SMESHGUI_MeshPatternDlg::getGrid()
1200 // Get points from pattern
1201 SMESH::point_array_var pnts;
1203 if (isRefine() && getIds(ids)) {
1204 SMESH::long_array_var varIds = new SMESH::long_array();
1205 varIds->length(ids.count());
1207 for (QList<int>::iterator it = ids.begin(); it != ids.end(); ++it)
1209 pnts = myType == Type_2d
1210 ? myPattern->ApplyToMeshFaces (myMesh, varIds, getNode(false), myReverseChk->isChecked())
1211 : myPattern->ApplyToHexahedrons(myMesh, varIds, getNode(false), getNode(true));
1213 pnts = myType == Type_2d
1214 ? myPattern->ApplyToFace (myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked())
1215 : myPattern->ApplyTo3DBlock(myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ]);
1218 SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints(true);
1220 if (pnts->length() == 0 || elemPoints->length() == 0)
1223 // to do : to be removed /////////////////////////////////////////////
1226 for (int i1 = 0, n1 = pnts->length(); i1 < n1; i1++)
1227 printf("%d: %g %g %g\n", i1, pnts[ i1 ].x, pnts[ i1 ].y, pnts[ i1 ].z);
1229 printf("\nELEMENTS : \n");
1230 for (int i2 = 0, n2 = elemPoints->length(); i2 < n2; i2++)
1234 for (int i3 = 0, n3 = elemPoints[ i2 ].length(); i3 < n3; i3++)
1235 printf("%d ", elemPoints[ i2 ][ i3 ]);
1241 //////////////////////////////////////////////////////////////////////
1243 // Calculate number of points used for cell
1244 vtkIdType aNbCells = elemPoints->length();
1245 vtkIdType aCellsSize = 0;
1246 for (int i = 0, n = elemPoints->length(); i < n; i++)
1247 aCellsSize += elemPoints[ i ].length();
1249 // Create unstructured grid and other usefull arrays
1250 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
1252 vtkCellArray* aConnectivity = vtkCellArray::New();
1253 aConnectivity->Allocate(aCellsSize, 0);
1255 vtkPoints* aPoints = vtkPoints::New();
1256 aPoints->SetNumberOfPoints(pnts->length());
1258 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
1259 aCellTypesArray->SetNumberOfComponents(1);
1260 aCellTypesArray->Allocate(aNbCells * aCellTypesArray->GetNumberOfComponents());
1262 vtkIdList *anIdList = vtkIdList::New();
1264 // Fill array of points
1265 for (int p = 0, nbPnt = pnts->length(); p < nbPnt; p++)
1266 aPoints->SetPoint(p, pnts[ p ].x, pnts[ p ].y, pnts[ p ].z);
1268 for (int e = 0, nbElem = elemPoints->length(); e < nbElem; e++) {
1269 int nbPoints = elemPoints[ e ].length();
1270 anIdList->SetNumberOfIds(nbPoints);
1271 for (int i = 0; i < nbPoints; i++)
1272 anIdList->SetId(i, elemPoints[ e ][ i ]);
1274 aConnectivity->InsertNextCell(anIdList);
1276 if (nbPoints == 3) aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
1277 else if (nbPoints == 5) aCellTypesArray->InsertNextValue(VTK_PYRAMID);
1278 else if (nbPoints == 6) aCellTypesArray->InsertNextValue(VTK_WEDGE);
1279 else if (nbPoints == 8) aCellTypesArray->InsertNextValue(VTK_HEXAHEDRON);
1280 else if (nbPoints == 4 && myType == Type_2d) aCellTypesArray->InsertNextValue(VTK_QUAD);
1281 else if (nbPoints == 4 && myType == Type_3d) aCellTypesArray->InsertNextValue(VTK_TETRA);
1282 else aCellTypesArray->InsertNextValue(VTK_EMPTY_CELL);
1285 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
1286 aCellLocationsArray->SetNumberOfComponents(1);
1287 aCellLocationsArray->SetNumberOfTuples(aNbCells);
1289 aConnectivity->InitTraversal();
1290 for (vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell(npts, pts); idType++)
1291 aCellLocationsArray->SetValue(idType, aConnectivity->GetTraversalLocation(npts));
1293 aGrid->SetPoints(aPoints);
1294 aGrid->SetCells(aCellTypesArray, aCellLocationsArray,aConnectivity);
1296 aConnectivity->Delete();
1298 aCellTypesArray->Delete();
1300 aCellLocationsArray->Delete();
1308 //=======================================================================
1309 // name : onModeToggled
1311 //=======================================================================
1312 void SMESHGUI_MeshPatternDlg::onModeToggled (bool on)
1314 on ? myRefineGrp->show() : myRefineGrp->hide();
1315 on ? myGeomGrp->hide() : myGeomGrp->show();
1320 //=======================================================================
1323 //=======================================================================
1324 bool SMESHGUI_MeshPatternDlg::isRefine() const
1326 return myRefine->isChecked();
1329 //=======================================================================
1330 // name : onTextChanged
1332 //=======================================================================
1333 void SMESHGUI_MeshPatternDlg::onTextChanged (const QString& theNewText)
1335 if (myBusy || !isRefine())
1340 if (mySelInput != Ids) {
1342 activateSelection();
1345 // hilight entered elements/nodes
1346 SMDS_Mesh* aMesh = 0;
1347 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
1349 aMesh = anActor->GetObject()->GetMesh();
1352 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
1354 TColStd_MapOfInteger newIndices;
1356 for (int i = 0; i < aListId.count(); i++) {
1357 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
1358 if (e && e->GetType() == (myType == Type_2d ? SMDSAbs_Face : SMDSAbs_Volume))
1359 newIndices.Add(e->GetID());
1361 mySelector->AddOrRemoveIndex( anActor->getIO(), newIndices, false);
1362 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1363 aViewWindow->highlight( anActor->getIO(), true, true );
1371 //=======================================================================
1372 // name : onNodeChanged
1374 //=======================================================================
1375 void SMESHGUI_MeshPatternDlg::onNodeChanged (int value)
1377 if (myType == Type_3d) {
1378 QSpinBox* first = (QSpinBox*)sender();
1379 QSpinBox* second = first == myNode1 ? myNode2 : myNode1;
1380 int secondVal = second->value();
1381 if (secondVal == value) {
1382 secondVal = value == second->maximum() ? second->minimum() : value + 1;
1383 bool blocked = second->signalsBlocked();
1384 second->blockSignals(true);
1385 second->setValue(secondVal);
1386 second->blockSignals(blocked);
1393 //=======================================================================
1396 //=======================================================================
1397 bool SMESHGUI_MeshPatternDlg::getIds (QList<int>& ids) const
1400 QStringList strIds = mySelEdit[Ids]->text().split(" ", QString::SkipEmptyParts );
1403 for (QStringList::iterator it = strIds.begin(); it != strIds.end(); ++it) {
1404 val = (*it).toInt(&isOk);
1412 //=======================================================================
1415 //=======================================================================
1416 int SMESHGUI_MeshPatternDlg::getNode (bool second) const
1418 return second ? myNode2->value() - 1 : myNode1->value() - 1;
1421 //=================================================================================
1422 // function : keyPressEvent()
1424 //=================================================================================
1425 void SMESHGUI_MeshPatternDlg::keyPressEvent( QKeyEvent* e )
1427 QDialog::keyPressEvent( e );
1428 if ( e->isAccepted() )
1431 if ( e->key() == Qt::Key_F1 )