X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_ShapeByMeshDlg.cxx;h=6647f4cdc00b76ec4dfb83dfb833f68829ec158a;hp=82352334b7f4953197a3766ba5b70383b928f04e;hb=6d32f944a0a115b6419184c50b57bf7c4eef5786;hpb=0635c9fc80f67d1e5dc0e94ec85f487286a92070 diff --git a/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx b/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx index 82352334b..6647f4cdc 100644 --- a/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx @@ -1,24 +1,25 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2019 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, 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SMESHGUI_ShapeByMeshDlg.cxx // Author : Edward AGAPOV, Open CASCADE S.A.S. // SMESH includes @@ -39,6 +40,7 @@ // SALOME GEOM includes #include #include +#include // SALOME GUI includes #include @@ -52,6 +54,8 @@ // SALOME KERNEL includes #include +#include +#include // OCCT includes #include @@ -79,8 +83,9 @@ enum { EDGE = 0, FACE, VOLUME }; * \brief Dialog to publish a sub-shape of the mesh main shape * by selecting mesh elements */ -SMESHGUI_ShapeByMeshDlg::SMESHGUI_ShapeByMeshDlg() - : SMESHGUI_Dialog( 0, false, true, OK | Close ) +SMESHGUI_ShapeByMeshDlg::SMESHGUI_ShapeByMeshDlg(bool isMultipleAllowed) + : SMESHGUI_Dialog( 0, false, true, OK | Close ), + myIsMultipleAllowed( isMultipleAllowed ) { setWindowTitle(tr("CAPTION")); @@ -129,7 +134,7 @@ QFrame* SMESHGUI_ShapeByMeshDlg::createMainFrame (QWidget* theParent) QLabel* anIdLabel = new QLabel( tr("ELEMENT_ID"), aMainGrp ); myElementId = new QLineEdit( aMainGrp ); myElementId->setValidator( new SMESHGUI_IdValidator( theParent, - !myIsMultipleAllowed ? 1 : 0 ) ); // 0 for any number of entities + !myIsMultipleAllowed ? 1 : 0 ) ); // 0 for any number of entities // shape name QLabel* aNameLabel = new QLabel( tr("GEOMETRY_NAME"), aMainGrp ); @@ -168,8 +173,7 @@ SMESHGUI_ShapeByMeshOp::SMESHGUI_ShapeByMeshOp(bool isMultipleAllowed): if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists GeometryGUI::InitGeomGen(); - myDlg = new SMESHGUI_ShapeByMeshDlg; - myDlg->setMultipleAllowed(myIsMultipleAllowed); + myDlg = new SMESHGUI_ShapeByMeshDlg(myIsMultipleAllowed); connect(myDlg->myElemTypeGroup, SIGNAL(buttonClicked(int)), SLOT(onTypeChanged(int))); connect(myDlg->myElementId, SIGNAL(textChanged(const QString&)), SLOT(onElemIdChanged(const QString&))); @@ -222,7 +226,7 @@ SMESH::SMESH_Mesh_ptr SMESHGUI_ShapeByMeshOp::GetMesh() //======================================================================= // function : GetShape() -// purpose : Get published sub-shape +// purpose : Return published sub-shape, it must be UnRegister()ed! //======================================================================= GEOM::GEOM_Object_ptr SMESHGUI_ShapeByMeshOp::GetShape() { @@ -250,40 +254,40 @@ void SMESHGUI_ShapeByMeshOp::SetMesh (SMESH::SMESH_Mesh_ptr thePtr) int shapeDim = 0; // max dim with several shapes //if ( /*mySelectionMgr*/ selectionMgr()->isOk(anIObj) ) // check that the mesh has a valid shape { - _PTR(SObject) aSO = SMESH::FindSObject(myMesh.in()); - GEOM::GEOM_Object_var mainShape = SMESH::GetGeom(aSO); - if ( !mainShape->_is_nil() ) - { - TopoDS_Shape aShape; - if ( GEOMBase::GetShape(mainShape, aShape)) - { - TopAbs_ShapeEnum types[4] = { TopAbs_EDGE, TopAbs_FACE, TopAbs_SHELL, TopAbs_SOLID }; - for ( int dim = 4; dim > 0; --dim ) { - TopAbs_ShapeEnum type = types[ dim - 1 ]; - TopAbs_ShapeEnum avoid = ( type == TopAbs_SHELL ) ? TopAbs_SOLID : TopAbs_SHAPE; - TopExp_Explorer exp( aShape, type, avoid ); - for ( ; nbShapes[ type ] < 2 && exp.More(); exp.Next() ) - ++nbShapes[ type ]; - if ( nbShapes[ type ] > 1 ) { - shapeDim = dim; - break; - } - } - } - } + _PTR(SObject) aSO = SMESH::FindSObject(myMesh.in()); + GEOM::GEOM_Object_var mainShape = SMESH::GetGeom(aSO); + if ( !mainShape->_is_nil() ) + { + TopoDS_Shape aShape; + if ( GEOMBase::GetShape(mainShape, aShape)) + { + TopAbs_ShapeEnum types[4] = { TopAbs_EDGE, TopAbs_FACE, TopAbs_SHELL, TopAbs_SOLID }; + for ( int dim = 4; dim > 0; --dim ) { + TopAbs_ShapeEnum type = types[ dim - 1 ]; + TopAbs_ShapeEnum avoid = ( type == TopAbs_SHELL ) ? TopAbs_SOLID : TopAbs_SHAPE; + TopExp_Explorer exp( aShape, type, avoid ); + for ( ; nbShapes[ type ] < 2 && exp.More(); exp.Next() ) + ++nbShapes[ type ]; + if ( nbShapes[ type ] > 1 ) { + shapeDim = dim; + break; + } + } + } + } } if (shapeDim > 0) - { - if ( nbShapes[ TopAbs_SHELL ] + nbShapes[ TopAbs_SOLID ] > 1 ) - shapeDim = 3; - hasElement[ EDGE ] = shapeDim > 0 && myMesh->NbEdges(); - hasElement[ FACE ] = shapeDim > 1 && myMesh->NbFaces(); - hasElement[ VOLUME ] = shapeDim > 2 && myMesh->NbVolumes(); - } + { + if ( nbShapes[ TopAbs_SHELL ] + nbShapes[ TopAbs_SOLID ] > 1 ) + shapeDim = 3; + hasElement[ EDGE ] = shapeDim > 0 && myMesh->NbEdges(); + hasElement[ FACE ] = shapeDim > 1 && myMesh->NbFaces(); + hasElement[ VOLUME ] = shapeDim > 2 && myMesh->NbVolumes(); + } myHasSolids = nbShapes[ TopAbs_SOLID ]; } - // disable inexistant elem types + // disable inexistent elem types for ( int i = 0; i < myDlg->myElemTypeGroup->buttons().count(); ++i ) { if ( QAbstractButton* button = myDlg->myElemTypeGroup->button( i ) ) button->setEnabled( hasElement[ i ] ); @@ -305,85 +309,90 @@ void SMESHGUI_ShapeByMeshOp::commitOperation() try { QStringList aListId = myDlg->myElementId->text().split( " ", QString::SkipEmptyParts); if (aListId.count() == 1) + { + int elemID = (aListId.first()).toInt(); + // GEOM_Object is published -> no need to UnRegister() + myGeomObj = GEOM::GEOM_Object::_duplicate + (SMESHGUI::GetSMESHGen()->GetGeometryByMeshElement + ( myMesh.in(), elemID, myDlg->myGeomName->text().toUtf8().constData()) ); + } + else + { + GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen(); + + if (geomGen->_is_nil()) + return; + + GEOM::GEOM_IShapesOperations_wrap aShapesOp = + geomGen->GetIShapesOperations(); + if (aShapesOp->_is_nil() ) + return; + + TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE; + + std::map aGeomObjectsMap; + GEOM::GEOM_Object_wrap aGeomObject; + + GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh(); + + for ( int i = 0; i < aListId.count(); i++ ) { - int elemID = (aListId.first()).toInt(); - myGeomObj = GEOM::GEOM_Object::_duplicate( - SMESHGUI::GetSMESHGen()->GetGeometryByMeshElement - ( myMesh.in(), elemID, myDlg->myGeomName->text().toLatin1().constData()) ); + aGeomObject = // received object need UnRegister()! + SMESHGUI::GetSMESHGen()->FindGeometryByMeshElement(myMesh.in(), aListId[i].toInt()); + + if (aGeomObject->_is_nil()) continue; + + int anId = aShapesOp->GetSubShapeIndex(aMeshShape, aGeomObject); + if (aShapesOp->IsDone() && !aGeomObjectsMap.count(anId) ) + { + aGeomObjectsMap[anId] = aGeomObject; + + TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aGeomObject->GetShapeType(); + if (i == 0) + aGroupType = aSubShapeType; + else if (aSubShapeType != aGroupType) + aGroupType = TopAbs_SHAPE; + } } - else + + int aNumberOfGO = aGeomObjectsMap.size(); + if (aNumberOfGO == 1) { - GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen(); - _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - - if (geomGen->_is_nil() || !aStudy) - return; - - GEOM::GEOM_IShapesOperations_var aShapesOp = - geomGen->GetIShapesOperations(aStudy->StudyId()); - if (aShapesOp->_is_nil() ) - return; - - TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE; - - std::map aGeomObjectsMap; - GEOM::GEOM_Object_var aGeomObject; - - GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh(); - - for ( int i = 0; i < aListId.count(); i++ ) - { - aGeomObject = - SMESHGUI::GetSMESHGen()->FindGeometryByMeshElement(myMesh.in(), aListId[i].toInt()); - - if (aGeomObject->_is_nil()) continue; - - double anId = aShapesOp->GetSubShapeIndex(aMeshShape, aGeomObject); - if (aShapesOp->IsDone() && aGeomObjectsMap.find(anId) == aGeomObjectsMap.end()) - { - aGeomObjectsMap[anId] = aGeomObject; - - TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aGeomObject->GetShapeType(); - if (i == 0) - aGroupType = aSubShapeType; - else if (aSubShapeType != aGroupType) - aGroupType = TopAbs_SHAPE; - } - } - - int aNumberOfGO = aGeomObjectsMap.size(); - if (aNumberOfGO == 1) - myGeomObj = (*aGeomObjectsMap.begin()).second; - else if (aNumberOfGO > 1) - { - GEOM::GEOM_IGroupOperations_var aGroupOp = - geomGen->GetIGroupOperations(aStudy->StudyId()); - if(aGroupOp->_is_nil()) - return; - - GEOM::ListOfGO_var aGeomObjects = new GEOM::ListOfGO(); - aGeomObjects->length( aNumberOfGO ); - - int i = 0; - std::map::iterator anIter; - for (anIter = aGeomObjectsMap.begin(); anIter!=aGeomObjectsMap.end(); anIter++) - aGeomObjects[i++] = (*anIter).second; - - //create geometry group - myGeomObj = aGroupOp->CreateGroup(aMeshShape, aGroupType); - aGroupOp->UnionList(myGeomObj, aGeomObjects); - - if (!aGroupOp->IsDone()) - return; - } - - // publish the GEOM object in study - QString aNewGeomGroupName ( myDlg->myGeomName->text() ); - - SALOMEDS::SObject_var aNewGroupSO = - geomGen->AddInStudy(SMESHGUI::GetSMESHGen()->GetCurrentStudy(), myGeomObj, - aNewGeomGroupName.toLatin1().data(), aMeshShape); + aGeomObject = (*aGeomObjectsMap.begin()).second; } + else if (aNumberOfGO > 1) + { + GEOM::GEOM_IGroupOperations_wrap aGroupOp = + geomGen->GetIGroupOperations(); + if(aGroupOp->_is_nil()) + return; + + GEOM::ListOfGO_var aGeomObjects = new GEOM::ListOfGO(); + aGeomObjects->length( aNumberOfGO ); + + int i = 0; + std::map::iterator anIter; + for (anIter = aGeomObjectsMap.begin(); anIter!=aGeomObjectsMap.end(); anIter++) + aGeomObjects[i++] = GEOM::GEOM_Object::_duplicate( (*anIter).second.in() ); + + //create geometry group + aGeomObject = aGroupOp->CreateGroup(aMeshShape, aGroupType); + aGroupOp->UnionList(aGeomObject, aGeomObjects); + + if (!aGroupOp->IsDone()) + return; + } + + // publish the GEOM object in study + QString aNewGeomGroupName ( myDlg->myGeomName->text() ); + SALOMEDS::SObject_wrap aNewGroupSO = + geomGen->AddInStudy( aGeomObject, + aNewGeomGroupName.toUtf8().data(), aMeshShape); + + // get a GEOM_Object already published, which doesn't need UnRegister() + CORBA::Object_var obj = aNewGroupSO->GetObject(); + myGeomObj = GEOM::GEOM_Object::_narrow( obj ); + } } catch (const SALOME::SALOME_Exception& S_ex) { SalomeApp_Tools::QtCatchCorbaException(S_ex); @@ -409,7 +418,7 @@ void SMESHGUI_ShapeByMeshOp::onSelectionDone() try { SALOME_ListIO aList; - selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type()); + selectionMgr()->selectedObjects(aList); if (!myIsMultipleAllowed && aList.Extent() != 1) return; @@ -422,7 +431,7 @@ void SMESHGUI_ShapeByMeshOp::onSelectionDone() aList.First(), aString); if (nbElems > 0) { if (!myIsMultipleAllowed && nbElems != 1 ) - return; + return; setElementID( aString ); myDlg->setButtonEnabled( true, QtxDialog::OK ); } @@ -485,31 +494,31 @@ void SMESHGUI_ShapeByMeshOp::onElemIdChanged(const QString& theNewText) { if ( SMDS_Mesh* aMesh = actor->GetObject()->GetMesh() ) { - SMDSAbs_ElementType type = SMDSAbs_Edge; - switch ( myDlg->myElemTypeGroup->checkedId() ) { - case EDGE : type = SMDSAbs_Edge; break; - case FACE : type = SMDSAbs_Face; break; - case VOLUME: type = SMDSAbs_Volume; break; - default: return; - } - TColStd_MapOfInteger newIndices; - QStringList aListId = theNewText.split( " ", QString::SkipEmptyParts); - for ( int i = 0; i < aListId.count(); i++ ) { - if ( const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() )) - if ( e->GetType() == type ) - newIndices.Add( e->GetID() ); - } - - if ( !newIndices.IsEmpty() ) - { - if (!myIsMultipleAllowed && newIndices.Extent() != 1) - return; - if ( SVTK_Selector* s = selector() ) { - s->AddOrRemoveIndex( actor->getIO(), newIndices, false ); - viewWindow()->highlight( actor->getIO(), true, true ); - myDlg->setButtonEnabled( true, QtxDialog::OK ); - } - } + SMDSAbs_ElementType type = SMDSAbs_Edge; + switch ( myDlg->myElemTypeGroup->checkedId() ) { + case EDGE : type = SMDSAbs_Edge; break; + case FACE : type = SMDSAbs_Face; break; + case VOLUME: type = SMDSAbs_Volume; break; + default: return; + } + TColStd_MapOfInteger newIndices; + QStringList aListId = theNewText.split( " ", QString::SkipEmptyParts); + for ( int i = 0; i < aListId.count(); i++ ) { + if ( const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() )) + if ( e->GetType() == type ) + newIndices.Add( e->GetID() ); + } + + if ( !newIndices.IsEmpty() ) + { + if (!myIsMultipleAllowed && newIndices.Extent() != 1) + return; + if ( SVTK_Selector* s = selector() ) { + s->AddOrRemoveIndex( actor->getIO(), newIndices, false ); + viewWindow()->highlight( actor->getIO(), true, true ); + myDlg->setButtonEnabled( true, QtxDialog::OK ); + } + } } } }