diff options
Diffstat (limited to 'grc/python')
-rw-r--r-- | grc/python/.gitignore | 2 | ||||
-rw-r--r-- | grc/python/CMakeLists.txt | 8 | ||||
-rw-r--r-- | grc/python/Makefile.am | 43 | ||||
-rw-r--r-- | grc/python/Param.py | 2 | ||||
-rw-r--r-- | grc/python/Port.py | 57 |
5 files changed, 55 insertions, 57 deletions
diff --git a/grc/python/.gitignore b/grc/python/.gitignore deleted file mode 100644 index b336cc7ce..000000000 --- a/grc/python/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Makefile -/Makefile.in diff --git a/grc/python/CMakeLists.txt b/grc/python/CMakeLists.txt index 0871c7bd1..4832dd897 100644 --- a/grc/python/CMakeLists.txt +++ b/grc/python/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright 2011 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # GNU Radio is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. -# +# # GNU Radio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/grc/python/Makefile.am b/grc/python/Makefile.am deleted file mode 100644 index eb35b6fc1..000000000 --- a/grc/python/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright 2008, 2009 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common - -ourpythondir = $(pkgpythondir)/grc/python -ourpython_PYTHON = \ - convert_hier.py \ - expr_utils.py \ - extract_docs.py \ - Block.py \ - Connection.py \ - Constants.py \ - FlowGraph.py \ - Generator.py \ - Param.py \ - Platform.py \ - Port.py \ - __init__.py - -ourdatadir = $(pkgpythondir)/grc/python -dist_ourdata_DATA = \ - block.dtd \ - default_flow_graph.grc \ - flow_graph.tmpl diff --git a/grc/python/Param.py b/grc/python/Param.py index 2a7258dc7..2caca4802 100644 --- a/grc/python/Param.py +++ b/grc/python/Param.py @@ -335,7 +335,7 @@ class Param(_Param, _GUIParam): # Stream ID Type ######################### elif t == 'stream_id': - #get a list of all stream ids used in the virtual sinks + #get a list of all stream ids used in the virtual sinks ids = [param.get_value() for param in filter( lambda p: p.get_parent().is_virtual_sink(), self.get_all_params(t), diff --git a/grc/python/Port.py b/grc/python/Port.py index c2bfd9ccc..d0ef51b48 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -1,5 +1,5 @@ """ -Copyright 2008-2011 Free Software Foundation, Inc. +Copyright 2008-2012 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -24,7 +24,7 @@ import Constants def _get_source_from_virtual_sink_port(vsp): """ Resolve the source port that is connected to the given virtual sink port. - Use the get source from virtual source to recursively resolve subsequent ports. + Use the get source from virtual source to recursively resolve subsequent ports. """ try: return _get_source_from_virtual_source_port( vsp.get_enabled_connections()[0].get_source()) @@ -50,6 +50,35 @@ def _get_source_from_virtual_source_port(vsp, traversed=[]): ) except: raise Exception, 'Could not resolve source for virtual source port %s'%vsp +def _get_sink_from_virtual_source_port(vsp): + """ + Resolve the sink port that is connected to the given virtual source port. + Use the get sink from virtual sink to recursively resolve subsequent ports. + """ + try: return _get_sink_from_virtual_sink_port( + vsp.get_enabled_connections()[0].get_sink()) # Could have many connections, but use first + except: raise Exception, 'Could not resolve source for virtual source port %s'%vsp + +def _get_sink_from_virtual_sink_port(vsp, traversed=[]): + """ + Recursively resolve sink ports over the virtual connections. + Keep track of traversed sinks to avoid recursive loops. + """ + if not vsp.get_parent().is_virtual_sink(): return vsp + if vsp in traversed: raise Exception, 'Loop found when resolving virtual sink %s'%vsp + try: return _get_sink_from_virtual_sink_port( + _get_sink_from_virtual_source_port( + filter(#get all virtual source with a matching stream id + lambda vs: vs.get_param('stream_id').get_value() == vsp.get_parent().get_param('stream_id').get_value(), + filter(#get all enabled blocks that are also virtual sinks + lambda b: b.is_virtual_source(), + vsp.get_parent().get_parent().get_enabled_blocks(), + ), + )[0].get_sources()[0] + ), traversed + [vsp], + ) + except: raise Exception, 'Could not resolve source for virtual sink port %s'%vsp + class Port(_Port, _GUIPort): def __init__(self, block, n, dir): @@ -81,6 +110,8 @@ class Port(_Port, _GUIPort): def get_types(self): return Constants.TYPE_TO_SIZEOF.keys() + def is_type_empty(self): return not self._n['type'] + def validate(self): _Port.validate(self) if not self.get_enabled_connections() and not self.get_optional(): @@ -99,18 +130,30 @@ class Port(_Port, _GUIPort): Handle the port cloning for virtual blocks. """ _Port.rewrite(self) - if self.get_parent().is_virtual_sink() or self.get_parent().is_virtual_source(): + if self.is_type_empty(): try: #clone type and vlen - source = self.resolve_virtual_source() + source = self.resolve_empty_type() self._type = str(source.get_type()) self._vlen = str(source.get_vlen()) except: #reset type and vlen self._type = '' self._vlen = '' - def resolve_virtual_source(self): - if self.get_parent().is_virtual_sink(): return _get_source_from_virtual_sink_port(self) - if self.get_parent().is_virtual_source(): return _get_source_from_virtual_source_port(self) + def resolve_empty_type(self): + if self.is_sink(): + try: + src = _get_source_from_virtual_sink_port(self) + if not src.is_type_empty(): return src + except: pass + sink = _get_sink_from_virtual_sink_port(self) + if not sink.is_type_empty(): return sink + if self.is_source(): + try: + src = _get_source_from_virtual_source_port(self) + if not src.is_type_empty(): return src + except: pass + sink = _get_sink_from_virtual_source_port(self) + if not sink.is_type_empty(): return sink def get_vlen(self): """ |