+//================================================================================
+/*!
+ * \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;
+
+ // mesh
+ QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
+ _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().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 = SMESH::GetGEOMGen();
+ _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+ if (geomGen->_is_nil() || !aStudy) return false;
+
+ GEOM::GEOM_IGroupOperations_var op =
+ geomGen->GetIGroupOperations(aStudy->StudyId());
+ 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 = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().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);
+ //if (mainObj->_is_nil() ||
+ // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
+ while(1) {
+ if (mainObj->_is_nil())
+ return false;
+ if (string(mainObj->GetEntry()) == string(mainGeom->GetEntry()))
+ return true;
+ mainObj = op->GetMainShape(mainObj);
+ }
+ }
+ //return true;
+ }
+
+ 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.toLatin1().data() );
+ _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
+ 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::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::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)();
+}
+