2 Copyright 2008 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
19 ##@package grc_gnuradio.Port
20 #Flow graph block port (source or sink).
23 from grc.elements.Port import Port as _Port
25 from grc.Constants import MAX_NUM_PORTS
30 TYPES = ['complex', 'float', 'int', 'short', 'byte']
32 def __init__(self, block, n):
34 Make a new port from nested data.
35 @param block the parent element
36 @param n the nested odict
39 vlen = Utils.exists_or_else(n, 'vlen', '1')
40 nports = Utils.exists_or_else(n, 'nports', '')
41 optional = Utils.exists_or_else(n, 'optional', '')
50 self._optional = bool(optional)
54 Get the vector length.
55 If the evaluation of vlen cannot be cast to an integer, return 1.
56 @return the vector length or 1
58 vlen = self.get_parent().resolve_dependencies(self._vlen)
59 try: return int(self.get_parent().get_parent().evaluate(vlen))
64 Get the number of ports.
65 If already blank, return a blank
66 If the evaluation of nports cannot be cast to an integer, return 1.
67 @return the number of ports or 1
69 nports = self.get_parent().resolve_dependencies(self._nports)
70 #return blank if nports is blank
71 if not nports: return ''
73 nports = int(self.get_parent().get_parent().evaluate(nports))
74 assert(0 < nports <= MAX_NUM_PORTS)
78 def get_optional(self): return bool(self._optional)
82 Get the color that represents this port's type.
83 Codes differ for ports where the vec length is 1 or greater than 1.
84 @return a hex color code.
87 if self.get_vlen() == 1:
95 return {#vlen is non 1
102 except: return _Port.get_color(self)
107 An empty port has no connections.
108 Not empty of optional is set.
109 @return true if empty
111 return not self.get_optional() and not self.get_connections()
115 def __init__(self, block, n):
118 n['key'] = str(block._source_count)
119 block._source_count = block._source_count + 1
120 Port.__init__(self, block, n)
123 self.get_parent()._source_count = self.get_parent()._source_count - 1
127 def __init__(self, block, n):
130 n['key'] = str(block._sink_count)
131 block._sink_count = block._sink_count + 1
132 Port.__init__(self, block, n)
135 self.get_parent()._sink_count = self.get_parent()._sink_count - 1