#include "SMDS_MeshFace.hxx"
#include "SMDS_MeshVolume.hxx"
#include "SMDS_PolyhedralVolumeOfNodes.hxx"
-#include "SMESH_MeshEditor.hxx"
#include "SMESH_subMeshEventListener.hxx"
#include "SMESH_Gen_i.hxx"
#include "SMESH_Filter_i.hxx"
#endif
#include <sstream>
+#include <limits>
#define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
*/
//================================================================================
- void idSourceToSet(SMESH::SMESH_IDSource_ptr theIDSource,
+ bool idSourceToSet(SMESH::SMESH_IDSource_ptr theIDSource,
const SMESHDS_Mesh* theMeshDS,
TIDSortedElemSet& theElemSet,
- const SMDSAbs_ElementType theType)
+ const SMDSAbs_ElementType theType,
+ const bool emptyIfIsMesh=false)
{
if ( CORBA::is_nil( theIDSource ) )
- return;
+ return false;
+ if ( emptyIfIsMesh && SMESH::DownCast<SMESH_Mesh_i*>( theIDSource ))
+ return true;
+
SMESH::long_array_var anIDs = theIDSource->GetIDs();
- arrayToSet( anIDs, theMeshDS, theElemSet, theType);
+ if ( anIDs->length() == 0 )
+ return false;
+ SMESH::array_of_ElementType_var types = theIDSource->GetTypes();
+ if ( types->length() == 1 && types[0] == SMESH::NODE ) // group of nodes
+ {
+ if ( theType == SMDSAbs_All || theType == SMDSAbs_Node )
+ arrayToSet( anIDs, theMeshDS, theElemSet, SMDSAbs_Node );
+ else
+ return false;
+ }
+ else
+ {
+ arrayToSet( anIDs, theMeshDS, theElemSet, theType);
+ }
+ return true;
}
//================================================================================
/*!
//=======================================================================
SMESH::ListOfGroups*
-SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements,
+SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements,
const SMESH::AxisStruct & theAxis,
SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
CORBA::Boolean theCopy,
{
initData();
- TIDSortedElemSet elements;
- arrayToSet(theIDsOfElements, GetMeshDS(), elements);
-
gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
::SMESH_MeshEditor anEditor( myMesh );
::SMESH_MeshEditor::PGroupIDs groupIds =
- anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
+ anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
if(theCopy)
storeResult(anEditor);
<< mirrorTypeName(theMirrorType) << ", "
<< theCopy << " )";
}
- mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
+ if ( theIDsOfElements.length() > 0 )
+ {
+ TIDSortedElemSet elements;
+ arrayToSet(theIDsOfElements, GetMeshDS(), elements);
+ mirror(elements, theAxis, theMirrorType, theCopy, false);
+ }
}
<< mirrorTypeName(theMirrorType) << ", "
<< theCopy << " )";
}
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
+ TIDSortedElemSet elements;
+ if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
+ mirror(elements, theAxis, theMirrorType, theCopy, false);
}
//=======================================================================
const SMESH::AxisStruct& theMirror,
SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
{
- SMESH::ListOfGroups * aGroups = mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
+ SMESH::ListOfGroups * aGroups = 0;
+ if ( theIDsOfElements.length() > 0 )
+ {
+ TIDSortedElemSet elements;
+ arrayToSet(theIDsOfElements, GetMeshDS(), elements);
+ aGroups = mirror(elements, theMirror, theMirrorType, true, true);
+ }
if ( !myPreviewMode ) {
TPythonDump aPythonDump;
DumpGroupsList(aPythonDump,aGroups);
const SMESH::AxisStruct& theMirror,
SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
{
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- SMESH::ListOfGroups * aGroups = mirror(anElementsId, theMirror, theMirrorType, true, true);
- if ( !myPreviewMode ) {
+ SMESH::ListOfGroups * aGroups = 0;
+ TIDSortedElemSet elements;
+ if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
+ aGroups = mirror(elements, theMirror, theMirrorType, true, true);
+
+ if ( !myPreviewMode )
+ {
TPythonDump aPythonDump;
DumpGroupsList(aPythonDump,aGroups);
aPythonDump << this << ".MirrorObjectMakeGroups( "
mesh = makeMesh( theMeshName );
mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
- if (mesh_i) {
- mirror(theIDsOfElements, theMirror, theMirrorType,
+ if (mesh_i && theIDsOfElements.length() > 0 )
+ {
+ TIDSortedElemSet elements;
+ arrayToSet(theIDsOfElements, GetMeshDS(), elements);
+ mirror(elements, theMirror, theMirrorType,
false, theCopyGroups, & mesh_i->GetImpl());
mesh_i->CreateGroupServants();
}
mesh = makeMesh( theMeshName );
mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
- if ( mesh_i ) {
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- mirror(anElementsId, theMirror, theMirrorType,
+ TIDSortedElemSet elements;
+ if ( mesh_i &&
+ idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
+ {
+ mirror(elements, theMirror, theMirrorType,
false, theCopyGroups, & mesh_i->GetImpl());
mesh_i->CreateGroupServants();
}
-
if ( !myPreviewMode ) {
pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
<< theObject << ", "
<< theCopyGroups << ", '"
<< theMeshName << "' )";
}
- }
+ }
//dump "GetGroups"
if(!myPreviewMode && mesh_i)
//=======================================================================
SMESH::ListOfGroups*
-SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
+SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements,
const SMESH::DirStruct & theVector,
CORBA::Boolean theCopy,
const bool theMakeGroups,
{
initData();
- TIDSortedElemSet elements;
- arrayToSet(theIDsOfElements, GetMeshDS(), elements);
-
gp_Trsf aTrsf;
const SMESH::PointStruct * P = &theVector.PS;
aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
::SMESH_MeshEditor anEditor( myMesh );
::SMESH_MeshEditor::PGroupIDs groupIds =
- anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
+ anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
if(theCopy)
storeResult(anEditor);
<< theVector << ", "
<< theCopy << " )";
}
- translate(theIDsOfElements,
- theVector,
- theCopy,
- false);
+ if ( theIDsOfElements.length() )
+ {
+ TIDSortedElemSet elements;
+ arrayToSet(theIDsOfElements, GetMeshDS(), elements);
+ translate(elements,theVector,theCopy,false);
+ }
}
//=======================================================================
<< theVector << ", "
<< theCopy << " )";
}
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- translate(anElementsId,
- theVector,
- theCopy,
- false);
+ TIDSortedElemSet elements;
+ if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
+ translate( elements, theVector, theCopy, false);
}
//=======================================================================
SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
const SMESH::DirStruct& theVector)
{
- SMESH::ListOfGroups * aGroups = translate(theIDsOfElements,theVector,true,true);
+ SMESH::ListOfGroups * aGroups = 0;
+ if ( theIDsOfElements.length() )
+ {
+ TIDSortedElemSet elements;
+ arrayToSet(theIDsOfElements, GetMeshDS(), elements);
+ aGroups = translate(elements,theVector,true,true);
+ }
if ( !myPreviewMode ) {
TPythonDump aPythonDump;
DumpGroupsList(aPythonDump,aGroups);
SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
const SMESH::DirStruct& theVector)
{
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- SMESH::ListOfGroups * aGroups = translate(anElementsId, theVector, true, true);
+ SMESH::ListOfGroups * aGroups = 0;
+ TIDSortedElemSet elements;
+ if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
+ aGroups = translate(elements, theVector, true, true);
if ( !myPreviewMode ) {
mesh = makeMesh( theMeshName );
mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
- if ( mesh_i ) {
- translate(theIDsOfElements, theVector,
- false, theCopyGroups, & mesh_i->GetImpl());
+ if ( mesh_i && theIDsOfElements.length() )
+ {
+ TIDSortedElemSet elements;
+ arrayToSet(theIDsOfElements, GetMeshDS(), elements);
+ translate(elements, theVector, false, theCopyGroups, & mesh_i->GetImpl());
mesh_i->CreateGroupServants();
}
mesh = makeMesh( theMeshName );
mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
- if ( mesh_i ) {
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- translate(anElementsId, theVector,
- false, theCopyGroups, & mesh_i->GetImpl());
+ TIDSortedElemSet elements;
+ if ( mesh_i &&
+ idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
+ {
+ translate(elements, theVector,false, theCopyGroups, & mesh_i->GetImpl());
mesh_i->CreateGroupServants();
}
if ( !myPreviewMode ) {
//=======================================================================
SMESH::ListOfGroups*
-SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
+SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements,
const SMESH::AxisStruct & theAxis,
CORBA::Double theAngle,
CORBA::Boolean theCopy,
{
initData();
- TIDSortedElemSet elements;
- arrayToSet(theIDsOfElements, GetMeshDS(), elements);
-
gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
::SMESH_MeshEditor anEditor( myMesh );
::SMESH_MeshEditor::PGroupIDs groupIds =
- anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
+ anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
if(theCopy)
storeResult(anEditor);
<< theAngle << ", "
<< theCopy << " )";
}
- rotate(theIDsOfElements,
- theAxis,
- theAngle,
- theCopy,
- false);
+ if ( theIDsOfElements.length() > 0 )
+ {
+ TIDSortedElemSet elements;
+ arrayToSet(theIDsOfElements, GetMeshDS(), elements);
+ rotate(elements,theAxis,theAngle,theCopy,false);
+ }
}
//=======================================================================
<< theAngle << ", "
<< theCopy << " )";
}
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- rotate(anElementsId,
- theAxis,
- theAngle,
- theCopy,
- false);
+ TIDSortedElemSet elements;
+ if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
+ rotate(elements,theAxis,theAngle,theCopy,false);
}
//=======================================================================
const SMESH::AxisStruct& theAxis,
CORBA::Double theAngle)
{
- SMESH::ListOfGroups * aGroups = rotate(theIDsOfElements,theAxis,theAngle,true,true);
+ SMESH::ListOfGroups * aGroups = 0;
+ if ( theIDsOfElements.length() > 0 )
+ {
+ TIDSortedElemSet elements;
+ arrayToSet(theIDsOfElements, GetMeshDS(), elements);
+ aGroups = rotate(elements,theAxis,theAngle,true,true);
+ }
if ( !myPreviewMode ) {
TPythonDump aPythonDump;
DumpGroupsList(aPythonDump,aGroups);
const SMESH::AxisStruct& theAxis,
CORBA::Double theAngle)
{
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- SMESH::ListOfGroups * aGroups = rotate(anElementsId,theAxis,theAngle,true,true);
+ SMESH::ListOfGroups * aGroups = 0;
+ TIDSortedElemSet elements;
+ if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
+ aGroups = rotate(elements,theAxis,theAngle,true,true);
if ( !myPreviewMode ) {
TPythonDump aPythonDump;
mesh = makeMesh( theMeshName );
mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
- if ( mesh_i ) {
- rotate(theIDsOfElements, theAxis, theAngleInRadians,
+ if ( mesh_i && theIDsOfElements.length() > 0 )
+ {
+ TIDSortedElemSet elements;
+ arrayToSet(theIDsOfElements, GetMeshDS(), elements);
+ rotate(elements, theAxis, theAngleInRadians,
false, theCopyGroups, & mesh_i->GetImpl());
mesh_i->CreateGroupServants();
}
}
//dump "GetGroups"
- if(!myPreviewMode && mesh_i)
+ if(!myPreviewMode && mesh_i && theIDsOfElements.length() > 0 )
mesh_i->GetGroups();
return mesh._retn();
//purpose :
//=======================================================================
-SMESH::SMESH_Mesh_ptr
+SMESH::SMESH_Mesh_ptr
SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
const SMESH::AxisStruct& theAxis,
CORBA::Double theAngleInRadians,
mesh = makeMesh( theMeshName );
mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
- if (mesh_i ) {
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- rotate(anElementsId, theAxis, theAngleInRadians,
+ TIDSortedElemSet elements;
+ if (mesh_i &&
+ idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
+ {
+ rotate(elements, theAxis, theAngleInRadians,
false, theCopyGroups, & mesh_i->GetImpl());
mesh_i->CreateGroupServants();
}
return mesh._retn();
}
-
//=======================================================================
//function : scale
//purpose :
//=======================================================================
SMESH::ListOfGroups*
-SMESH_MeshEditor_i::scale(const SMESH::long_array & theIDsOfElements,
+SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject,
const SMESH::PointStruct& thePoint,
const SMESH::double_array& theScaleFact,
CORBA::Boolean theCopy,
::SMESH_Mesh* theTargetMesh)
{
initData();
+ if ( theScaleFact.length() < 1 )
+ THROW_SALOME_CORBA_EXCEPTION("Scale factor not given", SALOME::BAD_PARAM);
+ if ( theScaleFact.length() == 2 )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM);
TIDSortedElemSet elements;
- arrayToSet(theIDsOfElements, GetMeshDS(), elements);
+ if ( !idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/true))
+ return 0;
- gp_Pnt aPnt( thePoint.x, thePoint.y, thePoint.z );
- list<double> aScaleFact;
- for (int i = 0; i < theScaleFact.length(); i++) {
- aScaleFact.push_back( theScaleFact[i] );
- }
+ vector<double> S(3);
+ S[0] = theScaleFact[0];
+ S[1] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1];
+ S[2] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2];
+ double tol = std::numeric_limits<double>::max();
+ gp_Trsf aTrsf;
+ aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]),
+ 0, S[1], 0, thePoint.y * (1-S[1]),
+ 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol);
::SMESH_MeshEditor anEditor( myMesh );
::SMESH_MeshEditor::PGroupIDs groupIds =
- anEditor.Scale (elements, aPnt, aScaleFact, theCopy,
- theMakeGroups, theTargetMesh);
+ anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
if(theCopy)
storeResult(anEditor);
return theMakeGroups ? getGroups(groupIds.get()) : 0;
}
-
//=======================================================================
//function : Scale
//purpose :
<< theScaleFact << ", "
<< theCopy << " )";
}
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- scale(anElementsId, thePoint, theScaleFact, theCopy, false);
+ scale(theObject, thePoint, theScaleFact, theCopy, false);
}
const SMESH::PointStruct& thePoint,
const SMESH::double_array& theScaleFact)
{
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- SMESH::ListOfGroups * aGroups =
- scale(anElementsId, thePoint, theScaleFact, true, true);
-
+ SMESH::ListOfGroups * aGroups = scale(theObject, thePoint, theScaleFact, true, true);
if ( !myPreviewMode ) {
TPythonDump aPythonDump;
mesh = makeMesh( theMeshName );
mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
- if ( mesh_i ) {
- SMESH::long_array_var anElementsId = theObject->GetIDs();
- scale(anElementsId, thePoint, theScaleFact,
- false, theCopyGroups, & mesh_i->GetImpl());
+ if ( mesh_i )
+ {
+ scale(theObject, thePoint, theScaleFact,false, theCopyGroups, & mesh_i->GetImpl());
mesh_i->CreateGroupServants();
}
- if ( !myPreviewMode ) {
+ if ( !myPreviewMode )
pydump << mesh << " = " << this << ".ScaleMakeMesh( "
<< theObject << ", "
<< "SMESH.PointStruct( " << thePoint.x << ", "
<< theScaleFact << ", "
<< theCopyGroups << ", '"
<< theMeshName << "' )";
- }
}
//dump "GetGroups"