X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_AddMeshElementDlg.cxx;h=20452fc65c95785afb236029fffeaf436dccbe41;hp=a15542896d3dc1096a00767baafa98bea2f529b3;hb=ea8a0289f14641c23d515de68aa4fdc24a6208ba;hpb=c38c10811a065cf5b13e8807ed71864d92ca7d80 diff --git a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx index a15542896..20452fc65 100644 --- a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx @@ -1,95 +1,98 @@ -// SMESH SMESHGUI : GUI for SMESH component +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is 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, or (at your option) any later version. // -// 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. +// 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 +// 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 +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// -// -// File : SMESHGUI_AddMeshElementDlg.cxx -// Author : Nicolas REJNERI -// Module : SMESH -// $Header$ +// SMESH SMESHGUI : GUI for SMESH component +// File : SMESHGUI_AddMeshElementDlg.cxx +// Author : Nicolas REJNERI, Open CASCADE S.A.S. +// SMESH includes +// #include "SMESHGUI_AddMeshElementDlg.h" #include "SMESHGUI.h" +#include "SMESHGUI_GroupUtils.h" +#include "SMESHGUI_IdValidator.h" +#include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_SpinBox.h" #include "SMESHGUI_Utils.h" #include "SMESHGUI_VTKUtils.h" -#include "SMESHGUI_MeshUtils.h" -#include "SMESHGUI_IdValidator.h" -#include "SMESH_ActorUtils.h" - -#include "SMDS_Mesh.hxx" -#include "SMESH_Actor.h" - -#include "SUIT_Session.h" - -#include "SVTK_Selection.h" -#include "SVTK_Selector.h" -#include "SALOME_ListIO.hxx" -#include "SALOME_ListIteratorOfListIO.hxx" - -#include "SalomeApp_Study.h" -#include "SalomeApp_Application.h" - -#include "SVTK_ViewModel.h" -#include "SVTK_ViewWindow.h" -#include "utilities.h" - -// OCCT Includes +#include +#include +#include +#include + +// SALOME GUI inclues +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// IDL incldues +#include CORBA_SERVER_HEADER(SMESH_MeshEditor) + +// OCCT includes #include -#include -// VTK Includes +// VTK includes #include #include -#include -#include -#include #include #include - -// QT Includes -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// STL includes -#include - -using namespace std; - -namespace SMESH { - - class TElementSimulation { +#include +#include +#include + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SPACING 6 +#define MARGIN 11 + +namespace SMESH +{ + class TElementSimulation + { SalomeApp_Application* myApplication; SUIT_ViewWindow* myViewWindow; SVTK_ViewWindow* myVTKViewWindow; @@ -97,6 +100,14 @@ namespace SMESH { SALOME_Actor* myPreviewActor; vtkDataSetMapper* myMapper; vtkUnstructuredGrid* myGrid; + + SALOME_Actor* myBallActor; + VTKViewer_PolyDataMapper* myBallMapper; + vtkPolyData* myBallPolyData; + + SALOME_Actor* myFaceOrientation; + vtkPolyDataMapper* myFaceOrientationDataMapper; + SMESH_FaceOrientationFilter* myFaceOrientationFilter; public: TElementSimulation (SalomeApp_Application* theApplication) @@ -111,100 +122,156 @@ namespace SMESH { // Create and display actor myMapper = vtkDataSetMapper::New(); - myMapper->SetInput(myGrid); + myMapper->SetInputData(myGrid); myPreviewActor = SALOME_Actor::New(); myPreviewActor->PickableOff(); myPreviewActor->VisibilityOff(); myPreviewActor->SetMapper(myMapper); + QColor ffc, bfc; + int delta; + vtkProperty* aProp = vtkProperty::New(); - float anRGB[3]; - anRGB[0] = GetFloat("SMESH:SettingsFillColorRed", 0)/255.; - anRGB[1] = GetFloat("SMESH:SettingsFillColorGreen", 170)/255.; - anRGB[2] = GetFloat("SMESH:SettingsFillColorBlue", 255)/255.; - aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); - myPreviewActor->SetProperty(aProp); + SMESH::GetColor( "SMESH", "preview_color", ffc, delta, "0, 255, 0|-100" ) ; + aProp->SetColor( ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255. ); + myPreviewActor->SetProperty( aProp ); aProp->Delete(); vtkProperty* aBackProp = vtkProperty::New(); - anRGB[0] = GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.; - anRGB[1] = GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.; - anRGB[2] = GetFloat("SMESH:SettingsBackFaceColorBlue", 255)/255.; - aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); - myPreviewActor->SetBackfaceProperty(aBackProp); + bfc = Qtx::mainColorToSecondary(ffc, delta); + aBackProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. ); + myPreviewActor->SetBackfaceProperty( aBackProp ); aBackProp->Delete(); myVTKViewWindow->AddActor(myPreviewActor); + + // Orientation of faces + myFaceOrientationFilter = SMESH_FaceOrientationFilter::New(); + myFaceOrientationFilter->SetInputData(myGrid); + + myFaceOrientationDataMapper = vtkPolyDataMapper::New(); + myFaceOrientationDataMapper->SetInputConnection(myFaceOrientationFilter->GetOutputPort()); + + myFaceOrientation = SALOME_Actor::New(); + myFaceOrientation->PickableOff(); + myFaceOrientation->VisibilityOff(); + myFaceOrientation->SetMapper(myFaceOrientationDataMapper); + + vtkProperty* anOrientationProp = vtkProperty::New(); + double anRGB[3]; + 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); + + // Preview for the balls + vtkProperty* aBallProp = vtkProperty::New(); + aBallProp->SetColor(ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255.); + double aBallElemSize = SMESH::GetFloat("SMESH:ball_elem_size",10); + aBallProp->SetPointSize(aBallElemSize); + + myBallPolyData = vtkPolyData::New(); + myBallPolyData->Allocate(); + + myBallMapper = VTKViewer_PolyDataMapper::New(); + myBallMapper->SetInputData(myBallPolyData); + myBallMapper->SetBallEnabled(true); + + myBallActor = SALOME_Actor::New(); + myBallActor->PickableOff(); + myBallActor->SetVisibility(false); + myBallActor->SetProperty(aBallProp); + myBallActor->SetMapper(myBallMapper); + aBallProp->Delete(); + + myVTKViewWindow->AddActor(myBallActor); } typedef std::vector TVTKIds; void SetPosition (SMESH_Actor* theActor, - vtkIdType theType, - const TVTKIds& theIds) + vtkIdType theType, + TVTKIds& theIds) { vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid(); myGrid->SetPoints(aGrid->GetPoints()); + myGrid->Reset(); - const int* aConn = NULL; - switch (theType) { - case VTK_TETRA: - { - static int anIds[] = {0,2,1,3}; - aConn = anIds; - break; - } - case VTK_PYRAMID: - { - static int anIds[] = {0,3,2,1,4}; - aConn = anIds; - break; - } - case VTK_HEXAHEDRON: - { - static int anIds[] = {0,3,2,1,4,7,6,5}; - aConn = anIds; - break; - } - } + const std::vector& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( theType )); + SMDS_MeshCell::applyInterlace( interlace, theIds ); - myGrid->Reset(); vtkIdList *anIds = vtkIdList::New(); - - if(aConn) - for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) - anIds->InsertId(i,theIds[aConn[i]]); - else - for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) - anIds->InsertId(i,theIds[i]); + for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) + anIds->InsertId(i,theIds[i]); myGrid->InsertNextCell(theType,anIds); anIds->Delete(); myGrid->Modified(); - SetVisibility(true); + SetVisibility(true, theActor->GetFacesOriented(), false); } + void SetBallPosition(SMESH_Actor* theActor,TVTKIds& theIds, double theDiameter) { + vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid(); + myBallPolyData->Reset(); + myBallPolyData->DeleteCells(); + myBallPolyData->SetPoints(aGrid->GetPoints()); + + vtkDataArray* aScalars = vtkDataArray::CreateDataArray(VTK_DOUBLE); + aScalars->SetNumberOfComponents(1); + aScalars->SetNumberOfTuples(theIds.size()); + myBallPolyData->GetCellData()->SetScalars(aScalars); + aScalars->Delete(); + + vtkIdList *anIds = vtkIdList::New(); + anIds->SetNumberOfIds(1); + for (int i = 0, iEnd = theIds.size(); i < iEnd; i++){ + anIds->InsertId(0,theIds[i]); + vtkIdType anId = myBallPolyData->InsertNextCell(VTK_POLY_VERTEX,anIds); + double d = theDiameter * theActor->GetBallScale(); + aScalars->SetTuple(anId,&d); + anIds->Reset(); + } + + anIds->Delete(); + myBallPolyData->Modified(); + SetVisibility (false, false, true); + } - void SetVisibility (bool theVisibility) + void SetVisibility (bool theVisibility, bool theShowOrientation = false, bool theShowBalls = false) { myPreviewActor->SetVisibility(theVisibility); + myFaceOrientation->SetVisibility(theShowOrientation); + myBallActor->SetVisibility(theShowBalls); RepaintCurrentView(); } ~TElementSimulation() { + myMapper->RemoveAllInputs(); + myFaceOrientationDataMapper->RemoveAllInputs(); + myBallMapper->RemoveAllInputs(); + if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) { - myVTKViewWindow->RemoveActor(myPreviewActor); + myVTKViewWindow->RemoveActor(myPreviewActor,false,false); + myVTKViewWindow->RemoveActor(myFaceOrientation,false,false); + myVTKViewWindow->RemoveActor(myBallActor,false,false); } - myPreviewActor->Delete(); - myMapper->RemoveAllInputs(); myMapper->Delete(); - myGrid->Delete(); + myPreviewActor->Delete(); + + myFaceOrientationFilter->Delete(); + myFaceOrientationDataMapper->Delete(); + myFaceOrientation->Delete(); + + myBallMapper->Delete(); + myBallPolyData->Delete(); + myBallActor->Delete(); } }; } @@ -213,165 +280,212 @@ namespace SMESH { // function : SMESHGUI_AddMeshElementDlg() // purpose : constructor //================================================================================= -SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, - const char* name, - SMDSAbs_ElementType ElementType, int nbNodes, - bool modal, WFlags fl) - : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | - WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose), - mySMESHGUI( theModule ), - mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), - myViewWindow( SMESH::GetViewWindow( theModule ) ), - mySelector( myViewWindow->GetSelector() ) +SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, + SMDSAbs_EntityType ElementType) + : QDialog( SMESH::GetDesktop( theModule ) ), + mySMESHGUI( theModule ), + mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), + myBusy ( false ) { + setModal( false ); + setAttribute( Qt::WA_DeleteOnClose, true ); + SalomeApp_Application* anApp = dynamic_cast (SUIT_Session::session()->activeApplication()); myIsPoly = false; mySimulation = new SMESH::TElementSimulation (anApp); + mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector(); + myGeomType = ElementType; + myElementType = SMDSAbs_Volume; // verify nb nodes and type - myNbNodes = nbNodes; - myElementType = ElementType; - switch (ElementType) { - case SMDSAbs_Face: -// if (myNbNodes != 3 && myNbNodes != 4) -// myNbNodes = 3; -// break; - case SMDSAbs_Volume: -// if (myNbNodes != 4 && myNbNodes != 8) //(nbNodes < 4 || nbNodes > 8 || nbNodes == 7) -// myNbNodes = 4; + QString elemName; + switch ( myGeomType ) { + case SMDSEntity_0D: + myNbNodes = 1; + myElementType = SMDSAbs_0DElement; + elemName = "ELEM0D"; + myHelpFileName = "adding_nodes_and_elements_page.html#adding_0delems_anchor"; break; - default: - myElementType = SMDSAbs_Edge; + case SMDSEntity_Ball: + myNbNodes = 1; + myElementType = SMDSAbs_Ball; + elemName = "BALL"; + myHelpFileName = "adding_nodes_and_elements_page.html#adding_ball_anchor"; + break; + case SMDSEntity_Edge: myNbNodes = 2; - } - - QString elemName; - if (myNbNodes == 2) + myElementType = SMDSAbs_Edge; elemName = "EDGE"; - else if (myNbNodes == 3) + myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor"; + break; + case SMDSEntity_Triangle: + myNbNodes = 3; elemName = "TRIANGLE"; - else if (myNbNodes == 4) - if (myElementType == SMDSAbs_Face) - elemName = "QUADRANGLE"; - else - elemName = "TETRAS"; - else if (myNbNodes == 8) - elemName = "HEXAS"; - else if (myElementType == SMDSAbs_Face){ + myElementType = SMDSAbs_Face; + myHelpFileName = "adding_nodes_and_elements_page.html#adding_triangles_anchor"; + 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"; + 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"; } - - QString iconName = tr(QString("ICON_DLG_%1").arg(elemName)); - QString buttonGrTitle = tr(QString("SMESH_%1").arg(elemName)); - QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(elemName)); - QString grBoxTitle = tr(QString("SMESH_ADD_%1").arg(elemName)); - - QPixmap image0 (SMESHGUI::resourceMgr()->loadPixmap("SMESH", iconName)); - QPixmap image1 (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT"))); - if (!name) - setName("SMESHGUI_AddMeshElementDlg"); - resize(303, 185); - setCaption(caption); - - setSizeGripEnabled(TRUE); - SMESHGUI_AddMeshElementDlgLayout = new QGridLayout(this); - SMESHGUI_AddMeshElementDlgLayout->setSpacing(6); - SMESHGUI_AddMeshElementDlgLayout->setMargin(11); - - /***************************************************************/ - GroupConstructors = new QButtonGroup(this, "GroupConstructors"); - GroupConstructors->setTitle(buttonGrTitle); - - GroupConstructors->setExclusive(TRUE); - GroupConstructors->setColumnLayout(0, Qt::Vertical); - GroupConstructors->layout()->setSpacing(0); - GroupConstructors->layout()->setMargin(0); - GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout()); - GroupConstructorsLayout->setAlignment(Qt::AlignTop); - GroupConstructorsLayout->setSpacing(6); - GroupConstructorsLayout->setMargin(11); - Constructor1 = new QRadioButton(GroupConstructors, "Constructor1"); - Constructor1->setText(tr("" )); - Constructor1->setPixmap(image0); - Constructor1->setChecked(TRUE); - Constructor1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth())); - Constructor1->setMinimumSize(QSize(50, 0)); - GroupConstructorsLayout->addWidget(Constructor1, 0, 0); - QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - GroupConstructorsLayout->addItem(spacer, 0, 1); - SMESHGUI_AddMeshElementDlgLayout->addWidget(GroupConstructors, 0, 0); - - /***************************************************************/ - GroupButtons = new QGroupBox(this, "GroupButtons"); - GroupButtons->setGeometry(QRect(10, 10, 281, 48)); - GroupButtons->setTitle(tr("" )); - GroupButtons->setColumnLayout(0, Qt::Vertical); - GroupButtons->layout()->setSpacing(0); - GroupButtons->layout()->setMargin(0); - GroupButtonsLayout = new QGridLayout(GroupButtons->layout()); - GroupButtonsLayout->setAlignment(Qt::AlignTop); - GroupButtonsLayout->setSpacing(6); - GroupButtonsLayout->setMargin(11); - buttonCancel = new QPushButton(GroupButtons, "buttonCancel"); - buttonCancel->setText(tr("SMESH_BUT_CLOSE" )); - buttonCancel->setAutoDefault(TRUE); - GroupButtonsLayout->addWidget(buttonCancel, 0, 3); - buttonApply = new QPushButton(GroupButtons, "buttonApply"); - buttonApply->setText(tr("SMESH_BUT_APPLY" )); - buttonApply->setAutoDefault(TRUE); - GroupButtonsLayout->addWidget(buttonApply, 0, 1); - QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - GroupButtonsLayout->addItem(spacer_9, 0, 2); - buttonOk = new QPushButton(GroupButtons, "buttonOk"); - buttonOk->setText(tr("SMESH_BUT_OK" )); - buttonOk->setAutoDefault(TRUE); - buttonOk->setDefault(TRUE); - GroupButtonsLayout->addWidget(buttonOk, 0, 0); - SMESHGUI_AddMeshElementDlgLayout->addWidget(GroupButtons, 2, 0); + 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()); + + QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName)); + QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT"))); + + setWindowTitle(caption); + setSizeGripEnabled(true); + + QVBoxLayout* aTopLayout = new QVBoxLayout(this); + aTopLayout->setSpacing(SPACING); + aTopLayout->setMargin(MARGIN); + + /* Constructor *************************************************/ + GroupConstructors = new QGroupBox(buttonGrTitle, this); + QButtonGroup* ButtonGroup = new QButtonGroup(this); + QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors); + GroupConstructorsLayout->setSpacing(SPACING); + GroupConstructorsLayout->setMargin(MARGIN); + + Constructor1 = new QRadioButton(GroupConstructors); + Constructor1->setIcon(image0); + Constructor1->setChecked(true); + + GroupConstructorsLayout->addWidget(Constructor1); + ButtonGroup->addButton( Constructor1, 0 ); + + /* Nodes & Reverse *********************************************/ + 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); + LineEditC1A1->setValidator + (new SMESHGUI_IdValidator(this, ( myIsPoly || myNbNodes == 1 ) ? 1000 : myNbNodes)); + + Reverse = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0; + + AutomaticPresentation = (myGeomType == SMDSEntity_Quadrangle || myGeomType == SMDSEntity_Polygon || + myGeomType == SMDSEntity_Pyramid || myGeomType == SMDSEntity_Hexa || + myGeomType == SMDSEntity_Penta || myGeomType == SMDSEntity_Hexagonal_Prism ) ? new QCheckBox(tr("SMESH_AUTOMATIC_PRESENTATION"), GroupC1) : 0; + if ( AutomaticPresentation ) { + GetNextPresentationButton = new QPushButton(tr("SMESH_BUT_GET_NEXT_SHAPE"), GroupC1); + GetNextPresentationButton->setAutoDefault(false); + } + DiameterSpinBox = ( myGeomType == SMDSEntity_Ball ) ? new SMESHGUI_SpinBox(GroupC1) : 0; + QLabel* diameterLabel = DiameterSpinBox ? new QLabel( tr("BALL_DIAMETER"),GroupC1) : 0; - /***************************************************************/ - GroupC1 = new QGroupBox(this, "GroupC1"); - GroupC1->setTitle(grBoxTitle); - - GroupC1->setMinimumSize(QSize(0, 0)); - GroupC1->setFrameShape(QGroupBox::Box); - GroupC1->setFrameShadow(QGroupBox::Sunken); - GroupC1->setColumnLayout(0, Qt::Vertical); - GroupC1->layout()->setSpacing(0); - GroupC1->layout()->setMargin(0); - GroupC1Layout = new QGridLayout(GroupC1->layout()); - GroupC1Layout->setAlignment(Qt::AlignTop); - GroupC1Layout->setSpacing(6); - GroupC1Layout->setMargin(11); - TextLabelC1A1 = new QLabel(GroupC1, "TextLabelC1A1"); - TextLabelC1A1->setText(tr("SMESH_ID_NODES" )); - TextLabelC1A1->setMinimumSize(QSize(50, 0)); - TextLabelC1A1->setFrameShape(QLabel::NoFrame); - TextLabelC1A1->setFrameShadow(QLabel::Plain); - GroupC1Layout->addWidget(TextLabelC1A1, 0, 0); - SelectButtonC1A1 = new QPushButton(GroupC1, "SelectButtonC1A1"); - SelectButtonC1A1->setText(tr("" )); - SelectButtonC1A1->setPixmap(image1); - SelectButtonC1A1->setToggleButton(FALSE); + GroupC1Layout->addWidget(TextLabelC1A1, 0, 0); GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1); - LineEditC1A1 = new QLineEdit(GroupC1, "LineEditC1A1"); -// LineEditC1A1->setReadOnly(TRUE); - if (!myIsPoly) - LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this, "validator", myNbNodes)); - GroupC1Layout->addWidget(LineEditC1A1, 0, 2); - - if (myElementType == SMDSAbs_Face) { - Reverse = new QCheckBox(GroupC1, "Reverse"); - Reverse->setText(tr("SMESH_REVERSE" )); - GroupC1Layout->addWidget(Reverse, 1, 0); + GroupC1Layout->addWidget(LineEditC1A1, 0, 2); + if ( AutomaticPresentation ) { + AutomaticPresentation->setChecked(true); + GroupC1Layout->addWidget(AutomaticPresentation, 1, 0, 1, 2); + GroupC1Layout->addWidget(GetNextPresentationButton, 1, 2, 1, 1); + } + if ( Reverse ) { + GroupC1Layout->addWidget(Reverse, 2, 0, 1, 3); + } + if ( DiameterSpinBox ) { + GroupC1Layout->addWidget(diameterLabel, 1, 0); + GroupC1Layout->addWidget(DiameterSpinBox, 1, 1, 1, 2); + + DiameterSpinBox->RangeStepAndValidator( 1e-7, 1e+9, 0.1 ); + DiameterSpinBox->SetValue( 1. ); + connect( DiameterSpinBox, SIGNAL( valueChanged ( double ) ), this, SLOT( onDiameterChanged( ) ) ); } - else - Reverse = 0; + /* 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 ***************************************************/ + 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); - SMESHGUI_AddMeshElementDlgLayout->addWidget(GroupC1, 1, 0); + /***************************************************************/ + aTopLayout->addWidget(GroupConstructors); + aTopLayout->addWidget(GroupC1); + aTopLayout->addWidget(GroupGroups); + aTopLayout->addWidget(GroupButtons); Init(); /* Initialisations */ } @@ -382,7 +496,6 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, //================================================================================= SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg() { - // no need to delete child widgets, Qt does it all for us delete mySimulation; } @@ -393,38 +506,42 @@ SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg() void SMESHGUI_AddMeshElementDlg::Init() { GroupC1->show(); - Constructor1->setChecked(TRUE); + Constructor1->setChecked(true); myEditCurrentArgument = LineEditC1A1; mySMESHGUI->SetActiveDialogBox((QDialog*)this); + /* reset "Add to group" control */ + GroupGroups->setChecked( false ); + //GroupGroups->setVisible( myElementType != SMDSAbs_0DElement ); + myNbOkNodes = 0; myActor = 0; /* signals and slots connections */ - connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk())); - connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel())); - connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply())); - - 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())); + connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk())); + connect(buttonCancel, SIGNAL(clicked()), SLOT(reject())); + 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())); /* to close dialog if study frame change */ - connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel())); + connect(mySMESHGUI, SIGNAL(SignalStudyFrameChanged()), SLOT(reject())); + connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject())); if (Reverse) - connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int))); - - // Move widget on the botton right corner of main widget - int x, y; - mySMESHGUI->DefineDlgPosition(this, x, y); - this->move(x, y); - this->show(); // displays Dialog - + connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int))); + if (AutomaticPresentation) { + connect(AutomaticPresentation, SIGNAL(stateChanged(int)), SLOT(SelectionIntoArgument())); + connect(GetNextPresentationButton, SIGNAL(clicked()), SLOT(GetNextShapePresentation())); + } // set selection mode SMESH::SetPointRepresentation(true); - myViewWindow->SetSelectionMode( NodeSelection ); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) + aViewWindow->SetSelectionMode( NodeSelection ); myBusy = false; @@ -437,41 +554,124 @@ void SMESHGUI_AddMeshElementDlg::Init() //================================================================================= void SMESHGUI_AddMeshElementDlg::ClickOnApply() { + if( !isValid() ) + return; + if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) { myBusy = true; - SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array; - anArrayOfIdeces->length(myNbNodes); - bool reverse = (Reverse && Reverse->isChecked()); - QStringList aListId = QStringList::split(" ", myEditCurrentArgument->text(), false); - for (int i = 0; i < aListId.count(); i++) - if (reverse) - anArrayOfIdeces[i] = aListId[ myNbNodes - i - 1 ].toInt(); - else - anArrayOfIdeces[i] = aListId[ i ].toInt(); + QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts); + SMESH::long_array_var anArrayOfIndices = new SMESH::long_array; + anArrayOfIndices->length(aListId.count()); + const std::vector& 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(); + for ( int i = 1; i <= ComboBox_GroupName->count(); i++ ) { + QString aName = ComboBox_GroupName->itemText( i ); + if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) ) + idx = i; + } + if ( idx > 0 && idx <= myGroups.count() ) { + 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]; + } + } SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); + SMESH::long_array_var anIdList = new SMESH::long_array; + anIdList->length( 1 ); + anIdList[0] = -1; + switch (myElementType) { + case SMDSAbs_0DElement: + anIdList->length( anArrayOfIndices->length() ); + for ( size_t i = 0; i < anArrayOfIndices->length(); ++i ) + anIdList[i] = aMeshEditor->Add0DElement(anArrayOfIndices[i]); + break; + case SMDSAbs_Ball: + 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; case SMDSAbs_Edge: - aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break; + anIdList[0] = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break; case SMDSAbs_Face: - aMeshEditor->AddFace(anArrayOfIdeces.inout()); break; - case SMDSAbs_Volume: - aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break; - default:; + if ( myIsPoly ) + anIdList[0] = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout()); + else + anIdList[0] = aMeshEditor->AddFace(anArrayOfIndices.inout()); + break; + default: + anIdList[0] = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break; + } + + if ( anIdList[0] > 0 && addToGroup && !aGroupName.isEmpty() ) { + 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 ); + } + + if ( !aGroupUsed->_is_nil() ) + aGroupUsed->Add( anIdList.inout() ); } SALOME_ListIO aList; aList.Append( myActor->getIO() ); + mySelector->ClearIndex(); mySelectionMgr->setSelectedObjects( aList, false ); - SMESH::UpdateView(); mySimulation->SetVisibility(false); - + SMESH::UpdateView(); + buttonOk->setEnabled(false); buttonApply->setEnabled(false); + if ( AutomaticPresentation ) + GetNextPresentationButton->setEnabled(false); myEditCurrentArgument->setText(""); myBusy = false; + + SMESHGUI::Modified(); } } @@ -481,25 +681,48 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply() //================================================================================= void SMESHGUI_AddMeshElementDlg::ClickOnOk() { - this->ClickOnApply(); - this->ClickOnCancel(); - return; + ClickOnApply(); + reject(); } //================================================================================= -// function : ClickOnCancel() +// function : reject() // purpose : //================================================================================= -void SMESHGUI_AddMeshElementDlg::ClickOnCancel() +void SMESHGUI_AddMeshElementDlg::reject() { - mySelectionMgr->clearSelected(); mySimulation->SetVisibility(false); SMESH::SetPointRepresentation(false); - myViewWindow->SetSelectionMode( ActorSelection ); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) + aViewWindow->SetSelectionMode( ActorSelection ); disconnect(mySelectionMgr, 0, this, 0); mySMESHGUI->ResetState(); - reject(); - return; + QDialog::reject(); +} + +//================================================================================= +// function : ClickOnHelp() +// purpose : +//================================================================================= +void SMESHGUI_AddMeshElementDlg::ClickOnHelp() +{ + LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication()); + if (app) + app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), + myHelpFileName); + else { + QString platform; +#ifdef WIN32 + platform = "winapplication"; +#else + platform = "application"; +#endif + SUIT_MessageBox::warning(this, tr("WRN_WARNING"), + tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). + arg(app->resourceMgr()->stringValue("ExternalBrowser", + platform)). + arg(myHelpFileName)); + } } //================================================================================= @@ -515,6 +738,8 @@ void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText) buttonOk->setEnabled(false); buttonApply->setEnabled(false); + if ( AutomaticPresentation ) + GetNextPresentationButton->setEnabled(false); mySimulation->SetVisibility(false); @@ -524,41 +749,43 @@ void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText) aMesh = myActor->GetObject()->GetMesh(); if (aMesh) { - SALOME_ListIO aList; aList.Append( myActor->getIO() ); - mySelectionMgr->setSelectedObjects( aList, false ); - - TColStd_IndexedMapOfInteger selectedIndices; TColStd_MapOfInteger newIndices; - mySelector->GetIndex(myActor->getIO(), selectedIndices); - QStringList aListId = QStringList::split(" ", theNewText, false); + 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() ) ) + { + newIndices.Add( n->GetID() ); + myNbOkNodes++; + } + else + allOk = false; + } + + mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false ); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) + aViewWindow->highlight( myActor->getIO(), true, true ); + + myNbOkNodes = ( allOk && ( myNbNodes == aListId.count() || myNbNodes == 1 )); + + if (myIsPoly) { - if( selectedIndices.Add( n->GetID() ) ) - newIndices.Add( n->GetID() ); - myNbOkNodes++; + if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 ) + myNbOkNodes = 0; + else + myNbOkNodes = aListId.count(); } - } - - if( newIndices.Extent()>0 ) - { - mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, true ); - myViewWindow->highlight( myActor->getIO(), true, true ); - } - bool aNodesOK = false; - if (myIsPoly && myElementType == SMDSAbs_Face && aListId.count() >=3 ){ - myNbOkNodes = aListId.count(); - aNodesOK = true; - } } - + if(myNbOkNodes) { buttonOk->setEnabled(true); buttonApply->setEnabled(true); + if ( AutomaticPresentation && AutomaticPresentation->isChecked() ) + GetNextPresentationButton->setEnabled(true); displaySimulation(); } - + myBusy = false; } @@ -575,6 +802,7 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument() myActor = 0; myBusy = true; + QString anOldEditArgument = myEditCurrentArgument->text(); myEditCurrentArgument->setText(""); myBusy = false; @@ -583,9 +811,13 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument() buttonOk->setEnabled(false); buttonApply->setEnabled(false); + if ( AutomaticPresentation ) + GetNextPresentationButton->setEnabled(false); mySimulation->SetVisibility(false); -// SMESH::SetPointRepresentation(true); + // SMESH::SetPointRepresentation(true); + + QString aCurrentEntry = myEntry; // get selected mesh SALOME_ListIO aList; @@ -595,24 +827,63 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument() return; Handle(SALOME_InteractiveObject) anIO = aList.First(); + myEntry = anIO->getEntry(); myMesh = SMESH::GetMeshByIO(anIO); if (myMesh->_is_nil()) return; + // 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) return; // get selected nodes QString aString = ""; - int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString); - myBusy = true; - myEditCurrentArgument->setText(aString); - myBusy = false; - if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) { - myNbNodes = nbNodes; - } else if (myNbNodes != nbNodes) { - return; + int nbNodes = 0; + while ( aString == "" || anOldEditArgument == aString ) { + if ( AutomaticPresentation && AutomaticPresentation->isChecked() ) { + nbNodes = SMESH::GetNameOfSelectedSortedNodes( myGeomType , mySelector, myActor, myShift, aString ); + } + else + nbNodes = SMESH::GetNameOfSelectedNodes( mySelector, myActor->getIO(), aString ); + if ( aString!= "" && myNbNodes == nbNodes && anOldEditArgument == aString && AutomaticPresentation && AutomaticPresentation->isChecked()) { + myShift++; + if ( myShift > nbNodes ) { + myEditCurrentArgument->setText(aString); + myShift = 0; + break; + } + continue; + } + myBusy = true; + myEditCurrentArgument->setText(aString); + myBusy = false; + if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) + myNbNodes = nbNodes; + else if (myNbNodes != nbNodes && myNbNodes != 1) { + myShift = 0; + return; + } + if ( !AutomaticPresentation || !AutomaticPresentation->isChecked() || + ( myIsPoly && nbNodes < 3 ) ) + break; } // OK @@ -620,6 +891,8 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument() buttonOk->setEnabled(true); buttonApply->setEnabled(true); + if ( AutomaticPresentation && AutomaticPresentation->isChecked() ) + GetNextPresentationButton->setEnabled(true); displaySimulation(); } @@ -632,30 +905,26 @@ void SMESHGUI_AddMeshElementDlg::displaySimulation() { if (myNbOkNodes && GroupButtons->isEnabled()) { SMESH::TElementSimulation::TVTKIds anIds; - QStringList aListId = QStringList::split(" ", myEditCurrentArgument->text(), false); + QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts); for (int i = 0; i < aListId.count(); i++) anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt())); if (Reverse && Reverse->isChecked()) - reverse(anIds.begin(),anIds.end()); - - vtkIdType aType = 0; - if (myIsPoly) - switch ( myElementType ) { - case SMDSAbs_Face : aType = VTK_POLYGON; break; - default: return; - } - else { - switch (myNbNodes) { - case 2: aType = VTK_LINE; break; - case 3: aType = VTK_TRIANGLE; break; - case 4: aType = myElementType == SMDSAbs_Face ? VTK_QUAD : VTK_TETRA; break; - case 8: aType = VTK_HEXAHEDRON; break; - default: return; - } + { + const std::vector& i = SMDS_MeshCell::reverseSmdsOrder( myGeomType ); + if ( i.empty() ) // polygon + std::reverse( anIds.begin(), anIds.end() ); + else + SMDS_MeshCell::applyInterlace( i, anIds ); } - mySimulation->SetPosition(myActor,aType,anIds); + vtkIdType aType = SMDS_MeshCell::toVtkType( myGeomType ); + if(aType == VTK_POLY_VERTEX) { + mySimulation->SetBallPosition(myActor,anIds,DiameterSpinBox->GetValue()); + } else { + mySimulation->SetPosition(myActor,aType,anIds); + } + SMESH::UpdateView(); } } @@ -673,6 +942,16 @@ void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument() SelectionIntoArgument(); } +//================================================================================= +// function : GetNextShapePresentation() +// purpose : +//================================================================================= +void SMESHGUI_AddMeshElementDlg::GetNextShapePresentation() +{ + myShift++; + SetEditCurrentArgument(); +} + //================================================================================= // function : DeactivateActiveDialog() // purpose : @@ -704,7 +983,8 @@ void SMESHGUI_AddMeshElementDlg::ActivateThisDialog() SMESH::SetPointRepresentation(true); - myViewWindow->SetSelectionMode( NodeSelection ); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) + aViewWindow->SetSelectionMode( NodeSelection ); SelectionIntoArgument(); } @@ -717,41 +997,56 @@ void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*) if (GroupConstructors->isEnabled()) return; ActivateThisDialog(); - return; } //================================================================================= -// function : closeEvent() +// function : CheckBox() // purpose : //================================================================================= -void SMESHGUI_AddMeshElementDlg::closeEvent (QCloseEvent*) +void SMESHGUI_AddMeshElementDlg::CheckBox (int state) { - /* same than click on cancel button */ - this->ClickOnCancel(); - return; + if (!myNbOkNodes) + return; + + if (state >= 0) { + mySimulation->SetVisibility(false); + displaySimulation(); + } } //================================================================================= -// function : hideEvent() -// purpose : caused by ESC key +// function : keyPressEvent() +// purpose : //================================================================================= -void SMESHGUI_AddMeshElementDlg::hideEvent (QHideEvent*) +void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e ) { - if (!isMinimized()) - ClickOnCancel(); + QDialog::keyPressEvent( e ); + if ( e->isAccepted() ) + return; + + if ( e->key() == Qt::Key_F1 ) { + e->accept(); + ClickOnHelp(); + } } //================================================================================= -// function : CheckBox() +// function : isValid // purpose : //================================================================================= -void SMESHGUI_AddMeshElementDlg::CheckBox (int state) -{ - if (!myNbOkNodes) - return; +void SMESHGUI_AddMeshElementDlg::onDiameterChanged(){ + displaySimulation(); +} - if (state >= 0) { - mySimulation->SetVisibility(false); - displaySimulation(); +//================================================================================= +// 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; }