From: ouv Date: Mon, 28 Dec 2009 16:23:43 +0000 (+0000) Subject: Fix of issue 0020614: EDF 1133 SMESH : Put new added elements and nodes to group X-Git-Tag: PARAVIS_29012010~29 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=48633271692b647b8b01eed5b6e0594f627b276c;p=modules%2Fsmesh.git Fix of issue 0020614: EDF 1133 SMESH : Put new added elements and nodes to group --- diff --git a/doc/salome/gui/SMESH/images/a-createpolyhedralvolume.png b/doc/salome/gui/SMESH/images/a-createpolyhedralvolume.png index 26403226c..009f71d51 100755 Binary files a/doc/salome/gui/SMESH/images/a-createpolyhedralvolume.png and b/doc/salome/gui/SMESH/images/a-createpolyhedralvolume.png differ diff --git a/doc/salome/gui/SMESH/images/add0delement.png b/doc/salome/gui/SMESH/images/add0delement.png index e6578f888..432387998 100644 Binary files a/doc/salome/gui/SMESH/images/add0delement.png and b/doc/salome/gui/SMESH/images/add0delement.png differ diff --git a/doc/salome/gui/SMESH/images/addedge.png b/doc/salome/gui/SMESH/images/addedge.png index f142dffb2..34f4fe07a 100755 Binary files a/doc/salome/gui/SMESH/images/addedge.png and b/doc/salome/gui/SMESH/images/addedge.png differ diff --git a/doc/salome/gui/SMESH/images/addhexahedron.png b/doc/salome/gui/SMESH/images/addhexahedron.png index 78ea3b50f..65d881f86 100755 Binary files a/doc/salome/gui/SMESH/images/addhexahedron.png and b/doc/salome/gui/SMESH/images/addhexahedron.png differ diff --git a/doc/salome/gui/SMESH/images/addnode.png b/doc/salome/gui/SMESH/images/addnode.png index 1f5375b9a..bbde71e6a 100755 Binary files a/doc/salome/gui/SMESH/images/addnode.png and b/doc/salome/gui/SMESH/images/addnode.png differ diff --git a/doc/salome/gui/SMESH/images/addnode_notebook.png b/doc/salome/gui/SMESH/images/addnode_notebook.png index 4abab3358..804f806df 100755 Binary files a/doc/salome/gui/SMESH/images/addnode_notebook.png and b/doc/salome/gui/SMESH/images/addnode_notebook.png differ diff --git a/doc/salome/gui/SMESH/images/addpolygon.png b/doc/salome/gui/SMESH/images/addpolygon.png index 5d02dd70d..71b81ecca 100755 Binary files a/doc/salome/gui/SMESH/images/addpolygon.png and b/doc/salome/gui/SMESH/images/addpolygon.png differ diff --git a/doc/salome/gui/SMESH/images/addquadrangle.png b/doc/salome/gui/SMESH/images/addquadrangle.png index 3e5c87c42..3dccce258 100755 Binary files a/doc/salome/gui/SMESH/images/addquadrangle.png and b/doc/salome/gui/SMESH/images/addquadrangle.png differ diff --git a/doc/salome/gui/SMESH/images/addtetrahedron.png b/doc/salome/gui/SMESH/images/addtetrahedron.png index 37dc29659..0289a95e4 100755 Binary files a/doc/salome/gui/SMESH/images/addtetrahedron.png and b/doc/salome/gui/SMESH/images/addtetrahedron.png differ diff --git a/doc/salome/gui/SMESH/images/addtriangle.png b/doc/salome/gui/SMESH/images/addtriangle.png index 52a644e51..991085fd1 100755 Binary files a/doc/salome/gui/SMESH/images/addtriangle.png and b/doc/salome/gui/SMESH/images/addtriangle.png differ diff --git a/doc/salome/gui/SMESH/images/aqt.png b/doc/salome/gui/SMESH/images/aqt.png index ae8e0d081..46ee94dae 100755 Binary files a/doc/salome/gui/SMESH/images/aqt.png and b/doc/salome/gui/SMESH/images/aqt.png differ diff --git a/doc/salome/gui/SMESH/input/adding_nodes_and_elements.doc b/doc/salome/gui/SMESH/input/adding_nodes_and_elements.doc index 5cb3b1548..fde5fc0f0 100644 --- a/doc/salome/gui/SMESH/input/adding_nodes_and_elements.doc +++ b/doc/salome/gui/SMESH/input/adding_nodes_and_elements.doc @@ -26,6 +26,10 @@ following associated submenu will appear: \image html image146.png From this submenu select the type of element which you would like to add to your mesh. +\note All dialogs intended for adding nodes or elements to mesh provide a possibility +to add these nodes/elements to the specified group (or to create the group if it +doesn't exist). Add to group box allows to choose an existing group for created +node or element or to specify a name for new group. See Also sample TUI Scripts of diff --git a/doc/salome/gui/SMESH/input/adding_quadratic_elements.doc b/doc/salome/gui/SMESH/input/adding_quadratic_elements.doc index afe9b77b5..2a587d147 100644 --- a/doc/salome/gui/SMESH/input/adding_quadratic_elements.doc +++ b/doc/salome/gui/SMESH/input/adding_quadratic_elements.doc @@ -18,6 +18,11 @@ one of the following: \image html image152.png +\note All dialogs intended for adding quadratic elements to mesh provide a possibility +to add these elements to the specified group (or to create the group if it doesn't exist). +Add to group box allows to choose an existing group for created element or +to specify a name for new group. + To create any Quadratic Element specify the nodes which will form your triangle by selecting them in the 3D viewer with pressed Shift button. Their numbers will appear in the dialog box as Corner Nodes diff --git a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx index 33c410193..6df9978de 100644 --- a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx @@ -30,6 +30,7 @@ #include "SMESHGUI_Utils.h" #include "SMESHGUI_VTKUtils.h" #include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_GroupUtils.h" #include "SMESHGUI_IdValidator.h" #include @@ -64,6 +65,7 @@ #include // Qt includes +#include #include #include #include @@ -358,6 +360,20 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, GroupC1Layout->addWidget(LineEditC1A1, 0, 2); if ( Reverse ) GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3); + /***************************************************************/ + 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 ); + + GroupGroupsLayout->addWidget( TextLabel_GroupName ); + GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 ); + /***************************************************************/ GroupButtons = new QGroupBox(this); QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons); @@ -385,6 +401,7 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, /***************************************************************/ aTopLayout->addWidget(GroupConstructors); aTopLayout->addWidget(GroupC1); + aTopLayout->addWidget(GroupGroups); aTopLayout->addWidget(GroupButtons); Init(); /* Initialisations */ @@ -410,6 +427,9 @@ void SMESHGUI_AddMeshElementDlg::Init() myEditCurrentArgument = LineEditC1A1; mySMESHGUI->SetActiveDialogBox((QDialog*)this); + /* reset "Add to group" control */ + GroupGroups->setChecked( false ); + myNbOkNodes = 0; myActor = 0; @@ -446,6 +466,9 @@ void SMESHGUI_AddMeshElementDlg::Init() //================================================================================= void SMESHGUI_AddMeshElementDlg::ClickOnApply() { + if( !isValid() ) + return; + if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) { myBusy = true; SMESH::long_array_var anArrayOfIndices = new SMESH::long_array; @@ -458,24 +481,53 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply() else anArrayOfIndices[i] = aListId[ i ].toInt(); + long anElemId = -1; SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); switch (myElementType) { case SMDSAbs_0DElement: - aMeshEditor->Add0DElement(anArrayOfIndices[0]); break; + anElemId = aMeshEditor->Add0DElement(anArrayOfIndices[0]); break; case SMDSAbs_Edge: - aMeshEditor->AddEdge(anArrayOfIndices.inout()); break; + anElemId = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break; case SMDSAbs_Face: { if(myIsPoly) - aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout()); + anElemId = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout()); else - aMeshEditor->AddFace(anArrayOfIndices.inout()); + anElemId = aMeshEditor->AddFace(anArrayOfIndices.inout()); break; } case SMDSAbs_Volume: - aMeshEditor->AddVolume(anArrayOfIndices.inout()); break; + anElemId = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break; default:; } + if( anElemId != -1 && GroupGroups->isChecked() ) { + SMESH::SMESH_Group_var aGroup; + QString aGroupName = ComboBox_GroupName->currentText(); + SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups(); + for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) { + SMESH::SMESH_GroupBase_var aGroupBase = aListOfGroups[i]; + if( !aGroupBase->_is_nil() ) { + SMESH::SMESH_Group_var aRefGroup = SMESH::SMESH_Group::_narrow( aGroupBase ); + if( !aRefGroup->_is_nil() ) { + QString aRefGroupName( aRefGroup->GetName() ); + if( aRefGroupName == aGroupName ) { + aGroup = aRefGroup; // // add node to existing group + break; + } + } + } + } + if( aGroup->_is_nil() ) // create new group + aGroup = SMESH::AddGroup( myMesh, (SMESH::ElementType)myElementType, aGroupName ); + + if( !aGroup->_is_nil() ) { + SMESH::long_array_var anIdList = new SMESH::long_array; + anIdList->length( 1 ); + anIdList[0] = anElemId; + aGroup->Add( anIdList.inout() ); + } + } + SALOME_ListIO aList; aList.Append( myActor->getIO() ); mySelector->ClearIndex(); mySelectionMgr->setSelectedObjects( aList, false ); @@ -628,6 +680,8 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument() mySimulation->SetVisibility(false); // SMESH::SetPointRepresentation(true); + QString aCurrentEntry = myEntry; + // get selected mesh SALOME_ListIO aList; mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type()); @@ -636,10 +690,29 @@ 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 ) { + 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 aGroupBase = aListOfGroups[i]; + if ( !aGroupBase->_is_nil() && aGroupBase->GetType() == (SMESH::ElementType)myElementType ) { + SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupBase ); + if ( !aGroup->_is_nil() ) { + QString aGroupName( aGroup->GetName() ); + if ( !aGroupName.isEmpty() ) + ComboBox_GroupName->addItem( aGroupName ); + } + } + } + } + myActor = SMESH::FindActorByEntry(anIO->getEntry()); if (!myActor) return; @@ -812,3 +885,16 @@ void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e ) ClickOnHelp(); } } + +//================================================================================= +// 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; +} diff --git a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.h b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.h index ee10b312f..ae0c44e0f 100644 --- a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.h +++ b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.h @@ -38,6 +38,7 @@ #include #include CORBA_SERVER_HEADER(SMESH_Mesh) +class QComboBox; class QGroupBox; class QLabel; class QLineEdit; @@ -74,6 +75,8 @@ private: void keyPressEvent( QKeyEvent* ); void displaySimulation(); + bool isValid(); + SMESHGUI* mySMESHGUI; /* Current SMESHGUI object */ LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */ int myNbOkNodes; /* to check when arguments is defined */ @@ -89,9 +92,13 @@ private: SMESH::SMESH_Mesh_var myMesh; SMESH_Actor* myActor; SMESH::TElementSimulation* mySimulation; + QString myEntry; QGroupBox* GroupConstructors; QRadioButton* Constructor1; + QGroupBox* GroupGroups; + QLabel* TextLabel_GroupName; + QComboBox* ComboBox_GroupName; QGroupBox* GroupButtons; QPushButton* buttonOk; QPushButton* buttonCancel; diff --git a/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.cxx b/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.cxx index 4a9fa18ac..23b49bc12 100644 --- a/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.cxx @@ -30,6 +30,7 @@ #include "SMESHGUI_Utils.h" #include "SMESHGUI_VTKUtils.h" #include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_GroupUtils.h" #include "SMESHGUI_IdValidator.h" #include @@ -69,6 +70,7 @@ #include // Qt includes +#include #include #include #include @@ -505,6 +507,20 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM aGroupArgumentsLayout->addWidget(myTable, 1, 0, 1, 3); aGroupArgumentsLayout->addWidget(myReverseCB, 2, 0, 1, 3); + /***************************************************************/ + 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 ); + + GroupGroupsLayout->addWidget( TextLabel_GroupName ); + GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 ); + /***************************************************************/ GroupButtons = new QGroupBox(this); QHBoxLayout* aGroupButtonsLayout = new QHBoxLayout(GroupButtons); @@ -532,6 +548,7 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM /***************************************************************/ aDialogLayout->addWidget(GroupConstructors); aDialogLayout->addWidget(GroupArguments); + aDialogLayout->addWidget(GroupGroups); aDialogLayout->addWidget(GroupButtons); Init(); /* Initialisations */ @@ -555,6 +572,9 @@ void SMESHGUI_AddQuadraticElementDlg::Init() myRadioButton1->setChecked(true); mySMESHGUI->SetActiveDialogBox((QDialog*)this); + /* reset "Add to group" control */ + GroupGroups->setChecked( false ); + myActor = 0; int aNumRows; @@ -661,6 +681,9 @@ void SMESHGUI_AddQuadraticElementDlg::Init() //================================================================================= void SMESHGUI_AddQuadraticElementDlg::ClickOnApply() { + if( !isValid() ) + return; + if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() ) return; @@ -696,20 +719,53 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply() for (int i = 0; i < aNumberOfIds; i++) anArrayOfIdeces[i] = anIds[ i ]; + SMESH::ElementType anElementType; + long anElemId = -1; SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); switch (myType) { case QUAD_EDGE: - aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break; + anElementType = SMESH::EDGE; + anElemId = aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break; case QUAD_TRIANGLE: case QUAD_QUADRANGLE: - aMeshEditor->AddFace(anArrayOfIdeces.inout()); break; + anElementType = SMESH::FACE; + anElemId = aMeshEditor->AddFace(anArrayOfIdeces.inout()); break; case QUAD_TETRAHEDRON: case QUAD_PYRAMID: case QUAD_PENTAHEDRON: case QUAD_HEXAHEDRON: - aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break; + anElementType = SMESH::VOLUME; + anElemId = aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break; } + if( anElemId != -1 && GroupGroups->isChecked() ) { + SMESH::SMESH_Group_var aGroup; + QString aGroupName = ComboBox_GroupName->currentText(); + SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups(); + for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) { + SMESH::SMESH_GroupBase_var aGroupBase = aListOfGroups[i]; + if( !aGroupBase->_is_nil() ) { + SMESH::SMESH_Group_var aRefGroup = SMESH::SMESH_Group::_narrow( aGroupBase ); + if( !aRefGroup->_is_nil() ) { + QString aRefGroupName( aRefGroup->GetName() ); + if( aRefGroupName == aGroupName ) { + aGroup = aRefGroup; // // add node to existing group + break; + } + } + } + } + if( aGroup->_is_nil() ) // create new group + aGroup = SMESH::AddGroup( myMesh, anElementType, aGroupName ); + + if( !aGroup->_is_nil() ) { + SMESH::long_array_var anIdList = new SMESH::long_array; + anIdList->length( 1 ); + anIdList[0] = anElemId; + aGroup->Add( anIdList.inout() ); + } + } + SALOME_ListIO aList; aList.Append( myActor->getIO() ); mySelector->ClearIndex(); mySelectionMgr->setSelectedObjects( aList, false ); @@ -827,6 +883,8 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument() if (myBusy) return; BusyLocker lock( myBusy ); + QString aCurrentEntry = myEntry; + if ( myIsEditCorners ) { // clear @@ -851,6 +909,7 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument() } Handle(SALOME_InteractiveObject) anIO = aList.First(); + myEntry = anIO->getEntry(); myMesh = SMESH::GetMeshByIO(anIO); if (myMesh->_is_nil()) { updateButtons(); @@ -860,6 +919,37 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument() myActor = SMESH::FindActorByEntry(anIO->getEntry()); } + + // process groups + if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) { + SMESH::ElementType anElementType; + switch ( myType ) { + case QUAD_EDGE: + anElementType = SMESH::EDGE; break; + case QUAD_TRIANGLE: + case QUAD_QUADRANGLE: + anElementType = SMESH::FACE; break; + case QUAD_TETRAHEDRON: + case QUAD_PYRAMID: + case QUAD_PENTAHEDRON: + case QUAD_HEXAHEDRON: + anElementType = SMESH::VOLUME; break; + } + 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 aGroupBase = aListOfGroups[i]; + if ( !aGroupBase->_is_nil() && aGroupBase->GetType() == anElementType ) { + SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupBase ); + if ( !aGroup->_is_nil() ) { + QString aGroupName( aGroup->GetName() ); + if ( !aGroupName.isEmpty() ) + ComboBox_GroupName->addItem( aGroupName ); + } + } + } + } if (!myActor) { updateButtons(); @@ -1169,3 +1259,16 @@ void SMESHGUI_AddQuadraticElementDlg::updateButtons() buttonOk->setEnabled( valid ); buttonApply->setEnabled( valid ); } + +//================================================================================= +// function : isValid +// purpose : +//================================================================================= +bool SMESHGUI_AddQuadraticElementDlg::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; +} diff --git a/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.h b/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.h index a048a6760..998d3284f 100644 --- a/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.h +++ b/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.h @@ -36,7 +36,9 @@ #include #include CORBA_SERVER_HEADER(SMESH_Mesh) +class QComboBox; class QGroupBox; +class QLabel; class QLineEdit; class QPushButton; class QRadioButton; @@ -78,6 +80,8 @@ private: bool IsValid(); void updateButtons(); + bool isValid(); + SMESHGUI* mySMESHGUI; /* Current SMESHGUI object */ LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */ int myNbCorners; /* The required number of corners */ @@ -87,6 +91,7 @@ private: SMESH::SMESH_Mesh_var myMesh; SMESH_Actor* myActor; SMESH::TElementSimulation* mySimulation; + QString myEntry; int myType; bool myIsEditCorners; @@ -100,6 +105,10 @@ private: QTableWidget* myTable; QCheckBox* myReverseCB; + QGroupBox* GroupGroups; + QLabel* TextLabel_GroupName; + QComboBox* ComboBox_GroupName; + QGroupBox* GroupButtons; QPushButton* buttonOk; QPushButton* buttonCancel; diff --git a/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.cxx b/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.cxx index c62b83711..b97b4d7f2 100644 --- a/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.cxx @@ -30,6 +30,7 @@ #include "SMESHGUI_Utils.h" #include "SMESHGUI_VTKUtils.h" #include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_GroupUtils.h" #include "SMESHGUI_IdValidator.h" #include @@ -63,6 +64,7 @@ // Qt includes #include #include +#include #include #include #include @@ -246,6 +248,20 @@ SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI GroupContentLayout->addWidget( RemoveButton, 3, 3 ); GroupContentLayout->addWidget( Preview, 5, 0, 1, 4 ); + /***************************************************************/ + 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 ); + + GroupGroupsLayout->addWidget( TextLabel_GroupName ); + GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 ); + /***************************************************************/ GroupButtons = new QGroupBox( this ); QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons ); @@ -273,6 +289,7 @@ SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI /***************************************************************/ topLayout->addWidget( ConstructorsBox ); topLayout->addWidget( GroupContent ); + topLayout->addWidget( GroupGroups ); topLayout->addWidget( GroupButtons ); mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector(); @@ -306,6 +323,9 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::Init() myEditCurrentArgument = LineEditElements; mySMESHGUI->SetActiveDialogBox( (QDialog*)this ); + /* reset "Add to group" control */ + GroupGroups->setChecked( false ); + myNbOkElements = 0; myActor = 0; @@ -420,10 +440,14 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){ //================================================================================= void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply() { + if( !isValid() ) + return; + if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked()) { if(checkEditLine(false) == -1) {return;} busy = true; + long anElemId = -1; if (GetConstructorId() == 0) { SMESH::long_array_var anIdsOfNodes = new SMESH::long_array; @@ -453,7 +477,7 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply() try{ SUIT_OverrideCursor aWaitCursor; SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); - aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities); + anElemId = aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities); }catch(SALOME::SALOME_Exception& exc){ INFOS("Follow exception was cought:\n\t"<GetMeshEditor(); - aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces); + anElemId = aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces); }catch(SALOME::SALOME_Exception& exc){ INFOS("Follow exception was cought:\n\t"<isChecked() ) { + SMESH::SMESH_Group_var aGroup; + QString aGroupName = ComboBox_GroupName->currentText(); + SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups(); + for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) { + SMESH::SMESH_GroupBase_var aGroupBase = aListOfGroups[i]; + if( !aGroupBase->_is_nil() ) { + SMESH::SMESH_Group_var aRefGroup = SMESH::SMESH_Group::_narrow( aGroupBase ); + if( !aRefGroup->_is_nil() ) { + QString aRefGroupName( aRefGroup->GetName() ); + if( aRefGroupName == aGroupName ) { + aGroup = aRefGroup; // // add node to existing group + break; + } + } + } + } + if( aGroup->_is_nil() ) // create new group + aGroup = SMESH::AddGroup( myMesh, SMESH::VOLUME, aGroupName ); + + if( !aGroup->_is_nil() ) { + SMESH::long_array_var anIdList = new SMESH::long_array; + anIdList->length( 1 ); + anIdList[0] = anElemId; + aGroup->Add( anIdList.inout() ); + } + } + //SALOME_ListIO aList; //mySelectionMgr->setSelectedObjects( aList ); SMESH::UpdateView(); @@ -663,6 +715,8 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument() mySimulation->SetVisibility(false); + QString aCurrentEntry = myEntry; + // get selected mesh SALOME_ListIO selected; @@ -672,10 +726,29 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument() return; } + myEntry = selected.First()->getEntry(); myMesh = SMESH::GetMeshByIO( selected.First() ); if ( myMesh->_is_nil() ) return; + // process groups + if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) { + 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 aGroupBase = aListOfGroups[i]; + if ( !aGroupBase->_is_nil() && aGroupBase->GetType() == SMESH::VOLUME ) { + SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupBase ); + if ( !aGroup->_is_nil() ) { + QString aGroupName( aGroup->GetName() ); + if ( !aGroupName.isEmpty() ) + ComboBox_GroupName->addItem( aGroupName ); + } + } + } + } + myActor = SMESH::FindActorByObject(myMesh); if ( !myActor ) return; @@ -1062,3 +1135,16 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e ) ClickOnHelp(); } } + +//================================================================================= +// function : isValid +// purpose : +//================================================================================= +bool SMESHGUI_CreatePolyhedralVolumeDlg::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; +} diff --git a/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.h b/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.h index b46d0c35b..51fbae54c 100644 --- a/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.h +++ b/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.h @@ -37,6 +37,7 @@ #include CORBA_SERVER_HEADER(SMESH_Mesh) class QButtonGroup; +class QComboBox; class QGroupBox; class QListWidget; class QLabel; @@ -75,6 +76,8 @@ private: int GetConstructorId(); void displaySimulation(); + bool isValid(); + int checkEditLine( bool = true ); /*! Checking for indices, return 1 if all ok, esle -1*/ SMESHGUI* mySMESHGUI; /* Current SMESHGUI object */ @@ -88,12 +91,16 @@ private: SMESH::SMESH_Mesh_var myMesh; SMESH_Actor* myActor; SMESH::TPolySimulation* mySimulation; + QString myEntry; QGroupBox* ConstructorsBox; QButtonGroup* GroupConstructors; QRadioButton* RadioButton1; QRadioButton* RadioButton2; QCheckBox* Preview; + QGroupBox* GroupGroups; + QLabel* TextLabel_GroupName; + QComboBox* ComboBox_GroupName; QGroupBox* GroupButtons; QPushButton* buttonOk; QPushButton* buttonCancel; diff --git a/src/SMESHGUI/SMESHGUI_NodesDlg.cxx b/src/SMESHGUI/SMESHGUI_NodesDlg.cxx index 76b75dbb9..ebc42b198 100644 --- a/src/SMESHGUI/SMESHGUI_NodesDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_NodesDlg.cxx @@ -31,6 +31,7 @@ #include "SMESHGUI_Utils.h" #include "SMESHGUI_VTKUtils.h" #include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_GroupUtils.h" #include #include @@ -70,6 +71,7 @@ #include // Qt includes +#include #include #include #include @@ -88,13 +90,14 @@ namespace SMESH { - void AddNode( SMESH::SMESH_Mesh_ptr theMesh, float x, float y, float z, const QStringList& theParameters ) + long AddNode( SMESH::SMESH_Mesh_ptr theMesh, float x, float y, float z, const QStringList& theParameters ) { + long aNodeId = -1; SUIT_OverrideCursor wc; try { _PTR(SObject) aSobj = SMESH::FindSObject( theMesh ); SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor(); - aMeshEditor->AddNode( x, y, z ); + aNodeId = aMeshEditor->AddNode( x, y, z ); theMesh->SetParameters( theParameters.join(":").toLatin1().constData() ); _PTR(Study) aStudy = GetActiveStudyDocument(); CORBA::Long anId = aStudy->StudyId(); @@ -111,6 +114,7 @@ namespace SMESH catch ( ... ) { INFOS( "Unknown exception was cought !!!" ); } + return aNodeId; } class TNodeSimulation @@ -277,6 +281,21 @@ SMESHGUI_NodesDlg::SMESHGUI_NodesDlg( SMESHGUI* theModule ): GroupCoordinatesLayout->addWidget( TextLabel_Z ); GroupCoordinatesLayout->addWidget( SpinBox_Z ); + + /***************************************************************/ + 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 ); + + GroupGroupsLayout->addWidget( TextLabel_GroupName ); + GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 ); + /***************************************************************/ GroupButtons = new QGroupBox( this ); QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons ); @@ -303,6 +322,7 @@ SMESHGUI_NodesDlg::SMESHGUI_NodesDlg( SMESHGUI* theModule ): /***************************************************************/ SMESHGUI_NodesDlgLayout->addWidget( GroupConstructors ); SMESHGUI_NodesDlgLayout->addWidget( GroupCoordinates ); + SMESHGUI_NodesDlgLayout->addWidget( GroupGroups ); SMESHGUI_NodesDlgLayout->addWidget( GroupButtons ); myHelpFileName = "adding_nodes_and_elements_page.html#adding_nodes_anchor"; @@ -337,6 +357,9 @@ void SMESHGUI_NodesDlg::Init() SpinBox_Y->SetValue( 0.0 ); SpinBox_Z->SetValue( 0.0 ); + /* reset "Add to group" control */ + GroupGroups->setChecked( false ); + mySMESHGUI->SetActiveDialogBox( this ); /* signals and slots connections */ @@ -416,9 +439,37 @@ bool SMESHGUI_NodesDlg::ClickOnApply() aParameters << SpinBox_Z->text(); mySimulation->SetVisibility( false ); - SMESH::AddNode( myMesh, x, y, z, aParameters ); + long aNodeId = SMESH::AddNode( myMesh, x, y, z, aParameters ); SMESH::SetPointRepresentation( true ); + if( aNodeId != -1 && GroupGroups->isChecked() ) { + SMESH::SMESH_Group_var aGroup; + QString aGroupName = ComboBox_GroupName->currentText(); + SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups(); + for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) { + SMESH::SMESH_GroupBase_var aGroupBase = aListOfGroups[i]; + if( !aGroupBase->_is_nil() ) { + SMESH::SMESH_Group_var aRefGroup = SMESH::SMESH_Group::_narrow( aGroupBase ); + if( !aRefGroup->_is_nil() ) { + QString aRefGroupName( aRefGroup->GetName() ); + if( aRefGroupName == aGroupName ) { + aGroup = aRefGroup; // // add node to existing group + break; + } + } + } + } + if( aGroup->_is_nil() ) // create new group + aGroup = SMESH::AddGroup( myMesh, SMESH::NODE, aGroupName ); + + if( !aGroup->_is_nil() ) { + SMESH::long_array_var anIdList = new SMESH::long_array; + anIdList->length( 1 ); + anIdList[0] = aNodeId; + aGroup->Add( anIdList.inout() ); + } + } + // select myMesh SALOME_ListIO aList; mySelectionMgr->selectedObjects( aList ); @@ -500,10 +551,13 @@ void SMESHGUI_NodesDlg::SelectionIntoArgument() mySimulation->SetVisibility( false ); SMESH::SetPointRepresentation( true ); + QString aCurrentEntry = myEntry; + const SALOME_ListIO& aList = mySelector->StoredIObjects(); if ( aList.Extent() == 1 ) { Handle(SALOME_InteractiveObject) anIO = aList.First(); if ( anIO->hasEntry() ) { + myEntry = anIO->getEntry(); myMesh = SMESH::GetMeshByIO( anIO ); if ( myMesh->_is_nil() ) return; QString aText; @@ -523,6 +577,24 @@ void SMESHGUI_NodesDlg::SelectionIntoArgument() SpinBox_Z->GetValue() ); } } + + // process groups + if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) { + 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 aGroupBase = aListOfGroups[i]; + if ( !aGroupBase->_is_nil() && aGroupBase->GetType() == SMESH::NODE ) { + SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupBase ); + if ( !aGroup->_is_nil() ) { + QString aGroupName( aGroup->GetName() ); + if ( !aGroupName.isEmpty() ) + ComboBox_GroupName->addItem( aGroupName ); + } + } + } + } } //================================================================================= @@ -623,5 +695,10 @@ bool SMESHGUI_NodesDlg::isValid() SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str ); return false; } + + if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) { + SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) ); + return false; + } return true; } diff --git a/src/SMESHGUI/SMESHGUI_NodesDlg.h b/src/SMESHGUI/SMESHGUI_NodesDlg.h index 8fc28eacc..c40109d90 100644 --- a/src/SMESHGUI/SMESHGUI_NodesDlg.h +++ b/src/SMESHGUI/SMESHGUI_NodesDlg.h @@ -36,6 +36,7 @@ #include #include CORBA_SERVER_HEADER(SMESH_Mesh) +class QComboBox; class QGroupBox; class QLabel; class QPushButton; @@ -70,6 +71,7 @@ private: SMESH::SMESH_Mesh_var myMesh; SMESH::TNodeSimulation* mySimulation; + QString myEntry; void Init(); void enterEvent( QEvent* ); @@ -90,6 +92,10 @@ private: QLabel* TextLabel_Y; QLabel* TextLabel_Z; + QGroupBox* GroupGroups; + QLabel* TextLabel_GroupName; + QComboBox* ComboBox_GroupName; + QGroupBox* GroupButtons; QPushButton* buttonApply; QPushButton* buttonOk; diff --git a/src/SMESHGUI/SMESH_msg_en.ts b/src/SMESHGUI/SMESH_msg_en.ts index 10320d163..5e0e03e4f 100644 --- a/src/SMESHGUI/SMESH_msg_en.ts +++ b/src/SMESHGUI/SMESH_msg_en.ts @@ -742,6 +742,11 @@ Please, select a mesh and try again MULTI_BORDERS Borders at Multi-Connections + + GROUP_NAME_IS_EMPTY + Name of group is empty +Please input a name of new group or choose the existing one + NODE_ID Node ID @@ -864,6 +869,10 @@ Please enter correct values and try again SMESH_ADD_TETRAS_TITLE Add Tetrahedron + + SMESH_ADD_TO_GROUP + Add to group + SMESH_ADD_TRIANGLE Add Triangle