+//================================================================================
+/*!
+ * \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 selected shape is a sub-shape of the shape to mesh
+ * \retval bool - check result
+ */
+//================================================================================
+bool SMESHGUI_MeshOp::isSubshapeOk() const
+{
+ if ( !myToCreate || myIsMesh ) // not submesh creation
+ return false;
+
+ // mesh
+ QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
+ _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
+ if (!pMesh) return false;
+
+ SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
+ if (mesh->_is_nil()) return false;
+
+ // main shape of the mesh
+ GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
+ if (mainGeom->_is_nil()) return false;
+
+ // geometry
+ QStringList aGEOMs;
+ myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
+
+ if (aGEOMs.count() > 0) {
+ 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;
+
+ // check all selected shapes
+ QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
+ for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++)
+ {
+ QString aSubGeomEntry = (*aSubShapesIter);
+ _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
+ if (!pSubGeom) return false;
+
+ GEOM::GEOM_Object_var aSubGeomVar =
+ GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
+ if (aSubGeomVar->_is_nil()) return false;
+
+ // skl for NPAL14695 - implementation of searching of mainObj
+ GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _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 ( aSubGeomVar->GetShapeType() == GEOM::COMPOUND )
+ {
+ // is aSubGeomVar a compound of sub-shapes?
+ GEOM::GEOM_IShapesOperations_wrap sop = geomGen->GetIShapesOperations();
+ if (sop->_is_nil()) return false;
+ GEOM::ListOfLong_var ids = sop->GetAllSubShapesIDs( aSubGeomVar,
+ GEOM::SHAPE,/*sorted=*/false);
+ if ( ids->length() > 0 )
+ {
+ GEOM_Client geomClient;
+ TopoDS_Shape subShape = geomClient.GetShape( geomGen, aSubGeomVar );
+ 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;
+}
+
+//================================================================================
+/*!
+ * \brief Return name of the algorithm that does not support sub-meshes and makes
+ * sub-mesh creation useless
+ * \retval char* - string is to be deleted!!!
+ */
+//================================================================================
+char* SMESHGUI_MeshOp::isSubmeshIgnored() const
+{
+ if ( myToCreate && !myIsMesh ) {
+
+ QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
+ QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+ _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
+ if ( pMesh ) {
+
+ QStringList algoNames;
+ THypList algoList;
+ existingHyps(3, Algo, pMesh, algoNames, algoList);
+ if (!algoList.empty()) {
+ HypothesisData* algo =
+ SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
+ if ( algo &&
+ algo->InputTypes.empty() && // builds all dimensions it-self
+ !algo->IsSupportSubmeshes )
+ return CORBA::string_dup( algoNames[0].toUtf8().data() );
+ }
+
+// GEOM::GEOM_Object_var geom;
+// if (_PTR(SObject) pGeom = SMESH::getStudy()->FindObjectID( aGeomEntry.toUtf8().data() ))
+// geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
+
+// 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( SMESH::toQStr( algoList[0].first->GetName() ));
+ if ( algo &&
+ algo->InputTypes.empty() && // builds all dimensions it-self
+ !algo->IsSupportSubmeshes )
+ return CORBA::string_dup( algoNames[0].toUtf8().data() );
+ }
+ // }
+ }
+ }
+ return 0;
+}
+
+//================================================================================
+/*!
+ * \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 );
+ _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( aMeshEntry.toUtf8().data() );
+ if ( pMesh && !myGeom->_is_nil() ) {
+ int tag = -1;
+ switch ( myGeom->GetShapeType() ) {
+ case GEOM::VERTEX: tag = SMESH::Tag_SubMeshOnVertex; break;
+ case GEOM::EDGE: tag = SMESH::Tag_SubMeshOnEdge; break;
+ case GEOM::WIRE: tag = SMESH::Tag_SubMeshOnWire; break;
+ case GEOM::FACE: tag = SMESH::Tag_SubMeshOnFace; break;
+ case GEOM::SHELL: tag = SMESH::Tag_SubMeshOnShell; break;
+ case GEOM::SOLID: tag = SMESH::Tag_SubMeshOnSolid; break;
+ case GEOM::COMPOUND: tag = SMESH::Tag_SubMeshOnCompound; break;
+ default:;
+ }
+ _PTR(GenericAttribute) anAttr;
+ _PTR(SObject) aSubmeshRoot;
+ _PTR(Study) aStudy = SMESH::getStudy();
+ 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 ) &&
+ myGeomEntry == pGeom2->GetID().c_str() )
+ return aSmObj;
+ }
+ }
+ }
+ }
+ return _PTR(SObject)();
+}
+