summaryrefslogtreecommitdiff
path: root/grc
diff options
context:
space:
mode:
authorjblum2009-02-06 19:01:10 +0000
committerjblum2009-02-06 19:01:10 +0000
commitc077a28498d2691f28e34846667575a8c4dc6859 (patch)
tree37df84b3c15508ace6f5668e10d7713db0186be8 /grc
parentf23f2dee67cf7a0e3aa7ccfbf889ecc2177826bf (diff)
downloadgnuradio-c077a28498d2691f28e34846667575a8c4dc6859.tar.gz
gnuradio-c077a28498d2691f28e34846667575a8c4dc6859.tar.bz2
gnuradio-c077a28498d2691f28e34846667575a8c4dc6859.zip
grc: better handling of disabled elements
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10403 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc')
-rw-r--r--grc/src/gui/Messages.py2
-rw-r--r--grc/src/platforms/base/Block.py3
-rw-r--r--grc/src/platforms/base/Connection.py6
-rw-r--r--grc/src/platforms/base/Element.py7
-rw-r--r--grc/src/platforms/base/Port.py33
-rw-r--r--grc/src/platforms/python/Block.py1
-rw-r--r--grc/src/platforms/python/Port.py16
7 files changed, 22 insertions, 46 deletions
diff --git a/grc/src/gui/Messages.py b/grc/src/gui/Messages.py
index bd7b4b2b7..e8e36f90f 100644
--- a/grc/src/gui/Messages.py
+++ b/grc/src/gui/Messages.py
@@ -91,7 +91,7 @@ def send_fail_save(file_path):
################# functions for connections ########################################
def send_fail_connection():
- send('>>> Warning: A connection can only be created between a source and an unconnected sink.\n')
+ send('>>> Error: Cannot create connection.\n')
################# functions for preferences ########################################
def send_fail_load_preferences(prefs_file_path):
diff --git a/grc/src/platforms/base/Block.py b/grc/src/platforms/base/Block.py
index 89a4c4383..8cbcad5a7 100644
--- a/grc/src/platforms/base/Block.py
+++ b/grc/src/platforms/base/Block.py
@@ -142,8 +142,7 @@ class Block(Element):
All ports and params must be valid.
All checks must evaluate to true.
"""
- if not self.get_enabled(): return
- for c in self.get_params() + self.get_sinks() + self.get_sources() + self.get_connections():
+ for c in self.get_params() + self.get_ports() + self.get_connections():
try: assert(c.is_valid())
except AssertionError:
for msg in c.get_error_messages():
diff --git a/grc/src/platforms/base/Connection.py b/grc/src/platforms/base/Connection.py
index 954d4866a..b8b75ac13 100644
--- a/grc/src/platforms/base/Connection.py
+++ b/grc/src/platforms/base/Connection.py
@@ -37,10 +37,10 @@ class Connection(Element):
for port in (porta, portb):
if port.is_source(): source = port
if port.is_sink(): sink = port
- #verify the source and sink
assert(source and sink)
- assert(not source.is_full())
- assert(not sink.is_full())
+ #ensure that this connection (source -> sink) is unique
+ for connection in self.get_parent().get_connections():
+ assert not (connection.get_source() is source and connection.get_sink() is sink)
self._source = source
self._sink = sink
diff --git a/grc/src/platforms/base/Element.py b/grc/src/platforms/base/Element.py
index b6602a314..a16be9127 100644
--- a/grc/src/platforms/base/Element.py
+++ b/grc/src/platforms/base/Element.py
@@ -41,10 +41,13 @@ class Element(object):
def is_valid(self):
self._error_messages = []#reset err msgs
- try: self.validate()
- except: pass
+ if self.get_enabled():
+ try: self.validate()
+ except: pass
return not self.get_error_messages()
+ def get_enabled(self): return True
+
def _add_error_message(self, msg):
self._error_messages.append(msg)
diff --git a/grc/src/platforms/base/Port.py b/grc/src/platforms/base/Port.py
index 672b2e4db..26ad1fc4a 100644
--- a/grc/src/platforms/base/Port.py
+++ b/grc/src/platforms/base/Port.py
@@ -47,8 +47,6 @@ class Port(Element):
Validate the port.
The port must be non-empty and type must a possible type.
"""
- try: assert(not self.is_empty())
- except AssertionError: self._add_error_message('Port is not connected.')
try: assert(self.get_type() in self.TYPES)
except AssertionError: self._add_error_message('Type "%s" is not a possible type.'%self.get_type())
@@ -59,17 +57,11 @@ class Port(Element):
return 'Sink - %s(%s)'%(self.get_name(), self.get_key())
def is_port(self): return True
-
def get_color(self): return '#FFFFFF'
-
def get_name(self): return self._name
-
def get_key(self): return self._key
-
def is_sink(self): return self in self.get_parent().get_sinks()
-
def is_source(self): return self in self.get_parent().get_sources()
-
def get_type(self): return self.get_parent().resolve_dependencies(self._type)
def get_connections(self):
@@ -81,26 +73,9 @@ class Port(Element):
connections = filter(lambda c: c.get_source() is self or c.get_sink() is self, connections)
return connections
- def is_connected(self):
- """
- Is this port connected?
- @return true if at least one connection
+ def get_enabled_connections(self):
"""
- return bool(self.get_connections())
-
- def is_full(self):
- """
- Is this port full of connections?
- Generally a sink can handle one connection and a source can handle many.
- @return true if the port is full
- """
- if self.is_source(): return False
- if self.is_sink(): return bool(self.get_connections())
-
- def is_empty(self):
- """
- Is this port empty?
- An empty port has no connections.
- @return true if empty
+ Get all enabled connections that use this port.
+ @return a list of connection objects
"""
- return not self.get_connections()
+ return filter(lambda c: c.get_enabled(), self.get_connections())
diff --git a/grc/src/platforms/python/Block.py b/grc/src/platforms/python/Block.py
index 655a6ec55..91b86cc85 100644
--- a/grc/src/platforms/python/Block.py
+++ b/grc/src/platforms/python/Block.py
@@ -69,6 +69,7 @@ class Block(_Block):
try: assert check_eval
except AssertionError: self._add_error_message('Check "%s" failed.'%check)
except: self._add_error_message('Check "%s" did not evaluate.'%check)
+ #adjust nports
for ports, Port in (
(self._sources, self.get_parent().get_parent().Source),
(self._sinks, self.get_parent().get_parent().Sink),
diff --git a/grc/src/platforms/python/Port.py b/grc/src/platforms/python/Port.py
index e75b47e4b..73ec07242 100644
--- a/grc/src/platforms/python/Port.py
+++ b/grc/src/platforms/python/Port.py
@@ -46,6 +46,13 @@ class Port(_Port):
self._vlen = vlen
self._optional = bool(optional)
+ def validate(self):
+ _Port.validate(self)
+ try: assert(self.get_enabled_connections() or self.get_optional())
+ 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.')
+
def get_vlen(self):
"""
Get the vector length.
@@ -98,15 +105,6 @@ class Port(_Port):
}[self.get_type()]
except: return _Port.get_color(self)
- def is_empty(self):
- """
- Is this port empty?
- An empty port has no connections.
- Not empty of optional is set.
- @return true if empty
- """
- return not self.get_optional() and not self.get_connections()
-
class Source(Port):
def __init__(self, block, n):