Salome HOME
Merge from V6_main 01/04/2013
[modules/smesh.git] / doc / salome / gui / SMESH / collect_mesh_methods.py
1 #!/usr/bin/env python
2 #  -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2012-2013  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 #################################################################################
23 #
24 # File:   collect_mesh_methods.py
25 # Author: Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com)
26 #
27 #################################################################################
28 #
29 # Extraction of the meshing algorithm classes
30 # dynamically added by the plug-in to the Mesh
31 # class.
32
33 # This script is intended for internal usage - only
34 # for generatation of the extra developer documentation for
35 # the meshing plug-in(s).
36
37 # Usage:
38 #       collect_mesh_methods.py <plugin_name>
39 # where
40 #   <plugin_name> is a name of the plug-in module
41 #
42 # Notes:
43 # - the script is supposed to be run in correct environment
44 # i.e. PYTHONPATH, SMESH_MeshersList and other important
45 # variables are set properly; otherwise the script will fail.
46 #
47 ################################################################################
48
49 import sys
50
51 def main(plugin, dummymeshhelp = True, output_file = "smesh.py"):
52     plugin_module = plugin + "DC"
53     try:
54         mod = __import__(plugin_module)
55         methods = {}
56         for attr in dir( mod ):
57             if attr.startswith( '_' ): continue
58             algo = getattr( mod, attr )
59             if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
60                 method = getattr( algo, "meshMethod" )
61                 if method not in methods: methods[ method ] = []
62                 methods[ method ].append( algo )
63                 pass
64             pass
65         if methods:
66             output = []
67             if dummymeshhelp:
68                 output.append( "## @package smesh" )
69                 output.append( "#  Documentation of the methods dynamically added by the " + plugin + " meshing plug-in to the Mesh class." )
70                 output.append( "" )
71                 pass
72             output.append( "## This class allows defining and managing a mesh." )
73             output.append( "#" )
74             if dummymeshhelp:
75                 # Add dummy Mesh help
76                 # This is supposed to be done when generating documentation for meshing plug-ins
77                 output.append( "#  @note The documentation below does not provide complete description of class @b %Mesh" )
78                 output.append( "#  from @b %smesh.py package. This documentation provides only information about" )
79                 output.append( "#  the methods dynamically added to the %Mesh class by the " + plugin + " plugin" )
80                 output.append( "#  For more details on the %Mesh class, please refer to the SALOME %Mesh module" )
81                 output.append( "#  documentation." )
82                 pass
83             else:
84                 # Extend documentation for Mesh class with information about dynamically added methods.
85                 # This is supposed to be done only when building documentation for SMESH module
86                 output.append( "#  @note Some methods are dynamically added to the @b %Mesh class in runtime by meshing " )
87                 output.append( "#  plug-in modules. If you fail to find help on some methods in the documentation of SMESH module, " )
88                 output.append( "#  try to look into the documentation for the meshing plug-ins." )
89                 pass
90             output.append( "class Mesh:" )
91             for method in methods:
92                 docHelper = ""
93                 for algo in methods[ method ]:
94                     if hasattr( algo, "docHelper" ): docHelper = getattr( algo, "docHelper" )
95                     if docHelper: break
96                     pass
97                 if not docHelper: docHelper = "Creates new algorithm."
98                 output.append( " ## %s" % docHelper )
99                 output.append( " #" )
100                 output.append( " #  This method is dynamically added to %Mesh class by the meshing plug-in(s). " )
101                 output.append( " #" )
102                 output.append( " #  If the optional @a geom_shape parameter is not set, this algorithm is global (applied to whole mesh)." )
103                 output.append( " #  Otherwise, this algorithm defines a submesh based on @a geom_shape subshape." )
104                 output.append( " #  @param algo_type type of algorithm to be created; allowed values are specified by classes implemented by plug-in (see below)" )
105                 output.append( " #  @param geom_shape if defined, the subshape to be meshed (GEOM_Object)" )
106                 output.append( " #  @return An instance of Mesh_Algorithm sub-class according to the specified @a algo_type, see " )
107                 output.append( " #  %s" % ", ".join( [ "%s.%s" % ( plugin_module, algo.__name__ ) for algo in methods[ method ] ] ) )
108                 output.append( " def %s(algo_type, geom_shape=0):" % method )
109                 output.append( "   pass" )
110                 pass
111             f = open(output_file, "w")
112             for line in output: f.write( line + "\n" )
113             f.close()
114             pass
115         pass
116     except Exception, e:
117         print e
118         pass
119     pass
120     
121 if __name__ == "__main__":
122     import optparse
123     parser = optparse.OptionParser(usage="%prog [options] plugin")
124     h  = "Output file (smesh.py by default)"
125     parser.add_option("-o", "--output", dest="output",
126                       action="store", default=None, metavar="file",
127                       help=h)
128     h  = "If this option is True, dummy help for Mesh class is added. "
129     h += "This option should be False (default) when building documentation for SMESH module "
130     h += "and True when building documentation for meshing plug-ins."
131     parser.add_option("-d", "--dummy-mesh-help", dest="dummymeshhelp",
132                       action="store_true", default=False,
133                       help=h)
134     (options, args) = parser.parse_args()
135
136     if len( args ) < 1: sys.exit("Plugin name is not specified")
137     main( args[0], options.dummymeshhelp, options.output )
138     pass