summaryrefslogtreecommitdiff
path: root/grc
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-10-08 10:23:00 -0700
committerJosh Blum <josh@joshknows.com>2011-10-12 15:54:55 -0700
commit413964379c19fce5c2c0ad25d1de968a68744f4d (patch)
treecd492a076e2879e42b92375de1982841bbd24e2b /grc
parent178590c3afae08ccafd3db711e2cfa65c841403f (diff)
grc: added new IO types
Added all complex/real float/integer types. Used volk naming convention: fc32, etc... The port type checking now relies on IO size, therefore a short vector of length 2 can connect to a complex short, a float can connect to an int. Basically, the same size checking done in gnuradio runtime.
Diffstat (limited to 'grc')
-rw-r--r--grc/python/Connection.py15
-rw-r--r--grc/python/Constants.py32
-rw-r--r--grc/python/Platform.py15
-rw-r--r--grc/python/Port.py28
4 files changed, 52 insertions, 38 deletions
diff --git a/grc/python/Connection.py b/grc/python/Connection.py
index 39f9157401..218baf0743 100644
--- a/grc/python/Connection.py
+++ b/grc/python/Connection.py
@@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
+import Constants
+from .. base.Element import Element
from .. base.Connection import Connection as _Connection
from .. gui.Connection import Connection as _GUIConnection
@@ -32,11 +34,10 @@ class Connection(_Connection, _GUIConnection):
def validate(self):
"""
Validate the connections.
- The ports must match in type and vector length.
+ The ports must match in io size.
"""
- _Connection.validate(self) #checks type
- #check vector length
- source_vlen = self.get_source().get_vlen()
- sink_vlen = self.get_sink().get_vlen()
- if source_vlen != sink_vlen:
- self.add_error_message('Source vector length "%s" does not match sink vector length "%s".'%(source_vlen, sink_vlen))
+ Element.validate(self)
+ source_size = Constants.TYPE_TO_SIZEOF[self.get_source().get_type()] * self.get_source().get_vlen()
+ sink_size = Constants.TYPE_TO_SIZEOF[self.get_sink().get_type()] * self.get_sink().get_vlen()
+ if source_size != sink_size:
+ self.add_error_message('Source IO size "%s" does not match sink IO size "%s".'%(source_size, sink_size))
diff --git a/grc/python/Constants.py b/grc/python/Constants.py
index 868c822aaa..4a234f080b 100644
--- a/grc/python/Constants.py
+++ b/grc/python/Constants.py
@@ -45,6 +45,38 @@ FLOW_GRAPH_TEMPLATE = os.path.join(DATA_DIR, 'flow_graph.tmpl')
BLOCK_DTD = os.path.join(DATA_DIR, 'block.dtd')
DEFAULT_FLOW_GRAPH = os.path.join(DATA_DIR, 'default_flow_graph.grc')
+CORE_TYPES = ( #name, key, sizeof, color
+ ('Complex Float 64', 'fc64', 16, '#72f313'),
+ ('Complex Float 32', 'fc32', 8, '#3399FF'),
+ ('Complex Integer 32', 'sc32', 8, '#00b789'),
+ ('Complex Integer 16', 'sc16', 4, '#f37913'),
+ ('Complex Integer 8', 'sc8', 2, '#ff0e7f'),
+ ('Float 64', 'f64', 8, '#86a8fa'),
+ ('Float 32', 'f32', 4, '#FF8C69'),
+ ('Integer 32', 's32', 4, '#00FF99'),
+ ('Integer 16', 's16', 2, '#FFFF66'),
+ ('Integer 8', 's8', 1, '#FF66FF'),
+ ('Message Queue', 'msg', 0, '#777777'),
+ ('Wildcard', '', 0, '#FFFFFF'),
+)
+
+ALIAS_TYPES = {
+ 'complex' : (8, '#3399FF'),
+ 'float' : (4, '#FF8C69'),
+ 'int' : (4, '#00FF99'),
+ 'short' : (2, '#FFFF66'),
+ 'byte' : (1, '#FF66FF'),
+}
+
+TYPE_TO_COLOR = dict()
+TYPE_TO_SIZEOF = dict()
+for name, key, sizeof, color in CORE_TYPES:
+ TYPE_TO_COLOR[key] = color
+ TYPE_TO_SIZEOF[key] = sizeof
+for key, (sizeof, color) in ALIAS_TYPES.iteritems():
+ TYPE_TO_COLOR[key] = color
+ TYPE_TO_SIZEOF[key] = sizeof
+
#coloring
COMPLEX_COLOR_SPEC = '#3399FF'
FLOAT_COLOR_SPEC = '#FF8C69'
diff --git a/grc/python/Platform.py b/grc/python/Platform.py
index a9c2b18ad1..e036361ff0 100644
--- a/grc/python/Platform.py
+++ b/grc/python/Platform.py
@@ -32,20 +32,7 @@ from Constants import \
DEFAULT_FLOW_GRAPH, BLOCKS_DIRS
import Constants
-COLORS = (#title, #color spec
- ('Complex', Constants.COMPLEX_COLOR_SPEC),
- ('Float', Constants.FLOAT_COLOR_SPEC),
- ('Integer', Constants.INT_COLOR_SPEC),
- ('Short', Constants.SHORT_COLOR_SPEC),
- ('Byte', Constants.BYTE_COLOR_SPEC),
- ('Complex Vector', Constants.COMPLEX_VECTOR_COLOR_SPEC),
- ('Float Vector', Constants.FLOAT_VECTOR_COLOR_SPEC),
- ('Integer Vector', Constants.INT_VECTOR_COLOR_SPEC),
- ('Short Vector', Constants.SHORT_VECTOR_COLOR_SPEC),
- ('Byte Vector', Constants.BYTE_VECTOR_COLOR_SPEC),
- ('Wildcard', Constants.WILDCARD_COLOR_SPEC),
- ('Message', Constants.MSG_COLOR_SPEC),
-)
+COLORS = [(name, color) for name, key, sizeof, color in Constants.CORE_TYPES]
class Platform(_Platform, _GUIPlatform):
diff --git a/grc/python/Port.py b/grc/python/Port.py
index 3846b0f4e3..9baa811101 100644
--- a/grc/python/Port.py
+++ b/grc/python/Port.py
@@ -79,7 +79,7 @@ class Port(_Port, _GUIPort):
self._vlen = n.find('vlen') or ''
self._optional = bool(n.find('optional'))
- def get_types(self): return ('complex', 'float', 'int', 'short', 'byte', 'msg', '')
+ def get_types(self): return Constants.TYPE_TO_SIZEOF.keys()
def validate(self):
_Port.validate(self)
@@ -146,22 +146,16 @@ class Port(_Port, _GUIPort):
@return a hex color code.
"""
try:
- if self.get_vlen() == 1:
- return {#vlen is 1
- 'complex': Constants.COMPLEX_COLOR_SPEC,
- 'float': Constants.FLOAT_COLOR_SPEC,
- 'int': Constants.INT_COLOR_SPEC,
- 'short': Constants.SHORT_COLOR_SPEC,
- 'byte': Constants.BYTE_COLOR_SPEC,
- 'msg': Constants.MSG_COLOR_SPEC,
- }[self.get_type()]
- return {#vlen is non 1
- 'complex': Constants.COMPLEX_VECTOR_COLOR_SPEC,
- 'float': Constants.FLOAT_VECTOR_COLOR_SPEC,
- 'int': Constants.INT_VECTOR_COLOR_SPEC,
- 'short': Constants.SHORT_VECTOR_COLOR_SPEC,
- 'byte': Constants.BYTE_VECTOR_COLOR_SPEC,
- }[self.get_type()]
+ color = Constants.TYPE_TO_COLOR[self.get_type()]
+ if self.get_vlen() == 1: return color
+ color_val = int(color[1:], 16)
+ r = (color_val >> 16) & 0xff
+ g = (color_val >> 8) & 0xff
+ b = (color_val >> 0) & 0xff
+ r = max(r-50, 0)
+ g = max(g-50, 0)
+ b = max(b-50, 0)
+ return '#%.2x%.2x%.2x'%(r, g, b)
except: return _Port.get_color(self)
def copy(self, new_key=None):