commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 01/01: grc: fix for block bypass where the


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/01: grc: fix for block bypass where the next block is a virtual sink and moved bypass code in generator
Date: Tue, 4 Aug 2015 09:37:25 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 5cc562c0cb8fd5ce44a16e082d5891d9ca9b339f
Author: Seth Hitefield <address@hidden>
Date:   Fri Jul 31 15:29:56 2015 -0400

    grc: fix for block bypass where the next block is a virtual sink and moved 
bypass code in generator
---
 grc/base/FlowGraph.py      | 38 ++-------------------------------
 grc/python/Generator.py    | 53 +++++++++++++++++++++++++++++++++++++++++++---
 grc/python/flow_graph.tmpl |  9 +-------
 3 files changed, 53 insertions(+), 47 deletions(-)

diff --git a/grc/base/FlowGraph.py b/grc/base/FlowGraph.py
index 7fd8df5..52ec741 100644
--- a/grc/base/FlowGraph.py
+++ b/grc/base/FlowGraph.py
@@ -147,7 +147,7 @@ class FlowGraph(Element):
 
     def get_enabled_blocks(self):
         """
-        Get a list of all blocks that are enabled.
+        Get a list of all blocks that are enabled and not bypassed.
 
         Returns:
             a list of blocks
@@ -170,41 +170,7 @@ class FlowGraph(Element):
         Returns:
             a list of connections
         """
-        # First get all the enabled connections, then get the bypassed blocks.
-        connections = filter(lambda c: c.get_enabled(), self.get_connections())
-        bypassed_blocks = self.get_bypassed_blocks()
-
-        # Bypassing blocks: Need to find all the enabled connections for the 
block using
-        # the *connections* object rather than get_connections(). Create new 
connections
-        # that bypass the selected block and remove the existing ones. This 
allows adjacent
-        # bypassed blocks to see the newly created connections to downstream 
blocks,
-        # allowing them to correctly construct bypass connections.
-
-        for block in bypassed_blocks:
-            # Get the upstream connection (off of the sink ports)
-            # Use *connections* not get_connections()
-            get_source_connection = lambda c: c.get_sink() == 
block.get_sinks()[0]
-            source_connection = filter(get_source_connection, connections)
-            # The source connection should never have more than one element.
-            assert (len(source_connection) == 1)
-
-            # Get the source of the connection.
-            source_port = source_connection[0].get_source()
-
-            # Loop through all the downstream connections
-            get_sink_connections = lambda c: c.get_source() == 
block.get_sources()[0]
-            for sink in filter(get_sink_connections, connections):
-                if not sink.get_enabled():
-                    # Ignore disabled connections
-                    continue
-                sink_port = sink.get_sink()
-                connection = self.get_parent().Connection(flow_graph=self, 
porta=source_port, portb=sink_port)
-                connections.append(connection)
-                # Remove this sink connection
-                connections.remove(sink)
-            # Remove the source connection
-            connections.remove(source_connection[0])
-        return connections
+        return filter(lambda c: c.get_enabled(), self.get_connections())
 
     def get_new_block(self, key):
         """
diff --git a/grc/python/Generator.py b/grc/python/Generator.py
index 98b671d..38a5052 100644
--- a/grc/python/Generator.py
+++ b/grc/python/Generator.py
@@ -166,18 +166,65 @@ class TopBlockGenerator(object):
             except:
                 pass
             return code
+
         blocks = expr_utils.sort_objects(
             self._flow_graph.get_enabled_blocks(),
             lambda b: b.get_id(), _get_block_sort_text
         )
-        # list of regular blocks (all blocks minus the special ones)
+        # List of regular blocks (all blocks minus the special ones)
         blocks = filter(lambda b: b not in (imports + parameters), blocks)
-        # list of connections where each endpoint is enabled (sorted by 
domains, block names)
-        connections = filter(lambda c: not (c.is_bus() or c.is_msg()), 
self._flow_graph.get_enabled_connections())
+
+        # Filter out virtual sink connections
+        cf = lambda c: not (c.is_bus() or c.is_msg() or 
c.get_sink().get_parent().is_virtual_sink())
+        connections = filter(cf, self._flow_graph.get_enabled_connections())
+
+        # Get the virtual blocks and resolve their conenctions
+        virtual = filter(lambda c: 
c.get_source().get_parent().is_virtual_source(), connections)
+        for connection in virtual:
+            source = connection.get_source().resolve_virtual_source()
+            sink = connection.get_sink()
+            resolved = 
self._flow_graph.get_parent().Connection(flow_graph=self._flow_graph, 
porta=source, portb=sink)
+            connections.append(resolved)
+            # Remove the virtual connection
+            connections.remove(connection)
+
+        # Bypassing blocks: Need to find all the enabled connections for the 
block using
+        # the *connections* object rather than get_connections(). Create new 
connections
+        # that bypass the selected block and remove the existing ones. This 
allows adjacent
+        # bypassed blocks to see the newly created connections to downstream 
blocks,
+        # allowing them to correctly construct bypass connections.
+        bypassed_blocks = self._flow_graph.get_bypassed_blocks()
+        for block in bypassed_blocks:
+            # Get the upstream connection (off of the sink ports)
+            # Use *connections* not get_connections()
+            get_source_connection = lambda c: c.get_sink() == 
block.get_sinks()[0]
+            source_connection = filter(get_source_connection, connections)
+            # The source connection should never have more than one element.
+            assert (len(source_connection) == 1)
+
+            # Get the source of the connection.
+            source_port = source_connection[0].get_source()
+
+            # Loop through all the downstream connections
+            get_sink_connections = lambda c: c.get_source() == 
block.get_sources()[0]
+            for sink in filter(get_sink_connections, connections):
+                if not sink.get_enabled():
+                    # Ignore disabled connections
+                    continue
+                sink_port = sink.get_sink()
+                connection = 
self._flow_graph.get_parent().Connection(flow_graph=self._flow_graph, 
porta=source_port, portb=sink_port)
+                connections.append(connection)
+                # Remove this sink connection
+                connections.remove(sink)
+            # Remove the source connection
+            connections.remove(source_connection[0])
+
+        # List of connections where each endpoint is enabled (sorted by 
domains, block names)
         connections.sort(key=lambda c: (
             c.get_source().get_domain(), c.get_sink().get_domain(),
             c.get_source().get_parent().get_id(), 
c.get_sink().get_parent().get_id()
         ))
+
         connection_templates = 
self._flow_graph.get_parent().get_connection_templates()
         msgs = filter(lambda c: c.is_msg(), 
self._flow_graph.get_enabled_connections())
         # list of variable names
diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl
index 3dd772b..3cc16e7 100644
--- a/grc/python/flow_graph.tmpl
+++ b/grc/python/flow_graph.tmpl
@@ -255,15 +255,8 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', 
'.join($size_strs))])
 #for $con in $connections
     #set global $source = $con.get_source()
     #set global $sink = $con.get_sink()
-    ##resolve virtual sources to the actual sources
-    #if $source.get_parent().is_virtual_source()
-        #set global $source = $source.resolve_virtual_source()
-    #end if
-    ##do not generate connections with virtual sinks
-    #if not $sink.get_parent().is_virtual_sink()
-        #include source=$connection_templates[($source.get_domain(), 
$sink.get_domain())]
+    #include source=$connection_templates[($source.get_domain(), 
$sink.get_domain())]
 
-    #end if
 #end for
 
 ########################################################



reply via email to

[Prev in Thread] Current Thread [Next in Thread]