X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_AddMeshElementDlg.cxx;h=6e25fd08fb1b22c8a8078c26bdafbc69d9648d0d;hb=d502285de5fe37ccf721ee1841f833f516e7cee5;hp=97e393a248d67f7c03253f60609e9dbf81802441;hpb=0635c9fc80f67d1e5dc0e94ec85f487286a92070;p=modules%2Fsmesh.git diff --git a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx index 97e393a24..6e25fd08f 100644 --- a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx @@ -1,24 +1,25 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003-2007 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. // -// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // SMESH SMESHGUI : GUI for SMESH component // File : SMESHGUI_AddMeshElementDlg.cxx // Author : Nicolas REJNERI, Open CASCADE S.A.S. @@ -30,6 +31,7 @@ #include "SMESHGUI_Utils.h" #include "SMESHGUI_VTKUtils.h" #include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_GroupUtils.h" #include "SMESHGUI_IdValidator.h" #include @@ -64,6 +66,7 @@ #include // Qt includes +#include #include #include #include @@ -186,11 +189,11 @@ namespace SMESH vtkIdList *anIds = vtkIdList::New(); if(aConn) - for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) - anIds->InsertId(i,theIds[aConn[i]]); + 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(); @@ -212,8 +215,8 @@ namespace SMESH ~TElementSimulation() { if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) { - myVTKViewWindow->RemoveActor(myPreviewActor); - myVTKViewWindow->RemoveActor(myFaceOrientation); + myVTKViewWindow->RemoveActor(myPreviewActor); + myVTKViewWindow->RemoveActor(myFaceOrientation); } myPreviewActor->Delete(); myFaceOrientation->Delete(); @@ -236,8 +239,8 @@ namespace SMESH // purpose : constructor //================================================================================= SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, - SMDSAbs_ElementType ElementType, - int nbNodes ) + SMDSAbs_ElementType ElementType, + int nbNodes ) : QDialog( SMESH::GetDesktop( theModule ) ), mySMESHGUI( theModule ), mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ) @@ -255,6 +258,10 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, myNbNodes = nbNodes; myElementType = ElementType; switch (ElementType) { + case SMDSAbs_0DElement: + if (myNbNodes != 1) + myNbNodes = 1; + break; case SMDSAbs_Face: // if (myNbNodes != 3 && myNbNodes != 4) // myNbNodes = 3; @@ -269,7 +276,11 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, } QString elemName; - if (myNbNodes == 2) { + if (myNbNodes == 1) { + elemName = "ELEM0D"; + myHelpFileName = "adding_nodes_and_elements_page.html#adding_0delems_anchor"; + } + else if (myNbNodes == 2) { elemName = "EDGE"; myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor"; } @@ -277,7 +288,7 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, elemName = "TRIANGLE"; myHelpFileName = "adding_nodes_and_elements_page.html#adding_triangles_anchor"; } - else if (myNbNodes == 4) + else if (myNbNodes == 4) { if (myElementType == SMDSAbs_Face) { elemName = "QUADRANGLE"; myHelpFileName = "adding_nodes_and_elements_page.html#adding_quadrangles_anchor"; @@ -286,6 +297,7 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, elemName = "TETRAS"; myHelpFileName = "adding_nodes_and_elements_page.html#adding_tetrahedrons_anchor"; } + } else if (myNbNodes == 8) { elemName = "HEXAS"; myHelpFileName = "adding_nodes_and_elements_page.html#adding_hexahedrons_anchor"; @@ -298,7 +310,7 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, else if (myElementType == SMDSAbs_Volume) { myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor"; } - + 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()); @@ -349,6 +361,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); @@ -376,6 +402,7 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule, /***************************************************************/ aTopLayout->addWidget(GroupConstructors); aTopLayout->addWidget(GroupC1); + aTopLayout->addWidget(GroupGroups); aTopLayout->addWidget(GroupButtons); Init(); /* Initialisations */ @@ -401,6 +428,10 @@ void SMESHGUI_AddMeshElementDlg::Init() myEditCurrentArgument = LineEditC1A1; mySMESHGUI->SetActiveDialogBox((QDialog*)this); + /* reset "Add to group" control */ + GroupGroups->setChecked( false ); + GroupGroups->setVisible( myElementType != SMDSAbs_0DElement ); + myNbOkNodes = 0; myActor = 0; @@ -416,6 +447,7 @@ void SMESHGUI_AddMeshElementDlg::Init() connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument())); /* to close dialog if study frame change */ connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel())); + connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), SLOT(ClickOnCancel())); if (Reverse) connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int))); @@ -437,33 +469,93 @@ 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); + SMESH::long_array_var anArrayOfIndices = new SMESH::long_array; + anArrayOfIndices->length(myNbNodes); bool reverse = (Reverse && Reverse->isChecked()); QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts); for (int i = 0; i < aListId.count(); i++) if (reverse) - anArrayOfIdeces[i] = aListId[ myNbNodes - i - 1 ].toInt(); + anArrayOfIndices[i] = aListId[ myNbNodes - i - 1 ].toInt(); else - anArrayOfIdeces[i] = aListId[ i ].toInt(); + 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 ) { + 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]; + } + } + long anElemId = -1; SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); switch (myElementType) { + case SMDSAbs_0DElement: + anElemId = aMeshEditor->Add0DElement(anArrayOfIndices[0]); break; case SMDSAbs_Edge: - aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break; - case SMDSAbs_Face:{ + anElemId = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break; + case SMDSAbs_Face: { if(myIsPoly) - aMeshEditor->AddPolygonalFace(anArrayOfIdeces.inout()); + anElemId = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout()); else - aMeshEditor->AddFace(anArrayOfIdeces.inout()); + anElemId = aMeshEditor->AddFace(anArrayOfIndices.inout()); break; - } case SMDSAbs_Volume: - aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break; - default:; + anElemId = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break; + default: break; + } + + if ( anElemId != -1 && 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() ) { + SMESH::long_array_var anIdList = new SMESH::long_array; + anIdList->length( 1 ); + anIdList[0] = anElemId; + aGroupUsed->Add( anIdList.inout() ); + } } SALOME_ListIO aList; aList.Append( myActor->getIO() ); @@ -479,6 +571,8 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply() myEditCurrentArgument->setText(""); myBusy = false; + + SMESHGUI::Modified(); } } @@ -515,8 +609,9 @@ void SMESHGUI_AddMeshElementDlg::ClickOnCancel() void SMESHGUI_AddMeshElementDlg::ClickOnHelp() { LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication()); - if (app) - app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName); + if (app) + app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), + myHelpFileName); else { QString platform; #ifdef WIN32 @@ -525,10 +620,10 @@ void SMESHGUI_AddMeshElementDlg::ClickOnHelp() platform = "application"; #endif SUIT_MessageBox::warning(this, tr("WRN_WARNING"), - tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). - arg(app->resourceMgr()->stringValue("ExternalBrowser", - platform)). - arg(myHelpFileName)); + tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). + arg(app->resourceMgr()->stringValue("ExternalBrowser", + platform)). + arg(myHelpFileName)); } } @@ -555,40 +650,40 @@ void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText) if (aMesh) { TColStd_MapOfInteger newIndices; - + 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++; - } + { + newIndices.Add( n->GetID() ); + myNbOkNodes++; + } else - allOk = false; + 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() ); - + if (myIsPoly) { - if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 ) - myNbOkNodes = 0; - else - myNbOkNodes = aListId.count(); + if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 ) + myNbOkNodes = 0; + else + myNbOkNodes = aListId.count(); } } - + if(myNbOkNodes) { buttonOk->setEnabled(true); buttonApply->setEnabled(true); displaySimulation(); } - + myBusy = false; } @@ -617,6 +712,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()); @@ -625,10 +722,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 ) { + 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; @@ -795,9 +911,22 @@ void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e ) QDialog::keyPressEvent( e ); if ( e->isAccepted() ) return; - + if ( e->key() == Qt::Key_F1 ) { e->accept(); 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; +}