#include "SMESH_Gen_i.hxx"
#include "SMESH_Filter_i.hxx"
#include "SMESH_PythonDump.hxx"
-#include "CASCatch.hxx"
#include "utilities.h"
-
+#include "Utils_ExceptHandlers.hxx"
+#include "Utils_CorbaException.hxx"
+
+#include <BRepAdaptor_Surface.hxx>
+#include <BRep_Tool.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>
#include <gp_Vec.hxx>
#ifdef NO_CAS_CATCH
#include <Standard_ErrorHandler.hxx>
-#else
-#include "CASCatch.hxx"
#endif
#include <sstream>
return 0;
}
+//=============================================================================
+/*!
+ * \brief Bind a node to a vertex
+ * \param NodeID - node ID
+ * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
+ * \retval boolean - false if NodeID or VertexID is invalid
+ */
+//=============================================================================
+
+void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ SMESHDS_Mesh * mesh = GetMeshDS();
+ SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
+ if ( !node )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
+
+ if ( mesh->MaxShapeIndex() < VertexID )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
+
+ TopoDS_Shape shape = mesh->IndexToShape( VertexID );
+ if ( shape.ShapeType() != TopAbs_VERTEX )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
+
+ mesh->SetNodeOnVertex( node, VertexID );
+}
+
+//=============================================================================
+/*!
+ * \brief Store node position on an edge
+ * \param NodeID - node ID
+ * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
+ * \param paramOnEdge - parameter on edge where the node is located
+ * \retval boolean - false if any parameter is invalid
+ */
+//=============================================================================
+
+void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
+ CORBA::Double paramOnEdge)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ SMESHDS_Mesh * mesh = GetMeshDS();
+ SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
+ if ( !node )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
+
+ if ( mesh->MaxShapeIndex() < EdgeID )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
+
+ TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
+ if ( shape.ShapeType() != TopAbs_EDGE )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
+
+ Standard_Real f,l;
+ BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
+ if ( paramOnEdge < f || paramOnEdge > l )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
+
+ mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
+}
+
+//=============================================================================
+/*!
+ * \brief Store node position on a face
+ * \param NodeID - node ID
+ * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
+ * \param u - U parameter on face where the node is located
+ * \param v - V parameter on face where the node is located
+ * \retval boolean - false if any parameter is invalid
+ */
+//=============================================================================
+
+void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
+ CORBA::Double u, CORBA::Double v)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ SMESHDS_Mesh * mesh = GetMeshDS();
+ SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
+ if ( !node )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
+
+ if ( mesh->MaxShapeIndex() < FaceID )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
+
+ TopoDS_Shape shape = mesh->IndexToShape( FaceID );
+ if ( shape.ShapeType() != TopAbs_FACE )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
+
+ BRepAdaptor_Surface surf( TopoDS::Face( shape ));
+ bool isOut = ( u < surf.FirstUParameter() ||
+ u > surf.LastUParameter() ||
+ v < surf.FirstVParameter() ||
+ v > surf.LastVParameter() );
+
+ if ( isOut ) {
+#ifdef _DEBUG_
+ cout << "FACE " << FaceID << " (" << u << "," << v << ") out of "
+ << " u( " << surf.FirstUParameter()
+ << "," << surf.LastUParameter()
+ << ") v( " << surf.FirstVParameter()
+ << "," << surf.LastVParameter()
+ << ")" << endl;
+#endif
+ THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
+ }
+
+ mesh->SetNodeOnFace( node, FaceID, u, v );
+}
+
+//=============================================================================
+/*!
+ * \brief Bind a node to a solid
+ * \param NodeID - node ID
+ * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
+ * \retval boolean - false if NodeID or SolidID is invalid
+ */
+//=============================================================================
+
+void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ SMESHDS_Mesh * mesh = GetMeshDS();
+ SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
+ if ( !node )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
+
+ if ( mesh->MaxShapeIndex() < SolidID )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
+
+ TopoDS_Shape shape = mesh->IndexToShape( SolidID );
+ if ( shape.ShapeType() != TopAbs_SOLID &&
+ shape.ShapeType() != TopAbs_SHELL)
+ THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
+
+ mesh->SetNodeInVolume( node, SolidID );
+}
+
+//=============================================================================
+/*!
+ * \brief Bind an element to a shape
+ * \param ElementID - element ID
+ * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
+ * \retval boolean - false if ElementID or ShapeID is invalid
+ */
+//=============================================================================
+
+void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
+ CORBA::Long ShapeID)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ SMESHDS_Mesh * mesh = GetMeshDS();
+ SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
+ if ( !elem )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
+
+ if ( mesh->MaxShapeIndex() < ShapeID )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
+
+ TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
+ if ( shape.ShapeType() != TopAbs_EDGE &&
+ shape.ShapeType() != TopAbs_FACE &&
+ shape.ShapeType() != TopAbs_SOLID &&
+ shape.ShapeType() != TopAbs_SHELL )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
+
+ mesh->SetMeshElementOnShape( elem, ShapeID );
+}
+
+
//=============================================================================
/*!
*
{
initData();
-#ifdef NO_CAS_CATCH
try {
+#ifdef NO_CAS_CATCH
OCC_CATCH_SIGNALS;
-#else
- CASCatch_TRY {
#endif
TIDSortedElemSet elements;
arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
return theMakeGroups ? getGroups(groupIds.get()) : 0;
-#ifdef NO_CAS_CATCH
} catch(Standard_Failure) {
-#else
- } CASCatch_CATCH(Standard_Failure) {
-#endif
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
}
const SMESH::AxisStruct & theAxis,
SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
CORBA::Boolean theCopy,
- const bool theMakeGroups)
+ const bool theMakeGroups,
+ ::SMESH_Mesh* theTargetMesh)
{
initData();
::SMESH_MeshEditor anEditor( myMesh );
::SMESH_MeshEditor::PGroupIDs groupIds =
- anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups);
+ anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
if(theCopy) {
storeResult(anEditor);
return mirror(anElementsId, theMirror, theMirrorType, true, true);
}
+//=======================================================================
+//function : MirrorMakeMesh
+//purpose :
+//=======================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
+ const SMESH::AxisStruct& theMirror,
+ SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
+ CORBA::Boolean theCopyGroups,
+ const char* theMeshName)
+{
+ TPythonDump pydump; // to prevent dump at mesh creation
+
+ SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
+ if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh ))
+ {
+ mirror(theIDsOfElements, theMirror, theMirrorType,
+ false, theCopyGroups, & mesh_i->GetImpl());
+ mesh_i->CreateGroupServants();
+ }
+
+ if ( !myPreviewMode ) {
+ pydump << mesh << " = " << this << ".MirrorMakeMesh( "
+ << theIDsOfElements << ", "
+ << theMirror << ", "
+ << mirrorTypeName(theMirrorType) << ", "
+ << theCopyGroups << ", '"
+ << theMeshName << "' )";
+ }
+ return mesh._retn();
+}
+
+//=======================================================================
+//function : MirrorObjectMakeMesh
+//purpose :
+//=======================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
+ const SMESH::AxisStruct& theMirror,
+ SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
+ CORBA::Boolean theCopyGroups,
+ const char* theMeshName)
+{
+ TPythonDump pydump; // to prevent dump at mesh creation
+
+ SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
+ if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh ))
+ {
+ SMESH::long_array_var anElementsId = theObject->GetIDs();
+ mirror(anElementsId, theMirror, theMirrorType,
+ false, theCopyGroups, & mesh_i->GetImpl());
+ mesh_i->CreateGroupServants();
+ }
+ if ( !myPreviewMode ) {
+ pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
+ << theObject << ", "
+ << theMirror << ", "
+ << mirrorTypeName(theMirrorType) << ", "
+ << theCopyGroups << ", '"
+ << theMeshName << "' )";
+ }
+ return mesh._retn();
+}
//=======================================================================
//function : translate
SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
const SMESH::DirStruct & theVector,
CORBA::Boolean theCopy,
- const bool theMakeGroups)
+ const bool theMakeGroups,
+ ::SMESH_Mesh* theTargetMesh)
{
initData();
::SMESH_MeshEditor anEditor( myMesh );
::SMESH_MeshEditor::PGroupIDs groupIds =
- anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups);
+ anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
if(theCopy)
storeResult(anEditor);
const SMESH::DirStruct& theVector)
{
if ( !myPreviewMode ) {
+ TPythonDump() << "vector = " << theVector;
TPythonDump() << this << ".TranslateObjectMakeGroups( "
<< theObject
<< ", vector )";
return translate(anElementsId, theVector, true, true);
}
+//=======================================================================
+//function : TranslateMakeMesh
+//purpose :
+//=======================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
+ const SMESH::DirStruct& theVector,
+ CORBA::Boolean theCopyGroups,
+ const char* theMeshName)
+{
+ TPythonDump pydump; // to prevent dump at mesh creation
+ SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
+
+ if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
+ translate(theIDsOfElements, theVector,
+ false, theCopyGroups, & mesh_i->GetImpl());
+ mesh_i->CreateGroupServants();
+ }
+ if ( !myPreviewMode ) {
+ pydump << mesh << " = " << this << ".TranslateMakeMesh( "
+ << theIDsOfElements << ", "
+ << theVector << ", "
+ << theCopyGroups << ", '"
+ << theMeshName << "' )";
+ }
+ return mesh._retn();
+}
+
+//=======================================================================
+//function : TranslateObjectMakeMesh
+//purpose :
+//=======================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
+ const SMESH::DirStruct& theVector,
+ CORBA::Boolean theCopyGroups,
+ const char* theMeshName)
+{
+ TPythonDump pydump; // to prevent dump at mesh creation
+ SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
+
+ if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
+ SMESH::long_array_var anElementsId = theObject->GetIDs();
+ translate(anElementsId, theVector,
+ false, theCopyGroups, & mesh_i->GetImpl());
+ mesh_i->CreateGroupServants();
+ }
+ if ( !myPreviewMode ) {
+ pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
+ << theObject << ", "
+ << theVector << ", "
+ << theCopyGroups << ", '"
+ << theMeshName << "' )";
+ }
+ return mesh._retn();
+}
+
//=======================================================================
//function : rotate
//purpose :
const SMESH::AxisStruct & theAxis,
CORBA::Double theAngle,
CORBA::Boolean theCopy,
- const bool theMakeGroups)
+ const bool theMakeGroups,
+ ::SMESH_Mesh* theTargetMesh)
{
initData();
::SMESH_MeshEditor anEditor( myMesh );
::SMESH_MeshEditor::PGroupIDs groupIds =
- anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups);
+ anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
if(theCopy) {
storeResult(anEditor);
return rotate(anElementsId,theAxis,theAngle,true,true);
}
+//=======================================================================
+//function : RotateMakeMesh
+//purpose :
+//=======================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
+ const SMESH::AxisStruct& theAxis,
+ CORBA::Double theAngleInRadians,
+ CORBA::Boolean theCopyGroups,
+ const char* theMeshName)
+{
+ TPythonDump pydump; // to prevent dump at mesh creation
+ SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
+
+ if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
+ rotate(theIDsOfElements, theAxis, theAngleInRadians,
+ false, theCopyGroups, & mesh_i->GetImpl());
+ mesh_i->CreateGroupServants();
+ }
+ if ( !myPreviewMode ) {
+ pydump << mesh << " = " << this << ".RotateMakeMesh( "
+ << theIDsOfElements << ", "
+ << theAxis << ", "
+ << theAngleInRadians << ", "
+ << theCopyGroups << ", '"
+ << theMeshName << "' )";
+ }
+ return mesh._retn();
+}
+
+//=======================================================================
+//function : RotateObjectMakeMesh
+//purpose :
+//=======================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
+ const SMESH::AxisStruct& theAxis,
+ CORBA::Double theAngleInRadians,
+ CORBA::Boolean theCopyGroups,
+ const char* theMeshName)
+{
+ TPythonDump pydump; // to prevent dump at mesh creation
+ SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName );
+
+ if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh )) {
+ SMESH::long_array_var anElementsId = theObject->GetIDs();
+ rotate(anElementsId, theAxis, theAngleInRadians,
+ false, theCopyGroups, & mesh_i->GetImpl());
+ mesh_i->CreateGroupServants();
+ }
+ if ( !myPreviewMode ) {
+ pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
+ << theObject << ", "
+ << theAxis << ", "
+ << theAngleInRadians << ", "
+ << theCopyGroups << ", '"
+ << theMeshName << "' )";
+ }
+ return mesh._retn();
+}
+
//=======================================================================
//function : FindCoincidentNodes
//purpose :
TPythonDump() << this << ".ConvertFromQuadratic()";
return isDone;
}
+
+//=======================================================================
+//function : makeMesh
+//purpose : create a named imported mesh
+//=======================================================================
+
+SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
+{
+ SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
+ SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
+ SALOMEDS::Study_var study = gen->GetCurrentStudy();
+ SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
+ gen->SetName( meshSO, theMeshName, "Mesh" );
+
+ SALOMEDS::StudyBuilder_var builder = study->NewBuilder();
+ SALOMEDS::GenericAttribute_var anAttr
+ = builder->FindOrCreateAttribute( meshSO, "AttributePixMap" );
+ SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
+
+ return mesh._retn();
+}