Salome HOME
24fd31880739affeb4c7188241337096c1ec80f4
[modules/smesh.git] / doc / salome / gui / SMESH / collect_mesh_methods.py
1 #!/usr/bin/env python
2 #################################################################################
3 #
4 # File:   collect_mesh_methods.py
5 # Author: Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com)
6 #
7 #################################################################################
8 #
9 # Extraction of the meshing algorithm classes
10 # dynamically added by the plug-in to the Mesh
11 # class.
12
13 # This script is intended for internal usage - only
14 # for generatation of the extra developer documentation for
15 # the meshing plug-in(s).
16
17 # Usage:
18 #       collect_mesh_methods.py <plugin_name>
19 # where
20 #   <plugin_name> is a name of the plug-in module
21 #
22 # Notes:
23 # - the script is supposed to be run in correct environment
24 # i.e. PYTHONPATH, SMESH_MeshersList and other important
25 # variables are set properly; otherwise the script will fail.
26 #
27 ################################################################################
28
29 import sys
30
31 def main(plugin, dummymeshhelp = True, output_file = "smesh.py"):
32     plugin_module = plugin + "DC"
33     try:
34         mod = __import__(plugin_module)
35         methods = {}
36         for attr in dir( mod ):
37             if attr.startswith( '_' ): continue
38             algo = getattr( mod, attr )
39             if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
40                 method = getattr( algo, "meshMethod" )
41                 if method not in methods: methods[ method ] = []
42                 methods[ method ].append( algo )
43                 pass
44             pass
45         if methods:
46             output = []
47             if dummymeshhelp:
48                 output.append( "## @package smesh" )
49                 output.append( "#  Documentation of the methods dynamically added by the " + plugin + " meshing plug-in to the Mesh class." )
50                 output.append( "" )
51                 pass
52             output.append( "## This class allows defining and managing a mesh." )
53             output.append( "#" )
54             if dummymeshhelp:
55                 # Add dummy Mesh help
56                 # This is supposed to be done when generating documentation for meshing plug-ins
57                 output.append( "#  @note The documentation below does not provide complete description of class @b %Mesh" )
58                 output.append( "#  from @b %smesh.py package. This documentation provides only information about" )
59                 output.append( "#  the methods dynamically added to the %Mesh class by the " + plugin + " plugin" )
60                 output.append( "#  For more details on the %Mesh class, please refer to the SALOME %Mesh module" )
61                 output.append( "#  documentation." )
62                 pass
63             else:
64                 # Extend documentation for Mesh class with information about dynamically added methods.
65                 # This is supposed to be done only when building documentation for SMESH module
66                 output.append( "#  @note Some methods are dynamically added to the @b %Mesh class in runtime by meshing " )
67                 output.append( "#  plug-in modules. If you fail to find help on some methods in the documentation of SMESH module, " )
68                 output.append( "#  try to look into the documentation for the meshing plug-ins." )
69                 pass
70             output.append( "class Mesh:" )
71             for method in methods:
72                 docHelper = ""
73                 for algo in methods[ method ]:
74                     if hasattr( algo, "docHelper" ): docHelper = getattr( algo, "docHelper" )
75                     if docHelper: break
76                     pass
77                 if not docHelper: docHelper = "Creates new algorithm."
78                 output.append( " ## %s" % docHelper )
79                 output.append( " #" )
80                 output.append( " #  This method is dynamically added to %Mesh class by the meshing plug-in(s). " )
81                 output.append( " #" )
82                 output.append( " #  If the optional @a geom_shape parameter is not set, this algorithm is global (applied to whole mesh)." )
83                 output.append( " #  Otherwise, this algorithm defines a submesh based on @a geom_shape subshape." )
84                 output.append( " #  @param algo_type type of algorithm to be created; allowed values are specified by classes implemented by plug-in (see below)" )
85                 output.append( " #  @param geom_shape if defined, the subshape to be meshed (GEOM_Object)" )
86                 output.append( " #  @return An instance of Mesh_Algorithm sub-class according to the specified @a algo_type, see " )
87                 output.append( " #  %s" % ", ".join( [ "%s.%s" % ( plugin_module, algo.__name__ ) for algo in methods[ method ] ] ) )
88                 output.append( " def %s(algo_type, geom_shape=0):" % method )
89                 output.append( "   pass" )
90                 pass
91             f = open(output_file, "w")
92             for line in output: f.write( line + "\n" )
93             f.close()
94             pass
95         pass
96     except Exception, e:
97         print e
98         pass
99     pass
100     
101 if __name__ == "__main__":
102     import optparse
103     parser = optparse.OptionParser(usage="%prog [options] plugin")
104     h  = "Output file (smesh.py by default)"
105     parser.add_option("-o", "--output", dest="output",
106                       action="store", default=None, metavar="file",
107                       help=h)
108     h  = "If this option is True, dummy help for Mesh class is added. "
109     h += "This option should be False (default) when building documentation for SMESH module "
110     h += "and True when building documentation for meshing plug-ins."
111     parser.add_option("-d", "--dummy-mesh-help", dest="dummymeshhelp",
112                       action="store_true", default=False,
113                       help=h)
114     (options, args) = parser.parse_args()
115
116     if len( args ) < 1: sys.exit("Plugin name is not specified")
117     main( args[0], options.dummymeshhelp, options.output )
118     pass