From bf232a6e6e73d156c9a46c26842480352c6794c0 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 20 Aug 2009 01:30:23 -0700 Subject: [PATCH] added continuation mode for pad source and sinks --- grc/base/Block.py | 4 +++- grc/blocks/pad_sink.xml | 21 ++++++++++++++++++--- grc/blocks/pad_source.xml | 31 +++++++++++++++++++++++++++---- grc/python/flow_graph.tmpl | 17 +++++++++++++++++ grc/todo.txt | 2 ++ 5 files changed, 67 insertions(+), 8 deletions(-) diff --git a/grc/base/Block.py b/grc/base/Block.py index 82d27656..349e71f7 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -47,7 +47,9 @@ class TemplateArg(UserDict): return self._param.get_evaluated() def _get_keys(lst): return [elem.get_key() for elem in lst] -def _get_elem(lst, key): return lst[_get_keys(lst).index(key)] +def _get_elem(lst, key): + try: return lst[_get_keys(lst).index(key)] + except ValueError: raise ValueError, 'Key "%s" not found in %s.'%(key, _get_keys(lst)) class Block(Element): diff --git a/grc/blocks/pad_sink.xml b/grc/blocks/pad_sink.xml index 477f2ad1..999de315 100644 --- a/grc/blocks/pad_sink.xml +++ b/grc/blocks/pad_sink.xml @@ -8,6 +8,20 @@ Pad Sink pad_sink + + Mode + mode + hb + enum + + + Num Inputs nports @@ -59,10 +73,11 @@ $nports -This is a sink pad block for creating hierarchical flow graphs. \ +Continuation Mode: +The inputs of this block can be aliased by one or more pad source blocks. + +Hierarchical Mode: The inputs of this block will become the outputs to this flow graph when it is instantiated as a hierarchical block. \ Limit one sink pad block per flow graph. - -Remember to set the generate options to hier block. diff --git a/grc/blocks/pad_source.xml b/grc/blocks/pad_source.xml index b6ef2c55..26491adb 100644 --- a/grc/blocks/pad_source.xml +++ b/grc/blocks/pad_source.xml @@ -8,6 +8,20 @@ Pad Source pad_source + + Mode + mode + hb + enum + + + Num Outputs nports @@ -50,6 +64,13 @@ 1 int + + Pad Sink ID + pad_sink_id + pad_sink_0 + string + #if $mode() == 'cont' then 'none' else 'all'# + $vlen > 0 0 < $nports @@ -59,10 +80,12 @@ $nports -This is a source pad block for creating hierarchical flow graphs. \ -The outputs of this block will become the inputs to this flow graph when it is instantiated as a hierarchical block. \ -Limit one source pad block per flow graph. +Continuation Mode: +The outputs of this block will alias the inputs of the pad sink specified by "pad sink id". -Remember to set the generate options to hier block. +Hierarchical Mode: +The outputs of this block will become the inputs to this flow graph when it is instantiated as a hierarchical block. \ +Limit one source pad block per flow graph. \ +The "pad sink id" will be ignored in this mode. diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl index df346dd1..32139636 100644 --- a/grc/python/flow_graph.tmpl +++ b/grc/python/flow_graph.tmpl @@ -161,8 +161,20 @@ class $(class_name)(gr.hier_block2): $DIVIDER #end if #for $con in $connections + #################################################################### + ## Logic to extract source and sink + ## Special resolution logic for pad source in continuation mode + #################################################################### #set $source = $con.get_source() #set $sink = $con.get_sink() + #if $source.get_parent().get_key() == 'pad_source' and $source.get_parent().get_param('mode').get_value() == 'cont' + #set $pad_sink_id = $source.get_parent().get_param('pad_sink_id').get_evaluated() + #set $pad_sink = filter(lambda b: b.get_id() == pad_sink_id, $blocks)[0] + #set $source = $pad_sink.get_sink($source.get_key()).get_connections()[0].get_source() + #end if + #################################################################### + ## Logic to extract source and sink names + #################################################################### #if $source.get_parent().get_key() == 'pad_source' #set $source_name = 'self' #else @@ -173,7 +185,12 @@ class $(class_name)(gr.hier_block2): #else #set $sink_name = 'self.' + $sink.get_parent().get_id() #end if + #################################################################### + ## Dont make a connection for continuation pad sinks!!! + #################################################################### + #if not ($sink.get_parent().get_key() == 'pad_sink' and $sink.get_parent().get_param('mode').get_value() == 'cont') self.connect(($source_name, $source.get_key()), ($sink_name, $sink.get_key())) + #end if #end for ######################################################## diff --git a/grc/todo.txt b/grc/todo.txt index bb40e1f1..577e4c33 100644 --- a/grc/todo.txt +++ b/grc/todo.txt @@ -59,6 +59,8 @@ ################################################## # Problems ################################################## +* need a way to make an id param in the xml that will override the default + * ex: display pad sink id in continuation mode using hide tag for id param * hier block generation * auto generate hier library on changes * auto clean hier library when block removed -- 2.47.2