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 "SMESHGUI.h"
\r
31 #include "SMESHGUI_Utils.h"
\r
32 #include "SMESHGUI_VTKUtils.h"
\r
33 #include "SMESHGUI_PatternUtils.h"
\r
34 #include "SMESHGUI_PatternWidget.h"
\r
36 #include "SMESH_NumberFilter.hxx"
\r
38 #include "SALOME_Selection.h"
\r
39 #include "SALOME_ListIteratorOfListOfFilter.hxx"
\r
40 #include "SALOMEGUI_QtCatchCorbaException.hxx"
\r
42 #include "QAD_Desktop.h"
\r
43 #include "QAD_FileDlg.h"
\r
45 #include <TColStd_MapOfInteger.hxx>
\r
48 #include <qlayout.h>
\r
49 #include <qlineedit.h>
\r
50 #include <qpushbutton.h>
\r
51 #include <qgroupbox.h>
\r
53 #include <qradiobutton.h>
\r
54 #include <qcheckbox.h>
\r
55 #include <qbuttongroup.h>
\r
56 #include <qmessagebox.h>
\r
57 #include <qapplication.h>
\r
63 Class : SMESHGUI_CreatePatternDlg
\r
64 Description : Dialog to specify filters for VTK viewer
\r
67 //=======================================================================
\r
68 // name : SMESHGUI_CreatePatternDlg::SMESHGUI_CreatePatternDlg
\r
69 // Purpose : Constructor
\r
70 //=======================================================================
\r
71 SMESHGUI_CreatePatternDlg::SMESHGUI_CreatePatternDlg( QWidget* theParent,
\r
72 SALOME_Selection* theSelection,
\r
74 const char* theName )
\r
75 : QDialog( theParent, theName, false,
\r
76 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
\r
78 setCaption( tr( "CAPTION" ) );
\r
80 QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING );
\r
82 QFrame* aMainFrame = createMainFrame ( this );
\r
83 QFrame* aBtnFrame = createButtonFrame( this );
\r
85 aDlgLay->addWidget( aMainFrame );
\r
86 aDlgLay->addWidget( aBtnFrame );
\r
88 aDlgLay->setStretchFactor( aMainFrame, 1 );
\r
90 Init( theSelection, theType );
\r
93 //=======================================================================
\r
94 // name : SMESHGUI_CreatePatternDlg::createMainFrame
\r
95 // Purpose : Create frame containing dialog's input fields
\r
96 //=======================================================================
\r
97 QFrame* SMESHGUI_CreatePatternDlg::createMainFrame( QWidget* theParent )
\r
99 QPixmap iconSlct( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
\r
100 QPixmap icon2d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) );
\r
101 QPixmap icon3d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) );
\r
103 QPixmap iconSample2d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) );
\r
105 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, theParent );
\r
106 aMainGrp->setFrameStyle( QFrame::NoFrame );
\r
107 aMainGrp->setInsideMargin( 0 );
\r
109 // Pattern type group
\r
111 myTypeGrp = new QButtonGroup( 1, Qt::Vertical, tr( "PATTERN_TYPE" ), aMainGrp );
\r
112 mySwitch2d = new QRadioButton( myTypeGrp );
\r
113 mySwitch3d = new QRadioButton( myTypeGrp );
\r
114 mySwitch2d->setPixmap( icon2d );
\r
115 mySwitch3d->setPixmap( icon3d );
\r
116 myTypeGrp->insert( mySwitch2d, Type_2d );
\r
117 myTypeGrp->insert( mySwitch3d, Type_3d );
\r
119 QGroupBox* aPatternGrp = new QGroupBox( 1, Qt::Horizontal, tr( "PATTERN" ), aMainGrp );
\r
121 // Mesh and pattern name group
\r
123 QGroupBox* aMeshGrp = new QGroupBox( 1, Qt::Vertical, aPatternGrp );
\r
124 aMeshGrp->setFrameStyle( QFrame::NoFrame );
\r
125 aMeshGrp->setInsideMargin( 0 );
\r
127 new QLabel( tr( "MESH_OR_SUBMESH" ), aMeshGrp );
\r
129 QPushButton* aSelBtn = new QPushButton( aMeshGrp );
\r
130 aSelBtn->setPixmap( iconSlct );
\r
131 myMeshEdit = new QLineEdit( aMeshGrp );
\r
132 myMeshEdit->setReadOnly( true );
\r
134 QGroupBox* aPattGrp = new QGroupBox( 1, Qt::Vertical, aPatternGrp );
\r
135 aPattGrp->setFrameStyle( QFrame::NoFrame );
\r
136 aPattGrp->setInsideMargin( 0 );
\r
138 new QLabel( tr( "PATTERN_NAME" ), aPattGrp );
\r
139 myName = new QLineEdit( aPattGrp );
\r
143 myPicture2d = new SMESHGUI_PatternWidget( aPatternGrp ),
\r
144 myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
\r
146 // Project check box
\r
148 myProjectChk = new QCheckBox( tr( "PROJECT" ), aPatternGrp );
\r
150 // Connect signals and slots
\r
152 connect( myTypeGrp, SIGNAL( clicked( int ) ), SLOT( onTypeChanged( int ) ) );
\r
153 connect( myProjectChk, SIGNAL( toggled( bool ) ), SLOT( onProject( bool ) ) );
\r
154 connect( aSelBtn, SIGNAL( clicked() ), SLOT( onSelBtnClicked() ) );
\r
159 //=======================================================================
\r
160 // name : SMESHGUI_CreatePatternDlg::createButtonFrame
\r
161 // Purpose : Create frame containing buttons
\r
162 //=======================================================================
\r
163 QFrame* SMESHGUI_CreatePatternDlg::createButtonFrame( QWidget* theParent )
\r
165 QFrame* aFrame = new QFrame( theParent );
\r
166 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
\r
168 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), aFrame );
\r
169 mySaveBtn = new QPushButton( tr( "SAVE" ), aFrame );
\r
170 myCloseBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), aFrame );
\r
172 QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
\r
174 QHBoxLayout* aLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
\r
176 aLay->addWidget( myOkBtn );
\r
177 aLay->addWidget( mySaveBtn );
\r
178 aLay->addItem( aSpacer);
\r
179 aLay->addWidget( myCloseBtn );
\r
181 connect( myOkBtn, SIGNAL( clicked() ), SLOT( onOk() ) );
\r
182 connect( myCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) ) ;
\r
183 connect( mySaveBtn, SIGNAL( clicked() ), SLOT( onSave() ) );
\r
188 //=======================================================================
\r
189 // name : SMESHGUI_CreatePatternDlg::~SMESHGUI_CreatePatternDlg
\r
190 // Purpose : Destructor
\r
191 //=======================================================================
\r
192 SMESHGUI_CreatePatternDlg::~SMESHGUI_CreatePatternDlg()
\r
196 //=======================================================================
\r
197 // name : SMESHGUI_CreatePatternDlg::onProject
\r
198 // Purpose : SLOT. Called when state of "Project nodes on ther face"
\r
199 // checkbox is changed
\r
200 //=======================================================================
\r
201 void SMESHGUI_CreatePatternDlg::onProject( bool )
\r
203 loadFromObject( false );
\r
207 //=======================================================================
\r
208 // name : SMESHGUI_CreatePatternDlg::Init
\r
209 // Purpose : Init dialog fields, connect signals and slots, show dialog
\r
210 //=======================================================================
\r
211 void SMESHGUI_CreatePatternDlg::Init( SALOME_Selection* theSelection, const int theType )
\r
213 myIsLoaded = false;
\r
216 mySelection = theSelection;
\r
217 mySubMesh = SMESH::SMESH_subMesh::_nil();
\r
218 myMesh = SMESH::SMESH_Mesh::_nil();
\r
219 myGeomObj = GEOM::GEOM_Object::_nil();
\r
220 myPattern = SMESH::SMESH_Pattern::_nil();
\r
224 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
\r
225 aSMESHGUI->SetActiveDialogBox( ( QDialog* )this );
\r
227 // selection and SMESHGUI
\r
228 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
\r
229 connect( aSMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) );
\r
230 connect( aSMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) );
\r
232 mySwitch2d->setEnabled( theType == Type_2d );
\r
233 mySwitch3d->setEnabled( theType == Type_3d );
\r
235 if ( theType == Type_2d )
\r
236 myProjectChk->show();
\r
238 myProjectChk->hide();
\r
240 myTypeGrp->setButton( theType );
\r
241 onTypeChanged( theType );
\r
243 myName->setText( getDefaultName() );
\r
244 myMeshEdit->setText( "" );
\r
246 setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) );
\r
247 qApp->processEvents();
\r
249 myPicture2d->updateGeometry();
\r
251 resize( minimumSize() );
\r
253 activateSelection();
\r
257 aSMESHGUI->DefineDlgPosition( this, x, y );
\r
258 this->move( x, y );
\r
262 //=======================================================================
\r
263 // name : SMESHGUI_CreatePatternDlg::SetMesh
\r
264 // Purpose : Set mesh to dialog
\r
265 //=======================================================================
\r
266 void SMESHGUI_CreatePatternDlg::SetMesh( SMESH::SMESH_Mesh_ptr thePtr )
\r
268 myMesh = SMESH::SMESH_Mesh::_duplicate( thePtr );
\r
269 mySubMesh = SMESH::SMESH_subMesh::_nil();
\r
271 bool isValidMesh = false;
\r
272 if ( !myMesh->_is_nil() )
\r
274 SALOMEDS::SObject_var aSobj = SMESH::FindSObject( thePtr );
\r
275 CORBA::String_var anEntry = aSobj->GetID();
\r
276 Handle(SALOME_InteractiveObject) anIObj =
\r
277 new SALOME_InteractiveObject( anEntry.in(), "SMESH" );
\r
279 const SALOME_ListOfFilter& aList = mySelection->StoredFilters();
\r
280 SALOME_ListIteratorOfListOfFilter anIter( aList );
\r
281 for ( ; anIter.More(); anIter.Next() )
\r
282 if ( !anIter.Value()->IsOk( anIObj ) )
\r
285 if ( !anIter.More() )
\r
286 isValidMesh = true;
\r
292 SALOMEDS::SObject_var aSO = SMESH::FindSObject( myMesh.in() );
\r
293 myMeshEdit->setText( aSO->GetName() );
\r
294 myGeomObj = getGeom( aSO );
\r
298 myMeshEdit->setText( "" );
\r
299 myGeomObj = GEOM::GEOM_Object::_nil();
\r
302 if ( myType == Type_2d )
\r
304 loadFromObject( false );
\r
309 //=======================================================================
\r
310 // name : SMESHGUI_CreatePatternDlg::isValid
\r
311 // Purpose : Verify validity of entry data
\r
312 //=======================================================================
\r
313 bool SMESHGUI_CreatePatternDlg::isValid()
\r
315 if ( myGeomObj->_is_nil() )
\r
317 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
318 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SMESHGUI_INVALID_PARAMETERS" ), QMessageBox::Ok );
\r
327 //=======================================================================
\r
328 // name : SMESHGUI_CreatePatternDlg::getDefaultName
\r
329 // Purpose : Get default pattern name
\r
330 //=======================================================================
\r
331 QString SMESHGUI_CreatePatternDlg::getDefaultName() const
\r
333 return myType == Type_2d ? tr( "DEFAULT_2D" ) : tr( "DEFAULT_3D" );
\r
336 //=======================================================================
\r
337 // name : SMESHGUI_CreatePatternDlg::onSave
\r
338 // Purpose : SLOT called when "Save" button pressed. Build pattern and
\r
341 //=======================================================================
\r
342 void SMESHGUI_CreatePatternDlg::onSave()
\r
350 loadFromObject( true );
\r
352 // Load pattern from object
\r
356 ///////////////////////////////////////////////////////
\r
357 QAD_FileDlg* aDlg = new QAD_FileDlg( this, false );
\r
358 aDlg->setCaption( tr( "SAVE_PATTERN" ) );
\r
359 aDlg->setMode( QFileDialogP::AnyFile );
\r
360 aDlg->setFilters( tr( "PATTERN_FILT" ) );
\r
361 if ( myName->text() != "" )
\r
362 aDlg->setSelection( myName->text() );
\r
364 if ( aDlg->exec() != Accepted )
\r
367 QString fName = aDlg->selectedFile();
\r
368 if ( fName.isEmpty() )
\r
371 if ( QFileInfo( fName ).extension().isEmpty() )
\r
372 fName = autoExtension( fName );
\r
374 fName = QDir::convertSeparators( fName );
\r
376 QString aData( myPattern->GetString() );
\r
377 long aLen = aData.length();
\r
379 QFile aFile( fName );
\r
380 aFile.open( IO_WriteOnly );
\r
381 long aWritten = aFile.writeBlock( aData, aLen );
\r
384 if ( aWritten != aLen )
\r
386 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
\r
387 tr( "SMESH_ERROR" ), tr( "ERROR_OF_SAVING" ), QMessageBox::Ok );
\r
391 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
392 disconnect( mySelection, 0, this, 0 );
\r
393 disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );
\r
394 SMESHGUI::GetSMESHGUI()->ResetState();
\r
399 catch( const SALOME::SALOME_Exception& S_ex )
\r
401 QtCatchCorbaException( S_ex );
\r
408 //=======================================================================
\r
409 // name : SMESHGUI_CreatePatternDlg::GetPatternName
\r
410 // Purpose : Get name of pattern
\r
411 //=======================================================================
\r
412 QString SMESHGUI_CreatePatternDlg::GetPatternName() const
\r
414 return myName->text();
\r
417 //=======================================================================
\r
418 // name : SMESHGUI_CreatePatternDlg::GetPattern
\r
419 // Purpose : Get result pattern
\r
420 //=======================================================================
\r
421 SMESH::SMESH_Pattern_ptr SMESHGUI_CreatePatternDlg::GetPattern()
\r
423 return myPattern.in();
\r
426 //=======================================================================
\r
427 // name : SMESHGUI_CreatePatternDlg::onOk
\r
428 // Purpose : SLOT called when "Ok" button pressed.
\r
429 //=======================================================================
\r
430 void SMESHGUI_CreatePatternDlg::onOk()
\r
438 loadFromObject( true );
\r
440 // Load pattern from object
\r
445 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
446 disconnect( mySelection, 0, this, 0 );
\r
447 disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );
\r
448 SMESHGUI::GetSMESHGUI()->ResetState();
\r
453 catch( const SALOME::SALOME_Exception& S_ex )
\r
455 QtCatchCorbaException( S_ex );
\r
462 //=======================================================================
\r
463 // name : SMESHGUI_CreatePatternDlg::onClose
\r
464 // Purpose : SLOT called when "Close" button pressed. Close dialog
\r
465 //=======================================================================
\r
466 void SMESHGUI_CreatePatternDlg::onClose()
\r
468 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
469 disconnect( mySelection, 0, this, 0 );
\r
470 disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );
\r
471 SMESHGUI::GetSMESHGUI()->ResetState();
\r
476 //=======================================================================
\r
477 // name : SMESHGUI_CreatePatternDlg::loadFromObject
\r
478 // Purpose : Load pattern from geom object corresponding to the mesh/submesh
\r
479 //=======================================================================
\r
480 bool SMESHGUI_CreatePatternDlg::loadFromObject( const bool theMess )
\r
484 myIsLoaded = false;
\r
486 if ( myPattern->_is_nil() )
\r
487 myPattern = SMESH::GetPattern();
\r
489 if ( myMesh->_is_nil() && mySubMesh->_is_nil() || myGeomObj->_is_nil() )
\r
492 SMESH::SMESH_Mesh_ptr aMesh = mySubMesh->_is_nil() ? myMesh.in() : mySubMesh->GetFather();
\r
494 myIsLoaded = myType == Type_2d
\r
495 ? myPattern->LoadFromFace( aMesh, myGeomObj, myProjectChk->isChecked() )
\r
496 : myPattern->LoadFrom3DBlock( aMesh, myGeomObj );
\r
498 if ( !myIsLoaded && theMess )
\r
501 SMESH::SMESH_Pattern::ErrorCode aCode = myPattern->GetErrorCode();
\r
503 if ( aCode == SMESH::SMESH_Pattern::ERR_LOAD_EMPTY_SUBMESH ) aMess = tr( "ERR_LOAD_EMPTY_SUBMESH" );
\r
504 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_NARROW_FACE ) aMess = tr( "ERR_LOADF_NARROW_FACE" );
\r
505 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_CLOSED_FACE ) aMess = tr( "ERR_LOADF_CLOSED_FACE" );
\r
506 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADV_BAD_SHAPE ) aMess = tr( "ERR_LOADV_BAD_SHAPE" );
\r
507 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADV_COMPUTE_PARAMS ) aMess = tr( "ERR_LOADV_COMPUTE_PARAMS" );
\r
508 else aMess = tr( "ERROR_OF_CREATION" );
\r
510 QMessageBox::information(
\r
511 SMESHGUI::GetSMESHGUI()->GetDesktop(), tr( "SMESH_ERROR" ), aMess, QMessageBox::Ok );
\r
515 catch( const SALOME::SALOME_Exception& S_ex )
\r
517 QtCatchCorbaException( S_ex );
\r
523 //=======================================================================
\r
524 // name : SMESHGUI_CreatePatternDlg::getGeom
\r
525 // Purpose : Retrieve geom object from SObject
\r
526 //=======================================================================
\r
527 GEOM::GEOM_Object_ptr SMESHGUI_CreatePatternDlg::getGeom( SALOMEDS::SObject_ptr theSO )
\r
529 if ( theSO->_is_nil() )
\r
530 return GEOM::GEOM_Object::_nil();
\r
532 SALOMEDS::Study_var aStudy =
\r
533 SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getStudyDocument();
\r
535 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSO );
\r
536 for( ; anIter->More(); anIter->Next() )
\r
538 SALOMEDS::SObject_var aSO = anIter->Value();
\r
539 SALOMEDS::SObject_var aRefSO;
\r
541 GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(
\r
542 aSO->ReferencedObject( aRefSO )? aRefSO->GetObject() : aSO->GetObject() );
\r
544 if ( !aMeshShape->_is_nil() )
\r
545 return aMeshShape._retn();
\r
547 return GEOM::GEOM_Object::_nil();
\r
550 //=======================================================================
\r
551 // name : SMESHGUI_CreatePatternDlg::onSelectionDone
\r
552 // Purpose : SLOT called when selection changed
\r
553 //=======================================================================
\r
554 void SMESHGUI_CreatePatternDlg::onSelectionDone()
\r
558 if ( mySelection->IObjectCount() != 1 )
\r
561 // Get mesh or sub-mesh from selection
\r
562 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
\r
563 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIO );
\r
564 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>( anIO );
\r
565 if ( aMesh->_is_nil() && aSubMesh->_is_nil() )
\r
568 // Get geom object corresponding to the mesh
\r
569 SALOMEDS::SObject_var aSO;
\r
570 if ( !aMesh->_is_nil() )
\r
571 aSO = SMESH::FindSObject( aMesh.in() );
\r
573 aSO = SMESH::FindSObject( aSubMesh.in() );
\r
576 GEOM::GEOM_Object_var aGeomObj = getGeom( aSO );
\r
577 if ( aGeomObj->_is_nil() )
\r
580 myGeomObj = aGeomObj;
\r
582 // init class fields
\r
583 if ( !aMesh->_is_nil() )
\r
586 mySubMesh = SMESH::SMESH_subMesh::_nil();
\r
590 mySubMesh = aSubMesh;
\r
591 myMesh = SMESH::SMESH_Mesh::_nil();
\r
595 SMESH::GetNameOfSelectedIObjects( mySelection, aName );
\r
596 myMeshEdit->setText( aName );
\r
598 if ( myType == Type_2d )
\r
600 loadFromObject( true );
\r
606 myMesh = SMESH::SMESH_Mesh::_nil();
\r
607 mySubMesh = SMESH::SMESH_subMesh::_nil();
\r
608 myGeomObj = GEOM::GEOM_Object::_nil();
\r
613 //=======================================================================
\r
614 // name : SMESHGUI_CreatePatternDlg::onDeactivate
\r
615 // Purpose : SLOT called when dialog must be deativated
\r
616 //=======================================================================
\r
617 void SMESHGUI_CreatePatternDlg::onDeactivate()
\r
619 disconnect( mySelection, 0, this, 0 );
\r
620 setEnabled( false );
\r
623 //=======================================================================
\r
624 // name : SMESHGUI_CreatePatternDlg::enterEvent
\r
625 // Purpose : Event filter
\r
626 //=======================================================================
\r
627 void SMESHGUI_CreatePatternDlg::enterEvent( QEvent* )
\r
629 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
\r
630 setEnabled( true );
\r
631 activateSelection();
\r
632 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
\r
636 //=================================================================================
\r
637 // function : closeEvent()
\r
638 // purpose : Close dialog box
\r
639 //=================================================================================
\r
640 void SMESHGUI_CreatePatternDlg::closeEvent( QCloseEvent* e )
\r
645 //=======================================================================
\r
646 // name : SMESHGUI_CreatePatternDlg::onSelBtnClicked
\r
647 // Purpose : SLOT. Called when -> button clicked.
\r
648 //=======================================================================
\r
649 void SMESHGUI_CreatePatternDlg::onSelBtnClicked()
\r
654 //================================================================
\r
655 // Function : SMESHGUI_CreatePatternDlg::autoExtension
\r
656 // Purpose : Append extension to the file name
\r
657 //================================================================
\r
658 QString SMESHGUI_CreatePatternDlg::autoExtension( const QString& theFileName ) const
\r
660 QString anExt = theFileName.section( '.', -1 );
\r
661 return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName;
\r
664 //=======================================================================
\r
665 // name : SMESHGUI_CreatePatternDlg::displayPreview
\r
666 // Purpose : Display preview
\r
667 //=======================================================================
\r
668 void SMESHGUI_CreatePatternDlg::displayPreview()
\r
671 // Redisplay preview in dialog
\r
679 SMESH::point_array_var pnts = myPattern->GetPoints();
\r
680 SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
\r
681 SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints(false);
\r
683 if ( pnts->length() == 0 ||
\r
684 keyPoints->length() == 0 ||
\r
685 elemPoints->length() == 0 )
\r
687 myIsLoaded = false;
\r
692 PointVector aPoints( pnts->length() );
\r
693 QValueVector<int> aKeyPoints( keyPoints->length() );
\r
694 ConnectivityVector anElemPoints( elemPoints->length() );
\r
696 for ( int i = 0, n = pnts->length(); i < n; i++ )
\r
697 aPoints[ i ] = pnts[ i ];
\r
699 for ( int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++ )
\r
700 aKeyPoints[ i2 ] = keyPoints[ i2 ];
\r
702 for ( int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++ )
\r
704 QValueVector<int> aVec( elemPoints[ i3 ].length() );
\r
705 for ( int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++ )
\r
706 aVec[ i4 ] = elemPoints[ i3 ][ i4 ];
\r
708 anElemPoints[ i3 ] = aVec;
\r
711 myPicture2d->SetPoints( aPoints, aKeyPoints, anElemPoints );
\r
716 catch( const SALOME::SALOME_Exception& S_ex )
\r
718 QtCatchCorbaException( S_ex );
\r
726 //=======================================================================
\r
727 // name : SMESHGUI_CreatePatternDlg::erasePreview
\r
728 // Purpose : Erase preview
\r
729 //=======================================================================
\r
730 void SMESHGUI_CreatePatternDlg::erasePreview()
\r
733 // Erase preview in 2D viewer
\r
734 myPicture2d->SetPoints( PointVector(), QValueVector<int>(), ConnectivityVector() );
\r
737 //=======================================================================
\r
738 // name : SMESHGUI_CreatePatternDlg::activateSelection
\r
739 // Purpose : Activate selection in accordance with current pattern type
\r
740 //=======================================================================
\r
741 void SMESHGUI_CreatePatternDlg::activateSelection()
\r
743 mySelection->ClearFilters();
\r
744 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
\r
746 if ( myType == Type_2d )
\r
748 mySelection->AddFilter(
\r
749 new SMESH_NumberFilter( "SMESH", TopAbs_SHAPE, -1, TopAbs_FACE ) );
\r
753 TColStd_MapOfInteger aTypes;
\r
754 aTypes.Add( TopAbs_SHELL );
\r
755 aTypes.Add( TopAbs_SOLID );
\r
756 mySelection->AddFilter( new SMESH_NumberFilter(
\r
757 "SMESH", TopAbs_FACE, 6, aTypes, GEOM::GEOM_Object::_nil(), true ) );
\r
761 //=======================================================================
\r
762 // name : SMESHGUI_CreatePatternDlg::onTypeChanged
\r
763 // Purpose : SLOT. Called when pattern type changed.
\r
764 // Change dialog's look and feel
\r
765 //=======================================================================
\r
766 void SMESHGUI_CreatePatternDlg::onTypeChanged( int theType )
\r
768 if ( myType == theType )
\r
773 if ( theType == Type_2d )
\r
774 myPicture2d->show();
\r
776 myPicture2d->hide();
\r