Salome HOME
IPAL54364: Add Gravity Center measurement
[modules/smesh.git] / src / SMESH_SWIG / smeshBuilder.py
index 6e0f59579baa41d3aac4cd8947262b06f25d36eb..270d5946bf631382e392f4febd7163d812c59347 100644 (file)
@@ -1155,6 +1155,18 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen):
         aMeasurements.UnRegister()
         return value
 
+    ## Get gravity center of all nodes of the mesh object.
+    #  @param obj mesh, submesh or group
+    #  @return three components of the gravity center: x,y,z
+    #  @ingroup l1_measurements
+    def GetGravityCenter(self, obj):
+        if isinstance(obj, Mesh): obj = obj.mesh
+        if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
+        aMeasurements = self.CreateMeasurements()
+        pointStruct = aMeasurements.GravityCenter(obj)
+        aMeasurements.UnRegister()
+        return pointStruct.x, pointStruct.y, pointStruct.z
+
     pass # end of class smeshBuilder
 
 import omniORB
@@ -3290,7 +3302,7 @@ class Mesh:
         return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
 
     ## Split quadrangles into triangles.
-    #  @param IDsOfElements the faces to be splitted.
+    #  @param IDsOfElements the faces to be split.
     #  @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
     #         choose a diagonal for splitting. If @a theCriterion is None, which is a default
     #         value, then quadrangles will be split by the smallest diagonal.
@@ -3326,7 +3338,7 @@ class Mesh:
 
     ## Split each of given quadrangles into 4 triangles. A node is added at the center of
     #  a quadrangle.
-    #  @param theElements the faces to be splitted. This can be either mesh, sub-mesh,
+    #  @param theElements the faces to be split. This can be either mesh, sub-mesh,
     #         group or a list of face IDs. By default all quadrangles are split
     #  @ingroup l2_modif_cutquadr
     def QuadTo4Tri (self, theElements=[]):
@@ -3341,7 +3353,7 @@ class Mesh:
         return self.editor.QuadTo4Tri( theElements )
 
     ## Split quadrangles into triangles.
-    #  @param IDsOfElements the faces to be splitted
+    #  @param IDsOfElements the faces to be split
     #  @param Diag13        is used to choose a diagonal for splitting.
     #  @return TRUE in case of success, FALSE otherwise.
     #  @ingroup l2_modif_cutquadr
@@ -3362,7 +3374,7 @@ class Mesh:
         return self.editor.SplitQuadObject(theObject, Diag13)
 
     ## Find a better splitting of the given quadrangle.
-    #  @param IDOfQuad   the ID of the quadrangle to be splitted.
+    #  @param IDOfQuad   the ID of the quadrangle to be split.
     #  @param theCriterion  is a numerical functor, in terms of enum SMESH.FunctorType, used to
     #         choose a diagonal for splitting.
     #         Type SMESH.FunctorType._items in the Python Console to see all items.
@@ -4974,6 +4986,32 @@ class Mesh:
     def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
         return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
 
+    ## Create a polyline consisting of 1D mesh elements each lying on a 2D element of
+    #  the initial mesh. Positions of new nodes are found by cutting the mesh by the
+    #  plane passing through pairs of points specified by each PolySegment structure.
+    #  If there are several paths connecting a pair of points, the shortest path is
+    #  selected by the module. Position of the cutting plane is defined by the two
+    #  points and an optional vector lying on the plane specified by a PolySegment.
+    #  By default the vector is defined by Mesh module as following. A middle point
+    #  of the two given points is computed. The middle point is projected to the mesh.
+    #  The vector goes from the middle point to the projection point. In case of planar
+    #  mesh, the vector is normal to the mesh.
+    #  @param segments - PolySegment's defining positions of cutting planes.
+    #         Return the used vector which goes from the middle point to its projection.
+    #  @param groupName - optional name of a group where created mesh segments will
+    #         be added.
+    #  @ingroup l2_modif_duplicat
+    def MakePolyLine(self, segments, groupName='', isPreview=False ):
+        editor = self.editor
+        if isPreview:
+            editor = self.mesh.GetMeshEditPreviewer()
+        segmentsRes = editor.MakePolyLine( segments, groupName )
+        for i, seg in enumerate( segmentsRes ):
+            segments[i].vector = seg.vector
+        if isPreview:
+            return editor.GetPreviewData()
+        return None        
+
     ## Return a cached numerical functor by its type.
     #  @param theCriterion functor type - an item of SMESH.FunctorType enumeration.
     #          Type SMESH.FunctorType._items in the Python Console to see all items.