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.
Clears the canvas and draws the grid if necessary
To be implemented in subclasses.
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.
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.
Draw a single point using the current pen at (x,y)
Draw a set of points, given as [(x,y)], using the current pen
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.
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.
Restore the last saved state from the stack
The state includes default pose, pen and brush.
To be implemented in subclasses.
Store the current state on the stack.
Current state includes default pose, pen and brush.
To be implemented in subclasses.
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.
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.
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.
Tell the renderer to draw on canvas.
The type of canvas is implementation-dependent
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.
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. |
---|
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. |
---|
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.
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
The interaction between the UI and the simulator happens through two thread-safe queues. One queue contains the commands for the simulator, the other queue contains messages from the simulator. The communication is implemented in the base ui class, ui.SimUI.
The SimUI class defines a front-end for the Simulator. It contains the necessary functions for the frontend-simulator communication and stubs for the message callbacks.
This class manages three important objects:
The constructor of SimUI takes a Renderer object as parameter. This renderer will be passed to the simulator to draw on.
Processes one or all incoming events from the simulator. A single event is a tuple (name,args). During the processing of the event, the function simulator_name will be called with args as parameters.
It is strongly discouraged to create new class methods with the name starting with simulator_. Such functions could be called from the simulator without your consent.
Unknown or malformed events will lead to an error message printed to the console.
Register a callback that will be executed to process the
Sends the command command to the simulator. All arguments after command are passed to the command processing function on the simulator side.
See Simulator for the available commands.
An exception was raised in the simulator thread in the attempt to process an incoming command.
A log message was generated by one of the simulation objects of class objclass. The objcolor is the color of the simobject, in the case the object is connected to one, and None otherwise.
A request from the supervisor to create a parameter window. robot_id is guaranteed to uniquely identify a robot in a simulation. Currently, robot_id is the actual robot object. It can be used e.g. to extract the color of the robot as robot_id.get_color(). name is the desired window name, and parameters is the structure returned by get_ui_description().
A request to redraw the simulation window. This notification signifies that the simulation has stopped using the renderer, and is waiting for the UI to process this event.
The simulation will be resumed after this function exits.
uiParameter represents a single GUI element that is used to build a parameter window in the UI (simulator event “make_param_window”).
It has one parameter, type, that defines the type of the parameter. Possible parameter types are GROUP, INT, FLOAT, BOOL and SELECT.