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", format = "doxygen"):
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 if format == "doxygen":
72 output.append( "## @package smeshBuilder" )
73 output.append( "# Documentation of the methods dynamically added by the " + plugin_name + " meshing plug-in to the Mesh class." )
75 elif format == "sphinx":
76 output.append( '"""' )
77 output.append( 'Documentation of the methods dynamically added by the ' + plugin_name + ' meshing plug-in to the Mesh class.' )
78 output.append( '"""' )
81 if format == "doxygen":
82 output.append( "## This class allows defining and managing a mesh." )
84 elif format == "sphinx":
85 output.append( "class Mesh:" )
86 output.append( ' """' )
87 output.append( ' This class allows defining and managing a mesh.' )
91 # This is supposed to be done when generating documentation for meshing plug-ins
92 if format == "doxygen":
93 output.append( "# @note The documentation below does not provide complete description of class @b %Mesh" )
94 output.append( "# from @b smeshBuilder package. This documentation provides only information about" )
95 output.append( "# the methods dynamically added to the %Mesh class by the " + plugin_name + " plugin" )
96 output.append( "# For more details on the %Mesh class, please refer to the SALOME %Mesh module" )
97 output.append( "# documentation." )
98 elif format == "sphinx":
99 output.append( ' The documentation below does not provide complete description of class @b %Mesh' )
100 output.append( ' from @b smeshBuilder package. This documentation provides only information about' )
101 output.append( ' the methods dynamically added to the %Mesh class by the " + plugin_name + " plugin' )
102 output.append( ' For more details on the %Mesh class, please refer to the SALOME %Mesh module' )
103 output.append( ' documentation.' )
104 output.append( ' """' )
108 # Extend documentation for Mesh class with information about dynamically added methods.
109 # This is supposed to be done only when building documentation for SMESH module
110 if format == "doxygen":
111 output.append( "# @note Some methods are dynamically added to the @b %Mesh class in runtime by meshing " )
112 output.append( "# plug-in modules. If you fail to find help on some methods in the documentation of SMESH module, " )
113 output.append( "# try to look into the documentation for the meshing plug-ins." )
114 elif format == "sphinx":
115 output.append( " Note:")
116 output.append( " Some methods are dynamically added to the @b %Mesh class in runtime by meshing " )
117 output.append( " plug-in modules. If you fail to find help on some methods in the documentation of SMESH module, " )
118 output.append( " try to look into the documentation for the meshing plug-ins." )
119 output.append( ' """' )
122 if format == "doxygen":
123 output.append( "class Mesh:" )
124 for method in methods:
126 for algo in methods[ method ]:
127 if hasattr( algo, "docHelper" ): docHelper = getattr( algo, "docHelper" )
130 if not docHelper: docHelper = "Creates new algorithm."
131 if format == "doxygen":
132 output.append( " ## %s" % docHelper )
133 output.append( " #" )
134 output.append( " # This method is dynamically added to %Mesh class by the meshing plug-in(s). " )
135 output.append( " #" )
136 output.append( " # If the optional @a geom_shape parameter is not set, this algorithm is global (applied to whole mesh)." )
137 output.append( " # Otherwise, this algorithm defines a submesh based on @a geom_shape subshape." )
138 output.append( " # @param algo_type type of algorithm to be created; allowed values are specified by classes implemented by plug-in" )
139 output.append( " # @param geom_shape if defined, the subshape to be meshed (GEOM_Object)" )
140 output.append( " # @return An instance of Mesh_Algorithm sub-class according to the specified @a algo_type, see " )
141 output.append( " # %s" % ", ".join( [ "%s.%s" % ( plugin_module_name, algo.__name__ ) for algo in methods[ method ] ] ) )
142 output.append( " def %s(algo_type, geom_shape=0):" % method )
143 output.append( " pass" )
144 elif format == "sphinx":
145 output.append( ' def %s(algo_type, geom_shape=0):' % method )
146 output.append( ' """' )
147 output.append( ' %s' % docHelper )
149 output.append( ' This method is dynamically added to :class:`Mesh <smeshBuilder.Mesh>` class by the meshing plug-in(s). ' )
151 output.append( ' If the optional *geom_shape* parameter is not set, this algorithm is global (applied to whole mesh).' )
152 output.append( ' Otherwise, this algorithm defines a submesh based on *geom_shape* subshape.' )
154 output.append( ' Parameters:' )
155 output.append( ' algo_type: type of algorithm to be created; allowed values are specified by classes implemented by plug-in' )
156 output.append( ' geom_shape (GEOM_Object): if defined, the subshape to be meshed' )
158 output.append( ' Returns:')
159 output.append( ' An instance of Mesh_Algorithm sub-class according to the specified *algo_type*, see ' )
160 output.append( ' %s' % ", ".join( [ ":class:`~%s.%s`" % ( plugin_module_name, algo.__name__ ) for algo in methods[ method ] ] ) )
161 output.append( ' """' )
162 output.append( ' pass' )
164 with open(output_file, "w", encoding='utf8') as f:
165 f.write('\n'.join(output))
168 except Exception as e:
173 if __name__ == "__main__":
175 parser = argparse.ArgumentParser()
176 h = "Output file (smesh.py by default)"
177 parser.add_argument("-o", "--output", dest="output",
178 action="store", default='smesh.py', metavar="file",
180 h = "If this option is True, dummy help for Mesh class is added. "
181 h += "This option should be False (default) when building documentation for SMESH module "
182 h += "and True when building documentation for meshing plug-ins."
183 parser.add_argument("-d", "--dummy-mesh-help", dest="dummymeshhelp",
184 action="store_true", default=False,
186 h = "Format of the documentation strings in the output file. Possible values are: "
187 h+= "'doxygen' - documentation strings are generated in the doxygen format, before a method definition."
188 h+= "'sphinx' - documentation strings are generated in the sphinx format, after a method definition."
189 parser.add_argument("-f", "--format", dest="format",
190 action="store", default="doxygen", help=h)
192 parser.add_argument("plugin_name")
195 args = parser.parse_args()
197 if args.plugin_name is None : sys.exit("Plugin name is not specified")
198 main( args.plugin_name, args.dummymeshhelp, args.output, args.format )