X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_AddQuadraticElementDlg.cxx;h=daa119db5590a1597597afda75ac8672638a1fdb;hp=1c3106e735eb3c1ed149aceebfa603bd56d8d136;hb=2c607013a23bd4e7ba07e72e0c04dee2c1209cff;hpb=0635c9fc80f67d1e5dc0e94ec85f487286a92070 diff --git a/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.cxx b/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.cxx index 1c3106e73..daa119db5 100644 --- a/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.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 @@ -69,6 +71,7 @@ #include // Qt includes +#include #include #include #include @@ -221,7 +224,7 @@ namespace SMESH void SetPosition (SMESH_Actor* theActor, const int theType, TVTKIds& theIds, - const int theMode, + const int theMode, const bool theReverse) { vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid(); @@ -311,8 +314,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(); @@ -411,7 +414,7 @@ QWidget* IdEditItem::createEditor() const // purpose : constructor //================================================================================= SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule, - const int theType ) + const int theType ) : QDialog( SMESH::GetDesktop( theModule ) ), mySMESHGUI( theModule ), mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), @@ -505,6 +508,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 +549,7 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM /***************************************************************/ aDialogLayout->addWidget(GroupConstructors); aDialogLayout->addWidget(GroupArguments); + aDialogLayout->addWidget(GroupGroups); aDialogLayout->addWidget(GroupButtons); Init(); /* Initialisations */ @@ -555,6 +573,9 @@ void SMESHGUI_AddQuadraticElementDlg::Init() myRadioButton1->setChecked(true); mySMESHGUI->SetActiveDialogBox((QDialog*)this); + /* reset "Add to group" control */ + GroupGroups->setChecked( false ); + myActor = 0; int aNumRows; @@ -645,6 +666,7 @@ void SMESHGUI_AddQuadraticElementDlg::Init() connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog())); connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel())); + connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), SLOT(ClickOnCancel())); // set selection mode SMESH::SetPointRepresentation(true); @@ -661,6 +683,9 @@ void SMESHGUI_AddQuadraticElementDlg::Init() //================================================================================= void SMESHGUI_AddQuadraticElementDlg::ClickOnApply() { + if( !isValid() ) + return; + if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() ) return; @@ -696,20 +721,81 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply() for (int i = 0; i < aNumberOfIds; i++) anArrayOfIdeces[i] = anIds[ i ]; + 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]; + } + } + + 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; + default: break; } + if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) { + SMESH::SMESH_Group_var aGroupUsed; + if ( aGroup->_is_nil() ) { + // create new group + aGroupUsed = SMESH::AddGroup( myMesh, anElementType, 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() ); mySelector->ClearIndex(); mySelectionMgr->setSelectedObjects( aList, false ); @@ -721,6 +807,8 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply() SetEditCorners(); updateButtons(); + + SMESHGUI::Modified(); } //================================================================================= @@ -766,10 +854,10 @@ void SMESHGUI_AddQuadraticElementDlg::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)); } } @@ -797,12 +885,12 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText) for (int i = 0; i < aListId.count(); i++) { if ( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) ) { - newIndices.Add( n->GetID() ); + newIndices.Add( n->GetID() ); } else { - allOk = false; - break; + allOk = false; + break; } } @@ -827,6 +915,8 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument() if (myBusy) return; BusyLocker lock( myBusy ); + QString aCurrentEntry = myEntry; + if ( myIsEditCorners ) { // clear @@ -851,6 +941,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 +951,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; + } + 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() == anElementType ) { + QString aGroupName( aGroup->GetName() ); + if ( !aGroupName.isEmpty() ) { + myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup)); + ComboBox_GroupName->addItem( aGroupName ); + } + } + } + } if (!myActor) { updateButtons(); @@ -914,16 +1036,16 @@ void SMESHGUI_AddQuadraticElementDlg::displaySimulation() else { for ( int row = 0; row < myNbCorners; row++ ) - anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(row, 0)->text().toInt() ) ); + anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(row, 0)->text().toInt() ) ); for ( int row = 0; row < myTable->rowCount(); row++ ) { - anID = myTable->item(row, 1)->text().toInt(&ok); - if (!ok) { - anID = myTable->item(row, 0)->text().toInt(); - aDisplayMode = VTK_WIREFRAME; - } - anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) ); + anID = myTable->item(row, 1)->text().toInt(&ok); + if (!ok) { + anID = myTable->item(row, 0)->text().toInt(); + aDisplayMode = VTK_WIREFRAME; + } + anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) ); } } @@ -1117,7 +1239,7 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity ) // clear table for ( int row = 0; row < myTable->rowCount(); row++ ) for ( int col = 0; col < myTable->columnCount(); col++ ) - if ( QTableWidgetItem* aTWI = myTable->item(row, col) ) aTWI->setText(""); + if ( QTableWidgetItem* aTWI = myTable->item(row, col) ) aTWI->setText(""); myTable->setEnabled( false ); } @@ -1169,3 +1291,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; +}