From 3eb21ad301385822cfbaa81f2ed6fbfd7bacf23b Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 25 Jul 2014 18:06:05 +0400 Subject: [PATCH] IPAL52460: Optimal Axes button is inert when edit body fitting parameters --- idl/SMESH_Gen.idl | 29 ++- src/SMESHGUI/SMESHGUI.cxx | 26 ++- src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx | 85 ++++++++ src/SMESHGUI/SMESHGUI_GEOMGenUtils.h | 5 + src/SMESHGUI/SMESHGUI_MeshOp.cxx | 201 ++++++++---------- src/SMESHGUI/SMESHGUI_MeshOp.h | 2 + src/SMESHGUI/SMESHGUI_Utils.h | 24 +++ src/SMESH_I/SMESH_Gen_i.cxx | 120 ++++++++++- src/SMESH_I/SMESH_Gen_i.hxx | 7 + .../StdMeshersGUI_StdHypothesisCreator.cxx | 23 +- .../StdMeshersGUI_SubShapeSelectorWdg.cxx | 71 +++++-- .../StdMeshersGUI_SubShapeSelectorWdg.h | 5 +- src/StdMeshersGUI/StdMeshers_msg_en.ts | 16 ++ 13 files changed, 455 insertions(+), 159 deletions(-) diff --git a/idl/SMESH_Gen.idl b/idl/SMESH_Gen.idl index c987a0770..cb625d0b9 100644 --- a/idl/SMESH_Gen.idl +++ b/idl/SMESH_Gen.idl @@ -173,6 +173,17 @@ module SMESH in boolean byMesh) raises ( SALOME::SALOME_Exception ); + /*! + * Returns \c True if a hypothesis is assigned to a sole sub-mesh in a current Study + * \param [in] theHyp - the hypothesis of interest + * \param [out] theMesh - the sole mesh using \a theHyp + * \param [out] theShape - the sole geometry \a theHyp is assigned to + * \return boolean - \c True if \a theMesh and \a theShape are sole using \a theHyp + */ + boolean GetSoleSubMeshUsingHyp( in SMESH_Hypothesis theHyp, + out SMESH_Mesh theMesh, + out GEOM::GEOM_Object theShape); + /*! * Sets number of segments per diagonal of boundary box of geometry by which * default segment length of appropriate 1D hypotheses is defined @@ -407,18 +418,22 @@ module SMESH /*! * \brief Moves objects to the specified position + * \param what objects being moved + * \param where parent object where objects are moved to + * \param row position in the parent object's children list at which objects are moved * * This function is used in the drag-n-drop functionality. - * - * \param what objects being moved - * \param where parent object where objects are moved to - * \param row position in the parent object's children list at which objects are moved */ - void Move( in sobject_list what, - in SALOMEDS::SObject where, + void Move( in sobject_list what, + in SALOMEDS::SObject where, in long row ); /*! - * Return true if algorithm can be applied + * Returns true if algorithm can be used to mesh a given geometry + * \param theAlgoType - the algorithm type + * \param theLibName - a name of the Plug-in library implementing the algorithm + * \param theShapeObject - the geometry to mesh + * \param toCheckAll - if \c True, returns \c True if all shapes are meshable, + * else, returns \c True if at least one shape is meshable */ boolean IsApplicable( in string theAlgoType, in string theLibName, diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index bc593e2ff..71ccf611d 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -83,6 +83,7 @@ #include "SMESHGUI_TransparencyDlg.h" #include "SMESHGUI_FilterUtils.h" +#include "SMESHGUI_GEOMGenUtils.h" #include "SMESHGUI_GroupUtils.h" #include "SMESHGUI_HypothesesUtils.h" #include "SMESHGUI_MeshUtils.h" @@ -3093,15 +3094,26 @@ bool SMESHGUI::OnGUIEvent( int theCommandID ) Handle(SALOME_InteractiveObject) anIObject = selected.First(); SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface(anIObject); - /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */ - /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects */ - /* Warning : however by internal mechanism all subMeshes icons are changed ! */ if ( !aHypothesis->_is_nil() ) { - // BUG 0020378 - //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName()); - SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName()); - if (aCreator) { + SMESHGUI_GenericHypothesisCreator* aCreator = + SMESH::GetHypothesisCreator( SMESH::toQStr( aHypothesis->GetName() )); + if (aCreator) + { + // set geometry of mesh and sub-mesh to aCreator + aSel->selectedObjects( selected, "", /*convertReferences=*/false); + if ( selected.Extent() == 1 ) + { + QString subGeomID, meshGeomID; + Handle(SALOME_InteractiveObject) hypIO = selected.First(); + if ( SMESH::GetGeomEntries( hypIO, subGeomID, meshGeomID )) + { + if ( subGeomID.isEmpty() ) subGeomID = meshGeomID; + aCreator->setShapeEntry( subGeomID ); + aCreator->setMainShapeEntry( meshGeomID ); + } + } + aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) ); } else diff --git a/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx b/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx index 8c2fa06ef..88b181944 100644 --- a/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx @@ -27,6 +27,7 @@ // #include "SMESHGUI_GEOMGenUtils.h" #include "SMESHGUI_Utils.h" +#include "SMESHGUI.h" // SALOME GEOM includes #include @@ -39,6 +40,8 @@ #include #include CORBA_CLIENT_HEADER(SMESH_Mesh) +#include + namespace SMESH { GEOM::GEOM_Gen_var GetGEOMGen() @@ -156,4 +159,86 @@ namespace SMESH GEOM::GEOM_Object_wrap subShape = aShapesOp->GetSubShape (theMainShape,theID); return subShape._retn(); } + + //================================================================================ + /*! + * \brief Return entries of sub-mesh geometry and mesh geometry by an IO of assigned + * hypothesis + * \param [in] hypIO - IO of hyp which is a reference SO to a hyp SO + * \param [out] subGeom - found entry of a sub-mesh if any + * \param [out] meshGeom - found entry of a mesh + * \return bool - \c true if any geometry has been found + */ + //================================================================================ + + bool GetGeomEntries( Handle(SALOME_InteractiveObject)& hypIO, + QString& subGeom, + QString& meshGeom ) + { + subGeom.clear(); + meshGeom.clear(); + if ( hypIO.IsNull() ) return false; + + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + if ( !aStudy ) return false; + + _PTR(SObject) hypSO = aStudy->FindObjectID( hypIO->getEntry() ); + if ( !hypSO ) return false; + + // Depth() is a number of fathers + if ( hypSO->Depth() == 4 ) // hypSO is not a reference to a hyp but a hyp it-self + { + SMESH::SMESH_Hypothesis_var hyp = + SMESH::SObjectToInterface< SMESH::SMESH_Hypothesis >( hypSO ); + SMESH::SMESH_Mesh_var mesh; + GEOM::GEOM_Object_var geom; + SMESH::SMESH_Gen_var gen = SMESHGUI::GetSMESHGUI()->GetSMESHGen(); + if ( !gen || !gen->GetSoleSubMeshUsingHyp( hyp, mesh.out(), geom.out() )) + return false; + + subGeom = toQStr( geom->GetStudyEntry() ); + + geom = mesh->GetShapeToMesh(); + if ( geom->_is_nil() ) + return false; + meshGeom = toQStr( geom->GetStudyEntry() ); + } + else + { + _PTR(SObject) appliedSO = hypSO->GetFather(); // "Applied hypotheses" folder + if ( !appliedSO ) return false; + + _PTR(SObject) subOrMeshSO = appliedSO->GetFather(); // mesh or sub-mesh SO + if ( !subOrMeshSO ) return false; + + bool isMesh; + GEOM::GEOM_Object_var geom = GetShapeOnMeshOrSubMesh( subOrMeshSO, &isMesh ); + if ( geom->_is_nil() ) + return false; + + if ( isMesh ) + { + meshGeom = toQStr( geom->GetStudyEntry() ); + return !meshGeom.isEmpty(); + } + + subGeom = toQStr( geom->GetStudyEntry() ); + + _PTR(SObject) subFolderSO = subOrMeshSO->GetFather(); // "SubMeshes on ..." folder + if ( !subFolderSO ) return false; + + _PTR(SObject) meshSO = subFolderSO->GetFather(); // mesh SO + if ( !meshSO ) return false; + + geom = GetShapeOnMeshOrSubMesh( meshSO ); + if ( geom->_is_nil() ) + return false; + + meshGeom = toQStr( geom->GetStudyEntry() ); + } + + return !meshGeom.isEmpty() && !subGeom.isEmpty(); + } + + } // end of namespace SMESH diff --git a/src/SMESHGUI/SMESHGUI_GEOMGenUtils.h b/src/SMESHGUI/SMESHGUI_GEOMGenUtils.h index 72fa9e6d3..f9cdeafd4 100644 --- a/src/SMESHGUI/SMESHGUI_GEOMGenUtils.h +++ b/src/SMESHGUI/SMESHGUI_GEOMGenUtils.h @@ -38,6 +38,8 @@ #include CORBA_SERVER_HEADER(GEOM_Gen) class SALOMEDSClient_SObject; +class Handle_SALOME_InteractiveObject; +class QString; namespace SMESH { @@ -50,6 +52,9 @@ namespace SMESH SMESHGUI_EXPORT char* GetGeomName( _PTR(SObject) smeshSO ); SMESHGUI_EXPORT GEOM::GEOM_Object_ptr GetSubShape( GEOM::GEOM_Object_ptr, long ); + + SMESHGUI_EXPORT bool GetGeomEntries( Handle_SALOME_InteractiveObject& hypIO, + QString& subGeom, QString& meshGeom); } #endif // SMESHGUI_GEOMGENUTILS_H diff --git a/src/SMESHGUI/SMESHGUI_MeshOp.cxx b/src/SMESHGUI/SMESHGUI_MeshOp.cxx index 8a3346e8f..de77540c6 100644 --- a/src/SMESHGUI/SMESHGUI_MeshOp.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshOp.cxx @@ -398,7 +398,8 @@ char* SMESHGUI_MeshOp::isSubmeshIgnored() const THypList algoList; existingHyps(3, Algo, pMesh, algoNames, algoList); if (!algoList.empty()) { - HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() ); + HypothesisData* algo = + SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() )); if ( algo && algo->InputTypes.empty() && // builds all dimensions it-self !algo->IsSupportSubmeshes ) @@ -412,7 +413,8 @@ char* SMESHGUI_MeshOp::isSubmeshIgnored() const // if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well existingHyps(2, Algo, pMesh, algoNames, algoList); if (!algoList.empty()) { - HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() ); + HypothesisData* algo = + SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() )); if ( algo && algo->InputTypes.empty() && // builds all dimensions it-self !algo->IsSupportSubmeshes ) @@ -1031,6 +1033,71 @@ SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType, return hyp; } +//================================================================================ +/*! + * \brief initialize a hypothesis creator + */ +//================================================================================ + +void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator ) +{ + if ( !theCreator ) return; + + // Set shapes, of mesh and sub-mesh if any + + // get Entry of the Geom object + QString aGeomEntry = ""; + QString aMeshEntry = ""; + QString anObjEntry = ""; + aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom ); + aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ); + anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ); + + if ( myToCreate && myIsMesh ) + aMeshEntry = aGeomEntry; + + if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited + _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() ); + GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj ); + aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() ); + } + + if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited + _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() ); + bool isMesh; + GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh ); + if ( !aGeomVar->_is_nil() ) + { + aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() ); + if ( isMesh ) + aMeshEntry = aGeomEntry; + } + } + + if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) { + // take geometry from submesh being created + _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() ); + if ( pObj ) { + // if current object is sub-mesh + SMESH::SMESH_subMesh_var aSubMeshVar = + SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() ); + if ( !aSubMeshVar->_is_nil() ) { + SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather(); + if ( !aMeshVar->_is_nil() ) { + _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar ); + GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO ); + if ( !aGeomVar->_is_nil() ) + aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() ); + } + } + } + } + + theCreator->setShapeEntry( aGeomEntry ); + if ( aMeshEntry != "" ) + theCreator->setMainShapeEntry( aMeshEntry ); +} + //================================================================================ /*! * \Brief Returns tab dimention @@ -1138,64 +1205,17 @@ void SMESHGUI_MeshOp::createHypothesis(const int theDim, SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName); // Create hypothesis - if (aCreator) { + if (aCreator) + { // Get parameters appropriate to initialize a new hypothesis SMESH::SMESH_Hypothesis_var initParamHyp = getInitParamsHypothesis(theTypeName, aData->ServerLibName); removeCustomFilters(); // Issue 0020170 - // Get Entry of the Geom object - QString aGeomEntry = ""; - QString aMeshEntry = ""; - QString anObjEntry = ""; - aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom ); - aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ); - anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ); + // set shapes, of mesh and sub-mesh if any + initHypCreator( aCreator ); - if ( myToCreate && myIsMesh ) - aMeshEntry = aGeomEntry; - - if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited - _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() ); - GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj ); - aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry(); - } - - if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited - _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() ); - bool isMesh; - GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh ); - if ( !aGeomVar->_is_nil() ) - { - aGeomEntry = aGeomVar->GetStudyEntry(); - if ( isMesh ) - aMeshEntry = aGeomEntry; - } - } - - if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) { - // take geometry from submesh being created - _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() ); - if ( pObj ) { - // if current object is sub-mesh - SMESH::SMESH_subMesh_var aSubMeshVar = - SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() ); - if ( !aSubMeshVar->_is_nil() ) { - SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather(); - if ( !aMeshVar->_is_nil() ) { - _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar ); - GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO ); - if ( !aGeomVar->_is_nil() ) - aMeshEntry = aGeomVar->GetStudyEntry(); - } - } - } - } - - aCreator->setShapeEntry( aGeomEntry ); - if ( aMeshEntry != "" ) - aCreator->setMainShapeEntry( aMeshEntry ); myDlg->setEnabled( false ); aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) ); dialog = true; @@ -1270,67 +1290,22 @@ void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex ) if ( aHyp->_is_nil() ) return; - SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName()); + SMESHGUI_GenericHypothesisCreator* aCreator = + SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() )); if ( aCreator ) { - // Get initial parameters + // set initial parameters SMESH::SMESH_Hypothesis_var initParamHyp = - getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName()); + getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ), + SMESH::toQStr( aHyp->GetLibName() )); aCreator->setInitParamsHypothesis( initParamHyp ); - // Get Entry of the Geom object - QString aGeomEntry = ""; - QString aMeshEntry = ""; - QString anObjEntry = ""; - aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom ); - aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ); - anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ); + // set shapes, of mesh and sub-mesh if any + initHypCreator( aCreator ); - if ( myToCreate && myIsMesh ) - aMeshEntry = aGeomEntry; - - if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited - _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() ); - GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj ); - aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry(); - } - - if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited - _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() ); - bool isMesh; - GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh ); - if ( !aGeomVar->_is_nil() ) - { - aGeomEntry = aGeomVar->GetStudyEntry(); - if ( isMesh ) - aMeshEntry = aGeomEntry; - } - } - - if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) { - // take geometry from submesh being created - _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() ); - if ( pObj ) { - // if current object is sub-mesh - SMESH::SMESH_subMesh_var aSubMeshVar = - SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() ); - if ( !aSubMeshVar->_is_nil() ) { - SMESH::SMESH_Mesh_var aMeshVar = aSubMeshVar->GetFather(); - if ( !aMeshVar->_is_nil() ) { - _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar ); - GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO ); - if ( !aGeomVar->_is_nil() ) - aMeshEntry = aGeomVar->GetStudyEntry(); - } - } - } - } - - aCreator->setShapeEntry( aGeomEntry ); - if ( aMeshEntry != "" ) - aCreator->setMainShapeEntry( aMeshEntry ); removeCustomFilters(); // Issue 0020170 myDlg->setEnabled( false ); + aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) ); } } @@ -1521,10 +1496,10 @@ void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex, if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected // try to find algo by selected hypothesis in order to keep it selected bool algoDeselectedByUser = ( theDim < 0 && aDim == dim ); - CORBA::String_var curHypType = curHyp->GetName(); + QString curHypType = SMESH::toQStr( curHyp->GetName() ); if ( !algoDeselectedByUser && - myObjHyps[ dim ][ type ].count() > 0 && - !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) ) + myObjHyps[ dim ][ type ].count() > 0 && + curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) ) { HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() ); for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) { @@ -1994,8 +1969,7 @@ SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim ) for ( ; anIter != aHypVarList.end(); anIter++) { SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first; - CORBA::String_var aName = aHypVar->GetName(); - if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) ) + if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() )) { anAlgoVar = aHypVar; break; @@ -2038,8 +2012,7 @@ SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim ) for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter ) { SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first; - CORBA::String_var aName = aHypVar->GetName(); - if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) ) + if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() )) { anAlgoVar = aHypVar; break; @@ -2430,7 +2403,7 @@ void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op) GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape(); if ( !aGeomVar->_is_nil() ) { - QString ID = aGeomVar->GetStudyEntry(); + QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() ); if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) { selectObject( aGeomSO ); selectionDone(); diff --git a/src/SMESHGUI/SMESHGUI_MeshOp.h b/src/SMESHGUI/SMESHGUI_MeshOp.h index fcaedabf3..8aa0fb9da 100644 --- a/src/SMESHGUI/SMESHGUI_MeshOp.h +++ b/src/SMESHGUI/SMESHGUI_MeshOp.h @@ -36,6 +36,7 @@ class HypothesesSet; class SMESHGUI_MeshDlg; class SMESHGUI_ShapeByMeshOp; class HypothesisData; +class SMESHGUI_GenericHypothesisCreator; /*! * \brief Operation for mech creation or editing @@ -126,6 +127,7 @@ private: const THypList& ) const; SMESH::SMESH_Hypothesis_var getInitParamsHypothesis( const QString&, const QString& ) const; + void initHypCreator( SMESHGUI_GenericHypothesisCreator* aCreator ); bool isSubshapeOk() const; char* isSubmeshIgnored() const; _PTR(SObject) getSubmeshByGeom() const; diff --git a/src/SMESHGUI/SMESHGUI_Utils.h b/src/SMESHGUI/SMESHGUI_Utils.h index 2cf9eaac2..d5ec25ed4 100644 --- a/src/SMESHGUI/SMESHGUI_Utils.h +++ b/src/SMESHGUI/SMESHGUI_Utils.h @@ -184,6 +184,30 @@ SMESHGUI_EXPORT // type to use instead of SMESH_IDSource_var for automatic UnRegister() typedef SALOME::GenericObj_wrap SMESH_IDSource_wrap; + /*! + * \brief Class usefull to convert a string returned from a CORBA call + * to other string types w/o memory leak. + * + * Usage (of instantiations): QString s = toQStr( objVar->GetName() ); + * std::string ss = toStdStr( objVar->GetName() ); + */ + template < class _STRING > + class toStrT : public _STRING { + CORBA::String_var myStr; + public: + toStrT( char* s ): myStr(s), _STRING( s ) + {} + operator const char*() const + { return myStr.in(); } + }; + // Instantiations: + struct toQStr : public toStrT< QString > { + toQStr( char* s ): toStrT< QString >(s) {} + }; + class toStdStr : public toStrT< std::string > { + toStdStr( char* s ): toStrT< std::string >(s) {} + }; + } #endif // SMESHGUI_UTILS_H diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 7d1dbf9c8..b822651b7 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -280,7 +280,7 @@ SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb, PortableServer::ObjectId* contId, const char* instanceName, const char* interfaceName ) - : Engines_Component_i( orb, poa, contId, instanceName, interfaceName ) + : Engines_Component_i( orb, poa, contId, instanceName, interfaceName ) { MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" ); @@ -472,7 +472,7 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName // create a new hypothesis object, store its ref. in studyContext if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName); myHypothesis_i = - myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen); + myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen); myHypothesis_i->SetLibName(aPlatformLibName.c_str()); // for persistency assurance if (!myHypothesis_i) @@ -495,7 +495,7 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName */ //============================================================================= SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh() - throw ( SALOME::SALOME_Exception ) + throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" ); @@ -673,7 +673,7 @@ SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy() StudyContext* SMESH_Gen_i::GetCurrentStudyContext() { if ( !CORBA::is_nil( myCurrentStudy ) && - myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() ) + myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() ) return myStudyContextMap[ myCurrentStudy->StudyId() ]; else return 0; @@ -689,7 +689,7 @@ StudyContext* SMESH_Gen_i::GetCurrentStudyContext() SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName, const char* theLibName ) - throw ( SALOME::SALOME_Exception ) + throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); // Create hypothesis/algorithm @@ -803,6 +803,97 @@ SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType, return SMESH::SMESH_Hypothesis::_nil(); } +//============================================================================= +/*! + * Returns \c True if a hypothesis is assigned to a sole sub-mesh in a current Study + * \param [in] theHyp - the hypothesis of interest + * \param [out] theMesh - the sole mesh using \a theHyp + * \param [out] theShape - the sole geometry \a theHyp is assigned to + * \return boolean - \c True if \a theMesh and \a theShape are sole using \a theHyp + * + * If two meshes on same shape have theHyp assigned to the same sub-shape, they are + * considered as SAME sub-mesh => result is \c true. + * This method ids used to initialize SMESHGUI_GenericHypothesisCreator with + * a shape to which an hyp being edited is assigned. + */ +//============================================================================= + +CORBA::Boolean SMESH_Gen_i::GetSoleSubMeshUsingHyp( SMESH::SMESH_Hypothesis_ptr theHyp, + SMESH::SMESH_Mesh_out theMesh, + GEOM::GEOM_Object_out theShape) +{ + if ( GetCurrentStudyID() < 0 || CORBA::is_nil( theHyp )) + return false; + + // get Mesh component SO + CORBA::String_var compDataType = ComponentDataType(); + SALOMEDS::SComponent_wrap comp = myCurrentStudy->FindComponent( compDataType.in() ); + if ( CORBA::is_nil( comp )) + return false; + + // look for child SO of meshes + SMESH::SMESH_Mesh_var foundMesh; + TopoDS_Shape foundShape; + bool isSole = true; + SALOMEDS::ChildIterator_wrap meshIter = myCurrentStudy->NewChildIterator( comp ); + for ( ; meshIter->More() && isSole; meshIter->Next() ) + { + SALOMEDS::SObject_wrap curSO = meshIter->Value(); + CORBA::Object_var obj = SObjectToObject( curSO ); + SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( obj ); + if ( ! mesh_i ) + continue; + + // look for a sole shape where theHyp is assigned + bool isHypFound = false; + const ShapeToHypothesis & s2hyps = mesh_i->GetImpl().GetMeshDS()->GetHypotheses(); + ShapeToHypothesis::Iterator s2hypsIt( s2hyps ); + for ( ; s2hypsIt.More() && isSole; s2hypsIt.Next() ) + { + const THypList& hyps = s2hypsIt.Value(); + THypList::const_iterator h = hyps.begin(); + for ( ; h != hyps.end(); ++h ) + if ( (*h)->GetID() == theHyp->GetId() ) + break; + if ( h != hyps.end()) // theHyp found + { + isHypFound = true; + if ( ! foundShape.IsNull() && + ! foundShape.IsSame( s2hypsIt.Key() )) // not a sole sub-shape + { + foundShape.Nullify(); + isSole = false; + break; + } + foundShape = s2hypsIt.Key(); + } + } // loop on assigned hyps + + if ( isHypFound && !foundShape.IsNull() ) // a mesh using theHyp is found + { + if ( !foundMesh->_is_nil() ) // not a sole mesh + { + GEOM::GEOM_Object_var s1 = mesh_i ->GetShapeToMesh(); + GEOM::GEOM_Object_var s2 = foundMesh->GetShapeToMesh(); + if ( ! ( isSole = s1->IsSame( s2 ))) + break; + } + foundMesh = SMESH::SMESH_Mesh::_narrow( obj ); + } + + } // loop on meshes + + if ( isSole && + ! foundMesh->_is_nil() && + ! foundShape.IsNull() ) + { + theMesh = foundMesh._retn(); + theShape = ShapeToGeomObject( foundShape ); + return ( !theMesh->_is_nil() && !theShape->_is_nil() ); + } + return false; +} + //============================================================================= /*! * Sets number of segments per diagonal of boundary box of geometry by which @@ -5062,10 +5153,18 @@ void SMESH_Gen_i::Move( const SMESH::sobject_list& what, useCaseBuilder->AppendTo( where, sobj ); // append to the end of list } } -//================================================================================= -// function : IsApplicable -// purpose : Return true if algorithm can be applied -//================================================================================= +//================================================================================ +/*! + * \brief Returns true if algorithm can be used to mesh a given geometry + * \param [in] theAlgoType - the algorithm type + * \param [in] theLibName - a name of the Plug-in library implementing the algorithm + * \param [in] theGeomObject - the geometry to mesh + * \param [in] toCheckAll - if \c True, returns \c True if all shapes are meshable, + * else, returns \c True if at least one shape is meshable + * \return CORBA::Boolean - can or can't + */ +//================================================================================ + CORBA::Boolean SMESH_Gen_i::IsApplicable ( const char* theAlgoType, const char* theLibName, GEOM::GEOM_Object_ptr theGeomObject, @@ -5075,7 +5174,8 @@ CORBA::Boolean SMESH_Gen_i::IsApplicable ( const char* theAlgoType, std::string aPlatformLibName; typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char*); - GenericHypothesisCreator_i* aCreator = getHypothesisCreator(theAlgoType, theLibName, aPlatformLibName); + GenericHypothesisCreator_i* aCreator = + getHypothesisCreator(theAlgoType, theLibName, aPlatformLibName); if (aCreator) { TopoDS_Shape shape = GeomObjectToShape( theGeomObject ); diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index 3405a8375..ba4ed98b5 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -205,6 +205,13 @@ public: CORBA::Boolean byMesh) throw ( SALOME::SALOME_Exception ); + /* + * Returns True if a hypothesis is assigned to a sole sub-mesh in a current Study + */ + CORBA::Boolean GetSoleSubMeshUsingHyp( SMESH::SMESH_Hypothesis_ptr theHyp, + SMESH::SMESH_Mesh_out theMesh, + GEOM::GEOM_Object_out theShape); + // Preferences // ------------ /*! diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx index 891b2c0c8..c481eea7e 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx @@ -47,6 +47,7 @@ // SALOME GUI includes #include +#include // IDL includes #include @@ -1265,8 +1266,15 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const idsWg->SetMainShapeEntry( aMainEntry ); idsWg->SetGeomShapeEntry( aSubEntry.isEmpty() ? aMainEntry : aSubEntry ); - idsWg->SetListOfIDs( h->GetFaces() ); - idsWg->showPreview( true ); + if ( idsWg->SetListOfIDs( h->GetFaces() )) + { + idsWg->showPreview( true ); + } + else + { + SUIT_MessageBox::warning( dlg(),tr( "SMESH_WRN_WARNING" ),tr( "BAD_FACES_WARNING" )); + idsWg->setEnabled( false ); + } customWidgets()->append ( idsWg ); } } @@ -1317,8 +1325,15 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const idsWg->SetMainShapeEntry( aMainEntry ); idsWg->SetGeomShapeEntry( aSubEntry.isEmpty() ? aMainEntry : aSubEntry ); - idsWg->SetListOfIDs( h->GetEdges() ); - idsWg->showPreview( true ); + if ( idsWg->SetListOfIDs( h->GetEdges() )) + { + idsWg->showPreview( true ); + } + else + { + SUIT_MessageBox::warning( dlg(),tr( "SMESH_WRN_WARNING" ),tr( "BAD_EDGES_WARNING" )); + idsWg->setEnabled( false ); + } customWidgets()->append ( idsWg ); } } diff --git a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx index 935df0cc3..9cd4ff727 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx @@ -515,9 +515,9 @@ SMESH::long_array_var StdMeshersGUI_SubShapeSelectorWdg::GetListOfIDs() //================================================================================= // function : SetListOfIds -// purpose : Called to set the list of SubShapes IDs +// purpose : Called to set the list of SubShapes IDs. Returns false if any ID is invalid //================================================================================= -void StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theIds) +bool StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theIds) { mySelectedIDs.clear(); myListOfIDs.clear(); @@ -525,8 +525,10 @@ void StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theI for ( int i = 0; i < size; i++ ) mySelectedIDs.append( theIds[ i ] ); - mySelectedIDs = GetCorrectedListOfIDs( false ); + bool isOk; + mySelectedIDs = GetCorrectedListOfIDs( false, &isOk ); onAdd(); + return isOk; } //================================================================================= @@ -556,35 +558,74 @@ const char* StdMeshersGUI_SubShapeSelectorWdg::GetMainShapeEntry() // function : GetCorrectedListOfIds // purpose : Called to convert the list of IDs from sub-shape IDs to main shape IDs //================================================================================= -QList StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSubshapeToMainshape ) +QList +StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSubshapeToMainshape, + bool* isOK ) { - if ( ( myMainShape.IsNull() || myGeomShape.IsNull() ) && fromSubshapeToMainshape ) + if (( myMainShape.IsNull() || myGeomShape.IsNull() ) && fromSubshapeToMainshape ) return myListOfIDs; - else if ( ( myMainShape.IsNull() || myGeomShape.IsNull() ) && !fromSubshapeToMainshape ) + else if (( myMainShape.IsNull() /*||*/&& myGeomShape.IsNull() ) && !fromSubshapeToMainshape ) return mySelectedIDs; + if ( !fromSubshapeToMainshape ) // called from SetListOfIDs + { + if ( myMainShape.IsNull() ) + std::swap( myMainShape, myGeomShape ); + } + QList aList; - TopTools_IndexedMapOfShape aGeomMap; - TopTools_IndexedMapOfShape aMainMap; - TopExp::MapShapes(myGeomShape, aGeomMap); + TopTools_IndexedMapOfShape aGeomMap, aMainMap; TopExp::MapShapes(myMainShape, aMainMap); + if ( !myGeomShape.IsNull() ) + TopExp::MapShapes(myGeomShape, aGeomMap); - if ( fromSubshapeToMainshape ) { // convert indexes from sub-shape to mainshape + bool ok = true; + if ( fromSubshapeToMainshape ) // convert indexes from sub-shape to mainshape + { int size = myListOfIDs.size(); for (int i = 0; i < size; i++) { - TopoDS_Shape aSubShape = aGeomMap.FindKey( myListOfIDs.at(i) ); - int index = aMainMap.FindIndex( aSubShape ); + int index = myListOfIDs.at(i); + if ( aGeomMap.Extent() < index ) + { + ok = false; + } + else + { + TopoDS_Shape aSubShape = aGeomMap.FindKey( index ); + if ( mySubShType != aSubShape.ShapeType() ) + ok = false; + if ( !aMainMap.Contains( aSubShape )) + ok = false; + else + index = aMainMap.FindIndex( aSubShape ); + } aList.append( index ); } myIsNotCorrected = false; - } else { // convert indexes from main shape to sub-shape + } + else // convert indexes from main shape to sub-shape, or just check indices + { int size = mySelectedIDs.size(); for (int i = 0; i < size; i++) { - TopoDS_Shape aSubShape = aMainMap.FindKey( mySelectedIDs.at(i) ); - int index = aGeomMap.FindIndex( aSubShape ); + int index = mySelectedIDs.at(i); + if ( aMainMap.Extent() < index ) + { + ok = false; + } + else + { + TopoDS_Shape aSubShape = aMainMap.FindKey( index ); + if ( mySubShType != aSubShape.ShapeType() ) + ok = false; + if ( !aGeomMap.Contains( aSubShape ) && !aGeomMap.IsEmpty() ) + ok = false; + else + index = aGeomMap.FindIndex( aSubShape ); + } aList.append( index ); } } + if ( isOK ) *isOK = ok; return aList; } diff --git a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.h b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.h index f8ea6e9e1..7793817be 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.h +++ b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.h @@ -58,7 +58,7 @@ public: ~StdMeshersGUI_SubShapeSelectorWdg(); SMESH::long_array_var GetListOfIDs(); - void SetListOfIDs( SMESH::long_array_var ); + bool SetListOfIDs( SMESH::long_array_var ); void SetGeomShapeEntry( const QString& theEntry ); const char* GetGeomShapeEntry() { return myEntry.toLatin1().data();} @@ -69,7 +69,8 @@ public: TopoDS_Shape GetGeomShape() { return myGeomShape; } TopoDS_Shape GetMainShape() { return myMainShape; } - QList GetCorrectedListOfIDs( bool fromSubshapeToMainshape = true ); + QList GetCorrectedListOfIDs( bool fromSubshapeToMainshape, + bool* isOK=0); static GEOM::GEOM_Object_var GetGeomObjectByEntry( const QString& ); static TopoDS_Shape GetTopoDSByEntry( const QString& ); diff --git a/src/StdMeshersGUI/StdMeshers_msg_en.ts b/src/StdMeshersGUI/StdMeshers_msg_en.ts index 08dcd5671..5e38ea864 100644 --- a/src/StdMeshersGUI/StdMeshers_msg_en.ts +++ b/src/StdMeshersGUI/StdMeshers_msg_en.ts @@ -27,6 +27,22 @@ TO_IGNORE_FACES Faces without layers (inlets and oulets) + + BAD_FACES_WARNING + +Specified faces are not sub-shapes of the shape of +mesh/sub-mesh. +Consider creating another hypothesis instead of using +this one for this mesh/sub-mesh. + + + BAD_EDGES_WARNING + +Specified edges are not sub-shapes of the shape of +mesh/sub-mesh. +Consider creating another hypothesis instead of using +this one for this mesh/sub-mesh. + @default -- 2.39.2