added continuation mode for pad source and sinks
authorJosh Blum <josh@joshknows.com>
Thu, 20 Aug 2009 08:30:23 +0000 (01:30 -0700)
committerJosh Blum <josh@joshknows.com>
Thu, 20 Aug 2009 08:30:23 +0000 (01:30 -0700)
grc/base/Block.py
grc/blocks/pad_sink.xml
grc/blocks/pad_source.xml
grc/python/flow_graph.tmpl
grc/todo.txt

index 82d27656785609e3b8eb12b7e68a85b2e12f0380..349e71f76b212f322d42a479161735186941cd64 100644 (file)
@@ -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):
 
index 477f2ad13a044a8911bd2e8db37488fdb522059a..999de315dbb166f7b057459d375be982e6a8401e 100644 (file)
@@ -8,6 +8,20 @@
        <name>Pad Sink</name>
        <key>pad_sink</key>
        <make></make>
+       <param>
+               <name>Mode</name>
+               <key>mode</key>
+               <value>hb</value>
+               <type>enum</type>
+               <option>
+                       <name>Hierarchical</name>
+                       <key>hb</key>
+               </option>
+               <option>
+                       <name>Continuation</name>
+                       <key>cont</key>
+               </option>
+       </param>
        <param>
                <name>Num Inputs</name>
                <key>nports</key>
                <nports>$nports</nports>
        </sink>
        <doc>
-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.
        </doc>
 </block>
index b6ef2c55d1e2f2e6bbc3770ff066716d4da2b644..26491adb3986b16455e3ae07b0eac7f3b43263b2 100644 (file)
@@ -8,6 +8,20 @@
        <name>Pad Source</name>
        <key>pad_source</key>
        <make></make>
+       <param>
+               <name>Mode</name>
+               <key>mode</key>
+               <value>hb</value>
+               <type>enum</type>
+               <option>
+                       <name>Hierarchical</name>
+                       <key>hb</key>
+               </option>
+               <option>
+                       <name>Continuation</name>
+                       <key>cont</key>
+               </option>
+       </param>
        <param>
                <name>Num Outputs</name>
                <key>nports</key>
                <value>1</value>
                <type>int</type>
        </param>
+       <param>
+               <name>Pad Sink ID</name>
+               <key>pad_sink_id</key>
+               <value>pad_sink_0</value>
+               <type>string</type>
+               <hide>#if $mode() == 'cont' then 'none' else 'all'#</hide>
+       </param>
        <check>$vlen &gt; 0</check>
        <check>0 &lt; $nports</check>
        <source>
                <nports>$nports</nports>
        </source>
        <doc>
-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.
        </doc>
 </block>
index df346dd165567002a34fcfbcd2787818ef43cbea..32139636af8fcdec8aa319ec1e7a714a219052df 100644 (file)
@@ -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
 
 ########################################################
index bb40e1f160fe4009dec974596cefed2ca38f0284..577e4c3308799f180a7b2dc604a6aa7213bf1fd8 100644 (file)
@@ -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