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_CreatePatternDlg.cxx
\r
25 // Author : Sergey LITONIN
\r
28 #include "SMESHGUI_CreatePatternDlg.h"
\r
30 #include "QAD_Desktop.h"
\r
31 #include "QAD_FileDlg.h"
\r
33 #include "SMESHGUI_PatternWidget.h"
\r
34 #include "SMESHGUI_SpinBox.h"
\r
35 #include "SMESHGUI.h"
\r
36 #include "SALOME_Selection.h"
\r
37 #include "SALOME_ListIteratorOfListOfFilter.hxx"
\r
38 #include "SALOMEGUI_QtCatchCorbaException.hxx"
\r
39 #include "SMESH_NumberFilter.hxx"
\r
40 #include "SMESHGUI_Utils.h"
\r
41 #include "SMESHGUI_VTKUtils.h"
\r
42 #include "SMESHGUI_PatternUtils.h"
\r
44 #include <TColStd_MapOfInteger.hxx>
\r
47 #include <qlayout.h>
\r
48 #include <qlineedit.h>
\r
49 #include <qpushbutton.h>
\r
50 #include <qgroupbox.h>
\r
52 #include <qradiobutton.h>
\r
53 #include <qcheckbox.h>
\r
54 #include <qbuttongroup.h>
\r
55 #include <qmessagebox.h>
\r
56 #include <qapplication.h>
\r
62 Class : SMESHGUI_CreatePatternDlg
\r
63 Description : Dialog to specify filters for VTK viewer
\r
66 //=======================================================================
\r
67 // name : SMESHGUI_CreatePatternDlg::SMESHGUI_CreatePatternDlg
\r
68 // Purpose : Constructor
\r
69 //=======================================================================
\r
70 SMESHGUI_CreatePatternDlg::SMESHGUI_CreatePatternDlg( QWidget* theParent,
\r
71 SALOME_Selection* theSelection,
\r
73 const char* theName )
\r
74 : QDialog( theParent, theName, false,
\r
75 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
\r
77 setCaption( tr( "CAPTION" ) );
\r
79 QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING );
\r
81 QFrame* aMainFrame = createMainFrame ( this );
\r
82 QFrame* aBtnFrame = createButtonFrame( this );
\r
84 aDlgLay->addWidget( aMainFrame );
\r
85 aDlgLay->addWidget( aBtnFrame );
\r
87 aDlgLay->setStretchFactor( aMainFrame, 1 );
\r
89 Init( theSelection, theType );
\r
92 //=======================================================================
\r
93 // name : SMESHGUI_CreatePatternDlg::createMainFrame
\r
94 // Purpose : Create frame containing dialog's input fields
\r
95 //=======================================================================
\r
96 QFrame* SMESHGUI_CreatePatternDlg::createMainFrame( QWidget* theParent )
\r
98 QPixmap iconSlct( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
\r
99 QPixmap icon2d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) );
\r
100 QPixmap icon3d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) );
\r
102 QPixmap iconSample2d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) );
\r
104 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, theParent );
\r
105 aMainGrp->setFrameStyle( QFrame::NoFrame );
\r
106 aMainGrp->setInsideMargin( 0 );
\r
108 // Pattern type group
\r
110 myTypeGrp = new QButtonGroup( 1, Qt::Vertical, tr( "PATTERN_TYPE" ), aMainGrp );
\r
111 mySwitch2d = new QRadioButton( myTypeGrp );
\r
112 mySwitch3d = new QRadioButton( myTypeGrp );
\r
113 mySwitch2d->setPixmap( icon2d );
\r
114 mySwitch3d->setPixmap( icon3d );
\r
115 myTypeGrp->insert( mySwitch2d, Type_2d );
\r
116 myTypeGrp->insert( mySwitch3d, Type_3d );
\r
118 QGroupBox* aPatternGrp = new QGroupBox( 1, Qt::Horizontal, tr( "PATTERN" ), aMainGrp );
\r
120 // Mesh and pattern name group
\r
122 QGroupBox* aMeshGrp = new QGroupBox( 1, Qt::Vertical, aPatternGrp );
\r
123 aMeshGrp->setFrameStyle( QFrame::NoFrame );
\r
124 aMeshGrp->setInsideMargin( 0 );
\r
126 new QLabel( tr( "MESH_OR_SUBMESH" ), aMeshGrp );
\r
128 QPushButton* aSelBtn = new QPushButton( aMeshGrp );
\r
129 aSelBtn->setPixmap( iconSlct );
\r
130 myMeshEdit = new QLineEdit( aMeshGrp );
\r
131 myMeshEdit->setReadOnly( true );
\r
133 QGroupBox* aPattGrp = new QGroupBox( 1, Qt::Vertical, aPatternGrp );
\r
134 aPattGrp->setFrameStyle( QFrame::NoFrame );
\r
135 aPattGrp->setInsideMargin( 0 );
\r
137 new QLabel( tr( "PATTERN_NAME" ), aPattGrp );
\r
138 myName = new QLineEdit( aPattGrp );
\r
142 myPicture2d = new SMESHGUI_PatternWidget( aPatternGrp ),
\r
143 myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
\r
145 // Project check box
\r
147 myProjectChk = new QCheckBox( tr( "PROJECT" ), aPatternGrp );
\r
149 // Connect signals and slots
\r
151 connect( myTypeGrp, SIGNAL( clicked( int ) ), SLOT( onTypeChanged( int ) ) );
\r
152 connect( myProjectChk, SIGNAL( toggled( bool ) ), SLOT( onProject( bool ) ) );
\r
153 connect( aSelBtn, SIGNAL( clicked() ), SLOT( onSelBtnClicked() ) );
\r
158 //=======================================================================
\r
159 // name : SMESHGUI_CreatePatternDlg::createButtonFrame
\r
160 // Purpose : Create frame containing buttons
\r
161 //=======================================================================
\r
162 QFrame* SMESHGUI_CreatePatternDlg::createButtonFrame( QWidget* theParent )
\r
164 QFrame* aFrame = new QFrame( theParent );
\r
165 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
\r
167 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), aFrame );
\r
168 mySaveBtn = new QPushButton( tr( "SAVE" ), aFrame );
\r
169 myCloseBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), aFrame );
\r
171 QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
\r
173 QHBoxLayout* aLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
\r
175 aLay->addWidget( myOkBtn );
\r
176 aLay->addWidget( mySaveBtn );
\r
177 aLay->addItem( aSpacer);
\r
178 aLay->addWidget( myCloseBtn );
\r
180 connect( myOkBtn, SIGNAL( clicked() ), SLOT( onOk() ) );
\r
181 connect( myCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) ) ;
\r
182 connect( mySaveBtn, SIGNAL( clicked() ), SLOT( onSave() ) );
\r
187 //=======================================================================
\r
188 // name : SMESHGUI_CreatePatternDlg::~SMESHGUI_CreatePatternDlg
\r
189 // Purpose : Destructor
\r
190 //=======================================================================
\r
191 SMESHGUI_CreatePatternDlg::~SMESHGUI_CreatePatternDlg()
\r
195 //=======================================================================
\r
196 // name : SMESHGUI_CreatePatternDlg::onProject
\r
197 // Purpose : SLOT. Called when state of "Project nodes on ther face"
\r
198 // checkbox is changed
\r
199 //=======================================================================
\r
200 void SMESHGUI_CreatePatternDlg::onProject( bool )
\r
202 loadFromObject( false );
\r
206 //=======================================================================
\r
207 // name : SMESHGUI_CreatePatternDlg::Init
\r
208 // Purpose : Init dialog fields, connect signals and slots, show dialog
\r
209 //=======================================================================
\r
210 void SMESHGUI_CreatePatternDlg::Init( SALOME_Selection* theSelection, const int theType )
\r
212 myIsLoaded = false;
\r
215 mySelection = theSelection;
\r
216 mySubMesh = SMESH::SMESH_subMesh::_nil();
\r
217 myMesh = SMESH::SMESH_Mesh::_nil();
\r
218 myGeomObj = GEOM::GEOM_Object::_nil();
\r
219 myPattern = SMESH::SMESH_Pattern::_nil();
\r
223 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
\r
224 aSMESHGUI->SetActiveDialogBox( ( QDialog* )this );
\r
226 // selection and SMESHGUI
\r
227 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
\r
228 connect( aSMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) );
\r
229 connect( aSMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) );
\r
231 mySwitch2d->setEnabled( theType == Type_2d );
\r
232 mySwitch3d->setEnabled( theType == Type_3d );
\r
234 if ( theType == Type_2d )
\r
235 myProjectChk->show();
\r
237 myProjectChk->hide();
\r
239 myTypeGrp->setButton( theType );
\r
240 onTypeChanged( theType );
\r
242 myName->setText( getDefaultName() );
\r
243 myMeshEdit->setText( "" );
\r
245 setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) );
\r
246 qApp->processEvents();
\r
248 myPicture2d->updateGeometry();
\r
250 resize( minimumSize() );
\r
252 activateSelection();
\r
256 aSMESHGUI->DefineDlgPosition( this, x, y );
\r
257 this->move( x, y );
\r
261 //=======================================================================
\r
262 // name : SMESHGUI_CreatePatternDlg::SetMesh
\r
263 // Purpose : Set mesh to dialog
\r
264 //=======================================================================
\r
265 void SMESHGUI_CreatePatternDlg::SetMesh( SMESH::SMESH_Mesh_ptr thePtr )
\r
267 myMesh = SMESH::SMESH_Mesh::_duplicate( thePtr );
\r
268 mySubMesh = SMESH::SMESH_subMesh::_nil();
\r
270 bool isValidMesh = false;
\r
271 if ( !myMesh->_is_nil() )
\r
273 SALOMEDS::SObject_var aSobj = SMESH::FindSObject( thePtr );
\r
274 CORBA::String_var anEntry = aSobj->GetID();
\r
275 Handle(SALOME_InteractiveObject) anIObj =
\r
276 new SALOME_InteractiveObject( anEntry.in(), "SMESH" );
\r
278 const SALOME_ListOfFilter& aList = mySelection->StoredFilters();
\r
279 SALOME_ListIteratorOfListOfFilter anIter( aList );
\r
280 for ( ; anIter.More(); anIter.Next() )
\r
281 if ( !anIter.Value()->IsOk( anIObj ) )
\r
284 if ( !anIter.More() )
\r
285 isValidMesh = true;
\r
291 SALOMEDS::SObject_var aSO = SMESH::FindSObject( myMesh.in() );
\r
292 myMeshEdit->setText( aSO->GetName() );
\r
293 myGeomObj = getGeom( aSO );
\r
297 myMeshEdit->setText( "" );
\r
298 myGeomObj = GEOM::GEOM_Object::_nil();
\r
301 if ( myType == Type_2d )
\r
303 loadFromObject( false );
\r
308 //=======================================================================
\r
309 // name : SMESHGUI_CreatePatternDlg::isValid
\r
310 // Purpose : Verify validity of entry data
\r
311 //=======================================================================
\r
312 bool SMESHGUI_CreatePatternDlg::isValid()
\r
314 if ( myGeomObj->_is_nil() )
\r
316 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
317 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SMESHGUI_INVALID_PARAMETERS" ), QMessageBox::Ok );
\r
326 //=======================================================================
\r
327 // name : SMESHGUI_CreatePatternDlg::getDefaultName
\r
328 // Purpose : Get default pattern name
\r
329 //=======================================================================
\r
330 QString SMESHGUI_CreatePatternDlg::getDefaultName() const
\r
332 return myType == Type_2d ? tr( "DEFAULT_2D" ) : tr( "DEFAULT_3D" );
\r
335 //=======================================================================
\r
336 // name : SMESHGUI_CreatePatternDlg::onSave
\r
337 // Purpose : SLOT called when "Save" button pressed. Build pattern and
\r
340 //=======================================================================
\r
341 void SMESHGUI_CreatePatternDlg::onSave()
\r
349 loadFromObject( true );
\r
351 // Load pattern from object
\r
355 ///////////////////////////////////////////////////////
\r
356 QAD_FileDlg* aDlg = new QAD_FileDlg( this, false );
\r
357 aDlg->setCaption( tr( "SAVE_PATTERN" ) );
\r
358 aDlg->setMode( QFileDialogP::AnyFile );
\r
359 aDlg->setFilters( tr( "PATTERN_FILT" ) );
\r
360 if ( myName->text() != "" )
\r
361 aDlg->setSelection( myName->text() );
\r
363 if ( aDlg->exec() != Accepted )
\r
366 QString fName = aDlg->selectedFile();
\r
367 if ( fName.isEmpty() )
\r
370 if ( QFileInfo( fName ).extension().isEmpty() )
\r
371 fName = autoExtension( fName );
\r
373 fName = QDir::convertSeparators( fName );
\r
375 QString aData( myPattern->GetString() );
\r
376 long aLen = aData.length();
\r
378 QFile aFile( fName );
\r
379 aFile.open( IO_WriteOnly );
\r
380 long aWritten = aFile.writeBlock( aData, aLen );
\r
383 if ( aWritten != aLen )
\r
385 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
386 tr( "SMESH_ERROR" ), tr( "ERROR_OF_SAVING" ), QMessageBox::Ok );
\r
390 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
391 disconnect( mySelection, 0, this, 0 );
\r
392 disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );
\r
393 SMESHGUI::GetSMESHGUI()->ResetState();
\r
398 catch( const SALOME::SALOME_Exception& S_ex )
\r
400 QtCatchCorbaException( S_ex );
\r
407 //=======================================================================
\r
408 // name : SMESHGUI_CreatePatternDlg::GetPatternName
\r
409 // Purpose : Get name of pattern
\r
410 //=======================================================================
\r
411 QString SMESHGUI_CreatePatternDlg::GetPatternName() const
\r
413 return myName->text();
\r
416 //=======================================================================
\r
417 // name : SMESHGUI_CreatePatternDlg::GetPattern
\r
418 // Purpose : Get result pattern
\r
419 //=======================================================================
\r
420 SMESH::SMESH_Pattern_ptr SMESHGUI_CreatePatternDlg::GetPattern()
\r
422 return myPattern.in();
\r
425 //=======================================================================
\r
426 // name : SMESHGUI_CreatePatternDlg::onOk
\r
427 // Purpose : SLOT called when "Ok" button pressed.
\r
428 //=======================================================================
\r
429 void SMESHGUI_CreatePatternDlg::onOk()
\r
437 loadFromObject( true );
\r
439 // Load pattern from object
\r
444 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
445 disconnect( mySelection, 0, this, 0 );
\r
446 disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );
\r
447 SMESHGUI::GetSMESHGUI()->ResetState();
\r
452 catch( const SALOME::SALOME_Exception& S_ex )
\r
454 QtCatchCorbaException( S_ex );
\r
461 //=======================================================================
\r
462 // name : SMESHGUI_CreatePatternDlg::onClose
\r
463 // Purpose : SLOT called when "Close" button pressed. Close dialog
\r
464 //=======================================================================
\r
465 void SMESHGUI_CreatePatternDlg::onClose()
\r
467 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
468 disconnect( mySelection, 0, this, 0 );
\r
469 disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );
\r
470 SMESHGUI::GetSMESHGUI()->ResetState();
\r
475 //=======================================================================
\r
476 // name : SMESHGUI_CreatePatternDlg::loadFromObject
\r
477 // Purpose : Load pattern from geom object corresponding to the mesh/submesh
\r
478 //=======================================================================
\r
479 bool SMESHGUI_CreatePatternDlg::loadFromObject( const bool theMess )
\r
483 myIsLoaded = false;
\r
485 if ( myPattern->_is_nil() )
\r
486 myPattern = SMESH::GetPattern();
\r
488 if ( myMesh->_is_nil() && mySubMesh->_is_nil() || myGeomObj->_is_nil() )
\r
491 SMESH::SMESH_Mesh_ptr aMesh = mySubMesh->_is_nil() ? myMesh.in() : mySubMesh->GetFather();
\r
493 myIsLoaded = myType == Type_2d
\r
494 ? myPattern->LoadFromFace( aMesh, myGeomObj, myProjectChk->isChecked() )
\r
495 : myPattern->LoadFrom3DBlock( aMesh, myGeomObj );
\r
497 if ( !myIsLoaded && theMess )
\r
500 SMESH::SMESH_Pattern::ErrorCode aCode = myPattern->GetErrorCode();
\r
502 if ( aCode == SMESH::SMESH_Pattern::ERR_LOAD_EMPTY_SUBMESH ) aMess = tr( "ERR_LOAD_EMPTY_SUBMESH" );
\r
503 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_NARROW_FACE ) aMess = tr( "ERR_LOADF_NARROW_FACE" );
\r
504 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_CLOSED_FACE ) aMess = tr( "ERR_LOADF_CLOSED_FACE" );
\r
505 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADV_BAD_SHAPE ) aMess = tr( "ERR_LOADV_BAD_SHAPE" );
\r
506 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADV_COMPUTE_PARAMS ) aMess = tr( "ERR_LOADV_COMPUTE_PARAMS" );
\r
507 else aMess = tr( "ERROR_OF_CREATION" );
\r
509 QMessageBox::information(
\r
510 SMESHGUI::GetSMESHGUI()->GetDesktop(), tr( "SMESH_ERROR" ), aMess, QMessageBox::Ok );
\r
514 catch( const SALOME::SALOME_Exception& S_ex )
\r
516 QtCatchCorbaException( S_ex );
\r
522 //=======================================================================
\r
523 // name : SMESHGUI_CreatePatternDlg::getGeom
\r
524 // Purpose : Retrieve geom object from SObject
\r
525 //=======================================================================
\r
526 GEOM::GEOM_Object_ptr SMESHGUI_CreatePatternDlg::getGeom( SALOMEDS::SObject_ptr theSO )
\r
528 if ( theSO->_is_nil() )
\r
529 return GEOM::GEOM_Object::_nil();
\r
531 SALOMEDS::Study_var aStudy =
\r
532 SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getStudyDocument();
\r
534 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSO );
\r
535 for( ; anIter->More(); anIter->Next() )
\r
537 SALOMEDS::SObject_var aSO = anIter->Value();
\r
538 SALOMEDS::SObject_var aRefSO;
\r
540 GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(
\r
541 aSO->ReferencedObject( aRefSO )? aRefSO->GetObject() : aSO->GetObject() );
\r
543 if ( !aMeshShape->_is_nil() )
\r
544 return aMeshShape._retn();
\r
546 return GEOM::GEOM_Object::_nil();
\r
549 //=======================================================================
\r
550 // name : SMESHGUI_CreatePatternDlg::onSelectionDone
\r
551 // Purpose : SLOT called when selection changed
\r
552 //=======================================================================
\r
553 void SMESHGUI_CreatePatternDlg::onSelectionDone()
\r
557 if ( mySelection->IObjectCount() != 1 )
\r
560 // Get mesh or sub-mesh from selection
\r
561 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
\r
562 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIO );
\r
563 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>( anIO );
\r
564 if ( aMesh->_is_nil() && aSubMesh->_is_nil() )
\r
567 // Get geom object corresponding to the mesh
\r
568 SALOMEDS::SObject_var aSO;
\r
569 if ( !aMesh->_is_nil() )
\r
570 aSO = SMESH::FindSObject( aMesh.in() );
\r
572 aSO = SMESH::FindSObject( aSubMesh.in() );
\r
575 GEOM::GEOM_Object_var aGeomObj = getGeom( aSO );
\r
576 if ( aGeomObj->_is_nil() )
\r
579 myGeomObj = aGeomObj;
\r
581 // init class fields
\r
582 if ( !aMesh->_is_nil() )
\r
585 mySubMesh = SMESH::SMESH_subMesh::_nil();
\r
589 mySubMesh = aSubMesh;
\r
590 myMesh = SMESH::SMESH_Mesh::_nil();
\r
594 SMESH::GetNameOfSelectedIObjects( mySelection, aName );
\r
595 myMeshEdit->setText( aName );
\r
597 if ( myType == Type_2d )
\r
599 loadFromObject( true );
\r
605 myMesh = SMESH::SMESH_Mesh::_nil();
\r
606 mySubMesh = SMESH::SMESH_subMesh::_nil();
\r
607 myGeomObj = GEOM::GEOM_Object::_nil();
\r
612 //=======================================================================
\r
613 // name : SMESHGUI_CreatePatternDlg::onDeactivate
\r
614 // Purpose : SLOT called when dialog must be deativated
\r
615 //=======================================================================
\r
616 void SMESHGUI_CreatePatternDlg::onDeactivate()
\r
618 disconnect( mySelection, 0, this, 0 );
\r
619 setEnabled( false );
\r
622 //=======================================================================
\r
623 // name : SMESHGUI_CreatePatternDlg::enterEvent
\r
624 // Purpose : Event filter
\r
625 //=======================================================================
\r
626 void SMESHGUI_CreatePatternDlg::enterEvent( QEvent* )
\r
628 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
\r
629 setEnabled( true );
\r
630 activateSelection();
\r
631 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
\r
635 //=================================================================================
\r
636 // function : closeEvent()
\r
637 // purpose : Close dialog box
\r
638 //=================================================================================
\r
639 void SMESHGUI_CreatePatternDlg::closeEvent( QCloseEvent* e )
\r
644 //=======================================================================
\r
645 // name : SMESHGUI_CreatePatternDlg::onSelBtnClicked
\r
646 // Purpose : SLOT. Called when -> button clicked.
\r
647 //=======================================================================
\r
648 void SMESHGUI_CreatePatternDlg::onSelBtnClicked()
\r
653 //================================================================
\r
654 // Function : SMESHGUI_CreatePatternDlg::autoExtension
\r
655 // Purpose : Append extension to the file name
\r
656 //================================================================
\r
657 QString SMESHGUI_CreatePatternDlg::autoExtension( const QString& theFileName ) const
\r
659 QString anExt = theFileName.section( '.', -1 );
\r
660 return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName;
\r
663 //=======================================================================
\r
664 // name : SMESHGUI_CreatePatternDlg::displayPreview
\r
665 // Purpose : Display preview
\r
666 //=======================================================================
\r
667 void SMESHGUI_CreatePatternDlg::displayPreview()
\r
670 // Redisplay preview in dialog
\r
678 SMESH::point_array_var pnts = myPattern->GetPoints();
\r
679 SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
\r
680 SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints(false);
\r
682 if ( pnts->length() == 0 ||
\r
683 keyPoints->length() == 0 ||
\r
684 elemPoints->length() == 0 )
\r
686 myIsLoaded = false;
\r
691 PointVector aPoints( pnts->length() );
\r
692 QValueVector<int> aKeyPoints( keyPoints->length() );
\r
693 ConnectivityVector anElemPoints( elemPoints->length() );
\r
695 for ( int i = 0, n = pnts->length(); i < n; i++ )
\r
696 aPoints[ i ] = pnts[ i ];
\r
698 for ( int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++ )
\r
699 aKeyPoints[ i2 ] = keyPoints[ i2 ];
\r
701 for ( int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++ )
\r
703 QValueVector<int> aVec( elemPoints[ i3 ].length() );
\r
704 for ( int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++ )
\r
705 aVec[ i4 ] = elemPoints[ i3 ][ i4 ];
\r
707 anElemPoints[ i3 ] = aVec;
\r
710 myPicture2d->SetPoints( aPoints, aKeyPoints, anElemPoints );
\r
715 catch( const SALOME::SALOME_Exception& S_ex )
\r
717 QtCatchCorbaException( S_ex );
\r
725 //=======================================================================
\r
726 // name : SMESHGUI_CreatePatternDlg::erasePreview
\r
727 // Purpose : Erase preview
\r
728 //=======================================================================
\r
729 void SMESHGUI_CreatePatternDlg::erasePreview()
\r
732 // Erase preview in 2D viewer
\r
733 myPicture2d->SetPoints( PointVector(), QValueVector<int>(), ConnectivityVector() );
\r
736 //=======================================================================
\r
737 // name : SMESHGUI_CreatePatternDlg::activateSelection
\r
738 // Purpose : Activate selection in accordance with current pattern type
\r
739 //=======================================================================
\r
740 void SMESHGUI_CreatePatternDlg::activateSelection()
\r
742 mySelection->ClearFilters();
\r
743 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
745 if ( myType == Type_2d )
\r
747 mySelection->AddFilter(
\r
748 new SMESH_NumberFilter( "SMESH", TopAbs_SHAPE, -1, TopAbs_FACE ) );
\r
752 TColStd_MapOfInteger aTypes;
\r
753 aTypes.Add( TopAbs_SHELL );
\r
754 aTypes.Add( TopAbs_SOLID );
\r
755 mySelection->AddFilter( new SMESH_NumberFilter(
\r
756 "SMESH", TopAbs_FACE, 6, aTypes, GEOM::GEOM_Object::_nil(), true ) );
\r
760 //=======================================================================
\r
761 // name : SMESHGUI_CreatePatternDlg::onTypeChanged
\r
762 // Purpose : SLOT. Called when pattern type changed.
\r
763 // Change dialog's look and feel
\r
764 //=======================================================================
\r
765 void SMESHGUI_CreatePatternDlg::onTypeChanged( int theType )
\r
767 if ( myType == theType )
\r
772 if ( theType == Type_2d )
\r
773 myPicture2d->show();
\r
775 myPicture2d->hide();
\r