diff --git a/src/openalea/mtg/interface/mtg.py b/src/openalea/mtg/interface/mtg.py index ebc27ce..7932bb7 100644 --- a/src/openalea/mtg/interface/mtg.py +++ b/src/openalea/mtg/interface/mtg.py @@ -18,7 +18,7 @@ This module provides multiscale tree concepts to form MTG interface. """ -class MultiscaleTreeConcept(object): +class MultiscaleTreeConcept(): """ Multiscale Tree Graph definition. """ diff --git a/src/openalea/mtg/io.py b/src/openalea/mtg/io.py index 69e8cf3..eaf98d1 100644 --- a/src/openalea/mtg/io.py +++ b/src/openalea/mtg/io.py @@ -130,14 +130,17 @@ def get_properties(name,vid=None, time=False): args[k] = klass(v) except: if vid is not None: + if k =='_line': + continue print('Args ', v, 'of vertex ', vid, 'of type ', k, 'is not of type ', str(klass)) else: print('Args ', v, 'of type ', k, 'is not of type ', str(klass)) return args def add_dynamic_properties(mtg, vid, args): - print("Existing properties at ", vid, " ", mtg.get_vertex_property(vid)) - print("New property: ", args) + if mtg.verbose: + log("Existing properties at ", vid, " ", mtg.get_vertex_property(vid)) + log("New property: ", args) # a property can be a list but not a timeserie. # Create a real timeserie object... @@ -167,7 +170,7 @@ def add_dynamic_properties(mtg, vid, args): implicit_scale = bool(symbol_at_scale) if debug: - print(list(symbol_at_scale.keys())) + log(list(symbol_at_scale.keys())) mtg = mtg if mtg else MTG() @@ -234,7 +237,7 @@ def add_dynamic_properties(mtg, vid, args): scale = mtg.scale(vid) elif tag == '*': args = get_properties(name, vid=vid, time=True) - print(vid, '*(', args, ')') + log(vid, '*(', args, ')') # CPL Manage Dynamic_MTG add_dynamic_properties(mtg, vid, args) else: @@ -252,7 +255,7 @@ def add_dynamic_properties(mtg, vid, args): try: new_scale = symbol_at_scale[symbol_class] except: - print('NODE ',node, bool(tag=='*')) + print('NODE ',symbol_class, node, tag, bool(tag=='*')) if tag == '/' and new_scale <= scale: new_scale -= 1 pending_edge = '/' @@ -457,7 +460,7 @@ def transform(turtle, mesh): current_vertex = vid pending_edge = '' - log('','Cas 1.1', scale, + log('','Case 1.1', scale, 'mtg.scale(vid)', mtg.scale(vid), 'generated vertex', vid) @@ -467,7 +470,7 @@ def transform(turtle, mesh): current_vertex = mtg.add_child(current_vertex, edge_type=edge_type, label=name) - log('', 'Cas 1.2', scale, + log('', 'Case 1.2', scale, 'mtg.scale(vid)', mtg.scale(vid), 'generated vertex', current_vertex) assert mtg.scale(current_vertex) == module_scale @@ -481,7 +484,7 @@ def transform(turtle, mesh): assert vid == current_vertex vid = mtg.add_component(vid) current_vertex = vid - log('', '', 'Cas 2.1', scale, 'generate new component', current_vertex) + log('', '', 'Case 2.1', scale, 'generate new component', current_vertex) scale += 1 if module_scale == scale: assert mtg.scale(current_vertex) == module_scale @@ -893,7 +896,7 @@ class Reader(object): The code contains topology relations and properties. """ - def __init__(self, string, has_line_as_param=True, mtg=None, has_date=False): + def __init__(self, string, has_line_as_param=True, mtg=None, has_date=False, verbose=True): self.mtg = mtg # First implementation. @@ -912,14 +915,17 @@ def __init__(self, string, has_line_as_param=True, mtg=None, has_date=False): self._no_line = 0 self.warnings = [] self.has_line_as_param = has_line_as_param + self.verbose = verbose def parse(self): - """ + """ Read the header and parse the code. """ self.header() self.code() - self.errors() + if self.verbose: + self.errors() + return self.mtg def header(self): @@ -1120,6 +1126,7 @@ def errors(self): print(warning) else: print(id, " ", warning) + ############################################################################ ### Parsing of the MTG code ### That's the real stuff... @@ -1270,7 +1277,7 @@ def build_mtg(self): self.mtg = multiscale_edit(self._new_code, self._symbols, self._features, self.has_date, mtg=self.mtg) #self.mtg = multiscale_edit(self._new_code, {}, self._features) -def read_mtg(s, mtg=None, has_date=False): +def read_mtg(s, mtg=None, has_date=False, verbose=True): """ Create an MTG from its string representation in the MTG format. :Parameter: @@ -1290,11 +1297,11 @@ def read_mtg(s, mtg=None, has_date=False): .. seealso:: :func:`read_mtg_file`. """ - reader = Reader(s, mtg=mtg, has_date=has_date) + reader = Reader(s, mtg=mtg, has_date=has_date, verbose=verbose) g = reader.parse() return g -def read_mtg_file(fn, mtg=None, has_date=False): +def read_mtg_file(fn, mtg=None, has_date=False, verbose=True): """ Create an MTG from a filename. :Usage: @@ -1306,7 +1313,7 @@ def read_mtg_file(fn, mtg=None, has_date=False): f = open(fn) txt = f.read() f.close() - return read_mtg(txt, mtg=mtg, has_date=has_date) + return read_mtg(txt, mtg=mtg, has_date=has_date, verbose=verbose) def mtg_display(g, vtx_id, tab=' ', edge_type=None, label=None): diff --git a/src/openalea/mtg/mtg.py b/src/openalea/mtg/mtg.py index b330c64..8063a06 100644 --- a/src/openalea/mtg/mtg.py +++ b/src/openalea/mtg/mtg.py @@ -67,7 +67,7 @@ class MTG(PropertyTree): ''' - def __init__(self, filename='', has_date=False): + def __init__(self, filename='', has_date=False, verbose=False): ''' Create a new MTG object. :Usage: @@ -78,6 +78,8 @@ def __init__(self, filename='', has_date=False): super(MTG, self).__init__() + self.verbose = verbose + # Map a vid to its scale self._scale = {0:0} @@ -93,7 +95,9 @@ def __init__(self, filename='', has_date=False): if filename: from .io import read_mtg_file - self = read_mtg_file(filename, mtg=self, has_date=has_date) + self = read_mtg_file(filename, mtg=self, has_date=has_date, verbose=verbose) + + def __getitem__(self, vtx_id): """A simple getitem to extract relevant information on a vertex. @@ -2389,7 +2393,8 @@ def _compute_missing_edges(mtg, scale, edge_type_property=None): for vid in roots: components = mtg._components.get(vid) if components is None: - print('ERROR: Missing component for vertex %d'%vid) + if mtg.verbose: + print('ERROR: Missing component for vertex %d'%vid) continue #assert len(components) == 1 cid = components[0] @@ -2398,7 +2403,8 @@ def _compute_missing_edges(mtg, scale, edge_type_property=None): parent_id = mtg.complex(mtg.parent(cid)) if parent_id is None: #roots.append(vid) - print('ERROR: Missing parent for vertex %d'%cid) + if mtg.verbose: + print('ERROR: Missing parent for vertex %d'%cid) continue if edge_type_property: edge_type = edge_type_property.get(cid) @@ -2753,7 +2759,7 @@ def new_f(self, *args, **kwds): new_f.__doc__ = mtg_f.__doc__ return new_f -class _ProxyNode(object): +class _ProxyNode(): def __init__(self, g, vid): self.__dict__['_g'] = g self.__dict__['_vid'] = vid diff --git a/src/openalea/mtg/plantframe/dresser.py b/src/openalea/mtg/plantframe/dresser.py index 5267218..5bef0e4 100644 --- a/src/openalea/mtg/plantframe/dresser.py +++ b/src/openalea/mtg/plantframe/dresser.py @@ -43,7 +43,7 @@ import os from openalea.plantgl.scenegraph import AmapSymbol -class DressingData(object): +class DressingData(): """ Data and default geometric parameters. The dressing data are the default data that are used to define @@ -205,7 +205,7 @@ def dressing_data(file): ############################################################### ## Define the parser which is just a dict from keyword to a function -class Reader(object): +class Reader(): def __init__(self, dresser): self.dresser = dresser diff --git a/src/openalea/mtg/plantframe/frame.py b/src/openalea/mtg/plantframe/frame.py index 893780e..ff41431 100644 --- a/src/openalea/mtg/plantframe/frame.py +++ b/src/openalea/mtg/plantframe/frame.py @@ -34,7 +34,7 @@ -class Frame(object): +class Frame(): """ Frame representing geometric variables of each topologic elements. A frame is used to have a common representation of the geometric information @@ -137,7 +137,7 @@ def get_top_radius(self): top_radius = property(get_top_radius, set_top_radius, 'top_radius of the Frame') -class AxialFrames(object): +class AxialFrames(): ''' Solve continuity constraints on an axis, i.e. a set of frames. ''' @@ -145,7 +145,7 @@ class AxialFrames(object): -class PlantFrame(object): +class PlantFrame(): ''' Engine to compute the geometry of a plant based on its topological description and parameters. ''' diff --git a/src/openalea/mtg/plantframe/plantframe.py b/src/openalea/mtg/plantframe/plantframe.py index 66d221b..c35c8cd 100644 --- a/src/openalea/mtg/plantframe/plantframe.py +++ b/src/openalea/mtg/plantframe/plantframe.py @@ -56,7 +56,7 @@ error = True epsilon = 1e-5 -class PlantFrame(object): +class PlantFrame(): ''' Engine to compute the geometry of a plant based on its topological description and parameters. ''' diff --git a/src/openalea/mtg/rewriting.py b/src/openalea/mtg/rewriting.py index 0dd566f..c41dda1 100644 --- a/src/openalea/mtg/rewriting.py +++ b/src/openalea/mtg/rewriting.py @@ -20,7 +20,7 @@ #### Module declaration ####### -class Module(object): +class Module(): def __init__(self, name, scale, **parameters): self.name = name self.scale = scale @@ -299,7 +299,7 @@ def interpretation(f): eForward, eBackward = 1,0 -class MTGLsystem(object): +class MTGLsystem(): rules = dict() def __init__(self): diff --git a/src/openalea/mtg/traversal.py b/src/openalea/mtg/traversal.py index 4b9f2f0..c0d7d2e 100644 --- a/src/openalea/mtg/traversal.py +++ b/src/openalea/mtg/traversal.py @@ -271,7 +271,7 @@ def traverse_tree(tree, vtx_id, visitor): yield visitor.post_order(vtx_id) -class Visitor(object): +class Visitor(): ''' Used during a tree traversal. ''' def pre_order(self, vtx_id): diff --git a/src/openalea/mtg/tree.py b/src/openalea/mtg/tree.py index dd2d66a..faad5c0 100644 --- a/src/openalea/mtg/tree.py +++ b/src/openalea/mtg/tree.py @@ -43,7 +43,7 @@ class InvalidVertex (GraphError, KeyError) : exception raised when a wrong vertex id is provided """ -class Tree(object): +class Tree(): ''' Implementation of a rooted :class:`Tree`, with methods to add and remove vertex. diff --git a/src/openalea/mtg/version.py b/src/openalea/mtg/version.py index 15d5f2e..5429bda 100644 --- a/src/openalea/mtg/version.py +++ b/src/openalea/mtg/version.py @@ -7,7 +7,7 @@ minor = 2 """(int) Version minor component.""" -post = 0 +post = 1 """(int) Version post or bugfix component.""" __version__ = ".".join([str(s) for s in (major, minor, post)])