Salome HOME
0020321: EDF : Some windows do not appear depending on the platform (MinimumSizeHint())
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_CreatePatternDlg.cxx
index 3e63d654f9b34945a32fc5fa50cd97a4defff4dd..e50b7048ca01c56b79aba75afbdbb4dd81f19ed4 100755 (executable)
-//  SMESH SMESHGUI : GUI for SMESH component\r
-//\r
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
-// \r
-//  This library is free software; you can redistribute it and/or \r
-//  modify it under the terms of the GNU Lesser General Public \r
-//  License as published by the Free Software Foundation; either \r
-//  version 2.1 of the License. \r
-// \r
-//  This library is distributed in the hope that it will be useful, \r
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of \r
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU \r
-//  Lesser General Public License for more details. \r
-// \r
-//  You should have received a copy of the GNU Lesser General Public \r
-//  License along with this library; if not, write to the Free Software \r
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA \r
-// \r
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
-//\r
-//\r
-//\r
-//  File   : SMESHGUI_CreatePatternDlg.cxx\r
-//  Author : Sergey LITONIN\r
-//  Module : SMESH\r
-\r
-#include "SMESHGUI_CreatePatternDlg.h"\r
-\r
-#include "QAD_Desktop.h"\r
-#include "QAD_FileDlg.h"\r
-\r
-#include "SMESHGUI_PatternWidget.h"\r
-#include "SMESHGUI_SpinBox.h"\r
-#include "SMESHGUI.h"\r
-#include "SALOME_Selection.h"\r
-#include "SALOME_ListIteratorOfListOfFilter.hxx"\r
-#include "SALOMEGUI_QtCatchCorbaException.hxx"\r
-#include "SMESH_NumberFilter.hxx"\r
-#include "SMESHGUI_Utils.h"\r
-#include "SMESHGUI_VTKUtils.h"\r
-#include "SMESHGUI_PatternUtils.h"\r
-\r
-#include <TColStd_MapOfInteger.hxx>\r
-\r
-#include <qframe.h>\r
-#include <qlayout.h>\r
-#include <qlineedit.h>\r
-#include <qpushbutton.h>\r
-#include <qgroupbox.h>\r
-#include <qlabel.h>\r
-#include <qradiobutton.h>\r
-#include <qcheckbox.h>\r
-#include <qbuttongroup.h>\r
-#include <qmessagebox.h>\r
-#include <qapplication.h>\r
-\r
-#define SPACING 5\r
-#define MARGIN  10\r
-\r
-/*\r
-  Class       : SMESHGUI_CreatePatternDlg\r
-  Description : Dialog to specify filters for VTK viewer\r
-*/\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::SMESHGUI_CreatePatternDlg\r
-// Purpose : Constructor\r
-//=======================================================================\r
-SMESHGUI_CreatePatternDlg::SMESHGUI_CreatePatternDlg( QWidget*          theParent,\r
-                                                      SALOME_Selection* theSelection,\r
-                                                      const int         theType,\r
-                                                      const char*       theName )\r
-: QDialog( theParent, theName, false,\r
-           WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )\r
-{\r
-  setCaption( tr( "CAPTION" ) );\r
-\r
-  QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING );\r
-\r
-  QFrame* aMainFrame = createMainFrame  ( this );\r
-  QFrame* aBtnFrame  = createButtonFrame( this );\r
-\r
-  aDlgLay->addWidget( aMainFrame );\r
-  aDlgLay->addWidget( aBtnFrame );\r
-\r
-  aDlgLay->setStretchFactor( aMainFrame, 1 );\r
-\r
-  Init( theSelection, theType );\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::createMainFrame\r
-// Purpose : Create frame containing dialog's input fields\r
-//=======================================================================\r
-QFrame* SMESHGUI_CreatePatternDlg::createMainFrame( QWidget* theParent )\r
-{\r
-  QPixmap iconSlct( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );\r
-  QPixmap icon2d  ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) );\r
-  QPixmap icon3d  ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) );\r
-\r
-  QPixmap iconSample2d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) );\r
-\r
-  QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, theParent );\r
-  aMainGrp->setFrameStyle( QFrame::NoFrame );\r
-  aMainGrp->setInsideMargin( 0 );\r
-\r
-  // Pattern type group\r
-\r
-  myTypeGrp = new QButtonGroup( 1, Qt::Vertical, tr( "PATTERN_TYPE" ), aMainGrp );\r
-  mySwitch2d = new QRadioButton( myTypeGrp );\r
-  mySwitch3d = new QRadioButton( myTypeGrp );\r
-  mySwitch2d->setPixmap( icon2d );\r
-  mySwitch3d->setPixmap( icon3d );\r
-  myTypeGrp->insert( mySwitch2d, Type_2d );\r
-  myTypeGrp->insert( mySwitch3d, Type_3d );\r
-\r
-  QGroupBox* aPatternGrp = new QGroupBox( 1, Qt::Horizontal, tr( "PATTERN" ), aMainGrp );\r
-\r
-  // Mesh and pattern name group\r
-  \r
-  QGroupBox* aMeshGrp = new QGroupBox( 1, Qt::Vertical, aPatternGrp );\r
-  aMeshGrp->setFrameStyle( QFrame::NoFrame );\r
-  aMeshGrp->setInsideMargin( 0 );\r
-  \r
-  new QLabel( tr( "MESH_OR_SUBMESH" ), aMeshGrp );\r
-\r
-  QPushButton* aSelBtn = new QPushButton( aMeshGrp );\r
-  aSelBtn->setPixmap( iconSlct );\r
-  myMeshEdit = new QLineEdit( aMeshGrp );\r
-  myMeshEdit->setReadOnly( true );\r
-\r
-  QGroupBox* aPattGrp = new QGroupBox( 1, Qt::Vertical, aPatternGrp );\r
-  aPattGrp->setFrameStyle( QFrame::NoFrame );\r
-  aPattGrp->setInsideMargin( 0 );\r
-  \r
-  new QLabel( tr( "PATTERN_NAME" ), aPattGrp );\r
-  myName = new QLineEdit( aPattGrp );\r
-\r
-  // Picture 2d\r
-  \r
-  myPicture2d = new SMESHGUI_PatternWidget( aPatternGrp ),\r
-  myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );\r
-\r
-  // Project check box\r
-  \r
-  myProjectChk = new QCheckBox( tr( "PROJECT" ), aPatternGrp );\r
-  \r
-  // Connect signals and slots\r
-\r
-  connect( myTypeGrp,    SIGNAL( clicked( int )  ), SLOT( onTypeChanged( int ) ) );\r
-  connect( myProjectChk, SIGNAL( toggled( bool ) ), SLOT( onProject( bool )    ) );\r
-  connect( aSelBtn,      SIGNAL( clicked()       ), SLOT( onSelBtnClicked() ) );\r
-\r
-  return aMainGrp;\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::createButtonFrame\r
-// Purpose : Create frame containing buttons\r
-//=======================================================================\r
-QFrame* SMESHGUI_CreatePatternDlg::createButtonFrame( QWidget* theParent )\r
-{\r
-  QFrame* aFrame = new QFrame( theParent );\r
-  aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );\r
-\r
-  myOkBtn    = new QPushButton( tr( "SMESH_BUT_OK"     ), aFrame );\r
-  mySaveBtn  = new QPushButton( tr( "SAVE"             ), aFrame );\r
-  myCloseBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), aFrame );\r
-\r
-  QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );\r
-\r
-  QHBoxLayout* aLay = new QHBoxLayout( aFrame, MARGIN, SPACING );\r
-\r
-  aLay->addWidget( myOkBtn );\r
-  aLay->addWidget( mySaveBtn );\r
-  aLay->addItem( aSpacer);\r
-  aLay->addWidget( myCloseBtn );\r
-\r
-  connect( myOkBtn,    SIGNAL( clicked() ), SLOT( onOk() ) );\r
-  connect( myCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) ) ;\r
-  connect( mySaveBtn, SIGNAL( clicked() ), SLOT( onSave() ) );\r
-\r
-  return aFrame;\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::~SMESHGUI_CreatePatternDlg\r
-// Purpose : Destructor\r
-//=======================================================================\r
-SMESHGUI_CreatePatternDlg::~SMESHGUI_CreatePatternDlg()\r
-{\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::onProject\r
-// Purpose : SLOT. Called when state of "Project nodes on ther face"\r
-//           checkbox is changed\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::onProject( bool )\r
-{\r
-  loadFromObject( false );\r
-  displayPreview();\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::Init\r
-// Purpose : Init dialog fields, connect signals and slots, show dialog\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::Init( SALOME_Selection* theSelection, const int theType )\r
-{\r
-  myIsLoaded  = false;\r
-  myType      = -1;\r
-  myNbPoints  = -1;\r
-  mySelection = theSelection;\r
-  mySubMesh   = SMESH::SMESH_subMesh::_nil();\r
-  myMesh      = SMESH::SMESH_Mesh::_nil();\r
-  myGeomObj   = GEOM::GEOM_Object::_nil();\r
-  myPattern   = SMESH::SMESH_Pattern::_nil();\r
-  \r
-  erasePreview();\r
-\r
-  SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();\r
-  aSMESHGUI->SetActiveDialogBox( ( QDialog* )this );\r
-\r
-  // selection and SMESHGUI\r
-  connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );\r
-  connect( aSMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) );\r
-  connect( aSMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) );\r
-\r
-  mySwitch2d->setEnabled( theType == Type_2d );\r
-  mySwitch3d->setEnabled( theType == Type_3d );\r
-\r
-  if ( theType == Type_2d )\r
-    myProjectChk->show();\r
-  else\r
-    myProjectChk->hide();\r
-  \r
-  myTypeGrp->setButton( theType );\r
-  onTypeChanged( theType );\r
-  \r
-  myName->setText( getDefaultName() );\r
-  myMeshEdit->setText( "" );\r
-\r
-  setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) );\r
-  qApp->processEvents();\r
-  updateGeometry();\r
-  myPicture2d->updateGeometry();\r
-  adjustSize();\r
-  resize( minimumSize() );\r
-\r
-  activateSelection();\r
-  onSelectionDone();\r
-\r
-  int x, y ;\r
-  aSMESHGUI->DefineDlgPosition( this, x, y );\r
-  this->move( x, y );\r
-  this->show();\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::SetMesh\r
-// Purpose : Set mesh to dialog\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::SetMesh( SMESH::SMESH_Mesh_ptr thePtr )\r
-{\r
-  myMesh = SMESH::SMESH_Mesh::_duplicate( thePtr );\r
-  mySubMesh = SMESH::SMESH_subMesh::_nil();\r
-\r
-  bool isValidMesh = false;\r
-  if ( !myMesh->_is_nil() )\r
-  {\r
-    SALOMEDS::SObject_var aSobj = SMESH::FindSObject( thePtr );\r
-    CORBA::String_var anEntry = aSobj->GetID();\r
-    Handle(SALOME_InteractiveObject) anIObj =\r
-      new SALOME_InteractiveObject( anEntry.in(), "SMESH" );\r
-\r
-    const SALOME_ListOfFilter& aList = mySelection->StoredFilters();\r
-    SALOME_ListIteratorOfListOfFilter anIter( aList );\r
-    for ( ; anIter.More(); anIter.Next() )\r
-      if ( !anIter.Value()->IsOk( anIObj ) )\r
-        break;\r
-\r
-    if ( !anIter.More() )\r
-      isValidMesh = true;\r
-  }\r
-\r
-\r
-  if ( isValidMesh )\r
-  {\r
-    SALOMEDS::SObject_var aSO = SMESH::FindSObject( myMesh.in() );\r
-    myMeshEdit->setText( aSO->GetName() );\r
-    myGeomObj = getGeom( aSO );\r
-  }\r
-  else\r
-  {\r
-    myMeshEdit->setText( "" );\r
-    myGeomObj = GEOM::GEOM_Object::_nil();\r
-  }\r
-\r
-  if ( myType == Type_2d )\r
-  {\r
-    loadFromObject( false );\r
-    displayPreview();\r
-  }\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::isValid\r
-// Purpose : Verify validity of entry data\r
-//=======================================================================\r
-bool SMESHGUI_CreatePatternDlg::isValid()\r
-{\r
-  if ( myGeomObj->_is_nil() )\r
-  {\r
-    QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),\r
-      tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SMESHGUI_INVALID_PARAMETERS" ), QMessageBox::Ok );\r
-    return false;\r
-  }\r
-  else\r
-    return true;\r
-}\r
-\r
-\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::getDefaultName\r
-// Purpose : Get default pattern name\r
-//=======================================================================\r
-QString SMESHGUI_CreatePatternDlg::getDefaultName() const\r
-{\r
-  return myType == Type_2d ? tr( "DEFAULT_2D" ) : tr( "DEFAULT_3D" );\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::onSave\r
-// Purpose : SLOT called when "Save" button pressed. Build pattern and\r
-\r
-//           save it to disk\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::onSave()\r
-{\r
-  try\r
-  {\r
-    if ( !isValid() )\r
-      return;\r
-\r
-    if ( !myIsLoaded )\r
-      loadFromObject( true );\r
-\r
-    // Load pattern from object\r
-    if ( !myIsLoaded )\r
-      return;\r
-\r
-    ///////////////////////////////////////////////////////\r
-    QAD_FileDlg* aDlg = new QAD_FileDlg( this, false );\r
-    aDlg->setCaption( tr( "SAVE_PATTERN" ) );\r
-    aDlg->setMode( QFileDialogP::AnyFile );\r
-    aDlg->setFilters( tr( "PATTERN_FILT" ) );\r
-    if ( myName->text() != "" )\r
-      aDlg->setSelection( myName->text() );\r
-\r
-    if ( aDlg->exec() != Accepted )\r
-      return;\r
-\r
-    QString fName = aDlg->selectedFile();\r
-    if ( fName.isEmpty() )\r
-      return;\r
-\r
-    if ( QFileInfo( fName ).extension().isEmpty() )\r
-      fName = autoExtension( fName );\r
-\r
-    fName = QDir::convertSeparators( fName );\r
-\r
-    QString aData( myPattern->GetString() );\r
-    long aLen = aData.length();\r
-\r
-    QFile aFile( fName );\r
-    aFile.open( IO_WriteOnly );\r
-    long aWritten = aFile.writeBlock( aData, aLen );\r
-    aFile.close();\r
-\r
-    if ( aWritten != aLen )\r
-    {\r
-      QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),\r
-        tr( "SMESH_ERROR" ), tr( "ERROR_OF_SAVING" ), QMessageBox::Ok );\r
-    }\r
-    else\r
-    {\r
-      QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );\r
-      disconnect( mySelection, 0, this, 0 );\r
-      disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );\r
-      SMESHGUI::GetSMESHGUI()->ResetState();\r
-      accept();\r
-      emit NewPattern();\r
-    }\r
-  }\r
-  catch( const SALOME::SALOME_Exception& S_ex )\r
-  {\r
-    QtCatchCorbaException( S_ex );\r
-  }\r
-  catch( ... )\r
-  {\r
-  }\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::GetPatternName\r
-// Purpose : Get name of pattern\r
-//=======================================================================\r
-QString SMESHGUI_CreatePatternDlg::GetPatternName() const\r
-{\r
-  return myName->text();\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::GetPattern\r
-// Purpose : Get result pattern\r
-//=======================================================================\r
-SMESH::SMESH_Pattern_ptr SMESHGUI_CreatePatternDlg::GetPattern()\r
-{\r
-  return myPattern.in();\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::onOk\r
-// Purpose : SLOT called when "Ok" button pressed.\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::onOk()\r
-{\r
-  try\r
-  {\r
-    if ( !isValid() )\r
-      return;\r
-\r
-    if ( !myIsLoaded )\r
-      loadFromObject( true );\r
-\r
-    // Load pattern from object\r
-    if ( !myIsLoaded )\r
-      return;\r
-    else\r
-    {\r
-      QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );\r
-      disconnect( mySelection, 0, this, 0 );\r
-      disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );\r
-      SMESHGUI::GetSMESHGUI()->ResetState();\r
-      accept();\r
-      emit NewPattern();\r
-    }\r
-  }\r
-  catch( const SALOME::SALOME_Exception& S_ex )\r
-  {\r
-    QtCatchCorbaException( S_ex );\r
-  }\r
-  catch( ... )\r
-  {\r
-  }\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::onClose\r
-// Purpose : SLOT called when "Close" button pressed. Close dialog\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::onClose()\r
-{\r
-  QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );\r
-  disconnect( mySelection, 0, this, 0 );\r
-  disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );\r
-  SMESHGUI::GetSMESHGUI()->ResetState();\r
-  reject();\r
-  emit Close();\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::loadFromObject\r
-// Purpose : Load pattern from geom object corresponding to the mesh/submesh\r
-//=======================================================================\r
-bool SMESHGUI_CreatePatternDlg::loadFromObject( const bool theMess )\r
-{\r
-  try\r
-  {\r
-    myIsLoaded = false;\r
-    \r
-    if ( myPattern->_is_nil() )\r
-      myPattern = SMESH::GetPattern();\r
-\r
-    if ( myMesh->_is_nil() && mySubMesh->_is_nil() || myGeomObj->_is_nil() )\r
-      return false;\r
-\r
-    SMESH::SMESH_Mesh_ptr aMesh = mySubMesh->_is_nil() ? myMesh.in() : mySubMesh->GetFather();\r
-\r
-    myIsLoaded = myType == Type_2d\r
-      ? myPattern->LoadFromFace( aMesh, myGeomObj, myProjectChk->isChecked() )\r
-      : myPattern->LoadFrom3DBlock( aMesh, myGeomObj );\r
-\r
-    if ( !myIsLoaded && theMess )\r
-    {\r
-      QString aMess;\r
-      SMESH::SMESH_Pattern::ErrorCode aCode = myPattern->GetErrorCode();\r
-      \r
-      if      ( aCode == SMESH::SMESH_Pattern::ERR_LOAD_EMPTY_SUBMESH   ) aMess = tr( "ERR_LOAD_EMPTY_SUBMESH" );\r
-      else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_NARROW_FACE    ) aMess = tr( "ERR_LOADF_NARROW_FACE" );\r
-      else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_CLOSED_FACE    ) aMess = tr( "ERR_LOADF_CLOSED_FACE" );\r
-      else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADV_BAD_SHAPE      ) aMess = tr( "ERR_LOADV_BAD_SHAPE" );\r
-      else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADV_COMPUTE_PARAMS ) aMess = tr( "ERR_LOADV_COMPUTE_PARAMS" );\r
-      else                                                                aMess = tr( "ERROR_OF_CREATION" );\r
-\r
-      QMessageBox::information(\r
-        SMESHGUI::GetSMESHGUI()->GetDesktop(), tr( "SMESH_ERROR" ), aMess, QMessageBox::Ok );\r
-    }\r
-\r
-  }\r
-  catch( const SALOME::SALOME_Exception& S_ex )\r
-  {\r
-    QtCatchCorbaException( S_ex );\r
-  }\r
-    \r
-  return myIsLoaded;\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::getGeom\r
-// Purpose : Retrieve geom object from SObject\r
-//=======================================================================\r
-GEOM::GEOM_Object_ptr SMESHGUI_CreatePatternDlg::getGeom( SALOMEDS::SObject_ptr theSO )\r
-{\r
-  if ( theSO->_is_nil() )\r
-    return GEOM::GEOM_Object::_nil();\r
-\r
-  SALOMEDS::Study_var aStudy =\r
-    SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getStudyDocument();\r
-\r
-  SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSO );\r
-  for( ; anIter->More(); anIter->Next() )\r
-  {\r
-    SALOMEDS::SObject_var aSO = anIter->Value();\r
-    SALOMEDS::SObject_var aRefSO;\r
-\r
-    GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(\r
-      aSO->ReferencedObject( aRefSO )? aRefSO->GetObject() : aSO->GetObject() );\r
-\r
-    if ( !aMeshShape->_is_nil() )\r
-      return aMeshShape._retn();\r
-  }\r
-  return GEOM::GEOM_Object::_nil();\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::onSelectionDone\r
-// Purpose : SLOT called when selection changed\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::onSelectionDone()\r
-{\r
-  try\r
-  {\r
-    if ( mySelection->IObjectCount() != 1 )\r
-      return;\r
-\r
-    // Get mesh or sub-mesh from selection\r
-    Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();\r
-    SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIO );\r
-    SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>( anIO );\r
-    if ( aMesh->_is_nil() && aSubMesh->_is_nil() )\r
-      return;\r
-\r
-    // Get geom object corresponding to the mesh\r
-    SALOMEDS::SObject_var aSO;\r
-    if ( !aMesh->_is_nil() )\r
-      aSO = SMESH::FindSObject( aMesh.in() );\r
-    else\r
-      aSO = SMESH::FindSObject( aSubMesh.in() );\r
-\r
-\r
-    GEOM::GEOM_Object_var aGeomObj = getGeom( aSO );\r
-    if ( aGeomObj->_is_nil() )\r
-      return;\r
-\r
-    myGeomObj = aGeomObj;\r
-\r
-    // init class fields\r
-    if ( !aMesh->_is_nil() )\r
-    {\r
-      myMesh = aMesh;\r
-      mySubMesh = SMESH::SMESH_subMesh::_nil();\r
-    }\r
-    else\r
-    {\r
-      mySubMesh = aSubMesh;\r
-      myMesh = SMESH::SMESH_Mesh::_nil();\r
-    }\r
-\r
-    QString aName;\r
-    SMESH::GetNameOfSelectedIObjects( mySelection, aName );\r
-    myMeshEdit->setText( aName );\r
-\r
-    if ( myType == Type_2d )\r
-    {\r
-      loadFromObject( true );\r
-      displayPreview();\r
-    }\r
-  }\r
-  catch( ... )\r
-  {\r
-    myMesh = SMESH::SMESH_Mesh::_nil();\r
-    mySubMesh = SMESH::SMESH_subMesh::_nil();\r
-    myGeomObj = GEOM::GEOM_Object::_nil();\r
-    erasePreview();\r
-  }\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::onDeactivate\r
-// Purpose : SLOT called when dialog must be deativated\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::onDeactivate()\r
-{\r
-  disconnect( mySelection, 0, this, 0 );\r
-  setEnabled( false );\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::enterEvent\r
-// Purpose : Event filter\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::enterEvent( QEvent* )\r
-{\r
-  SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();\r
-  setEnabled( true );\r
-  activateSelection();\r
-  connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );\r
-}\r
-\r
-\r
-//=================================================================================\r
-// function : closeEvent()\r
-// purpose  : Close dialog box\r
-//=================================================================================\r
-void SMESHGUI_CreatePatternDlg::closeEvent( QCloseEvent* e )\r
-{\r
-  onClose() ;\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::onSelBtnClicked\r
-// Purpose : SLOT. Called when -> button clicked.\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::onSelBtnClicked()\r
-{\r
-  onSelectionDone();\r
-}\r
-\r
-//================================================================\r
-// Function : SMESHGUI_CreatePatternDlg::autoExtension\r
-// Purpose  : Append extension to the file name\r
-//================================================================\r
-QString SMESHGUI_CreatePatternDlg::autoExtension( const QString& theFileName ) const\r
-{\r
-  QString anExt = theFileName.section( '.', -1 );\r
-  return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName;\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::displayPreview\r
-// Purpose : Display preview\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::displayPreview()\r
-{\r
-\r
-  // Redisplay preview in dialog\r
-\r
-  try\r
-  {\r
-    if ( !myIsLoaded )\r
-      erasePreview();\r
-    else\r
-    {\r
-      SMESH::point_array_var pnts = myPattern->GetPoints();\r
-      SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();\r
-      SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints();\r
-\r
-      if ( pnts->length()       == 0 ||\r
-           keyPoints->length()  == 0 ||\r
-           elemPoints->length() == 0 )\r
-      {\r
-        myIsLoaded = false;\r
-        erasePreview();\r
-        return;\r
-      }\r
-\r
-      PointVector aPoints( pnts->length() );\r
-      QValueVector<int> aKeyPoints( keyPoints->length() );\r
-      ConnectivityVector anElemPoints( elemPoints->length() );\r
-\r
-      for ( int i = 0, n = pnts->length(); i < n; i++ )\r
-        aPoints[ i ] = pnts[ i ];\r
-\r
-      for ( int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++ )\r
-        aKeyPoints[ i2 ] = keyPoints[ i2 ];\r
-\r
-      for ( int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++ )\r
-      {\r
-        QValueVector<int> aVec( elemPoints[ i3 ].length() );\r
-        for ( int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++ )\r
-          aVec[ i4 ] = elemPoints[ i3 ][ i4 ];\r
-\r
-        anElemPoints[ i3 ] = aVec;\r
-      }\r
-\r
-      myPicture2d->SetPoints( aPoints, aKeyPoints, anElemPoints );\r
-    }\r
-\r
-    return;\r
-  }\r
-  catch( const SALOME::SALOME_Exception& S_ex )\r
-  {\r
-    QtCatchCorbaException( S_ex );\r
-  }\r
-  catch( ... )\r
-  {\r
-  }\r
-  erasePreview();\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::erasePreview\r
-// Purpose : Erase preview\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::erasePreview()\r
-\r
-{\r
-  // Erase preview in 2D viewer\r
-  myPicture2d->SetPoints( PointVector(), QValueVector<int>(), ConnectivityVector() );\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::activateSelection\r
-// Purpose : Activate selection in accordance with current pattern type\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::activateSelection()\r
-{\r
-  mySelection->ClearFilters();\r
-  QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );\r
-  \r
-  if ( myType == Type_2d )\r
-  {\r
-    mySelection->AddFilter(\r
-      new SMESH_NumberFilter( "SMESH", TopAbs_SHAPE, -1, TopAbs_FACE ) );\r
-  }\r
-  else\r
-  {\r
-    TColStd_MapOfInteger aTypes;\r
-    aTypes.Add( TopAbs_SHELL );\r
-    aTypes.Add( TopAbs_SOLID );\r
-    mySelection->AddFilter( new SMESH_NumberFilter(\r
-      "SMESH", TopAbs_FACE, 6, aTypes, GEOM::GEOM_Object::_nil(), true ) );\r
-  }\r
-}\r
-\r
-//=======================================================================\r
-// name    : SMESHGUI_CreatePatternDlg::onTypeChanged\r
-// Purpose : SLOT. Called when pattern type changed.\r
-//           Change dialog's look and feel\r
-//=======================================================================\r
-void SMESHGUI_CreatePatternDlg::onTypeChanged( int theType )\r
-{\r
-  if ( myType == theType )\r
-    return;\r
-\r
-  myType = theType;\r
-\r
-  if ( theType == Type_2d )\r
-    myPicture2d->show();\r
-  else\r
-    myPicture2d->hide();\r
-}\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File   : SMESHGUI_CreatePatternDlg.cxx
+// Author : Sergey LITONIN, Open CASCADE S.A.S.
+// SMESH includes
+//
+#include "SMESHGUI_CreatePatternDlg.h"
+
+#include "SMESHGUI.h"
+#include "SMESHGUI_PatternWidget.h"
+#include "SMESHGUI_Utils.h"
+#include "SMESHGUI_VTKUtils.h"
+#include "SMESHGUI_PatternUtils.h"
+#include "SMESHGUI_GEOMGenUtils.h"
+
+#include <SMESH_NumberFilter.hxx>
+
+// SALOME GUI includes
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_FileDlg.h>
+#include <SUIT_Session.h>
+#include <SUIT_MessageBox.h>
+
+#include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Tools.h>
+
+#include <SALOME_ListIO.hxx>
+#include <SVTK_ViewModel.h>
+#include <SVTK_ViewWindow.h>
+
+// SALOME KERNEL includes
+#include <SALOMEDS_SObject.hxx>
+
+// OCCT includes
+#include <TColStd_MapOfInteger.hxx>
+
+// Qt includes
+#include <QFrame>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QGroupBox>
+#include <QLabel>
+#include <QRadioButton>
+#include <QCheckBox>
+#include <QButtonGroup>
+#include <QApplication>
+#include <QKeyEvent>
+#include <QFile>
+#include <QDir>
+
+#define SPACING 6
+#define MARGIN  11
+
+/*!
+ *  Class       : SMESHGUI_CreatePatternDlg
+ *  Description : Dialog to specify filters for VTK viewer
+ */
+
+//=======================================================================
+// function : SMESHGUI_CreatePatternDlg()
+// purpose  : Constructor
+//=======================================================================
+SMESHGUI_CreatePatternDlg::SMESHGUI_CreatePatternDlg( SMESHGUI*   theModule,
+                                                      const int   theType )
+  : QDialog( SMESH::GetDesktop( theModule ) ),
+    mySMESHGUI( theModule ),
+    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
+{
+  setModal( false );
+  setWindowTitle( tr( "CAPTION" ) );
+
+  QVBoxLayout* aDlgLay = new QVBoxLayout( this );
+  aDlgLay->setMargin( MARGIN );
+  aDlgLay->setSpacing( SPACING );
+
+  QWidget* aMainFrame = createMainFrame( this );
+  QWidget* aBtnFrame  = createButtonFrame( this );
+
+  aDlgLay->addWidget( aMainFrame );
+  aDlgLay->addWidget( aBtnFrame );
+
+  aDlgLay->setStretchFactor( aMainFrame, 1 );
+
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
+    mySelector = aViewWindow->GetSelector();
+
+  myHelpFileName = "pattern_mapping_page.html";
+
+  Init( theType );
+}
+
+//=======================================================================
+// function : createMainFrame()
+// purpose  : Create frame containing dialog's input fields
+//=======================================================================
+QWidget* SMESHGUI_CreatePatternDlg::createMainFrame( QWidget* theParent )
+{
+  QPixmap iconSlct    ( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
+  QPixmap icon2d      ( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) );
+  QPixmap icon3d      ( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) );
+  QPixmap iconSample2d( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) );
+
+  QWidget* aMainGrp = new QWidget( theParent );
+  QVBoxLayout* aMainGrpLayout = new QVBoxLayout( aMainGrp );
+  aMainGrpLayout->setMargin( 0 );
+  aMainGrpLayout->setSpacing( SPACING );
+
+  // Pattern type group
+
+  QGroupBox* aTypeGrp = new QGroupBox( tr( "PATTERN_TYPE" ), aMainGrp );
+  QHBoxLayout* aTypeGrpLayout = new QHBoxLayout( aTypeGrp );
+  aTypeGrpLayout->setMargin( MARGIN );
+  aTypeGrpLayout->setSpacing( SPACING );
+
+  mySwitch2d = new QRadioButton( aTypeGrp );
+  mySwitch3d = new QRadioButton( aTypeGrp );
+  mySwitch2d->setIcon( icon2d );
+  mySwitch3d->setIcon( icon3d );
+
+  myTypeGrp = new QButtonGroup( aMainGrp );
+  myTypeGrp->addButton( mySwitch2d, Type_2d );
+  myTypeGrp->addButton( mySwitch3d, Type_3d );
+
+  // ... layout widgets
+
+  aTypeGrpLayout->addWidget( mySwitch2d );
+  aTypeGrpLayout->addWidget( mySwitch3d );
+
+  // Mesh and pattern name group
+
+  QGroupBox* aPatternGrp = new QGroupBox( tr( "PATTERN" ), aMainGrp );
+  QGridLayout* aPatternGrpLayout = new QGridLayout( aPatternGrp );
+  aPatternGrpLayout->setMargin( MARGIN );
+  aPatternGrpLayout->setSpacing( SPACING );
+
+  QLabel* aMeshLab = new QLabel( tr( "MESH_OR_SUBMESH" ), aPatternGrp );
+
+  QPushButton* aSelBtn = new QPushButton( aPatternGrp );
+  aSelBtn->setIcon( iconSlct );
+  myMeshEdit = new QLineEdit( aPatternGrp );
+  myMeshEdit->setReadOnly( true );
+
+  QLabel* aNameLab = new QLabel( tr( "PATTERN_NAME" ), aPatternGrp );
+  myName = new QLineEdit( aPatternGrp );
+
+  // Picture 2d
+
+  myPicture2d = new SMESHGUI_PatternWidget( aPatternGrp ),
+  myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
+
+  // Project check box
+
+  myProjectChk = new QCheckBox( tr( "PROJECT" ), aPatternGrp );
+
+  // ... layout widgets
+
+  aPatternGrpLayout->addWidget( aMeshLab,     0, 0 );
+  aPatternGrpLayout->addWidget( aSelBtn,      0, 1 );
+  aPatternGrpLayout->addWidget( myMeshEdit,   0, 2 );
+  aPatternGrpLayout->addWidget( aNameLab,     1, 0 );
+  aPatternGrpLayout->addWidget( myName,       1, 2 );
+  aPatternGrpLayout->addWidget( myPicture2d,  2, 0, 1, 3 );
+  aPatternGrpLayout->addWidget( myProjectChk, 3, 0, 1, 3 );
+
+  // main layout
+
+  aMainGrpLayout->addWidget( aTypeGrp );
+  aMainGrpLayout->addWidget( aPatternGrp );
+
+  // Connect signals and slots
+
+  connect( myTypeGrp,    SIGNAL( buttonClicked( int )  ),
+          this,         SLOT( onTypeChanged( int ) ) );
+  connect( myProjectChk, SIGNAL( toggled( bool ) ),
+          this,         SLOT( onProject( bool ) ) );
+  connect( aSelBtn,      SIGNAL( clicked() ),
+          this,         SLOT( onSelBtnClicked() ) );
+
+  return aMainGrp;
+}
+
+//=======================================================================
+// function : createButtonFrame()
+// purpose  : Create frame containing buttons
+//=======================================================================
+QWidget* SMESHGUI_CreatePatternDlg::createButtonFrame( QWidget* theParent )
+{
+  QFrame* aFrame = new QFrame( theParent );
+  aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
+
+  QPushButton* myOkBtn    = new QPushButton( tr( "SMESH_BUT_OK"    ), aFrame );
+  QPushButton* mySaveBtn  = new QPushButton( tr( "SAVE"            ), aFrame );
+  QPushButton* myCloseBtn = new QPushButton( tr( "SMESH_BUT_CANCEL"), aFrame );
+  QPushButton* myHelpBtn  = new QPushButton( tr( "SMESH_BUT_HELP"),   aFrame );
+
+  QHBoxLayout* aLay = new QHBoxLayout( aFrame );
+  aLay->setMargin( MARGIN );
+  aLay->setSpacing( SPACING );
+
+  aLay->addWidget( myOkBtn );
+  aLay->addSpacing( 10 );
+  aLay->addWidget( mySaveBtn );
+  aLay->addSpacing( 10 );
+  aLay->addStretch();
+  aLay->addWidget( myCloseBtn );
+  aLay->addWidget( myHelpBtn );
+
+  connect( myOkBtn,    SIGNAL( clicked() ), this, SLOT( onOk() ) );
+  connect( myCloseBtn, SIGNAL( clicked() ), this, SLOT( onClose() ) );
+  connect( mySaveBtn,  SIGNAL( clicked() ), this, SLOT( onSave() ) );
+  connect( myHelpBtn,  SIGNAL( clicked() ), this, SLOT( onHelp() ) );
+
+  return aFrame;
+}
+
+//=======================================================================
+// function : ~SMESHGUI_CreatePatternDlg()
+// purpose  : Destructor
+//=======================================================================
+SMESHGUI_CreatePatternDlg::~SMESHGUI_CreatePatternDlg()
+{
+}
+
+//=======================================================================
+// function : onProject()
+// purpose  : SLOT. Called when state of "Project nodes on ther face"
+//            checkbox is changed
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::onProject( bool )
+{
+  loadFromObject( false );
+  displayPreview();
+}
+
+//=======================================================================
+// function : Init()
+// purpose  : Init dialog fields, connect signals and slots, show dialog
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::Init( const int theType )
+{
+  myIsLoaded     = false;
+  myType         = -1;
+  mySubMesh      = SMESH::SMESH_subMesh::_nil();
+  myMesh         = SMESH::SMESH_Mesh::_nil();
+  myGeomObj      = GEOM::GEOM_Object::_nil();
+  myPattern      = SMESH::SMESH_Pattern::_nil();
+
+  erasePreview();
+
+  mySMESHGUI->SetActiveDialogBox((QDialog*)this);
+
+  // selection and SMESHGUI
+  connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ),
+          this,           SLOT( onSelectionDone() ) );
+  connect( mySMESHGUI,     SIGNAL( SignalDeactivateActiveDialog() ),
+          this,           SLOT( onDeactivate() ) );
+  connect( mySMESHGUI,     SIGNAL( SignalCloseAllDialogs() ),
+          this,           SLOT( onClose() ) );
+
+  mySwitch2d->setEnabled( theType == Type_2d );
+  mySwitch3d->setEnabled( theType == Type_3d );
+
+  myTypeGrp->button( theType )->setChecked( true );
+  onTypeChanged( theType );
+
+  myName->setText( getDefaultName() );
+  myMeshEdit->setText( "" );
+
+  QApplication::instance()->processEvents();
+  updateGeometry();
+  resize(100,100);
+
+  activateSelection();
+  onSelectionDone();
+
+  //show();
+}
+
+//=======================================================================
+// function : SetMesh()
+// purpose  : Set mesh to dialog
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::SetMesh( SMESH::SMESH_Mesh_ptr thePtr )
+{
+  myMesh = SMESH::SMESH_Mesh::_duplicate( thePtr );
+  mySubMesh = SMESH::SMESH_subMesh::_nil();
+
+  bool isValidMesh = false;
+  if ( !myMesh->_is_nil() ) {
+    _PTR(SObject) aSobj = SMESH::FindSObject( myMesh.in() );
+    //Handle(SALOME_InteractiveObject) anIObj =
+    //  new SALOME_InteractiveObject(aSobj->GetID().c_str(), "SMESH");
+    SUIT_DataOwnerPtr anIObj( new LightApp_DataOwner( aSobj->GetID().c_str() ) );
+
+    isValidMesh = mySelectionMgr->isOk( anIObj );
+  }
+
+  if ( isValidMesh ) {
+    _PTR(SObject) aSO = SMESH::FindSObject( myMesh.in() );
+    myMeshEdit->setText( aSO->GetName().c_str() );
+    myGeomObj = SMESH::GetGeom( aSO );
+  } 
+  else {
+    myMeshEdit->setText( "" );
+    myGeomObj = GEOM::GEOM_Object::_nil();
+  }
+
+  if ( myType == Type_2d ) {
+    loadFromObject( false );
+    displayPreview();
+  }
+}
+
+//=======================================================================
+// function : isValid()
+// purpose  : Verify validity of entry data
+//=======================================================================
+bool SMESHGUI_CreatePatternDlg::isValid()
+{
+  if ( myGeomObj->_is_nil() ) {
+    SUIT_MessageBox::information( this,
+                                 tr( "SMESH_INSUFFICIENT_DATA" ),
+                                 tr( "SMESHGUI_INVALID_PARAMETERS" ) );
+    return false;
+  }
+  return true;
+}
+
+//=======================================================================
+// function : getDefaultName()
+// purpose  : Get default pattern name
+//=======================================================================
+QString SMESHGUI_CreatePatternDlg::getDefaultName() const
+{
+  return myType == Type_2d ? tr( "DEFAULT_2D" ) : tr( "DEFAULT_3D" );
+}
+
+//=======================================================================
+// function : onSave()
+// purpose  : SLOT called when "Save" button pressed. Build pattern and
+//           save it to disk
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::onSave()
+{
+  try {
+    if ( !isValid() )
+      return;
+
+    if ( !myIsLoaded )
+      loadFromObject( true );
+
+    // Load pattern from object
+    if ( !myIsLoaded )
+      return;
+
+    ///////////////////////////////////////////////////////
+    SUIT_FileDlg* aDlg = new SUIT_FileDlg( this, false );
+    aDlg->setWindowTitle( tr( "SAVE_PATTERN" ) );
+    aDlg->setFileMode( QFileDialog::AnyFile );
+    aDlg->setFilter( tr( "PATTERN_FILT" ) );
+    if ( myName->text() != "" )
+      aDlg->selectFile( myName->text() );
+
+    if ( aDlg->exec() != Accepted )
+      return;
+
+    QString fName = aDlg->selectedFile();
+    if ( fName.isEmpty() )
+      return;
+
+    if ( QFileInfo( fName ).suffix().isEmpty() )
+      fName = autoExtension( fName );
+
+    fName = QDir::convertSeparators( fName );
+
+    QString aData( myPattern->GetString() );
+    long aLen = aData.length();
+
+    QFile aFile( fName );
+    aFile.open( QIODevice::WriteOnly );
+    long aWritten = aFile.write( aData.toLatin1(), aLen );
+    aFile.close();
+
+    if ( aWritten != aLen ) {
+      SUIT_MessageBox::information( this,
+                                   tr( "SMESH_ERROR" ),
+                                   tr( "ERROR_OF_SAVING" ) );
+    } 
+    else {
+      //SUIT_Application::getDesktop()->setSelectionModes(ActorSelection);
+      if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
+       aViewWindow->SetSelectionMode( ActorSelection );
+      disconnect( mySelectionMgr, 0, this, 0 );
+      disconnect( mySMESHGUI, 0, this, 0 );
+      mySMESHGUI->ResetState();
+      accept();
+      emit NewPattern();
+    }
+  } 
+  catch ( const SALOME::SALOME_Exception& S_ex ) {
+    SalomeApp_Tools::QtCatchCorbaException( S_ex );
+  } 
+  catch (...) {
+  }
+}
+
+//=======================================================================
+// function : GetPatternName()
+// purpose  : Get name of pattern
+//=======================================================================
+QString SMESHGUI_CreatePatternDlg::GetPatternName() const
+{
+  return myName->text();
+}
+
+//=======================================================================
+// function : GetPattern()
+// purpose  : Get result pattern
+//=======================================================================
+SMESH::SMESH_Pattern_ptr SMESHGUI_CreatePatternDlg::GetPattern()
+{
+  return myPattern.in();
+}
+
+//=======================================================================
+// function : onOk()
+// purpose  : SLOT called when "Ok" button pressed.
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::onOk()
+{
+  try {
+    if ( !isValid() )
+      return;
+
+    if ( !myIsLoaded )
+      loadFromObject( true );
+
+    // Load pattern from object
+    if ( !myIsLoaded ) {
+      return;
+    }
+    else {
+      //SUIT_Application::getDesktop()->setSelectionModes(ActorSelection);
+      if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
+       aViewWindow->SetSelectionMode( ActorSelection );
+      disconnect( mySelectionMgr, 0, this, 0 );
+      disconnect( mySMESHGUI, 0, this, 0 );
+      mySMESHGUI->ResetState();
+      accept();
+      emit NewPattern();
+    }
+  } 
+  catch ( const SALOME::SALOME_Exception& S_ex ) {
+    SalomeApp_Tools::QtCatchCorbaException( S_ex );
+  } 
+  catch (...) {
+  }
+}
+
+//=======================================================================
+// function : onClose()
+// purpose  : SLOT called when "Close" button pressed. Close dialog
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::onClose()
+{
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
+    aViewWindow->SetSelectionMode( ActorSelection );
+  disconnect( mySelectionMgr, 0, this, 0 );
+  disconnect( mySMESHGUI, 0, this, 0 );
+  mySMESHGUI->ResetState();
+  reject();
+  emit Close();
+}
+
+//=================================================================================
+// function : onHelp()
+// purpose  :
+//=================================================================================
+void SMESHGUI_CreatePatternDlg::onHelp()
+{
+  LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
+  if ( app ) 
+    app->onHelpContextModule( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) : QString( "" ), myHelpFileName );
+  else {
+    QString platform;
+#ifdef WIN32
+    platform = "winapplication";
+#else
+    platform = "application";
+#endif
+    SUIT_MessageBox::warning( this, 
+                             tr( "WRN_WARNING" ),
+                             tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
+                             arg( app->resourceMgr()->stringValue( "ExternalBrowser", 
+                                                                   platform ) ).
+                             arg( myHelpFileName ) );
+  }
+}
+
+//=======================================================================
+// function : loadFromObject()
+// purpose  : Load pattern from geom object corresponding to the mesh/submesh
+//=======================================================================
+bool SMESHGUI_CreatePatternDlg::loadFromObject( const bool theMess )
+{
+  try {
+    myIsLoaded = false;
+
+    if ( myPattern->_is_nil() )
+      myPattern = SMESH::GetPattern();
+
+    if ( myMesh->_is_nil() && mySubMesh->_is_nil() || myGeomObj->_is_nil() )
+      return false;
+
+    SMESH::SMESH_Mesh_ptr aMesh = mySubMesh->_is_nil() ? myMesh.in() : mySubMesh->GetFather();
+
+    myIsLoaded = myType == Type_2d
+      ? myPattern->LoadFromFace( aMesh, myGeomObj, myProjectChk->isChecked() )
+      : myPattern->LoadFrom3DBlock( aMesh, myGeomObj );
+
+    if ( !myIsLoaded && theMess ) {
+      QString aMess;
+      SMESH::SMESH_Pattern::ErrorCode aCode = myPattern->GetErrorCode();
+
+      if      ( aCode == SMESH::SMESH_Pattern::ERR_LOAD_EMPTY_SUBMESH )   aMess = tr( "ERR_LOAD_EMPTY_SUBMESH" );
+      else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_NARROW_FACE )    aMess = tr( "ERR_LOADF_NARROW_FACE" );
+      else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_CLOSED_FACE )    aMess = tr( "ERR_LOADF_CLOSED_FACE" );
+      else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADF_CANT_PROJECT )   aMess = tr( "ERR_LOADF_CANT_PROJECT" );
+      else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADV_BAD_SHAPE )      aMess = tr( "ERR_LOADV_BAD_SHAPE" );
+      else if ( aCode == SMESH::SMESH_Pattern::ERR_LOADV_COMPUTE_PARAMS ) aMess = tr( "ERR_LOADV_COMPUTE_PARAMS" );
+      else                                                                aMess = tr( "ERROR_OF_CREATION" );
+
+      SUIT_MessageBox::information( this, tr( "SMESH_ERROR" ), aMess );
+    }
+  } 
+  catch ( const SALOME::SALOME_Exception& S_ex ) {
+    SalomeApp_Tools::QtCatchCorbaException( S_ex );
+  }
+
+  return myIsLoaded;
+}
+
+//=======================================================================
+// function : onSelectionDone()
+// purpose  : SLOT called when selection changed
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::onSelectionDone()
+{
+  try {
+    SALOME_ListIO aList;
+    mySelectionMgr->selectedObjects( aList, SVTK_Viewer::Type() );
+    if ( aList.Extent() != 1 )
+      return;
+
+    // Get mesh or sub-mesh from selection
+    Handle(SALOME_InteractiveObject) anIO = aList.First();
+    SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIO );
+    SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>( anIO );
+    if ( aMesh->_is_nil() && aSubMesh->_is_nil() )
+      return;
+
+    // Get geom object corresponding to the mesh
+    _PTR(SObject) aSO;
+    if ( !aMesh->_is_nil() )
+      aSO = SMESH::FindSObject( aMesh.in() );
+    else
+      aSO = SMESH::FindSObject( aSubMesh.in() );
+
+    GEOM::GEOM_Object_var aGeomObj = SMESH::GetGeom( aSO );
+    if ( aGeomObj->_is_nil() )
+      return;
+
+    myGeomObj = aGeomObj;
+
+    // init class fields
+    if ( !aMesh->_is_nil() ) {
+      myMesh = aMesh;
+      mySubMesh = SMESH::SMESH_subMesh::_nil();
+    } 
+    else {
+      mySubMesh = aSubMesh;
+      myMesh = SMESH::SMESH_Mesh::_nil();
+    }
+
+    QString aName;
+    SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aName );
+    myMeshEdit->setText( aName );
+
+    if ( myType == Type_2d ) {
+      loadFromObject( true );
+      displayPreview();
+    }
+  } 
+  catch (...) {
+    myMesh = SMESH::SMESH_Mesh::_nil();
+    mySubMesh = SMESH::SMESH_subMesh::_nil();
+    myGeomObj = GEOM::GEOM_Object::_nil();
+    erasePreview();
+  }
+}
+
+//=======================================================================
+// function : onDeactivate()
+// purpose  : SLOT called when dialog must be deativated
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::onDeactivate()
+{
+  disconnect( mySelectionMgr, 0, this, 0 );
+  setEnabled( false );
+}
+
+//=======================================================================
+// function : enterEvent()
+// purpose  : Event filter
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::enterEvent( QEvent* )
+{
+  // there is a stange problem that enterEvent() comes after onSave()
+  if ( isVisible () ) {
+    mySMESHGUI->EmitSignalDeactivateDialog();
+    setEnabled( true );
+    activateSelection();
+    connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
+  }
+}
+
+//=================================================================================
+// function : closeEvent()
+// purpose  : Close dialog box
+//=================================================================================
+void SMESHGUI_CreatePatternDlg::closeEvent( QCloseEvent* )
+{
+  onClose();
+}
+
+//=======================================================================
+// function : onSelBtnClicked()
+// purpose  : SLOT. Called when -> button clicked.
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::onSelBtnClicked()
+{
+  onSelectionDone();
+}
+
+//================================================================
+// function : autoExtension()
+// purpose  : Append extension to the file name
+//================================================================
+QString SMESHGUI_CreatePatternDlg::autoExtension( const QString& theFileName ) const
+{
+  QString anExt = theFileName.section('.', -1);
+  return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName;
+}
+
+//=======================================================================
+// function : displayPreview()
+// purpose  : Display preview
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::displayPreview()
+{
+  // Redisplay preview in dialog
+  try {
+    if ( !myIsLoaded ) {
+      erasePreview();
+    }
+    else {
+      SMESH::point_array_var pnts = myPattern->GetPoints();
+      SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
+      SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints( false );
+
+      if ( pnts->length()       == 0 ||
+           keyPoints->length()  == 0 ||
+           elemPoints->length() == 0 ) {
+        myIsLoaded = false;
+        erasePreview();
+        return;
+      }
+
+      PointVector aPoints( pnts->length() );
+      QVector<int> aKeyPoints( keyPoints->length() );
+      ConnectivityVector anElemPoints( elemPoints->length() );
+
+      for ( int i = 0, n = pnts->length(); i < n; i++ )
+        aPoints[ i ] = pnts[ i ];
+
+      for ( int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++ )
+        aKeyPoints[ i2 ] = keyPoints[ i2 ];
+
+      for (int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++) {
+        QVector<int> aVec (elemPoints[ i3 ].length());
+        for (int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++)
+          aVec[ i4 ] = elemPoints[ i3 ][ i4 ];
+
+        anElemPoints[ i3 ] = aVec;
+      }
+
+      myPicture2d->SetPoints( aPoints, aKeyPoints, anElemPoints );
+    }
+
+    return;
+
+  } 
+  catch ( const SALOME::SALOME_Exception& S_ex ) {
+    SalomeApp_Tools::QtCatchCorbaException( S_ex );
+  }
+  catch (...) {
+  }
+  erasePreview();
+}
+
+//=======================================================================
+// function : erasePreview()
+// purpose  : Erase preview
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::erasePreview()
+{
+  // Erase preview in 2D viewer
+  myPicture2d->SetPoints( PointVector(), QVector<int>(), ConnectivityVector() );
+}
+
+//=======================================================================
+// function : activateSelection()
+// purpose  : Activate selection in accordance with current pattern type
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::activateSelection()
+{
+  mySelectionMgr->clearFilters();
+  //SUIT_Application::getDesktop()->setSelectionModes(ActorSelection);
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
+    aViewWindow->SetSelectionMode( ActorSelection );
+
+  if ( myType == Type_2d ) {
+    mySelectionMgr->installFilter( new SMESH_NumberFilter( "SMESH",
+                                                          TopAbs_SHAPE,
+                                                          -1,
+                                                          TopAbs_FACE ) );
+  } 
+  else {
+    TColStd_MapOfInteger aTypes;
+    aTypes.Add( TopAbs_SHELL );
+    aTypes.Add( TopAbs_SOLID );
+    mySelectionMgr->installFilter( new SMESH_NumberFilter( "SMESH",
+                                                          TopAbs_FACE,
+                                                          6,
+                                                          aTypes,
+                                                          GEOM::GEOM_Object::_nil(),
+                                                          true ) );
+  }
+}
+
+//=======================================================================
+// function : onTypeChanged()
+// purpose  : SLOT. Called when pattern type changed.
+//            Change dialog's look and feel
+//=======================================================================
+void SMESHGUI_CreatePatternDlg::onTypeChanged( int theType )
+{
+  if ( myType == theType )
+    return;
+
+  myType = theType;
+
+  myPicture2d->setVisible( theType == Type_2d );
+  myProjectChk->setVisible( theType == Type_2d );
+}
+
+//=================================================================================
+// function : keyPressEvent()
+// purpose  :
+//=================================================================================
+void SMESHGUI_CreatePatternDlg::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Qt::Key_F1 ){
+    e->accept();
+    onHelp();
+  }
+}