smesh/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx

940 lines
31 KiB
C++
Raw Normal View History

2012-08-09 16:03:55 +06:00
// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
2004-12-01 15:48:31 +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
2004-12-01 15:48:31 +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_AddMeshElementDlg.cxx
// Author : Nicolas REJNERI, Open CASCADE S.A.S.
// SMESH includes
2004-12-01 15:48:31 +05:00
//
#include "SMESHGUI_AddMeshElementDlg.h"
#include "SMESHGUI.h"
2012-08-09 16:03:55 +06:00
#include "SMESHGUI_GroupUtils.h"
#include "SMESHGUI_IdValidator.h"
#include "SMESHGUI_MeshUtils.h"
#include "SMESHGUI_SpinBox.h"
2004-12-01 15:48:31 +05:00
#include "SMESHGUI_Utils.h"
#include "SMESHGUI_VTKUtils.h"
2009-02-17 10:27:49 +05:00
#include <SMESH_Actor.h>
#include <SMESH_ActorUtils.h>
#include <SMESH_FaceOrientationFilter.h>
#include <SMDS_Mesh.hxx>
// SALOME GUI inclues
#include <SUIT_Desktop.h>
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_MessageBox.h>
#include <SUIT_ViewManager.h>
#include <LightApp_SelectionMgr.h>
#include <SALOME_ListIO.hxx>
#include <SalomeApp_Application.h>
#include <SVTK_ViewModel.h>
#include <SVTK_ViewWindow.h>
// IDL incldues
#include CORBA_SERVER_HEADER(SMESH_MeshEditor)
2009-02-17 10:27:49 +05:00
// OCCT includes
#include <TColStd_MapOfInteger.hxx>
2009-02-17 10:27:49 +05:00
// VTK includes
2004-12-01 15:48:31 +05:00
#include <vtkCell.h>
#include <vtkIdList.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataSetMapper.h>
2009-02-17 10:27:49 +05:00
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
// Qt includes
2012-08-09 16:03:55 +06:00
#include <QComboBox>
2009-02-17 10:27:49 +05:00
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QRadioButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QVariant>
#include <QCheckBox>
#include <QKeyEvent>
#include <QButtonGroup>
#define SPACING 6
#define MARGIN 11
namespace SMESH
{
class TElementSimulation
{
SalomeApp_Application* myApplication;
SUIT_ViewWindow* myViewWindow;
SVTK_ViewWindow* myVTKViewWindow;
2004-12-01 15:48:31 +05:00
SALOME_Actor* myPreviewActor;
2004-12-01 15:48:31 +05:00
vtkDataSetMapper* myMapper;
vtkUnstructuredGrid* myGrid;
2009-02-17 10:27:49 +05:00
SALOME_Actor* myFaceOrientation;
vtkPolyDataMapper* myFaceOrientationDataMapper;
SMESH_FaceOrientationFilter* myFaceOrientationFilter;
2004-12-01 15:48:31 +05:00
public:
TElementSimulation (SalomeApp_Application* theApplication)
2004-12-01 15:48:31 +05:00
{
myApplication = theApplication;
SUIT_ViewManager* mgr = theApplication->activeViewManager();
if (!mgr) return;
myViewWindow = mgr->getActiveView();
myVTKViewWindow = GetVtkViewWindow(myViewWindow);
2004-12-01 15:48:31 +05:00
myGrid = vtkUnstructuredGrid::New();
2004-12-01 15:48:31 +05:00
// Create and display actor
myMapper = vtkDataSetMapper::New();
myMapper->SetInput(myGrid);
2004-12-01 15:48:31 +05:00
myPreviewActor = SALOME_Actor::New();
myPreviewActor->PickableOff();
myPreviewActor->VisibilityOff();
myPreviewActor->SetMapper(myMapper);
2004-12-01 15:48:31 +05:00
vtkFloatingPointType anRGB[3];
2005-06-27 17:29:58 +06:00
vtkProperty* aProp = vtkProperty::New();
GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
myPreviewActor->SetProperty( aProp );
2004-12-01 15:48:31 +05:00
aProp->Delete();
vtkProperty* aBackProp = vtkProperty::New();
2005-06-27 17:29:58 +06:00
GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
aBackProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
myPreviewActor->SetBackfaceProperty( aBackProp );
2004-12-01 15:48:31 +05:00
aBackProp->Delete();
myVTKViewWindow->AddActor(myPreviewActor);
2009-02-17 10:27:49 +05:00
// Orientation of faces
myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
myFaceOrientationFilter->SetInput(myGrid);
myFaceOrientationDataMapper = vtkPolyDataMapper::New();
myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
myFaceOrientation = SALOME_Actor::New();
myFaceOrientation->PickableOff();
myFaceOrientation->VisibilityOff();
myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
vtkProperty* anOrientationProp = vtkProperty::New();
GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
anOrientationProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
myFaceOrientation->SetProperty( anOrientationProp );
anOrientationProp->Delete();
myVTKViewWindow->AddActor(myFaceOrientation);
2004-12-01 15:48:31 +05:00
}
typedef std::vector<vtkIdType> TVTKIds;
void SetPosition (SMESH_Actor* theActor,
2012-08-09 16:03:55 +06:00
vtkIdType theType,
TVTKIds& theIds)
2004-12-01 15:48:31 +05:00
{
vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
myGrid->SetPoints(aGrid->GetPoints());
2012-08-09 16:03:55 +06:00
myGrid->Reset();
2004-12-01 15:48:31 +05:00
2012-08-09 16:03:55 +06:00
const std::vector<int>& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( theType ));
SMDS_MeshCell::applyInterlace( interlace, theIds );
2004-12-01 15:48:31 +05:00
vtkIdList *anIds = vtkIdList::New();
2012-08-09 16:03:55 +06:00
for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
anIds->InsertId(i,theIds[i]);
2004-12-01 15:48:31 +05:00
myGrid->InsertNextCell(theType,anIds);
anIds->Delete();
myGrid->Modified();
2009-02-17 10:27:49 +05:00
SetVisibility(true, theActor->GetFacesOriented());
2004-12-01 15:48:31 +05:00
}
2009-02-17 10:27:49 +05:00
void SetVisibility (bool theVisibility, bool theShowOrientation = false)
{
2004-12-01 15:48:31 +05:00
myPreviewActor->SetVisibility(theVisibility);
2009-02-17 10:27:49 +05:00
myFaceOrientation->SetVisibility(theShowOrientation);
2004-12-01 15:48:31 +05:00
RepaintCurrentView();
}
~TElementSimulation()
{
if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
2012-08-09 16:03:55 +06:00
myVTKViewWindow->RemoveActor(myPreviewActor);
myVTKViewWindow->RemoveActor(myFaceOrientation);
2004-12-01 15:48:31 +05:00
}
myPreviewActor->Delete();
2009-02-17 10:27:49 +05:00
myFaceOrientation->Delete();
2004-12-01 15:48:31 +05:00
myMapper->RemoveAllInputs();
myMapper->Delete();
2009-02-17 10:27:49 +05:00
myFaceOrientationFilter->Delete();
myFaceOrientationDataMapper->RemoveAllInputs();
myFaceOrientationDataMapper->Delete();
2004-12-01 15:48:31 +05:00
myGrid->Delete();
}
};
}
//=================================================================================
// function : SMESHGUI_AddMeshElementDlg()
// purpose : constructor
2004-12-01 15:48:31 +05:00
//=================================================================================
2012-08-09 16:03:55 +06:00
SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
SMDSAbs_EntityType ElementType)
2009-02-17 10:27:49 +05:00
: QDialog( SMESH::GetDesktop( theModule ) ),
mySMESHGUI( theModule ),
2012-08-09 16:03:55 +06:00
mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
myBusy ( false )
2004-12-01 15:48:31 +05:00
{
2009-02-17 10:27:49 +05:00
setModal( false );
setAttribute( Qt::WA_DeleteOnClose, true );
SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
(SUIT_Session::session()->activeApplication());
myIsPoly = false;
mySimulation = new SMESH::TElementSimulation (anApp);
mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
2012-08-09 16:03:55 +06:00
myGeomType = ElementType;
myElementType = SMDSAbs_Volume;
2004-12-01 15:48:31 +05:00
// verify nb nodes and type
2012-08-09 16:03:55 +06:00
QString elemName;
switch ( myGeomType ) {
case SMDSEntity_0D:
myNbNodes = 1;
myElementType = SMDSAbs_0DElement;
elemName = "ELEM0D";
myHelpFileName = "adding_nodes_and_elements_page.html#adding_0delems_anchor";
2004-12-01 15:48:31 +05:00
break;
2012-08-09 16:03:55 +06:00
case SMDSEntity_Ball:
myNbNodes = 1;
myElementType = SMDSAbs_Ball;
elemName = "BALL";
myHelpFileName = "adding_nodes_and_elements_page.html#adding_ball_anchor";
break;
case SMDSEntity_Edge:
2004-12-01 15:48:31 +05:00
myNbNodes = 2;
2012-08-09 16:03:55 +06:00
myElementType = SMDSAbs_Edge;
elemName = "EDGE";
myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
2012-08-09 16:03:55 +06:00
break;
case SMDSEntity_Triangle:
myNbNodes = 3;
elemName = "TRIANGLE";
2012-08-09 16:03:55 +06:00
myElementType = SMDSAbs_Face;
myHelpFileName = "adding_nodes_and_elements_page.html#adding_triangles_anchor";
2012-08-09 16:03:55 +06:00
break;
case SMDSEntity_Quadrangle:
myNbNodes = 4;
myElementType = SMDSAbs_Face;
elemName = "QUADRANGLE";
myHelpFileName = "adding_nodes_and_elements_page.html#adding_quadrangles_anchor";
break;
case SMDSEntity_Polygon:
myNbNodes = 0;
myElementType = SMDSAbs_Face;
elemName = "POLYGON";
myIsPoly = true;
myHelpFileName = "adding_nodes_and_elements_page.html#adding_polygons_anchor";
2012-08-09 16:03:55 +06:00
break;
case SMDSEntity_Tetra:
myNbNodes = 4;
elemName = "TETRAS";
myHelpFileName = "adding_nodes_and_elements_page.html#adding_tetrahedrons_anchor";
break;
case SMDSEntity_Pyramid:
myNbNodes = 5;
elemName = "PYRAMID";
myHelpFileName = "adding_nodes_and_elements_page.html#adding_pyramids_anchor";
break;
case SMDSEntity_Hexa:
myNbNodes = 8;
elemName = "HEXAS";
myHelpFileName = "adding_nodes_and_elements_page.html#adding_hexahedrons_anchor";
break;
case SMDSEntity_Penta:
myNbNodes = 6;
elemName = "PENTA";
myHelpFileName = "adding_nodes_and_elements_page.html#adding_pentahedrons_anchor";
break;
case SMDSEntity_Hexagonal_Prism:
myNbNodes = 12;
elemName = "OCTA";
myHelpFileName = "adding_nodes_and_elements_page.html#adding_octahedrons_anchor";
break;
default:
myNbNodes = 2;
elemName = "EDGE";
myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
}
2012-08-09 16:03:55 +06:00
2009-02-17 10:27:49 +05:00
QString iconName = tr(QString("ICON_DLG_%1").arg(elemName).toLatin1().data());
QString buttonGrTitle = tr(QString("SMESH_%1").arg(elemName).toLatin1().data());
QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(elemName).toLatin1().data());
QString grBoxTitle = tr(QString("SMESH_ADD_%1").arg(elemName).toLatin1().data());
2005-06-08 16:45:19 +06:00
QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
setWindowTitle(caption);
setSizeGripEnabled(true);
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
QVBoxLayout* aTopLayout = new QVBoxLayout(this);
aTopLayout->setSpacing(SPACING);
aTopLayout->setMargin(MARGIN);
2004-12-01 15:48:31 +05:00
2012-08-09 16:03:55 +06:00
/* Constructor *************************************************/
2009-02-17 10:27:49 +05:00
GroupConstructors = new QGroupBox(buttonGrTitle, this);
QButtonGroup* ButtonGroup = new QButtonGroup(this);
QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
GroupConstructorsLayout->setSpacing(SPACING);
GroupConstructorsLayout->setMargin(MARGIN);
2009-02-17 10:27:49 +05:00
Constructor1 = new QRadioButton(GroupConstructors);
Constructor1->setIcon(image0);
Constructor1->setChecked(true);
GroupConstructorsLayout->addWidget(Constructor1);
ButtonGroup->addButton( Constructor1, 0 );
2004-12-01 15:48:31 +05:00
2012-08-09 16:03:55 +06:00
/* Nodes & Reverse *********************************************/
2009-02-17 10:27:49 +05:00
GroupC1 = new QGroupBox(grBoxTitle, this);
QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
GroupC1Layout->setSpacing(SPACING);
GroupC1Layout->setMargin(MARGIN);
TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
SelectButtonC1A1 = new QPushButton(GroupC1);
SelectButtonC1A1->setIcon(image1);
LineEditC1A1 = new QLineEdit(GroupC1);
2012-12-13 17:41:29 +06:00
LineEditC1A1->setValidator
(new SMESHGUI_IdValidator(this, ( myIsPoly || myNbNodes == 1 ) ? 1000 : myNbNodes));
2012-08-09 16:03:55 +06:00
Reverse = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
DiameterSpinBox = ( myGeomType == SMDSEntity_Ball ) ? new SMESHGUI_SpinBox(GroupC1) : 0;
QLabel* diameterLabel = DiameterSpinBox ? new QLabel( tr("BALL_DIAMETER"),GroupC1) : 0;
2009-02-17 10:27:49 +05:00
GroupC1Layout->addWidget(TextLabelC1A1, 0, 0);
GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
GroupC1Layout->addWidget(LineEditC1A1, 0, 2);
2012-08-09 16:03:55 +06:00
if ( Reverse ) {
GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
}
if ( DiameterSpinBox ) {
GroupC1Layout->addWidget(diameterLabel, 1, 0);
GroupC1Layout->addWidget(DiameterSpinBox, 1, 1, 1, 2);
2009-02-17 10:27:49 +05:00
2012-08-09 16:03:55 +06:00
DiameterSpinBox->RangeStepAndValidator( 1e-7, 1e+9, 0.1 );
DiameterSpinBox->SetValue( 1. );
}
/* Add to group ************************************************/
GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
GroupGroups->setCheckable( true );
QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
GroupGroupsLayout->setSpacing(SPACING);
GroupGroupsLayout->setMargin(MARGIN);
TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
ComboBox_GroupName = new QComboBox( GroupGroups );
ComboBox_GroupName->setEditable( true );
ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
GroupGroupsLayout->addWidget( TextLabel_GroupName );
GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
/* Apply etc ***************************************************/
2009-02-17 10:27:49 +05:00
GroupButtons = new QGroupBox(this);
QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
GroupButtonsLayout->setSpacing(SPACING);
GroupButtonsLayout->setMargin(MARGIN);
buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
buttonOk->setAutoDefault(true);
buttonOk->setDefault(true);
buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
buttonApply->setAutoDefault(true);
buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
buttonCancel->setAutoDefault(true);
buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
buttonHelp->setAutoDefault(true);
GroupButtonsLayout->addWidget(buttonOk);
GroupButtonsLayout->addSpacing(10);
GroupButtonsLayout->addWidget(buttonApply);
GroupButtonsLayout->addSpacing(10);
GroupButtonsLayout->addStretch();
GroupButtonsLayout->addWidget(buttonCancel);
GroupButtonsLayout->addWidget(buttonHelp);
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
/***************************************************************/
aTopLayout->addWidget(GroupConstructors);
aTopLayout->addWidget(GroupC1);
2012-08-09 16:03:55 +06:00
aTopLayout->addWidget(GroupGroups);
2009-02-17 10:27:49 +05:00
aTopLayout->addWidget(GroupButtons);
2004-12-01 15:48:31 +05:00
Init(); /* Initialisations */
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : ~SMESHGUI_AddMeshElementDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
{
delete mySimulation;
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::Init()
2004-12-01 15:48:31 +05:00
{
GroupC1->show();
2009-02-17 10:27:49 +05:00
Constructor1->setChecked(true);
myEditCurrentArgument = LineEditC1A1;
mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2004-12-01 15:48:31 +05:00
2012-08-09 16:03:55 +06:00
/* reset "Add to group" control */
GroupGroups->setChecked( false );
//GroupGroups->setVisible( myElementType != SMDSAbs_0DElement );
myNbOkNodes = 0;
2004-12-01 15:48:31 +05:00
myActor = 0;
/* signals and slots connections */
2012-12-13 17:41:29 +06:00
connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
connect(SelectButtonC1A1,SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()),SLOT(DeactivateActiveDialog()));
connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
2004-12-01 15:48:31 +05:00
/* to close dialog if study frame change */
2012-12-13 17:41:29 +06:00
connect(mySMESHGUI, SIGNAL(SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(ClickOnCancel()));
2004-12-01 15:48:31 +05:00
if (Reverse)
2012-12-13 17:41:29 +06:00
connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
2004-12-01 15:48:31 +05:00
// set selection mode
SMESH::SetPointRepresentation(true);
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode( NodeSelection );
2004-12-01 15:48:31 +05:00
myBusy = false;
SelectionIntoArgument();
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::ClickOnApply()
{
2012-08-09 16:03:55 +06:00
if( !isValid() )
return;
if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) {
2004-12-01 15:48:31 +05:00
myBusy = true;
2009-02-17 10:27:49 +05:00
QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
2012-12-13 17:41:29 +06:00
SMESH::long_array_var anArrayOfIndices = new SMESH::long_array;
anArrayOfIndices->length(aListId.count());
2012-08-09 16:03:55 +06:00
const std::vector<int>& revIndex = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
if ( Reverse && Reverse->isChecked() && !revIndex.empty() )
for (int i = 0; i < aListId.count(); i++)
anArrayOfIndices[i] = aListId[ revIndex[i] ].toInt();
else if ( Reverse && Reverse->isChecked() && revIndex.empty() ) // polygon
for (int i = 0; i < aListId.count(); i++)
anArrayOfIndices[i] = aListId[ aListId.count()-1 - i ].toInt();
else
for (int i = 0; i < aListId.count(); i++)
anArrayOfIndices[i] = aListId[ i ].toInt();
bool addToGroup = GroupGroups->isChecked();
QString aGroupName;
SMESH::SMESH_GroupBase_var aGroup;
int idx = 0;
if( addToGroup ) {
aGroupName = ComboBox_GroupName->currentText();
2012-10-08 17:56:59 +06:00
for ( int i = 1; i <= ComboBox_GroupName->count(); i++ ) {
2012-08-09 16:03:55 +06:00
QString aName = ComboBox_GroupName->itemText( i );
if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
idx = i;
}
2012-10-08 17:56:59 +06:00
if ( idx > 0 && idx <= myGroups.count() ) {
2012-08-09 16:03:55 +06:00
SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
if ( !aGeomGroup->_is_nil() ) {
int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
if ( res == 1 ) return;
}
aGroup = myGroups[idx-1];
}
}
2004-12-01 15:48:31 +05:00
SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
2012-12-13 17:41:29 +06:00
SMESH::long_array_var anIdList = new SMESH::long_array;
anIdList->length( 1 );
anIdList[0] = -1;
switch (myElementType) {
2012-08-09 16:03:55 +06:00
case SMDSAbs_0DElement:
2012-12-13 17:41:29 +06:00
anIdList->length( anArrayOfIndices->length() );
for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
anIdList[i] = aMeshEditor->Add0DElement(anArrayOfIndices[i]);
break;
2012-08-09 16:03:55 +06:00
case SMDSAbs_Ball:
2012-12-13 17:41:29 +06:00
if ( myGeomType == SMDSEntity_Ball ) {
anIdList->length( anArrayOfIndices->length() );
for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
anIdList[i] = aMeshEditor->AddBall(anArrayOfIndices[i],
DiameterSpinBox->GetValue());
}
break;
2004-12-01 15:48:31 +05:00
case SMDSAbs_Edge:
2012-12-13 17:41:29 +06:00
anIdList[0] = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break;
2012-08-09 16:03:55 +06:00
case SMDSAbs_Face:
if ( myIsPoly )
2012-12-13 17:41:29 +06:00
anIdList[0] = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout());
else
2012-12-13 17:41:29 +06:00
anIdList[0] = aMeshEditor->AddFace(anArrayOfIndices.inout());
break;
2012-08-09 16:03:55 +06:00
default:
2012-12-13 17:41:29 +06:00
anIdList[0] = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break;
}
2012-08-09 16:03:55 +06:00
2012-12-13 17:41:29 +06:00
if ( anIdList[0] > 0 && addToGroup && !aGroupName.isEmpty() ) {
2012-08-09 16:03:55 +06:00
SMESH::SMESH_Group_var aGroupUsed;
if ( aGroup->_is_nil() ) {
// create new group
aGroupUsed = SMESH::AddGroup( myMesh, (SMESH::ElementType)myElementType, aGroupName );
if ( !aGroupUsed->_is_nil() ) {
myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
ComboBox_GroupName->addItem( aGroupName );
}
}
else {
SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
if ( !aGeomGroup->_is_nil() ) {
aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
if ( !aGroupUsed->_is_nil() && idx > 0 ) {
myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
}
}
else
aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
}
2012-12-13 17:41:29 +06:00
if ( !aGroupUsed->_is_nil() )
2012-08-09 16:03:55 +06:00
aGroupUsed->Add( anIdList.inout() );
2004-12-01 15:48:31 +05:00
}
SALOME_ListIO aList; aList.Append( myActor->getIO() );
mySelector->ClearIndex();
mySelectionMgr->setSelectedObjects( aList, false );
2004-12-01 15:48:31 +05:00
SMESH::UpdateView();
mySimulation->SetVisibility(false);
buttonOk->setEnabled(false);
buttonApply->setEnabled(false);
2004-12-01 15:48:31 +05:00
myEditCurrentArgument->setText("");
myBusy = false;
2012-08-09 16:03:55 +06:00
SMESHGUI::Modified();
2004-12-01 15:48:31 +05:00
}
}
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::ClickOnOk()
{
2009-02-17 10:27:49 +05:00
ClickOnApply();
ClickOnCancel();
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : ClickOnCancel()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
{
//mySelectionMgr->clearSelected();
2004-12-01 15:48:31 +05:00
mySimulation->SetVisibility(false);
SMESH::SetPointRepresentation(false);
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode( ActorSelection );
disconnect(mySelectionMgr, 0, this, 0);
mySMESHGUI->ResetState();
reject();
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : ClickOnHelp()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::ClickOnHelp()
{
LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2012-08-09 16:03:55 +06:00
if (app)
app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""),
myHelpFileName);
else {
2009-02-17 10:27:49 +05:00
QString platform;
#ifdef WIN32
2009-02-17 10:27:49 +05:00
platform = "winapplication";
#else
2009-02-17 10:27:49 +05: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));
}
}
//=================================================================================
// function : onTextChange()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
2004-12-01 15:48:31 +05:00
{
if (myBusy) return;
2004-12-01 15:48:31 +05:00
myBusy = true;
myNbOkNodes = 0;
2004-12-01 15:48:31 +05:00
buttonOk->setEnabled(false);
buttonApply->setEnabled(false);
2004-12-01 15:48:31 +05:00
mySimulation->SetVisibility(false);
// hilight entered nodes
SMDS_Mesh* aMesh = 0;
if (myActor)
2004-12-01 15:48:31 +05:00
aMesh = myActor->GetObject()->GetMesh();
if (aMesh) {
TColStd_MapOfInteger newIndices;
2012-08-09 16:03:55 +06:00
2009-02-17 10:27:49 +05:00
QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
bool allOk = true;
for (int i = 0; i < aListId.count(); i++) {
if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
2012-08-09 16:03:55 +06:00
{
newIndices.Add( n->GetID() );
myNbOkNodes++;
}
else
2012-08-09 16:03:55 +06:00
allOk = false;
2004-12-01 15:48:31 +05:00
}
2012-08-09 16:03:55 +06:00
2005-06-24 19:54:25 +06:00
mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->highlight( myActor->getIO(), true, true );
2012-08-09 16:03:55 +06:00
2012-12-13 17:41:29 +06:00
myNbOkNodes = ( allOk && ( myNbNodes == aListId.count() || myNbNodes == 1 ));
2012-08-09 16:03:55 +06:00
if (myIsPoly)
{
2012-08-09 16:03:55 +06:00
if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
myNbOkNodes = 0;
else
myNbOkNodes = aListId.count();
}
2004-12-01 15:48:31 +05:00
}
2012-08-09 16:03:55 +06:00
if(myNbOkNodes) {
buttonOk->setEnabled(true);
buttonApply->setEnabled(true);
displaySimulation();
}
2012-08-09 16:03:55 +06:00
2004-12-01 15:48:31 +05:00
myBusy = false;
}
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection has changed
//=================================================================================
void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
{
if (myBusy) return;
2004-12-01 15:48:31 +05:00
// clear
myNbOkNodes = 0;
2004-12-01 15:48:31 +05:00
myActor = 0;
myBusy = true;
myEditCurrentArgument->setText("");
2004-12-01 15:48:31 +05:00
myBusy = false;
if (!GroupButtons->isEnabled()) // inactive
2004-12-01 15:48:31 +05:00
return;
buttonOk->setEnabled(false);
buttonApply->setEnabled(false);
2004-12-01 15:48:31 +05:00
mySimulation->SetVisibility(false);
2009-02-17 10:27:49 +05:00
// SMESH::SetPointRepresentation(true);
2004-12-01 15:48:31 +05:00
2012-08-09 16:03:55 +06:00
QString aCurrentEntry = myEntry;
2004-12-01 15:48:31 +05:00
// get selected mesh
SALOME_ListIO aList;
mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
2004-12-01 15:48:31 +05:00
if (aList.Extent() != 1)
2004-12-01 15:48:31 +05:00
return;
Handle(SALOME_InteractiveObject) anIO = aList.First();
2012-08-09 16:03:55 +06:00
myEntry = anIO->getEntry();
myMesh = SMESH::GetMeshByIO(anIO);
if (myMesh->_is_nil())
2004-12-01 15:48:31 +05:00
return;
2012-08-09 16:03:55 +06:00
// process groups
if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
myGroups.clear();
ComboBox_GroupName->clear();
ComboBox_GroupName->addItem( QString() );
SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
if ( !aGroup->_is_nil() && aGroup->GetType() == (SMESH::ElementType)myElementType ) {
QString aGroupName( aGroup->GetName() );
if ( !aGroupName.isEmpty() ) {
myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
ComboBox_GroupName->addItem( aGroupName );
}
}
}
}
myActor = SMESH::FindActorByEntry(anIO->getEntry());
if (!myActor)
2004-12-01 15:48:31 +05:00
return;
// get selected nodes
QString aString = "";
int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
2004-12-01 15:48:31 +05:00
myBusy = true;
myEditCurrentArgument->setText(aString);
2004-12-01 15:48:31 +05:00
myBusy = false;
if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
myNbNodes = nbNodes;
2012-12-13 17:41:29 +06:00
} else if (myNbNodes != nbNodes && myNbNodes != 1) {
2004-12-01 15:48:31 +05:00
return;
}
2004-12-01 15:48:31 +05:00
// OK
myNbOkNodes = nbNodes;
2004-12-01 15:48:31 +05:00
buttonOk->setEnabled(true);
buttonApply->setEnabled(true);
2004-12-01 15:48:31 +05:00
displaySimulation();
}
//=================================================================================
// function : displaySimulation()
// purpose :
//=================================================================================
2004-12-01 15:48:31 +05:00
void SMESHGUI_AddMeshElementDlg::displaySimulation()
{
if (myNbOkNodes && GroupButtons->isEnabled()) {
2004-12-01 15:48:31 +05:00
SMESH::TElementSimulation::TVTKIds anIds;
2009-02-17 10:27:49 +05:00
QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
for (int i = 0; i < aListId.count(); i++)
anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
2004-12-01 15:48:31 +05:00
if (Reverse && Reverse->isChecked())
2012-08-09 16:03:55 +06:00
{
const std::vector<int>& i = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
if ( i.empty() ) // polygon
std::reverse( anIds.begin(), anIds.end() );
else
SMDS_MeshCell::applyInterlace( i, anIds );
2004-12-01 15:48:31 +05:00
}
2012-08-09 16:03:55 +06:00
vtkIdType aType = SMDS_MeshCell::toVtkType( myGeomType );
2004-12-01 15:48:31 +05:00
mySimulation->SetPosition(myActor,aType,anIds);
2005-06-27 17:41:01 +06:00
SMESH::UpdateView();
2004-12-01 15:48:31 +05:00
}
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
{
QPushButton* send = (QPushButton*)sender();
if (send == SelectButtonC1A1) {
LineEditC1A1->setFocus();
2004-12-01 15:48:31 +05:00
myEditCurrentArgument = LineEditC1A1;
}
SelectionIntoArgument();
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : DeactivateActiveDialog()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
{
if (GroupConstructors->isEnabled()) {
GroupConstructors->setEnabled(false);
GroupC1->setEnabled(false);
GroupButtons->setEnabled(false);
2004-12-01 15:48:31 +05:00
mySimulation->SetVisibility(false);
mySMESHGUI->ResetState();
mySMESHGUI->SetActiveDialogBox(0);
2004-12-01 15:48:31 +05:00
}
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
{
/* Emit a signal to deactivate the active dialog */
mySMESHGUI->EmitSignalDeactivateDialog();
2004-12-01 15:48:31 +05:00
GroupConstructors->setEnabled(true);
GroupC1->setEnabled(true);
GroupButtons->setEnabled(true);
2004-12-01 15:48:31 +05:00
SMESH::SetPointRepresentation(true);
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode( NodeSelection );
2004-12-01 15:48:31 +05:00
SelectionIntoArgument();
}
//=================================================================================
// function : enterEvent()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
2004-12-01 15:48:31 +05:00
{
if (GroupConstructors->isEnabled())
return;
ActivateThisDialog();
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : closeEvent()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::closeEvent (QCloseEvent*)
2004-12-01 15:48:31 +05:00
{
/* same than click on cancel button */
2009-02-17 10:27:49 +05:00
ClickOnCancel();
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : hideEvent()
// purpose : caused by ESC key
//=================================================================================
void SMESHGUI_AddMeshElementDlg::hideEvent (QHideEvent*)
2004-12-01 15:48:31 +05:00
{
if (!isMinimized())
ClickOnCancel();
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : CheckBox()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
2004-12-01 15:48:31 +05:00
{
if (!myNbOkNodes)
2004-12-01 15:48:31 +05:00
return;
if (state >= 0) {
2004-12-01 15:48:31 +05:00
mySimulation->SetVisibility(false);
displaySimulation();
}
}
//=================================================================================
// function : keyPressEvent()
// purpose :
//=================================================================================
void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
{
QDialog::keyPressEvent( e );
if ( e->isAccepted() )
return;
2012-08-09 16:03:55 +06:00
2009-02-17 10:27:49 +05:00
if ( e->key() == Qt::Key_F1 ) {
e->accept();
ClickOnHelp();
}
}
2012-08-09 16:03:55 +06:00
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
bool SMESHGUI_AddMeshElementDlg::isValid()
{
if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );
return false;
}
return true;
}