def from_mxCell(el, batch, windowSize, lineWidth=10): # Parse style style = parse_style(el.attrib['style']) # Get parent style['parent'] = el.attrib['parent'] # Get geometry geometry = el[0] x = float(geometry.attrib.get('x', '0')) y = float(geometry.attrib.get('y', '0')) width = float(geometry.attrib['width']) height = float(geometry.attrib['height']) # Create drawing (x, y) = translate_coordinates((x, y), windowSize, height) pos = Position(x=x, y=y, w=width, h=height, movable=False) rotate = 0 if style.get('rotation', '') != '': rotate = int(style['rotation']) if rotate < 0: rotate = 360 + rotate pos.angle = rotate draw = None col_points = None center = (pos.x + pos.w // 2, pos.y + pos.h // 2) if 'ellipse' in style: draw = primitives.Ellipse(center, width, height, style, rotate) col_points = draw._get_points() else: draw = primitives.Rectangle(x, y, width, height, style, rotate) col_points = pos._get_box() label = el.attrib.get('value', '') if label: label = pyglet.text.HTMLLabel(label, batch=batch, x=center[0], y=center[1], anchor_x='center', anchor_y='center') batch_draw = draw.add_to_batch(batch) col_points = list(map(lambda x: Vector(x[0] - center[0], x[1] - center[1]), col_points)) collision_box = Poly(Vector(center[0], center[1]), col_points) return [pos, Collidable(shape=collision_box)], style, batch_draw
def from_mxCell(el, batch, windowSize, lineWidth=10): # Parse style style = parse_style(el.attrib['style']) if style.get('shape') != 'mxgraph.floorplan.wall': raise Exception("Cannot create Wall from {}: shape is not mxgraph.floorplan.wall".format(el)) # Get parent parent_element = el.attrib['parent'] style['parent'] = parent_element # Get geometry geometry = el[0] x = float(geometry.attrib.get('x', '0')) y = float(geometry.attrib.get('y', '0')) width = float(geometry.attrib['width']) height = float(geometry.attrib['height']) # Create drawing (x, y) = translate_coordinates((x, y), windowSize, height) pos = Position(x=x, y=y, w=width, h=height, movable=False) rotate = 0 if 'rotation' in style: rotate = int(style['rotation']) if rotate < 0: rotate = 360 + rotate pos.angle = rotate label = el.attrib.get('value', '') if label: label = pyglet.text.HTMLLabel(label, batch=batch, x=center[0], y=center[1], anchor_x='center', anchor_y='center') # Create collision box col_points = pos._get_box() center = (pos.x + pos.w // 2, pos.y + pos.h // 2) col_points = list(map(lambda x: Vector(x[0] - center[0], x[1] - center[1]), col_points)) collision_box = Poly(Vector(center[0], center[1]), col_points) rectangle = primitives.Rectangle(x, y, width, height, style, rotate) rectangle.add_to_batch(batch) return ([pos, Collidable(shape=collision_box)], style)