+//================================================================================
+/*!
+ * \brief Prepare SMESH_IDSource for work
+ */
+//================================================================================
+
+void SMESH_MeshEditor_i::prepareIdSource(SMESH::SMESH_IDSource_ptr theObject)
+{
+ if ( SMESH::Filter_i* filter = SMESH::DownCast<SMESH::Filter_i*>( theObject ))
+ {
+ SMESH::SMESH_Mesh_var mesh = myMesh_i->_this();
+ filter->SetMesh( mesh );
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Duplicates given elements, i.e. creates new elements based on the
+ * same nodes as the given ones.
+ * \param theElements - container of elements to duplicate.
+ * \param theGroupName - a name of group to contain the generated elements.
+ * If a group with such a name already exists, the new elements
+ * are added to the existng group, else a new group is created.
+ * If \a theGroupName is empty, new elements are not added
+ * in any group.
+ * \return a group where the new elements are added. NULL if theGroupName == "".
+ * \sa DoubleNode()
+ */
+//================================================================================
+
+SMESH::SMESH_Group_ptr
+SMESH_MeshEditor_i::DoubleElements(SMESH::SMESH_IDSource_ptr theElements,
+ const char* theGroupName)
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH::SMESH_Group_var newGroup;
+
+ SMESH_TRY;
+ initData();
+
+ TPythonDump pyDump;
+
+ TIDSortedElemSet elems;
+ prepareIdSource( theElements );
+ if ( idSourceToSet( theElements, getMeshDS(), elems, SMDSAbs_All, /*emptyIfIsMesh=*/true))
+ {
+ getEditor().DoubleElements( elems );
+
+ if ( strlen( theGroupName ) && !getEditor().GetLastCreatedElems().IsEmpty() )
+ {
+ // group type
+ SMESH::ElementType type =
+ SMESH::ElementType( getEditor().GetLastCreatedElems().Value(1)->GetType() );
+ // find existing group
+ SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
+ for ( size_t i = 0; i < groups->length(); ++i )
+ if ( groups[i]->GetType() == type )
+ {
+ CORBA::String_var name = groups[i]->GetName();
+ if ( strcmp( name, theGroupName ) == 0 ) {
+ newGroup = SMESH::SMESH_Group::_narrow( groups[i] );
+ break;
+ }
+ }
+ // create a new group
+ if ( newGroup->_is_nil() )
+ newGroup = myMesh_i->CreateGroup( type, theGroupName );
+ // fill newGroup
+ if ( SMESH_Group_i* group_i = SMESH::DownCast< SMESH_Group_i* >( newGroup ))
+ {
+ SMESHDS_Group* groupDS = static_cast< SMESHDS_Group* >( group_i->GetGroupDS() );
+ const SMESH_SequenceOfElemPtr& aSeq = getEditor().GetLastCreatedElems();
+ for ( int i = 1; i <= aSeq.Length(); i++ )
+ groupDS->SMDSGroup().Add( aSeq(i) );
+ }
+ }
+ }
+ // python dump
+ if ( !newGroup->_is_nil() )
+ pyDump << newGroup << " = ";
+ pyDump << this << ".DoubleElements( "
+ << theElements << ", " << "'" << theGroupName <<"')";
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return newGroup._retn();
+}
+