From: eap Date: Tue, 21 May 2013 09:07:16 +0000 (+0000) Subject: 0022107: EDF 2502 SMESH: Publish the result of show bad mesh in a group X-Git-Tag: V7_3_0a1~432 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=af65a4c6c953761545bd9d61f8f320ee74bc8ce0;p=modules%2Fsmesh.git 0022107: EDF 2502 SMESH: Publish the result of show bad mesh in a group + // Create groups of elements preventing computation of a sub-shape + SMESH::ListOfGroups* MakeGroupsOfBadInputElements( int theSubShapeID, + const char* theGroupName) + throw (SALOME::SALOME_Exception); --- diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 4c48e31e1..12f82ab43 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -4147,6 +4147,94 @@ SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id) return aResult._retn(); } +//================================================================================ +/*! + * \brief Create a group of elements preventing computation of a sub-shape + */ +//================================================================================ + +SMESH::ListOfGroups* +SMESH_Mesh_i::MakeGroupsOfBadInputElements( int theSubShapeID, + const char* theGroupName ) + throw ( SALOME::SALOME_Exception ) +{ + Unexpect aCatch(SALOME_SalomeException); + + if ( !theGroupName || strlen( theGroupName) == 0 ) + THROW_SALOME_CORBA_EXCEPTION( "empty group name",SALOME::BAD_PARAM ); + + SMESH::ListOfGroups_var groups = new SMESH::ListOfGroups; + + // submesh by subshape id + if ( !_impl->HasShapeToMesh() ) theSubShapeID = 1; + if ( SMESH_subMesh * sm = _impl->GetSubMeshContaining( theSubShapeID )) + { + // compute error + SMESH_ComputeErrorPtr error = sm->GetComputeError(); + if ( error && !error->myBadElements.empty()) + { + // sort bad elements by type + vector< const SMDS_MeshElement* > elemsByType[ SMDSAbs_NbElementTypes ]; + list::iterator elemIt = error->myBadElements.begin(); + list::iterator elemEnd = error->myBadElements.end(); + for ( ; elemIt != elemEnd; ++elemIt ) + { + const SMDS_MeshElement* elem = *elemIt; + if ( !elem ) continue; + + if ( elem->GetID() < 1 ) + { + // elem is a temporary element, make a real element + vector< const SMDS_MeshNode* > nodes; + SMDS_NodeIteratorPtr nIt = elem->nodeIterator(); + while ( nIt->more() && elem ) + { + nodes.push_back( nIt->next() ); + if ( nodes.back()->GetID() < 1 ) + elem = 0; // a temporary element on temporary nodes + } + if ( elem ) + { + ::SMESH_MeshEditor editor( _impl ); + elem = editor.AddElement( nodes, elem->GetType(), elem->IsPoly() ); + } + } + if ( elem ) + elemsByType[ elem->GetType() ].push_back( elem ); + } + + // how many groups to create? + int nbTypes = 0; + for ( int i = 0; i < SMDSAbs_NbElementTypes; ++i ) + nbTypes += int( !elemsByType[ i ].empty() ); + groups->length( nbTypes ); + + // create groups + for ( int i = 0, iG = -1; i < SMDSAbs_NbElementTypes; ++i ) + { + vector< const SMDS_MeshElement* >& elems = elemsByType[ i ]; + if ( elems.empty() ) continue; + + groups[ ++iG ] = createGroup( SMESH::ElementType(i), theGroupName ); + if ( _gen_i->CanPublishInStudy( groups[ iG ] )) + { + SALOMEDS::SObject_wrap aSO = + _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(), groups[ iG ], + GEOM::GEOM_Object::_nil(), theGroupName); + aSO->_is_nil(); // avoid "unused variable" warning + } + SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( groups[ iG ]); + if ( !grp_i ) continue; + + if ( SMESHDS_Group* grpDS = dynamic_cast< SMESHDS_Group* >( grp_i->GetGroupDS() )) + for ( size_t iE = 0; iE < elems.size(); ++iE ) + grpDS->SMDSGroup().Add( elems[ iE ]); + } + } + } + + return groups._retn(); +} //============================================================================= /*! diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 6bb0a59b4..f9df1792b 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -63,6 +63,7 @@ public: virtual ~SMESH_Mesh_i(); // --- CORBA + void SetShape( GEOM::GEOM_Object_ptr theShapeObject ) throw (SALOME::SALOME_Exception); @@ -182,6 +183,7 @@ public: CORBA::Long GetStudyId() throw (SALOME::SALOME_Exception); // --- C++ interface + void SetImpl(::SMESH_Mesh* impl); ::SMESH_Mesh& GetImpl(); // :: force no namespace here @@ -388,6 +390,11 @@ public: char* Dump(); + // Create groups of elements preventing computation of a sub-shape + SMESH::ListOfGroups* MakeGroupsOfBadInputElements( int theSubShapeID, + const char* theGroupName) + throw (SALOME::SALOME_Exception); + // Internal methods not available through CORBA // They are called by corresponding interface methods SMESH_Hypothesis::Hypothesis_Status addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject, @@ -419,7 +426,7 @@ public: // return an existing subMesh object for the shapeID. shapeID == submeshID. const std::map& getGroups() { return _mapGroups; } - // return an existing group object. + // return existing group objects void onHypothesisModified(); // callback from _impl to forget not loaded mesh data (issue 0021208)