+
+ //================================================================================
+ /*!
+ * \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(SObject) hypSO = SMESH::getStudy()->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();
+ }
+
+
+ //================================================================================
+ /*!
+ * \brief Return type of shape contained in a group
+ */
+ //================================================================================
+
+ TopAbs_ShapeEnum _getGroupType(const TopoDS_Shape& group)
+ {
+ if ( group.ShapeType() != TopAbs_COMPOUND )
+ return group.ShapeType();
+
+ // iterate on a compound
+ TopoDS_Iterator it( group );
+ if ( it.More() )
+ return _getGroupType( it.Value() );
+
+ return TopAbs_SHAPE;
+ }
+
+
+ //================================================================================
+ /*!
+ * \brief Check if a subGeom contains sub-shapes of a mainGeom
+ */
+ //================================================================================
+
+ bool ContainsSubShape( GEOM::GEOM_Object_ptr mainGeom,
+ GEOM::GEOM_Object_ptr subGeom )
+ {
+ if ( CORBA::is_nil( mainGeom ) ||
+ CORBA::is_nil( subGeom ))
+ return false;
+
+ GEOM::GEOM_Gen_var geomGen = mainGeom->GetGen();
+ if ( geomGen->_is_nil() ) return false;
+
+ GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
+ if ( op->_is_nil() ) return false;
+
+ GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom ); /* _var not _wrap as
+ mainObj already exists! */
+ while ( !mainObj->_is_nil() )
+ {
+ CORBA::String_var entry1 = mainObj->GetEntry();
+ CORBA::String_var entry2 = mainGeom->GetEntry();
+ if ( std::string( entry1.in() ) == entry2.in() )
+ return true;
+ mainObj = op->GetMainShape( mainObj );
+ }
+ if ( subGeom->GetShapeType() == GEOM::COMPOUND )
+ {
+ // is subGeom a compound of sub-shapes?
+ GEOM::GEOM_IShapesOperations_wrap sop = geomGen->GetIShapesOperations();
+ if ( sop->_is_nil() ) return false;
+ GEOM::ListOfLong_var ids = sop->GetAllSubShapesIDs( subGeom,
+ GEOM::SHAPE,/*sorted=*/false);
+ if ( ids->length() > 0 )
+ {
+ GEOM_Client geomClient;
+ TopoDS_Shape subShape = geomClient.GetShape( geomGen, subGeom );
+ TopoDS_Shape mainShape = geomClient.GetShape( geomGen, mainGeom );
+ if ( subShape.IsNull() || mainShape.IsNull() )
+ return false;
+
+ TopAbs_ShapeEnum subType = _getGroupType( subShape );
+ TopTools_IndexedMapOfShape subMap;
+ TopExp::MapShapes( subShape, subType, subMap );
+ for ( TopExp_Explorer exp( mainShape, subType ); exp.More(); exp.Next() )
+ if ( subMap.Contains( exp.Current() ))
+ return true;
+
+ }
+ }
+ return false;
+ }
+