From: eap Date: Thu, 15 Nov 2007 14:36:00 +0000 (+0000) Subject: PAL17694 (New Tool About Hexahedral Meshing) X-Git-Tag: V4_1_0rc2~27 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cf05ada8f4a7c685749d86fd6629ca31a61579eb;p=modules%2Fsmesh.git PAL17694 (New Tool About Hexahedral Meshing) + void SetNodeOnVertex(in long NodeID, in long VertexID) + void SetNodeOnEdge(in long NodeID, in long EdgeID, in double paramOnEdge) + void SetNodeOnFace(in long NodeID, in long FaceID, in double u, in double v) + void SetNodeInVolume(in long NodeID, in long SolidID) + void SetMeshElementOnShape(in long ElementID, in long ShapeID) --- diff --git a/idl/SMESH_MeshEditor.idl b/idl/SMESH_MeshEditor.idl index a080e19d5..f5a8cc421 100644 --- a/idl/SMESH_MeshEditor.idl +++ b/idl/SMESH_MeshEditor.idl @@ -106,6 +106,46 @@ module SMESH */ long AddPolyhedralVolumeByFaces (in long_array IdsOfFaces); + /*! + * \brief Bind a node to a vertex + * \param NodeID - node ID + * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0] + */ + void SetNodeOnVertex(in long NodeID, in long VertexID) + raises (SALOME::SALOME_Exception); + /*! + * \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 + */ + void SetNodeOnEdge(in long NodeID, in long EdgeID, in double paramOnEdge) + raises (SALOME::SALOME_Exception); + /*! + * \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 + */ + void SetNodeOnFace(in long NodeID, in long FaceID, in double u, in double v) + raises (SALOME::SALOME_Exception); + /*! + * \brief Bind a node to a solid + * \param NodeID - node ID + * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0] + */ + void SetNodeInVolume(in long NodeID, in long SolidID) + raises (SALOME::SALOME_Exception); + /*! + * \brief Bind an element to a shape + * \param ElementID - element ID + * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0] + */ + void SetMeshElementOnShape(in long ElementID, in long ShapeID) + raises (SALOME::SALOME_Exception); + + boolean MoveNode(in long NodeID, in double x, in double y, in double z); boolean InverseDiag(in long NodeID1, in long NodeID2); diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index c83334fa5..77914d16e 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -37,10 +37,18 @@ #include "SMESH_Gen_i.hxx" #include "SMESH_Filter_i.hxx" #include "SMESH_PythonDump.hxx" -#include "CASCatch.hxx" +#include "CASCatch.hxx" #include "utilities.h" - +#include "Utils_ExceptHandlers.hxx" +#include "Utils_CorbaException.hxx" + +#include +#include +#include +#include +#include +#include #include #include #include @@ -565,6 +573,185 @@ CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces 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( 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( 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( 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( 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(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 ); +} + + //============================================================================= /*! * diff --git a/src/SMESH_I/SMESH_MeshEditor_i.hxx b/src/SMESH_I/SMESH_MeshEditor_i.hxx index fbc8c01ac..b3b381109 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.hxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.hxx @@ -65,6 +65,48 @@ class SMESH_MeshEditor_i: public POA_SMESH::SMESH_MeshEditor const SMESH::long_array & Quantities); CORBA::Long AddPolyhedralVolumeByFaces(const SMESH::long_array & IdsOfFaces); + /*! + * \brief Bind a node to a vertex + * \param NodeID - node ID + * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0] + */ + void SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID) + throw (SALOME::SALOME_Exception); + /*! + * \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 + */ + void SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID, + CORBA::Double paramOnEdge) + throw (SALOME::SALOME_Exception); + /*! + * \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 + */ + void SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID, + CORBA::Double u, CORBA::Double v) + throw (SALOME::SALOME_Exception); + /*! + * \brief Bind a node to a solid + * \param NodeID - node ID + * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0] + */ + void SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID) + throw (SALOME::SALOME_Exception); + /*! + * \brief Bind an element to a shape + * \param ElementID - element ID + * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0] + */ + void SetMeshElementOnShape(CORBA::Long ElementID, CORBA::Long ShapeID) + throw (SALOME::SALOME_Exception); + + CORBA::Boolean MoveNode(CORBA::Long NodeID, CORBA::Double x, CORBA::Double y, CORBA::Double z); diff --git a/src/SMESH_SWIG/smeshDC.py b/src/SMESH_SWIG/smeshDC.py index a50e23fdb..47a75203a 100644 --- a/src/SMESH_SWIG/smeshDC.py +++ b/src/SMESH_SWIG/smeshDC.py @@ -496,7 +496,7 @@ class Mesh_Algorithm: CreateNew = 1 if UseExisting: hypo = self.FindHypothesis(hyp, args) - if hypo!=None: CreateNew = 0 + if hypo: CreateNew = 0 pass if CreateNew: hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so) @@ -1318,6 +1318,26 @@ class Mesh_RadialPrism3D(Mesh_Algorithm): hyp.SetFineness( fineness ) return hyp +# Private class: Mesh_UseExisting +# ------------------------------- +class Mesh_UseExisting(Mesh_Algorithm): + + algo1D = 0 # StdMeshers_UseExisting_1D object common for all Mesh_UseExisting + algo2D = 0 # StdMeshers_UseExisting_2D object common for all Mesh_UseExisting + + def __init__(self, dim, mesh, geom=0): + if dim == 1: + if not Mesh_UseExisting.algo1D: + Mesh_UseExisting.algo1D= self.Create(mesh, geom, "UseExisting_1D") + else: + self.Assign( Mesh_UseExisting.algo1D, mesh, geom) + pass + else: + if not Mesh_UseExisting.algo2D: + Mesh_UseExisting.algo2D= self.Create(mesh, geom, "UseExisting_2D") + else: + self.Assign( Mesh_UseExisting.algo2D, mesh, geom) + pass # Public class: Mesh # ================== @@ -1454,6 +1474,28 @@ class Mesh: else: return Mesh_Segment(self, geom) + ## Enable creation of nodes and segments usable by 2D algoritms. + # Added nodes and segments must be bound to edges and vertices by + # SetNodeOnVertex(), SetNodeOnEdge() and SetMeshElementOnShape() + # If the optional \a geom parameter is not sets, this algorithm is global. + # \n Otherwise, this algorithm define a submesh based on \a geom subshape. + # @param geom subshape to be manually meshed + # @return StdMeshers_UseExisting_1D algorithm that generates nothing + def UseExistingSegments(self, geom=0): + algo = Mesh_UseExisting(1,self,geom) + return algo.GetAlgorithm() + + ## Enable creation of nodes and faces usable by 3D algoritms. + # Added nodes and faces must be bound to geom faces by SetNodeOnFace() + # and SetMeshElementOnShape() + # If the optional \a geom parameter is not sets, this algorithm is global. + # \n Otherwise, this algorithm define a submesh based on \a geom subshape. + # @param geom subshape to be manually meshed + # @return StdMeshers_UseExisting_2D algorithm that generates nothing + def UseExistingFaces(self, geom=0): + algo = Mesh_UseExisting(2,self,geom) + return algo.GetAlgorithm() + ## Creates a triangle 2D algorithm for faces. # If the optional \a geom parameter is not sets, this algorithm is global. # \n Otherwise, this algorithm define a submesh based on \a geom subshape. @@ -2069,19 +2111,34 @@ class Mesh: return self.mesh.GetElementType(id, iselem) ## Returns list of submesh elements ids - # @param shapeID is geom object(subshape) IOR - def GetSubMeshElementsId(self, shapeID): - return self.mesh.GetSubMeshElementsId(shapeID) + # @param Shape is geom object(subshape) IOR + # Shape must be subshape of a ShapeToMesh() + def GetSubMeshElementsId(self, Shape): + if ( isinstance( Shape, geompy.GEOM._objref_GEOM_Object)): + ShapeID = Shape.GetSubShapeIndices()[0] + else: + ShapeID = Shape + return self.mesh.GetSubMeshElementsId(ShapeID) ## Returns list of submesh nodes ids - # @param shapeID is geom object(subshape) IOR - def GetSubMeshNodesId(self, shapeID, all): - return self.mesh.GetSubMeshNodesId(shapeID, all) + # @param Shape is geom object(subshape) IOR + # Shape must be subshape of a ShapeToMesh() + def GetSubMeshNodesId(self, Shape, all): + if ( isinstance( Shape, geompy.GEOM._objref_GEOM_Object)): + ShapeID = Shape.GetSubShapeIndices()[0] + else: + ShapeID = Shape + return self.mesh.GetSubMeshNodesId(ShapeID, all) ## Returns list of ids of submesh elements with given type - # @param shapeID is geom object(subshape) IOR - def GetSubMeshElementType(self, shapeID): - return self.mesh.GetSubMeshElementType(shapeID) + # @param Shape is geom object(subshape) IOR + # Shape must be subshape of a ShapeToMesh() + def GetSubMeshElementType(self, Shape): + if ( isinstance( Shape, geompy.GEOM._objref_GEOM_Object)): + ShapeID = Shape.GetSubShapeIndices()[0] + else: + ShapeID = Shape + return self.mesh.GetSubMeshElementType(ShapeID) ## Get mesh description def Dump(self): @@ -2101,6 +2158,11 @@ class Mesh: def GetNodeInverseElements(self, id): return self.mesh.GetNodeInverseElements(id) + ## @brief Return position of a node on shape + # @return SMESH::NodePosition + def GetNodePosition(self,NodeID): + return self.mesh.GetNodePosition(NodeID) + ## If given element is node returns IDs of shape from position # \n If there is not node for given ID - returns -1 def GetShapeID(self, id): @@ -2224,6 +2286,87 @@ class Mesh: def AddPolyhedralVolumeByFaces (self, IdsOfFaces): return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces) + + ## @brief Bind a node to a vertex + # @param NodeID - node ID + # @param Vertex - vertex or vertex ID + # @return True if succeed else raise an exception + def SetNodeOnVertex(self, NodeID, Vertex): + if ( isinstance( Vertex, geompy.GEOM._objref_GEOM_Object)): + VertexID = Vertex.GetSubShapeIndices()[0] + else: + VertexID = Vertex + try: + self.editor.SetNodeOnVertex(NodeID, VertexID) + except SALOME.SALOME_Exception, inst: + raise ValueError, inst.details.text + return True + + + ## @brief Store node position on an edge + # @param NodeID - node ID + # @param Edge - edge or edge ID + # @param paramOnEdge - parameter on edge where the node is located + # @return True if succeed else raise an exception + def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge): + if ( isinstance( Edge, geompy.GEOM._objref_GEOM_Object)): + EdgeID = Edge.GetSubShapeIndices()[0] + else: + EdgeID = Edge + try: + self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge) + except SALOME.SALOME_Exception, inst: + raise ValueError, inst.details.text + return True + + ## @brief Store node position on a face + # @param NodeID - node ID + # @param Face - face or face ID + # @param u - U parameter on face where the node is located + # @param v - V parameter on face where the node is located + # @return True if succeed else raise an exception + def SetNodeOnFace(self, NodeID, Face, u, v): + if ( isinstance( Face, geompy.GEOM._objref_GEOM_Object)): + FaceID = Face.GetSubShapeIndices()[0] + else: + FaceID = Face + try: + self.editor.SetNodeOnFace(NodeID, FaceID, u, v) + except SALOME.SALOME_Exception, inst: + raise ValueError, inst.details.text + return True + + ## @brief Bind a node to a solid + # @param NodeID - node ID + # @param Solid - solid or solid ID + # @return True if succeed else raise an exception + def SetNodeInVolume(self, NodeID, Solid): + if ( isinstance( Solid, geompy.GEOM._objref_GEOM_Object)): + SolidID = Solid.GetSubShapeIndices()[0] + else: + SolidID = Solid + try: + self.editor.SetNodeInVolume(NodeID, SolidID) + except SALOME.SALOME_Exception, inst: + raise ValueError, inst.details.text + return True + + ## @brief Bind an element to a shape + # @param ElementID - element ID + # @param Shape - shape or shape ID + # @return True if succeed else raise an exception + def SetMeshElementOnShape(self, ElementID, Shape): + if ( isinstance( Shape, geompy.GEOM._objref_GEOM_Object)): + ShapeID = Shape.GetSubShapeIndices()[0] + else: + ShapeID = Shape + try: + self.editor.SetMeshElementOnShape(ElementID, ShapeID) + except SALOME.SALOME_Exception, inst: + raise ValueError, inst.details.text + return True + + ## Move node with given id # @param NodeID id of the node # @param x new X coordinate