}
void Remove( SMDSAbs_ElementType type )
{
- SMDS_ElemIteratorPtr eIt = GetMeshDS()->elementsIterator( type );
+ Remove( GetMeshDS()->elementsIterator( type ));
+ }
+ void Remove( SMDS_ElemIteratorPtr eIt )
+ {
while ( eIt->more() )
GetMeshDS()->RemoveFreeElement( eIt->next(), /*sm=*/0, /*fromGroups=*/false );
}
SMESH_TRY;
const bool hasBadElems = ( getEditor().GetError() && getEditor().GetError()->HasBadElems() );
- if ( myIsPreviewMode || hasBadElems ) { // --- MeshPreviewStruct filling ---
-
+ if ( myIsPreviewMode || hasBadElems )
+ {
list<int> aNodesConnectivity;
typedef map<int, int> TNodesMap;
TNodesMap nodesMap;
SMESHDS_Mesh* aMeshDS;
- std::auto_ptr< SMESH_MeshPartDS > aMeshPartDS;
+ std::unique_ptr< SMESH_MeshPartDS > aMeshPartDS;
if ( hasBadElems ) {
aMeshPartDS.reset( new SMESH_MeshPartDS( getEditor().GetError()->myBadElements ));
aMeshDS = aMeshPartDS.get();
SMESH::long_array_var myLastCreatedNodes = new SMESH::long_array();
const SMESH_SequenceOfElemPtr& aSeq = getEditor().GetLastCreatedNodes();
- myLastCreatedNodes->length( aSeq.Length() );
- for (int i = 1; i <= aSeq.Length(); i++)
- myLastCreatedNodes[i-1] = aSeq.Value(i)->GetID();
+ myLastCreatedNodes->length( aSeq.size() );
+ for ( size_t i = 0; i < aSeq.size(); i++)
+ myLastCreatedNodes[i] = aSeq[i]->GetID();
return myLastCreatedNodes._retn();
SMESH_CATCH( SMESH::throwCorbaException );
SMESH::long_array_var myLastCreatedElems = new SMESH::long_array();
const SMESH_SequenceOfElemPtr& aSeq = getEditor().GetLastCreatedElems();
- myLastCreatedElems->length( aSeq.Length() );
- for ( int i = 1; i <= aSeq.Length(); i++ )
- myLastCreatedElems[i-1] = aSeq.Value(i)->GetID();
+ myLastCreatedElems->length( aSeq.size() );
+ for ( size_t i = 0; i < aSeq.size(); i++ )
+ myLastCreatedElems[i] = aSeq[i]->GetID();
return myLastCreatedElems._retn();
SMESH_CATCH( SMESH::throwCorbaException );
//=============================================================================
/*!
* Find better splitting of the given quadrangle.
- * \param IDOfQuad ID of the quadrangle to be splitted.
+ * \param IDOfQuad ID of the quadrangle to be split.
* \param Criterion A criterion to choose a diagonal for splitting.
* \return 1 if 1-3 diagonal is better, 2 if 2-4
* diagonal is better, 0 if error occurs.
return mesh._retn();
}
+//================================================================================
+/*!
+ * \brief Make an offset mesh from a source 2D mesh
+ * \param [inout] theObject - source mesh. New elements are added to this mesh
+ * if \a theMeshName is empty.
+ * \param [in] theValue - offset value
+ * \param [in] theCopyGroups - to generate groups
+ * \param [in] theMeshName - optional name of a new mesh
+ * \param [out] theGroups - new groups
+ * \return SMESH::SMESH_Mesh_ptr - the modified mesh
+ */
+//================================================================================
+
+SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::Offset( SMESH::SMESH_IDSource_ptr theObject,
+ CORBA::Double theValue,
+ CORBA::Boolean theCopyGroups,
+ const char* theMeshName,
+ SMESH::ListOfGroups_out theGroups)
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH_TRY;
+ initData();
+
+ SMESHDS_Mesh* aMeshDS = getMeshDS();
+
+ SMESH::SMESH_Mesh_var mesh_var;
+ ::SMESH_MeshEditor::PGroupIDs groupIds;
+
+ TPythonDump pyDump;
+
+ TIDSortedElemSet elements, copyElements;
+ if ( idSourceToSet( theObject, aMeshDS, elements, SMDSAbs_Face,
+ /*emptyIfIsMesh=*/ !myIsPreviewMode ))
+ {
+ // mesh to modify
+ SMESH_Mesh* tgtMesh = 0;
+ if ( myIsPreviewMode )
+ {
+ TPreviewMesh * tmpMesh = getPreviewMesh();
+ tgtMesh = tmpMesh;
+ tmpMesh->Copy( elements, copyElements );
+ theCopyGroups = false;
+ }
+ else
+ {
+ mesh_var =
+ *theMeshName ? makeMesh( theMeshName ) : SMESH::SMESH_Mesh::_duplicate( myMesh_i->_this() );
+ SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
+ tgtMesh = & mesh_i->GetImpl();
+ }
+ groupIds = getEditor().Offset( elements, theValue, tgtMesh, theCopyGroups, !myIsPreviewMode );
+
+ tgtMesh->GetMeshDS()->Modified();
+ }
+
+ if ( myIsPreviewMode )
+ {
+ getPreviewMesh()->Remove( SMESHUtils::elemSetIterator( copyElements ));
+ }
+ else
+ {
+ theGroups = theCopyGroups ? getGroups( groupIds.get() ) : new SMESH::ListOfGroups;
+
+ // result of Offset() is a tuple (mesh, groups)
+ if ( mesh_var->_is_nil() ) pyDump << myMesh_i->_this() << ", ";
+ else pyDump << mesh_var << ", ";
+ pyDump << theGroups << " = "
+ << this << ".Offset( "
+ << theValue << ", "
+ << theCopyGroups << ", "
+ << "'" << theMeshName<< "')";
+ }
+
+ return mesh_var._retn();
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+ return SMESH::SMESH_Mesh::_nil();
+}
//=======================================================================
//function : findCoincidentNodes
getEditor().ClearLastCreated();
SMESH_SequenceOfElemPtr& aSeq =
const_cast<SMESH_SequenceOfElemPtr&>( getEditor().GetLastCreatedElems() );
- for ( size_t i = 0; i < newFaces.size(); ++i )
- aSeq.Append( newFaces[i] );
+ aSeq.swap( newFaces );
TPythonDump() << this << ".FillHole( SMESH.FreeBorder(" << theHole.nodeIDs << " ))";
}
* \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.
+ * are added to the existing 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 == "".
{
getEditor().DoubleElements( elems );
- if ( strlen( theGroupName ) && !getEditor().GetLastCreatedElems().IsEmpty() )
+ if ( strlen( theGroupName ) && !getEditor().GetLastCreatedElems().empty() )
{
// group type
SMESH::ElementType type =
- SMESH::ElementType( getEditor().GetLastCreatedElems().Value(1)->GetType() );
+ SMESH::ElementType( getEditor().GetLastCreatedElems()[0]->GetType() );
// find existing group
SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
for ( size_t i = 0; i < groups->length(); ++i )
{
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) );
+ for ( size_t i = 0; i < aSeq.size(); i++ )
+ groupDS->SMDSGroup().Add( aSeq[i] );
}
}
}
if ( !CORBA::is_nil( theModifiedElems ) )
aModifiedElems = theModifiedElems->GetListOfID();
else
- {
aModifiedElems = new SMESH::long_array;
- aModifiedElems->length( 0 );
- }
TPythonDump pyDump; // suppress dump by the next line
// Create group with newly created elements
CORBA::String_var elemGroupName = theElems->GetName();
std::string aNewName = generateGroupName( std::string(elemGroupName.in()) + "_double");
- if ( !getEditor().GetLastCreatedElems().IsEmpty() && theElemGroupNeeded )
+ if ( !getEditor().GetLastCreatedElems().empty() && theElemGroupNeeded )
{
SMESH::long_array_var anIds = GetLastCreatedElems();
SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
aNewElemGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
aNewElemGroup->Add(anIds);
}
- if ( !getEditor().GetLastCreatedNodes().IsEmpty() && theNodeGroupNeeded )
+ if ( !getEditor().GetLastCreatedNodes().empty() && theNodeGroupNeeded )
{
SMESH::long_array_var anIds = GetLastCreatedNodes();
aNewNodeGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
// Create group with newly created elements
CORBA::String_var elemGroupName = theElems[0]->GetName();
std::string aNewName = generateGroupName( std::string(elemGroupName.in()) + "_double");
- if ( !getEditor().GetLastCreatedElems().IsEmpty() && theElemGroupNeeded )
+ if ( !getEditor().GetLastCreatedElems().empty() && theElemGroupNeeded )
{
SMESH::long_array_var anIds = GetLastCreatedElems();
SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
aNewElemGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
aNewElemGroup->Add(anIds);
}
- if ( !getEditor().GetLastCreatedNodes().IsEmpty() && theNodeGroupNeeded )
+ if ( !getEditor().GetLastCreatedNodes().empty() && theNodeGroupNeeded )
{
SMESH::long_array_var anIds = GetLastCreatedNodes();
aNewNodeGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
{
SMESH_TRY;
SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
- bool isEdgeGroup = false;
- bool isFaceGroup = false;
- bool isVolumeGroup = false;
- SMESH::SMESH_Group_var aNewEdgeGroup = myMesh_i->CreateGroup(SMESH::EDGE, "affectedEdges");
- SMESH::SMESH_Group_var aNewFaceGroup = myMesh_i->CreateGroup(SMESH::FACE, "affectedFaces");
- SMESH::SMESH_Group_var aNewVolumeGroup = myMesh_i->CreateGroup(SMESH::VOLUME, "affectedVolumes");
+ SMESH::SMESH_Group_var aNewEdgeGroup = SMESH::SMESH_Group::_nil();
+ SMESH::SMESH_Group_var aNewFaceGroup = SMESH::SMESH_Group::_nil();
+ SMESH::SMESH_Group_var aNewVolumeGroup = SMESH::SMESH_Group::_nil();
initData();
SMESHDS_Mesh* aMeshDS = getMeshDS();
TIDSortedElemSet anElems, aNodes;
- listOfGroupToSet(theElems, aMeshDS, anElems, false);
+ bool isNodeGrp = theElems.length() ? theElems[0]->GetType() == SMESH::NODE : false;
+ listOfGroupToSet(theElems, aMeshDS, anElems, isNodeGrp);
listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true);
TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape(theShape);
TIDSortedElemSet anAffected;
bool aResult = aMeshEditor.AffectedElemGroupsInRegion(anElems, aNodes, aShape, anAffected);
-
declareMeshModified( /*isReComputeSafe=*/ !aResult );
TPythonDump pyDump;
- if (aResult)
+ if ( aResult && anAffected.size() > 0 )
{
- int lg = anAffected.size();
SMESH::long_array_var volumeIds = new SMESH::long_array;
- volumeIds->length(lg);
- SMESH::long_array_var faceIds = new SMESH::long_array;
- faceIds->length(lg);
- SMESH::long_array_var edgeIds = new SMESH::long_array;
- edgeIds->length(lg);
+ SMESH::long_array_var faceIds = new SMESH::long_array;
+ SMESH::long_array_var edgeIds = new SMESH::long_array;
+ volumeIds->length( anAffected.size() );
+ faceIds ->length( anAffected.size() );
+ edgeIds ->length( anAffected.size() );
+
int ivol = 0;
int iface = 0;
int iedge = 0;
-
TIDSortedElemSet::const_iterator eIt = anAffected.begin();
for (; eIt != anAffected.end(); ++eIt)
{
const SMDS_MeshElement* anElem = *eIt;
- if (!anElem)
- continue;
int elemId = anElem->GetID();
- if (myMesh->GetElementType(elemId, true) == SMDSAbs_Volume)
- volumeIds[ivol++] = elemId;
- else if (myMesh->GetElementType(elemId, true) == SMDSAbs_Face)
- faceIds[iface++] = elemId;
- else if (myMesh->GetElementType(elemId, true) == SMDSAbs_Edge)
- edgeIds[iedge++] = elemId;
+ switch ( anElem->GetType() ) {
+ case SMDSAbs_Volume: volumeIds[ivol++] = elemId; break;
+ case SMDSAbs_Face: faceIds[iface++] = elemId; break;
+ case SMDSAbs_Edge: edgeIds[iedge++] = elemId; break;
+ default:;
+ }
}
volumeIds->length(ivol);
faceIds->length(iface);
edgeIds->length(iedge);
- aNewVolumeGroup->Add(volumeIds);
- aNewFaceGroup->Add(faceIds);
- aNewEdgeGroup->Add(edgeIds);
- isVolumeGroup = (aNewVolumeGroup->Size() > 0);
- isFaceGroup = (aNewFaceGroup->Size() > 0);
- isEdgeGroup = (aNewEdgeGroup->Size() > 0);
+ int nbGroups = 0;
+ if ( ivol > 0 )
+ {
+ aNewVolumeGroup = myMesh_i->CreateGroup(SMESH::VOLUME,
+ generateGroupName("affectedVolumes").c_str());
+ aNewVolumeGroup->Add(volumeIds);
+ aListOfGroups->length( nbGroups+1 );
+ aListOfGroups[ nbGroups++ ] = aNewVolumeGroup._retn();
+ }
+ if ( iface > 0 )
+ {
+ aNewFaceGroup = myMesh_i->CreateGroup(SMESH::FACE,
+ generateGroupName("affectedFaces").c_str());
+ aNewFaceGroup->Add(faceIds);
+ aListOfGroups->length( nbGroups+1 );
+ aListOfGroups[ nbGroups++ ] = aNewFaceGroup._retn();
+ }
+ if ( iedge > 0 )
+ {
+ aNewEdgeGroup = myMesh_i->CreateGroup(SMESH::EDGE,
+ generateGroupName("affectedEdges").c_str());
+ aNewEdgeGroup->Add(edgeIds);
+ aListOfGroups->length( nbGroups+1 );
+ aListOfGroups[ nbGroups++ ] = aNewEdgeGroup._retn();
+ }
}
- int nbGroups = 0;
- if (isEdgeGroup) nbGroups++;
- if (isFaceGroup) nbGroups++;
- if (isVolumeGroup) nbGroups++;
- aListOfGroups->length(nbGroups);
-
- int i = 0;
- if (isEdgeGroup) aListOfGroups[i++] = aNewEdgeGroup._retn();
- if (isFaceGroup) aListOfGroups[i++] = aNewFaceGroup._retn();
- if (isVolumeGroup) aListOfGroups[i++] = aNewVolumeGroup._retn();
-
// Update Python script
- pyDump << "[ ";
- if (isEdgeGroup) pyDump << aNewEdgeGroup << ", ";
- if (isFaceGroup) pyDump << aNewFaceGroup << ", ";
- if (isVolumeGroup) pyDump << aNewVolumeGroup << ", ";
- pyDump << "] = ";
- pyDump << this << ".AffectedElemGroupsInRegion( "
+ pyDump << aListOfGroups << " = " << this << ".AffectedElemGroupsInRegion( "
<< &theElems << ", " << &theNodesNot << ", " << theShape << " )";
return aListOfGroups._retn();
//================================================================================
/*!
\brief Generated skin mesh (containing 2D cells) from 3D mesh
- The created 2D mesh elements based on nodes of free faces of boundary volumes
+ The created 2D mesh elements based on nodes of free faces of boundary volumes
\return TRUE if operation has been completed successfully, FALSE otherwise
*/
//================================================================================