-// 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_MeshPatternDlg.cxx\r
-// Author : Sergey LITONIN\r
-// Module : SMESH\r
-\r
-#include "SMESHGUI_MeshPatternDlg.h"\r
-\r
-#include "QAD_Desktop.h"\r
-#include "QAD_FileDlg.h"\r
-\r
-#include "SMESHGUI_SpinBox.h"\r
-#include "SMESHGUI.h"\r
-#include "SALOME_Selection.h"\r
-#include "SMESH_NumberFilter.hxx"\r
-#include "SMESHGUI_Utils.h"\r
-#include "SMESHGUI_VTKUtils.h"\r
-#include "SMESHGUI_CreatePatternDlg.h"\r
-#include "SMESHGUI_PatternWidget.h"\r
-#include "SMESH_Actor.h"\r
-#include "SALOMEGUI_QtCatchCorbaException.hxx"\r
-#include "VTKViewer_ViewFrame.h"\r
-#include "SMESHGUI_PatternUtils.h"\r
-#include "SMESH_ActorUtils.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 <qcstring.h>\r
-\r
-#include <vtkCell.h>\r
-#include <vtkIdList.h>\r
-#include <vtkIntArray.h>\r
-#include <vtkCellArray.h>\r
-#include <vtkUnsignedCharArray.h>\r
-#include <vtkUnstructuredGrid.h>\r
-#include <vtkDataSetMapper.h>\r
-\r
-#define SPACING 5\r
-#define MARGIN 10\r
-\r
-/*\r
- Class : SMESHGUI_MeshPatternDlg\r
- Description : Dialog to specify filters for VTK viewer\r
-*/\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg\r
-// Purpose : Constructor\r
-//=======================================================================\r
-SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg( QWidget* theParent,\r
- SALOME_Selection* theSelection,\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
-\r
-\r
-\r
- aDlgLay->addWidget( aMainFrame );\r
- aDlgLay->addWidget( aBtnFrame );\r
-\r
- aDlgLay->setStretchFactor( aMainFrame, 1 );\r
-\r
- myCreationDlg = 0;\r
- Init( theSelection );\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::createMainFrame\r
-// Purpose : Create frame containing dialog's input fields\r
-//=======================================================================\r
-QFrame* SMESHGUI_MeshPatternDlg::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
- QPixmap iconOpen( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_FILE_OPEN" ) ) );\r
-\r
- QPixmap iconSample2d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) );\r
- QPixmap iconSample3d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_3D" ) ) );\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
-\r
- // Mesh group\r
- \r
- QGroupBox* aMeshGrp = new QGroupBox( 1, Qt::Vertical, tr( "SMESH_MESH" ), aMainGrp );\r
- new QLabel( tr( "SMESH_MESH" ), aMeshGrp );\r
- mySelBtn[ Mesh ] = new QPushButton( aMeshGrp );\r
- mySelBtn[ Mesh ]->setPixmap( iconSlct );\r
- mySelEdit[ Mesh ] = new QLineEdit( aMeshGrp );\r
- mySelEdit[ Mesh ]->setReadOnly( true );\r
-\r
- // Pattern group\r
- \r
- QGroupBox* aPatGrp = new QGroupBox( 1, Qt::Horizontal, tr( "PATTERN" ), aMainGrp );\r
-\r
- // pattern name\r
- QGroupBox* aNameGrp = new QGroupBox( 1, Qt::Vertical, aPatGrp );\r
- aNameGrp->setFrameStyle( QFrame::NoFrame );\r
- aNameGrp->setInsideMargin( 0 );\r
- new QLabel( tr( "PATTERN" ), aNameGrp );\r
- myName = new QLineEdit( aNameGrp );\r
- myName->setReadOnly( true );\r
- myOpenBtn = new QPushButton( aNameGrp );\r
- myOpenBtn->setPixmap( iconOpen );\r
- myNewBtn = new QPushButton( tr( "NEW" ), aNameGrp );\r
-\r
- // selection widgets\r
- QGroupBox* aGrp = new QGroupBox( 3, Qt::Horizontal, aPatGrp );\r
- aGrp->setFrameStyle( QFrame::NoFrame );\r
- aGrp->setInsideMargin( 0 );\r
-\r
- for ( int i = Object; i <= Vertex2; i++ )\r
- {\r
- mySelLbl[ i ] = new QLabel( aGrp );\r
- mySelBtn[ i ] = new QPushButton( aGrp );\r
- mySelBtn[ i ]->setPixmap( iconSlct );\r
- mySelEdit[ i ] = new QLineEdit( aGrp );\r
- mySelEdit[ i ]->setReadOnly( true );\r
- }\r
-\r
- // reverse check box\r
- myReverseChk = new QCheckBox( tr( "REVERSE" ), aPatGrp );\r
-\r
- // Pictures 2d and 3d\r
- for ( int i = 0; i < 2; i++ )\r
- {\r
- if ( i == 0 )\r
- {\r
- myPicture2d = new SMESHGUI_PatternWidget( aPatGrp ),\r
- myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );\r
- }\r
- else\r
- {\r
- myPicture3d = new QFrame( aPatGrp ),\r
- myPreview3d = new QLabel( myPicture3d );\r
- myPreview3d->setPixmap( iconSample3d );\r
- QGridLayout* aLay = new QGridLayout( myPicture3d, 3, 3, 0, 0 );\r
- QSpacerItem* aSpacerH1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );\r
- QSpacerItem* aSpacerH2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );\r
- QSpacerItem* aSpacerV1 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );\r
- QSpacerItem* aSpacerV2 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );\r
- aLay->addItem( aSpacerH1, 1, 0 );\r
- aLay->addItem( aSpacerH2, 1, 2 );\r
- aLay->addItem( aSpacerV1, 0, 1 );\r
- aLay->addItem( aSpacerV2, 2, 1 );\r
- aLay->addWidget( myPreview3d, 1, 1 );\r
- }\r
- }\r
-\r
- myPreviewChk = new QCheckBox( tr( "PREVIEW" ), aPatGrp );\r
-\r
- // Connect signals and slots\r
-\r
- connect( myTypeGrp, SIGNAL( clicked( int ) ), SLOT( onTypeChanged( int ) ) );\r
- connect( myOpenBtn, SIGNAL( clicked() ), SLOT( onOpen() ) );\r
- connect( myNewBtn, SIGNAL( clicked() ), SLOT( onNew() ) );\r
- connect( myReverseChk, SIGNAL( toggled( bool ) ), SLOT( onReverse( bool ) ) );\r
- connect( myPreviewChk, SIGNAL( toggled( bool ) ), SLOT( onPreview( bool ) ) );\r
-\r
- QMap< int, QPushButton* >::iterator anIter;\r
- for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter )\r
- connect( *anIter, SIGNAL( clicked() ), SLOT( onSelInputChanged() ) );\r
-\r
- return aMainGrp;\r
-}\r
-\r
-//=======================================================================\r
-\r
-// name : SMESHGUI_MeshPatternDlg::createButtonFrame\r
-// Purpose : Create frame containing buttons\r
-//=======================================================================\r
-QFrame* SMESHGUI_MeshPatternDlg::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
- myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), aFrame );\r
- myCloseBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), 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( myApplyBtn );\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( myApplyBtn, SIGNAL( clicked() ), SLOT( onApply() ) );\r
-\r
- return aFrame;\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg\r
-// Purpose : Destructor\r
-//=======================================================================\r
-SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg()\r
-{\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::Init\r
-// Purpose : Init dialog fields, connect signals and slots, show dialog\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::Init( SALOME_Selection* theSelection )\r
-{\r
- myPattern = SMESH::GetPattern();\r
- myPreviewActor = 0;\r
- myIsCreateDlgOpen = false;\r
- mySelInput = Mesh;\r
- myType = -1;\r
- myNbPoints = -1;\r
- mySelection = theSelection;\r
- SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();\r
- aSMESHGUI->SetActiveDialogBox( ( QDialog* )this );\r
- myMesh = SMESH::SMESH_Mesh::_nil();\r
-\r
- myMeshShape = GEOM::GEOM_Object::_nil();\r
- myGeomObj[ Object ] = GEOM::GEOM_Object::_nil();\r
- myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();\r
- myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();\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
- myTypeGrp->setButton( Type_2d );\r
- onTypeChanged( Type_2d );\r
-\r
- updateGeometry();\r
-\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_MeshPatternDlg::isValid\r
-// Purpose : Verify validity of entry data\r
-//=======================================================================\r
-bool SMESHGUI_MeshPatternDlg::isValid( const bool theMess )\r
-{\r
- if ( myMesh->_is_nil() || myMeshShape->_is_nil() || myGeomObj[ Object ]->_is_nil() ||\r
- myGeomObj[ Vertex1 ]->_is_nil() || myType == Type_3d && myGeomObj[ Vertex2 ]->_is_nil() )\r
- {\r
- if ( theMess )\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
-// name : SMESHGUI_MeshPatternDlg::onApply\r
-// Purpose : SLOT called when "Apply" button pressed.\r
-//=======================================================================\r
-bool SMESHGUI_MeshPatternDlg::onApply()\r
-{\r
- try\r
- {\r
- if ( !isValid() )\r
- return false;\r
-\r
- if ( myType == Type_2d )\r
- myPattern->ApplyToFace(\r
- myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() );\r
- else\r
- myPattern->ApplyTo3DBlock(\r
- myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] );\r
-\r
- if ( myPattern->MakeMesh( myMesh ) )\r
- {\r
- mySelection->ClearIObjects();\r
- SMESH::UpdateView();\r
- SMESHGUI::GetSMESHGUI()->GetActiveStudy()->updateObjBrowser( true );\r
- return true;\r
- }\r
- else\r
- {\r
- QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),\r
- tr( "SMESH_ERROR" ), tr( "SMESH_OPERATION_FAILED" ), QMessageBox::Ok );\r
- return false;\r
- }\r
- }\r
- catch( const SALOME::SALOME_Exception& S_ex )\r
- {\r
- QtCatchCorbaException( S_ex ); \r
- }\r
- catch( ... )\r
- {\r
- }\r
-\r
- return false;\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::onOk\r
-// Purpose : SLOT called when "Ok" button pressed.\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onOk()\r
-{\r
- if ( onApply() )\r
- onClose();\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::onClose\r
-// Purpose : SLOT called when "Close" button pressed. Close dialog\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onClose()\r
-{\r
- mySelection->ClearFilters();\r
- QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );\r
- disconnect( mySelection, 0, this, 0 );\r
- disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );\r
- SMESHGUI::GetSMESHGUI()->ResetState();\r
- erasePreview();\r
- reject();\r
-}\r
-\r
-\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::onSelectionDone\r
-// Purpose : SLOT called when selection changed\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onSelectionDone()\r
-{\r
- try\r
- {\r
- if ( mySelection->IObjectCount() != 1 )\r
- return;\r
-\r
- if ( mySelInput == Mesh )\r
- {\r
- // Retrieve mesh from selection\r
- Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();\r
- SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIO );\r
- if ( aMesh->_is_nil() )\r
- return;\r
-\r
- // Get geom object corresponding to the mesh\r
- SALOMEDS::Study_var aStudy =\r
- SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getStudyDocument();\r
-\r
- SALOMEDS::SObject_var aSO = SMESH::FindSObject( aMesh.in() );\r
- if ( aSO->_is_nil() )\r
- return;\r
-\r
- bool isFound = false;\r
- SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( aSO );\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
- {\r
- isFound = true;\r
- myMeshShape = aMeshShape;\r
- break;\r
-\r
- }\r
- }\r
-\r
- if ( !isFound )\r
- return;\r
-\r
- // Clear fields of geom objects if mesh was changed\r
- if ( myMesh != aMesh )\r
- {\r
- for ( int i = Object; i <= Vertex2; i++ )\r
- {\r
- myGeomObj[ i ] = GEOM::GEOM_Object::_nil();\r
- mySelEdit[ i ]->setText( "" );\r
- }\r
- }\r
-\r
- myMesh = aMesh;\r
-\r
- // Set name of mesh in line edit\r
- QString aName;\r
- SMESH::GetNameOfSelectedIObjects( mySelection, aName );\r
- mySelEdit[ Mesh ]->setText( aName );\r
- }\r
- else\r
- {\r
- // Get geom object from selection\r
- Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();\r
- GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>( anIO );\r
- if ( anObj->_is_nil() )\r
- return;\r
-\r
- // Clear fields of vertexes if face or 3d block was changed\r
- if ( anObj != myGeomObj[ mySelInput ] && mySelInput == Object )\r
- {\r
- for ( int i = Vertex1; i <= Vertex2; i++ )\r
- {\r
- myGeomObj[ i ] = GEOM::GEOM_Object::_nil();\r
- mySelEdit[ i ]->setText( "" );\r
- }\r
- }\r
-\r
- myGeomObj[ mySelInput ] = anObj;\r
-\r
- // Set name of geom object in line edit\r
- QString aName;\r
- SMESH::GetNameOfSelectedIObjects( mySelection, aName );\r
- mySelEdit[ mySelInput ]->setText( aName );\r
- }\r
- }\r
- catch( const SALOME::SALOME_Exception& S_ex )\r
- {\r
- QtCatchCorbaException( S_ex );\r
- resetSelInput();\r
- }\r
- catch( ... )\r
- {\r
- resetSelInput();\r
- }\r
-\r
- updateWgState();\r
- displayPreview();\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::resetSelInput\r
-// Purpose : Reset fields corresponding to the current selection input\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::resetSelInput()\r
-{\r
- if ( mySelInput == Mesh )\r
- {\r
- myMesh = SMESH::SMESH_Mesh::_nil();\r
- myMeshShape = GEOM::GEOM_Object::_nil();\r
- }\r
-\r
- else\r
- myGeomObj[ mySelInput ] = GEOM::GEOM_Object::_nil();\r
-\r
- mySelEdit[ mySelInput ]->setText( "" );\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::onDeactivate\r
-// Purpose : SLOT called when dialog must be deativated\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onDeactivate()\r
-{\r
- mySelection->ClearFilters();\r
- //if ( myReverseChk->isChecked() )\r
- // erasePreview();\r
- disconnect( mySelection, 0, this, 0 );\r
- setEnabled( false );\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::enterEvent\r
-// Purpose : Event filter\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::enterEvent( QEvent* )\r
-{\r
- if ( myIsCreateDlgOpen )\r
- return;\r
- \r
- if ( myReverseChk->isChecked() )\r
- displayPreview();\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 :\r
-//=================================================================================\r
-void SMESHGUI_MeshPatternDlg::closeEvent( QCloseEvent* e )\r
-{\r
- onClose() ;\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::onSelInputChanged\r
-// Purpose : SLOT. Called when -> button clicked.\r
-// Change current selection input field\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onSelInputChanged()\r
-{\r
- const QObject* aSender = sender();\r
- for ( int i = Mesh; i <= Vertex2; i++ )\r
- if ( aSender == mySelBtn[ i ] )\r
- mySelInput = i;\r
-\r
- activateSelection();\r
- onSelectionDone();\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::prepareFilters\r
-// Purpose : Prepare filters for dialog\r
-//=======================================================================\r
-\r
-QStringList SMESHGUI_MeshPatternDlg::prepareFilters() const\r
-{\r
- static QStringList aList;\r
- if ( aList.isEmpty() )\r
- {\r
- aList.append( tr( "PATTERN_FILT" ) );\r
- //aList.append( tr( "ALL_FILES_FILTER" ) );\r
- }\r
-\r
- return aList;\r
-}\r
-\r
-//================================================================\r
-\r
-// Function : SMESHGUI_MeshPatternDlg::autoExtension\r
-// Purpose : Append extension to the file name\r
-//================================================================\r
-QString SMESHGUI_MeshPatternDlg::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_MeshPatternDlg::onOpen\r
-// Purpose : SLOT. Called when "Open" button clicked.\r
-// Displays file open dialog\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onOpen()\r
-{\r
- QAD_FileDlg* aDlg = new QAD_FileDlg( this, true );\r
- aDlg->setCaption( tr( "LOAD_PATTERN" ) );\r
- aDlg->setMode( QFileDialogP::ExistingFile );\r
- aDlg->setFilters( prepareFilters() );\r
- if ( myName->text() != "" )\r
- aDlg->setSelection( myName->text() + ".smp" );\r
- QPushButton* anOkBtn = ( QPushButton* )aDlg->child( "OK", "QPushButton" );\r
- if ( anOkBtn != 0 )\r
- anOkBtn->setText( tr( "SMESH_BUT_OK" ) );\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 prev = QDir::convertSeparators( myName->text() );\r
- if ( prev == fName )\r
- return;\r
-\r
- // Read string from file\r
- QFile aFile( fName );\r
- if ( !aFile.open( IO_ReadOnly ) )\r
- {\r
- QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),\r
- tr( "SMESH_ERROR" ), tr( "ERROR_OF_OPENING" ), QMessageBox::Ok );\r
- return;\r
- }\r
- \r
- QByteArray aDataArray = aFile.readAll();\r
- const char* aData = aDataArray.data();\r
- if ( aData == 0 )\r
- {\r
- QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),\r
- tr( "SMESH_ERROR" ), tr( "ERROR_OF_READING" ), QMessageBox::Ok );\r
- return;\r
- }\r
- \r
- if ( loadFromFile( aData ) )\r
- myName->setText( QFileInfo( fName ).baseName() );\r
- \r
- updateWgState();\r
- displayPreview();\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::onCloseCreationDlg\r
-// Purpose : SLOT. Called when "Pattern creation" dialog closed with "Close"\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onCloseCreationDlg()\r
-{\r
- setEnabled( true );\r
- myIsCreateDlgOpen = false;\r
-}\r
-\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::onOkCreationDlg\r
-// Purpose : SLOT. Called when "Pattern creation" dialog closed with OK\r
-// or SAVE buttons. Initialize myPattern field. Redisplay preview\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onOkCreationDlg()\r
-{\r
- myPattern = SMESH::SMESH_Pattern::_duplicate( myCreationDlg->GetPattern() );\r
- myName->setText( myCreationDlg->GetPatternName() );\r
- displayPreview();\r
- setEnabled( true );\r
- myIsCreateDlgOpen = false;\r
-}\r
-\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::onNew\r
-// Purpose : SLOT. Called when "New..." button clicked. Create new pattern\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onNew()\r
-{\r
- setEnabled( false );\r
- myIsCreateDlgOpen = true;\r
- if ( myCreationDlg == 0 )\r
- {\r
- myCreationDlg = new SMESHGUI_CreatePatternDlg( this, mySelection, myType );\r
- connect( myCreationDlg, SIGNAL( NewPattern() ), SLOT( onOkCreationDlg() ) );\r
- connect( myCreationDlg, SIGNAL( Close() ), SLOT( onCloseCreationDlg() ) );\r
- }\r
- else\r
- myCreationDlg->Init( mySelection, myType );\r
-\r
- myCreationDlg->SetMesh( myMesh );\r
- myCreationDlg->show();\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::onReverse\r
-// Purpose : SLOT. Called when state of "Reverse order..." checkbox chaged\r
-// Calculate new points of the mesh to be created. Redisplay preview\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onReverse( bool )\r
-{\r
- displayPreview();\r
-}\r
-\r
-//=======================================================================\r
-\r
-// name : SMESHGUI_MeshPatternDlg::onPreview\r
-// Purpose : SLOT. Called when state of "Preview" checkbox changed\r
-// Display/Erase preview\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onPreview( bool )\r
-{\r
- displayPreview();\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::displayPreview\r
-// Purpose : Display preview\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::displayPreview()\r
-{\r
- try\r
- {\r
- // Redisplay preview in dialog\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
- erasePreview();\r
- return;\r
- }\r
-\r
- else\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
-\r
- // Redisplay preview in 3D viewer\r
-\r
- if ( myPreviewActor != 0 )\r
- {\r
- if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() )\r
- {\r
- vf->RemoveActor(myPreviewActor);\r
- vf->Repaint();\r
- }\r
- myPreviewActor->Delete();\r
- myPreviewActor = 0;\r
- }\r
-\r
- if ( !myPreviewChk->isChecked() || !isValid( false ) )\r
- return;\r
-\r
- vtkUnstructuredGrid* aGrid = getGrid();\r
- if ( aGrid == 0 )\r
- return;\r
-\r
- // Create and display actor\r
- vtkDataSetMapper* aMapper = vtkDataSetMapper::New();\r
- aMapper->SetInput( aGrid );\r
-\r
- myPreviewActor = SALOME_Actor::New();\r
- myPreviewActor->PickableOff();\r
- myPreviewActor->SetMapper( aMapper );\r
-\r
- vtkProperty* aProp = vtkProperty::New();\r
- aProp->SetRepresentationToWireframe();\r
- aProp->SetColor( 250, 0, 250 );\r
- if ( SMESH::FindActorByObject( myMesh ) )\r
- aProp->SetLineWidth( SMESH::GetFloat( "SMESH:SettingsWidth", 1 ) +1 );\r
- else\r
- aProp->SetLineWidth( 1 );\r
- myPreviewActor->SetProperty( aProp );\r
-\r
- myPreviewActor->SetRepresentation( 3 );\r
-\r
- SMESH::GetCurrentVtkView()->AddActor( myPreviewActor );\r
- SMESH::GetCurrentVtkView()->Repaint();\r
-\r
- aProp->Delete();\r
- aGrid->Delete();\r
- }\r
- catch( const SALOME::SALOME_Exception& S_ex )\r
- {\r
- QtCatchCorbaException( S_ex );\r
- erasePreview();\r
- }\r
- catch( ... )\r
- {\r
- erasePreview();\r
- }\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::erasePreview\r
-// Purpose : Erase preview\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::erasePreview()\r
-{\r
- // Erase preview in 2D viewer\r
- myPicture2d->SetPoints( PointVector(), QValueVector<int>(), ConnectivityVector() );\r
-\r
- // Erase preview in 3D viewer\r
- if ( myPreviewActor == 0 )\r
- return;\r
-\r
-\r
- if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() )\r
- {\r
- vf->RemoveActor(myPreviewActor);\r
- vf->Repaint();\r
- }\r
- myPreviewActor->Delete();\r
- myPreviewActor = 0;\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::updateWgState\r
-// Purpose : Enable/disable selection widgets\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::updateWgState()\r
-{\r
- if ( myMesh->_is_nil() )\r
- {\r
- for ( int i = Object; i <= Vertex2; i++ )\r
- {\r
- mySelBtn [ i ]->setEnabled( false );\r
- mySelEdit[ i ]->setEnabled( false );\r
- mySelEdit[ i ]->setText( "" );\r
- }\r
- }\r
- else\r
- {\r
- mySelBtn [ Object ]->setEnabled( true );\r
- mySelEdit[ Object ]->setEnabled( true );\r
- \r
- if ( myGeomObj[ Object ]->_is_nil() )\r
- {\r
- for ( int i = Vertex1; i <= Vertex2; i++ )\r
- {\r
- mySelBtn [ i ]->setEnabled( false );\r
- mySelEdit[ i ]->setEnabled( false );\r
- mySelEdit[ i ]->setText( "" );\r
- }\r
- }\r
- else\r
- {\r
- for ( int i = Object; i <= Vertex2; i++ )\r
- {\r
- mySelBtn [ i ]->setEnabled( true );\r
- mySelEdit[ i ]->setEnabled( true );\r
- }\r
- }\r
- }\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::activateSelection\r
-// Purpose : Activate selection in accordance with current selection input\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::activateSelection()\r
-{\r
- mySelection->ClearFilters();\r
- QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );\r
- \r
- if ( mySelInput == Object && !myMeshShape->_is_nil() )\r
- {\r
- if ( myType == Type_2d )\r
- {\r
- if ( myNbPoints > 0 )\r
- mySelection->AddFilter( new SMESH_NumberFilter( \r
-\r
- "GEOM", TopAbs_VERTEX, myNbPoints, TopAbs_FACE, myMeshShape ) );\r
- else\r
- mySelection->AddFilter( new SMESH_NumberFilter(\r
- "GEOM", TopAbs_SHAPE, myNbPoints, TopAbs_FACE, myMeshShape ) );\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
- "GEOM", TopAbs_FACE, 6, aTypes, myMeshShape, true ) );\r
- }\r
- }\r
- else if ( ( mySelInput == Vertex1 || mySelInput == Vertex2 ) && !myGeomObj[ Object ]->_is_nil() )\r
- {\r
- mySelection->AddFilter( new SMESH_NumberFilter(\r
- "GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX, myGeomObj[ Object ] ) );\r
- }\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::loadFromFile\r
-// Purpose : Load pattern from file\r
-//=======================================================================\r
-bool SMESHGUI_MeshPatternDlg::loadFromFile( const QString& theName )\r
-{\r
- try\r
- {\r
- SMESH::SMESH_Pattern_var aPattern = SMESH::GetPattern();\r
-\r
- if ( !aPattern->LoadFromFile( theName.latin1() ) ||\r
- myType == Type_2d && !aPattern->Is2D())\r
- {\r
- SMESH::SMESH_Pattern::ErrorCode aCode = aPattern->GetErrorCode();\r
- QString aMess;\r
- if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NB_POINTS ) aMess = tr( "ERR_READ_NB_POINTS" );\r
- else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_POINT_COORDS ) aMess = tr( "ERR_READ_POINT_COORDS" );\r
- else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_TOO_FEW_POINTS ) aMess = tr( "ERR_READ_TOO_FEW_POINTS" );\r
- else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_3D_COORD ) aMess = tr( "ERR_READ_3D_COORD" );\r
- else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_KEYPOINT ) aMess = tr( "ERR_READ_NO_KEYPOINT" );\r
- else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_INDEX ) aMess = tr( "ERR_READ_BAD_INDEX" );\r
- else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_ELEM_POINTS ) aMess = tr( "ERR_READ_ELEM_POINTS" );\r
- else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_ELEMS ) aMess = tr( "ERR_READ_NO_ELEMS" );\r
- else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_KEY_POINT ) aMess = tr( "ERR_READ_BAD_KEY_POINT" );\r
- else aMess = tr( "ERROR_OF_LOADING" );\r
-\r
- QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),\r
- tr( "SMESH_ERROR" ), aMess, QMessageBox::Ok );\r
- return false;\r
- }\r
- else\r
- {\r
- myPattern = aPattern;\r
- return true;\r
- }\r
- }\r
- catch( const SALOME::SALOME_Exception& S_ex )\r
- {\r
- QtCatchCorbaException( S_ex );\r
- QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),\r
- tr( "SMESH_ERROR" ), tr( "ERROR_OF_LOADING" ), QMessageBox::Ok );\r
- return false;\r
- }\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::onTypeChanged\r
-\r
-// Purpose : SLOT. Called when pattern type changed.\r
-// Change dialog's look and feel\r
-//=======================================================================\r
-void SMESHGUI_MeshPatternDlg::onTypeChanged( int theType )\r
-{\r
- if ( myType == theType )\r
- return;\r
-\r
- myType = theType;\r
-\r
- myNbPoints = -1;\r
- myGeomObj[ Object ] = GEOM::GEOM_Object::_nil();\r
- myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();\r
- myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();\r
- myPattern = SMESH::GetPattern();\r
-\r
- myName->setText( "" );\r
- mySelEdit[ Object ]->setText( "" );\r
- mySelEdit[ Vertex1 ]->setText( "" );\r
- mySelEdit[ Vertex2 ]->setText( "" );\r
-\r
- if ( theType == Type_2d )\r
- {\r
- mySelLbl [ Vertex2 ]->hide();\r
- mySelBtn [ Vertex2 ]->hide();\r
- mySelEdit[ Vertex2 ]->hide();\r
- myReverseChk->show();\r
- myPicture2d->show();\r
- myPicture3d->hide();\r
- mySelLbl[ Object ]->setText( tr( "FACE" ) );\r
- mySelLbl[ Vertex1 ]->setText( tr( "VERTEX" ) );\r
- }\r
- else\r
- {\r
- mySelLbl [ Vertex2 ]->show();\r
- mySelBtn [ Vertex2 ]->show();\r
- mySelEdit[ Vertex2 ]->show();\r
- myReverseChk->hide();\r
- myPicture2d->hide();\r
- myPicture3d->show();\r
- mySelLbl[ Object ]->setText( tr( "3D_BLOCK" ) );\r
- mySelLbl[ Vertex1 ]->setText( tr( "VERTEX1" ) );\r
- mySelLbl[ Vertex2 ]->setText( tr( "VERTEX2" ) );\r
- }\r
-\r
- mySelInput = Mesh;\r
- activateSelection();\r
- updateWgState();\r
- displayPreview();\r
-}\r
-\r
-//=======================================================================\r
-// name : SMESHGUI_MeshPatternDlg::getGrid\r
-// Purpose : Get unstructured grid for pattern\r
-//=======================================================================\r
-vtkUnstructuredGrid* SMESHGUI_MeshPatternDlg::getGrid()\r
-{\r
- try\r
- {\r
- // Get points from pattern\r
- SMESH::point_array_var pnts = myType == Type_2d\r
- ? myPattern->ApplyToFace( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() )\r
- : myPattern->ApplyTo3DBlock( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] );\r
-\r
- SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints();\r
-\r
- if ( pnts->length() == 0 || elemPoints->length() == 0 )\r
- return 0;\r
-\r
- \r
-\r
- // to do : to be removed /////////////////////////////////////////////\r
-\r
-#ifdef DEB_SLN\r
- for ( int i1 = 0, n1 = pnts->length(); i1 < n1; i1++ )\r
- printf( "%d: %g %g %g\n", i1, pnts[ i1 ].x, pnts[ i1 ].y, pnts[ i1 ].z );\r
-\r
- printf( "\nELEMENTS : \n" );\r
- for ( int i2 = 0, n2 = elemPoints->length(); i2 < n2; i2++ )\r
- {\r
-\r
- printf( "%d: ", i2 );\r
- for ( int i3 = 0, n3 = elemPoints[ i2 ].length(); i3 < n3; i3++ )\r
- printf( "%d ", elemPoints[ i2 ][ i3 ] );\r
-\r
- printf( "\n" );\r
-\r
- }\r
-#endif\r
- //////////////////////////////////////////////////////////////////////\r
-\r
- // Calculate number of points used for cell\r
- vtkIdType aNbCells = elemPoints->length();\r
- vtkIdType aCellsSize = 0;\r
- for ( int i = 0, n = elemPoints->length(); i < n; i++ )\r
- aCellsSize += elemPoints[ i ].length();\r
-\r
- // Create unstructured grid and other usefull arrays\r
- vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();\r
-\r
- vtkCellArray* aConnectivity = vtkCellArray::New();\r
- aConnectivity->Allocate( aCellsSize, 0 );\r
-\r
- vtkPoints* aPoints = vtkPoints::New();\r
- aPoints->SetNumberOfPoints( pnts->length() );\r
-\r
- vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();\r
- aCellTypesArray->SetNumberOfComponents( 1 );\r
- aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );\r
-\r
- vtkIdList *anIdList = vtkIdList::New();\r
-\r
- // Fill array of points\r
- for ( int p = 0, nbPnt = pnts->length(); p < nbPnt; p++ )\r
- aPoints->SetPoint( p, pnts[ p ].x, pnts[ p ].y, pnts[ p ].z );\r
-\r
- for ( int e = 0, nbElem = elemPoints->length(); e < nbElem; e++ )\r
- {\r
- int nbPoints = elemPoints[ e ].length();\r
- anIdList->SetNumberOfIds( nbPoints );\r
- for ( int i = 0; i < nbPoints; i++ )\r
- anIdList->SetId( i, elemPoints[ e ][ i ] );\r
-\r
- aConnectivity->InsertNextCell( anIdList );\r
-\r
- if ( nbPoints == 3 ) aCellTypesArray->InsertNextValue( VTK_TRIANGLE );\r
- else if ( nbPoints == 5 ) aCellTypesArray->InsertNextValue( VTK_PYRAMID );\r
- else if ( nbPoints == 6 ) aCellTypesArray->InsertNextValue( VTK_WEDGE );\r
- else if ( nbPoints == 8 ) aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );\r
- else if ( nbPoints == 4 && myType == Type_2d ) aCellTypesArray->InsertNextValue( VTK_QUAD );\r
- else if ( nbPoints == 4 && myType == Type_3d ) aCellTypesArray->InsertNextValue( VTK_TETRA );\r
- else aCellTypesArray->InsertNextValue( VTK_EMPTY_CELL );\r
- }\r
-\r
- vtkIntArray* aCellLocationsArray = vtkIntArray::New();\r
- aCellLocationsArray->SetNumberOfComponents( 1 );\r
- aCellLocationsArray->SetNumberOfTuples( aNbCells );\r
-\r
- aConnectivity->InitTraversal();\r
- for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )\r
- aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );\r
-\r
- aGrid->SetPoints( aPoints );\r
- aGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );\r
-\r
- aConnectivity->Delete();\r
- aPoints->Delete();\r
- aCellTypesArray->Delete();\r
- anIdList->Delete();\r
- aCellLocationsArray->Delete();\r
-\r
- return aGrid;\r
- }\r
- catch( ... )\r
- {\r
- return 0;\r
- }\r
-}\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
+// SMESH SMESHGUI : GUI for SMESH component
+//
+// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : SMESHGUI_MeshPatternDlg.cxx
+// Author : Sergey LITONIN
+// Module : SMESH
+
+#include "SMESHGUI_MeshPatternDlg.h"
+
+#include "QAD_Desktop.h"
+#include "QAD_FileDlg.h"
+
+#include "SMESHGUI_SpinBox.h"
+#include "SMESHGUI.h"
+#include "SALOME_Selection.h"
+#include "SMESH_NumberFilter.hxx"
+#include "SMESHGUI_Utils.h"
+#include "SMESHGUI_VTKUtils.h"
+#include "SMESHGUI_CreatePatternDlg.h"
+#include "SMESHGUI_PatternWidget.h"
+#include "SMESH_Actor.h"
+#include "SALOMEGUI_QtCatchCorbaException.hxx"
+#include "VTKViewer_ViewFrame.h"
+#include "SMESHGUI_PatternUtils.h"
+#include "SMESH_ActorUtils.h"
+#include "SMDS_MeshElement.hxx"
+#include "SMDS_Mesh.hxx"
+
+#include <TColStd_MapOfInteger.hxx>
+
+#include <qframe.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qradiobutton.h>
+#include <qcheckbox.h>
+#include <qbuttongroup.h>
+#include <qmessagebox.h>
+#include <qcstring.h>
+#include <qspinbox.h>
+#include <qvaluelist.h>
+
+#include <vtkCell.h>
+#include <vtkIdList.h>
+#include <vtkIntArray.h>
+#include <vtkCellArray.h>
+#include <vtkUnsignedCharArray.h>
+#include <vtkUnstructuredGrid.h>
+#include <vtkDataSetMapper.h>
+
+#define SPACING 5
+#define MARGIN 10
+
+/*
+ Class : SMESHGUI_MeshPatternDlg
+ Description : Dialog to specify filters for VTK viewer
+*/
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg
+// Purpose : Constructor
+//=======================================================================
+SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg( QWidget* theParent,
+ SALOME_Selection* theSelection,
+ const char* theName )
+: QDialog( theParent, theName, false,
+ WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
+ myBusy( false )
+{
+ setCaption( tr( "CAPTION" ) );
+
+ QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING );
+
+ QFrame* aMainFrame = createMainFrame ( this );
+ QFrame* aBtnFrame = createButtonFrame( this );
+
+
+
+
+ aDlgLay->addWidget( aMainFrame );
+ aDlgLay->addWidget( aBtnFrame );
+
+ aDlgLay->setStretchFactor( aMainFrame, 1 );
+
+ myCreationDlg = 0;
+ Init( theSelection );
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::createMainFrame
+// Purpose : Create frame containing dialog's input fields
+//=======================================================================
+QFrame* SMESHGUI_MeshPatternDlg::createMainFrame( QWidget* theParent )
+{
+ QPixmap iconSlct( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
+ QPixmap icon2d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) );
+ QPixmap icon3d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) );
+ QPixmap iconOpen( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_FILE_OPEN" ) ) );
+
+ QPixmap iconSample2d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) );
+ QPixmap iconSample3d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_3D" ) ) );
+
+ QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, theParent );
+ aMainGrp->setFrameStyle( QFrame::NoFrame );
+ aMainGrp->setInsideMargin( 0 );
+
+ // Pattern type group
+
+ myTypeGrp = new QButtonGroup( 1, Qt::Vertical, tr( "PATTERN_TYPE" ), aMainGrp );
+ mySwitch2d = new QRadioButton( myTypeGrp );
+ mySwitch3d = new QRadioButton( myTypeGrp );
+ mySwitch2d->setPixmap( icon2d );
+ mySwitch3d->setPixmap( icon3d );
+ myTypeGrp->insert( mySwitch2d, Type_2d );
+ myTypeGrp->insert( mySwitch3d, Type_3d );
+
+
+ // Mesh group
+
+ QGroupBox* aMeshGrp = new QGroupBox( 1, Qt::Vertical, tr( "SMESH_MESH" ), aMainGrp );
+ new QLabel( tr( "SMESH_MESH" ), aMeshGrp );
+ mySelBtn[ Mesh ] = new QPushButton( aMeshGrp );
+ mySelBtn[ Mesh ]->setPixmap( iconSlct );
+ mySelEdit[ Mesh ] = new QLineEdit( aMeshGrp );
+ mySelEdit[ Mesh ]->setReadOnly( true );
+
+ // Pattern group
+
+ QGroupBox* aPatGrp = new QGroupBox( 1, Qt::Horizontal, tr( "PATTERN" ), aMainGrp );
+
+ // pattern name
+ QGroupBox* aNameGrp = new QGroupBox( 1, Qt::Vertical, aPatGrp );
+ aNameGrp->setFrameStyle( QFrame::NoFrame );
+ aNameGrp->setInsideMargin( 0 );
+ new QLabel( tr( "PATTERN" ), aNameGrp );
+ myName = new QLineEdit( aNameGrp );
+ myName->setReadOnly( true );
+ myOpenBtn = new QPushButton( aNameGrp );
+ myOpenBtn->setPixmap( iconOpen );
+ myNewBtn = new QPushButton( tr( "NEW" ), aNameGrp );
+
+ // Mode selection check box
+ myRefine = new QCheckBox( tr( "REFINE" ), aPatGrp );
+
+ // selection widgets for Apply to geom mode
+ myGeomGrp = new QGroupBox( 3, Qt::Horizontal, aPatGrp );
+ myGeomGrp->setFrameStyle( QFrame::NoFrame );
+ myGeomGrp->setInsideMargin( 0 );
+
+ for ( int i = Object; i <= Vertex2; i++ )
+ {
+ mySelLbl[ i ] = new QLabel( myGeomGrp );
+ mySelBtn[ i ] = new QPushButton( myGeomGrp );
+ mySelBtn[ i ]->setPixmap( iconSlct );
+ mySelEdit[ i ] = new QLineEdit( myGeomGrp );
+ mySelEdit[ i ]->setReadOnly( true );
+ }
+
+ // Widgets for refinement of existing mesh elements
+ myRefineGrp = new QFrame( aPatGrp );
+ myRefineGrp->setFrameStyle( QFrame::NoFrame );
+ QGridLayout* aRefGrid = new QGridLayout( myRefineGrp, 3, 3, 0, 5 );
+
+ mySelLbl[ Ids ] = new QLabel( myRefineGrp );
+ mySelBtn[ Ids ] = new QPushButton( myRefineGrp );
+ mySelBtn[ Ids ]->setPixmap( iconSlct );
+ mySelEdit[ Ids ] = new QLineEdit( myRefineGrp );
+
+ QLabel* aNodeLbl = new QLabel( tr( "NODE_1" ), myRefineGrp );
+ myNode1 = new QSpinBox( myRefineGrp );
+ myNode2Lbl = new QLabel( tr( "NODE_2" ), myRefineGrp );
+ myNode2 = new QSpinBox( myRefineGrp );
+
+ aRefGrid->addWidget( mySelLbl [ Ids ], 0, 0 );
+ aRefGrid->addWidget( mySelBtn [ Ids ], 0, 1 );
+ aRefGrid->addWidget( mySelEdit[ Ids ], 0, 2 );
+ aRefGrid->addWidget( aNodeLbl, 1, 0 );
+ aRefGrid->addMultiCellWidget( myNode1, 1, 1, 1, 2 );
+ aRefGrid->addWidget( myNode2Lbl, 2, 0 );
+ aRefGrid->addMultiCellWidget( myNode2, 2, 2, 1, 2 );
+
+ // reverse check box
+ myReverseChk = new QCheckBox( tr( "REVERSE" ), aPatGrp );
+
+ // Pictures 2d and 3d
+ for ( int i = 0; i < 2; i++ )
+ {
+ if ( i == 0 )
+ {
+ myPicture2d = new SMESHGUI_PatternWidget( aPatGrp ),
+ myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
+ }
+ else
+ {
+ myPicture3d = new QFrame( aPatGrp ),
+ myPreview3d = new QLabel( myPicture3d );
+ myPreview3d->setPixmap( iconSample3d );
+ QGridLayout* aLay = new QGridLayout( myPicture3d, 3, 3, 0, 0 );
+ QSpacerItem* aSpacerH1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
+ QSpacerItem* aSpacerH2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
+ QSpacerItem* aSpacerV1 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
+ QSpacerItem* aSpacerV2 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
+ aLay->addItem( aSpacerH1, 1, 0 );
+ aLay->addItem( aSpacerH2, 1, 2 );
+ aLay->addItem( aSpacerV1, 0, 1 );
+ aLay->addItem( aSpacerV2, 2, 1 );
+ aLay->addWidget( myPreview3d, 1, 1 );
+ }
+ }
+
+ myPreviewChk = new QCheckBox( tr( "PREVIEW" ), aPatGrp );
+
+ // Connect signals and slots
+
+ connect( myTypeGrp, SIGNAL( clicked( int ) ), SLOT( onTypeChanged( int ) ) );
+ connect( myOpenBtn, SIGNAL( clicked() ), SLOT( onOpen() ) );
+ connect( myNewBtn, SIGNAL( clicked() ), SLOT( onNew() ) );
+ connect( myReverseChk, SIGNAL( toggled( bool ) ), SLOT( onReverse( bool ) ) );
+ connect( myPreviewChk, SIGNAL( toggled( bool ) ), SLOT( onPreview( bool ) ) );
+ connect( myRefine, SIGNAL( toggled( bool ) ), SLOT( onModeToggled( bool ) ) );
+ connect( myNode1, SIGNAL( valueChanged( int ) ), SLOT( onNodeChanged( int ) ) );
+ connect( myNode2, SIGNAL( valueChanged( int ) ), SLOT( onNodeChanged( int ) ) );
+ connect( mySelEdit[Ids], SIGNAL( textChanged( const QString& ) ), SLOT( onTextChanged( const QString& ) ) );
+
+ QMap< int, QPushButton* >::iterator anIter;
+ for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter )
+ connect( *anIter, SIGNAL( clicked() ), SLOT( onSelInputChanged() ) );
+
+ return aMainGrp;
+}
+
+//=======================================================================
+
+// name : SMESHGUI_MeshPatternDlg::createButtonFrame
+// Purpose : Create frame containing buttons
+//=======================================================================
+QFrame* SMESHGUI_MeshPatternDlg::createButtonFrame( QWidget* theParent )
+{
+ QFrame* aFrame = new QFrame( theParent );
+ aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
+
+ myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), aFrame );
+ myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), aFrame );
+ myCloseBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), aFrame );
+
+ QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
+
+ QHBoxLayout* aLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
+
+ aLay->addWidget( myOkBtn );
+ aLay->addWidget( myApplyBtn );
+ aLay->addItem( aSpacer);
+ aLay->addWidget( myCloseBtn );
+
+ connect( myOkBtn, SIGNAL( clicked() ), SLOT( onOk() ) );
+ connect( myCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) ) ;
+ connect( myApplyBtn, SIGNAL( clicked() ), SLOT( onApply() ) );
+
+ return aFrame;
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg
+// Purpose : Destructor
+//=======================================================================
+SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg()
+{
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::Init
+// Purpose : Init dialog fields, connect signals and slots, show dialog
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::Init( SALOME_Selection* theSelection )
+{
+ myPattern = SMESH::GetPattern();
+ myPreviewActor = 0;
+ myIsCreateDlgOpen = false;
+ mySelInput = Mesh;
+ myType = -1;
+ myNbPoints = -1;
+ mySelection = theSelection;
+ SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
+ aSMESHGUI->SetActiveDialogBox( ( QDialog* )this );
+ myMesh = SMESH::SMESH_Mesh::_nil();
+
+ myMeshShape = GEOM::GEOM_Object::_nil();
+ myGeomObj[ Object ] = GEOM::GEOM_Object::_nil();
+ myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();
+ myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();
+
+ // selection and SMESHGUI
+ connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
+ connect( aSMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) );
+ connect( aSMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) );
+
+ myTypeGrp->setButton( Type_2d );
+ onTypeChanged( Type_2d );
+ onModeToggled( isRefine() );
+
+ updateGeometry();
+
+ resize( minimumSize() );
+
+ activateSelection();
+ onSelectionDone();
+
+ int x, y ;
+ aSMESHGUI->DefineDlgPosition( this, x, y );
+ this->move( x, y );
+ this->show();
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::isValid
+// Purpose : Verify validity of entry data
+//=======================================================================
+bool SMESHGUI_MeshPatternDlg::isValid( const bool theMess )
+{
+ QValueList<int> ids;
+ if ( ( isRefine() && ( myMesh->_is_nil() || !getIds( ids ) || getNode( false ) < 0 || myType == Type_3d && ( getNode( true ) < 0 || getNode( false ) == getNode( true ) ) ) )
+ || ( !isRefine() && ( myMesh->_is_nil() || myMeshShape->_is_nil() || myGeomObj[ Object ]->_is_nil() ||
+ myGeomObj[ Vertex1 ]->_is_nil() || myType == Type_3d && myGeomObj[ Vertex2 ]->_is_nil() ) ) )
+ {
+ if ( theMess )
+ QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
+ tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SMESHGUI_INVALID_PARAMETERS" ), QMessageBox::Ok );
+ return false;
+ }
+ else
+ return true;
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onApply
+// Purpose : SLOT called when "Apply" button pressed.
+//=======================================================================
+bool SMESHGUI_MeshPatternDlg::onApply()
+{
+ try
+ {
+ if ( !isValid() )
+ return false;
+
+ erasePreview();
+
+ if ( isRefine() ) { // Refining existing mesh elements
+ QValueList<int> ids;
+ getIds( ids );
+ SMESH::long_array_var varIds = new SMESH::long_array();
+ varIds->length( ids.count() );
+ int i = 0;
+ for ( QValueList<int>::iterator it = ids.begin(); it != ids.end(); ++it )
+ varIds[i++] = *it;
+ myType == Type_2d
+ ? myPattern->ApplyToMeshFaces ( myMesh, varIds, getNode( false ), myReverseChk->isChecked() )
+ : myPattern->ApplyToHexahedrons( myMesh, varIds, getNode( false ), getNode( true ) );
+ }
+ else { // Applying a pattern to geometrical object
+ if ( myType == Type_2d )
+ myPattern->ApplyToFace(
+ myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() );
+ else
+ myPattern->ApplyTo3DBlock(
+ myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] );
+ }
+
+ if ( myPattern->MakeMesh( myMesh ) )
+ {
+ mySelection->ClearIObjects();
+ SMESH::UpdateView();
+ SMESHGUI::GetSMESHGUI()->GetActiveStudy()->updateObjBrowser( true );
+ return true;
+ }
+ else
+ {
+ QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
+ tr( "SMESH_ERROR" ), tr( "SMESH_OPERATION_FAILED" ), QMessageBox::Ok );
+ return false;
+ }
+ }
+ catch( const SALOME::SALOME_Exception& S_ex )
+ {
+ QtCatchCorbaException( S_ex );
+ }
+ catch( ... )
+ {
+ }
+
+ return false;
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onOk
+// Purpose : SLOT called when "Ok" button pressed.
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onOk()
+{
+ if ( onApply() )
+ onClose();
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onClose
+// Purpose : SLOT called when "Close" button pressed. Close dialog
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onClose()
+{
+ mySelection->ClearFilters();
+ SMESH::SetPickable();
+ QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
+ disconnect( mySelection, 0, this, 0 );
+ disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );
+ SMESHGUI::GetSMESHGUI()->ResetState();
+ erasePreview();
+ reject();
+}
+
+
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onSelectionDone
+// Purpose : SLOT called when selection changed
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onSelectionDone()
+{
+ if ( myBusy )
+ return;
+
+ try
+ {
+ if ( mySelInput == Mesh )
+ {
+ if ( mySelection->IObjectCount() != 1 )
+ return;
+
+ // Retrieve mesh from selection
+ Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
+ SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIO );
+ if ( aMesh->_is_nil() )
+ return;
+
+ // Get geom object corresponding to the mesh
+ SALOMEDS::Study_var aStudy =
+ SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getStudyDocument();
+
+ SALOMEDS::SObject_var aSO = SMESH::FindSObject( aMesh.in() );
+ if ( aSO->_is_nil() )
+ return;
+
+ bool isFound = false;
+ SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( aSO );
+ for( ; anIter->More(); anIter->Next() )
+ {
+ SALOMEDS::SObject_var aSO = anIter->Value();
+ SALOMEDS::SObject_var aRefSO;
+
+ GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(
+ aSO->ReferencedObject( aRefSO )? aRefSO->GetObject() : aSO->GetObject() );
+
+ if ( !aMeshShape->_is_nil() )
+ {
+ isFound = true;
+ myMeshShape = aMeshShape;
+ break;
+
+ }
+ }
+
+ if ( !isFound )
+ myMeshShape = GEOM::GEOM_Object::_nil();
+
+ // Clear fields of geom objects if mesh was changed
+ if ( myMesh != aMesh )
+ {
+ for ( int i = Object; i <= Ids; i++ )
+ {
+ myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
+ mySelEdit[ i ]->setText( "" );
+ }
+ }
+
+ myMesh = aMesh;
+
+ // Set name of mesh in line edit
+ QString aName;
+ SMESH::GetNameOfSelectedIObjects( mySelection, aName );
+ mySelEdit[ Mesh ]->setText( aName );
+ }
+ else if ( mySelInput == Ids ) {
+ QString anIds;
+ if ( !SMESH::GetNameOfSelectedElements( mySelection, anIds ) )
+ anIds = "";
+
+ myBusy = true;
+ mySelEdit[ Ids ]->setText( anIds );
+ myBusy = false;
+ }
+ else
+ {
+ if ( mySelection->IObjectCount() != 1 )
+ return;
+
+ // Get geom object from selection
+ Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
+ GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>( anIO );
+ if ( anObj->_is_nil() )
+ return;
+
+ // Clear fields of vertexes if face or 3d block was changed
+ if ( anObj != myGeomObj[ mySelInput ] && mySelInput == Object )
+ {
+ for ( int i = Vertex1; i <= Vertex2; i++ )
+ {
+ myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
+ mySelEdit[ i ]->setText( "" );
+ }
+ }
+
+ myGeomObj[ mySelInput ] = anObj;
+
+ // Set name of geom object in line edit
+ QString aName;
+ SMESH::GetNameOfSelectedIObjects( mySelection, aName );
+ mySelEdit[ mySelInput ]->setText( aName );
+ }
+ }
+ catch( const SALOME::SALOME_Exception& S_ex )
+ {
+ QtCatchCorbaException( S_ex );
+ resetSelInput();
+ }
+ catch( ... )
+ {
+ resetSelInput();
+ }
+
+ updateWgState();
+ displayPreview();
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::resetSelInput
+// Purpose : Reset fields corresponding to the current selection input
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::resetSelInput()
+{
+ if ( mySelInput == Mesh )
+ {
+ myMesh = SMESH::SMESH_Mesh::_nil();
+ myMeshShape = GEOM::GEOM_Object::_nil();
+ }
+
+ else
+ myGeomObj[ mySelInput ] = GEOM::GEOM_Object::_nil();
+
+ mySelEdit[ mySelInput ]->setText( "" );
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onDeactivate
+// Purpose : SLOT called when dialog must be deativated
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onDeactivate()
+{
+ mySelection->ClearFilters();
+ //if ( myReverseChk->isChecked() )
+ // erasePreview();
+ disconnect( mySelection, 0, this, 0 );
+ setEnabled( false );
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::enterEvent
+// Purpose : Event filter
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::enterEvent( QEvent* )
+{
+ if ( myIsCreateDlgOpen )
+ return;
+
+ if ( myReverseChk->isChecked() )
+ displayPreview();
+ SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog() ;
+ setEnabled( true );
+ activateSelection();
+ connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
+ onTextChanged( mySelEdit[Ids]->text() );
+}
+
+
+//=================================================================================
+// function : closeEvent()
+// purpose :
+//=================================================================================
+void SMESHGUI_MeshPatternDlg::closeEvent( QCloseEvent* e )
+{
+ onClose() ;
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onSelInputChanged
+// Purpose : SLOT. Called when -> button clicked.
+// Change current selection input field
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onSelInputChanged()
+{
+ const QObject* aSender = sender();
+ for ( int i = Mesh; i <= Ids; i++ )
+ if ( aSender == mySelBtn[ i ] )
+ mySelInput = i;
+
+ activateSelection();
+ onSelectionDone();
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::prepareFilters
+// Purpose : Prepare filters for dialog
+//=======================================================================
+
+QStringList SMESHGUI_MeshPatternDlg::prepareFilters() const
+{
+ static QStringList aList;
+ if ( aList.isEmpty() )
+ {
+ aList.append( tr( "PATTERN_FILT" ) );
+ //aList.append( tr( "ALL_FILES_FILTER" ) );
+ }
+
+ return aList;
+}
+
+//================================================================
+
+// Function : SMESHGUI_MeshPatternDlg::autoExtension
+// Purpose : Append extension to the file name
+//================================================================
+QString SMESHGUI_MeshPatternDlg::autoExtension( const QString& theFileName ) const
+{
+ QString anExt = theFileName.section( '.', -1 );
+ return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName;
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onOpen
+// Purpose : SLOT. Called when "Open" button clicked.
+// Displays file open dialog
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onOpen()
+{
+ QAD_FileDlg* aDlg = new QAD_FileDlg( this, true );
+ aDlg->setCaption( tr( "LOAD_PATTERN" ) );
+ aDlg->setMode( QFileDialogP::ExistingFile );
+ aDlg->setFilters( prepareFilters() );
+ if ( myName->text() != "" )
+ aDlg->setSelection( myName->text() + ".smp" );
+ QPushButton* anOkBtn = ( QPushButton* )aDlg->child( "OK", "QPushButton" );
+ if ( anOkBtn != 0 )
+ anOkBtn->setText( tr( "SMESH_BUT_OK" ) );
+
+ if ( aDlg->exec() != Accepted )
+ return;
+
+ QString fName = aDlg->selectedFile();
+ if ( fName.isEmpty() )
+ return;
+
+ if ( QFileInfo( fName ).extension().isEmpty() )
+ fName = autoExtension( fName );
+
+ fName = QDir::convertSeparators( fName );
+
+ QString prev = QDir::convertSeparators( myName->text() );
+ if ( prev == fName )
+ return;
+
+ // Read string from file
+ QFile aFile( fName );
+ if ( !aFile.open( IO_ReadOnly ) )
+ {
+ QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
+ tr( "SMESH_ERROR" ), tr( "ERROR_OF_OPENING" ), QMessageBox::Ok );
+ return;
+ }
+
+ QByteArray aDataArray = aFile.readAll();
+ const char* aData = aDataArray.data();
+ if ( aData == 0 )
+ {
+ QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
+ tr( "SMESH_ERROR" ), tr( "ERROR_OF_READING" ), QMessageBox::Ok );
+ return;
+ }
+
+ if ( loadFromFile( aData ) )
+ myName->setText( QFileInfo( fName ).baseName() );
+
+ updateWgState();
+ displayPreview();
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onCloseCreationDlg
+// Purpose : SLOT. Called when "Pattern creation" dialog closed with "Close"
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onCloseCreationDlg()
+{
+ setEnabled( true );
+ myIsCreateDlgOpen = false;
+}
+
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onOkCreationDlg
+// Purpose : SLOT. Called when "Pattern creation" dialog closed with OK
+// or SAVE buttons. Initialize myPattern field. Redisplay preview
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onOkCreationDlg()
+{
+ myPattern = SMESH::SMESH_Pattern::_duplicate( myCreationDlg->GetPattern() );
+ myName->setText( myCreationDlg->GetPatternName() );
+ displayPreview();
+ setEnabled( true );
+ myIsCreateDlgOpen = false;
+}
+
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onNew
+// Purpose : SLOT. Called when "New..." button clicked. Create new pattern
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onNew()
+{
+ setEnabled( false );
+ myIsCreateDlgOpen = true;
+ if ( myCreationDlg == 0 )
+ {
+ myCreationDlg = new SMESHGUI_CreatePatternDlg( this, mySelection, myType );
+ connect( myCreationDlg, SIGNAL( NewPattern() ), SLOT( onOkCreationDlg() ) );
+ connect( myCreationDlg, SIGNAL( Close() ), SLOT( onCloseCreationDlg() ) );
+ }
+ else
+ myCreationDlg->Init( mySelection, myType );
+
+ myCreationDlg->SetMesh( myMesh );
+ myCreationDlg->show();
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onReverse
+// Purpose : SLOT. Called when state of "Reverse order..." checkbox chaged
+// Calculate new points of the mesh to be created. Redisplay preview
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onReverse( bool )
+{
+ displayPreview();
+}
+
+//=======================================================================
+
+// name : SMESHGUI_MeshPatternDlg::onPreview
+// Purpose : SLOT. Called when state of "Preview" checkbox changed
+// Display/Erase preview
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onPreview( bool )
+{
+ displayPreview();
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::displayPreview
+// Purpose : Display preview
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::displayPreview()
+{
+ try
+ {
+ // Redisplay preview in dialog
+
+ SMESH::point_array_var pnts = myPattern->GetPoints();
+ SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
+ SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints();
+
+ if ( pnts->length() == 0 ||
+ keyPoints->length() == 0 ||
+ elemPoints->length() == 0 )
+ {
+ erasePreview();
+ return;
+ }
+
+ else
+ {
+ PointVector aPoints( pnts->length() );
+ QValueVector<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++ )
+ {
+ QValueVector<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 );
+ }
+
+
+ // Redisplay preview in 3D viewer
+
+ if ( myPreviewActor != 0 )
+ {
+ if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() )
+ {
+ vf->RemoveActor(myPreviewActor);
+ vf->Repaint();
+ }
+ myPreviewActor->Delete();
+ myPreviewActor = 0;
+ }
+
+ if ( !myPreviewChk->isChecked() || !isValid( false ) )
+ return;
+
+ vtkUnstructuredGrid* aGrid = getGrid();
+ if ( aGrid == 0 )
+ return;
+
+ // Create and display actor
+ vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
+ aMapper->SetInput( aGrid );
+
+ myPreviewActor = SALOME_Actor::New();
+ myPreviewActor->PickableOff();
+ myPreviewActor->SetMapper( aMapper );
+
+ vtkProperty* aProp = vtkProperty::New();
+ aProp->SetRepresentationToWireframe();
+ aProp->SetColor( 250, 0, 250 );
+ if ( SMESH::FindActorByObject( myMesh ) )
+ aProp->SetLineWidth( SMESH::GetFloat( "SMESH:SettingsWidth", 1 ) +1 );
+ else
+ aProp->SetLineWidth( 1 );
+ myPreviewActor->SetProperty( aProp );
+
+ myPreviewActor->SetRepresentation( 3 );
+
+ SMESH::GetCurrentVtkView()->AddActor( myPreviewActor );
+ SMESH::GetCurrentVtkView()->Repaint();
+
+ aProp->Delete();
+ aGrid->Delete();
+ }
+ catch( const SALOME::SALOME_Exception& S_ex )
+ {
+ QtCatchCorbaException( S_ex );
+ erasePreview();
+ }
+ catch( ... )
+ {
+ erasePreview();
+ }
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::erasePreview
+// Purpose : Erase preview
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::erasePreview()
+{
+ // Erase preview in 2D viewer
+ myPicture2d->SetPoints( PointVector(), QValueVector<int>(), ConnectivityVector() );
+
+ // Erase preview in 3D viewer
+ if ( myPreviewActor == 0 )
+ return;
+
+
+ if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() )
+ {
+ vf->RemoveActor(myPreviewActor);
+ vf->Repaint();
+ }
+ myPreviewActor->Delete();
+ myPreviewActor = 0;
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::updateWgState
+// Purpose : Enable/disable selection widgets
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::updateWgState()
+{
+ if ( myMesh->_is_nil() )
+ {
+ for ( int i = Object; i <= Ids; i++ )
+ {
+ mySelBtn [ i ]->setEnabled( false );
+ mySelEdit[ i ]->setEnabled( false );
+ mySelEdit[ i ]->setText( "" );
+ }
+ myNode1->setEnabled( false );
+ myNode2->setEnabled( false );
+ myNode1->setRange( 0, 0 );
+ myNode2->setRange( 0, 0 );
+ }
+ else
+ {
+ mySelBtn [ Object ]->setEnabled( true );
+ mySelEdit[ Object ]->setEnabled( true );
+ mySelBtn [ Ids ] ->setEnabled( true );
+ mySelEdit[ Ids ] ->setEnabled( true );
+
+ if ( myGeomObj[ Object ]->_is_nil() )
+ {
+ for ( int i = Vertex1; i <= Vertex2; i++ )
+ {
+ mySelBtn [ i ]->setEnabled( false );
+ mySelEdit[ i ]->setEnabled( false );
+ mySelEdit[ i ]->setText( "" );
+ }
+ }
+ else
+ {
+ for ( int i = Object; i <= Vertex2; i++ )
+ {
+ mySelBtn [ i ]->setEnabled( true );
+ mySelEdit[ i ]->setEnabled( true );
+ }
+ }
+
+ QValueList<int> ids;
+ if ( !CORBA::is_nil( myPattern ) && getIds( ids ) ) {
+ SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
+ if ( keyPoints->length() ) {
+ myNode1->setEnabled( true );
+ myNode2->setEnabled( true );
+ myNode1->setRange( 1, keyPoints->length() );
+ myNode2->setRange( 1, keyPoints->length() );
+ return;
+ }
+ }
+
+ myNode1->setEnabled( false );
+ myNode2->setEnabled( false );
+ myNode1->setRange( 0, 0 );
+ myNode2->setRange( 0, 0 );
+ }
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::activateSelection
+// Purpose : Activate selection in accordance with current selection input
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::activateSelection()
+{
+ mySelection->ClearFilters();
+ if ( mySelInput == Ids ) {
+ SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
+ if ( anActor )
+ SMESH::SetPickable(anActor);
+
+ if ( myType == Type_2d )
+ QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true );
+ else
+ QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
+ }
+ else {
+ SMESH::SetPickable();
+ QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
+ }
+
+ if ( mySelInput == Object && !myMeshShape->_is_nil() )
+ {
+ if ( myType == Type_2d )
+ {
+ if ( myNbPoints > 0 )
+ mySelection->AddFilter( new SMESH_NumberFilter(
+
+ "GEOM", TopAbs_VERTEX, myNbPoints, TopAbs_FACE, myMeshShape ) );
+ else
+ mySelection->AddFilter( new SMESH_NumberFilter(
+ "GEOM", TopAbs_SHAPE, myNbPoints, TopAbs_FACE, myMeshShape ) );
+ }
+ else
+ {
+ TColStd_MapOfInteger aTypes;
+ aTypes.Add( TopAbs_SHELL );
+ aTypes.Add( TopAbs_SOLID );
+ mySelection->AddFilter( new SMESH_NumberFilter(
+ "GEOM", TopAbs_FACE, 6, aTypes, myMeshShape, true ) );
+ }
+ }
+ else if ( ( mySelInput == Vertex1 || mySelInput == Vertex2 ) && !myGeomObj[ Object ]->_is_nil() )
+ {
+ mySelection->AddFilter( new SMESH_NumberFilter(
+ "GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX, myGeomObj[ Object ] ) );
+ }
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::loadFromFile
+// Purpose : Load pattern from file
+//=======================================================================
+bool SMESHGUI_MeshPatternDlg::loadFromFile( const QString& theName )
+{
+ try
+ {
+ SMESH::SMESH_Pattern_var aPattern = SMESH::GetPattern();
+
+ if ( !aPattern->LoadFromFile( theName.latin1() ) ||
+ myType == Type_2d && !aPattern->Is2D())
+ {
+ SMESH::SMESH_Pattern::ErrorCode aCode = aPattern->GetErrorCode();
+ QString aMess;
+ if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NB_POINTS ) aMess = tr( "ERR_READ_NB_POINTS" );
+ else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_POINT_COORDS ) aMess = tr( "ERR_READ_POINT_COORDS" );
+ else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_TOO_FEW_POINTS ) aMess = tr( "ERR_READ_TOO_FEW_POINTS" );
+ else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_3D_COORD ) aMess = tr( "ERR_READ_3D_COORD" );
+ else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_KEYPOINT ) aMess = tr( "ERR_READ_NO_KEYPOINT" );
+ else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_INDEX ) aMess = tr( "ERR_READ_BAD_INDEX" );
+ else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_ELEM_POINTS ) aMess = tr( "ERR_READ_ELEM_POINTS" );
+ else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_ELEMS ) aMess = tr( "ERR_READ_NO_ELEMS" );
+ else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_KEY_POINT ) aMess = tr( "ERR_READ_BAD_KEY_POINT" );
+ else aMess = tr( "ERROR_OF_LOADING" );
+
+ QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
+ tr( "SMESH_ERROR" ), aMess, QMessageBox::Ok );
+ return false;
+ }
+ else
+ {
+ myPattern = aPattern;
+ return true;
+ }
+ }
+ catch( const SALOME::SALOME_Exception& S_ex )
+ {
+ QtCatchCorbaException( S_ex );
+ QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
+ tr( "SMESH_ERROR" ), tr( "ERROR_OF_LOADING" ), QMessageBox::Ok );
+ return false;
+ }
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::onTypeChanged
+
+// Purpose : SLOT. Called when pattern type changed.
+// Change dialog's look and feel
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onTypeChanged( int theType )
+{
+ if ( myType == theType )
+ return;
+
+ myType = theType;
+
+ myNbPoints = -1;
+ myGeomObj[ Object ] = GEOM::GEOM_Object::_nil();
+ myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil();
+ myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil();
+ myPattern = SMESH::GetPattern();
+
+ myName->setText( "" );
+ mySelEdit[ Object ]->setText( "" );
+ mySelEdit[ Vertex1 ]->setText( "" );
+ mySelEdit[ Vertex2 ]->setText( "" );
+ mySelEdit[ Ids ] ->setText( "" );
+
+ if ( theType == Type_2d )
+ {
+ // Geom widgets
+ mySelLbl [ Vertex2 ]->hide();
+ mySelBtn [ Vertex2 ]->hide();
+ mySelEdit[ Vertex2 ]->hide();
+ myReverseChk->show();
+ myPicture2d->show();
+ myPicture3d->hide();
+ mySelLbl[ Object ]->setText( tr( "FACE" ) );
+ mySelLbl[ Vertex1 ]->setText( tr( "VERTEX" ) );
+ // Refine widgets
+ mySelLbl[ Ids ]->setText( tr( "MESH_FACES" ) );
+ myNode2Lbl->hide();
+ myNode2 ->hide();
+ }
+ else
+ {
+ // Geom widgets
+ mySelLbl [ Vertex2 ]->show();
+ mySelBtn [ Vertex2 ]->show();
+ mySelEdit[ Vertex2 ]->show();
+ myReverseChk->hide();
+ myPicture2d->hide();
+ myPicture3d->show();
+ mySelLbl[ Object ]->setText( tr( "3D_BLOCK" ) );
+ mySelLbl[ Vertex1 ]->setText( tr( "VERTEX1" ) );
+ mySelLbl[ Vertex2 ]->setText( tr( "VERTEX2" ) );
+ // Refine widgets
+ mySelLbl[ Ids ]->setText( tr( "MESH_VOLUMES" ) );
+ myNode2Lbl->show();
+ myNode2 ->show();
+ }
+
+ mySelInput = Mesh;
+ activateSelection();
+ updateWgState();
+ displayPreview();
+}
+
+//=======================================================================
+// name : SMESHGUI_MeshPatternDlg::getGrid
+// Purpose : Get unstructured grid for pattern
+//=======================================================================
+vtkUnstructuredGrid* SMESHGUI_MeshPatternDlg::getGrid()
+{
+ try
+ {
+ // Get points from pattern
+ SMESH::point_array_var pnts;
+ QValueList<int> ids;
+ if ( isRefine() && getIds( ids ) ) {
+ SMESH::long_array_var varIds = new SMESH::long_array();
+ varIds->length( ids.count() );
+ int i = 0;
+ for ( QValueList<int>::iterator it = ids.begin(); it != ids.end(); ++it )
+ varIds[i++] = *it;
+ pnts = myType == Type_2d
+ ? myPattern->ApplyToMeshFaces ( myMesh, varIds, getNode( false ), myReverseChk->isChecked() )
+ : myPattern->ApplyToHexahedrons( myMesh, varIds, getNode( false ), getNode( true ) );
+ }
+ else {
+ pnts = myType == Type_2d
+ ? myPattern->ApplyToFace ( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() )
+ : myPattern->ApplyTo3DBlock( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] );
+ }
+
+ SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints();
+
+ if ( pnts->length() == 0 || elemPoints->length() == 0 )
+ return 0;
+
+
+
+ // to do : to be removed /////////////////////////////////////////////
+
+#ifdef DEB_SLN
+ for ( int i1 = 0, n1 = pnts->length(); i1 < n1; i1++ )
+ printf( "%d: %g %g %g\n", i1, pnts[ i1 ].x, pnts[ i1 ].y, pnts[ i1 ].z );
+
+ printf( "\nELEMENTS : \n" );
+ for ( int i2 = 0, n2 = elemPoints->length(); i2 < n2; i2++ )
+ {
+
+ printf( "%d: ", i2 );
+ for ( int i3 = 0, n3 = elemPoints[ i2 ].length(); i3 < n3; i3++ )
+ printf( "%d ", elemPoints[ i2 ][ i3 ] );
+
+ printf( "\n" );
+
+ }
+#endif
+ //////////////////////////////////////////////////////////////////////
+
+ // Calculate number of points used for cell
+ vtkIdType aNbCells = elemPoints->length();
+ vtkIdType aCellsSize = 0;
+ for ( int i = 0, n = elemPoints->length(); i < n; i++ )
+ aCellsSize += elemPoints[ i ].length();
+
+ // Create unstructured grid and other usefull arrays
+ vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
+
+ vtkCellArray* aConnectivity = vtkCellArray::New();
+ aConnectivity->Allocate( aCellsSize, 0 );
+
+ vtkPoints* aPoints = vtkPoints::New();
+ aPoints->SetNumberOfPoints( pnts->length() );
+
+ vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
+ aCellTypesArray->SetNumberOfComponents( 1 );
+ aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
+
+ vtkIdList *anIdList = vtkIdList::New();
+
+ // Fill array of points
+ for ( int p = 0, nbPnt = pnts->length(); p < nbPnt; p++ )
+ aPoints->SetPoint( p, pnts[ p ].x, pnts[ p ].y, pnts[ p ].z );
+
+ for ( int e = 0, nbElem = elemPoints->length(); e < nbElem; e++ )
+ {
+ int nbPoints = elemPoints[ e ].length();
+ anIdList->SetNumberOfIds( nbPoints );
+ for ( int i = 0; i < nbPoints; i++ )
+ anIdList->SetId( i, elemPoints[ e ][ i ] );
+
+ aConnectivity->InsertNextCell( anIdList );
+
+ if ( nbPoints == 3 ) aCellTypesArray->InsertNextValue( VTK_TRIANGLE );
+ else if ( nbPoints == 5 ) aCellTypesArray->InsertNextValue( VTK_PYRAMID );
+ else if ( nbPoints == 6 ) aCellTypesArray->InsertNextValue( VTK_WEDGE );
+ else if ( nbPoints == 8 ) aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
+ else if ( nbPoints == 4 && myType == Type_2d ) aCellTypesArray->InsertNextValue( VTK_QUAD );
+ else if ( nbPoints == 4 && myType == Type_3d ) aCellTypesArray->InsertNextValue( VTK_TETRA );
+ else aCellTypesArray->InsertNextValue( VTK_EMPTY_CELL );
+ }
+
+ vtkIntArray* aCellLocationsArray = vtkIntArray::New();
+ aCellLocationsArray->SetNumberOfComponents( 1 );
+ aCellLocationsArray->SetNumberOfTuples( aNbCells );
+
+ aConnectivity->InitTraversal();
+ for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
+ aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
+
+ aGrid->SetPoints( aPoints );
+ aGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
+
+ aConnectivity->Delete();
+ aPoints->Delete();
+ aCellTypesArray->Delete();
+ anIdList->Delete();
+ aCellLocationsArray->Delete();
+
+ return aGrid;
+ }
+ catch( ... )
+ {
+ return 0;
+ }
+}
+
+//=======================================================================
+// name : onModeToggled
+// Purpose :
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onModeToggled( bool on )
+{
+ on ? myRefineGrp->show() : myRefineGrp->hide();
+ on ? myGeomGrp->hide() : myGeomGrp->show();
+}
+
+//=======================================================================
+// name : isRefine
+// Purpose :
+//=======================================================================
+bool SMESHGUI_MeshPatternDlg::isRefine() const
+{
+ return myRefine->isChecked();
+}
+
+//=======================================================================
+//function : onTextChanged
+//purpose :
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onTextChanged(const QString& theNewText)
+{
+ if ( myBusy || !isRefine() )
+ return;
+
+ myBusy = true;
+
+ if ( mySelInput != Ids ) {
+ mySelInput = Ids;
+ activateSelection();
+ }
+
+ // hilight entered elements/nodes
+ SMDS_Mesh* aMesh = 0;
+ SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
+ if ( anActor )
+ aMesh = anActor->GetObject()->GetMesh();
+
+ if ( aMesh ) {
+ mySelection->ClearIObjects();
+ mySelection->AddIObject( anActor->getIO() );
+
+ QStringList aListId = QStringList::split( " ", theNewText, false);
+
+ for ( int i = 0; i < aListId.count(); i++ ) {
+ const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
+ if ( e && e->GetType() == ( myType == Type_2d ? SMDSAbs_Face : SMDSAbs_Volume ) ) {
+ if ( !mySelection->IsIndexSelected( anActor->getIO(), e->GetID() ) )
+ mySelection->AddOrRemoveIndex( anActor->getIO(), e->GetID(), true );
+ }
+ }
+ }
+
+ myBusy = false;
+}
+
+//=======================================================================
+//function : onNodeChanged
+//purpose :
+//=======================================================================
+void SMESHGUI_MeshPatternDlg::onNodeChanged( int value )
+{
+ if ( myType == Type_3d ) {
+ QSpinBox* first = (QSpinBox*)sender();
+ QSpinBox* second = first == myNode1 ? myNode2 : myNode1;
+ int secondVal = second->value();
+ if ( secondVal == value ) {
+ secondVal = value == second->maxValue() ? second->minValue() : value + 1;
+ bool blocked = second->signalsBlocked();
+ second->blockSignals( true );
+ second->setValue( secondVal );
+ second->blockSignals( blocked );
+ }
+ }
+
+ displayPreview();
+}
+
+//=======================================================================
+//function : getIds
+//purpose :
+//=======================================================================
+bool SMESHGUI_MeshPatternDlg::getIds( QValueList<int>& ids ) const
+{
+ ids.clear();
+ QStringList strIds = QStringList::split( " ", mySelEdit[Ids]->text() );
+ bool isOk;
+ int val;
+ for ( QStringList::iterator it = strIds.begin(); it != strIds.end(); ++it ) {
+ val = (*it).toInt( &isOk );
+ if ( isOk )
+ ids.append( val );
+ }
+
+ return ids.count();
+}
+
+//=======================================================================
+//function : getNode1
+//purpose :
+//=======================================================================
+int SMESHGUI_MeshPatternDlg::getNode( bool second ) const
+{
+ return second ? myNode2->value() - 1 : myNode1->value() - 1;
+}
+