IMP PAL13422: EDF291: define a submesh with more than one entities. Create a group from all selected subshapes and then define a submesh on this group.

This commit is contained in:
jfa 2006-11-01 08:15:13 +00:00
parent c73213143d
commit b4b28c38b9

View File

@ -294,42 +294,49 @@ bool SMESHGUI_MeshOp::isSubshapeOk() const
if ( !myToCreate || myIsMesh ) // not submesh creation if ( !myToCreate || myIsMesh ) // not submesh creation
return false; return false;
// mesh
QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ); QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
_PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() ); _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() ); if (!pMesh) return false;
if ( pMesh && pGeom ) {
SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh ); SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
if ( !mesh->_is_nil() ) { if (mesh->_is_nil()) return false;
GEOM::GEOM_Object_var mainGeom, subGeom;
mainGeom = mesh->GetShapeToMesh(); // main shape of the mesh
subGeom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom ); GEOM::GEOM_Object_var mainGeom = mesh->GetShapeToMesh();
if ( !mainGeom->_is_nil() && !subGeom->_is_nil() ) { if (mainGeom->_is_nil()) return false;
TopoDS_Shape mainShape, subShape;
if ( GEOMBase::GetShape( mainGeom, mainShape ) && // geometry
GEOMBase::GetShape( subGeom, subShape ) ) QStringList aGEOMs;
{ myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
int index = GEOMBase::GetIndex( subShape, mainShape, 0 );
if ( index > 0 ) { if (aGEOMs.count() > 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(); GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
if ( !geomGen->_is_nil() && aStudy ) { if (geomGen->_is_nil() || !aStudy) return false;
GEOM::GEOM_IGroupOperations_var op = GEOM::GEOM_IGroupOperations_var op =
geomGen->GetIGroupOperations(aStudy->StudyId()); geomGen->GetIGroupOperations(aStudy->StudyId());
if ( ! op->_is_nil() ) { if (op->_is_nil()) return false;
GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom );
if ( !mainObj->_is_nil() ) // check all selected shapes
return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() )); QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
} for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++) {
} QString aSubGeomEntry = (*aSubShapesIter);
} _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
} if (!pSubGeom) return false;
GEOM::GEOM_Object_var aSubGeomVar =
GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
if (aSubGeomVar->_is_nil()) return false;
GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar);
if (mainObj->_is_nil() ||
string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false;
} }
return true;
} }
return false; return false;
} }
@ -404,26 +411,44 @@ void SMESHGUI_MeshOp::selectionDone()
int shapeDim = 3; int shapeDim = 3;
GEOM::GEOM_Object_var aGeomVar; QStringList aGEOMs;
QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom ); myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() ); GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
if ( pGeom ) {
aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() ); if (aGEOMs.count() > 0) {
// one or more GEOM shape selected
aSeq->length(aGEOMs.count());
QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
int iSubSh = 0;
for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
QString aSubGeomEntry = (*aSubShapesIter);
_PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
GEOM::GEOM_Object_var aSubGeomVar =
GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
aSeq[iSubSh] = aSubGeomVar;
} }
else { } else {
// get geometry by selected sub-mesh
QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ); QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
_PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() ); _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj ); GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
}
if (!aGeomVar->_is_nil()) { if (!aGeomVar->_is_nil()) {
aSeq->length(1);
aSeq[0] = aGeomVar;
}
}
if (aSeq->length() > 0) {
shapeDim = 0; shapeDim = 0;
for (int iss = 0; iss < aSeq->length() && shapeDim < 3; iss++) {
GEOM::GEOM_Object_var aGeomVar = aSeq[iss];
switch ( aGeomVar->GetShapeType() ) { switch ( aGeomVar->GetShapeType() ) {
case GEOM::SOLID: case GEOM::SOLID:
case GEOM::SHELL: shapeDim = 3; break; case GEOM::SHELL: shapeDim = 3; break;
case GEOM::FACE: shapeDim = 2; break; case GEOM::FACE: shapeDim = (shapeDim < 2) ? 2 : shapeDim; break;
case GEOM::WIRE: case GEOM::WIRE:
case GEOM::EDGE: shapeDim = 1; break; case GEOM::EDGE: shapeDim = (shapeDim < 1) ? 1 : shapeDim; break;
case GEOM::VERTEX: shapeDim = 0; break; case GEOM::VERTEX: break;
default: default:
TopoDS_Shape aShape; TopoDS_Shape aShape;
if ( GEOMBase::GetShape(aGeomVar, aShape)) { if ( GEOMBase::GetShape(aGeomVar, aShape)) {
@ -431,11 +456,12 @@ void SMESHGUI_MeshOp::selectionDone()
if ( exp.More() ) if ( exp.More() )
shapeDim = 3; shapeDim = 3;
else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() ) else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
shapeDim = 2; shapeDim = (shapeDim < 2) ? 2 : shapeDim;
else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() ) else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
shapeDim = 1; shapeDim = (shapeDim < 1) ? 1 : shapeDim;
else else
shapeDim = 0; ;//shapeDim = 0;
}
} }
} }
} }
@ -1247,17 +1273,80 @@ bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
_PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() ); _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() );
SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh_var aMeshVar =
SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() ); SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
if (aMeshVar->_is_nil())
return false;
// GEOM shape of the main mesh
GEOM::GEOM_Object_var mainGeom = aMeshVar->GetShapeToMesh();
// Name for the new sub-mesh
QString aName = myDlg->objectText(SMESHGUI_MeshDlg::Obj);
// get geom object // get geom object
QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom ); GEOM::GEOM_Object_var aGeomVar;
QStringList aGEOMs;
myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
if (aGEOMs.count() == 1)
{
//QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
QString aGeomEntry = aGEOMs.first();
_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() ); _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
GEOM::GEOM_Object_var aGeomVar = aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() ); }
else if (aGEOMs.count() > 1)
{
// create a GEOM 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()) {
// check and add all selected GEOM objects: they must be
// a sub-shapes of the main GEOM and must be of one type
int iSubSh = 0;
TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
aSeq->length(aGEOMs.count());
QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
for (; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
QString aSubGeomEntry = (*aSubShapesIter);
_PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.latin1());
GEOM::GEOM_Object_var aSubGeomVar =
GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aSubGeomVar->GetShapeType();
if (iSubSh == 0) {
aGroupType = aSubShapeType;
} else {
if (aSubShapeType != aGroupType)
aGroupType = TopAbs_SHAPE;
}
aSeq[iSubSh] = aSubGeomVar;
}
// create a group
GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType);
op->UnionList(aGroupVar, aSeq);
if (op->IsDone()) {
aGeomVar = aGroupVar;
// publish the GEOM group in study
QString aNewGeomGroupName ("Auto_group_for_");
aNewGeomGroupName += aName;
SALOMEDS::SObject_var aNewGroupSO =
geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar, aNewGeomGroupName, mainGeom);
}
}
}
}
else {
}
if (aGeomVar->_is_nil())
return false;
SUIT_OverrideCursor aWaitCursor; SUIT_OverrideCursor aWaitCursor;
// create sub-mesh // create sub-mesh
QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() ); SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.latin1() );
for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ ) for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )