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
181 myPicture2d = new SMESHGUI_PatternWidget( aPatGrp ),
\r
182 myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
\r
186 myPicture3d = new QFrame( aPatGrp ),
\r
187 myPreview3d = new QLabel( myPicture3d );
\r
188 myPreview3d->setPixmap( iconSample3d );
\r
189 QGridLayout* aLay = new QGridLayout( myPicture3d, 3, 3, 0, 0 );
\r
190 QSpacerItem* aSpacerH1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
\r
191 QSpacerItem* aSpacerH2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
\r
192 QSpacerItem* aSpacerV1 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
\r
193 QSpacerItem* aSpacerV2 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
\r
194 aLay->addItem( aSpacerH1, 1, 0 );
\r
195 aLay->addItem( aSpacerH2, 1, 2 );
\r
196 aLay->addItem( aSpacerV1, 0, 1 );
\r
197 aLay->addItem( aSpacerV2, 2, 1 );
\r
198 aLay->addWidget( myPreview3d, 1, 1 );
\r
202 myPreviewChk = new QCheckBox( tr( "PREVIEW" ), aPatGrp );
\r
204 // Connect signals and slots
\r
206 connect( myTypeGrp, SIGNAL( clicked( int ) ), SLOT( onTypeChanged( int ) ) );
\r
207 connect( myOpenBtn, SIGNAL( clicked() ), SLOT( onOpen() ) );
\r
208 connect( myNewBtn, SIGNAL( clicked() ), SLOT( onNew() ) );
\r
209 connect( myReverseChk, SIGNAL( toggled( bool ) ), SLOT( onReverse( bool ) ) );
\r
210 connect( myPreviewChk, SIGNAL( toggled( bool ) ), SLOT( onPreview( bool ) ) );
\r
212 QMap< int, QPushButton* >::iterator anIter;
\r
213 for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter )
\r
214 connect( *anIter, SIGNAL( clicked() ), SLOT( onSelInputChanged() ) );
\r
219 //=======================================================================
\r
221 // name : SMESHGUI_MeshPatternDlg::createButtonFrame
\r
222 // Purpose : Create frame containing buttons
\r
223 //=======================================================================
\r
224 QFrame* SMESHGUI_MeshPatternDlg::createButtonFrame( QWidget* theParent )
\r
226 QFrame* aFrame = new QFrame( theParent );
\r
227 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
\r
229 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), aFrame );
\r
230 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), aFrame );
\r
231 myCloseBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), aFrame );
\r
233 QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
\r
235 QHBoxLayout* aLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
\r
237 aLay->addWidget( myOkBtn );
\r
238 aLay->addWidget( myApplyBtn );
\r
239 aLay->addItem( aSpacer);
\r
240 aLay->addWidget( myCloseBtn );
\r
242 connect( myOkBtn, SIGNAL( clicked() ), SLOT( onOk() ) );
\r
243 connect( myCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) ) ;
\r
244 connect( myApplyBtn, SIGNAL( clicked() ), SLOT( onApply() ) );
\r
249 //=======================================================================
\r
250 // name : SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg
\r
251 // Purpose : Destructor
\r
252 //=======================================================================
\r
253 SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg()
\r
257 //=======================================================================
\r
258 // name : SMESHGUI_MeshPatternDlg::Init
\r
259 // Purpose : Init dialog fields, connect signals and slots, show dialog
\r
260 //=======================================================================
\r
261 void SMESHGUI_MeshPatternDlg::Init( SALOME_Selection* theSelection )
\r
263 myPattern = SMESH::GetPattern();
\r
264 myPreviewActor = 0;
\r
265 myIsCreateDlgOpen = false;
\r
269 mySelection = theSelection;
\r
270 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
\r
271 aSMESHGUI->SetActiveDialogBox( ( QDialog* )this );
\r
272 myMesh = SMESH::SMESH_Mesh::_nil();
\r
274 myMeshShape = GEOM::GEOM_Object::_nil();
\r
275 myGeomObj[ Object ] = GEOM::GEOM_Object::_nil();
\r
276 myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();
\r
277 myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();
\r
279 // selection and SMESHGUI
\r
280 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
\r
281 connect( aSMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) );
\r
282 connect( aSMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) );
\r
284 myTypeGrp->setButton( Type_2d );
\r
285 onTypeChanged( Type_2d );
\r
289 resize( minimumSize() );
\r
291 activateSelection();
\r
295 aSMESHGUI->DefineDlgPosition( this, x, y );
\r
296 this->move( x, y );
\r
300 //=======================================================================
\r
301 // name : SMESHGUI_MeshPatternDlg::isValid
\r
302 // Purpose : Verify validity of entry data
\r
303 //=======================================================================
\r
304 bool SMESHGUI_MeshPatternDlg::isValid( const bool theMess )
\r
306 if ( myMesh->_is_nil() || myMeshShape->_is_nil() || myGeomObj[ Object ]->_is_nil() ||
\r
307 myGeomObj[ Vertex1 ]->_is_nil() || myType == Type_3d && myGeomObj[ Vertex2 ]->_is_nil() )
\r
310 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
311 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SMESHGUI_INVALID_PARAMETERS" ), QMessageBox::Ok );
\r
318 //=======================================================================
\r
319 // name : SMESHGUI_MeshPatternDlg::onApply
\r
320 // Purpose : SLOT called when "Apply" button pressed.
\r
321 //=======================================================================
\r
322 bool SMESHGUI_MeshPatternDlg::onApply()
\r
329 if ( myType == Type_2d )
\r
330 myPattern->ApplyToFace(
\r
331 myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() );
\r
333 myPattern->ApplyTo3DBlock(
\r
334 myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] );
\r
336 if ( myPattern->MakeMesh( myMesh ) )
\r
338 mySelection->ClearIObjects();
\r
339 SMESH::UpdateView();
\r
340 SMESHGUI::GetSMESHGUI()->GetActiveStudy()->updateObjBrowser( true );
\r
345 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
346 tr( "SMESH_ERROR" ), tr( "SMESH_OPERATION_FAILED" ), QMessageBox::Ok );
\r
350 catch( const SALOME::SALOME_Exception& S_ex )
\r
352 QtCatchCorbaException( S_ex );
\r
361 //=======================================================================
\r
362 // name : SMESHGUI_MeshPatternDlg::onOk
\r
363 // Purpose : SLOT called when "Ok" button pressed.
\r
364 //=======================================================================
\r
365 void SMESHGUI_MeshPatternDlg::onOk()
\r
371 //=======================================================================
\r
372 // name : SMESHGUI_MeshPatternDlg::onClose
\r
373 // Purpose : SLOT called when "Close" button pressed. Close dialog
\r
374 //=======================================================================
\r
375 void SMESHGUI_MeshPatternDlg::onClose()
\r
377 mySelection->ClearFilters();
\r
378 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
379 disconnect( mySelection, 0, this, 0 );
\r
380 disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );
\r
381 SMESHGUI::GetSMESHGUI()->ResetState();
\r
388 //=======================================================================
\r
389 // name : SMESHGUI_MeshPatternDlg::onSelectionDone
\r
390 // Purpose : SLOT called when selection changed
\r
391 //=======================================================================
\r
392 void SMESHGUI_MeshPatternDlg::onSelectionDone()
\r
396 if ( mySelection->IObjectCount() != 1 )
\r
399 if ( mySelInput == Mesh )
\r
401 // Retrieve mesh from selection
\r
402 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
\r
403 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIO );
\r
404 if ( aMesh->_is_nil() )
\r
407 // Get geom object corresponding to the mesh
\r
408 SALOMEDS::Study_var aStudy =
\r
409 SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getStudyDocument();
\r
411 SALOMEDS::SObject_var aSO = SMESH::FindSObject( aMesh.in() );
\r
412 if ( aSO->_is_nil() )
\r
415 bool isFound = false;
\r
416 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( aSO );
\r
417 for( ; anIter->More(); anIter->Next() )
\r
419 SALOMEDS::SObject_var aSO = anIter->Value();
\r
420 SALOMEDS::SObject_var aRefSO;
\r
422 GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(
\r
423 aSO->ReferencedObject( aRefSO )? aRefSO->GetObject() : aSO->GetObject() );
\r
425 if ( !aMeshShape->_is_nil() )
\r
428 myMeshShape = aMeshShape;
\r
437 // Clear fields of geom objects if mesh was changed
\r
438 if ( myMesh != aMesh )
\r
440 for ( int i = Object; i <= Vertex2; i++ )
\r
442 myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
\r
443 mySelEdit[ i ]->setText( "" );
\r
449 // Set name of mesh in line edit
\r
451 SMESH::GetNameOfSelectedIObjects( mySelection, aName );
\r
452 mySelEdit[ Mesh ]->setText( aName );
\r
456 // Get geom object from selection
\r
457 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
\r
458 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>( anIO );
\r
459 if ( anObj->_is_nil() )
\r
462 // Clear fields of vertexes if face or 3d block was changed
\r
463 if ( anObj != myGeomObj[ mySelInput ] && mySelInput == Object )
\r
465 for ( int i = Vertex1; i <= Vertex2; i++ )
\r
467 myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
\r
468 mySelEdit[ i ]->setText( "" );
\r
472 myGeomObj[ mySelInput ] = anObj;
\r
474 // Set name of geom object in line edit
\r
476 SMESH::GetNameOfSelectedIObjects( mySelection, aName );
\r
477 mySelEdit[ mySelInput ]->setText( aName );
\r
480 catch( const SALOME::SALOME_Exception& S_ex )
\r
482 QtCatchCorbaException( S_ex );
\r
494 //=======================================================================
\r
495 // name : SMESHGUI_MeshPatternDlg::resetSelInput
\r
496 // Purpose : Reset fields corresponding to the current selection input
\r
497 //=======================================================================
\r
498 void SMESHGUI_MeshPatternDlg::resetSelInput()
\r
500 if ( mySelInput == Mesh )
\r
502 myMesh = SMESH::SMESH_Mesh::_nil();
\r
503 myMeshShape = GEOM::GEOM_Object::_nil();
\r
507 myGeomObj[ mySelInput ] = GEOM::GEOM_Object::_nil();
\r
509 mySelEdit[ mySelInput ]->setText( "" );
\r
512 //=======================================================================
\r
513 // name : SMESHGUI_MeshPatternDlg::onDeactivate
\r
514 // Purpose : SLOT called when dialog must be deativated
\r
515 //=======================================================================
\r
516 void SMESHGUI_MeshPatternDlg::onDeactivate()
\r
518 mySelection->ClearFilters();
\r
519 //if ( myReverseChk->isChecked() )
\r
521 disconnect( mySelection, 0, this, 0 );
\r
522 setEnabled( false );
\r
525 //=======================================================================
\r
526 // name : SMESHGUI_MeshPatternDlg::enterEvent
\r
527 // Purpose : Event filter
\r
528 //=======================================================================
\r
529 void SMESHGUI_MeshPatternDlg::enterEvent( QEvent* )
\r
531 if ( myIsCreateDlgOpen )
\r
534 if ( myReverseChk->isChecked() )
\r
536 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog() ;
\r
537 setEnabled( true );
\r
538 activateSelection();
\r
539 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
\r
543 //=================================================================================
\r
544 // function : closeEvent()
\r
546 //=================================================================================
\r
547 void SMESHGUI_MeshPatternDlg::closeEvent( QCloseEvent* e )
\r
552 //=======================================================================
\r
553 // name : SMESHGUI_MeshPatternDlg::onSelInputChanged
\r
554 // Purpose : SLOT. Called when -> button clicked.
\r
555 // Change current selection input field
\r
556 //=======================================================================
\r
557 void SMESHGUI_MeshPatternDlg::onSelInputChanged()
\r
559 const QObject* aSender = sender();
\r
560 for ( int i = Mesh; i <= Vertex2; i++ )
\r
561 if ( aSender == mySelBtn[ i ] )
\r
564 activateSelection();
\r
568 //=======================================================================
\r
569 // name : SMESHGUI_MeshPatternDlg::prepareFilters
\r
570 // Purpose : Prepare filters for dialog
\r
571 //=======================================================================
\r
573 QStringList SMESHGUI_MeshPatternDlg::prepareFilters() const
\r
575 static QStringList aList;
\r
576 if ( aList.isEmpty() )
\r
578 aList.append( tr( "PATTERN_FILT" ) );
\r
579 //aList.append( tr( "ALL_FILES_FILTER" ) );
\r
585 //================================================================
\r
587 // Function : SMESHGUI_MeshPatternDlg::autoExtension
\r
588 // Purpose : Append extension to the file name
\r
589 //================================================================
\r
590 QString SMESHGUI_MeshPatternDlg::autoExtension( const QString& theFileName ) const
\r
592 QString anExt = theFileName.section( '.', -1 );
\r
593 return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName;
\r
596 //=======================================================================
\r
597 // name : SMESHGUI_MeshPatternDlg::onOpen
\r
598 // Purpose : SLOT. Called when "Open" button clicked.
\r
599 // Displays file open dialog
\r
600 //=======================================================================
\r
601 void SMESHGUI_MeshPatternDlg::onOpen()
\r
603 QAD_FileDlg* aDlg = new QAD_FileDlg( this, true );
\r
604 aDlg->setCaption( tr( "LOAD_PATTERN" ) );
\r
605 aDlg->setMode( QFileDialogP::ExistingFile );
\r
606 aDlg->setFilters( prepareFilters() );
\r
607 if ( myName->text() != "" )
\r
608 aDlg->setSelection( myName->text() + ".smp" );
\r
609 QPushButton* anOkBtn = ( QPushButton* )aDlg->child( "OK", "QPushButton" );
\r
610 if ( anOkBtn != 0 )
\r
611 anOkBtn->setText( tr( "SMESH_BUT_OK" ) );
\r
613 if ( aDlg->exec() != Accepted )
\r
616 QString fName = aDlg->selectedFile();
\r
617 if ( fName.isEmpty() )
\r
620 if ( QFileInfo( fName ).extension().isEmpty() )
\r
621 fName = autoExtension( fName );
\r
623 fName = QDir::convertSeparators( fName );
\r
625 QString prev = QDir::convertSeparators( myName->text() );
\r
626 if ( prev == fName )
\r
629 // Read string from file
\r
630 QFile aFile( fName );
\r
631 if ( !aFile.open( IO_ReadOnly ) )
\r
633 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
634 tr( "SMESH_ERROR" ), tr( "ERROR_OF_OPENING" ), QMessageBox::Ok );
\r
638 QByteArray aDataArray = aFile.readAll();
\r
639 const char* aData = aDataArray.data();
\r
642 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
643 tr( "SMESH_ERROR" ), tr( "ERROR_OF_READING" ), QMessageBox::Ok );
\r
647 if ( loadFromFile( aData ) )
\r
648 myName->setText( QFileInfo( fName ).baseName() );
\r
654 //=======================================================================
\r
655 // name : SMESHGUI_MeshPatternDlg::onCloseCreationDlg
\r
656 // Purpose : SLOT. Called when "Pattern creation" dialog closed with "Close"
\r
657 //=======================================================================
\r
658 void SMESHGUI_MeshPatternDlg::onCloseCreationDlg()
\r
660 setEnabled( true );
\r
661 myIsCreateDlgOpen = false;
\r
665 //=======================================================================
\r
666 // name : SMESHGUI_MeshPatternDlg::onOkCreationDlg
\r
667 // Purpose : SLOT. Called when "Pattern creation" dialog closed with OK
\r
668 // or SAVE buttons. Initialize myPattern field. Redisplay preview
\r
669 //=======================================================================
\r
670 void SMESHGUI_MeshPatternDlg::onOkCreationDlg()
\r
672 myPattern = SMESH::SMESH_Pattern::_duplicate( myCreationDlg->GetPattern() );
\r
673 myName->setText( myCreationDlg->GetPatternName() );
\r
675 setEnabled( true );
\r
676 myIsCreateDlgOpen = false;
\r
680 //=======================================================================
\r
681 // name : SMESHGUI_MeshPatternDlg::onNew
\r
682 // Purpose : SLOT. Called when "New..." button clicked. Create new pattern
\r
683 //=======================================================================
\r
684 void SMESHGUI_MeshPatternDlg::onNew()
\r
686 setEnabled( false );
\r
687 myIsCreateDlgOpen = true;
\r
688 if ( myCreationDlg == 0 )
\r
690 myCreationDlg = new SMESHGUI_CreatePatternDlg( this, mySelection, myType );
\r
691 connect( myCreationDlg, SIGNAL( NewPattern() ), SLOT( onOkCreationDlg() ) );
\r
692 connect( myCreationDlg, SIGNAL( Close() ), SLOT( onCloseCreationDlg() ) );
\r
695 myCreationDlg->Init( mySelection, myType );
\r
697 myCreationDlg->SetMesh( myMesh );
\r
698 myCreationDlg->show();
\r
701 //=======================================================================
\r
702 // name : SMESHGUI_MeshPatternDlg::onReverse
\r
703 // Purpose : SLOT. Called when state of "Reverse order..." checkbox chaged
\r
704 // Calculate new points of the mesh to be created. Redisplay preview
\r
705 //=======================================================================
\r
706 void SMESHGUI_MeshPatternDlg::onReverse( bool )
\r
711 //=======================================================================
\r
713 // name : SMESHGUI_MeshPatternDlg::onPreview
\r
714 // Purpose : SLOT. Called when state of "Preview" checkbox changed
\r
715 // Display/Erase preview
\r
716 //=======================================================================
\r
717 void SMESHGUI_MeshPatternDlg::onPreview( bool )
\r
722 //=======================================================================
\r
723 // name : SMESHGUI_MeshPatternDlg::displayPreview
\r
724 // Purpose : Display preview
\r
725 //=======================================================================
\r
726 void SMESHGUI_MeshPatternDlg::displayPreview()
\r
730 // Redisplay preview in dialog
\r
732 SMESH::point_array_var pnts = myPattern->GetPoints();
\r
733 SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
\r
734 SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints();
\r
736 if ( pnts->length() == 0 ||
\r
737 keyPoints->length() == 0 ||
\r
738 elemPoints->length() == 0 )
\r
746 PointVector aPoints( pnts->length() );
\r
747 QValueVector<int> aKeyPoints( keyPoints->length() );
\r
748 ConnectivityVector anElemPoints( elemPoints->length() );
\r
750 for ( int i = 0, n = pnts->length(); i < n; i++ )
\r
751 aPoints[ i ] = pnts[ i ];
\r
753 for ( int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++ )
\r
754 aKeyPoints[ i2 ] = keyPoints[ i2 ];
\r
756 for ( int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++ )
\r
758 QValueVector<int> aVec( elemPoints[ i3 ].length() );
\r
759 for ( int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++ )
\r
760 aVec[ i4 ] = elemPoints[ i3 ][ i4 ];
\r
762 anElemPoints[ i3 ] = aVec;
\r
765 myPicture2d->SetPoints( aPoints, aKeyPoints, anElemPoints );
\r
769 // Redisplay preview in 3D viewer
\r
771 if ( myPreviewActor != 0 )
\r
773 if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() )
\r
775 vf->RemoveActor(myPreviewActor);
\r
778 myPreviewActor->Delete();
\r
779 myPreviewActor = 0;
\r
782 if ( !myPreviewChk->isChecked() || !isValid( false ) )
\r
785 vtkUnstructuredGrid* aGrid = getGrid();
\r
789 // Create and display actor
\r
790 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
\r
791 aMapper->SetInput( aGrid );
\r
793 myPreviewActor = SALOME_Actor::New();
\r
794 myPreviewActor->PickableOff();
\r
795 myPreviewActor->SetMapper( aMapper );
\r
797 vtkProperty* aProp = vtkProperty::New();
\r
798 aProp->SetRepresentationToWireframe();
\r
799 aProp->SetColor( 250, 0, 250 );
\r
800 if ( SMESH::FindActorByObject( myMesh ) )
\r
801 aProp->SetLineWidth( SMESH::GetFloat( "SMESH:SettingsWidth", 1 ) +1 );
\r
803 aProp->SetLineWidth( 1 );
\r
804 myPreviewActor->SetProperty( aProp );
\r
806 myPreviewActor->SetRepresentation( 3 );
\r
808 SMESH::GetCurrentVtkView()->AddActor( myPreviewActor );
\r
809 SMESH::GetCurrentVtkView()->Repaint();
\r
814 catch( const SALOME::SALOME_Exception& S_ex )
\r
816 QtCatchCorbaException( S_ex );
\r
825 //=======================================================================
\r
826 // name : SMESHGUI_MeshPatternDlg::erasePreview
\r
827 // Purpose : Erase preview
\r
828 //=======================================================================
\r
829 void SMESHGUI_MeshPatternDlg::erasePreview()
\r
831 // Erase preview in 2D viewer
\r
832 myPicture2d->SetPoints( PointVector(), QValueVector<int>(), ConnectivityVector() );
\r
834 // Erase preview in 3D viewer
\r
835 if ( myPreviewActor == 0 )
\r
839 if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() )
\r
841 vf->RemoveActor(myPreviewActor);
\r
844 myPreviewActor->Delete();
\r
845 myPreviewActor = 0;
\r
848 //=======================================================================
\r
849 // name : SMESHGUI_MeshPatternDlg::updateWgState
\r
850 // Purpose : Enable/disable selection widgets
\r
851 //=======================================================================
\r
852 void SMESHGUI_MeshPatternDlg::updateWgState()
\r
854 if ( myMesh->_is_nil() )
\r
856 for ( int i = Object; i <= Vertex2; i++ )
\r
858 mySelBtn [ i ]->setEnabled( false );
\r
859 mySelEdit[ i ]->setEnabled( false );
\r
860 mySelEdit[ i ]->setText( "" );
\r
865 mySelBtn [ Object ]->setEnabled( true );
\r
866 mySelEdit[ Object ]->setEnabled( true );
\r
868 if ( myGeomObj[ Object ]->_is_nil() )
\r
870 for ( int i = Vertex1; i <= Vertex2; i++ )
\r
872 mySelBtn [ i ]->setEnabled( false );
\r
873 mySelEdit[ i ]->setEnabled( false );
\r
874 mySelEdit[ i ]->setText( "" );
\r
879 for ( int i = Object; i <= Vertex2; i++ )
\r
881 mySelBtn [ i ]->setEnabled( true );
\r
882 mySelEdit[ i ]->setEnabled( true );
\r
888 //=======================================================================
\r
889 // name : SMESHGUI_MeshPatternDlg::activateSelection
\r
890 // Purpose : Activate selection in accordance with current selection input
\r
891 //=======================================================================
\r
892 void SMESHGUI_MeshPatternDlg::activateSelection()
\r
894 mySelection->ClearFilters();
\r
895 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
897 if ( mySelInput == Object && !myMeshShape->_is_nil() )
\r
899 if ( myType == Type_2d )
\r
901 if ( myNbPoints > 0 )
\r
902 mySelection->AddFilter( new SMESH_NumberFilter(
\r
904 "GEOM", TopAbs_VERTEX, myNbPoints, TopAbs_FACE, myMeshShape ) );
\r
906 mySelection->AddFilter( new SMESH_NumberFilter(
\r
907 "GEOM", TopAbs_SHAPE, myNbPoints, TopAbs_FACE, myMeshShape ) );
\r
911 TColStd_MapOfInteger aTypes;
\r
912 aTypes.Add( TopAbs_SHELL );
\r
913 aTypes.Add( TopAbs_SOLID );
\r
914 mySelection->AddFilter( new SMESH_NumberFilter(
\r
915 "GEOM", TopAbs_FACE, 6, aTypes, myMeshShape, true ) );
\r
918 else if ( ( mySelInput == Vertex1 || mySelInput == Vertex2 ) && !myGeomObj[ Object ]->_is_nil() )
\r
920 mySelection->AddFilter( new SMESH_NumberFilter(
\r
921 "GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX, myGeomObj[ Object ] ) );
\r
925 //=======================================================================
\r
926 // name : SMESHGUI_MeshPatternDlg::loadFromFile
\r
927 // Purpose : Load pattern from file
\r
928 //=======================================================================
\r
929 bool SMESHGUI_MeshPatternDlg::loadFromFile( const QString& theName )
\r
933 SMESH::SMESH_Pattern_var aPattern = SMESH::GetPattern();
\r
935 if ( !aPattern->LoadFromFile( theName.latin1() ) ||
\r
936 myType == Type_2d && !aPattern->Is2D())
\r
938 SMESH::SMESH_Pattern::ErrorCode aCode = aPattern->GetErrorCode();
\r
940 if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NB_POINTS ) aMess = tr( "ERR_READ_NB_POINTS" );
\r
941 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_POINT_COORDS ) aMess = tr( "ERR_READ_POINT_COORDS" );
\r
942 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_TOO_FEW_POINTS ) aMess = tr( "ERR_READ_TOO_FEW_POINTS" );
\r
943 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_3D_COORD ) aMess = tr( "ERR_READ_3D_COORD" );
\r
944 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_KEYPOINT ) aMess = tr( "ERR_READ_NO_KEYPOINT" );
\r
945 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_INDEX ) aMess = tr( "ERR_READ_BAD_INDEX" );
\r
946 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_ELEM_POINTS ) aMess = tr( "ERR_READ_ELEM_POINTS" );
\r
947 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_ELEMS ) aMess = tr( "ERR_READ_NO_ELEMS" );
\r
948 else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_KEY_POINT ) aMess = tr( "ERR_READ_BAD_KEY_POINT" );
\r
949 else aMess = tr( "ERROR_OF_LOADING" );
\r
951 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
952 tr( "SMESH_ERROR" ), aMess, QMessageBox::Ok );
\r
957 myPattern = aPattern;
\r
961 catch( const SALOME::SALOME_Exception& S_ex )
\r
963 QtCatchCorbaException( S_ex );
\r
964 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
965 tr( "SMESH_ERROR" ), tr( "ERROR_OF_LOADING" ), QMessageBox::Ok );
\r
970 //=======================================================================
\r
971 // name : SMESHGUI_MeshPatternDlg::onTypeChanged
\r
973 // Purpose : SLOT. Called when pattern type changed.
\r
974 // Change dialog's look and feel
\r
975 //=======================================================================
\r
976 void SMESHGUI_MeshPatternDlg::onTypeChanged( int theType )
\r
978 if ( myType == theType )
\r
984 myGeomObj[ Object ] = GEOM::GEOM_Object::_nil();
\r
985 myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();
\r
986 myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();
\r
987 myPattern = SMESH::GetPattern();
\r
989 myName->setText( "" );
\r
990 mySelEdit[ Object ]->setText( "" );
\r
991 mySelEdit[ Vertex1 ]->setText( "" );
\r
992 mySelEdit[ Vertex2 ]->setText( "" );
\r
994 if ( theType == Type_2d )
\r
996 mySelLbl [ Vertex2 ]->hide();
\r
997 mySelBtn [ Vertex2 ]->hide();
\r
998 mySelEdit[ Vertex2 ]->hide();
\r
999 myReverseChk->show();
\r
1000 myPicture2d->show();
\r
1001 myPicture3d->hide();
\r
1002 mySelLbl[ Object ]->setText( tr( "FACE" ) );
\r
1003 mySelLbl[ Vertex1 ]->setText( tr( "VERTEX" ) );
\r
1007 mySelLbl [ Vertex2 ]->show();
\r
1008 mySelBtn [ Vertex2 ]->show();
\r
1009 mySelEdit[ Vertex2 ]->show();
\r
1010 myReverseChk->hide();
\r
1011 myPicture2d->hide();
\r
1012 myPicture3d->show();
\r
1013 mySelLbl[ Object ]->setText( tr( "3D_BLOCK" ) );
\r
1014 mySelLbl[ Vertex1 ]->setText( tr( "VERTEX1" ) );
\r
1015 mySelLbl[ Vertex2 ]->setText( tr( "VERTEX2" ) );
\r
1018 mySelInput = Mesh;
\r
1019 activateSelection();
\r
1024 //=======================================================================
\r
1025 // name : SMESHGUI_MeshPatternDlg::getGrid
\r
1026 // Purpose : Get unstructured grid for pattern
\r
1027 //=======================================================================
\r
1028 vtkUnstructuredGrid* SMESHGUI_MeshPatternDlg::getGrid()
\r
1032 // Get points from pattern
\r
1033 SMESH::point_array_var pnts = myType == Type_2d
\r
1034 ? myPattern->ApplyToFace( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() )
\r
1035 : myPattern->ApplyTo3DBlock( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] );
\r
1037 SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints();
\r
1039 if ( pnts->length() == 0 || elemPoints->length() == 0 )
\r
1044 // to do : to be removed /////////////////////////////////////////////
\r
1047 for ( int i1 = 0, n1 = pnts->length(); i1 < n1; i1++ )
\r
1048 printf( "%d: %g %g %g\n", i1, pnts[ i1 ].x, pnts[ i1 ].y, pnts[ i1 ].z );
\r
1050 printf( "\nELEMENTS : \n" );
\r
1051 for ( int i2 = 0, n2 = elemPoints->length(); i2 < n2; i2++ )
\r
1054 printf( "%d: ", i2 );
\r
1055 for ( int i3 = 0, n3 = elemPoints[ i2 ].length(); i3 < n3; i3++ )
\r
1056 printf( "%d ", elemPoints[ i2 ][ i3 ] );
\r
1062 //////////////////////////////////////////////////////////////////////
\r
1064 // Calculate number of points used for cell
\r
1065 vtkIdType aNbCells = elemPoints->length();
\r
1066 vtkIdType aCellsSize = 0;
\r
1067 for ( int i = 0, n = elemPoints->length(); i < n; i++ )
\r
1068 aCellsSize += elemPoints[ i ].length();
\r
1070 // Create unstructured grid and other usefull arrays
\r
1071 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
\r
1073 vtkCellArray* aConnectivity = vtkCellArray::New();
\r
1074 aConnectivity->Allocate( aCellsSize, 0 );
\r
1076 vtkPoints* aPoints = vtkPoints::New();
\r
1077 aPoints->SetNumberOfPoints( pnts->length() );
\r
1079 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
\r
1080 aCellTypesArray->SetNumberOfComponents( 1 );
\r
1081 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
\r
1083 vtkIdList *anIdList = vtkIdList::New();
\r
1085 // Fill array of points
\r
1086 for ( int p = 0, nbPnt = pnts->length(); p < nbPnt; p++ )
\r
1087 aPoints->SetPoint( p, pnts[ p ].x, pnts[ p ].y, pnts[ p ].z );
\r
1089 for ( int e = 0, nbElem = elemPoints->length(); e < nbElem; e++ )
\r
1091 int nbPoints = elemPoints[ e ].length();
\r
1092 anIdList->SetNumberOfIds( nbPoints );
\r
1093 for ( int i = 0; i < nbPoints; i++ )
\r
1094 anIdList->SetId( i, elemPoints[ e ][ i ] );
\r
1096 aConnectivity->InsertNextCell( anIdList );
\r
1098 if ( nbPoints == 3 ) aCellTypesArray->InsertNextValue( VTK_TRIANGLE );
\r
1099 else if ( nbPoints == 5 ) aCellTypesArray->InsertNextValue( VTK_PYRAMID );
\r
1100 else if ( nbPoints == 6 ) aCellTypesArray->InsertNextValue( VTK_WEDGE );
\r
1101 else if ( nbPoints == 8 ) aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
\r
1102 else if ( nbPoints == 4 && myType == Type_2d ) aCellTypesArray->InsertNextValue( VTK_QUAD );
\r
1103 else if ( nbPoints == 4 && myType == Type_3d ) aCellTypesArray->InsertNextValue( VTK_TETRA );
\r
1104 else aCellTypesArray->InsertNextValue( VTK_EMPTY_CELL );
\r
1107 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
\r
1108 aCellLocationsArray->SetNumberOfComponents( 1 );
\r
1109 aCellLocationsArray->SetNumberOfTuples( aNbCells );
\r
1111 aConnectivity->InitTraversal();
\r
1112 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
\r
1113 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
\r
1115 aGrid->SetPoints( aPoints );
\r
1116 aGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
\r
1118 aConnectivity->Delete();
\r
1119 aPoints->Delete();
\r
1120 aCellTypesArray->Delete();
\r
1121 anIdList->Delete();
\r
1122 aCellLocationsArray->Delete();
\r