Salome HOME
Updated copyright comment
[modules/geom.git] / src / GEOM_SWIG / proximity.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2022-2024  CEA, EDF, OPEN CASCADE
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19
20 ## @defgroup proximity ShapeProximity - tool to check the proximity distance between two shapes
21 #  @{ 
22 #  @details
23 #  The tool provides the user a possibility to compute the proximity distance between two shapes:
24 #  * a minimal diameter of a tube containing both edges (for edge-edge proximity);
25 #  * a minimal thickness of a shell containing both faces (for face-face proximity).
26 #
27 #  In other words, this tool calculate maximal of all possible distances between pair of objects.
28 #  It is supported to compute distance between two edges or between two faces.
29 #  Other combinations of shapes are prohibited.
30 #  @}
31
32 """
33     \namespace geompy
34     \brief ShapeProximity interface
35 """
36
37 ## A class to compute proximity value between two shapes.
38 #  Use geompy.ShapeProximity() method to obtain an instance of this class.
39 #
40 #  @ref tui_proximity_page "Example"
41 #  @ingroup proximity
42 class ShapeProximity():
43     """
44     ShapeProximity interface.
45
46     Example of usage:
47         prox = geompy.ShapeProximity()
48         value = prox.proximity(shape1, shape2)
49     """
50
51     def __init__(self, geompyD):
52         self.myCommand = "ShapeProximity"
53         self.myOp = geompyD.GetIMeasureOperations()
54         pass
55
56     ## Computes proximity between two shapes of the same type
57     def proximity(self, shape1, shape2):
58         self.setShapes(shape1, shape2)
59         #self.coarseProximity()
60         return self.preciseProximity()
61         pass
62
63     ## Customize object with the input shapes
64     def setShapes(self, shape1, shape2):
65         self.myProximityValue = None
66         from salome.geom.geomBuilder import RaiseIfFailed
67         self.myCalc = self.myOp.ShapeProximityCalculator(shape1, shape2)
68         RaiseIfFailed(self.myCommand, self.myOp)
69         pass
70
71     ## Define the minimal number of sample points for the given shape,
72     #  which should be used for raw computation of proximity value
73     def setSampling(self, shape, nbSamples):
74         self.myOp.SetShapeSampling(self.myCalc, shape, nbSamples)
75         pass
76
77     ## Find rough proximity value based on polygon/tessellation representation
78     def coarseProximity(self):
79         from salome.geom.geomBuilder import RaiseIfFailed
80         self.myProximityValue = self.myOp.GetCoarseProximity(self.myCalc)
81         RaiseIfFailed(self.myCommand, self.myOp)
82         return self.myProximityValue
83         pass
84
85     ## Find precise proximity value based on exact shapes
86     def preciseProximity(self):
87         from salome.geom.geomBuilder import RaiseIfFailed
88         self.myProximityValue = self.myOp.GetPreciseProximity(self.myCalc)
89         RaiseIfFailed(self.myCommand, self.myOp)
90         return self.myProximityValue
91         pass