smesh/src/SMESHGUI/SMESHGUI_MeshPatternDlg.cxx

1455 lines
48 KiB
C++
Raw Normal View History

2013-04-01 19:05:47 +06:00
// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
2005-01-20 11:25:54 +05:00
//
2012-08-09 16:03:55 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
2012-08-09 16:03:55 +06:00
// 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.
//
2012-08-09 16:03:55 +06:00
// 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.
//
2012-08-09 16:03:55 +06:00
// 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
//
2012-08-09 16:03:55 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2005-01-20 11:25:54 +05:00
//
2012-08-09 16:03:55 +06:00
2009-02-17 10:27:49 +05:00
// SMESH SMESHGUI : GUI for SMESH component
// File : SMESHGUI_MeshPatternDlg.cxx
// Author : Sergey LITONIN, Open CASCADE S.A.S.
// SMESH includes
2005-01-20 11:25:54 +05:00
//
#include "SMESHGUI_MeshPatternDlg.h"
#include "SMESHGUI.h"
#include "SMESHGUI_CreatePatternDlg.h"
#include "SMESHGUI_PatternWidget.h"
#include "SMESHGUI_Utils.h"
#include "SMESHGUI_VTKUtils.h"
2005-01-20 11:25:54 +05:00
#include "SMESHGUI_PatternUtils.h"
#include "SMESHGUI_GEOMGenUtils.h"
2009-02-17 10:27:49 +05:00
#include <SMESH_Actor.h>
#include <SMESH_ActorUtils.h>
#include <SMESH_NumberFilter.hxx>
2009-02-17 10:27:49 +05:00
#include <SMDS_Mesh.hxx>
#include <SMDS_MeshElement.hxx>
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
// SALOME GUI includes
#include <SUIT_ResourceMgr.h>
#include <SUIT_Desktop.h>
#include <SUIT_FileDlg.h>
#include <SUIT_Session.h>
#include <SUIT_MessageBox.h>
2009-02-17 10:27:49 +05:00
#include <LightApp_SelectionMgr.h>
#include <SalomeApp_Tools.h>
#include <LightApp_Application.h>
#include <SalomeApp_IntSpinBox.h>
2009-02-17 10:27:49 +05:00
#include <SALOME_ListIO.hxx>
2009-02-17 10:27:49 +05:00
#include <SVTK_ViewModel.h>
#include <SVTK_ViewWindow.h>
#include <VTKViewer_CellLocationsArray.h>
2009-02-17 10:27:49 +05:00
// SALOME KERNEL includes
#include <SALOMEDS_SObject.hxx>
2009-02-17 10:27:49 +05:00
// OCCT includes
2005-01-20 11:25:54 +05:00
#include <TColStd_MapOfInteger.hxx>
2009-02-17 10:27:49 +05:00
// Qt includes
#include <QFrame>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QGroupBox>
#include <QLabel>
#include <QRadioButton>
#include <QCheckBox>
#include <QButtonGroup>
#include <QList>
#include <QDir>
#include <QFileDialog>
#include <QFileInfo>
#include <QFile>
#include <QKeyEvent>
// VTK includes
2005-01-20 11:25:54 +05:00
#include <vtkIdList.h>
#include <vtkCellArray.h>
#include <vtkUnsignedCharArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataSetMapper.h>
#include <vtkProperty.h>
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
#define SPACING 6
#define MARGIN 11
2005-01-20 11:25:54 +05:00
/*!
* Class : SMESHGUI_MeshPatternDlg
* Description : Dialog to specify filters for VTK viewer
*/
2005-01-20 11:25:54 +05:00
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg
// Purpose : Constructor
//=======================================================================
2009-02-17 10:27:49 +05:00
SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg( SMESHGUI* theModule )
: QDialog( SMESH::GetDesktop( theModule ) ),
mySMESHGUI( theModule ),
mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
myBusy( false ),
myCreationDlg( 0 )
2005-01-20 11:25:54 +05:00
{
2009-02-17 10:27:49 +05:00
setModal( false );
setWindowTitle( tr( "CAPTION" ) );
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
QVBoxLayout* aDlgLay = new QVBoxLayout( this );
aDlgLay->setMargin( MARGIN );
aDlgLay->setSpacing( SPACING );
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
QWidget* aMainFrame = createMainFrame ( this );
QWidget* aBtnFrame = createButtonFrame( this );
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
aDlgLay->addWidget( aMainFrame );
aDlgLay->addWidget( aBtnFrame );
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
aDlgLay->setStretchFactor( aMainFrame, 1 );
mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
2005-08-11 14:04:31 +06:00
myHelpFileName = "pattern_mapping_page.html";
Init();
2005-01-20 11:25:54 +05:00
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::createMainFrame
// Purpose : Create frame containing dialog's input fields
//=======================================================================
2009-02-17 10:27:49 +05:00
QWidget* SMESHGUI_MeshPatternDlg::createMainFrame (QWidget* theParent)
2005-01-20 11:25:54 +05:00
{
2005-06-08 16:45:19 +06:00
SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
2009-02-17 10:27:49 +05:00
QPixmap iconSlct ( mgr->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
QPixmap icon2d ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) );
QPixmap icon3d ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) );
QPixmap iconOpen ( mgr->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ) );
QPixmap iconSample2d ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) );
QPixmap iconSample3d ( mgr->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_3D" ) ) );
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
QWidget* aMainGrp = new QWidget( theParent );
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
QVBoxLayout* aMainGrpLayout = new QVBoxLayout( aMainGrp );
aMainGrpLayout->setMargin( 0 );
aMainGrpLayout->setSpacing( SPACING );
2005-01-20 11:25:54 +05:00
// Pattern type group
2009-02-17 10:27:49 +05:00
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 );
2005-01-20 11:25:54 +05:00
// Mesh group
2009-02-17 10:27:49 +05:00
QGroupBox* aMeshGrp = new QGroupBox( tr( "SMESH_MESH" ), aMainGrp );
QHBoxLayout* aMeshGrpLayout = new QHBoxLayout( aMeshGrp );
aMeshGrpLayout->setMargin( MARGIN );
aMeshGrpLayout->setSpacing( SPACING );
QLabel* aMeshLab = new QLabel( tr( "SMESH_MESH" ), aMeshGrp );
mySelBtn[ Mesh ] = new QPushButton( aMeshGrp );
mySelBtn[ Mesh ]->setIcon( iconSlct );
mySelEdit[ Mesh ] = new QLineEdit( aMeshGrp );
mySelEdit[ Mesh ]->setReadOnly( true );
// ... layout widgets
aMeshGrpLayout->addWidget( aMeshLab );
aMeshGrpLayout->addWidget( mySelBtn[ Mesh ] );
aMeshGrpLayout->addWidget( mySelEdit[ Mesh ] );
2005-01-20 11:25:54 +05:00
// Pattern group
2009-02-17 10:27:49 +05:00
QGroupBox* aPatGrp = new QGroupBox( tr( "PATTERN" ), aMainGrp );
QGridLayout* aPatGrpLayout = new QGridLayout( aPatGrp );
aPatGrpLayout->setMargin( MARGIN );
aPatGrpLayout->setSpacing( SPACING );
// ... Pattern name
QLabel* aNameLab = new QLabel( tr( "PATTERN" ), aPatGrp );
myName = new QLineEdit( aPatGrp );
myName->setReadOnly( true );
myOpenBtn = new QPushButton( aPatGrp );
myOpenBtn->setIcon( iconOpen );
myNewBtn = new QPushButton( tr( "NEW" ), aPatGrp );
// ... Mode selection check box
myRefine = new QCheckBox( tr( "REFINE" ), aPatGrp );
// ... selection widgets for Apply to geom mode
myGeomGrp = new QFrame( aPatGrp );
myGeomGrp->setFrameStyle( QFrame::NoFrame );
QGridLayout* myGeomGrpLayout = new QGridLayout( myGeomGrp );
myGeomGrpLayout->setMargin( 0 );
myGeomGrpLayout->setSpacing( SPACING );
for ( int i = Object; i <= Vertex2; i++ ) {
mySelLbl[ i ] = new QLabel( myGeomGrp );
mySelBtn[ i ] = new QPushButton( myGeomGrp );
mySelBtn[ i ]->setIcon( iconSlct );
mySelEdit[ i ] = new QLineEdit( myGeomGrp );
mySelEdit[ i ]->setReadOnly( true );
myGeomGrpLayout->addWidget( mySelLbl[ i ], i - Object, 0 );
myGeomGrpLayout->addWidget( mySelBtn[ i ], i - Object, 1 );
myGeomGrpLayout->addWidget( mySelEdit[ i ], i - Object, 2 );
}
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
// ... Widgets for refinement of existing mesh elements
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
myRefineGrp = new QFrame( aPatGrp );
myRefineGrp->setFrameStyle( QFrame::NoFrame );
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
QGridLayout* myRefineGrpLayout = new QGridLayout( myRefineGrp );
myRefineGrpLayout->setMargin( 0 );
myRefineGrpLayout->setSpacing( SPACING );
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
mySelLbl[ Ids ] = new QLabel( myRefineGrp );
mySelBtn[ Ids ] = new QPushButton( myRefineGrp );
mySelBtn[ Ids ]->setIcon( iconSlct );
mySelEdit[ Ids ] = new QLineEdit( myRefineGrp );
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
QLabel* aNodeLbl = new QLabel( tr( "NODE_1" ), myRefineGrp );
myNode1 = new SalomeApp_IntSpinBox( myRefineGrp );
myNode2Lbl = new QLabel( tr( "NODE_2" ), myRefineGrp );
myNode2 = new SalomeApp_IntSpinBox( myRefineGrp );
myRefineGrpLayout->addWidget( mySelLbl[ Ids ], 0, 0 );
myRefineGrpLayout->addWidget( mySelBtn[ Ids ], 0, 1 );
myRefineGrpLayout->addWidget( mySelEdit[ Ids ], 0, 2 );
myRefineGrpLayout->addWidget( aNodeLbl, 1, 0 );
myRefineGrpLayout->addWidget( myNode1, 1, 1, 1, 2 );
myRefineGrpLayout->addWidget( myNode2Lbl, 2, 0 );
myRefineGrpLayout->addWidget( myNode2, 2, 1, 1, 2 );
// ... reverse check box
myReverseChk = new QCheckBox( tr( "REVERSE" ), aPatGrp );
// ... CreatePoly check box
myCreatePolygonsChk = new QCheckBox( tr( "CREATE_POLYGONS_NEAR_BOUNDARY" ), aPatGrp );
myCreatePolyedrsChk = new QCheckBox( tr( "CREATE_POLYEDRS_NEAR_BOUNDARY" ), aPatGrp );
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
// ... Pictures 2d and 3d
myPicture2d = new SMESHGUI_PatternWidget( aPatGrp );
myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
myPicture3d = new QLabel( aPatGrp );
myPicture3d->setPixmap( iconSample3d );
myPicture3d->setScaledContents( false );
myPicture3d->setAlignment( Qt::AlignCenter );
myPicture3d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
// ... preview check box
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
myPreviewChk = new QCheckBox( tr( "PREVIEW" ), aPatGrp );
// ... layout widgets
aPatGrpLayout->addWidget( aNameLab, 0, 0 );
aPatGrpLayout->addWidget( myName, 0, 1 );
aPatGrpLayout->addWidget( myOpenBtn, 0, 2 );
aPatGrpLayout->addWidget( myNewBtn, 0, 3 );
aPatGrpLayout->addWidget( myRefine, 1, 0, 1, 4 );
aPatGrpLayout->addWidget( myRefine, 1, 0, 1, 4 );
aPatGrpLayout->addWidget( myGeomGrp, 2, 0, 1, 4 );
aPatGrpLayout->addWidget( myRefineGrp, 3, 0, 1, 4 );
aPatGrpLayout->addWidget( myReverseChk, 4, 0, 1, 4 );
aPatGrpLayout->addWidget( myCreatePolygonsChk, 5, 0, 1, 4 );
aPatGrpLayout->addWidget( myCreatePolyedrsChk, 6, 0, 1, 4 );
aPatGrpLayout->addWidget( myPicture2d, 7, 0, 1, 4 );
aPatGrpLayout->addWidget( myPicture3d, 8, 0, 1, 4 );
aPatGrpLayout->addWidget( myPreviewChk, 9, 0, 1, 4 );
// main layout
aMainGrpLayout->addWidget( aTypeGrp );
aMainGrpLayout->addWidget( aMeshGrp );
aMainGrpLayout->addWidget( aPatGrp );
2005-01-20 11:25:54 +05:00
// Connect signals and slots
2009-02-17 10:27:49 +05:00
connect(myTypeGrp, SIGNAL(buttonClicked(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&)));
2005-01-20 11:25:54 +05:00
QMap< int, QPushButton* >::iterator anIter;
for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter)
connect(*anIter, SIGNAL(clicked()), SLOT(onSelInputChanged()));
2005-01-20 11:25:54 +05:00
return aMainGrp;
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::createButtonFrame
// Purpose : Create frame containing buttons
//=======================================================================
2009-02-17 10:27:49 +05:00
QWidget* SMESHGUI_MeshPatternDlg::createButtonFrame (QWidget* theParent)
2005-01-20 11:25:54 +05:00
{
QFrame* aFrame = new QFrame(theParent);
aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
2009-02-17 10:27:49 +05:00
myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
QHBoxLayout* aLay = new QHBoxLayout( aFrame );
aLay->setMargin( MARGIN );
aLay->setSpacing( SPACING );
2005-01-20 11:25:54 +05:00
aLay->addWidget(myOkBtn);
aLay->addWidget(myApplyBtn);
2009-02-17 10:27:49 +05:00
aLay->addSpacing( 10 );
aLay->addStretch();
aLay->addWidget(myCloseBtn);
aLay->addWidget(myHelpBtn);
2005-01-20 11:25:54 +05:00
connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
2013-02-28 21:07:35 +06:00
connect(myCloseBtn, SIGNAL(clicked()), SLOT(reject()));
connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
2005-01-20 11:25:54 +05:00
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()
2005-01-20 11:25:54 +05:00
{
myPattern = SMESH::GetPattern();
myPreviewActor = 0;
myIsCreateDlgOpen = false;
mySelInput = Mesh;
myType = -1;
myNbPoints = -1;
mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2005-01-20 11:25:54 +05:00
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(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
2013-02-28 21:07:35 +06:00
connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
2005-01-20 11:25:54 +05:00
2009-02-17 10:27:49 +05:00
myTypeGrp->button(Type_2d)->setChecked(true);
onTypeChanged(Type_2d);
onModeToggled(isRefine());
2005-01-20 11:25:54 +05:00
updateGeometry();
2012-08-09 16:03:55 +06:00
resize(100,100);
2005-01-20 11:25:54 +05:00
activateSelection();
onSelectionDone();
this->show();
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::isValid
// Purpose : Verify validity of entry data
//=======================================================================
bool SMESHGUI_MeshPatternDlg::isValid (const bool theMess)
2005-01-20 11:25:54 +05:00
{
2009-02-17 10:27:49 +05:00
if (isRefine())
{
QString msg;
bool ok = true;
ok = myNode1->isValid( msg, theMess ) && ok;
if (myType == Type_3d)
ok = myNode2->isValid( msg, theMess ) && ok;
if( !ok ) {
if( theMess ) {
2012-08-09 16:03:55 +06:00
QString str( tr( "SMESH_INCORRECT_INPUT" ) );
if ( !msg.isEmpty() )
str += "\n" + msg;
SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
2009-02-17 10:27:49 +05:00
}
return false;
}
}
QList<int> ids;
if ((isRefine() &&
(myMesh->_is_nil() || !getIds(ids) || getNode(false) < 0 ||
2012-08-09 16:03:55 +06:00
(myType == Type_3d && (getNode(true) < 0 || getNode(false) == getNode(true)))))
||
(!isRefine() &&
(myMesh->_is_nil() || myMeshShape->_is_nil() || myGeomObj[ Object ]->_is_nil() ||
2012-08-09 16:03:55 +06:00
myGeomObj[ Vertex1 ]->_is_nil() || (myType == Type_3d && myGeomObj[ Vertex2 ]->_is_nil()))))
2005-01-20 11:25:54 +05:00
{
if (theMess)
2009-02-17 10:27:49 +05:00
SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
2012-08-09 16:03:55 +06:00
tr("SMESHGUI_INVALID_PARAMETERS"));
2005-01-20 11:25:54 +05:00
return false;
}
2009-02-17 10:27:49 +05:00
if ( myName->text().isEmpty() ) {
if (theMess)
2009-02-17 10:27:49 +05:00
SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
2012-08-09 16:03:55 +06:00
tr("SMESHGUI_INVALID_PARAMETERS"));
return false;
}
return true;
2005-01-20 11:25:54 +05:00
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::onApply
// Purpose : SLOT called when "Apply" button pressed.
//=======================================================================
bool SMESHGUI_MeshPatternDlg::onApply()
{
try {
if (!isValid())
2005-01-20 11:25:54 +05:00
return false;
erasePreview();
if (isRefine()) { // Refining existing mesh elements
2012-08-09 16:03:55 +06:00
{
QStringList aParameters;
aParameters << myNode1->text();
if(myType == Type_3d )
aParameters << myNode2->text();
myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
}
2009-02-17 10:27:49 +05:00
QList<int> ids;
getIds(ids);
2005-01-20 11:25:54 +05:00
SMESH::long_array_var varIds = new SMESH::long_array();
varIds->length(ids.count());
2005-01-20 11:25:54 +05:00
int i = 0;
2009-02-17 10:27:49 +05:00
for (QList<int>::iterator it = ids.begin(); it != ids.end(); ++it)
2012-08-09 16:03:55 +06:00
varIds[i++] = *it;
2005-01-20 11:25:54 +05:00
myType == Type_2d
2012-08-09 16:03:55 +06:00
? myPattern->ApplyToMeshFaces (myMesh, varIds, getNode(false), myReverseChk->isChecked())
: myPattern->ApplyToHexahedrons(myMesh, varIds, getNode(false), getNode(true));
2009-02-17 10:27:49 +05:00
} 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]);
2005-01-20 11:25:54 +05:00
}
bool toCreatePolygons = myCreatePolygonsChk->isChecked();
bool toCreatePolyedrs = myCreatePolyedrsChk->isChecked();
if ( myPattern->MakeMesh( myMesh, toCreatePolygons, toCreatePolyedrs ) ) {
//mySelectionMgr->clearSelected();
2005-06-27 17:29:58 +06:00
bool autoUpdate = SMESHGUI::automaticUpdate();
if (!isRefine() && autoUpdate) {
2012-08-09 16:03:55 +06:00
_PTR(SObject) aSO = SMESH::FindSObject(myMesh.in());
SMESH_Actor* anActor = SMESH::FindActorByEntry(aSO->GetID().c_str());
if (!anActor) {
anActor = SMESH::CreateActor(aSO->GetStudy(), aSO->GetID().c_str());
if (anActor) {
SMESH::DisplayActor(SMESH::GetActiveWindow(), anActor);
SMESH::FitAll();
}
}
}
mySelectionMgr->clearSelected();
2005-01-20 11:25:54 +05:00
SMESH::UpdateView();
2012-08-09 16:03:55 +06:00
SMESHGUI::Modified();
2005-08-11 14:04:31 +06:00
mySMESHGUI->updateObjBrowser(true);
mySelEdit[ Ids ]->setText("");
2005-01-20 11:25:54 +05:00
return true;
} else {
2009-02-17 10:27:49 +05:00
SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
2012-08-09 16:03:55 +06:00
tr("SMESH_OPERATION_FAILED"));
2005-01-20 11:25:54 +05:00
return false;
}
} catch (const SALOME::SALOME_Exception& S_ex) {
SalomeApp_Tools::QtCatchCorbaException(S_ex);
} catch (...) {
2005-01-20 11:25:54 +05:00
}
return false;
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::onOk
// Purpose : SLOT called when "Ok" button pressed.
//=======================================================================
void SMESHGUI_MeshPatternDlg::onOk()
{
if (onApply())
2013-02-28 21:07:35 +06:00
reject();
2005-01-20 11:25:54 +05:00
}
//=======================================================================
2013-02-28 21:07:35 +06:00
// name : SMESHGUI_MeshPatternDlg::reject
2005-01-20 11:25:54 +05:00
// Purpose : SLOT called when "Close" button pressed. Close dialog
//=======================================================================
2013-02-28 21:07:35 +06:00
void SMESHGUI_MeshPatternDlg::reject()
2005-01-20 11:25:54 +05:00
{
mySelectionMgr->clearFilters();
2005-01-20 11:25:54 +05:00
SMESH::SetPickable();
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode(ActorSelection);
disconnect(mySelectionMgr, 0, this, 0);
disconnect(mySMESHGUI, 0, this, 0);
mySMESHGUI->ResetState();
2005-01-20 11:25:54 +05:00
erasePreview();
2013-02-28 21:07:35 +06:00
QDialog::reject();
2005-01-20 11:25:54 +05:00
}
//=================================================================================
// function : onHelp()
// purpose :
//=================================================================================
void SMESHGUI_MeshPatternDlg::onHelp()
{
LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
if (app)
app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
else {
2012-08-09 16:03:55 +06:00
QString platform;
#ifdef WIN32
2012-08-09 16:03:55 +06:00
platform = "winapplication";
#else
2012-08-09 16:03:55 +06:00
platform = "application";
#endif
2009-02-17 10:27:49 +05:00
SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
2012-08-09 16:03:55 +06:00
tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
arg(app->resourceMgr()->stringValue("ExternalBrowser",
platform)).
arg(myHelpFileName));
}
}
2005-01-20 11:25:54 +05:00
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::onSelectionDone
// Purpose : SLOT called when selection changed
//=======================================================================
void SMESHGUI_MeshPatternDlg::onSelectionDone()
{
if (myBusy)
2005-01-20 11:25:54 +05:00
return;
try {
if (mySelInput == Mesh) {
SALOME_ListIO aList;
mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
if (aList.Extent() != 1)
2012-08-09 16:03:55 +06:00
return;
2005-01-20 11:25:54 +05:00
// Retrieve mesh from selection
Handle(SALOME_InteractiveObject) anIO = aList.First();
SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
if (aMesh->_is_nil())
2005-01-20 11:25:54 +05:00
return;
// Get geom object corresponding to the mesh
_PTR(SObject) aSO = SMESH::FindSObject(aMesh.in());
myMeshShape = SMESH::GetGeom(aSO);
2005-01-20 11:25:54 +05:00
// Clear fields of geom objects if mesh was changed
if (myMesh != aMesh) {
for (int i = Object; i <= Ids; i++) {
2005-01-20 11:25:54 +05:00
myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
mySelEdit[ i ]->setText("");
2005-01-20 11:25:54 +05:00
}
}
myMesh = aMesh;
// Set name of mesh in line edit
QString aName;
SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
mySelEdit[ Mesh ]->setText(aName);
} else if (mySelInput == Ids) {
SALOME_ListIO aList;
mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
if (aList.Extent() != 1)
2012-08-09 16:03:55 +06:00
return;
2005-01-20 11:25:54 +05:00
QString anIds;
if (!SMESH::GetNameOfSelectedElements(mySelector, aList.First(), anIds))
2012-08-09 16:03:55 +06:00
anIds = "";
2005-01-20 11:25:54 +05:00
myBusy = true;
mySelEdit[ Ids ]->setText(anIds);
2005-01-20 11:25:54 +05:00
myBusy = false;
} else {
SALOME_ListIO aList;
mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
if (aList.Extent() != 1)
2012-08-09 16:03:55 +06:00
return;
2005-01-20 11:25:54 +05:00
// Get geom object from selection
Handle(SALOME_InteractiveObject) anIO = aList.First();
GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
if (anObj->_is_nil())
2005-01-20 11:25:54 +05:00
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++) {
2005-01-20 11:25:54 +05:00
myGeomObj[ i ] = GEOM::GEOM_Object::_nil();
mySelEdit[ i ]->setText("");
2005-01-20 11:25:54 +05:00
}
}
myGeomObj[ mySelInput ] = anObj;
// Set name of geom object in line edit
QString aName;
SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
mySelEdit[ mySelInput ]->setText(aName);
2005-01-20 11:25:54 +05:00
}
} catch (const SALOME::SALOME_Exception& S_ex) {
SalomeApp_Tools::QtCatchCorbaException(S_ex);
2005-01-20 11:25:54 +05:00
resetSelInput();
} catch (...) {
2005-01-20 11:25:54 +05:00
resetSelInput();
}
updateWgState();
displayPreview();
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::resetSelInput
// Purpose : Reset fields corresponding to the current selection input
//=======================================================================
void SMESHGUI_MeshPatternDlg::resetSelInput()
{
if (mySelInput == Mesh)
2005-01-20 11:25:54 +05:00
{
myMesh = SMESH::SMESH_Mesh::_nil();
myMeshShape = GEOM::GEOM_Object::_nil();
}
else
myGeomObj[ mySelInput ] = GEOM::GEOM_Object::_nil();
mySelEdit[ mySelInput ]->setText("");
2005-01-20 11:25:54 +05:00
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::onDeactivate
// Purpose : SLOT called when dialog must be deativated
//=======================================================================
void SMESHGUI_MeshPatternDlg::onDeactivate()
{
mySelectionMgr->clearFilters();
//if (myReverseChk->isChecked())
2005-01-20 11:25:54 +05:00
// erasePreview();
disconnect(mySelectionMgr, 0, this, 0);
setEnabled(false);
2005-01-20 11:25:54 +05:00
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::enterEvent
// Purpose : Event filter
//=======================================================================
void SMESHGUI_MeshPatternDlg::enterEvent (QEvent*)
2005-01-20 11:25:54 +05:00
{
if (myIsCreateDlgOpen)
2005-01-20 11:25:54 +05:00
return;
if (myReverseChk->isChecked())
2005-01-20 11:25:54 +05:00
displayPreview();
mySMESHGUI->EmitSignalDeactivateDialog();
setEnabled(true);
2005-01-20 11:25:54 +05:00
activateSelection();
connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
onTextChanged(mySelEdit[Ids]->text());
2005-01-20 11:25:54 +05:00
}
//=======================================================================
// 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 ])
2005-01-20 11:25:54 +05:00
mySelInput = i;
activateSelection();
onSelectionDone();
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::prepareFilters
// Purpose : Prepare filters for dialog
//=======================================================================
QStringList SMESHGUI_MeshPatternDlg::prepareFilters() const
{
static QStringList aList;
if (aList.isEmpty())
2005-01-20 11:25:54 +05:00
{
aList.append(tr("PATTERN_FILT"));
//aList.append(tr("ALL_FILES_FILTER"));
2005-01-20 11:25:54 +05:00
}
return aList;
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::autoExtension
// Purpose : Append extension to the file name
//=======================================================================
QString SMESHGUI_MeshPatternDlg::autoExtension (const QString& theFileName) const
2005-01-20 11:25:54 +05:00
{
QString anExt = theFileName.section('.', -1);
2005-01-20 11:25:54 +05:00
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()
{
SUIT_FileDlg* aDlg = new SUIT_FileDlg (this, true);
2009-02-17 10:27:49 +05:00
aDlg->setWindowTitle(tr("LOAD_PATTERN"));
aDlg->setFileMode(QFileDialog::ExistingFile);
aDlg->setFilters(prepareFilters());
2009-02-17 10:27:49 +05:00
if (!myName->text().isEmpty())
aDlg->selectFile(myName->text() + ".smp");
QPushButton* anOkBtn = qFindChild<QPushButton*>( aDlg, "OK" );
if (anOkBtn != 0)
anOkBtn->setText(tr("SMESH_BUT_OK"));
if (aDlg->exec() != Accepted)
2005-01-20 11:25:54 +05:00
return;
QString fName = aDlg->selectedFile();
if (fName.isEmpty())
2005-01-20 11:25:54 +05:00
return;
2009-02-17 10:27:49 +05:00
if (QFileInfo(fName).suffix().isEmpty())
fName = autoExtension(fName);
2005-01-20 11:25:54 +05:00
fName = QDir::convertSeparators(fName);
QString prev = QDir::convertSeparators(myName->text());
if (prev == fName)
2005-01-20 11:25:54 +05:00
return;
// Read string from file
QFile aFile(fName);
2009-02-17 10:27:49 +05:00
if (!aFile.open(QIODevice::ReadOnly)) {
SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
2012-08-09 16:03:55 +06:00
tr("ERROR_OF_OPENING"));
2005-01-20 11:25:54 +05:00
return;
}
2005-01-20 11:25:54 +05:00
QByteArray aDataArray = aFile.readAll();
2009-02-17 10:27:49 +05:00
if (aDataArray.isEmpty()) {
SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
2012-08-09 16:03:55 +06:00
tr("ERROR_OF_READING"));
2005-01-20 11:25:54 +05:00
return;
}
2009-02-17 10:27:49 +05:00
if (loadFromFile(aDataArray))
myName->setText(QFileInfo(fName).completeBaseName());
2005-01-20 11:25:54 +05:00
updateWgState();
displayPreview();
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::onCloseCreationDlg
// Purpose : SLOT. Called when "Pattern creation" dialog closed with "Close"
//=======================================================================
void SMESHGUI_MeshPatternDlg::onCloseCreationDlg()
{
setEnabled(true);
2005-01-20 11:25:54 +05:00
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());
updateWgState();
2005-01-20 11:25:54 +05:00
displayPreview();
setEnabled(true);
2005-01-20 11:25:54 +05:00
myIsCreateDlgOpen = false;
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::onNew
// Purpose : SLOT. Called when "New..." button clicked. Create new pattern
//=======================================================================
void SMESHGUI_MeshPatternDlg::onNew()
{
setEnabled(false);
2005-01-20 11:25:54 +05:00
myIsCreateDlgOpen = true;
if (myCreationDlg == 0)
2005-01-20 11:25:54 +05:00
{
myCreationDlg = new SMESHGUI_CreatePatternDlg( mySMESHGUI, myType);
connect(myCreationDlg, SIGNAL(NewPattern()), SLOT(onOkCreationDlg()));
connect(myCreationDlg, SIGNAL(Close()), SLOT(onCloseCreationDlg()));
2005-01-20 11:25:54 +05:00
}
else
myCreationDlg->Init(myType);
2005-01-20 11:25:54 +05:00
myCreationDlg->SetMesh(myMesh);
2005-01-20 11:25:54 +05:00
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)
2005-01-20 11:25:54 +05:00
{
displayPreview();
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::onPreview
// Purpose : SLOT. Called when state of "Preview" checkbox changed
// Display/Erase preview
//=======================================================================
void SMESHGUI_MeshPatternDlg::onPreview (bool)
2005-01-20 11:25:54 +05:00
{
displayPreview();
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::displayPreview
// Purpose : Display preview
//=======================================================================
void SMESHGUI_MeshPatternDlg::displayPreview()
{
try {
2005-01-20 11:25:54 +05:00
// 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(false);
2005-01-20 11:25:54 +05:00
if (pnts->length() == 0 ||
keyPoints->length() == 0 ||
elemPoints->length() == 0) {
2005-01-20 11:25:54 +05:00
erasePreview();
return;
} else {
PointVector aPoints(pnts->length());
2009-02-17 10:27:49 +05:00
QVector<int> aKeyPoints(keyPoints->length());
ConnectivityVector anElemPoints(elemPoints->length());
2005-01-20 11:25:54 +05:00
for (int i = 0, n = pnts->length(); i < n; i++)
2005-01-20 11:25:54 +05:00
aPoints[ i ] = pnts[ i ];
for (int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++)
2005-01-20 11:25:54 +05:00
aKeyPoints[ i2 ] = keyPoints[ i2 ];
for (int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++) {
2009-02-17 10:27:49 +05:00
QVector<int> aVec(elemPoints[ i3 ].length());
for (int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++)
2005-01-20 11:25:54 +05:00
aVec[ i4 ] = elemPoints[ i3 ][ i4 ];
anElemPoints[ i3 ] = aVec;
}
myPicture2d->SetPoints(aPoints, aKeyPoints, anElemPoints);
2005-01-20 11:25:54 +05:00
}
// Redisplay preview in 3D viewer
if (myPreviewActor != 0) {
if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView()) {
2005-01-20 11:25:54 +05:00
vf->RemoveActor(myPreviewActor);
vf->Repaint();
}
myPreviewActor->Delete();
myPreviewActor = 0;
}
if (!myPreviewChk->isChecked() || !isValid(false))
2005-01-20 11:25:54 +05:00
return;
vtkUnstructuredGrid* aGrid = getGrid();
if (aGrid == 0)
2005-01-20 11:25:54 +05:00
return;
// Create and display actor
vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
2013-03-01 19:13:25 +06:00
aMapper->SetInputData(aGrid);
2005-01-20 11:25:54 +05:00
myPreviewActor = SALOME_Actor::New();
myPreviewActor->PickableOff();
myPreviewActor->SetMapper(aMapper);
2005-01-20 11:25:54 +05:00
vtkProperty* aProp = vtkProperty::New();
aProp->SetRepresentationToWireframe();
aProp->SetColor(250, 0, 250);
if (SMESH::FindActorByObject(myMesh))
2005-06-27 17:29:58 +06:00
aProp->SetLineWidth( SMESH::GetFloat( "SMESH:element_width", 1 ) + 1 );
2005-01-20 11:25:54 +05:00
else
aProp->SetLineWidth(1);
myPreviewActor->SetProperty(aProp);
2005-01-20 11:25:54 +05:00
myPreviewActor->SetRepresentation(3);
2005-01-20 11:25:54 +05:00
SMESH::GetCurrentVtkView()->AddActor(myPreviewActor);
2005-01-20 11:25:54 +05:00
SMESH::GetCurrentVtkView()->Repaint();
aProp->Delete();
aGrid->Delete();
} catch (const SALOME::SALOME_Exception& S_ex) {
SalomeApp_Tools::QtCatchCorbaException(S_ex);
2005-01-20 11:25:54 +05:00
erasePreview();
} catch (...) {
2005-01-20 11:25:54 +05:00
erasePreview();
}
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::erasePreview
// Purpose : Erase preview
//=======================================================================
void SMESHGUI_MeshPatternDlg::erasePreview()
{
// Erase preview in 2D viewer
2009-02-17 10:27:49 +05:00
myPicture2d->SetPoints(PointVector(), QVector<int>(), ConnectivityVector());
2005-01-20 11:25:54 +05:00
// Erase preview in 3D viewer
if (myPreviewActor == 0)
2005-01-20 11:25:54 +05:00
return;
if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView())
2005-01-20 11:25:54 +05:00
{
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("");
2005-01-20 11:25:54 +05:00
}
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("");
2005-01-20 11:25:54 +05:00
}
} else {
for (int i = Object; i <= Vertex2; i++) {
mySelBtn [ i ]->setEnabled(true);
mySelEdit[ i ]->setEnabled(true);
2005-01-20 11:25:54 +05:00
}
}
2009-02-17 10:27:49 +05:00
QList<int> ids;
if (!CORBA::is_nil(myPattern)/* && getIds(ids)*/) {
2005-01-20 11:25:54 +05:00
SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
if (keyPoints->length()) {
2012-08-09 16:03:55 +06:00
myNode1->setEnabled(true);
myNode2->setEnabled(true);
myNode1->setRange(1, keyPoints->length());
myNode2->setRange(1, keyPoints->length());
return;
2005-01-20 11:25:54 +05:00
}
}
myNode1->setEnabled(false);
myNode2->setEnabled(false);
myNode1->setRange(0, 0);
myNode2->setRange(0, 0);
2005-01-20 11:25:54 +05:00
}
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::activateSelection
// Purpose : Activate selection in accordance with current selection input
//=======================================================================
void SMESHGUI_MeshPatternDlg::activateSelection()
{
mySelectionMgr->clearFilters();
if (mySelInput == Ids) {
SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
if (anActor)
2005-01-20 11:25:54 +05:00
SMESH::SetPickable(anActor);
if (myType == Type_2d)
{
2012-08-09 16:03:55 +06:00
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode(FaceSelection);
}
2005-01-20 11:25:54 +05:00
else
{
2012-08-09 16:03:55 +06:00
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode(CellSelection);
}
2005-01-20 11:25:54 +05:00
}
else {
SMESH::SetPickable();
//mySelectionMgr->setSelectionModes(ActorSelection);
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode(ActorSelection);
2005-01-20 11:25:54 +05:00
}
if (mySelInput == Object && !myMeshShape->_is_nil()) {
if (myType == Type_2d) {
if (myNbPoints > 0)
mySelectionMgr->installFilter
(new SMESH_NumberFilter ("GEOM", TopAbs_VERTEX, myNbPoints, TopAbs_FACE, myMeshShape));
2005-01-20 11:25:54 +05:00
else
mySelectionMgr->installFilter
(new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, myNbPoints, TopAbs_FACE, myMeshShape));
} else {
2005-01-20 11:25:54 +05:00
TColStd_MapOfInteger aTypes;
aTypes.Add(TopAbs_SHELL);
aTypes.Add(TopAbs_SOLID);
mySelectionMgr->installFilter
(new SMESH_NumberFilter ("GEOM", TopAbs_FACE, 6, aTypes, myMeshShape, true));
2005-01-20 11:25:54 +05:00
}
} else if ((mySelInput == Vertex1 || mySelInput == Vertex2) && !myGeomObj[ Object ]->_is_nil()) {
mySelectionMgr->installFilter
(new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX, myGeomObj[ Object ]));
} else {
2005-01-20 11:25:54 +05:00
}
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::loadFromFile
// Purpose : Load pattern from file
//=======================================================================
bool SMESHGUI_MeshPatternDlg::loadFromFile (const QString& theName)
2005-01-20 11:25:54 +05:00
{
try {
2005-01-20 11:25:54 +05:00
SMESH::SMESH_Pattern_var aPattern = SMESH::GetPattern();
2009-02-17 10:27:49 +05:00
if (!aPattern->LoadFromFile(theName.toLatin1().data()) ||
2012-08-09 16:03:55 +06:00
(myType == Type_2d && !aPattern->Is2D())) {
2005-01-20 11:25:54 +05:00
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");
2009-02-17 10:27:49 +05:00
SUIT_MessageBox::information(this, tr("SMESH_ERROR"), aMess);
2005-01-20 11:25:54 +05:00
return false;
} else {
2005-01-20 11:25:54 +05:00
myPattern = aPattern;
return true;
}
} catch (const SALOME::SALOME_Exception& S_ex) {
SalomeApp_Tools::QtCatchCorbaException(S_ex);
2009-02-17 10:27:49 +05:00
SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
2012-08-09 16:03:55 +06:00
tr("ERROR_OF_LOADING") );
2009-02-17 10:27:49 +05:00
return false;
2005-01-20 11:25:54 +05:00
}
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::onTypeChanged
// Purpose : SLOT. Called when pattern type changed.
// Change dialog's look and feel
//=======================================================================
void SMESHGUI_MeshPatternDlg::onTypeChanged (int theType)
2005-01-20 11:25:54 +05:00
{
if (myType == theType)
2005-01-20 11:25:54 +05:00
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("");
myCreatePolygonsChk->show();
myCreatePolyedrsChk->show();
2005-01-20 11:25:54 +05:00
if (theType == Type_2d) {
2005-01-20 11:25:54 +05:00
// 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"));
2005-01-20 11:25:54 +05:00
// Refine widgets
mySelLbl[ Ids ]->setText(tr("MESH_FACES"));
2005-01-20 11:25:54 +05:00
myNode2Lbl->hide();
myNode2 ->hide();
} else {
2005-01-20 11:25:54 +05:00
// 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"));
2005-01-20 11:25:54 +05:00
// Refine widgets
mySelLbl[ Ids ]->setText(tr("MESH_VOLUMES"));
2005-01-20 11:25:54 +05:00
myNode2Lbl->show();
myNode2 ->show();
}
mySelInput = Mesh;
activateSelection();
updateWgState();
displayPreview();
}
//=======================================================================
// name : SMESHGUI_MeshPatternDlg::getGrid
// Purpose : Get unstructured grid for pattern
//=======================================================================
vtkUnstructuredGrid* SMESHGUI_MeshPatternDlg::getGrid()
{
try {
2005-01-20 11:25:54 +05:00
// Get points from pattern
SMESH::point_array_var pnts;
2009-02-17 10:27:49 +05:00
QList<int> ids;
if (isRefine() && getIds(ids)) {
2005-01-20 11:25:54 +05:00
SMESH::long_array_var varIds = new SMESH::long_array();
varIds->length(ids.count());
2005-01-20 11:25:54 +05:00
int i = 0;
2009-02-17 10:27:49 +05:00
for (QList<int>::iterator it = ids.begin(); it != ids.end(); ++it)
2012-08-09 16:03:55 +06:00
varIds[i++] = *it;
2005-01-20 11:25:54 +05:00
pnts = myType == Type_2d
2012-08-09 16:03:55 +06:00
? myPattern->ApplyToMeshFaces (myMesh, varIds, getNode(false), myReverseChk->isChecked())
: myPattern->ApplyToHexahedrons(myMesh, varIds, getNode(false), getNode(true));
} else {
2005-01-20 11:25:54 +05:00
pnts = myType == Type_2d
2012-08-09 16:03:55 +06:00
? myPattern->ApplyToFace (myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked())
: myPattern->ApplyTo3DBlock(myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ]);
2005-01-20 11:25:54 +05:00
}
SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints(true);
2005-01-20 11:25:54 +05:00
if (pnts->length() == 0 || elemPoints->length() == 0)
2005-01-20 11:25:54 +05:00
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);
2005-01-20 11:25:54 +05:00
printf("\nELEMENTS : \n");
for (int i2 = 0, n2 = elemPoints->length(); i2 < n2; i2++)
2005-01-20 11:25:54 +05:00
{
printf("%d: ", i2);
for (int i3 = 0, n3 = elemPoints[ i2 ].length(); i3 < n3; i3++)
printf("%d ", elemPoints[ i2 ][ i3 ]);
2005-01-20 11:25:54 +05:00
printf("\n");
2005-01-20 11:25:54 +05:00
}
#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++)
2005-01-20 11:25:54 +05:00
aCellsSize += elemPoints[ i ].length();
// Create unstructured grid and other usefull arrays
vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
vtkCellArray* aConnectivity = vtkCellArray::New();
aConnectivity->Allocate(aCellsSize, 0);
2005-01-20 11:25:54 +05:00
vtkPoints* aPoints = vtkPoints::New();
aPoints->SetNumberOfPoints(pnts->length());
2005-01-20 11:25:54 +05:00
vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
aCellTypesArray->SetNumberOfComponents(1);
aCellTypesArray->Allocate(aNbCells * aCellTypesArray->GetNumberOfComponents());
2005-01-20 11:25:54 +05:00
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);
2005-01-20 11:25:54 +05:00
for (int e = 0, nbElem = elemPoints->length(); e < nbElem; e++) {
2005-01-20 11:25:54 +05:00
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);
2005-01-20 11:25:54 +05:00
}
VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
aCellLocationsArray->SetNumberOfComponents(1);
aCellLocationsArray->SetNumberOfTuples(aNbCells);
2005-01-20 11:25:54 +05:00
aConnectivity->InitTraversal();
for (vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell(npts, pts); idType++)
aCellLocationsArray->SetValue(idType, aConnectivity->GetTraversalLocation(npts));
2005-01-20 11:25:54 +05:00
aGrid->SetPoints(aPoints);
aGrid->SetCells(aCellTypesArray, aCellLocationsArray,aConnectivity);
2005-01-20 11:25:54 +05:00
aConnectivity->Delete();
aPoints->Delete();
aCellTypesArray->Delete();
anIdList->Delete();
aCellLocationsArray->Delete();
return aGrid;
} catch (...) {
2005-01-20 11:25:54 +05:00
return 0;
}
}
//=======================================================================
// name : onModeToggled
// Purpose :
2005-01-20 11:25:54 +05:00
//=======================================================================
void SMESHGUI_MeshPatternDlg::onModeToggled (bool on)
2005-01-20 11:25:54 +05:00
{
on ? myRefineGrp->show() : myRefineGrp->hide();
on ? myGeomGrp->hide() : myGeomGrp->show();
displayPreview();
2005-01-20 11:25:54 +05:00
}
//=======================================================================
// name : isRefine
// Purpose :
2005-01-20 11:25:54 +05:00
//=======================================================================
bool SMESHGUI_MeshPatternDlg::isRefine() const
{
return myRefine->isChecked();
}
//=======================================================================
// name : onTextChanged
// Purpose :
2005-01-20 11:25:54 +05:00
//=======================================================================
void SMESHGUI_MeshPatternDlg::onTextChanged (const QString& theNewText)
2005-01-20 11:25:54 +05:00
{
if (myBusy || !isRefine())
2005-01-20 11:25:54 +05:00
return;
myBusy = true;
if (mySelInput != Ids) {
2005-01-20 11:25:54 +05:00
mySelInput = Ids;
activateSelection();
}
// hilight entered elements/nodes
SMDS_Mesh* aMesh = 0;
SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
if (anActor)
2005-01-20 11:25:54 +05:00
aMesh = anActor->GetObject()->GetMesh();
if (aMesh) {
2009-02-17 10:27:49 +05:00
QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
2005-08-11 14:04:31 +06:00
TColStd_MapOfInteger newIndices;
2005-08-11 14:04:31 +06:00
for (int i = 0; i < aListId.count(); i++) {
const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
2005-06-24 19:54:25 +06:00
if (e && e->GetType() == (myType == Type_2d ? SMDSAbs_Face : SMDSAbs_Volume))
2012-08-09 16:03:55 +06:00
newIndices.Add(e->GetID());
}
2005-06-24 19:54:25 +06:00
mySelector->AddOrRemoveIndex( anActor->getIO(), newIndices, false);
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->highlight( anActor->getIO(), true, true );
2005-01-20 11:25:54 +05:00
}
myBusy = false;
displayPreview();
2005-01-20 11:25:54 +05:00
}
//=======================================================================
// name : onNodeChanged
// Purpose :
2005-01-20 11:25:54 +05:00
//=======================================================================
void SMESHGUI_MeshPatternDlg::onNodeChanged (int value)
2005-01-20 11:25:54 +05:00
{
if (myType == Type_3d) {
2009-02-17 10:27:49 +05:00
SalomeApp_IntSpinBox* first = (SalomeApp_IntSpinBox*)sender();
SalomeApp_IntSpinBox* second = first == myNode1 ? myNode2 : myNode1;
2005-01-20 11:25:54 +05:00
int secondVal = second->value();
if (secondVal == value) {
2009-02-17 10:27:49 +05:00
secondVal = value == second->maximum() ? second->minimum() : value + 1;
2005-01-20 11:25:54 +05:00
bool blocked = second->signalsBlocked();
second->blockSignals(true);
second->setValue(secondVal);
second->blockSignals(blocked);
2005-01-20 11:25:54 +05:00
}
}
displayPreview();
}
//=======================================================================
// name : getIds
// Purpose :
2005-01-20 11:25:54 +05:00
//=======================================================================
2009-02-17 10:27:49 +05:00
bool SMESHGUI_MeshPatternDlg::getIds (QList<int>& ids) const
2005-01-20 11:25:54 +05:00
{
ids.clear();
2009-02-17 10:27:49 +05:00
QStringList strIds = mySelEdit[Ids]->text().split(" ", QString::SkipEmptyParts );
2005-01-20 11:25:54 +05:00
bool isOk;
int val;
for (QStringList::iterator it = strIds.begin(); it != strIds.end(); ++it) {
val = (*it).toInt(&isOk);
if (isOk)
ids.append(val);
2005-01-20 11:25:54 +05:00
}
return ids.count();
}
//=======================================================================
// name : getNode1
// Purpose :
2005-01-20 11:25:54 +05:00
//=======================================================================
int SMESHGUI_MeshPatternDlg::getNode (bool second) const
2005-01-20 11:25:54 +05:00
{
return second ? myNode2->value() - 1 : myNode1->value() - 1;
}
//=================================================================================
// function : keyPressEvent()
// purpose :
//=================================================================================
void SMESHGUI_MeshPatternDlg::keyPressEvent( QKeyEvent* e )
{
QDialog::keyPressEvent( e );
if ( e->isAccepted() )
return;
2009-02-17 10:27:49 +05:00
if ( e->key() == Qt::Key_F1 )
{
e->accept();
onHelp();
}
}