Creating a new GUI

The modular design of pySimiam allows the use of any graphics engine. Even an HTML implementation should be possible. However, the creation of a new interface is a complicated task, as it has to support the rendering of the robots, and the control of supervisor parameters.

At the moment, only a Qt interface is implemented. It can be used as a source of inspiration, but a new UI does not have to follow exactly the same design. The only requirement is a correct processing of the simulator messages.

Todo

Specify the message types and possible responses.

Subclassing Renderer

Todo

Describe the Renderer interface

API

class renderer.Renderer(canvas)[source]

The Renderer class is an abstract class describing a generalized drawing engine. It has to be subclassed to implement the drawing in a way specific to the UI that the program is using.

The base class does not impose any restrictions on the type of the canvas parameter. It is up to a specific implementation to interpret this parameter correctly.

Renderer.add_pose(pose)[source]

Add a pose transformation to the current transformation

Renderer.clear_screen()[source]

Clears the canvas and draws the grid if necessary

To be implemented in subclasses.

Renderer.draw_arrow(x1, y1, x2, y2, angle=0.3, ratio=0.1, close=False)[source]

Draw an arrow from (x1, y1) to (x2, y2). You can also specify the arrowhead angle (in radians), the ratio between arrowhead and arrow length and the triangular (close=True) or linear (close=False) arrowhead shape.

Renderer.draw_ellipse(cx, cy, ra, rb=None)[source]

Draws an ellipse with current pen and fills it with current brush.

The center of the ellipse is at (cx, cy), the half-axes are ra and rb. In the case rb is not specified, the method draws a circle of radius ra.

Renderer.draw_line(x1, y1, x2, y2)[source]

Draw a line using the current pen from (x1,y1) to (x2, y2)

Renderer.draw_point(x, y)

Draw a single point using the current pen at (x,y)

Renderer.draw_points(points)

Draw a set of points, given as [(x,y)], using the current pen

Renderer.draw_polygon(points)[source]

Draws a polygon with current pen and fills it with current brush

Expects a list of points as a list of tuples or as a numpy array.

Renderer.draw_rectangle(x, y, width, height)[source]

Draws a rectangle with current pen and fills it with current brush

The bottom-left corner of the rectangle is at (x, y), if the width and height are positive.

Renderer.pop_state()[source]

Restore the last saved state from the stack

The state includes default pose, pen and brush.

To be implemented in subclasses.

Renderer.push_state()[source]

Store the current state on the stack.

Current state includes default pose, pen and brush.

To be implemented in subclasses.

Renderer.reset_canvas_size(size)[source]

Change canvas size

On canvas rescale the zoom factor will be recalculated: If the view rect was set, the view will be rescaled to fit the rect. If the view rect was not set, the zoom factor and default pose will be kept.

Renderer.reset_pose()[source]

Resets the renderer to default pose and zoom level

Renderer.rotate(angle)[source]

Rotate canvas by angle (in radians)

To be implemented in subclasses.

Renderer.scale(factor)[source]

Scale all drawing operations by factor

To be implemented in subclasses.

Renderer.scale_zoom_level(factor)[source]

Zoom up the drawing by an additional factor

Equivalent to set_zoom_level(zoom_level*factor)

The zoom center is at the last set screen pose. This method will clear the canvas.

Renderer.set_brush(color)[source]

Sets the fill color.

The color is an integer, interpreted as 0xAARRGGBB. In the case AA == 0 the color is considered fully opaque.

Use None to unset a brush.

Renderer.set_canvas(canvas)[source]

Tell the renderer to draw on canvas.

The type of canvas is implementation-dependent

Renderer.set_pen(color=0, thickness=1)[source]

Sets the line color anf thickness.

Color is interpreted as 0xAARRGGBB. In case AA == 0 the color is considered fully opaque.

Use None to unset a pen.

Renderer.set_pose(pose)[source]

Set a coordinate transformation based on pose

Renderer.set_screen_center_pose(pose)[source]

Set the pose of center of the canvas

The zoom center will switch to canvas center.

Parameters:pose (Pose) – The new pose of the lower-left corner.
Renderer.set_screen_pose(pose)[source]

Set the pose of the lower-left corner of the canvas.

The zoom center will switch to that corner.

Parameters:pose (Pose) – The new pose of the lower-left corner.
Renderer.set_view_rect(x, y, width, height)[source]

Zoom on the rectangle to fit it into the view

Renderer.set_zoom_level(zoom_level)[source]

Zoom up the drawing by a factor of zoom_level

The zoom center is at the last set screen pose.

This method will clear the canvas.

Renderer.show_grid(show=True)[source]

Draw the grid on the canvas background by default.

The grid is adaptive, with minimum interline distance of 40 px, and a maximum of 80 px. In the case the interline distance has to be smaller or larger, it is scaled. The interval is divided either in half, in five parts or in ten parts, to keep the grid decimal.

This method will clear the canvas

Renderer.translate(dx, dy)[source]

Translate canvas by dx, dy

To be implemented in subclasses.

Table Of Contents

Previous topic

Supervisor/Controller system

Next topic

PySimiam API Documentation

This Page