2 # Copyright (C) 2012-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #################################################################################
23 # File: collect_mesh_methods.py
24 # Author: Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com)
26 #################################################################################
28 # Extraction of the meshing algorithm classes
29 # dynamically added by the plug-in to the Mesh
32 # This script is intended for internal usage - only
33 # for generation of the extra developer documentation for
34 # the meshing plug-in(s).
37 # collect_mesh_methods.py <plugin_name>
39 # <plugin_name> is a name of the plug-in module
42 # - the script is supposed to be run in correct environment
43 # i.e. PYTHONPATH, SMESH_MeshersList and other important
44 # variables are set properly; otherwise the script will fail.
46 ################################################################################
51 def main(plugin_name, dummymeshhelp = True, output_file = "smeshBuilder.py"):
52 plugin_module_name = plugin_name + "Builder"
53 plugin_module = "salome.%s.%s" % (plugin_name, plugin_module_name)
55 exec("from salome.smesh.smeshBuilder import *", globals())
56 exec("import %s" % plugin_module, globals())
57 exec("mod = %s" % plugin_module , globals())
59 for attr in dir( mod ):
60 if attr.startswith( '_' ): continue
61 algo = getattr( mod, attr )
62 if inspect.isclass(algo) and hasattr(algo, "meshMethod"):
63 method = getattr( algo, "meshMethod" )
64 if method not in methods: methods[ method ] = []
65 methods[ method ].append( algo )
71 output.append( "## @package smeshBuilder" )
72 output.append( "# Documentation of the methods dynamically added by the " + plugin_name + " meshing plug-in to the Mesh class." )
75 output.append( "## This class allows defining and managing a mesh." )
79 # This is supposed to be done when generating documentation for meshing plug-ins
80 output.append( "# @note The documentation below does not provide complete description of class @b %Mesh" )
81 output.append( "# from @b smeshBuilder package. This documentation provides only information about" )
82 output.append( "# the methods dynamically added to the %Mesh class by the " + plugin_name + " plugin" )
83 output.append( "# For more details on the %Mesh class, please refer to the SALOME %Mesh module" )
84 output.append( "# documentation." )
87 # Extend documentation for Mesh class with information about dynamically added methods.
88 # This is supposed to be done only when building documentation for SMESH module
89 output.append( "# @note Some methods are dynamically added to the @b %Mesh class in runtime by meshing " )
90 output.append( "# plug-in modules. If you fail to find help on some methods in the documentation of SMESH module, " )
91 output.append( "# try to look into the documentation for the meshing plug-ins." )
93 output.append( "class Mesh:" )
94 for method in methods:
96 for algo in methods[ method ]:
97 if hasattr( algo, "docHelper" ): docHelper = getattr( algo, "docHelper" )
100 if not docHelper: docHelper = "Creates new algorithm."
101 output.append( " ## %s" % docHelper )
102 output.append( " #" )
103 output.append( " # This method is dynamically added to %Mesh class by the meshing plug-in(s). " )
104 output.append( " #" )
105 output.append( " # If the optional @a geom_shape parameter is not set, this algorithm is global (applied to whole mesh)." )
106 output.append( " # Otherwise, this algorithm defines a submesh based on @a geom_shape subshape." )
107 output.append( " # @param algo_type type of algorithm to be created; allowed values are specified by classes implemented by plug-in (see below)" )
108 output.append( " # @param geom_shape if defined, the subshape to be meshed (GEOM_Object)" )
109 output.append( " # @return An instance of Mesh_Algorithm sub-class according to the specified @a algo_type, see " )
110 output.append( " # %s" % ", ".join( [ "%s.%s" % ( plugin_module_name, algo.__name__ ) for algo in methods[ method ] ] ) )
111 output.append( " def %s(algo_type, geom_shape=0):" % method )
112 output.append( " pass" )
114 with open(output_file, "w", encoding='utf8') as f:
115 f.write('\n'.join(output))
118 except Exception as e:
123 if __name__ == "__main__":
125 parser = argparse.ArgumentParser()
126 h = "Output file (smesh.py by default)"
127 parser.add_argument("-o", "--output", dest="output",
128 action="store", default='smesh.py', metavar="file",
130 h = "If this option is True, dummy help for Mesh class is added. "
131 h += "This option should be False (default) when building documentation for SMESH module "
132 h += "and True when building documentation for meshing plug-ins."
133 parser.add_argument("-d", "--dummy-mesh-help", dest="dummymeshhelp",
134 action="store_true", default=False,
136 parser.add_argument("plugin", help='Name of plugin')
137 args = parser.parse_args()
139 main( args.plugin, args.dummymeshhelp, args.output )