Added virtual sink and logic to clone port.
authorJosh Blum <josh@joshknows.com>
Wed, 26 Aug 2009 18:23:23 +0000 (11:23 -0700)
committerJosh Blum <josh@joshknows.com>
Wed, 26 Aug 2009 18:23:23 +0000 (11:23 -0700)
Tweaks to the base validation routines.
Validate twice in the update until rewrite functions are implemented.

grc/base/Block.py
grc/base/FlowGraph.py
grc/blocks/Makefile.am
grc/blocks/block_tree.xml
grc/blocks/virtual_sink.xml [new file with mode: 0644]
grc/gui/ActionHandler.py
grc/gui/FlowGraph.py
grc/python/Port.py

index 349e71f76b212f322d42a479161735186941cd64..491c594cc8bf71aeb31c1fbf3593cccd00a6671d 100644 (file)
@@ -145,13 +145,12 @@ class Block(Element):
                Validate the block.
                All ports and params must be valid.
                All checks must evaluate to true.
+               Validate the params, ports, and the connections to this block.
                """
                Element.validate(self)
                for c in self.get_params() + self.get_ports() + self.get_connections():
-                       try:
-                               c.validate()
-                               assert c.is_valid()
-                       except AssertionError:
+                       c.validate()
+                       if not c.is_valid():
                                for msg in c.get_error_messages():
                                        self.add_error_message('>>> %s:\n\t%s'%(c, msg))
 
index ea489e948679b6106d9ea4d85b75534ca2627e0a..fe493cce1f39a2918e1e150270fe3a26cb523c1e 100644 (file)
@@ -150,14 +150,14 @@ class FlowGraph(Element):
        def validate(self):
                """
                Validate the flow graph.
-               All connections and blocks must be valid.
+               Validate only the blocks.
+               Connections will be validated within the blocks.
                """
                Element.validate(self)
-               for c in self.get_elements():
-                       try:
-                               c.validate()
-                               assert c.is_valid()
-                       except AssertionError: self.add_error_message('Element "%s" is not valid.'%c)
+               for c in self.get_blocks():
+                       c.validate()
+                       if not c.is_valid():
+                               self.add_error_message('Element "%s" is not valid.'%c)
 
        ##############################################
        ## Import/Export Methods
index caae6ce7540e7c8465a91c94d4feb23ce8ab8376..328661510b6783ac87c8bced9d3b67f6ea5de425 100644 (file)
@@ -218,6 +218,7 @@ dist_ourdata_DATA = \
        variable_slider.xml \
        variable_static_text.xml \
        variable_text_box.xml \
+       virtual_sink.xml \
        wxgui_constellationsink2.xml \
        wxgui_fftsink2.xml \
        wxgui_histosink2.xml \
index 5b45466f59289a25759b88bc5322debd24ca87e9..772320d1b2413bda43afc88a08c784c58d9a8a90 100644 (file)
@@ -35,6 +35,7 @@
                <block>gr_wavfile_sink</block>
                <block>gr_message_sink</block>
                <block>pad_sink</block>
+               <block>virtual_sink</block>
        </cat>
        <cat>
                <name>Graphical Sinks</name>
diff --git a/grc/blocks/virtual_sink.xml b/grc/blocks/virtual_sink.xml
new file mode 100644 (file)
index 0000000..314fb3d
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Virtual Sink
+###################################################
+ -->
+<block>
+       <name>Virtual Sink</name>
+       <key>virtual_sink</key>
+       <make></make>
+       <sink>
+               <name>in</name>
+               <type></type>
+       </sink>
+</block>
index 9af580e8e1e5721ad7c3f65cff0065eac69b5825..0e64aa89d1215de8b57a0b448a8accda0e37e097 100644 (file)
@@ -221,13 +221,11 @@ class ActionHandler:
                elif state == Actions.PORT_CONTROLLER_INC:
                        if self.get_flow_graph().port_controller_modify_selected(1):
                                self.get_flow_graph().update()
-                               self.get_flow_graph().update() #2 times
                                self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
                                self.get_page().set_saved(False)
                elif state == Actions.PORT_CONTROLLER_DEC:
                        if self.get_flow_graph().port_controller_modify_selected(-1):
                                self.get_flow_graph().update()
-                               self.get_flow_graph().update() #2 times
                                self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
                                self.get_page().set_saved(False)
                ##################################################
index f8028f199add9ca85120ea7ab19f53dbc93a8352..007bb622c5f04e71a94b2ca1ebf33553676f640e 100644 (file)
@@ -292,8 +292,12 @@ class FlowGraph(Element):
        def update(self):
                """
                Call update on all elements.
+               Validate twice:
+               1) elements call special rewrite rules that may break validation
+               2) elements should come up with the same results, validation can pass
                """
                self.validate()
+               self.validate()
                for element in self.get_elements(): element.update()
 
        ##########################################################################
index f71c5fa35f87e768a979c4cc84e471deb3408704..bfbac72374f11eac6a51576ede21654210939be1 100644 (file)
@@ -57,11 +57,25 @@ class Port(_Port):
                except AssertionError: self.add_error_message('Port is not connected.')
                try: assert self.is_source() or len(self.get_enabled_connections()) <= 1
                except AssertionError: self.add_error_message('Port has too many connections.')
+               ################################################################
+               # message port logic
+               ################################################################
                if self.get_type() == 'msg':
                        try: assert not self.get_nports()
                        except AssertionError: self.add_error_message('A port of type "msg" cannot have "nports" set.')
                        try: assert self.get_vlen() == 1
                        except AssertionError: self.add_error_message('A port of type "msg" must have a "vlen" of 1.')
+               ################################################################
+               # virtual sink logic
+               ################################################################
+               if self.get_parent().get_key() == 'virtual_sink':
+                       if self.get_enabled_connections(): #clone type and vlen
+                               source = self.get_enabled_connections()[0].get_source()
+                               self._type = str(source.get_type())
+                               self._vlen = str(source.get_vlen())
+                       else: #reset type and vlen
+                               self._type = ''
+                               self._vlen = ''
 
        def get_vlen(self):
                """