+//================================================================================
+/*!
+ * \brief check if selected shape is a subshape of the shape to mesh
+ * \retval bool - check result
+ */
+//================================================================================
+
+bool SMESHGUI_MeshOp::isSubshapeOk() const
+{
+ if ( !myToCreate || myIsMesh ) // not submesh creation
+ return false;
+
+ QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
+ QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+ _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
+ _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
+ if ( pMesh && pGeom ) {
+ SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
+ if ( !mesh->_is_nil() ) {
+ GEOM::GEOM_Object_var mainGeom, subGeom;
+ mainGeom = mesh->GetShapeToMesh();
+ subGeom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
+ if ( !mainGeom->_is_nil() && !subGeom->_is_nil() ) {
+ TopoDS_Shape mainShape, subShape;
+ if ( GEOMBase::GetShape( mainGeom, mainShape ) &&
+ GEOMBase::GetShape( subGeom, subShape ) )
+ {
+ int index = GEOMBase::GetIndex( subShape, mainShape, 0 );
+ if ( index > 0 ) {
+ // 1 is index of mainShape itself
+ return index > 1; // it is a subshape
+ }
+ // is it a group?
+ GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
+ _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+ if ( !geomGen->_is_nil() && aStudy ) {
+ GEOM::GEOM_IGroupOperations_var op =
+ geomGen->GetIGroupOperations( aStudy->StudyId() );
+ if ( ! op->_is_nil() ) {
+ GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom );
+ if ( !mainObj->_is_nil() )
+ return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() ));
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+}
+
+//================================================================================
+/*!
+ * \brief find an existing submesh by the selected shape
+ * \retval _PTR(SObject) - the found submesh SObject
+ */
+//================================================================================
+
+_PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const
+{
+ QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
+ QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+ _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
+ _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
+ if ( pMesh && pGeom ) {
+ GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
+ if ( !geom->_is_nil() ) {
+ int tag = -1;
+ switch ( geom->GetShapeType() ) {
+ case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break;
+ case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break;
+ case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break;
+ case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break;
+ case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break;
+ case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break;
+ default:;
+ }
+ _PTR(GenericAttribute) anAttr;
+ _PTR(SObject) aSubmeshRoot;
+ _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+ if ( pMesh->FindSubObject( tag, aSubmeshRoot ) )
+ {
+ _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
+ for (; smIter->More(); smIter->Next() )
+ {
+ _PTR(SObject) aSmObj = smIter->Value();
+ if ( ! aSmObj->FindAttribute( anAttr, "AttributeIOR" ))
+ continue;
+ _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj);
+ for (; anIter1->More(); anIter1->Next()) {
+ _PTR(SObject) pGeom2 = anIter1->Value();
+ if ( pGeom2->ReferencedObject( pGeom2 ) &&
+ pGeom2->GetID() == pGeom->GetID() )
+ return aSmObj;
+ }
+ }
+ }
+ }
+ }
+ return _PTR(SObject)();
+}
+