Salome HOME
8dfda9a17c449e11c8bbfbf55f4a3814994863ad
[plugins/canrecplugin.git] / src / CANRECPLUGIN_PY / CANRECPluginBuilder.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2014-2015  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
21 ##
22 # @package CANRECPluginBuilder
23 # Python API for the CANRECPLUGIN geometry plug-in module.
24
25 from CANRECPlugin import ICanRecOperations
26
27 # Engine Library Name
28 __libraryName__ = "CANRECPluginEngine"
29
30 ## Get Canonical recognition plugin operations interface
31 #  @return an instance of Canonical recognition plugin operations interface
32 def GetCANRECOperations(self):
33     """
34     Get Canonical recognition plugin operations interface.
35
36     Returns:
37         An instance of Canonical recognition plugin operations interface
38     """
39     anOp = self.GetPluginOperations(self.myStudyId, __libraryName__)
40     return anOp._narrow(ICanRecOperations)
41
42 ## Perform, if possible, conversion of NURBS (B-Spline, Bezier) geometry to canonical (analytical) form.
43 #  @param theObj the input object (solid, compound, compsolid).
44 #  @param theMergeSurf  the flag to switch on/off merging surfaces in the result shape.
45 #  @param theMergeCurves the flag to switch on/off merging curves in the result shape.
46 #  @param theTolerance the tolerance of the canonical recognition operation.
47 #  @param theName object name when specified, this parameter is used
48 #         for result publication in the study. Otherwise, if automatic
49 #         publication is switched on, default value is used for result name.
50 #
51 #  @return New GEOM_Object, containing the canonical recognition of the input object.
52 def MakeCanonicalRecognition(self, theObj, theMergeSurf, theMergeCurves,
53                              theTolerance=0.01, theName=None):
54     """
55     Perform, if possible, conversion of NURBS (B-Spline, Bezier) geometry to canonical (analytical) form.
56
57     Parameters:
58         theObj         the input object (solid, compound, compsolid).
59         theMergeSurf   the flag to switch on/off merging surfaces in the result shape.
60         theMergeCurves the flag to switch on/off merging curves in the result shape.
61         theTolerance   the tolerance of the canonical recognition operation.
62         theName        object name when specified, this parameter is used
63                        for result publication in the study. Otherwise, if automatic
64                        publication is switched on, default value is used for result name.
65
66         Returns:
67             New GEOM_Object, containing the canonical recognition of the input object.
68     """
69     from salome.geom.geomBuilder import ParseParameters, RaiseIfFailed
70     anOp = GetCANRECOperations(self)
71     theMergeSurf, theMergeCurves, theTolerance, Parameters = ParseParameters(theMergeSurf, theMergeCurves, theTolerance)
72     (anObj, aStat) = anOp.MakeCanonicalRecognition(theObj, theMergeSurf, theMergeCurves, theTolerance)
73     RaiseIfFailed("MakeCanonicalRecognition", anOp)
74     self._autoPublish(anObj, theName, "canonical")
75     anOp.UnRegister()
76     print "Total number of faces in the initial shape: %s" % aStat[0]
77     print "Number of canonical faces in the initial shape: %s" % aStat[1]
78     print "Number of faces converted to the canonical form: %s" % aStat[2]
79     if aStat[3] >= 0:
80       print "Number of merged surfaces: %s" % aStat[3]
81     if aStat[4] >= 0:
82       print "Number of merged curves: %s" % aStat[4]
83
84     return anObj
85
86 ## Get the number of canonical faces in the shape.
87 #  @param theObj the input object (solid, compound, compsolid).
88 #
89 #  @return the number of canonical faces in the object.
90 def GetNbCanonicalFaces(self, theObj):
91     """
92     Get the number of canonical faces in the shape.
93
94     Parameters:
95         theObj the input object (solid, compound, compsolid).
96
97         Returns:
98             the number of canonical faces in the object.
99     """
100     from salome.geom.geomBuilder import RaiseIfFailed
101     anOp = GetCANRECOperations(self)
102     aNbCanFaces = anOp.GetNbCanonicalFaces(theObj)
103     RaiseIfFailed("GetNbCanonicalFaces", anOp)
104     anOp.UnRegister()
105     return aNbCanFaces