Version: 6.3.1

src/SMESHGUI/SMESHGUI_MeshPatternDlg.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_MeshPatternDlg.cxx
00025 // Author : Sergey LITONIN, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_MeshPatternDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_CreatePatternDlg.h"
00032 #include "SMESHGUI_PatternWidget.h"
00033 #include "SMESHGUI_Utils.h"
00034 #include "SMESHGUI_VTKUtils.h"
00035 #include "SMESHGUI_PatternUtils.h"
00036 #include "SMESHGUI_GEOMGenUtils.h"
00037 
00038 #include <SMESH_Actor.h>
00039 #include <SMESH_ActorUtils.h>
00040 #include <SMESH_NumberFilter.hxx>
00041 
00042 #include <SMDS_Mesh.hxx>
00043 #include <SMDS_MeshElement.hxx>
00044 
00045 // SALOME GUI includes
00046 #include <SUIT_ResourceMgr.h>
00047 #include <SUIT_Desktop.h>
00048 #include <SUIT_FileDlg.h>
00049 #include <SUIT_Session.h>
00050 #include <SUIT_MessageBox.h>
00051 
00052 #include <LightApp_SelectionMgr.h>
00053 #include <SalomeApp_Tools.h>
00054 #include <LightApp_Application.h>
00055 #include <SalomeApp_IntSpinBox.h>
00056 
00057 #include <SALOME_ListIO.hxx>
00058 
00059 #include <SVTK_ViewModel.h>
00060 #include <SVTK_ViewWindow.h>
00061 #include <VTKViewer_CellLocationsArray.h>
00062 
00063 // SALOME KERNEL includes 
00064 #include <SALOMEDS_SObject.hxx>
00065 
00066 // OCCT includes
00067 #include <TColStd_MapOfInteger.hxx>
00068 
00069 // Qt includes
00070 #include <QFrame>
00071 #include <QVBoxLayout>
00072 #include <QHBoxLayout>
00073 #include <QGridLayout>
00074 #include <QLineEdit>
00075 #include <QPushButton>
00076 #include <QGroupBox>
00077 #include <QLabel>
00078 #include <QRadioButton>
00079 #include <QCheckBox>
00080 #include <QButtonGroup>
00081 #include <QList>
00082 #include <QDir>
00083 #include <QFileDialog>
00084 #include <QFileInfo>
00085 #include <QFile>
00086 #include <QKeyEvent>
00087 
00088 // VTK includes
00089 #include <vtkIdList.h>
00090 #include <vtkCellArray.h>
00091 #include <vtkUnsignedCharArray.h>
00092 #include <vtkUnstructuredGrid.h>
00093 #include <vtkDataSetMapper.h>
00094 #include <vtkProperty.h>
00095 
00096 #define SPACING 6
00097 #define MARGIN  11
00098 
00104 //=======================================================================
00105 // name    : SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg
00106 // Purpose : Constructor
00107 //=======================================================================
00108 SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg( SMESHGUI* theModule )
00109   : QDialog( SMESH::GetDesktop( theModule ) ),
00110     mySMESHGUI( theModule ),
00111     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00112     myBusy( false ),
00113     myCreationDlg( 0 )
00114 {
00115   setModal( false );
00116   setWindowTitle( tr( "CAPTION" ) );
00117 
00118   QVBoxLayout* aDlgLay = new QVBoxLayout( this );
00119   aDlgLay->setMargin( MARGIN );
00120   aDlgLay->setSpacing( SPACING );
00121 
00122   QWidget* aMainFrame = createMainFrame  ( this );
00123   QWidget* aBtnFrame  = createButtonFrame( this );
00124 
00125   aDlgLay->addWidget( aMainFrame );
00126   aDlgLay->addWidget( aBtnFrame );
00127 
00128   aDlgLay->setStretchFactor( aMainFrame, 1 );
00129 
00130   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00131 
00132   myHelpFileName = "pattern_mapping_page.html";
00133 
00134   Init();
00135 }
00136 
00137 //=======================================================================
00138 // name    : SMESHGUI_MeshPatternDlg::createMainFrame
00139 // Purpose : Create frame containing dialog's input fields
00140 //=======================================================================
00141 QWidget* SMESHGUI_MeshPatternDlg::createMainFrame (QWidget* theParent)
00142 {
00143   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
00144   QPixmap iconSlct ( mgr->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
00145   QPixmap icon2d   ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) );
00146   QPixmap icon3d   ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) );
00147   QPixmap iconOpen ( mgr->loadPixmap( "STD",   tr( "ICON_FILE_OPEN" ) ) );
00148 
00149   QPixmap iconSample2d ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) );
00150   QPixmap iconSample3d ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_3D" ) ) );
00151 
00152   QWidget* aMainGrp = new QWidget( theParent );
00153 
00154   QVBoxLayout* aMainGrpLayout = new QVBoxLayout( aMainGrp );
00155   aMainGrpLayout->setMargin( 0 );
00156   aMainGrpLayout->setSpacing( SPACING );
00157 
00158   // Pattern type group
00159 
00160   QGroupBox* aTypeGrp = new QGroupBox( tr( "PATTERN_TYPE" ), aMainGrp );
00161   QHBoxLayout* aTypeGrpLayout = new QHBoxLayout( aTypeGrp );
00162   aTypeGrpLayout->setMargin( MARGIN );
00163   aTypeGrpLayout->setSpacing( SPACING );
00164 
00165   mySwitch2d = new QRadioButton( aTypeGrp );
00166   mySwitch3d = new QRadioButton( aTypeGrp );
00167   mySwitch2d->setIcon( icon2d );
00168   mySwitch3d->setIcon( icon3d );
00169 
00170   myTypeGrp = new QButtonGroup( aMainGrp );
00171   myTypeGrp->addButton( mySwitch2d, Type_2d );
00172   myTypeGrp->addButton( mySwitch3d, Type_3d );
00173 
00174   // ... layout widgets
00175 
00176   aTypeGrpLayout->addWidget( mySwitch2d );
00177   aTypeGrpLayout->addWidget( mySwitch3d );
00178 
00179   // Mesh group
00180 
00181   QGroupBox* aMeshGrp = new QGroupBox( tr( "SMESH_MESH" ), aMainGrp );
00182   QHBoxLayout* aMeshGrpLayout = new QHBoxLayout( aMeshGrp );
00183   aMeshGrpLayout->setMargin( MARGIN );
00184   aMeshGrpLayout->setSpacing( SPACING );
00185 
00186   QLabel* aMeshLab = new QLabel( tr( "SMESH_MESH" ), aMeshGrp );
00187   mySelBtn[ Mesh ] = new QPushButton( aMeshGrp );
00188   mySelBtn[ Mesh ]->setIcon( iconSlct );
00189   mySelEdit[ Mesh ] = new QLineEdit( aMeshGrp );
00190   mySelEdit[ Mesh ]->setReadOnly( true );
00191 
00192   // ... layout widgets
00193 
00194   aMeshGrpLayout->addWidget( aMeshLab );
00195   aMeshGrpLayout->addWidget( mySelBtn[ Mesh ] );
00196   aMeshGrpLayout->addWidget( mySelEdit[ Mesh ] );
00197 
00198   // Pattern group
00199 
00200   QGroupBox* aPatGrp = new QGroupBox( tr( "PATTERN" ), aMainGrp );
00201   QGridLayout* aPatGrpLayout = new QGridLayout( aPatGrp );
00202   aPatGrpLayout->setMargin( MARGIN );
00203   aPatGrpLayout->setSpacing( SPACING );
00204 
00205   // ... Pattern name
00206 
00207   QLabel* aNameLab = new QLabel( tr( "PATTERN" ), aPatGrp );
00208   myName = new QLineEdit( aPatGrp );
00209   myName->setReadOnly( true );
00210   myOpenBtn = new QPushButton( aPatGrp );
00211   myOpenBtn->setIcon( iconOpen );
00212   myNewBtn = new QPushButton( tr( "NEW" ), aPatGrp );
00213 
00214   // ... Mode selection check box
00215   myRefine = new QCheckBox( tr( "REFINE" ), aPatGrp );
00216 
00217   // ... selection widgets for Apply to geom mode
00218   myGeomGrp = new QFrame( aPatGrp );
00219   myGeomGrp->setFrameStyle( QFrame::NoFrame );
00220   QGridLayout* myGeomGrpLayout = new QGridLayout( myGeomGrp );
00221   myGeomGrpLayout->setMargin( 0 );
00222   myGeomGrpLayout->setSpacing( SPACING );
00223 
00224   for ( int i = Object; i <= Vertex2; i++ ) {
00225     mySelLbl[ i ] = new QLabel( myGeomGrp );
00226     mySelBtn[ i ] = new QPushButton( myGeomGrp );
00227     mySelBtn[ i ]->setIcon( iconSlct );
00228     mySelEdit[ i ] = new QLineEdit( myGeomGrp );
00229     mySelEdit[ i ]->setReadOnly( true );
00230     myGeomGrpLayout->addWidget( mySelLbl[ i ],  i - Object, 0 );
00231     myGeomGrpLayout->addWidget( mySelBtn[ i ],  i - Object, 1 );
00232     myGeomGrpLayout->addWidget( mySelEdit[ i ], i - Object, 2 );
00233   }
00234 
00235   // ... Widgets for refinement of existing mesh elements
00236 
00237   myRefineGrp = new QFrame( aPatGrp );
00238   myRefineGrp->setFrameStyle( QFrame::NoFrame );
00239 
00240   QGridLayout* myRefineGrpLayout = new QGridLayout( myRefineGrp );
00241   myRefineGrpLayout->setMargin( 0 );
00242   myRefineGrpLayout->setSpacing( SPACING );
00243 
00244   mySelLbl[ Ids ] = new QLabel( myRefineGrp );
00245   mySelBtn[ Ids ] = new QPushButton( myRefineGrp );
00246   mySelBtn[ Ids ]->setIcon( iconSlct );
00247   mySelEdit[ Ids ] = new QLineEdit( myRefineGrp );
00248 
00249   QLabel* aNodeLbl = new QLabel( tr( "NODE_1" ), myRefineGrp );
00250   myNode1          = new SalomeApp_IntSpinBox( myRefineGrp );
00251   myNode2Lbl       = new QLabel( tr( "NODE_2" ), myRefineGrp );
00252   myNode2          = new SalomeApp_IntSpinBox( myRefineGrp );
00253 
00254   myRefineGrpLayout->addWidget( mySelLbl[ Ids ],  0, 0 );
00255   myRefineGrpLayout->addWidget( mySelBtn[ Ids ],  0, 1 );
00256   myRefineGrpLayout->addWidget( mySelEdit[ Ids ], 0, 2 );
00257   myRefineGrpLayout->addWidget( aNodeLbl,         1, 0 );
00258   myRefineGrpLayout->addWidget( myNode1,          1, 1, 1, 2 );
00259   myRefineGrpLayout->addWidget( myNode2Lbl,       2, 0 );
00260   myRefineGrpLayout->addWidget( myNode2,          2, 1, 1, 2 );
00261 
00262   // ... reverse check box
00263   myReverseChk = new QCheckBox( tr( "REVERSE" ), aPatGrp );
00264 
00265   // ... CreatePoly check box
00266   myCreatePolygonsChk = new QCheckBox( tr( "CREATE_POLYGONS_NEAR_BOUNDARY" ), aPatGrp );
00267   myCreatePolyedrsChk = new QCheckBox( tr( "CREATE_POLYEDRS_NEAR_BOUNDARY" ), aPatGrp );
00268 
00269   // ... Pictures 2d and 3d
00270 
00271   myPicture2d = new SMESHGUI_PatternWidget( aPatGrp );
00272   myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
00273 
00274   myPicture3d = new QLabel( aPatGrp );
00275   myPicture3d->setPixmap( iconSample3d );
00276   myPicture3d->setScaledContents( false );
00277   myPicture3d->setAlignment( Qt::AlignCenter );
00278   myPicture3d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
00279 
00280   // ... preview check box
00281 
00282   myPreviewChk = new QCheckBox( tr( "PREVIEW" ), aPatGrp );
00283 
00284   // ... layout widgets 
00285 
00286   aPatGrpLayout->addWidget( aNameLab,            0, 0 );
00287   aPatGrpLayout->addWidget( myName,              0, 1 );
00288   aPatGrpLayout->addWidget( myOpenBtn,           0, 2 );
00289   aPatGrpLayout->addWidget( myNewBtn,            0, 3 );
00290   aPatGrpLayout->addWidget( myRefine,            1, 0, 1, 4 );
00291   aPatGrpLayout->addWidget( myRefine,            1, 0, 1, 4 );
00292   aPatGrpLayout->addWidget( myGeomGrp,           2, 0, 1, 4 );
00293   aPatGrpLayout->addWidget( myRefineGrp,         3, 0, 1, 4 );
00294   aPatGrpLayout->addWidget( myReverseChk,        4, 0, 1, 4 );
00295   aPatGrpLayout->addWidget( myCreatePolygonsChk, 5, 0, 1, 4 );
00296   aPatGrpLayout->addWidget( myCreatePolyedrsChk, 6, 0, 1, 4 );
00297   aPatGrpLayout->addWidget( myPicture2d,         7, 0, 1, 4 );
00298   aPatGrpLayout->addWidget( myPicture3d,         8, 0, 1, 4 );
00299   aPatGrpLayout->addWidget( myPreviewChk,        9, 0, 1, 4 );
00300 
00301   // main layout
00302   
00303   aMainGrpLayout->addWidget( aTypeGrp );
00304   aMainGrpLayout->addWidget( aMeshGrp );
00305   aMainGrpLayout->addWidget( aPatGrp );
00306 
00307   // Connect signals and slots
00308 
00309   connect(myTypeGrp, SIGNAL(buttonClicked(int)), SLOT(onTypeChanged(int)));
00310   connect(myOpenBtn, SIGNAL(clicked()),    SLOT(onOpen()));
00311   connect(myNewBtn,  SIGNAL(clicked()),    SLOT(onNew()));
00312 
00313   connect(myReverseChk, SIGNAL(toggled(bool)), SLOT(onReverse(bool)));
00314   connect(myPreviewChk, SIGNAL(toggled(bool)), SLOT(onPreview(bool)));
00315   connect(myRefine,     SIGNAL(toggled(bool)), SLOT(onModeToggled(bool)));
00316 
00317   connect(myNode1, SIGNAL(valueChanged(int)), SLOT(onNodeChanged(int)));
00318   connect(myNode2, SIGNAL(valueChanged(int)), SLOT(onNodeChanged(int)));
00319 
00320   connect(mySelEdit[Ids], SIGNAL(textChanged(const QString&)), SLOT(onTextChanged(const QString&)));
00321 
00322   QMap< int, QPushButton* >::iterator anIter;
00323   for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter)
00324     connect(*anIter, SIGNAL(clicked()), SLOT(onSelInputChanged()));
00325 
00326   return aMainGrp;
00327 }
00328 
00329 //=======================================================================
00330 // name    : SMESHGUI_MeshPatternDlg::createButtonFrame
00331 // Purpose : Create frame containing buttons
00332 //=======================================================================
00333 QWidget* SMESHGUI_MeshPatternDlg::createButtonFrame (QWidget* theParent)
00334 {
00335   QFrame* aFrame = new QFrame(theParent);
00336   aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
00337 
00338   myOkBtn     = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
00339   myApplyBtn  = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
00340   myCloseBtn  = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
00341   myHelpBtn   = new QPushButton(tr("SMESH_BUT_HELP"),  aFrame);
00342 
00343   QHBoxLayout* aLay = new QHBoxLayout( aFrame );
00344   aLay->setMargin( MARGIN );
00345   aLay->setSpacing( SPACING );
00346 
00347   aLay->addWidget(myOkBtn);
00348   aLay->addWidget(myApplyBtn);
00349   aLay->addSpacing( 10 );
00350   aLay->addStretch();
00351   aLay->addWidget(myCloseBtn);
00352   aLay->addWidget(myHelpBtn);
00353 
00354   connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
00355   connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
00356   connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
00357   connect(myHelpBtn,  SIGNAL(clicked()), SLOT(onHelp()));
00358 
00359   return aFrame;
00360 }
00361 
00362 //=======================================================================
00363 // name    : SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg
00364 // Purpose : Destructor
00365 //=======================================================================
00366 SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg()
00367 {
00368 }
00369 
00370 //=======================================================================
00371 // name    : SMESHGUI_MeshPatternDlg::Init
00372 // Purpose : Init dialog fields, connect signals and slots, show dialog
00373 //=======================================================================
00374 void SMESHGUI_MeshPatternDlg::Init()
00375 {
00376   myPattern = SMESH::GetPattern();
00377   myPreviewActor = 0;
00378   myIsCreateDlgOpen = false;
00379   mySelInput = Mesh;
00380   myType = -1;
00381   myNbPoints = -1;
00382   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00383   myMesh = SMESH::SMESH_Mesh::_nil();
00384 
00385   myMeshShape = GEOM::GEOM_Object::_nil();
00386   myGeomObj[ Object  ] = GEOM::GEOM_Object::_nil();
00387   myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();
00388   myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();
00389 
00390   // selection and SMESHGUI
00391   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
00392   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
00393   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
00394 
00395   myTypeGrp->button(Type_2d)->setChecked(true);
00396   onTypeChanged(Type_2d);
00397   onModeToggled(isRefine());
00398 
00399   updateGeometry();
00400 
00401   resize(100,100);
00402 
00403   activateSelection();
00404   onSelectionDone();
00405 
00406   this->show();
00407 }
00408 
00409 //=======================================================================
00410 // name    : SMESHGUI_MeshPatternDlg::isValid
00411 // Purpose : Verify validity of entry data
00412 //=======================================================================
00413 bool SMESHGUI_MeshPatternDlg::isValid (const bool theMess)
00414 {
00415   if (isRefine())
00416   {
00417     QString msg;
00418     bool ok = true;
00419     ok = myNode1->isValid( msg, theMess ) && ok;
00420     if (myType == Type_3d)
00421       ok = myNode2->isValid( msg, theMess ) && ok;
00422     if( !ok ) {
00423       if( theMess ) {
00424         QString str( tr( "SMESH_INCORRECT_INPUT" ) );
00425         if ( !msg.isEmpty() )
00426           str += "\n" + msg;
00427         SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
00428       }
00429       return false;
00430     }
00431   }
00432 
00433   QList<int> ids;
00434   if ((isRefine() &&
00435        (myMesh->_is_nil() || !getIds(ids) || getNode(false) < 0 ||
00436         (myType == Type_3d && (getNode(true) < 0 || getNode(false) == getNode(true)))))
00437       ||
00438       (!isRefine() &&
00439        (myMesh->_is_nil() || myMeshShape->_is_nil() || myGeomObj[ Object ]->_is_nil() ||
00440         myGeomObj[ Vertex1 ]->_is_nil() || (myType == Type_3d && myGeomObj[ Vertex2 ]->_is_nil()))))
00441   {
00442     if (theMess)
00443       SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
00444                                    tr("SMESHGUI_INVALID_PARAMETERS"));
00445     return false;
00446   }
00447 
00448   if ( myName->text().isEmpty() ) {
00449     if (theMess)
00450       SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
00451                                    tr("SMESHGUI_INVALID_PARAMETERS"));
00452     return false;
00453   }
00454 
00455   return true;
00456 }
00457 
00458 //=======================================================================
00459 // name    : SMESHGUI_MeshPatternDlg::onApply
00460 // Purpose : SLOT called when "Apply" button pressed.
00461 //=======================================================================
00462 bool SMESHGUI_MeshPatternDlg::onApply()
00463 {
00464   try {
00465     if (!isValid())
00466       return false;
00467 
00468     erasePreview();
00469 
00470     if (isRefine()) { // Refining existing mesh elements
00471       QList<int> ids;
00472       getIds(ids);
00473       SMESH::long_array_var varIds = new SMESH::long_array();
00474       varIds->length(ids.count());
00475       int i = 0;
00476       for (QList<int>::iterator it = ids.begin(); it != ids.end(); ++it)
00477         varIds[i++] = *it;
00478       myType == Type_2d
00479         ? myPattern->ApplyToMeshFaces  (myMesh, varIds, getNode(false), myReverseChk->isChecked())
00480         : myPattern->ApplyToHexahedrons(myMesh, varIds, getNode(false), getNode(true));
00481 
00482       QStringList aParameters;
00483       aParameters << myNode1->text();
00484       if(myType == Type_3d )
00485         aParameters << myNode2->text();
00486       myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
00487 
00488     } else { // Applying a pattern to geometrical object
00489       if (myType == Type_2d)
00490         myPattern->ApplyToFace(myGeomObj[Object], myGeomObj[Vertex1], myReverseChk->isChecked());
00491       else
00492         myPattern->ApplyTo3DBlock(myGeomObj[Object], myGeomObj[Vertex1], myGeomObj[Vertex2]);
00493     }
00494 
00495     bool toCreatePolygons = myCreatePolygonsChk->isChecked();
00496     bool toCreatePolyedrs = myCreatePolyedrsChk->isChecked();
00497     if ( myPattern->MakeMesh( myMesh, toCreatePolygons, toCreatePolyedrs ) ) {
00498       //mySelectionMgr->clearSelected();
00499       bool autoUpdate = SMESHGUI::automaticUpdate();
00500       if (!isRefine() && autoUpdate) {
00501         _PTR(SObject) aSO = SMESH::FindSObject(myMesh.in());
00502         SMESH_Actor* anActor = SMESH::FindActorByEntry(aSO->GetID().c_str());
00503         if (!anActor) {
00504           anActor = SMESH::CreateActor(aSO->GetStudy(), aSO->GetID().c_str());
00505           if (anActor) {
00506             SMESH::DisplayActor(SMESH::GetActiveWindow(), anActor);
00507             SMESH::FitAll();
00508           }
00509         }
00510       }
00511       mySelectionMgr->clearSelected();
00512       SMESH::UpdateView();
00513       SMESHGUI::Modified();
00514 
00515       mySMESHGUI->updateObjBrowser(true);
00516 
00517       mySelEdit[ Ids ]->setText("");
00518 
00519       return true;
00520     } else {
00521       SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
00522                                    tr("SMESH_OPERATION_FAILED"));
00523       return false;
00524     }
00525   } catch (const SALOME::SALOME_Exception& S_ex) {
00526     SalomeApp_Tools::QtCatchCorbaException(S_ex);
00527   } catch (...) {
00528   }
00529 
00530   return false;
00531 }
00532 
00533 //=======================================================================
00534 // name    : SMESHGUI_MeshPatternDlg::onOk
00535 // Purpose : SLOT called when "Ok" button pressed.
00536 //=======================================================================
00537 void SMESHGUI_MeshPatternDlg::onOk()
00538 {
00539   if (onApply())
00540     onClose();
00541 }
00542 
00543 //=======================================================================
00544 // name    : SMESHGUI_MeshPatternDlg::onClose
00545 // Purpose : SLOT called when "Close" button pressed. Close dialog
00546 //=======================================================================
00547 void SMESHGUI_MeshPatternDlg::onClose()
00548 {
00549   mySelectionMgr->clearFilters();
00550   SMESH::SetPickable();
00551   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00552     aViewWindow->SetSelectionMode(ActorSelection);
00553   disconnect(mySelectionMgr, 0, this, 0);
00554   disconnect(mySMESHGUI, 0, this, 0);
00555   mySMESHGUI->ResetState();
00556   erasePreview();
00557   reject();
00558 }
00559 
00560 //=================================================================================
00561 // function : onHelp()
00562 // purpose  :
00563 //=================================================================================
00564 void SMESHGUI_MeshPatternDlg::onHelp()
00565 {
00566   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00567   if (app) 
00568     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00569   else {
00570                 QString platform;
00571 #ifdef WIN32
00572                 platform = "winapplication";
00573 #else
00574                 platform = "application";
00575 #endif
00576     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00577                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00578                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00579                                                                  platform)).
00580                              arg(myHelpFileName));
00581   }
00582 }
00583 
00584 //=======================================================================
00585 // name    : SMESHGUI_MeshPatternDlg::onSelectionDone
00586 // Purpose : SLOT called when selection changed
00587 //=======================================================================
00588 void SMESHGUI_MeshPatternDlg::onSelectionDone()
00589 {
00590   if (myBusy)
00591     return;
00592 
00593   try {
00594     if (mySelInput == Mesh) {
00595       SALOME_ListIO aList;
00596       mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00597       if (aList.Extent() != 1)
00598         return;
00599 
00600       // Retrieve mesh from selection
00601       Handle(SALOME_InteractiveObject) anIO = aList.First();
00602       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
00603       if (aMesh->_is_nil())
00604         return;
00605 
00606       // Get geom object corresponding to the mesh
00607       _PTR(SObject) aSO = SMESH::FindSObject(aMesh.in());
00608       myMeshShape = SMESH::GetGeom(aSO);
00609 
00610       // Clear fields of geom objects if mesh was changed
00611       if (myMesh != aMesh) {
00612         for (int i = Object; i <= Ids; i++) {
00613           myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
00614           mySelEdit[ i ]->setText("");
00615         }
00616       }
00617 
00618       myMesh = aMesh;
00619 
00620       // Set name of mesh in line edit
00621       QString aName;
00622       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
00623       mySelEdit[ Mesh ]->setText(aName);
00624 
00625     } else if (mySelInput == Ids) {
00626       SALOME_ListIO aList;
00627       mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00628       if (aList.Extent() != 1)
00629         return;
00630 
00631       QString anIds;
00632       if (!SMESH::GetNameOfSelectedElements(mySelector, aList.First(), anIds))
00633         anIds = "";
00634 
00635       myBusy = true;
00636       mySelEdit[ Ids ]->setText(anIds);
00637       myBusy = false;
00638 
00639     } else {
00640       SALOME_ListIO aList;
00641       mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
00642       if (aList.Extent() != 1)
00643         return;
00644 
00645       // Get geom object from selection
00646       Handle(SALOME_InteractiveObject) anIO = aList.First();
00647       GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
00648       if (anObj->_is_nil())
00649         return;
00650 
00651       // Clear fields of vertexes if face or 3d block was changed
00652       if (anObj != myGeomObj[ mySelInput ] && mySelInput == Object) {
00653         for (int i = Vertex1; i <= Vertex2; i++) {
00654           myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
00655           mySelEdit[ i ]->setText("");
00656         }
00657       }
00658 
00659       myGeomObj[ mySelInput ] = anObj;
00660 
00661       // Set name of geom object in line edit
00662       QString aName;
00663       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
00664       mySelEdit[ mySelInput ]->setText(aName);
00665     }
00666   } catch (const SALOME::SALOME_Exception& S_ex) {
00667     SalomeApp_Tools::QtCatchCorbaException(S_ex);
00668     resetSelInput();
00669   } catch (...) {
00670     resetSelInput();
00671   }
00672 
00673   updateWgState();
00674   displayPreview();
00675 }
00676 
00677 //=======================================================================
00678 // name    : SMESHGUI_MeshPatternDlg::resetSelInput
00679 // Purpose : Reset fields corresponding to the current selection input
00680 //=======================================================================
00681 void SMESHGUI_MeshPatternDlg::resetSelInput()
00682 {
00683   if (mySelInput == Mesh)
00684   {
00685     myMesh = SMESH::SMESH_Mesh::_nil();
00686     myMeshShape = GEOM::GEOM_Object::_nil();
00687   }
00688 
00689   else
00690     myGeomObj[ mySelInput ] = GEOM::GEOM_Object::_nil();
00691 
00692   mySelEdit[ mySelInput ]->setText("");
00693 }
00694 
00695 //=======================================================================
00696 // name    : SMESHGUI_MeshPatternDlg::onDeactivate
00697 // Purpose : SLOT called when dialog must be deativated
00698 //=======================================================================
00699 void SMESHGUI_MeshPatternDlg::onDeactivate()
00700 {
00701   mySelectionMgr->clearFilters();
00702   //if (myReverseChk->isChecked())
00703   //  erasePreview();
00704   disconnect(mySelectionMgr, 0, this, 0);
00705   setEnabled(false);
00706 }
00707 
00708 //=======================================================================
00709 // name    : SMESHGUI_MeshPatternDlg::enterEvent
00710 // Purpose : Event filter
00711 //=======================================================================
00712 void SMESHGUI_MeshPatternDlg::enterEvent (QEvent*)
00713 {
00714   if (myIsCreateDlgOpen)
00715     return;
00716 
00717   if (myReverseChk->isChecked())
00718     displayPreview();
00719   mySMESHGUI->EmitSignalDeactivateDialog();
00720   setEnabled(true);
00721   activateSelection();
00722   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
00723   onTextChanged(mySelEdit[Ids]->text());
00724 }
00725 
00726 //=======================================================================
00727 // name    : SMESHGUI_MeshPatternDlg::closeEvent
00728 // Purpose :
00729 //=======================================================================
00730 void SMESHGUI_MeshPatternDlg::closeEvent (QCloseEvent*)
00731 {
00732   onClose();
00733 }
00734 
00735 //=======================================================================
00736 // name    : SMESHGUI_MeshPatternDlg::onSelInputChanged
00737 // Purpose : SLOT. Called when -> button clicked.
00738 //           Change current selection input field
00739 //=======================================================================
00740 void SMESHGUI_MeshPatternDlg::onSelInputChanged()
00741 {
00742   const QObject* aSender = sender();
00743   for (int i = Mesh; i <= Ids; i++)
00744     if (aSender == mySelBtn[ i ])
00745       mySelInput = i;
00746 
00747   activateSelection();
00748   onSelectionDone();
00749 }
00750 
00751 //=======================================================================
00752 // name    : SMESHGUI_MeshPatternDlg::prepareFilters
00753 // Purpose : Prepare filters for dialog
00754 //=======================================================================
00755 QStringList SMESHGUI_MeshPatternDlg::prepareFilters() const
00756 {
00757   static QStringList aList;
00758   if (aList.isEmpty())
00759   {
00760     aList.append(tr("PATTERN_FILT"));
00761     //aList.append(tr("ALL_FILES_FILTER"));
00762   }
00763 
00764   return aList;
00765 }
00766 
00767 //=======================================================================
00768 // name    : SMESHGUI_MeshPatternDlg::autoExtension
00769 // Purpose : Append extension to the file name
00770 //=======================================================================
00771 QString SMESHGUI_MeshPatternDlg::autoExtension (const QString& theFileName) const
00772 {
00773   QString anExt = theFileName.section('.', -1);
00774   return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName;
00775 }
00776 
00777 //=======================================================================
00778 // name    : SMESHGUI_MeshPatternDlg::onOpen
00779 // Purpose : SLOT. Called when "Open" button clicked.
00780 //           Displays file open dialog
00781 //=======================================================================
00782 void SMESHGUI_MeshPatternDlg::onOpen()
00783 {
00784   SUIT_FileDlg* aDlg = new SUIT_FileDlg (this, true);
00785   aDlg->setWindowTitle(tr("LOAD_PATTERN"));
00786   aDlg->setFileMode(QFileDialog::ExistingFile);
00787   aDlg->setFilters(prepareFilters());
00788   if (!myName->text().isEmpty())
00789     aDlg->selectFile(myName->text() + ".smp");
00790   QPushButton* anOkBtn = qFindChild<QPushButton*>( aDlg, "OK" );
00791   if (anOkBtn != 0)
00792     anOkBtn->setText(tr("SMESH_BUT_OK"));
00793 
00794   if (aDlg->exec() != Accepted)
00795     return;
00796 
00797   QString fName = aDlg->selectedFile();
00798   if (fName.isEmpty())
00799     return;
00800 
00801   if (QFileInfo(fName).suffix().isEmpty())
00802     fName = autoExtension(fName);
00803 
00804   fName = QDir::convertSeparators(fName);
00805 
00806   QString prev = QDir::convertSeparators(myName->text());
00807   if (prev == fName)
00808     return;
00809 
00810   // Read string from file
00811   QFile aFile(fName);
00812   if (!aFile.open(QIODevice::ReadOnly)) {
00813     SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
00814                                  tr("ERROR_OF_OPENING"));
00815     return;
00816   }
00817 
00818   QByteArray aDataArray = aFile.readAll();
00819   if (aDataArray.isEmpty()) {
00820     SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
00821                                  tr("ERROR_OF_READING"));
00822     return;
00823   }
00824 
00825   if (loadFromFile(aDataArray))
00826     myName->setText(QFileInfo(fName).completeBaseName());
00827 
00828   updateWgState();
00829   displayPreview();
00830 }
00831 
00832 //=======================================================================
00833 // name    : SMESHGUI_MeshPatternDlg::onCloseCreationDlg
00834 // Purpose : SLOT. Called when "Pattern creation" dialog closed with "Close"
00835 //=======================================================================
00836 void SMESHGUI_MeshPatternDlg::onCloseCreationDlg()
00837 {
00838   setEnabled(true);
00839   myIsCreateDlgOpen = false;
00840 }
00841 
00842 //=======================================================================
00843 // name    : SMESHGUI_MeshPatternDlg::onOkCreationDlg
00844 // Purpose : SLOT. Called when "Pattern creation" dialog closed with OK
00845 //           or SAVE buttons. Initialize myPattern field. Redisplay preview
00846 //=======================================================================
00847 void SMESHGUI_MeshPatternDlg::onOkCreationDlg()
00848 {
00849   myPattern = SMESH::SMESH_Pattern::_duplicate(myCreationDlg->GetPattern());
00850   myName->setText(myCreationDlg->GetPatternName());
00851 
00852   updateWgState();
00853   displayPreview();
00854 
00855   setEnabled(true);
00856   myIsCreateDlgOpen = false;
00857 }
00858 
00859 //=======================================================================
00860 // name    : SMESHGUI_MeshPatternDlg::onNew
00861 // Purpose : SLOT. Called when "New..." button clicked. Create new pattern
00862 //=======================================================================
00863 void SMESHGUI_MeshPatternDlg::onNew()
00864 {
00865   setEnabled(false);
00866   myIsCreateDlgOpen = true;
00867   if (myCreationDlg == 0)
00868   {
00869     myCreationDlg = new SMESHGUI_CreatePatternDlg( mySMESHGUI, myType);
00870     connect(myCreationDlg, SIGNAL(NewPattern()), SLOT(onOkCreationDlg()));
00871     connect(myCreationDlg, SIGNAL(Close()), SLOT(onCloseCreationDlg()));
00872   }
00873   else
00874     myCreationDlg->Init(myType);
00875 
00876   myCreationDlg->SetMesh(myMesh);
00877   myCreationDlg->show();
00878 }
00879 
00880 //=======================================================================
00881 // name    : SMESHGUI_MeshPatternDlg::onReverse
00882 // Purpose : SLOT. Called when state of "Reverse order..." checkbox chaged
00883 //           Calculate new points of the mesh to be created. Redisplay preview
00884 //=======================================================================
00885 void SMESHGUI_MeshPatternDlg::onReverse (bool)
00886 {
00887   displayPreview();
00888 }
00889 
00890 //=======================================================================
00891 
00892 // name    : SMESHGUI_MeshPatternDlg::onPreview
00893 // Purpose : SLOT. Called when state of "Preview" checkbox changed
00894 //           Display/Erase preview
00895 //=======================================================================
00896 void SMESHGUI_MeshPatternDlg::onPreview (bool)
00897 {
00898   displayPreview();
00899 }
00900 
00901 //=======================================================================
00902 // name    : SMESHGUI_MeshPatternDlg::displayPreview
00903 // Purpose : Display preview
00904 //=======================================================================
00905 void SMESHGUI_MeshPatternDlg::displayPreview()
00906 {
00907   try {
00908     // Redisplay preview in dialog
00909     SMESH::point_array_var pnts = myPattern->GetPoints();
00910     SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
00911     SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints(false);
00912 
00913     if (pnts->length()       == 0 ||
00914         keyPoints->length()  == 0 ||
00915         elemPoints->length() == 0) {
00916       erasePreview();
00917       return;
00918     } else {
00919       PointVector aPoints(pnts->length());
00920       QVector<int> aKeyPoints(keyPoints->length());
00921       ConnectivityVector anElemPoints(elemPoints->length());
00922 
00923       for (int i = 0, n = pnts->length(); i < n; i++)
00924         aPoints[ i ] = pnts[ i ];
00925 
00926       for (int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++)
00927         aKeyPoints[ i2 ] = keyPoints[ i2 ];
00928 
00929       for (int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++) {
00930         QVector<int> aVec(elemPoints[ i3 ].length());
00931         for (int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++)
00932           aVec[ i4 ] = elemPoints[ i3 ][ i4 ];
00933 
00934         anElemPoints[ i3 ] = aVec;
00935       }
00936 
00937       myPicture2d->SetPoints(aPoints, aKeyPoints, anElemPoints);
00938     }
00939 
00940     // Redisplay preview in 3D viewer
00941     if (myPreviewActor != 0) {
00942       if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView()) {
00943         vf->RemoveActor(myPreviewActor);
00944         vf->Repaint();
00945       }
00946       myPreviewActor->Delete();
00947       myPreviewActor = 0;
00948     }
00949 
00950     if (!myPreviewChk->isChecked() || !isValid(false))
00951       return;
00952 
00953     vtkUnstructuredGrid* aGrid = getGrid();
00954     if (aGrid == 0)
00955       return;
00956 
00957     // Create and display actor
00958     vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
00959     aMapper->SetInput(aGrid);
00960 
00961     myPreviewActor = SALOME_Actor::New();
00962     myPreviewActor->PickableOff();
00963     myPreviewActor->SetMapper(aMapper);
00964 
00965     vtkProperty* aProp = vtkProperty::New();
00966     aProp->SetRepresentationToWireframe();
00967     aProp->SetColor(250, 0, 250);
00968     if (SMESH::FindActorByObject(myMesh))
00969       aProp->SetLineWidth( SMESH::GetFloat( "SMESH:element_width", 1 ) + 1 );
00970     else
00971       aProp->SetLineWidth(1);
00972     myPreviewActor->SetProperty(aProp);
00973 
00974     myPreviewActor->SetRepresentation(3);
00975 
00976     SMESH::GetCurrentVtkView()->AddActor(myPreviewActor);
00977     SMESH::GetCurrentVtkView()->Repaint();
00978 
00979     aProp->Delete();
00980     aGrid->Delete();
00981   } catch (const SALOME::SALOME_Exception& S_ex) {
00982     SalomeApp_Tools::QtCatchCorbaException(S_ex);
00983     erasePreview();
00984   } catch (...) {
00985     erasePreview();
00986   }
00987 }
00988 
00989 //=======================================================================
00990 // name    : SMESHGUI_MeshPatternDlg::erasePreview
00991 // Purpose : Erase preview
00992 //=======================================================================
00993 void SMESHGUI_MeshPatternDlg::erasePreview()
00994 {
00995   // Erase preview in 2D viewer
00996   myPicture2d->SetPoints(PointVector(), QVector<int>(), ConnectivityVector());
00997 
00998   // Erase preview in 3D viewer
00999   if (myPreviewActor == 0)
01000     return;
01001 
01002 
01003   if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView())
01004   {
01005     vf->RemoveActor(myPreviewActor);
01006     vf->Repaint();
01007   }
01008   myPreviewActor->Delete();
01009   myPreviewActor = 0;
01010 }
01011 
01012 //=======================================================================
01013 // name    : SMESHGUI_MeshPatternDlg::updateWgState
01014 // Purpose : Enable/disable selection widgets
01015 //=======================================================================
01016 void SMESHGUI_MeshPatternDlg::updateWgState()
01017 {
01018   if (myMesh->_is_nil()) {
01019     for (int i = Object; i <= Ids; i++) {
01020       mySelBtn [ i ]->setEnabled(false);
01021       mySelEdit[ i ]->setEnabled(false);
01022       mySelEdit[ i ]->setText("");
01023     }
01024     myNode1->setEnabled(false);
01025     myNode2->setEnabled(false);
01026     myNode1->setRange(0, 0);
01027     myNode2->setRange(0, 0);
01028   } else {
01029     mySelBtn [ Object ]->setEnabled(true);
01030     mySelEdit[ Object ]->setEnabled(true);
01031     mySelBtn [ Ids ]   ->setEnabled(true);
01032     mySelEdit[ Ids ]   ->setEnabled(true);
01033 
01034     if (myGeomObj[ Object ]->_is_nil()) {
01035       for (int i = Vertex1; i <= Vertex2; i++) {
01036         mySelBtn [ i ]->setEnabled(false);
01037         mySelEdit[ i ]->setEnabled(false);
01038         mySelEdit[ i ]->setText("");
01039       }
01040     } else {
01041       for (int i = Object; i <= Vertex2; i++) {
01042         mySelBtn [ i ]->setEnabled(true);
01043         mySelEdit[ i ]->setEnabled(true);
01044       }
01045     }
01046 
01047     QList<int> ids;
01048     if (!CORBA::is_nil(myPattern)/* && getIds(ids)*/) {
01049       SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
01050       if (keyPoints->length()) {
01051         myNode1->setEnabled(true);
01052         myNode2->setEnabled(true);
01053         myNode1->setRange(1, keyPoints->length());
01054         myNode2->setRange(1, keyPoints->length());
01055         return;
01056       }
01057     }
01058 
01059     myNode1->setEnabled(false);
01060     myNode2->setEnabled(false);
01061     myNode1->setRange(0, 0);
01062     myNode2->setRange(0, 0);
01063   }
01064 }
01065 
01066 //=======================================================================
01067 // name    : SMESHGUI_MeshPatternDlg::activateSelection
01068 // Purpose : Activate selection in accordance with current selection input
01069 //=======================================================================
01070 void SMESHGUI_MeshPatternDlg::activateSelection()
01071 {
01072   mySelectionMgr->clearFilters();
01073   if (mySelInput == Ids) {
01074     SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
01075     if (anActor)
01076       SMESH::SetPickable(anActor);
01077 
01078     if (myType == Type_2d)
01079       {
01080         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01081           aViewWindow->SetSelectionMode(FaceSelection);
01082       }
01083     else
01084       {
01085         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01086           aViewWindow->SetSelectionMode(CellSelection);
01087       }
01088   }
01089   else {
01090     SMESH::SetPickable();
01091     //mySelectionMgr->setSelectionModes(ActorSelection);
01092     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01093       aViewWindow->SetSelectionMode(ActorSelection);
01094   }
01095 
01096   if (mySelInput == Object && !myMeshShape->_is_nil()) {
01097     if (myType == Type_2d) {
01098       if (myNbPoints > 0)
01099         mySelectionMgr->installFilter
01100           (new SMESH_NumberFilter ("GEOM", TopAbs_VERTEX, myNbPoints, TopAbs_FACE, myMeshShape));
01101       else
01102         mySelectionMgr->installFilter
01103           (new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, myNbPoints, TopAbs_FACE, myMeshShape));
01104     } else {
01105       TColStd_MapOfInteger aTypes;
01106       aTypes.Add(TopAbs_SHELL);
01107       aTypes.Add(TopAbs_SOLID);
01108       mySelectionMgr->installFilter
01109         (new SMESH_NumberFilter ("GEOM", TopAbs_FACE, 6, aTypes, myMeshShape, true));
01110     }
01111   } else if ((mySelInput == Vertex1 || mySelInput == Vertex2) && !myGeomObj[ Object ]->_is_nil()) {
01112     mySelectionMgr->installFilter
01113       (new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX, myGeomObj[ Object ]));
01114   } else {
01115   }
01116 }
01117 
01118 //=======================================================================
01119 // name    : SMESHGUI_MeshPatternDlg::loadFromFile
01120 // Purpose : Load pattern from file
01121 //=======================================================================
01122 bool SMESHGUI_MeshPatternDlg::loadFromFile (const QString& theName)
01123 {
01124   try {
01125     SMESH::SMESH_Pattern_var aPattern = SMESH::GetPattern();
01126 
01127     if (!aPattern->LoadFromFile(theName.toLatin1().data()) ||
01128         (myType == Type_2d && !aPattern->Is2D())) {
01129       SMESH::SMESH_Pattern::ErrorCode aCode = aPattern->GetErrorCode();
01130       QString aMess;
01131       if      (aCode == SMESH::SMESH_Pattern::ERR_READ_NB_POINTS     ) aMess = tr("ERR_READ_NB_POINTS");
01132       else if (aCode == SMESH::SMESH_Pattern::ERR_READ_POINT_COORDS  ) aMess = tr("ERR_READ_POINT_COORDS");
01133       else if (aCode == SMESH::SMESH_Pattern::ERR_READ_TOO_FEW_POINTS) aMess = tr("ERR_READ_TOO_FEW_POINTS");
01134       else if (aCode == SMESH::SMESH_Pattern::ERR_READ_3D_COORD      ) aMess = tr("ERR_READ_3D_COORD");
01135       else if (aCode == SMESH::SMESH_Pattern::ERR_READ_NO_KEYPOINT   ) aMess = tr("ERR_READ_NO_KEYPOINT");
01136       else if (aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_INDEX     ) aMess = tr("ERR_READ_BAD_INDEX");
01137       else if (aCode == SMESH::SMESH_Pattern::ERR_READ_ELEM_POINTS   ) aMess = tr("ERR_READ_ELEM_POINTS");
01138       else if (aCode == SMESH::SMESH_Pattern::ERR_READ_NO_ELEMS      ) aMess = tr("ERR_READ_NO_ELEMS");
01139       else if (aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_KEY_POINT ) aMess = tr("ERR_READ_BAD_KEY_POINT");
01140       else                                                             aMess = tr("ERROR_OF_LOADING");
01141 
01142       SUIT_MessageBox::information(this, tr("SMESH_ERROR"), aMess);
01143       return false;
01144     } else {
01145       myPattern = aPattern;
01146       return true;
01147     }
01148   } catch (const SALOME::SALOME_Exception& S_ex) {
01149     SalomeApp_Tools::QtCatchCorbaException(S_ex);
01150     SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
01151                                  tr("ERROR_OF_LOADING") );
01152     return false;
01153   }
01154 }
01155 
01156 //=======================================================================
01157 // name    : SMESHGUI_MeshPatternDlg::onTypeChanged
01158 // Purpose : SLOT. Called when pattern type changed.
01159 //           Change dialog's look and feel
01160 //=======================================================================
01161 void SMESHGUI_MeshPatternDlg::onTypeChanged (int theType)
01162 {
01163   if (myType == theType)
01164     return;
01165 
01166   myType = theType;
01167 
01168   myNbPoints = -1;
01169   myGeomObj[ Object  ] = GEOM::GEOM_Object::_nil();
01170   myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();
01171   myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();
01172   myPattern = SMESH::GetPattern();
01173 
01174   myName->setText("");
01175   mySelEdit[ Object  ]->setText("");
01176   mySelEdit[ Vertex1 ]->setText("");
01177   mySelEdit[ Vertex2 ]->setText("");
01178   mySelEdit[ Ids ]    ->setText("");
01179   myCreatePolygonsChk->show();
01180   myCreatePolyedrsChk->show();
01181 
01182   if (theType == Type_2d) {
01183     // Geom widgets
01184     mySelLbl [ Vertex2 ]->hide();
01185     mySelBtn [ Vertex2 ]->hide();
01186     mySelEdit[ Vertex2 ]->hide();
01187     myReverseChk->show();
01188     myPicture2d->show();
01189     myPicture3d->hide();
01190     mySelLbl[ Object  ]->setText(tr("FACE"));
01191     mySelLbl[ Vertex1 ]->setText(tr("VERTEX"));
01192     // Refine widgets
01193     mySelLbl[ Ids ]->setText(tr("MESH_FACES"));
01194     myNode2Lbl->hide();
01195     myNode2   ->hide();
01196   } else {
01197     // Geom widgets
01198     mySelLbl [ Vertex2 ]->show();
01199     mySelBtn [ Vertex2 ]->show();
01200     mySelEdit[ Vertex2 ]->show();
01201     myReverseChk->hide();
01202     myPicture2d->hide();
01203     myPicture3d->show();
01204     mySelLbl[ Object  ]->setText(tr("3D_BLOCK"));
01205     mySelLbl[ Vertex1 ]->setText(tr("VERTEX1"));
01206     mySelLbl[ Vertex2 ]->setText(tr("VERTEX2"));
01207     // Refine widgets
01208     mySelLbl[ Ids ]->setText(tr("MESH_VOLUMES"));
01209     myNode2Lbl->show();
01210     myNode2   ->show();
01211   }
01212 
01213   mySelInput = Mesh;
01214   activateSelection();
01215   updateWgState();
01216   displayPreview();
01217 }
01218 
01219 //=======================================================================
01220 // name    : SMESHGUI_MeshPatternDlg::getGrid
01221 // Purpose : Get unstructured grid for pattern
01222 //=======================================================================
01223 vtkUnstructuredGrid* SMESHGUI_MeshPatternDlg::getGrid()
01224 {
01225   try {
01226     // Get points from pattern
01227     SMESH::point_array_var pnts;
01228     QList<int> ids;
01229     if (isRefine() && getIds(ids)) {
01230       SMESH::long_array_var varIds = new SMESH::long_array();
01231       varIds->length(ids.count());
01232       int i = 0;
01233       for (QList<int>::iterator it = ids.begin(); it != ids.end(); ++it)
01234         varIds[i++] = *it;
01235       pnts = myType == Type_2d
01236         ? myPattern->ApplyToMeshFaces  (myMesh, varIds, getNode(false), myReverseChk->isChecked())
01237         : myPattern->ApplyToHexahedrons(myMesh, varIds, getNode(false), getNode(true));
01238     } else {
01239       pnts = myType == Type_2d
01240         ? myPattern->ApplyToFace   (myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked())
01241       : myPattern->ApplyTo3DBlock(myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ]);
01242     }
01243 
01244     SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints(true);
01245 
01246     if (pnts->length() == 0 || elemPoints->length() == 0)
01247       return 0;
01248 
01249     // to do : to be removed /////////////////////////////////////////////
01250 
01251 #ifdef DEB_SLN
01252     for (int i1 = 0, n1 = pnts->length(); i1 < n1; i1++)
01253       printf("%d: %g %g %g\n", i1, pnts[ i1 ].x, pnts[ i1 ].y, pnts[ i1 ].z);
01254 
01255     printf("\nELEMENTS : \n");
01256     for (int i2 = 0, n2 = elemPoints->length(); i2 < n2; i2++)
01257     {
01258 
01259       printf("%d: ", i2);
01260       for (int i3 = 0, n3 = elemPoints[ i2 ].length(); i3 < n3; i3++)
01261         printf("%d ", elemPoints[ i2 ][ i3 ]);
01262 
01263       printf("\n");
01264 
01265     }
01266 #endif
01267 
01268 
01269     // Calculate number of points used for cell
01270     vtkIdType aNbCells = elemPoints->length();
01271     vtkIdType aCellsSize = 0;
01272     for (int i = 0, n = elemPoints->length(); i < n; i++)
01273       aCellsSize += elemPoints[ i ].length();
01274 
01275     // Create unstructured grid and other  usefull arrays
01276     vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
01277 
01278     vtkCellArray* aConnectivity = vtkCellArray::New();
01279     aConnectivity->Allocate(aCellsSize, 0);
01280 
01281     vtkPoints* aPoints = vtkPoints::New();
01282     aPoints->SetNumberOfPoints(pnts->length());
01283 
01284     vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
01285     aCellTypesArray->SetNumberOfComponents(1);
01286     aCellTypesArray->Allocate(aNbCells * aCellTypesArray->GetNumberOfComponents());
01287 
01288     vtkIdList *anIdList = vtkIdList::New();
01289 
01290     // Fill array of points
01291     for (int p = 0, nbPnt = pnts->length(); p < nbPnt; p++)
01292       aPoints->SetPoint(p, pnts[ p ].x, pnts[ p ].y, pnts[ p ].z);
01293 
01294     for (int e = 0, nbElem = elemPoints->length(); e < nbElem; e++) {
01295       int nbPoints = elemPoints[ e ].length();
01296       anIdList->SetNumberOfIds(nbPoints);
01297       for (int i = 0; i < nbPoints; i++)
01298         anIdList->SetId(i, elemPoints[ e ][ i ]);
01299 
01300       aConnectivity->InsertNextCell(anIdList);
01301 
01302       if      (nbPoints == 3) aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
01303       else if (nbPoints == 5) aCellTypesArray->InsertNextValue(VTK_PYRAMID);
01304       else if (nbPoints == 6) aCellTypesArray->InsertNextValue(VTK_WEDGE);
01305       else if (nbPoints == 8) aCellTypesArray->InsertNextValue(VTK_HEXAHEDRON);
01306       else if (nbPoints == 4 && myType == Type_2d) aCellTypesArray->InsertNextValue(VTK_QUAD);
01307       else if (nbPoints == 4 && myType == Type_3d) aCellTypesArray->InsertNextValue(VTK_TETRA);
01308       else aCellTypesArray->InsertNextValue(VTK_EMPTY_CELL);
01309     }
01310 
01311     VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
01312     aCellLocationsArray->SetNumberOfComponents(1);
01313     aCellLocationsArray->SetNumberOfTuples(aNbCells);
01314 
01315     aConnectivity->InitTraversal();
01316     for (vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell(npts, pts); idType++)
01317       aCellLocationsArray->SetValue(idType, aConnectivity->GetTraversalLocation(npts));
01318 
01319     aGrid->SetPoints(aPoints);
01320     aGrid->SetCells(aCellTypesArray, aCellLocationsArray,aConnectivity);
01321 
01322     aConnectivity->Delete();
01323     aPoints->Delete();
01324     aCellTypesArray->Delete();
01325     anIdList->Delete();
01326     aCellLocationsArray->Delete();
01327 
01328     return aGrid;
01329   } catch (...) {
01330     return 0;
01331   }
01332 }
01333 
01334 //=======================================================================
01335 // name    : onModeToggled
01336 // Purpose :
01337 //=======================================================================
01338 void SMESHGUI_MeshPatternDlg::onModeToggled (bool on)
01339 {
01340   on ? myRefineGrp->show() : myRefineGrp->hide();
01341   on ? myGeomGrp->hide()   : myGeomGrp->show();
01342 
01343   displayPreview();
01344 }
01345 
01346 //=======================================================================
01347 // name    : isRefine
01348 // Purpose :
01349 //=======================================================================
01350 bool SMESHGUI_MeshPatternDlg::isRefine() const
01351 {
01352   return myRefine->isChecked();
01353 }
01354 
01355 //=======================================================================
01356 // name    : onTextChanged
01357 // Purpose :
01358 //=======================================================================
01359 void SMESHGUI_MeshPatternDlg::onTextChanged (const QString& theNewText)
01360 {
01361   if (myBusy || !isRefine())
01362     return;
01363 
01364   myBusy = true;
01365 
01366   if (mySelInput != Ids) {
01367     mySelInput = Ids;
01368     activateSelection();
01369   }
01370 
01371   // hilight entered elements/nodes
01372   SMDS_Mesh* aMesh = 0;
01373   SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
01374   if (anActor)
01375     aMesh = anActor->GetObject()->GetMesh();
01376 
01377   if (aMesh) {
01378     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
01379 
01380     TColStd_MapOfInteger newIndices;
01381 
01382     for (int i = 0; i < aListId.count(); i++) {
01383       const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
01384       if (e && e->GetType() == (myType == Type_2d ? SMDSAbs_Face : SMDSAbs_Volume))
01385         newIndices.Add(e->GetID());
01386     }
01387     mySelector->AddOrRemoveIndex( anActor->getIO(), newIndices, false);
01388     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01389       aViewWindow->highlight( anActor->getIO(), true, true );
01390   }
01391 
01392   myBusy = false;
01393 
01394   displayPreview();
01395 }
01396 
01397 //=======================================================================
01398 // name    : onNodeChanged
01399 // Purpose :
01400 //=======================================================================
01401 void SMESHGUI_MeshPatternDlg::onNodeChanged (int value)
01402 {
01403   if (myType == Type_3d) {
01404     SalomeApp_IntSpinBox* first = (SalomeApp_IntSpinBox*)sender();
01405     SalomeApp_IntSpinBox* second = first == myNode1 ? myNode2 : myNode1;
01406     int secondVal = second->value();
01407     if (secondVal == value) {
01408       secondVal = value == second->maximum() ? second->minimum() : value + 1;
01409       bool blocked = second->signalsBlocked();
01410       second->blockSignals(true);
01411       second->setValue(secondVal);
01412       second->blockSignals(blocked);
01413     }
01414   }
01415 
01416   displayPreview();
01417 }
01418 
01419 //=======================================================================
01420 // name    : getIds
01421 // Purpose :
01422 //=======================================================================
01423 bool SMESHGUI_MeshPatternDlg::getIds (QList<int>& ids) const
01424 {
01425   ids.clear();
01426   QStringList strIds = mySelEdit[Ids]->text().split(" ", QString::SkipEmptyParts );
01427   bool isOk;
01428   int val;
01429   for (QStringList::iterator it = strIds.begin(); it != strIds.end(); ++it) {
01430     val = (*it).toInt(&isOk);
01431     if (isOk)
01432       ids.append(val);
01433   }
01434 
01435   return ids.count();
01436 }
01437 
01438 //=======================================================================
01439 // name    : getNode1
01440 // Purpose :
01441 //=======================================================================
01442 int SMESHGUI_MeshPatternDlg::getNode (bool second) const
01443 {
01444   return second ? myNode2->value() - 1 : myNode1->value() - 1;
01445 }
01446 
01447 //=================================================================================
01448 // function : keyPressEvent()
01449 // purpose  :
01450 //=================================================================================
01451 void SMESHGUI_MeshPatternDlg::keyPressEvent( QKeyEvent* e )
01452 {
01453   QDialog::keyPressEvent( e );
01454   if ( e->isAccepted() )
01455     return;
01456 
01457   if ( e->key() == Qt::Key_F1 )
01458     {
01459       e->accept();
01460       onHelp();
01461     }
01462 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS