2 Copyright 2008, 2009 Free Software Foundation, Inc.
3 This file is part of GNU Radio
5 GNU Radio Companion is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 GNU Radio Companion is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 from .. base.Port import Port as _Port
26 TYPES = ['complex', 'float', 'int', 'short', 'byte', 'msg']
28 def __init__(self, block, n):
30 Make a new port from nested data.
31 @param block the parent element
32 @param n the nested odict
40 self._nports = n.find('nports') or ''
41 self._vlen = n.find('vlen') or ''
42 self._optional = bool(n.find('optional'))
46 try: assert self.get_enabled_connections() or self.get_optional()
47 except AssertionError: self.add_error_message('Port is not connected.')
48 try: assert self.is_source() or len(self.get_enabled_connections()) <= 1
49 except AssertionError: self.add_error_message('Port has too many connections.')
50 if self.get_type() == 'msg':
51 try: assert not self.get_nports()
52 except AssertionError: self.add_error_message('A port of type "msg" cannot have "nports" set.')
53 try: assert self.get_vlen() == 1
54 except AssertionError: self.add_error_message('A port of type "msg" must have a "vlen" of 1.')
58 Get the vector length.
59 If the evaluation of vlen cannot be cast to an integer, return 1.
60 @return the vector length or 1
62 vlen = self.get_parent().resolve_dependencies(self._vlen)
63 try: return int(self.get_parent().get_parent().evaluate(vlen))
68 Get the number of ports.
69 If already blank, return a blank
70 If the evaluation of nports cannot be cast to an integer, return 1.
71 @return the number of ports or 1
73 nports = self.get_parent().resolve_dependencies(self._nports)
74 #return blank if nports is blank
75 if not nports: return ''
77 nports = int(self.get_parent().get_parent().evaluate(nports))
82 def get_optional(self): return bool(self._optional)
86 Get the color that represents this port's type.
87 Codes differ for ports where the vec length is 1 or greater than 1.
88 @return a hex color code.
91 if self.get_vlen() == 1:
93 'complex': Constants.COMPLEX_COLOR_SPEC,
94 'float': Constants.FLOAT_COLOR_SPEC,
95 'int': Constants.INT_COLOR_SPEC,
96 'short': Constants.SHORT_COLOR_SPEC,
97 'byte': Constants.BYTE_COLOR_SPEC,
98 'msg': Constants.MSG_COLOR_SPEC,
100 return {#vlen is non 1
101 'complex': Constants.COMPLEX_VECTOR_COLOR_SPEC,
102 'float': Constants.FLOAT_VECTOR_COLOR_SPEC,
103 'int': Constants.INT_VECTOR_COLOR_SPEC,
104 'short': Constants.SHORT_VECTOR_COLOR_SPEC,
105 'byte': Constants.BYTE_VECTOR_COLOR_SPEC,
107 except: return _Port.get_color(self)
109 def copy(self, new_key=None):
111 if new_key: n['key'] = new_key
112 return self.__class__(self.get_parent(), n)
116 def __init__(self, block, n):
118 if n['type'] == 'msg': n['key'] = 'msg'
119 if not n.find('key'):
120 n['key'] = str(block._source_count)
121 block._source_count = block._source_count + 1
122 Port.__init__(self, block, n)
126 def __init__(self, block, n):
128 if n['type'] == 'msg': n['key'] = 'msg'
129 if not n.find('key'):
130 n['key'] = str(block._sink_count)
131 block._sink_count = block._sink_count + 1
132 Port.__init__(self, block, n)