From 2e44c46e33cc0ccc3662fe33965ca70c3cfd66b6 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 28 Aug 2013 13:57:59 +0000 Subject: [PATCH] 22172: [CEA 790] create the groups corresponding to domains Now group creation depends only on SetToMakeGroupsOfDomains flag --- src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx | 123 +++++++++++-------- src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx | 6 +- src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx | 12 +- 3 files changed, 84 insertions(+), 57 deletions(-) diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index e27c5b9..0ff403a 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -1079,7 +1079,7 @@ static void removeEmptyGroupsOfDomains(SMESH_Mesh* mesh, // check the name if ( strncmp( name, refName, refLen ) == 0 && // starts from refName; isdigit( *( name + refLen )) && // refName is followed by a digit; - strtol( name + refLen, &end, 10) && // there are only digits ... + strtol( name + refLen, &end, 10) >= 0 && // there are only digits ... *end == '\0') // ... till a string end. { mesh->RemoveGroup( *id ); @@ -1087,6 +1087,55 @@ static void removeEmptyGroupsOfDomains(SMESH_Mesh* mesh, } } +//================================================================================ +/*! + * \brief Create the groups corresponding to domains + */ +//================================================================================ + +static void makeDomainGroups( std::vector< std::vector< const SMDS_MeshElement* > >& elemsOfDomain, + SMESH_MesherHelper* theHelper) +{ + // int nbDomains = 0; + // for ( size_t i = 0; i < elemsOfDomain.size(); ++i ) + // nbDomains += ( elemsOfDomain[i].size() > 0 ); + + // if ( nbDomains > 1 ) + for ( size_t iDomain = 0; iDomain < elemsOfDomain.size(); ++iDomain ) + { + std::vector< const SMDS_MeshElement* > & elems = elemsOfDomain[ iDomain ]; + if ( elems.empty() ) continue; + + // find existing groups + std::vector< SMESH_Group* > groupOfType( SMDSAbs_NbElementTypes, (SMESH_Group*)NULL ); + const std::string domainName = ( SMESH_Comment( theDomainGroupNamePrefix ) << iDomain ); + SMESH_Mesh::GroupIteratorPtr groupIt = theHelper->GetMesh()->GetGroups(); + while ( groupIt->more() ) + { + SMESH_Group* group = groupIt->next(); + if ( domainName == group->GetName() && + dynamic_cast< SMESHDS_Group* >( group->GetGroupDS()) ) + groupOfType[ group->GetGroupDS()->GetType() ] = group; + } + // create and fill the groups + size_t iElem = 0; + int groupID; + do + { + SMESH_Group* group = groupOfType[ elems[ iElem ]->GetType() ]; + if ( !group ) + group = theHelper->GetMesh()->AddGroup( elems[ iElem ]->GetType(), + domainName.c_str(), groupID ); + SMDS_MeshGroup& groupDS = + static_cast< SMESHDS_Group* >( group->GetGroupDS() )->SMDSGroup(); + + while ( iElem < elems.size() && groupDS.Add( elems[iElem] )) + ++iElem; + + } while ( iElem < elems.size() ); + } +} + //======================================================================= //function : readGMFFile //purpose : read GMF file w/o geometry associated to mesh @@ -1401,46 +1450,7 @@ static bool readGMFFile(const char* theFile, // 0022172: [CEA 790] create the groups corresponding to domains if ( toMakeGroupsOfDomains ) - { - int nbDomains = 0; - for ( size_t i = 0; i < elemsOfDomain.size(); ++i ) - nbDomains += ( elemsOfDomain[i].size() > 0 ); - - if ( nbDomains > 1 ) - for ( size_t iDomain = 0; iDomain < elemsOfDomain.size(); ++iDomain ) - { - std::vector< const SMDS_MeshElement* > & elems = elemsOfDomain[ iDomain ]; - if ( elems.empty() ) continue; - - // find existing groups - std::vector< SMESH_Group* > groupOfType( SMDSAbs_NbElementTypes, (SMESH_Group*)NULL ); - const std::string domainName = ( SMESH_Comment( theDomainGroupNamePrefix ) << iDomain ); - SMESH_Mesh::GroupIteratorPtr groupIt = theHelper->GetMesh()->GetGroups(); - while ( groupIt->more() ) - { - SMESH_Group* group = groupIt->next(); - if ( domainName == group->GetName() && - dynamic_cast< SMESHDS_Group* >( group->GetGroupDS()) ) - groupOfType[ group->GetGroupDS()->GetType() ] = group; - } - // create and fill the groups - size_t iElem = 0; - int groupID; - do - { - SMESH_Group* group = groupOfType[ elems[ iElem ]->GetType() ]; - if ( !group ) - group = theHelper->GetMesh()->AddGroup( elems[ iElem ]->GetType(), - domainName.c_str(), groupID ); - SMDS_MeshGroup& groupDS = - static_cast< SMESHDS_Group* >( group->GetGroupDS() )->SMDSGroup(); - - while ( iElem < elems.size() && groupDS.Add( elems[iElem] )) - ++iElem; - - } while ( iElem < elems.size() ); - } - } + makeDomainGroups( elemsOfDomain, theHelper ); #ifdef _DEBUG_ MESSAGE("Nb subdomains " << subdomainId2tetraId.size()); @@ -2885,7 +2895,8 @@ static bool readResultFile(const int fileOpen, int nbEnforcedVertices, int nbEnforcedNodes, GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges, - GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles) + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles, + bool toMakeGroupsOfDomains) { MESSAGE("GHS3DPlugin_GHS3D::readResultFile()"); Kernel_Utils::Localizer loc; @@ -3037,6 +3048,9 @@ static bool readResultFile(const int fileOpen, if ( nbTriangle <= nbShape ) // no holes toMeshHoles = true; // not avoid creating tetras in holes + // IMP 0022172: [CEA 790] create the groups corresponding to domains + std::vector< std::vector< const SMDS_MeshElement* > > elemsOfDomain( Max( nbTriangle, nbShape )); + // Associating the tetrahedrons to the shapes shapeID = compoundID; for (int iElem = 0; iElem < nbElems; iElem++) { @@ -3052,6 +3066,7 @@ static bool readResultFile(const int fileOpen, // tetras within holes depending on hypo option, // so we first check if aTet is inside a hole and then create it //aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] ); + ghs3dShapeID = 0; // domain ID if ( nbTriangle > 1 ) { shapeID = HOLE_ID; // negative shapeID means not to create tetras if !toMeshHoles ghs3dShapeID = strtol(shapePtr, &shapePtr, 10) - IdShapeRef; @@ -3096,11 +3111,19 @@ static bool readResultFile(const int fileOpen, aTet = theHelper.AddVolume( node[1], node[0], node[2], node[3], /*id=*/0, /*force3d=*/false); theMeshDS->SetMeshElementOnShape( aTet, shapeID ); + if ( toMakeGroupsOfDomains ) + { + if ( int( elemsOfDomain.size() ) < ghs3dShapeID+1 ) + elemsOfDomain.resize( ghs3dShapeID+1 ); + elemsOfDomain[ ghs3dShapeID ].push_back( aTet ); + } } #ifdef _DEBUG_ shapeIDs.insert( shapeID ); #endif } + if ( toMakeGroupsOfDomains ) + makeDomainGroups( elemsOfDomain, &theHelper ); // Add enforced elements GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::const_iterator elemIt; @@ -3446,6 +3469,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, else { bool toMeshHoles = _hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles(); + const bool toMakeGroupsOfDomains = GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp ); helper.IsQuadraticSubMesh( theShape ); helper.SetElementsOnShape( false ); @@ -3459,7 +3483,8 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, aGhs3dIdToNodeMap, aNodeId2NodeIndexMap, toMeshHoles, nbEnforcedVertices, nbEnforcedNodes, - enforcedEdges, enforcedTriangles ); + enforcedEdges, enforcedTriangles, + toMakeGroupsOfDomains ); // Ok = readGMFFile( // #ifndef GMF_HAS_SUBDOMAIN_INFO @@ -3469,6 +3494,8 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // _nbShape, tabShape, tabBox, // aGhs3dIdToNodeMap, toMeshHoles, // nbEnforcedVertices, nbEnforcedNodes); + + removeEmptyGroupsOfDomains( helper.GetMesh(), /*notEmptyAsWell =*/ !toMakeGroupsOfDomains ); } @@ -3483,8 +3510,8 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, if ( !_keepFiles ) removeFile( aLogFileName ); - if ( _hyp && _hyp->GetToMakeGroupsOfDomains() ) - error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since the mesh is on shape" ); + // if ( _hyp && _hyp->GetToMakeGroupsOfDomains() ) + // error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since the mesh is on shape" ); } else if ( OSD_File( aLogFileName ).Size() > 0 ) { @@ -3705,7 +3732,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, groupsToRemove, toMakeGroupsOfDomains); updateMeshGroups(theHelper->GetMesh(), groupsToRemove); - removeEmptyGroupsOfDomains( theHelper->GetMesh() ); + removeEmptyGroupsOfDomains( theHelper->GetMesh(), /*notEmptyAsWell =*/ !toMakeGroupsOfDomains ); if ( Ok ) { GHS3DPlugin_Hypothesis* that = (GHS3DPlugin_Hypothesis*)this->_hyp; @@ -3721,8 +3748,8 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, if ( !_keepFiles ) removeFile( aLogFileName ); - if ( !toMakeGroupsOfDomains && _hyp && _hyp->GetToMakeGroupsOfDomains() ) - error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since 'toMeshHoles' is OFF." ); + //if ( !toMakeGroupsOfDomains && _hyp && _hyp->GetToMakeGroupsOfDomains() ) + //error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since 'toMeshHoles' is OFF." ); } else if ( OSD_File( aLogFileName ).Size() > 0 ) { diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx index c236a76..ac76a9d 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx @@ -126,8 +126,8 @@ bool GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains() const bool GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains(const GHS3DPlugin_Hypothesis* hyp) { bool res; - if ( hyp ) res = hyp->GetToMeshHoles(true) && hyp->GetToMakeGroupsOfDomains(); - else res = DefaultMeshHoles() && DefaultToMakeGroupsOfDomains(); + if ( hyp ) res = /*hyp->GetToMeshHoles(true) &&*/ hyp->GetToMakeGroupsOfDomains(); + else res = /*DefaultMeshHoles() &&*/ DefaultToMakeGroupsOfDomains(); return res; } @@ -796,7 +796,7 @@ bool GHS3DPlugin_Hypothesis::DefaultMeshHoles() bool GHS3DPlugin_Hypothesis::DefaultToMakeGroupsOfDomains() { - return DefaultMeshHoles(); // issue 0022172 + return true; // issue 0022172 } //======================================================================= diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx index 04517b5..25d7101 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx @@ -645,7 +645,7 @@ QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() tab->setCurrentIndex( STD_TAB ); // connections - connect( myToMeshHolesCheck, SIGNAL( toggled( bool ) ), this, SLOT( onToMeshHoles(bool))); + //connect( myToMeshHolesCheck, SIGNAL( toggled( bool ) ), this, SLOT( onToMeshHoles(bool))); connect( myMaximumMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) ); connect( myInitialMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) ); connect( myBoundaryRecoveryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) ); @@ -1387,9 +1387,9 @@ void GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() void GHS3DPluginGUI_HypothesisCreator::onToMeshHoles(bool isOn) { - myToMakeGroupsOfDomains->setEnabled( isOn ); - if ( !isOn ) - myToMakeGroupsOfDomains->setChecked( false ); + // myToMakeGroupsOfDomains->setEnabled( isOn ); + // if ( !isOn ) + // myToMakeGroupsOfDomains->setChecked( false ); } void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked() @@ -1401,7 +1401,7 @@ void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked() void GHS3DPluginGUI_HypothesisCreator::updateWidgets() { - myToMakeGroupsOfDomains->setEnabled( myToMeshHolesCheck->isChecked() ); + //myToMakeGroupsOfDomains->setEnabled( myToMeshHolesCheck->isChecked() ); myMaximumMemorySpin->setEnabled( myMaximumMemoryCheck->isChecked() ); myInitialMemoryCheck->setEnabled( !myBoundaryRecoveryCheck->isChecked() ); myInitialMemorySpin->setEnabled( myInitialMemoryCheck->isChecked() && !myBoundaryRecoveryCheck->isChecked() ); @@ -1678,7 +1678,7 @@ bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data.myName = isCreation() && data ? hypName() : ""; h_data.myToMeshHoles = h->GetToMeshHoles(); - h_data.myToMakeGroupsOfDomains = h->GetToMeshHoles() && h->GetToMakeGroupsOfDomains(); + h_data.myToMakeGroupsOfDomains = /*h->GetToMeshHoles() &&*/ h->GetToMakeGroupsOfDomains(); h_data.myMaximumMemory = h->GetMaximumMemory(); h_data.myInitialMemory = h->GetInitialMemory(); h_data.myInitialMemory = h->GetInitialMemory(); -- 2.39.2