Salome HOME
Implemented [bos #35094] [EDF] (2023-T1) X,Y,Z to U,V.
[modules/geom.git] / src / GEOM_SWIG / geomBuilder.py
index 5dbc1d202cb8aa211adf408876c15c8fe6696ea3..6b7947e0df628cf67fd72d857ec4ef8cb1f7b29a 100644 (file)
@@ -260,6 +260,9 @@ import os
 import functools
 
 from salome.geom.gsketcher import Sketcher3D, Sketcher2D, Polyline2D
+from salome.geom.canonicalrecognition import CanonicalRecognition
+from salome.geom.conformity import CheckConformity
+from salome.geom.proximity import ShapeProximity
 
 # In case the omniORBpy EnumItem class does not fully support Python 3
 # (for instance in version 4.2.1-2), the comparison ordering methods must be
@@ -379,6 +382,12 @@ def RaiseIfFailed (Method_name, Operation):
     if not Operation.IsDone() and Operation.GetErrorCode() != "NOT_FOUND_ANY":
         raise RuntimeError(Method_name + " : " + Operation.GetErrorCode())
 
+def PrintOrRaise(message, raiseException=False):
+    if raiseException:
+        raise RuntimeError(message)
+    else:
+        print(message)
+
 ## Return list of variables value from salome notebook
 ## @ingroup l1_geomBuilder_auxiliary
 def ParseParameters(*parameters):
@@ -1435,7 +1444,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
         #
         #  @ref swig_MakeVertexInsideFace "Example"
         @ManageTransactions("BasicOp")
-        def MakeVertexInsideFace (self, theFace, theName=None):
+        def MakeVertexInsideFace (self, theFace, theNumberOfPnts=1, theName=None):
             """
             Create a point, which lays on the given face.
             The point will lay in arbitrary place of the face.
@@ -1445,6 +1454,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
 
             Parameters:
                 theFace The referenced face.
+                theNumberOfPnts The number of points we want to get, 1 by default.
                 theName Object name; when specified, this parameter is used
                         for result publication in the study. Otherwise, if automatic
                         publication is switched on, default value is used for result name.
@@ -1456,7 +1466,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
                 p_on_face = geompy.MakeVertexInsideFace(Face)
             """
             # Example: see GEOM_TestAll.py
-            anObj = self.BasicOp.MakePointOnFace(theFace)
+            anObj = self.BasicOp.MakePointOnFace(theFace, theNumberOfPnts)
             RaiseIfFailed("MakeVertexInsideFace", self.BasicOp)
             self._autoPublish(anObj, theName, "vertex")
             return anObj
@@ -4750,7 +4760,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
         #
         #  @ref tui_creation_face "Example"
         @ManageTransactions("ShapesOp")
-        def MakeFace(self, theWire, isPlanarWanted, theName=None):
+        def MakeFace(self, theWire, isPlanarWanted, theName=None, raiseException=False):
             """
             Create a face on the given wire.
 
@@ -4771,7 +4781,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
             # Example: see GEOM_TestAll.py
             anObj = self.ShapesOp.MakeFace(theWire, isPlanarWanted)
             if isPlanarWanted and anObj is not None and self.ShapesOp.GetErrorCode() == "MAKE_FACE_TOLERANCE_TOO_BIG":
-                print("WARNING: Cannot build a planar face: required tolerance is too big. Non-planar face is built.")
+                PrintOrRaise("WARNING: Cannot build a planar face: required tolerance is too big. Non-planar face is built.",raiseException)
             else:
                 RaiseIfFailed("MakeFace", self.ShapesOp)
             self._autoPublish(anObj, theName, "face")
@@ -4792,7 +4802,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
         #
         #  @ref tui_creation_face "Example"
         @ManageTransactions("ShapesOp")
-        def MakeFaceWires(self, theWires, isPlanarWanted, theName=None):
+        def MakeFaceWires(self, theWires, isPlanarWanted, theName=None, raiseException=False):
             """
             Create a face on the given wires set.
 
@@ -4813,7 +4823,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
             # Example: see GEOM_TestAll.py
             anObj = self.ShapesOp.MakeFaceWires(ToList(theWires), isPlanarWanted)
             if isPlanarWanted and anObj is not None and self.ShapesOp.GetErrorCode() == "MAKE_FACE_TOLERANCE_TOO_BIG":
-                print("WARNING: Cannot build a planar face: required tolerance is too big. Non-planar face is built.")
+                PrintOrRaise("WARNING: Cannot build a planar face: required tolerance is too big. Non-planar face is built.",raiseException)
             else:
                 RaiseIfFailed("MakeFaceWires", self.ShapesOp)
             self._autoPublish(anObj, theName, "face")
@@ -11172,6 +11182,124 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
             return aSurf
         ## @}
 
+        ## Measure curvature radius of surface in the given point along the given direction.
+        #  @param theSurf the given face.
+        #  @param thePoint given point.
+        #  @param theDirection given direction.
+        #  @param theName Object name; when specified, this parameter is used
+        #         for result publication in the study. Otherwise, if automatic
+        #         publication is switched on, default value is used for result name.
+        #
+        #  @return New GEOM.GEOM_Object, containing vector of curvature of theSurf.
+        #          The returned vector is codirectional with the normal to the face
+        #          in the given point in case of positive curvature value
+        #          and opposite to the normal in case of negative curvature.
+        #          The normal of the returned vector is equal to the
+        #          absolute value of the curvature radius.
+        #          Null shape is returned in case of infinite radius
+        #          (zero curvature), for example, in case of flat face.
+        #
+        ## @ref swig_CurvatureOnFace "Example"
+        @ManageTransactions("MeasuOp")
+        def CurvatureOnFace(self, theSurf, thePoint, theDirection, theName=None):
+            """
+            Measure curvature radius of surface in the given point along the given direction.
+
+            Parameters:
+                theSurf the given face.
+                thePoint given point.
+                theDirection given direction.
+                theName Object name; when specified, this parameter is used
+                        for result publication in the study. Otherwise, if automatic
+                        publication is switched on, default value is used for result name.
+
+            Returns:
+                New GEOM.GEOM_Object, containing vector of curvature of theSurf.
+                The returned vector is codirectional with the normal to the face
+                in the given point in case of positive curvature value
+                and opposite to the normal in case of negative curvature.
+                The normal of the returned vector is equal to the
+                absolute value of the curvature radius.
+                Null shape is returned in case of infinite radius
+                (zero curvature), for example, in case of flat face.
+
+            Example of usage:
+                curvature_1 = geompy.CurvatureOnFace(Face_1, Vertex_1, OX)
+            """
+            aVec = self.MeasuOp.SurfaceCurvatureByPointAndDirection(theSurf,thePoint,theDirection)
+            if self.MeasuOp.GetErrorCode() != "ZERO_CURVATURE":
+                RaiseIfFailed("CurvatureOnFace", self.MeasuOp)
+                self._autoPublish(aVec, theName, "curvature")
+            return aVec
+
+        ## Convert X,Y,Z points coordinates to UV parameters on the given surface.
+        #  @param theSurf the given face. It can be also a shell or a compound with one face.
+        #  @param theXYZlist float list of size 3*N where N is the number of points
+        #                    for which we want their U,V coordinates.
+        #                    If the user enters a list of size not divisible by 3
+        #                    an exception will be thrown.
+        #  @param theIsNormalized if True, the returned parameters will be in range [0, 1].
+        #
+        #  @return list of float of size 2*N.
+        #
+        #  @ref tui_xyz_to_uv_page "Example"
+        @ManageTransactions("MeasuOp")
+        def XYZtoUV(self, theSurf, theXYZlist, theIsNormalized = True):
+            """
+            Convert X,Y,Z points coordinates to UV parameters on the given surface.
+
+            Parameters:
+                theSurf the given face. It can be also a shell or a compound with one face.
+                theXYZlist float list of size 3*N where N is the number of points
+                           for which we want their U,V coordinates.
+                           If the user enters a list of size not divisible by 3
+                           an exception will be thrown.
+                theIsNormalized if True, the returned parameters will be in range [0, 1].
+
+            Returns:
+                list of float of size 2*N.
+
+            Example of usage:
+                [u1,v1, u2,v2] = geompy.XYZtoUV(Face_1, [0,0,0, 0,10,10])
+            """
+            aUVlist = self.MeasuOp.XYZtoUV(theSurf, theXYZlist, theIsNormalized)
+            RaiseIfFailed("XYZtoUV", self.MeasuOp)
+            return aUVlist
+
+        ## Convert UV parameters on the given surface to 3D points coordinates.
+        #  @param theSurf the given face. It can be also a shell or a compound with one face.
+        #  @param theUVlist float list of size 2*N where N is the number of points
+        #                   for which we want their X,Y,Z coordinates.
+        #                   If the user enters a list of non-even size
+        #                   an exception will be thrown.
+        #  @param theIsNormalized if True, the input parameters are expected to be in range [0, 1].
+        #
+        #  @return list of float of size 3*N.
+        #
+        #  @ref tui_xyz_to_uv_page "Example"
+        @ManageTransactions("MeasuOp")
+        def UVtoXYZ(self, theSurf, theUVlist, theIsNormalized = True):
+            """
+            Convert UV parameters on the given surface to 3D points coordinates.
+
+            Parameters:
+                theSurf the given face. It can be also a shell or a compound with one face.
+                theUVlist float list of size 2*N where N is the number of points
+                          for which we want their X,Y,Z coordinates.
+                          If the user enters a list of non-even size
+                          an exception will be thrown.
+                theIsNormalized if True, the input parameters are expected to be in range [0, 1].
+
+            Returns:
+                list of float of size 3*N.
+
+            Example of usage:
+                [x1,y1,z1, x2,y2,z2] = geompy.UVtoXYZ(Face_1, [0,0, 10,10])
+            """
+            aXYZlist = self.MeasuOp.UVtoXYZ(theSurf, theUVlist, theIsNormalized)
+            RaiseIfFailed("UVtoXYZ", self.MeasuOp)
+            return aXYZlist
+
         ## Get min and max tolerances of sub-shapes of theShape
         #  @param theShape Shape, to get tolerances of.
         #  @return [FaceMin,FaceMax, EdgeMin,EdgeMax, VertMin,VertMax]\n
@@ -11727,6 +11855,39 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
 
             return aKindTuple
 
+        ## The function takes a single face with holes and returns a list of faces,
+        #  first of them is the original face without holes, and the other faces are placed
+        #  on the same surface as the original face but bounded by each hole wire.
+        #  If the original face has no holes, it will be returned as an output
+        #  @param theShape Face to perform operation on.
+        #
+        #  @return GEOM.ListOfGO, list created faces, where first of them is the original face without holes
+        @ManageTransactions("MeasuOp")
+        def PatchFace(self, theShape):
+            """
+            The function takes a single face with holes and returns a list of faces,
+            first of them is the original face without holes, and the other faces are placed
+            on the same surface as the original face but bounded by each hole wire.
+            If the original face has no holes, it will be returned as an output
+
+            Parameters:
+                theShape  Face to perform operation on.
+
+            Returns:
+                GEOM.ListOfGO, list created faces, where first of them is the original face without holes
+
+            Example of usage:
+                Circle_1 = geompy.MakeCircle(None, None, 190)
+                Circle_2 = geompy.MakeCircle(None, None, 100)
+                Face_1 = geompy.MakeFaceWires([Circle_1], 1)
+                Face_2 = geompy.MakeFaceWires([Circle_2], 1)
+                Cut_1 = geompy.MakeCutList(Face_1, [Face_2], True)
+                faces = geompy.PatchFace(Cut_1)
+            """
+            aList = self.MeasuOp.PatchFace(theShape)
+            RaiseIfFailed("PatchFace", self.MeasuOp)
+            return aList
+
         ## Returns the string that describes if the shell is good for solid.
         #  This is a support method for MakeSolid.
         #
@@ -11749,6 +11910,22 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
             aDescr = self.MeasuOp.IsGoodForSolid(theShell)
             return aDescr
 
+        ## Obtain a canonical recognition interface.
+        #  @return An instance of
+        #          @ref canonicalrecognition.CanonicalRecognition "CanonicalRecognition" interface
+        #
+        #  @ref tui_3dsketcher_page "Example"
+        def CanonicalRecognition (self):
+            """
+            Obtain a canonical recognition interface.
+
+            Example of usage:
+                cr = geompy.CanonicalRecognition()
+                cr.isLine(aLine, tolerance)
+            """
+            cr = CanonicalRecognition (self)
+            return cr
+
         # end of l2_measure
         ## @}
 
@@ -13929,6 +14106,40 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
             RaiseIfFailed("Tesselate", self.TestOp)
             return r
 
+        ## Obtain a shape checker
+        #  @return An instance of @ref conformity.CheckConformity "CheckConformity" interface
+        #
+        #  @ref tui_conformity_page "Example"
+        def CheckConformity (self, shape):
+            """
+            Obtain a shape checker.
+
+            Example of usage:
+                conf = geompy.CheckConformity(shape)
+                valid = conf.isValid()
+                si2d = conf.selfIntersected2D()
+                dist = conf.distantShapes()
+                small = conf.smallEdges()
+                interfer = cc.interferingSubshapes()
+            """
+            conf = CheckConformity (shape, self)
+            return conf
+
+        ## Obtain a shape proximity calculator
+        #  @return An instance of @ref proximity.ShapeProximity "ShapeProximity" interface
+        #
+        #  @ref tui_proximity_page "Example"
+        def ShapeProximity (self):
+            """
+            Obtain a shape proximity calculator.
+
+            Example of usage:
+                prox = geompy.ShapeProximity()
+                value = prox.proximity(shape1, shape2)
+            """
+            prox = ShapeProximity (self)
+            return prox
+
         # end of l2_testing
         ## @}