+ else if ( theDimension == SMESH::DIM_1D )
+ {
+ SMDS_NodeIteratorPtr nodeIt = smDS->GetNodes();
+ while ( nodeIt->more() )
+ {
+ listOfElemType.push_back( SMDSAbs_Node );
+ connectivity.push_back
+ ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
+ }
+ // add corner nodes by first vertex from edge
+ SMESH_subMeshIteratorPtr edgeSmIt =
+ sm->getDependsOnIterator(/*includeSelf*/false,
+ /*complexShapeFirst*/false);
+ while ( edgeSmIt->more() )
+ {
+ SMESH_subMesh* vertexSM = edgeSmIt->next();
+ // check that vertex is not already treated
+ if ( !setOfVSubMesh.insert( vertexSM ).second )
+ continue;
+ if ( vertexSM->GetSubShape().ShapeType() != TopAbs_VERTEX )
+ continue;
+
+ const SMESHDS_SubMesh* vertexSmDS = vertexSM->GetSubMeshDS();
+ SMDS_NodeIteratorPtr nodeIt = vertexSmDS->GetNodes();
+ while ( nodeIt->more() )
+ {
+ listOfElemType.push_back( SMDSAbs_Node );
+ connectivity.push_back
+ ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
+ }
+ }
+ }
+ }
+
+ // fill node coords and assign local ids to the nodes
+ int nbNodes = mapNode2LocalID.size();
+ result->nodesXYZ.length( nbNodes );
+ TNodeLocalID node2ID = mapNode2LocalID.begin();
+ for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
+ node2ID->second = i;
+ const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
+ result->nodesXYZ[i].x = node->X();
+ result->nodesXYZ[i].y = node->Y();
+ result->nodesXYZ[i].z = node->Z();
+ }
+ // fill connectivity
+ result->elementConnectivities.length( nbConnNodes );
+ list< TNodeLocalID >::iterator connIt = connectivity.begin();
+ for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
+ result->elementConnectivities[i] = (*connIt)->second;
+ }
+
+ // fill element types
+ result->elementTypes.length( listOfElemType.size() );
+ std::list< SMDSAbs_ElementType >::const_iterator typeIt = listOfElemType.begin();
+ std::list< SMDSAbs_ElementType >::const_iterator typeEnd = listOfElemType.end();
+ for ( i = 0; typeIt != typeEnd; ++i, ++typeIt )
+ {
+ SMDSAbs_ElementType elemType = *typeIt;
+ result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType)elemType;
+ result->elementTypes[i].isPoly = false;
+ result->elementTypes[i].nbNodesInElement = elemType == SMDSAbs_Edge ? 2 : 1;
+ }
+
+ // correct number of shapes
+ theShapesId.length( mapOfShIdNb.size() );
+ }
+ }
+ }
+ catch ( std::bad_alloc ) {
+ INFOS( "Precompute(): lack of memory" );
+ }
+ catch ( SALOME_Exception& S_ex ) {
+ INFOS( "Precompute(): catch exception "<< S_ex.what() );
+ }
+ catch ( ... ) {
+ INFOS( "Precompute(): unknown exception " );
+ }
+ return result._retn();
+}
+
+
+//=============================================================================
+/*!
+ * SMESH_Gen_i::Evaluate
+ *
+ * Evaluate mesh on a shape
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
+ GEOM::GEOM_Object_ptr theShapeObject)
+// SMESH::long_array& theNbElems)
+ throw ( SALOME::SALOME_Exception )
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Evaluate" );
+
+ if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
+ THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
+ SALOME::BAD_PARAM );
+
+ if ( CORBA::is_nil( theMesh ) )
+ THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
+ SALOME::BAD_PARAM );
+
+ SMESH::long_array_var nbels = new SMESH::long_array;
+ nbels->length(SMESH::Entity_Last);
+ int i = SMESH::Entity_Node;
+ for (; i < SMESH::Entity_Last; i++)
+ nbels[i] = 0;
+
+ // Update Python script
+ TPythonDump() << "theNbElems = " << this << ".Evaluate( "
+ << theMesh << ", " << theShapeObject << ")";
+
+ try {
+ // get mesh servant
+ SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
+ ASSERT( meshServant );
+ if ( meshServant ) {
+ meshServant->Load();
+ // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
+ meshServant->CheckGeomModif();
+ // get local TopoDS_Shape
+ TopoDS_Shape myLocShape;
+ if(theMesh->HasShapeToMesh())
+ myLocShape = GeomObjectToShape( theShapeObject );
+ else
+ myLocShape = SMESH_Mesh::PseudoShape();
+ // call implementation compute
+ ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
+ MapShapeNbElems aResMap;
+ /*CORBA::Boolean ret =*/ myGen.Evaluate( myLocMesh, myLocShape, aResMap);
+ MapShapeNbElemsItr anIt = aResMap.begin();
+ for(; anIt!=aResMap.end(); anIt++) {
+ const vector<int>& aVec = (*anIt).second;
+ for ( i = SMESH::Entity_Node; i < (int)aVec.size(); i++ ) {
+ int nbElem = aVec[i];
+ if ( nbElem < 0 ) // algo failed, check that it has reported a message
+ {
+ SMESH_subMesh* sm = anIt->first;
+ SMESH_ComputeErrorPtr& error = sm->GetComputeError();
+ const SMESH_Algo* algo = sm->GetAlgo();
+ if ( (algo && !error.get()) || error->IsOK() )
+ error.reset( new SMESH_ComputeError( COMPERR_ALGO_FAILED,"Failed to evaluate",algo));
+ }
+ else
+ {
+ nbels[i] += aVec[i];
+ }
+ }
+ }
+ return nbels._retn();
+ }
+ }
+ catch ( std::bad_alloc ) {
+ INFOS( "Evaluate(): lack of memory" );
+ }
+ catch ( SALOME_Exception& S_ex ) {
+ INFOS( "Evaluate(): catch exception "<< S_ex.what() );
+ }
+ catch ( ... ) {
+ INFOS( "Evaluate(): unknown exception " );
+ }
+
+ return nbels._retn();
+}
+
+//================================================================================
+/*!
+ * \brief Return geometrical object the given element is built on
+ * \param theMesh - the mesh the element is in
+ * \param theElementID - the element ID
+ * \param theGeomName - the name of the result geom object if it is not yet published
+ * \retval GEOM::GEOM_Object_ptr - the found or just published geom object (no need to UnRegister())
+ */
+//================================================================================
+
+GEOM::GEOM_Object_ptr
+SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
+ CORBA::Long theElementID,
+ const char* theGeomName)
+ throw ( SALOME::SALOME_Exception )
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ GEOM::GEOM_Object_wrap geom = FindGeometryByMeshElement(theMesh, theElementID);
+ if ( !geom->_is_nil() ) {
+ GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
+ GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
+
+ // try to find the corresponding SObject
+ SALOMEDS::SObject_wrap SObj = ObjectToSObject( myCurrentStudy, geom.in() );
+ if ( SObj->_is_nil() ) // submesh can be not found even if published
+ {
+ // try to find published submesh
+ GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
+ if ( !geom->IsMainShape() && list->length() == 1 ) {
+ SALOMEDS::SObject_wrap mainSO = ObjectToSObject( myCurrentStudy, mainShape );
+ SALOMEDS::ChildIterator_wrap it;
+ if ( !mainSO->_is_nil() ) {
+ it = myCurrentStudy->NewChildIterator( mainSO );
+ }
+ if ( !it->_is_nil() ) {
+ for ( it->InitEx(true); it->More(); it->Next() ) {
+ SALOMEDS::SObject_wrap so = it->Value();
+ CORBA::Object_var obj = SObjectToObject( so );
+ GEOM::GEOM_Object_var subGeom = GEOM::GEOM_Object::_narrow( obj );
+ if ( !subGeom->_is_nil() ) {
+ GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
+ if ( subList->length() == 1 && list[0] == subList[0] ) {
+ SObj = so;
+ geom = subGeom;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ if ( SObj->_is_nil() ) // publish a new subshape
+ SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
+
+ // return only published geometry
+ if ( !SObj->_is_nil() ) {
+ //return geom._retn(); -- servant of geom must be UnRegister()ed;
+ CORBA::Object_var obj = SObjectToObject( SObj );
+ GEOM::GEOM_Object_var go = GEOM::GEOM_Object::_narrow( obj );
+ return go._retn();
+ }
+ }
+ return GEOM::GEOM_Object::_nil();
+}
+
+//================================================================================
+/*!
+ * \brief Return geometrical object the given element is built on.
+ * \param theMesh - the mesh the element is in
+ * \param theElementID - the element ID
+ * \retval GEOM::GEOM_Object_ptr - the found or created (UnRegister()!) geom object
+ */
+//================================================================================
+
+GEOM::GEOM_Object_ptr
+SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
+ CORBA::Long theElementID)
+ throw ( SALOME::SALOME_Exception )
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( CORBA::is_nil( theMesh ) )
+ THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
+
+ GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
+ GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
+
+ // get a core mesh DS
+ SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
+ if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
+ {
+ ::SMESH_Mesh & mesh = meshServant->GetImpl();
+ SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
+ // find the element in mesh
+ if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) ) {
+ // find a shape id by the element
+ if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
+ // get a geom object by the shape id
+ GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
+ if ( geom->_is_nil() ) {
+ // try to find a published sub-shape
+ SALOMEDS::SObject_wrap mainSO = ObjectToSObject( myCurrentStudy, mainShape );
+ SALOMEDS::ChildIterator_wrap it;
+ if ( !mainSO->_is_nil() ) {
+ it = myCurrentStudy->NewChildIterator( mainSO );
+ }
+ if ( !it->_is_nil() ) {
+ for ( it->InitEx(true); it->More(); it->Next() ) {
+ SALOMEDS::SObject_wrap so = it->Value();
+ CORBA::Object_var obj = SObjectToObject( so );
+ GEOM::GEOM_Object_var subGeom = GEOM::GEOM_Object::_narrow( obj );
+ if ( !subGeom->_is_nil() ) {
+ GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
+ if ( subList->length() == 1 && shapeID == subList[0] ) {
+ geom = subGeom;
+ break;
+ }
+ }
+ }
+ }
+ }
+ if ( geom->_is_nil() ) {
+ // explode
+ GEOM::GEOM_IShapesOperations_wrap op =
+ geomGen->GetIShapesOperations( GetCurrentStudyID() );
+ if ( !op->_is_nil() )
+ geom = op->GetSubShape( mainShape, shapeID );
+ }
+ else {
+ geom->Register();
+ }
+ if ( !geom->_is_nil() ) {
+ GeomObjectToShape( geom ); // let geom client remember the found shape
+ return geom._retn();
+ }
+ }
+ }
+ }
+ return GEOM::GEOM_Object::_nil();
+}
+
+//================================================================================
+/*!
+ * SMESH_Gen_i::Concatenate
+ *
+ * Concatenate the given meshes into one mesh
+ */
+//================================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_Gen_i::Concatenate(const SMESH::ListOfIDSources& theMeshesArray,
+ CORBA::Boolean theUniteIdenticalGroups,
+ CORBA::Boolean theMergeNodesAndElements,
+ CORBA::Double theMergeTolerance)
+ throw ( SALOME::SALOME_Exception )
+{
+ return ConcatenateCommon(theMeshesArray,
+ theUniteIdenticalGroups,
+ theMergeNodesAndElements,
+ theMergeTolerance,
+ false);
+}
+
+//================================================================================
+/*!
+ * SMESH_Gen_i::ConcatenateWithGroups
+ *
+ * Concatenate the given meshes into one mesh
+ * Create the groups of all elements from initial meshes
+ */
+//================================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_Gen_i::ConcatenateWithGroups(const SMESH::ListOfIDSources& theMeshesArray,
+ CORBA::Boolean theUniteIdenticalGroups,
+ CORBA::Boolean theMergeNodesAndElements,
+ CORBA::Double theMergeTolerance)
+ throw ( SALOME::SALOME_Exception )
+{
+ return ConcatenateCommon(theMeshesArray,
+ theUniteIdenticalGroups,
+ theMergeNodesAndElements,
+ theMergeTolerance,
+ true);
+}
+
+//================================================================================
+/*!
+ * SMESH_Gen_i::ConcatenateCommon
+ *
+ * Concatenate the given meshes into one mesh
+ */
+//================================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_Gen_i::ConcatenateCommon(const SMESH::ListOfIDSources& theMeshesArray,
+ CORBA::Boolean theUniteIdenticalGroups,
+ CORBA::Boolean theMergeNodesAndElements,
+ CORBA::Double theMergeTolerance,
+ CORBA::Boolean theCommonGroups)
+ throw ( SALOME::SALOME_Exception )
+{
+ typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
+ typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
+
+ TPythonDump* pPythonDump = new TPythonDump;
+ TPythonDump& aPythonDump = *pPythonDump; // prevent dump of called methods
+
+ // create mesh
+ SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
+
+ if ( aNewMesh->_is_nil() )
+ return aNewMesh._retn();
+
+ SMESH_Mesh_i* aNewImpl = SMESH::DownCast<SMESH_Mesh_i*>( aNewMesh );
+ if ( !aNewImpl )
+ return aNewMesh._retn();
+
+ ::SMESH_Mesh& aLocMesh = aNewImpl->GetImpl();
+ SMESHDS_Mesh* aNewMeshDS = aLocMesh.GetMeshDS();
+
+ TGroupsMap aGroupsMap;
+ TListOfNewGroups aListOfNewGroups;
+ ::SMESH_MeshEditor aNewEditor(&aLocMesh);
+ SMESH::ListOfGroups_var aListOfGroups;
+
+ ::SMESH_MeshEditor::ElemFeatures elemType;
+ std::vector<const SMDS_MeshNode*> aNodesArray;
+
+ // loop on sub-meshes
+ for ( CORBA::ULong i = 0; i < theMeshesArray.length(); i++)
+ {
+ if ( CORBA::is_nil( theMeshesArray[i] )) continue;
+ SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i]->GetMesh();
+ if ( anInitMesh->_is_nil() ) continue;
+ SMESH_Mesh_i* anInitImpl = SMESH::DownCast<SMESH_Mesh_i*>( anInitMesh );
+ if ( !anInitImpl ) continue;
+ anInitImpl->Load();
+
+ //::SMESH_Mesh& aInitLocMesh = anInitImpl->GetImpl();
+ //SMESHDS_Mesh* anInitMeshDS = aInitLocMesh.GetMeshDS();
+
+ // remember nb of elements before filling in
+ SMESH::long_array_var prevState = aNewMesh->GetNbElementsByType();
+
+ typedef std::map<const SMDS_MeshElement*, const SMDS_MeshElement*, TIDCompare > TEEMap;
+ TEEMap elemsMap, nodesMap;
+
+ // loop on elements of a sub-mesh
+ SMDS_ElemIteratorPtr itElems = anInitImpl->GetElements( theMeshesArray[i], SMESH::ALL );
+ const SMDS_MeshElement* anElem;
+ const SMDS_MeshElement* aNewElem;
+ const SMDS_MeshNode* aNode;
+ const SMDS_MeshNode* aNewNode;
+ int anElemNbNodes;
+
+ while ( itElems->more() )
+ {
+ anElem = itElems->next();
+ anElemNbNodes = anElem->NbNodes();
+ aNodesArray.resize( anElemNbNodes );
+
+ // loop on nodes of an element
+ SMDS_ElemIteratorPtr itNodes = anElem->nodesIterator();
+ for ( int k = 0; itNodes->more(); k++)
+ {
+ aNode = static_cast<const SMDS_MeshNode*>( itNodes->next() );
+ TEEMap::iterator n2nnIt = nodesMap.find( aNode );
+ if ( n2nnIt == nodesMap.end() )
+ {
+ aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
+ nodesMap.insert( make_pair( aNode, aNewNode ));
+ }
+ else
+ {
+ aNewNode = static_cast<const SMDS_MeshNode*>( n2nnIt->second );
+ }
+ aNodesArray[k] = aNewNode;
+ }
+
+ // creates a corresponding element on existent nodes in new mesh
+ if ( anElem->GetType() == SMDSAbs_Node )
+ aNewElem = 0;
+ else
+ aNewElem =
+ aNewEditor.AddElement( aNodesArray, elemType.Init( anElem, /*basicOnly=*/false ));
+
+ if ( aNewElem )
+ elemsMap.insert( make_pair( anElem, aNewElem ));
+
+ } //elems loop
+
+ aNewEditor.ClearLastCreated(); // forget the history
+
+
+ // create groups of just added elements
+ SMESH::SMESH_Group_var aNewGroup;
+ SMESH::ElementType aGroupType;
+ if ( theCommonGroups )
+ {
+ SMESH::long_array_var curState = aNewMesh->GetNbElementsByType();
+
+ for( aGroupType = SMESH::NODE;
+ aGroupType < SMESH::NB_ELEMENT_TYPES;
+ aGroupType = (SMESH::ElementType)( aGroupType + 1 ))
+ {
+ if ( curState[ aGroupType ] <= prevState[ aGroupType ])
+ continue;
+
+ // make a group name
+ const char* typeNames[] = { "All","Nodes","Edges","Faces","Volumes","0DElems","Balls" };
+ { // check of typeNames: compilation failure mains that NB_ELEMENT_TYPES changed:
+ const int nbNames = sizeof(typeNames) / sizeof(const char*);
+ int _assert[( nbNames == SMESH::NB_ELEMENT_TYPES ) ? 2 : -1 ]; _assert[0]=_assert[1]=0;
+ }
+ string groupName = "Gr";
+ SALOMEDS::SObject_wrap aMeshSObj = ObjectToSObject( myCurrentStudy, theMeshesArray[i] );
+ if ( aMeshSObj ) {
+ CORBA::String_var name = aMeshSObj->GetName();
+ groupName += name;
+ }
+ groupName += "_";
+ groupName += typeNames[ aGroupType ];
+
+ // make and fill a group
+ TEEMap & e2neMap = ( aGroupType == SMESH::NODE ) ? nodesMap : elemsMap;
+ aNewGroup = aNewImpl->CreateGroup( aGroupType, groupName.c_str() );
+ if ( SMESH_Group_i* grp_i = SMESH::DownCast<SMESH_Group_i*>( aNewGroup ))
+ {
+ if ( SMESHDS_Group* grpDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() ))
+ {
+ TEEMap::iterator e2neIt = e2neMap.begin();
+ for ( ; e2neIt != e2neMap.end(); ++e2neIt )
+ {
+ aNewElem = e2neIt->second;
+ if ( aNewElem->GetType() == grpDS->GetType() )
+ {
+ grpDS->Add( aNewElem );
+
+ if ( prevState[ aGroupType ]++ >= curState[ aGroupType ] )
+ break;
+ }
+ }
+ }
+ }
+ aListOfNewGroups.clear();
+ aListOfNewGroups.push_back(aNewGroup);
+ aGroupsMap.insert(make_pair( make_pair(groupName, aGroupType), aListOfNewGroups ));
+ }
+ }
+
+ if ( SMESH_Mesh_i* anSrcImpl = SMESH::DownCast<SMESH_Mesh_i*>( theMeshesArray[i] ))
+ {
+ // copy orphan nodes
+ if ( anSrcImpl->NbNodes() > (int)nodesMap.size() )
+ {
+ SMDS_ElemIteratorPtr itNodes = anInitImpl->GetElements( theMeshesArray[i], SMESH::NODE );
+ while ( itNodes->more() )
+ {
+ const SMDS_MeshNode* aNode = static_cast< const SMDS_MeshNode* >( itNodes->next() );
+ if ( aNode->NbInverseElements() == 0 )
+ {
+ aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
+ nodesMap.insert( make_pair( aNode, aNewNode ));
+ }
+ }
+ }
+
+ // copy groups
+
+ SMESH::SMESH_GroupBase_ptr aGroup;
+ CORBA::String_var aGroupName;
+ SMESH::long_array_var anNewIDs = new SMESH::long_array();
+
+ // loop on groups of a source mesh
+ aListOfGroups = anSrcImpl->GetGroups();
+ for ( CORBA::ULong iG = 0; iG < aListOfGroups->length(); iG++ )
+ {
+ aGroup = aListOfGroups[iG];
+ aGroupType = aGroup->GetType();
+ aGroupName = aGroup->GetName();
+ string aName = aGroupName.in();
+
+ // convert a list of IDs
+ anNewIDs->length( aGroup->Size() );
+ TEEMap & e2neMap = ( aGroupType == SMESH::NODE ) ? nodesMap : elemsMap;
+ SMDS_ElemIteratorPtr itGrElems = anSrcImpl->GetElements( aGroup, SMESH::ALL );
+ int iElem = 0;
+ while ( itGrElems->more() )
+ {
+ anElem = itGrElems->next();
+ TEEMap::iterator e2neIt = e2neMap.find( anElem );
+ if ( e2neIt != e2neMap.end() )
+ anNewIDs[ iElem++ ] = e2neIt->second->GetID();
+ }
+ anNewIDs->length( iElem );
+
+ // check a current group name and type don't have identical ones in final mesh
+ aListOfNewGroups.clear();
+ TGroupsMap::iterator anIter = aGroupsMap.find( make_pair( aName, aGroupType ));
+ if ( anIter == aGroupsMap.end() ) {
+ // add a new group in the mesh
+ aNewGroup = aNewImpl->CreateGroup( aGroupType, aGroupName.in() );
+ // add elements into new group
+ aNewGroup->Add( anNewIDs );
+
+ aListOfNewGroups.push_back(aNewGroup);
+ aGroupsMap.insert(make_pair( make_pair(aName, aGroupType), aListOfNewGroups ));
+ }
+
+ else if ( theUniteIdenticalGroups ) {
+ // unite identical groups
+ TListOfNewGroups& aNewGroups = anIter->second;
+ aNewGroups.front()->Add( anNewIDs );
+ }
+
+ else {
+ // rename identical groups
+ aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName.in());
+ aNewGroup->Add( anNewIDs );
+
+ TListOfNewGroups& aNewGroups = anIter->second;
+ string aNewGroupName;
+ if (aNewGroups.size() == 1) {
+ aNewGroupName = aName + "_1";
+ aNewGroups.front()->SetName(aNewGroupName.c_str());
+ }
+ char aGroupNum[128];
+ sprintf(aGroupNum, "%u", (unsigned int)aNewGroups.size()+1);
+ aNewGroupName = aName + "_" + string(aGroupNum);
+ aNewGroup->SetName(aNewGroupName.c_str());
+ aNewGroups.push_back(aNewGroup);
+ }
+ } //groups loop
+ } // if an IDSource is a mesh
+ } //meshes loop
+
+ if (theMergeNodesAndElements) // merge nodes
+ {
+ TIDSortedNodeSet aMeshNodes; // no input nodes
+ SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
+ aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes,
+ /*SeparateCornersAndMedium=*/ false );
+ aNewEditor.MergeNodes( aGroupsOfNodes );
+ // merge elements
+ aNewEditor.MergeEqualElements();
+ }
+
+ // Update Python script
+ aPythonDump << aNewMesh << " = " << this << "."
+ << ( theCommonGroups ? "ConcatenateWithGroups" : "Concatenate" )
+ << "([";
+ for ( CORBA::ULong i = 0; i < theMeshesArray.length(); i++) {
+ if (i > 0) aPythonDump << ", ";
+ aPythonDump << theMeshesArray[i];
+ }
+ aPythonDump << "], ";
+ aPythonDump << theUniteIdenticalGroups << ", "
+ << theMergeNodesAndElements << ", "
+ << TVar( theMergeTolerance ) << ")";
+
+ delete pPythonDump; // enable python dump from GetGroups()
+
+ // 0020577: EDF 1164 SMESH: Bad dump of concatenate with create common groups
+ if ( !aNewMesh->_is_nil() )
+ {
+ SMESH::ListOfGroups_var groups = aNewMesh->GetGroups();
+ }
+
+ // IPAL21468 Change icon of compound because it need not be computed.
+ SALOMEDS::SObject_wrap aMeshSObj = ObjectToSObject( myCurrentStudy, aNewMesh );
+ SetPixMap( aMeshSObj, "ICON_SMESH_TREE_MESH" );
+
+ if (aNewMeshDS)
+ aNewMeshDS->Modified();
+
+ return aNewMesh._retn();
+}
+
+//================================================================================
+/*!
+ * \brief Create a mesh by copying a part of another mesh
+ * \param meshPart - a part of mesh to copy
+ * \param toCopyGroups - to create in the new mesh groups
+ * the copied elements belongs to
+ * \param toKeepIDs - to preserve IDs of the copied elements or not
+ * \retval SMESH::SMESH_Mesh_ptr - the new mesh
+ */
+//================================================================================
+
+SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
+ const char* meshName,
+ CORBA::Boolean toCopyGroups,
+ CORBA::Boolean toKeepIDs)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ TPythonDump* pyDump = new TPythonDump; // prevent dump from CreateMesh()
+
+ // 1. Get source mesh
+
+ if ( CORBA::is_nil( meshPart ))
+ THROW_SALOME_CORBA_EXCEPTION( "bad IDSource", SALOME::BAD_PARAM );
+
+ SMESH::SMESH_Mesh_var srcMesh = meshPart->GetMesh();
+ SMESH_Mesh_i* srcMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( srcMesh );
+ if ( !srcMesh_i )
+ THROW_SALOME_CORBA_EXCEPTION( "bad mesh of IDSource", SALOME::BAD_PARAM );
+
+ SMESHDS_Mesh* srcMeshDS = srcMesh_i->GetImpl().GetMeshDS();
+
+ // 2. Make a new mesh
+
+ SMESH::SMESH_Mesh_var newMesh = CreateMesh(GEOM::GEOM_Object::_nil());
+ SMESH_Mesh_i* newMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( newMesh );
+ if ( !newMesh_i )
+ THROW_SALOME_CORBA_EXCEPTION( "can't create a mesh", SALOME::INTERNAL_ERROR );
+ SALOMEDS::SObject_wrap meshSO = ObjectToSObject(myCurrentStudy, newMesh );
+ if ( !meshSO->_is_nil() )
+ {
+ SetName( meshSO, meshName, "Mesh" );
+ SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
+ }
+ SMESHDS_Mesh* newMeshDS = newMesh_i->GetImpl().GetMeshDS();
+ ::SMESH_MeshEditor editor( &newMesh_i->GetImpl() );
+ ::SMESH_MeshEditor::ElemFeatures elemType;
+
+ // 3. Get elements to copy
+
+ SMDS_ElemIteratorPtr srcElemIt; SMDS_NodeIteratorPtr srcNodeIt;
+ TIDSortedElemSet srcElems;
+ SMESH::array_of_ElementType_var srcElemTypes = meshPart->GetTypes();
+ if ( SMESH::DownCast<SMESH_Mesh_i*>( meshPart ))
+ {
+ srcMesh_i->Load();
+ srcElemIt = srcMeshDS->elementsIterator();
+ srcNodeIt = srcMeshDS->nodesIterator();
+ }
+ else
+ {
+ SMESH::long_array_var ids = meshPart->GetIDs();
+ if ( srcElemTypes->length() == 1 && srcElemTypes[0] == SMESH::NODE ) // group of nodes
+ {
+ for ( CORBA::ULong i=0; i < ids->length(); i++ )
+ if ( const SMDS_MeshElement * elem = srcMeshDS->FindNode( ids[i] ))
+ srcElems.insert( elem );
+ }
+ else
+ {
+ for ( CORBA::ULong i = 0; i < ids->length(); i++ )
+ if ( const SMDS_MeshElement * elem = srcMeshDS->FindElement( ids[i] ))
+ srcElems.insert( elem );
+ }
+ if ( srcElems.empty() )
+ return newMesh._retn();
+
+ typedef SMDS_SetIterator< SMDS_pElement, TIDSortedElemSet::const_iterator > ElIter;
+ srcElemIt = SMDS_ElemIteratorPtr( new ElIter( srcElems.begin(), srcElems.end() ));
+ }
+
+ // 4. Copy elements
+
+ typedef map<SMDS_pElement, SMDS_pElement, TIDCompare> TE2EMap;
+ TE2EMap e2eMapByType[ SMDSAbs_NbElementTypes ];
+ TE2EMap& n2nMap = e2eMapByType[ SMDSAbs_Node ];
+ int iN;
+ const SMDS_MeshNode *nSrc, *nTgt;
+ vector< const SMDS_MeshNode* > nodes;
+ while ( srcElemIt->more() )
+ {
+ const SMDS_MeshElement * elem = srcElemIt->next();
+ // find / add nodes
+ nodes.resize( elem->NbNodes());
+ SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
+ if ( toKeepIDs ) {
+ for ( iN = 0; nIt->more(); ++iN )
+ {
+ nSrc = static_cast<const SMDS_MeshNode*>( nIt->next() );
+ nTgt = newMeshDS->FindNode( nSrc->GetID());
+ if ( !nTgt )
+ nTgt = newMeshDS->AddNodeWithID( nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID());
+ nodes[ iN ] = nTgt;
+ }
+ }
+ else {
+ for ( iN = 0; nIt->more(); ++iN )
+ {
+ nSrc = static_cast<const SMDS_MeshNode*>( nIt->next() );
+ TE2EMap::iterator n2n = n2nMap.insert( make_pair( nSrc, SMDS_pNode(0) )).first;
+ if ( !n2n->second )
+ n2n->second = newMeshDS->AddNode( nSrc->X(), nSrc->Y(), nSrc->Z() );
+ nodes[ iN ] = (const SMDS_MeshNode*) n2n->second;