def define_wire(self, name, args, opts): """Createa a wire object with name NAME. Parameters (x, y, x2, y2, width and color) are taken from ARGS. Arrowhead and arrowtail are created if 'h' option and 't' option are specified, respectively.""" x, y, x2, y2, width, color = get_args( args, [0.25, 0.25, 0.75, 0.75, 1, 'white']) x, y = self.expand_position(x, y) x2, y2 = self.expand_position(x2, y2) self.validate_color(color) obj = cellx.Object( type='wire', name=name, x=x, y=y, x2=x2, y2=y2, width=width, color=color, priority=-10, ) self.cell.add(obj) # FIXME: head size must be configurable # force arrowhead to have a right angle if 'h' in opts: self._define_arrowhead(name + '_head', x, y2, x2, y2, width * 2, color) if 't' in opts: self._define_arrowhead(name + '_tail', x2, y, x, y, width * 2, color) return obj
def update_status(self): """Redefine the cell object with name '_status', which is used to display the running status.""" def status_string(self): """Compose and return a string summarizing the current display status.""" elapsed = time.time() - self.time_started if elapsed <= 1.: return '' fps = self.frame_count / elapsed nobjs = len(self.objects) return 'FPS: {:.2f}, OBJ: {}'.format(fps, nobjs) # FIXME: avoid hard-coding obj = cellx.Object( type='text', name='_status', text=status_string(self), size=10, x=96, y=self.height - 10, color='white', priority=10, ) self.add(obj)
def define_text(self, name, args, opts): """Createa a text object with name NAME. Parameters (text, size, color, x and y) are taken from ARGS. Text alignment can be specified with 'l' option (left justified) and 'r' option (right justified).""" text, size, color, x, y = get_args(args, ['', 16, 'white', 0.5, 0.5]) # force text argument to be string text = re.sub(r'__', ' ', str(text)) self.validate_color(color) x, y = self.expand_position(x, y) align = 'center' if opts.get('l', None): align = 'left' if opts.get('r', None): align = 'right' obj = cellx.Object( type='text', name=name, text=text, align=align, size=size, x=x, y=y, color=color, priority=10, ) self.cell.add(obj) return obj
def define_bitmap(self, name, args, opts=None): """Createa a bitmap object with name NAME. Parameters (filename, x and y) are taken from ARGS.""" file, x, y = get_args(args, [None, 0.5, 0.5]) if not os.path.exists(file): if os.path.exists('figure/' + file): file = 'figure/' + file else: self.abort('define_bitmap: not found: {}'.format(file)) x, y = self.expand_position(x, y) obj = cellx.Object( type='bitmap', name=name, file=file, x=x, y=y, ) self.cell.add(obj) return obj
def define_ellipse(self, name, args, opts): """Createa an ellipse with name NAME. Parameters (rx, ry, color, x, and y) are taken from ARGS. Frame color can be specified with 'f' option (e.g., opts = { 'f': 'cyan'}).""" rx, ry, color, x, y = get_args(args, [10, 10, 'white', 0.5, 0.5]) rx, ry = self.expand_position(rx, ry) self.validate_color(color) x, y = self.expand_position(x, y) obj = cellx.Object( type='ellipse', name=name, width=rx * 2, height=ry * 2, color=color, x=x, y=y, frame_color=opts.get('f', None), ) self.cell.add(obj) return obj
def define_polygon(self, name, args, opts): """Createa a polygon with name NAME. Parameters (n, r, color, x, y) are taken from ARGS. Rotation and frame color can be specified with 'r' option and 'f' option, respectively.""" n, r, color, x, y = get_args(args, [3, 10, 'white', 0.5, 0.5]) self.validate_color(color) x, y = self.expand_position(x, y) obj = cellx.Object( type='polygon', name=name, n=n, width=r * 2, height=r * 2, color=color, x=x, y=y, rotation=float(opts.get('r', 0)), frame_color=opts.get('f', None), ) self.cell.add(obj) return obj
def define_link(self, name, args): """Createa a link named NAME connecting two cell objects. Parameters (src_name, dst_name, width, and color) are taken from ARGS.""" src_name, dst_name, width, color = get_args(args, [None, None, 1, 'white']) if not self.cell.object(src_name): self.abort("undefined object '{}'".format(src_name)) if not self.cell.object(dst_name): self.abort("undefined object '{}'".format(dst_name)) self.validate_color(color) obj = cellx.Object( type='link', name=name, src=self.cell.object(src_name), dst=self.cell.object(dst_name), width=width, color=color, priority=-20, ) self.cell.add(obj) return obj
def define_box(self, name, args, opts=None): """Createa a box object with name NAME. Parameters (width, height, color, x, and y) are taken from ARGS. Frame color can be specified with 'f' option (e.g., opts = { 'f': 'cyan'}).""" width, height, color, x, y = get_args(args, [10, 10, 'white', 0.5, 0.5]) width, height = self.expand_position(width, height) self.validate_color(color) x, y = self.expand_position(x, y) obj = cellx.Object( type='box', name=name, width=width, height=height, color=color, x=x, y=y, frame_color=opts.get('f', None), ) self.cell.add(obj) return obj