1 // SMESH SMESHGUI : GUI for SMESH component
\r
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
\r
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
\r
6 // This library is free software; you can redistribute it and/or
\r
7 // modify it under the terms of the GNU Lesser General Public
\r
8 // License as published by the Free Software Foundation; either
\r
9 // version 2.1 of the License.
\r
11 // This library is distributed in the hope that it will be useful,
\r
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
14 // Lesser General Public License for more details.
\r
16 // You should have received a copy of the GNU Lesser General Public
\r
17 // License along with this library; if not, write to the Free Software
\r
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
\r
24 // File : SMESHGUI_MeshPatternDlg.cxx
\r
25 // Author : Sergey LITONIN
\r
28 #include "SMESHGUI_MeshPatternDlg.h"
\r
30 #include "QAD_Desktop.h"
\r
31 #include "QAD_FileDlg.h"
\r
33 #include "SMESHGUI_SpinBox.h"
\r
34 #include "SMESHGUI.h"
\r
35 #include "SALOME_Selection.h"
\r
36 #include "SMESH_NumberFilter.hxx"
\r
37 #include "SMESHGUI_Utils.h"
\r
38 #include "SMESHGUI_VTKUtils.h"
\r
39 #include "SMESHGUI_CreatePatternDlg.h"
\r
40 #include "SMESHGUI_PatternWidget.h"
\r
41 #include "SMESH_Actor.h"
\r
42 #include "SALOMEGUI_QtCatchCorbaException.hxx"
\r
43 #include "VTKViewer_ViewFrame.h"
\r
44 #include "SMESHGUI_PatternUtils.h"
\r
45 #include "SMESH_ActorUtils.h"
\r
47 #include <TColStd_MapOfInteger.hxx>
\r
50 #include <qlayout.h>
\r
51 #include <qlineedit.h>
\r
52 #include <qpushbutton.h>
\r
53 #include <qgroupbox.h>
\r
55 #include <qradiobutton.h>
\r
56 #include <qcheckbox.h>
\r
57 #include <qbuttongroup.h>
\r
58 #include <qmessagebox.h>
\r
59 #include <qcstring.h>
\r
61 #include <vtkCell.h>
\r
62 #include <vtkIdList.h>
\r
63 #include <vtkIntArray.h>
\r
64 #include <vtkCellArray.h>
\r
65 #include <vtkUnsignedCharArray.h>
\r
66 #include <vtkUnstructuredGrid.h>
\r
67 #include <vtkDataSetMapper.h>
\r
73 Class : SMESHGUI_MeshPatternDlg
\r
74 Description : Dialog to specify filters for VTK viewer
\r
77 //=======================================================================
\r
78 // name : SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg
\r
79 // Purpose : Constructor
\r
80 //=======================================================================
\r
81 SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg( QWidget* theParent,
\r
82 SALOME_Selection* theSelection,
\r
83 const char* theName )
\r
84 : QDialog( theParent, theName, false,
\r
85 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
\r
87 setCaption( tr( "CAPTION" ) );
\r
89 QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING );
\r
91 QFrame* aMainFrame = createMainFrame ( this );
\r
92 QFrame* aBtnFrame = createButtonFrame( this );
\r
97 aDlgLay->addWidget( aMainFrame );
\r
98 aDlgLay->addWidget( aBtnFrame );
\r
100 aDlgLay->setStretchFactor( aMainFrame, 1 );
\r
103 Init( theSelection );
\r
106 //=======================================================================
\r
107 // name : SMESHGUI_MeshPatternDlg::createMainFrame
\r
108 // Purpose : Create frame containing dialog's input fields
\r
109 //=======================================================================
\r
110 QFrame* SMESHGUI_MeshPatternDlg::createMainFrame( QWidget* theParent )
\r
112 QPixmap iconSlct( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
\r
113 QPixmap icon2d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) );
\r
114 QPixmap icon3d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) );
\r
115 QPixmap iconOpen( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_FILE_OPEN" ) ) );
\r
117 QPixmap iconSample2d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) );
\r
118 QPixmap iconSample3d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_3D" ) ) );
\r
120 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, theParent );
\r
121 aMainGrp->setFrameStyle( QFrame::NoFrame );
\r
122 aMainGrp->setInsideMargin( 0 );
\r
124 // Pattern type group
\r
126 myTypeGrp = new QButtonGroup( 1, Qt::Vertical, tr( "PATTERN_TYPE" ), aMainGrp );
\r
127 mySwitch2d = new QRadioButton( myTypeGrp );
\r
128 mySwitch3d = new QRadioButton( myTypeGrp );
\r
129 mySwitch2d->setPixmap( icon2d );
\r
130 mySwitch3d->setPixmap( icon3d );
\r
131 myTypeGrp->insert( mySwitch2d, Type_2d );
\r
132 myTypeGrp->insert( mySwitch3d, Type_3d );
\r
137 QGroupBox* aMeshGrp = new QGroupBox( 1, Qt::Vertical, tr( "SMESH_MESH" ), aMainGrp );
\r
138 new QLabel( tr( "SMESH_MESH" ), aMeshGrp );
\r
139 mySelBtn[ Mesh ] = new QPushButton( aMeshGrp );
\r
140 mySelBtn[ Mesh ]->setPixmap( iconSlct );
\r
141 mySelEdit[ Mesh ] = new QLineEdit( aMeshGrp );
\r
142 mySelEdit[ Mesh ]->setReadOnly( true );
\r
146 QGroupBox* aPatGrp = new QGroupBox( 1, Qt::Horizontal, tr( "PATTERN" ), aMainGrp );
\r
149 QGroupBox* aNameGrp = new QGroupBox( 1, Qt::Vertical, aPatGrp );
\r
150 aNameGrp->setFrameStyle( QFrame::NoFrame );
\r
151 aNameGrp->setInsideMargin( 0 );
\r
152 new QLabel( tr( "PATTERN" ), aNameGrp );
\r
153 myName = new QLineEdit( aNameGrp );
\r
154 myName->setReadOnly( true );
\r
155 myOpenBtn = new QPushButton( aNameGrp );
\r
156 myOpenBtn->setPixmap( iconOpen );
\r
157 myNewBtn = new QPushButton( tr( "NEW" ), aNameGrp );
\r
159 // selection widgets
\r
160 QGroupBox* aGrp = new QGroupBox( 3, Qt::Horizontal, aPatGrp );
\r
161 aGrp->setFrameStyle( QFrame::NoFrame );
\r
162 aGrp->setInsideMargin( 0 );
\r
164 for ( int i = Object; i <= Vertex2; i++ )
\r
166 mySelLbl[ i ] = new QLabel( aGrp );
\r
167 mySelBtn[ i ] = new QPushButton( aGrp );
\r
168 mySelBtn[ i ]->setPixmap( iconSlct );
\r
169 mySelEdit[ i ] = new QLineEdit( aGrp );
\r
170 mySelEdit[ i ]->setReadOnly( true );
\r
173 // reverse check box
\r
174 myReverseChk = new QCheckBox( tr( "REVERSE" ), aPatGrp );
\r
176 // Pictures 2d and 3d
\r
177 for ( int i = 0; i < 2; i++ )
\r
179 QWidget* aPreview, *aPicture;
\r
182 myPicture2d = new SMESHGUI_PatternWidget( aPatGrp ),
\r
183 myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
\r
187 myPicture3d = new QFrame( aPatGrp ),
\r
188 myPreview3d = new QLabel( myPicture3d );
\r
189 myPreview3d->setPixmap( iconSample3d );
\r
190 QGridLayout* aLay = new QGridLayout( myPicture3d, 3, 3, 0, 0 );
\r
191 QSpacerItem* aSpacerH1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
\r
192 QSpacerItem* aSpacerH2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
\r
193 QSpacerItem* aSpacerV1 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
\r
194 QSpacerItem* aSpacerV2 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
\r
195 aLay->addItem( aSpacerH1, 1, 0 );
\r
196 aLay->addItem( aSpacerH2, 1, 2 );
\r
197 aLay->addItem( aSpacerV1, 0, 1 );
\r
198 aLay->addItem( aSpacerV2, 2, 1 );
\r
199 aLay->addWidget( myPreview3d, 1, 1 );
\r
203 myPreviewChk = new QCheckBox( tr( "PREVIEW" ), aPatGrp );
\r
205 // Connect signals and slots
\r
207 connect( myTypeGrp, SIGNAL( clicked( int ) ), SLOT( onTypeChanged( int ) ) );
\r
208 connect( myOpenBtn, SIGNAL( clicked() ), SLOT( onOpen() ) );
\r
209 connect( myNewBtn, SIGNAL( clicked() ), SLOT( onNew() ) );
\r
210 connect( myReverseChk, SIGNAL( toggled( bool ) ), SLOT( onReverse( bool ) ) );
\r
211 connect( myPreviewChk, SIGNAL( toggled( bool ) ), SLOT( onPreview( bool ) ) );
\r
213 QMap< int, QPushButton* >::iterator anIter;
\r
214 for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter )
\r
215 connect( *anIter, SIGNAL( clicked() ), SLOT( onSelInputChanged() ) );
\r
220 //=======================================================================
\r
222 // name : SMESHGUI_MeshPatternDlg::createButtonFrame
\r
223 // Purpose : Create frame containing buttons
\r
224 //=======================================================================
\r
225 QFrame* SMESHGUI_MeshPatternDlg::createButtonFrame( QWidget* theParent )
\r
227 QFrame* aFrame = new QFrame( theParent );
\r
228 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
\r
230 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), aFrame );
\r
231 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), aFrame );
\r
232 myCloseBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), aFrame );
\r
234 QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
\r
236 QHBoxLayout* aLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
\r
238 aLay->addWidget( myOkBtn );
\r
239 aLay->addWidget( myApplyBtn );
\r
240 aLay->addItem( aSpacer);
\r
241 aLay->addWidget( myCloseBtn );
\r
243 connect( myOkBtn, SIGNAL( clicked() ), SLOT( onOk() ) );
\r
244 connect( myCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) ) ;
\r
245 connect( myApplyBtn, SIGNAL( clicked() ), SLOT( onApply() ) );
\r
250 //=======================================================================
\r
251 // name : SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg
\r
252 // Purpose : Destructor
\r
253 //=======================================================================
\r
254 SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg()
\r
258 //=======================================================================
\r
259 // name : SMESHGUI_MeshPatternDlg::Init
\r
260 // Purpose : Init dialog fields, connect signals and slots, show dialog
\r
261 //=======================================================================
\r
262 void SMESHGUI_MeshPatternDlg::Init( SALOME_Selection* theSelection )
\r
264 myPattern = SMESH::GetPattern();
\r
265 myPreviewActor = 0;
\r
266 myIsCreateDlgOpen = false;
\r
270 mySelection = theSelection;
\r
271 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
\r
272 aSMESHGUI->SetActiveDialogBox( ( QDialog* )this );
\r
273 myMesh = SMESH::SMESH_Mesh::_nil();
\r
275 myMeshShape = GEOM::GEOM_Object::_nil();
\r
276 myGeomObj[ Object ] = GEOM::GEOM_Object::_nil();
\r
277 myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();
\r
278 myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();
\r
280 // selection and SMESHGUI
\r
281 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
\r
282 connect( aSMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) );
\r
283 connect( aSMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) );
\r
285 myTypeGrp->setButton( Type_2d );
\r
286 onTypeChanged( Type_2d );
\r
290 resize( minimumSize() );
\r
292 activateSelection();
\r
296 aSMESHGUI->DefineDlgPosition( this, x, y );
\r
297 this->move( x, y );
\r
301 //=======================================================================
\r
302 // name : SMESHGUI_MeshPatternDlg::isValid
\r
303 // Purpose : Verify validity of entry data
\r
304 //=======================================================================
\r
305 bool SMESHGUI_MeshPatternDlg::isValid( const bool theMess )
\r
307 if ( myMesh->_is_nil() || myMeshShape->_is_nil() || myGeomObj[ Object ]->_is_nil() ||
\r
308 myGeomObj[ Vertex1 ]->_is_nil() || myType == Type_3d && myGeomObj[ Vertex2 ]->_is_nil() )
\r
311 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
312 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SMESHGUI_INVALID_PARAMETERS" ), QMessageBox::Ok );
\r
319 //=======================================================================
\r
320 // name : SMESHGUI_MeshPatternDlg::onApply
\r
321 // Purpose : SLOT called when "Apply" button pressed.
\r
322 //=======================================================================
\r
323 bool SMESHGUI_MeshPatternDlg::onApply()
\r
330 if ( myType == Type_2d )
\r
331 myPattern->ApplyToFace(
\r
332 myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() );
\r
334 myPattern->ApplyTo3DBlock(
\r
335 myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] );
\r
337 if ( myPattern->MakeMesh( myMesh ) )
\r
339 mySelection->ClearIObjects();
\r
340 SMESH::UpdateView();
\r
341 SMESHGUI::GetSMESHGUI()->GetActiveStudy()->updateObjBrowser( true );
\r
346 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
347 tr( "SMESH_ERROR" ), tr( "SMESH_OPERATION_FAILED" ), QMessageBox::Ok );
\r
351 catch( const SALOME::SALOME_Exception& S_ex )
\r
353 QtCatchCorbaException( S_ex );
\r
362 //=======================================================================
\r
363 // name : SMESHGUI_MeshPatternDlg::onOk
\r
364 // Purpose : SLOT called when "Ok" button pressed.
\r
365 //=======================================================================
\r
366 void SMESHGUI_MeshPatternDlg::onOk()
\r
372 //=======================================================================
\r
373 // name : SMESHGUI_MeshPatternDlg::onClose
\r
374 // Purpose : SLOT called when "Close" button pressed. Close dialog
\r
375 //=======================================================================
\r
376 void SMESHGUI_MeshPatternDlg::onClose()
\r
378 mySelection->ClearFilters();
\r
379 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
380 disconnect( mySelection, 0, this, 0 );
\r
381 disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );
\r
382 SMESHGUI::GetSMESHGUI()->ResetState();
\r
389 //=======================================================================
\r
390 // name : SMESHGUI_MeshPatternDlg::onSelectionDone
\r
391 // Purpose : SLOT called when selection changed
\r
392 //=======================================================================
\r
393 void SMESHGUI_MeshPatternDlg::onSelectionDone()
\r
397 if ( mySelection->IObjectCount() != 1 )
\r
400 if ( mySelInput == Mesh )
\r
402 // Retrieve mesh from selection
\r
403 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
\r
404 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIO );
\r
405 if ( aMesh->_is_nil() )
\r
408 // Get geom object corresponding to the mesh
\r
409 SALOMEDS::Study_var aStudy =
\r
410 SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getStudyDocument();
\r
412 SALOMEDS::SObject_var aSO = SMESH::FindSObject( aMesh.in() );
\r
413 if ( aSO->_is_nil() )
\r
416 bool isFound = false;
\r
417 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( aSO );
\r
418 for( ; anIter->More(); anIter->Next() )
\r
420 SALOMEDS::SObject_var aSO = anIter->Value();
\r
421 SALOMEDS::SObject_var aRefSO;
\r
423 GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(
\r
424 aSO->ReferencedObject( aRefSO )? aRefSO->GetObject() : aSO->GetObject() );
\r
426 if ( !aMeshShape->_is_nil() )
\r
429 myMeshShape = aMeshShape;
\r
438 // Clear fields of geom objects if mesh was changed
\r
439 if ( myMesh != aMesh )
\r
441 for ( int i = Object; i <= Vertex2; i++ )
\r
443 myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
\r
444 mySelEdit[ i ]->setText( "" );
\r
450 // Set name of mesh in line edit
\r
452 SMESH::GetNameOfSelectedIObjects( mySelection, aName );
\r
453 mySelEdit[ Mesh ]->setText( aName );
\r
457 // Get geom object from selection
\r
458 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
\r
459 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>( anIO );
\r
460 if ( anObj->_is_nil() )
\r
463 // Clear fields of vertexes if face or 3d block was changed
\r
464 if ( anObj != myGeomObj[ mySelInput ] && mySelInput == Object )
\r
466 for ( int i = Vertex1; i <= Vertex2; i++ )
\r
468 myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
\r
469 mySelEdit[ i ]->setText( "" );
\r
473 myGeomObj[ mySelInput ] = anObj;
\r
475 // Set name of geom object in line edit
\r
477 SMESH::GetNameOfSelectedIObjects( mySelection, aName );
\r
478 mySelEdit[ mySelInput ]->setText( aName );
\r
481 catch( const SALOME::SALOME_Exception& S_ex )
\r
483 QtCatchCorbaException( S_ex );
\r
495 //=======================================================================
\r
496 // name : SMESHGUI_MeshPatternDlg::resetSelInput
\r
497 // Purpose : Reset fields corresponding to the current selection input
\r
498 //=======================================================================
\r
499 void SMESHGUI_MeshPatternDlg::resetSelInput()
\r
501 if ( mySelInput == Mesh )
\r
503 myMesh = SMESH::SMESH_Mesh::_nil();
\r
504 myMeshShape = GEOM::GEOM_Object::_nil();
\r
508 myGeomObj[ mySelInput ] = GEOM::GEOM_Object::_nil();
\r
510 mySelEdit[ mySelInput ]->setText( "" );
\r
513 //=======================================================================
\r
514 // name : SMESHGUI_MeshPatternDlg::onDeactivate
\r
515 // Purpose : SLOT called when dialog must be deativated
\r
516 //=======================================================================
\r
517 void SMESHGUI_MeshPatternDlg::onDeactivate()
\r
519 mySelection->ClearFilters();
\r
520 //if ( myReverseChk->isChecked() )
\r
522 disconnect( mySelection, 0, this, 0 );
\r
523 setEnabled( false );
\r
526 //=======================================================================
\r
527 // name : SMESHGUI_MeshPatternDlg::enterEvent
\r
528 // Purpose : Event filter
\r
529 //=======================================================================
\r
530 void SMESHGUI_MeshPatternDlg::enterEvent( QEvent* )
\r
532 if ( myIsCreateDlgOpen )
\r
535 if ( myReverseChk->isChecked() )
\r
537 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog() ;
\r
538 setEnabled( true );
\r
539 activateSelection();
\r
540 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
\r
544 //=================================================================================
\r
545 // function : closeEvent()
\r
547 //=================================================================================
\r
548 void SMESHGUI_MeshPatternDlg::closeEvent( QCloseEvent* e )
\r
553 //=======================================================================
\r
554 // name : SMESHGUI_MeshPatternDlg::onSelInputChanged
\r
555 // Purpose : SLOT. Called when -> button clicked.
\r
556 // Change current selection input field
\r
557 //=======================================================================
\r
558 void SMESHGUI_MeshPatternDlg::onSelInputChanged()
\r
560 const QObject* aSender = sender();
\r
561 for ( int i = Mesh; i <= Vertex2; i++ )
\r
562 if ( aSender == mySelBtn[ i ] )
\r
565 activateSelection();
\r
569 //=======================================================================
\r
570 // name : SMESHGUI_MeshPatternDlg::prepareFilters
\r
571 // Purpose : Prepare filters for dialog
\r
572 //=======================================================================
\r
574 QStringList SMESHGUI_MeshPatternDlg::prepareFilters() const
\r
576 static QStringList aList;
\r
577 if ( aList.isEmpty() )
\r
579 aList.append( tr( "PATTERN_FILT" ) );
\r
580 //aList.append( tr( "ALL_FILES_FILTER" ) );
\r
586 //================================================================
\r
588 // Function : SMESHGUI_MeshPatternDlg::autoExtension
\r
589 // Purpose : Append extension to the file name
\r
590 //================================================================
\r
591 QString SMESHGUI_MeshPatternDlg::autoExtension( const QString& theFileName ) const
\r
593 QString anExt = theFileName.section( '.', -1 );
\r
594 return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName;
\r
597 //=======================================================================
\r
598 // name : SMESHGUI_MeshPatternDlg::onOpen
\r
599 // Purpose : SLOT. Called when "Open" button clicked.
\r
600 // Displays file open dialog
\r
601 //=======================================================================
\r
602 void SMESHGUI_MeshPatternDlg::onOpen()
\r
604 QAD_FileDlg* aDlg = new QAD_FileDlg( this, true );
\r
605 aDlg->setCaption( tr( "LOAD_PATTERN" ) );
\r
606 aDlg->setMode( QFileDialogP::ExistingFile );
\r
607 aDlg->setFilters( prepareFilters() );
\r
608 if ( myName->text() != "" )
\r
609 aDlg->setSelection( myName->text() + ".smp" );
\r
610 QPushButton* anOkBtn = ( QPushButton* )aDlg->child( "OK", "QPushButton" );
\r
611 if ( anOkBtn != 0 )
\r
612 anOkBtn->setText( tr( "SMESH_BUT_OK" ) );
\r
614 if ( aDlg->exec() != Accepted )
\r
617 QString fName = aDlg->selectedFile();
\r
618 if ( fName.isEmpty() )
\r
621 if ( QFileInfo( fName ).extension().isEmpty() )
\r
622 fName = autoExtension( fName );
\r
624 fName = QDir::convertSeparators( fName );
\r
626 QString prev = QDir::convertSeparators( myName->text() );
\r
627 if ( prev == fName )
\r
630 // Read string from file
\r
631 QFile aFile( fName );
\r
632 if ( !aFile.open( IO_ReadOnly ) )
\r
634 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
635 tr( "SMESH_ERROR" ), tr( "ERROR_OF_OPENING" ), QMessageBox::Ok );
\r
639 QByteArray aDataArray = aFile.readAll();
\r
640 const char* aData = aDataArray.data();
\r
643 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
644 tr( "SMESH_ERROR" ), tr( "ERROR_OF_READING" ), QMessageBox::Ok );
\r
648 if ( loadFromFile( aData ) )
\r
649 myName->setText( QFileInfo( fName ).baseName() );
\r
655 //=======================================================================
\r
656 // name : SMESHGUI_MeshPatternDlg::onCloseCreationDlg
\r
657 // Purpose : SLOT. Called when "Pattern creation" dialog closed with "Close"
\r
658 //=======================================================================
\r
659 void SMESHGUI_MeshPatternDlg::onCloseCreationDlg()
\r
661 setEnabled( true );
\r
662 myIsCreateDlgOpen = false;
\r
666 //=======================================================================
\r
667 // name : SMESHGUI_MeshPatternDlg::onOkCreationDlg
\r
668 // Purpose : SLOT. Called when "Pattern creation" dialog closed with OK
\r
669 // or SAVE buttons. Initialize myPattern field. Redisplay preview
\r
670 //=======================================================================
\r
671 void SMESHGUI_MeshPatternDlg::onOkCreationDlg()
\r
673 myPattern = SMESH::SMESH_Pattern::_duplicate( myCreationDlg->GetPattern() );
\r
674 myName->setText( myCreationDlg->GetPatternName() );
\r
676 setEnabled( true );
\r
677 myIsCreateDlgOpen = false;
\r
681 //=======================================================================
\r
682 // name : SMESHGUI_MeshPatternDlg::onNew
\r
683 // Purpose : SLOT. Called when "New..." button clicked. Create new pattern
\r
684 //=======================================================================
\r
685 void SMESHGUI_MeshPatternDlg::onNew()
\r
687 setEnabled( false );
\r
688 myIsCreateDlgOpen = true;
\r
689 if ( myCreationDlg == 0 )
\r
691 myCreationDlg = new SMESHGUI_CreatePatternDlg( this, mySelection, myType );
\r
692 connect( myCreationDlg, SIGNAL( NewPattern() ), SLOT( onOkCreationDlg() ) );
\r
693 connect( myCreationDlg, SIGNAL( Close() ), SLOT( onCloseCreationDlg() ) );
\r
696 myCreationDlg->Init( mySelection, myType );
\r
698 myCreationDlg->SetMesh( myMesh );
\r
699 myCreationDlg->show();
\r
702 //=======================================================================
\r
703 // name : SMESHGUI_MeshPatternDlg::onReverse
\r
704 // Purpose : SLOT. Called when state of "Reverse order..." checkbox chaged
\r
705 // Calculate new points of the mesh to be created. Redisplay preview
\r
706 //=======================================================================
\r
707 void SMESHGUI_MeshPatternDlg::onReverse( bool )
\r
712 //=======================================================================
\r
714 // name : SMESHGUI_MeshPatternDlg::onPreview
\r
715 // Purpose : SLOT. Called when state of "Preview" checkbox changed
\r
716 // Display/Erase preview
\r
717 //=======================================================================
\r
718 void SMESHGUI_MeshPatternDlg::onPreview( bool )
\r
723 //=======================================================================
\r
724 // name : SMESHGUI_MeshPatternDlg::displayPreview
\r
725 // Purpose : Display preview
\r
726 //=======================================================================
\r
727 void SMESHGUI_MeshPatternDlg::displayPreview()
\r
731 // Redisplay preview in dialog
\r
733 SMESH::point_array_var pnts = myPattern->GetPoints();
\r
734 SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
\r
735 SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints();
\r
737 if ( pnts->length() == 0 ||
\r
738 keyPoints->length() == 0 ||
\r
739 elemPoints->length() == 0 )
\r
747 PointVector aPoints( pnts->length() );
\r
748 QValueVector<int> aKeyPoints( keyPoints->length() );
\r
749 ConnectivityVector anElemPoints( elemPoints->length() );
\r
751 for ( int i = 0, n = pnts->length(); i < n; i++ )
\r
752 aPoints[ i ] = pnts[ i ];
\r
754 for ( int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++ )
\r
755 aKeyPoints[ i2 ] = keyPoints[ i2 ];
\r
757 for ( int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++ )
\r
759 QValueVector<int> aVec( elemPoints[ i3 ].length() );
\r
760 for ( int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++ )
\r
761 aVec[ i4 ] = elemPoints[ i3 ][ i4 ];
\r
763 anElemPoints[ i3 ] = aVec;
\r
766 myPicture2d->SetPoints( aPoints, aKeyPoints, anElemPoints );
\r
770 // Redisplay preview in 3D viewer
\r
772 if ( myPreviewActor != 0 )
\r
774 if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() )
\r
776 vf->RemoveActor(myPreviewActor);
\r
779 myPreviewActor->Delete();
\r
780 myPreviewActor = 0;
\r
783 if ( !myPreviewChk->isChecked() || !isValid( false ) )
\r
786 vtkUnstructuredGrid* aGrid = getGrid();
\r
790 // Create and display actor
\r
791 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
\r
792 aMapper->SetInput( aGrid );
\r
794 myPreviewActor = SALOME_Actor::New();
\r
795 myPreviewActor->PickableOff();
\r
796 myPreviewActor->SetMapper( aMapper );
\r
798 vtkProperty* aProp = vtkProperty::New();
\r
799 aProp->SetRepresentationToWireframe();
\r
800 aProp->SetColor( 250, 0, 250 );
\r
801 if ( SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh ) )
\r
802 aProp->SetLineWidth( SMESH::GetFloat( "SMESH:SettingsWidth", 1 ) +1 );
\r
804 aProp->SetLineWidth( 1 );
\r
805 myPreviewActor->SetProperty( aProp );
\r
807 myPreviewActor->SetRepresentation( 3 );
\r
809 SMESH::GetCurrentVtkView()->AddActor( myPreviewActor );
\r
810 SMESH::GetCurrentVtkView()->Repaint();
\r
815 catch( const SALOME::SALOME_Exception& S_ex )
\r
817 QtCatchCorbaException( S_ex );
\r
826 //=======================================================================
\r
827 // name : SMESHGUI_MeshPatternDlg::erasePreview
\r
828 // Purpose : Erase preview
\r
829 //=======================================================================
\r
830 void SMESHGUI_MeshPatternDlg::erasePreview()
\r
832 // Erase preview in 2D viewer
\r
833 myPicture2d->SetPoints( PointVector(), QValueVector<int>(), ConnectivityVector() );
\r
835 // Erase preview in 3D viewer
\r
836 if ( myPreviewActor == 0 )
\r
840 if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() )
\r
842 vf->RemoveActor(myPreviewActor);
\r
845 myPreviewActor->Delete();
\r
846 myPreviewActor = 0;
\r
849 //=======================================================================
\r
850 // name : SMESHGUI_MeshPatternDlg::updateWgState
\r
851 // Purpose : Enable/disable selection widgets
\r
852 //=======================================================================
\r
853 void SMESHGUI_MeshPatternDlg::updateWgState()
\r
855 if ( myMesh->_is_nil() )
\r
857 for ( int i = Object; i <= Vertex2; i++ )
\r
859 mySelBtn [ i ]->setEnabled( false );
\r
860 mySelEdit[ i ]->setEnabled( false );
\r
861 mySelEdit[ i ]->setText( "" );
\r
866 mySelBtn [ Object ]->setEnabled( true );
\r
867 mySelEdit[ Object ]->setEnabled( true );
\r
869 if ( myGeomObj[ Object ]->_is_nil() )
\r
871 for ( int i = Vertex1; i <= Vertex2; i++ )
\r
873 mySelBtn [ i ]->setEnabled( false );
\r
874 mySelEdit[ i ]->setEnabled( false );
\r
875 mySelEdit[ i ]->setText( "" );
\r
880 for ( int i = Object; i <= Vertex2; i++ )
\r
882 mySelBtn [ i ]->setEnabled( true );
\r
883 mySelEdit[ i ]->setEnabled( true );
\r
889 //=======================================================================
\r
890 // name : SMESHGUI_MeshPatternDlg::activateSelection
\r
891 // Purpose : Activate selection in accordance with current selection input
\r
892 //=======================================================================
\r
893 void SMESHGUI_MeshPatternDlg::activateSelection()
\r
895 mySelection->ClearFilters();
\r
896 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
898 if ( mySelInput == Object && !myMeshShape->_is_nil() )
\r
900 if ( myType == Type_2d )
\r
902 if ( myNbPoints > 0 )
\r
903 mySelection->AddFilter( new SMESH_NumberFilter(
\r
905 "GEOM", TopAbs_VERTEX, myNbPoints, TopAbs_FACE, myMeshShape ) );
\r
907 mySelection->AddFilter( new SMESH_NumberFilter(
\r
908 "GEOM", TopAbs_SHAPE, myNbPoints, TopAbs_FACE, myMeshShape ) );
\r
912 TColStd_MapOfInteger aTypes;
\r
913 aTypes.Add( TopAbs_SHELL );
\r
914 aTypes.Add( TopAbs_SOLID );
\r
915 mySelection->AddFilter( new SMESH_NumberFilter(
\r
916 "GEOM", TopAbs_FACE, 6, aTypes, myMeshShape, true ) );
\r
919 else if ( ( mySelInput == Vertex1 || mySelInput == Vertex2 ) && !myGeomObj[ Object ]->_is_nil() )
\r
921 mySelection->AddFilter( new SMESH_NumberFilter(
\r
922 "GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX, myGeomObj[ Object ] ) );
\r
926 //=======================================================================
\r
927 // name : SMESHGUI_MeshPatternDlg::loadFromFile
\r
928 // Purpose : Load pattern from file
\r
929 //=======================================================================
\r
930 bool SMESHGUI_MeshPatternDlg::loadFromFile( const QString& theName )
\r
934 SMESH::SMESH_Pattern_var aPattern = SMESH::GetPattern();
\r
936 if ( !aPattern->LoadFromFile( theName.latin1() ) ||
\r
937 myType == Type_2d && !aPattern->Is2D())
\r
939 SMESH::SMESH_Pattern::ErrorCode aCode = aPattern->GetErrorCode();
\r
941 if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NB_POINTS ) aMess = tr( "ERR_READ_NB_POINTS" );
\r
942 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_POINT_COORDS ) aMess = tr( "ERR_READ_POINT_COORDS" );
\r
943 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_TOO_FEW_POINTS ) aMess = tr( "ERR_READ_TOO_FEW_POINTS" );
\r
944 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_3D_COORD ) aMess = tr( "ERR_READ_3D_COORD" );
\r
945 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_KEYPOINT ) aMess = tr( "ERR_READ_NO_KEYPOINT" );
\r
946 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_INDEX ) aMess = tr( "ERR_READ_BAD_INDEX" );
\r
947 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_ELEM_POINTS ) aMess = tr( "ERR_READ_ELEM_POINTS" );
\r
948 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_ELEMS ) aMess = tr( "ERR_READ_NO_ELEMS" );
\r
949 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_KEY_POINT ) aMess = tr( "ERR_READ_BAD_KEY_POINT" );
\r
950 else aMess = tr( "ERROR_OF_LOADING" );
\r
952 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
953 tr( "SMESH_ERROR" ), aMess, QMessageBox::Ok );
\r
958 myPattern = aPattern;
\r
962 catch( const SALOME::SALOME_Exception& S_ex )
\r
964 QtCatchCorbaException( S_ex );
\r
965 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
966 tr( "SMESH_ERROR" ), tr( "ERROR_OF_LOADING" ), QMessageBox::Ok );
\r
971 //=======================================================================
\r
972 // name : SMESHGUI_MeshPatternDlg::onTypeChanged
\r
974 // Purpose : SLOT. Called when pattern type changed.
\r
975 // Change dialog's look and feel
\r
976 //=======================================================================
\r
977 void SMESHGUI_MeshPatternDlg::onTypeChanged( int theType )
\r
979 if ( myType == theType )
\r
985 myGeomObj[ Object ] = GEOM::GEOM_Object::_nil();
\r
986 myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();
\r
987 myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();
\r
988 myPattern = SMESH::GetPattern();
\r
990 myName->setText( "" );
\r
991 mySelEdit[ Object ]->setText( "" );
\r
992 mySelEdit[ Vertex1 ]->setText( "" );
\r
993 mySelEdit[ Vertex2 ]->setText( "" );
\r
995 if ( theType == Type_2d )
\r
997 mySelLbl [ Vertex2 ]->hide();
\r
998 mySelBtn [ Vertex2 ]->hide();
\r
999 mySelEdit[ Vertex2 ]->hide();
\r
1000 myReverseChk->show();
\r
1001 myPicture2d->show();
\r
1002 myPicture3d->hide();
\r
1003 mySelLbl[ Object ]->setText( tr( "FACE" ) );
\r
1004 mySelLbl[ Vertex1 ]->setText( tr( "VERTEX" ) );
\r
1008 mySelLbl [ Vertex2 ]->show();
\r
1009 mySelBtn [ Vertex2 ]->show();
\r
1010 mySelEdit[ Vertex2 ]->show();
\r
1011 myReverseChk->hide();
\r
1012 myPicture2d->hide();
\r
1013 myPicture3d->show();
\r
1014 mySelLbl[ Object ]->setText( tr( "3D_BLOCK" ) );
\r
1015 mySelLbl[ Vertex1 ]->setText( tr( "VERTEX1" ) );
\r
1016 mySelLbl[ Vertex2 ]->setText( tr( "VERTEX2" ) );
\r
1019 mySelInput = Mesh;
\r
1020 activateSelection();
\r
1025 //=======================================================================
\r
1026 // name : SMESHGUI_MeshPatternDlg::getGrid
\r
1027 // Purpose : Get unstructured grid for pattern
\r
1028 //=======================================================================
\r
1029 vtkUnstructuredGrid* SMESHGUI_MeshPatternDlg::getGrid()
\r
1033 // Get points from pattern
\r
1034 SMESH::point_array_var pnts = myType == Type_2d
\r
1035 ? myPattern->ApplyToFace( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() )
\r
1036 : myPattern->ApplyTo3DBlock( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] );
\r
1038 SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints();
\r
1040 if ( pnts->length() == 0 || elemPoints->length() == 0 )
\r
1045 // to do : to be removed /////////////////////////////////////////////
\r
1048 for ( int i1 = 0, n1 = pnts->length(); i1 < n1; i1++ )
\r
1049 printf( "%d: %g %g %g\n", i1, pnts[ i1 ].x, pnts[ i1 ].y, pnts[ i1 ].z );
\r
1051 printf( "\nELEMENTS : \n" );
\r
1052 for ( int i2 = 0, n2 = elemPoints->length(); i2 < n2; i2++ )
\r
1055 printf( "%d: ", i2 );
\r
1056 for ( int i3 = 0, n3 = elemPoints[ i2 ].length(); i3 < n3; i3++ )
\r
1057 printf( "%d ", elemPoints[ i2 ][ i3 ] );
\r
1063 //////////////////////////////////////////////////////////////////////
\r
1065 // Calculate number of points used for cell
\r
1066 vtkIdType aNbCells = elemPoints->length();
\r
1067 vtkIdType aCellsSize = 0;
\r
1068 for ( int i = 0, n = elemPoints->length(); i < n; i++ )
\r
1069 aCellsSize += elemPoints[ i ].length();
\r
1071 // Create unstructured grid and other usefull arrays
\r
1072 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
\r
1074 vtkCellArray* aConnectivity = vtkCellArray::New();
\r
1075 aConnectivity->Allocate( aCellsSize, 0 );
\r
1077 vtkPoints* aPoints = vtkPoints::New();
\r
1078 aPoints->SetNumberOfPoints( pnts->length() );
\r
1080 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
\r
1081 aCellTypesArray->SetNumberOfComponents( 1 );
\r
1082 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
\r
1084 vtkIdList *anIdList = vtkIdList::New();
\r
1086 // Fill array of points
\r
1087 for ( int p = 0, nbPnt = pnts->length(); p < nbPnt; p++ )
\r
1088 aPoints->SetPoint( p, pnts[ p ].x, pnts[ p ].y, pnts[ p ].z );
\r
1090 for ( int e = 0, nbElem = elemPoints->length(); e < nbElem; e++ )
\r
1092 int nbPoints = elemPoints[ e ].length();
\r
1093 anIdList->SetNumberOfIds( nbPoints );
\r
1094 for ( int i = 0; i < nbPoints; i++ )
\r
1095 anIdList->SetId( i, elemPoints[ e ][ i ] );
\r
1097 aConnectivity->InsertNextCell( anIdList );
\r
1099 if ( nbPoints == 3 ) aCellTypesArray->InsertNextValue( VTK_TRIANGLE );
\r
1100 else if ( nbPoints == 5 ) aCellTypesArray->InsertNextValue( VTK_PYRAMID );
\r
1101 else if ( nbPoints == 6 ) aCellTypesArray->InsertNextValue( VTK_WEDGE );
\r
1102 else if ( nbPoints == 8 ) aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
\r
1103 else if ( nbPoints == 4 && myType == Type_2d ) aCellTypesArray->InsertNextValue( VTK_QUAD );
\r
1104 else if ( nbPoints == 4 && myType == Type_3d ) aCellTypesArray->InsertNextValue( VTK_TETRA );
\r
1105 else aCellTypesArray->InsertNextValue( VTK_EMPTY_CELL );
\r
1108 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
\r
1109 aCellLocationsArray->SetNumberOfComponents( 1 );
\r
1110 aCellLocationsArray->SetNumberOfTuples( aNbCells );
\r
1112 aConnectivity->InitTraversal();
\r
1113 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
\r
1114 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
\r
1116 aGrid->SetPoints( aPoints );
\r
1117 aGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
\r
1119 aConnectivity->Delete();
\r
1120 aPoints->Delete();
\r
1121 aCellTypesArray->Delete();
\r
1122 anIdList->Delete();
\r
1123 aCellLocationsArray->Delete();
\r