00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "SMESHGUI_CreatePatternDlg.h"
00028
00029 #include "SMESHGUI.h"
00030 #include "SMESHGUI_PatternWidget.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_PatternUtils.h"
00034 #include "SMESHGUI_GEOMGenUtils.h"
00035
00036 #include <SMESH_NumberFilter.hxx>
00037
00038
00039 #include <SUIT_ResourceMgr.h>
00040 #include <SUIT_Desktop.h>
00041 #include <SUIT_FileDlg.h>
00042 #include <SUIT_Session.h>
00043 #include <SUIT_MessageBox.h>
00044
00045 #include <LightApp_Application.h>
00046 #include <LightApp_SelectionMgr.h>
00047 #include <SalomeApp_Tools.h>
00048
00049 #include <SALOME_ListIO.hxx>
00050 #include <SVTK_ViewModel.h>
00051 #include <SVTK_ViewWindow.h>
00052
00053
00054 #include <SALOMEDS_SObject.hxx>
00055
00056
00057 #include <TColStd_MapOfInteger.hxx>
00058
00059
00060 #include <QFrame>
00061 #include <QVBoxLayout>
00062 #include <QHBoxLayout>
00063 #include <QLineEdit>
00064 #include <QPushButton>
00065 #include <QGroupBox>
00066 #include <QLabel>
00067 #include <QRadioButton>
00068 #include <QCheckBox>
00069 #include <QButtonGroup>
00070 #include <QApplication>
00071 #include <QKeyEvent>
00072 #include <QFile>
00073 #include <QDir>
00074
00075 #define SPACING 6
00076 #define MARGIN 11
00077
00083
00084
00085
00086
00087 SMESHGUI_CreatePatternDlg::SMESHGUI_CreatePatternDlg( SMESHGUI* theModule,
00088 const int theType )
00089 : QDialog( SMESH::GetDesktop( theModule ) ),
00090 mySMESHGUI( theModule ),
00091 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
00092 {
00093 setModal( false );
00094 setWindowTitle( tr( "CAPTION" ) );
00095
00096 QVBoxLayout* aDlgLay = new QVBoxLayout( this );
00097 aDlgLay->setMargin( MARGIN );
00098 aDlgLay->setSpacing( SPACING );
00099
00100 QWidget* aMainFrame = createMainFrame( this );
00101 QWidget* aBtnFrame = createButtonFrame( this );
00102
00103 aDlgLay->addWidget( aMainFrame );
00104 aDlgLay->addWidget( aBtnFrame );
00105
00106 aDlgLay->setStretchFactor( aMainFrame, 1 );
00107
00108 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
00109 mySelector = aViewWindow->GetSelector();
00110
00111 myHelpFileName = "pattern_mapping_page.html";
00112
00113 Init( theType );
00114 }
00115
00116
00117
00118
00119
00120 QWidget* SMESHGUI_CreatePatternDlg::createMainFrame( QWidget* theParent )
00121 {
00122 QPixmap iconSlct ( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
00123 QPixmap icon2d ( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) );
00124 QPixmap icon3d ( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) );
00125 QPixmap iconSample2d( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) );
00126
00127 QWidget* aMainGrp = new QWidget( theParent );
00128 QVBoxLayout* aMainGrpLayout = new QVBoxLayout( aMainGrp );
00129 aMainGrpLayout->setMargin( 0 );
00130 aMainGrpLayout->setSpacing( SPACING );
00131
00132
00133
00134 QGroupBox* aTypeGrp = new QGroupBox( tr( "PATTERN_TYPE" ), aMainGrp );
00135 QHBoxLayout* aTypeGrpLayout = new QHBoxLayout( aTypeGrp );
00136 aTypeGrpLayout->setMargin( MARGIN );
00137 aTypeGrpLayout->setSpacing( SPACING );
00138
00139 mySwitch2d = new QRadioButton( aTypeGrp );
00140 mySwitch3d = new QRadioButton( aTypeGrp );
00141 mySwitch2d->setIcon( icon2d );
00142 mySwitch3d->setIcon( icon3d );
00143
00144 myTypeGrp = new QButtonGroup( aMainGrp );
00145 myTypeGrp->addButton( mySwitch2d, Type_2d );
00146 myTypeGrp->addButton( mySwitch3d, Type_3d );
00147
00148
00149
00150 aTypeGrpLayout->addWidget( mySwitch2d );
00151 aTypeGrpLayout->addWidget( mySwitch3d );
00152
00153
00154
00155 QGroupBox* aPatternGrp = new QGroupBox( tr( "PATTERN" ), aMainGrp );
00156 QGridLayout* aPatternGrpLayout = new QGridLayout( aPatternGrp );
00157 aPatternGrpLayout->setMargin( MARGIN );
00158 aPatternGrpLayout->setSpacing( SPACING );
00159
00160 QLabel* aMeshLab = new QLabel( tr( "MESH_OR_SUBMESH" ), aPatternGrp );
00161
00162 QPushButton* aSelBtn = new QPushButton( aPatternGrp );
00163 aSelBtn->setIcon( iconSlct );
00164 myMeshEdit = new QLineEdit( aPatternGrp );
00165 myMeshEdit->setReadOnly( true );
00166
00167 QLabel* aNameLab = new QLabel( tr( "PATTERN_NAME" ), aPatternGrp );
00168 myName = new QLineEdit( aPatternGrp );
00169
00170
00171
00172 myPicture2d = new SMESHGUI_PatternWidget( aPatternGrp ),
00173 myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
00174
00175
00176
00177 myProjectChk = new QCheckBox( tr( "PROJECT" ), aPatternGrp );
00178
00179
00180
00181 aPatternGrpLayout->addWidget( aMeshLab, 0, 0 );
00182 aPatternGrpLayout->addWidget( aSelBtn, 0, 1 );
00183 aPatternGrpLayout->addWidget( myMeshEdit, 0, 2 );
00184 aPatternGrpLayout->addWidget( aNameLab, 1, 0 );
00185 aPatternGrpLayout->addWidget( myName, 1, 2 );
00186 aPatternGrpLayout->addWidget( myPicture2d, 2, 0, 1, 3 );
00187 aPatternGrpLayout->addWidget( myProjectChk, 3, 0, 1, 3 );
00188
00189
00190
00191 aMainGrpLayout->addWidget( aTypeGrp );
00192 aMainGrpLayout->addWidget( aPatternGrp );
00193
00194
00195
00196 connect( myTypeGrp, SIGNAL( buttonClicked( int ) ),
00197 this, SLOT( onTypeChanged( int ) ) );
00198 connect( myProjectChk, SIGNAL( toggled( bool ) ),
00199 this, SLOT( onProject( bool ) ) );
00200 connect( aSelBtn, SIGNAL( clicked() ),
00201 this, SLOT( onSelBtnClicked() ) );
00202
00203 return aMainGrp;
00204 }
00205
00206
00207
00208
00209
00210 QWidget* SMESHGUI_CreatePatternDlg::createButtonFrame( QWidget* theParent )
00211 {
00212 QFrame* aFrame = new QFrame( theParent );
00213 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
00214
00215 QPushButton* myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), aFrame );
00216 QPushButton* mySaveBtn = new QPushButton( tr( "SAVE" ), aFrame );
00217 QPushButton* myCloseBtn = new QPushButton( tr( "SMESH_BUT_CANCEL"), aFrame );
00218 QPushButton* myHelpBtn = new QPushButton( tr( "SMESH_BUT_HELP"), aFrame );
00219
00220 QHBoxLayout* aLay = new QHBoxLayout( aFrame );
00221 aLay->setMargin( MARGIN );
00222 aLay->setSpacing( SPACING );
00223
00224 aLay->addWidget( myOkBtn );
00225 aLay->addSpacing( 10 );
00226 aLay->addWidget( mySaveBtn );
00227 aLay->addSpacing( 10 );
00228 aLay->addStretch();
00229 aLay->addWidget( myCloseBtn );
00230 aLay->addWidget( myHelpBtn );
00231
00232 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
00233 connect( myCloseBtn, SIGNAL( clicked() ), this, SLOT( onClose() ) );
00234 connect( mySaveBtn, SIGNAL( clicked() ), this, SLOT( onSave() ) );
00235 connect( myHelpBtn, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
00236
00237 return aFrame;
00238 }
00239
00240
00241
00242
00243
00244 SMESHGUI_CreatePatternDlg::~SMESHGUI_CreatePatternDlg()
00245 {
00246 }
00247
00248
00249
00250
00251
00252
00253 void SMESHGUI_CreatePatternDlg::onProject( bool )
00254 {
00255 loadFromObject( false );
00256 displayPreview();
00257 }
00258
00259
00260
00261
00262
00263 void SMESHGUI_CreatePatternDlg::Init( const int theType )
00264 {
00265 myIsLoaded = false;
00266 myType = -1;
00267 mySubMesh = SMESH::SMESH_subMesh::_nil();
00268 myMesh = SMESH::SMESH_Mesh::_nil();
00269 myGeomObj = GEOM::GEOM_Object::_nil();
00270 myPattern = SMESH::SMESH_Pattern::_nil();
00271
00272 erasePreview();
00273
00274 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00275
00276
00277 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ),
00278 this, SLOT( onSelectionDone() ) );
00279 connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ),
00280 this, SLOT( onDeactivate() ) );
00281 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ),
00282 this, SLOT( onClose() ) );
00283
00284 mySwitch2d->setEnabled( theType == Type_2d );
00285 mySwitch3d->setEnabled( theType == Type_3d );
00286
00287 myTypeGrp->button( theType )->setChecked( true );
00288 onTypeChanged( theType );
00289
00290 myName->setText( getDefaultName() );
00291 myMeshEdit->setText( "" );
00292
00293 QApplication::instance()->processEvents();
00294 updateGeometry();
00295 resize(100,100);
00296
00297 activateSelection();
00298 onSelectionDone();
00299
00300
00301 }
00302
00303
00304
00305
00306
00307 void SMESHGUI_CreatePatternDlg::SetMesh( SMESH::SMESH_Mesh_ptr thePtr )
00308 {
00309 myMesh = SMESH::SMESH_Mesh::_duplicate( thePtr );
00310 mySubMesh = SMESH::SMESH_subMesh::_nil();
00311
00312 bool isValidMesh = false;
00313 if ( !myMesh->_is_nil() ) {
00314 _PTR(SObject) aSobj = SMESH::FindSObject( myMesh.in() );
00315
00316
00317 SUIT_DataOwnerPtr anIObj( new LightApp_DataOwner( aSobj->GetID().c_str() ) );
00318
00319 isValidMesh = mySelectionMgr->isOk( anIObj );
00320 }
00321
00322 if ( isValidMesh ) {
00323 _PTR(SObject) aSO = SMESH::FindSObject( myMesh.in() );
00324 myMeshEdit->setText( aSO->GetName().c_str() );
00325 myGeomObj = SMESH::GetGeom( aSO );
00326 }
00327 else {
00328 myMeshEdit->setText( "" );
00329 myGeomObj = GEOM::GEOM_Object::_nil();
00330 }
00331
00332 if ( myType == Type_2d ) {
00333 loadFromObject( false );
00334 displayPreview();
00335 }
00336 }
00337
00338
00339
00340
00341
00342 bool SMESHGUI_CreatePatternDlg::isValid()
00343 {
00344 if ( myGeomObj->_is_nil() ) {
00345 SUIT_MessageBox::information( this,
00346 tr( "SMESH_INSUFFICIENT_DATA" ),
00347 tr( "SMESHGUI_INVALID_PARAMETERS" ) );
00348 return false;
00349 }
00350 return true;
00351 }
00352
00353
00354
00355
00356
00357 QString SMESHGUI_CreatePatternDlg::getDefaultName() const
00358 {
00359 return myType == Type_2d ? tr( "DEFAULT_2D" ) : tr( "DEFAULT_3D" );
00360 }
00361
00362
00363
00364
00365
00366
00367 void SMESHGUI_CreatePatternDlg::onSave()
00368 {
00369 try {
00370 if ( !isValid() )
00371 return;
00372
00373 if ( !myIsLoaded )
00374 loadFromObject( true );
00375
00376
00377 if ( !myIsLoaded )
00378 return;
00379
00381 SUIT_FileDlg* aDlg = new SUIT_FileDlg( this, false );
00382 aDlg->setWindowTitle( tr( "SAVE_PATTERN" ) );
00383 aDlg->setFileMode( QFileDialog::AnyFile );
00384 aDlg->setFilter( tr( "PATTERN_FILT" ) );
00385 if ( myName->text() != "" )
00386 aDlg->selectFile( myName->text() );
00387
00388 if ( aDlg->exec() != Accepted )
00389 return;
00390
00391 QString fName = aDlg->selectedFile();
00392 if ( fName.isEmpty() )
00393 return;
00394
00395 if ( QFileInfo( fName ).suffix().isEmpty() )
00396 fName = autoExtension( fName );
00397
00398 fName = QDir::convertSeparators( fName );
00399
00400 QString aData( myPattern->GetString() );
00401 long aLen = aData.length();
00402
00403 QFile aFile( fName );
00404 aFile.open( QIODevice::WriteOnly );
00405 long aWritten = aFile.write( aData.toLatin1(), aLen );
00406 aFile.close();
00407
00408 if ( aWritten != aLen ) {
00409 SUIT_MessageBox::information( this,
00410 tr( "SMESH_ERROR" ),
00411 tr( "ERROR_OF_SAVING" ) );
00412 }
00413 else {
00414
00415 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
00416 aViewWindow->SetSelectionMode( ActorSelection );
00417 disconnect( mySelectionMgr, 0, this, 0 );
00418 disconnect( mySMESHGUI, 0, this, 0 );
00419 mySMESHGUI->ResetState();
00420 accept();
00421 emit NewPattern();
00422 }
00423 }
00424 catch ( const SALOME::SALOME_Exception& S_ex ) {
00425 SalomeApp_Tools::QtCatchCorbaException( S_ex );
00426 }
00427 catch (...) {
00428 }
00429 }
00430
00431
00432
00433
00434
00435 QString SMESHGUI_CreatePatternDlg::GetPatternName() const
00436 {
00437 return myName->text();
00438 }
00439
00440
00441
00442
00443
00444 SMESH::SMESH_Pattern_ptr SMESHGUI_CreatePatternDlg::GetPattern()
00445 {
00446 return myPattern.in();
00447 }
00448
00449
00450
00451
00452
00453 void SMESHGUI_CreatePatternDlg::onOk()
00454 {
00455 try {
00456 if ( !isValid() )
00457 return;
00458
00459 if ( !myIsLoaded )
00460 loadFromObject( true );
00461
00462
00463 if ( !myIsLoaded ) {
00464 return;
00465 }
00466 else {
00467
00468 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
00469 aViewWindow->SetSelectionMode( ActorSelection );
00470 disconnect( mySelectionMgr, 0, this, 0 );
00471 disconnect( mySMESHGUI, 0, this, 0 );
00472 mySMESHGUI->ResetState();
00473 accept();
00474 emit NewPattern();
00475 }
00476 }
00477 catch ( const SALOME::SALOME_Exception& S_ex ) {
00478 SalomeApp_Tools::QtCatchCorbaException( S_ex );
00479 }
00480 catch (...) {
00481 }
00482 }
00483
00484
00485
00486
00487
00488 void SMESHGUI_CreatePatternDlg::onClose()
00489 {
00490 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
00491 aViewWindow->SetSelectionMode( ActorSelection );
00492 disconnect( mySelectionMgr, 0, this, 0 );
00493 disconnect( mySMESHGUI, 0, this, 0 );
00494 mySMESHGUI->ResetState();
00495 reject();
00496 emit Close();
00497 }
00498
00499
00500
00501
00502
00503 void SMESHGUI_CreatePatternDlg::onHelp()
00504 {
00505 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
00506 if ( app )
00507 app->onHelpContextModule( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) : QString( "" ), myHelpFileName );
00508 else {
00509 QString platform;
00510 #ifdef WIN32
00511 platform = "winapplication";
00512 #else
00513 platform = "application";
00514 #endif
00515 SUIT_MessageBox::warning( this,
00516 tr( "WRN_WARNING" ),
00517 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
00518 arg( app->resourceMgr()->stringValue( "ExternalBrowser",
00519 platform ) ).
00520 arg( myHelpFileName ) );
00521 }
00522 }
00523
00524
00525
00526
00527
00528 bool SMESHGUI_CreatePatternDlg::loadFromObject( const bool theMess )
00529 {
00530 try {
00531 myIsLoaded = false;
00532
00533 if ( myPattern->_is_nil() )
00534 myPattern = SMESH::GetPattern();
00535
00536 if ( (myMesh->_is_nil() && mySubMesh->_is_nil()) || myGeomObj->_is_nil() )
00537 return false;
00538
00539 SMESH::SMESH_Mesh_ptr aMesh = mySubMesh->_is_nil() ? myMesh.in() : mySubMesh->GetFather();
00540
00541 myIsLoaded = myType == Type_2d
00542 ? myPattern->LoadFromFace( aMesh, myGeomObj, myProjectChk->isChecked() )
00543 : myPattern->LoadFrom3DBlock( aMesh, myGeomObj );
00544
00545 if ( !myIsLoaded && theMess ) {
00546 QString aMess;
00547 SMESH::SMESH_Pattern::ErrorCode aCode = myPattern->GetErrorCode();
00548
00549 if ( aCode == SMESH::SMESH_Pattern::ERR_LOAD_EMPTY_SUBMESH ) aMess = tr( "ERR_LOAD_EMPTY_SUBMESH" );
00550 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_NARROW_FACE ) aMess = tr( "ERR_LOADF_NARROW_FACE" );
00551 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_CLOSED_FACE ) aMess = tr( "ERR_LOADF_CLOSED_FACE" );
00552 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_CANT_PROJECT ) aMess = tr( "ERR_LOADF_CANT_PROJECT" );
00553 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADV_BAD_SHAPE ) aMess = tr( "ERR_LOADV_BAD_SHAPE" );
00554 else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADV_COMPUTE_PARAMS ) aMess = tr( "ERR_LOADV_COMPUTE_PARAMS" );
00555 else aMess = tr( "ERROR_OF_CREATION" );
00556
00557 SUIT_MessageBox::information( this, tr( "SMESH_ERROR" ), aMess );
00558 }
00559 }
00560 catch ( const SALOME::SALOME_Exception& S_ex ) {
00561 SalomeApp_Tools::QtCatchCorbaException( S_ex );
00562 }
00563
00564 return myIsLoaded;
00565 }
00566
00567
00568
00569
00570
00571 void SMESHGUI_CreatePatternDlg::onSelectionDone()
00572 {
00573 try {
00574 SALOME_ListIO aList;
00575 mySelectionMgr->selectedObjects( aList, SVTK_Viewer::Type() );
00576 if ( aList.Extent() != 1 )
00577 return;
00578
00579
00580 Handle(SALOME_InteractiveObject) anIO = aList.First();
00581 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIO );
00582 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>( anIO );
00583 if ( aMesh->_is_nil() && aSubMesh->_is_nil() )
00584 return;
00585
00586
00587 _PTR(SObject) aSO;
00588 if ( !aMesh->_is_nil() )
00589 aSO = SMESH::FindSObject( aMesh.in() );
00590 else
00591 aSO = SMESH::FindSObject( aSubMesh.in() );
00592
00593 GEOM::GEOM_Object_var aGeomObj = SMESH::GetGeom( aSO );
00594 if ( aGeomObj->_is_nil() )
00595 return;
00596
00597 myGeomObj = aGeomObj;
00598
00599
00600 if ( !aMesh->_is_nil() ) {
00601 myMesh = aMesh;
00602 mySubMesh = SMESH::SMESH_subMesh::_nil();
00603 }
00604 else {
00605 mySubMesh = aSubMesh;
00606 myMesh = SMESH::SMESH_Mesh::_nil();
00607 }
00608
00609 QString aName;
00610 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aName );
00611 myMeshEdit->setText( aName );
00612
00613 if ( myType == Type_2d ) {
00614 loadFromObject( true );
00615 displayPreview();
00616 }
00617 }
00618 catch (...) {
00619 myMesh = SMESH::SMESH_Mesh::_nil();
00620 mySubMesh = SMESH::SMESH_subMesh::_nil();
00621 myGeomObj = GEOM::GEOM_Object::_nil();
00622 erasePreview();
00623 }
00624 }
00625
00626
00627
00628
00629
00630 void SMESHGUI_CreatePatternDlg::onDeactivate()
00631 {
00632 disconnect( mySelectionMgr, 0, this, 0 );
00633 setEnabled( false );
00634 }
00635
00636
00637
00638
00639
00640 void SMESHGUI_CreatePatternDlg::enterEvent( QEvent* )
00641 {
00642
00643 if ( isVisible () ) {
00644 mySMESHGUI->EmitSignalDeactivateDialog();
00645 setEnabled( true );
00646 activateSelection();
00647 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
00648 }
00649 }
00650
00651
00652
00653
00654
00655 void SMESHGUI_CreatePatternDlg::closeEvent( QCloseEvent* )
00656 {
00657 onClose();
00658 }
00659
00660
00661
00662
00663
00664 void SMESHGUI_CreatePatternDlg::onSelBtnClicked()
00665 {
00666 onSelectionDone();
00667 }
00668
00669
00670
00671
00672
00673 QString SMESHGUI_CreatePatternDlg::autoExtension( const QString& theFileName ) const
00674 {
00675 QString anExt = theFileName.section('.', -1);
00676 return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName;
00677 }
00678
00679
00680
00681
00682
00683 void SMESHGUI_CreatePatternDlg::displayPreview()
00684 {
00685
00686 try {
00687 if ( !myIsLoaded ) {
00688 erasePreview();
00689 }
00690 else {
00691 SMESH::point_array_var pnts = myPattern->GetPoints();
00692 SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
00693 SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints( false );
00694
00695 if ( pnts->length() == 0 ||
00696 keyPoints->length() == 0 ||
00697 elemPoints->length() == 0 ) {
00698 myIsLoaded = false;
00699 erasePreview();
00700 return;
00701 }
00702
00703 PointVector aPoints( pnts->length() );
00704 QVector<int> aKeyPoints( keyPoints->length() );
00705 ConnectivityVector anElemPoints( elemPoints->length() );
00706
00707 for ( int i = 0, n = pnts->length(); i < n; i++ )
00708 aPoints[ i ] = pnts[ i ];
00709
00710 for ( int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++ )
00711 aKeyPoints[ i2 ] = keyPoints[ i2 ];
00712
00713 for (int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++) {
00714 QVector<int> aVec (elemPoints[ i3 ].length());
00715 for (int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++)
00716 aVec[ i4 ] = elemPoints[ i3 ][ i4 ];
00717
00718 anElemPoints[ i3 ] = aVec;
00719 }
00720
00721 myPicture2d->SetPoints( aPoints, aKeyPoints, anElemPoints );
00722 }
00723
00724 return;
00725
00726 }
00727 catch ( const SALOME::SALOME_Exception& S_ex ) {
00728 SalomeApp_Tools::QtCatchCorbaException( S_ex );
00729 }
00730 catch (...) {
00731 }
00732 erasePreview();
00733 }
00734
00735
00736
00737
00738
00739 void SMESHGUI_CreatePatternDlg::erasePreview()
00740 {
00741
00742 myPicture2d->SetPoints( PointVector(), QVector<int>(), ConnectivityVector() );
00743 }
00744
00745
00746
00747
00748
00749 void SMESHGUI_CreatePatternDlg::activateSelection()
00750 {
00751 mySelectionMgr->clearFilters();
00752
00753 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
00754 aViewWindow->SetSelectionMode( ActorSelection );
00755
00756 if ( myType == Type_2d ) {
00757 mySelectionMgr->installFilter( new SMESH_NumberFilter( "SMESH",
00758 TopAbs_SHAPE,
00759 -1,
00760 TopAbs_FACE ) );
00761 }
00762 else {
00763 TColStd_MapOfInteger aTypes;
00764 aTypes.Add( TopAbs_SHELL );
00765 aTypes.Add( TopAbs_SOLID );
00766 mySelectionMgr->installFilter( new SMESH_NumberFilter( "SMESH",
00767 TopAbs_FACE,
00768 6,
00769 aTypes,
00770 GEOM::GEOM_Object::_nil(),
00771 true ) );
00772 }
00773 }
00774
00775
00776
00777
00778
00779
00780 void SMESHGUI_CreatePatternDlg::onTypeChanged( int theType )
00781 {
00782 if ( myType == theType )
00783 return;
00784
00785 myType = theType;
00786
00787 myPicture2d->setVisible( theType == Type_2d );
00788 myProjectChk->setVisible( theType == Type_2d );
00789 }
00790
00791
00792
00793
00794
00795 void SMESHGUI_CreatePatternDlg::keyPressEvent( QKeyEvent* e )
00796 {
00797 QDialog::keyPressEvent( e );
00798 if ( e->isAccepted() )
00799 return;
00800
00801 if ( e->key() == Qt::Key_F1 ){
00802 e->accept();
00803 onHelp();
00804 }
00805 }