node.draw module

Module draw contains a Drawing class which can used to perform drawing for the node. Class node.node.BaseNode inherits Drawing to add the drawing capability. Drawing class provides a collection of methods useful for users to add additional drawing on the simulation map. The drawing can be used to differentiate node status, shows coverage of a node, connectivity of a pair of nodes, text info beside a node, etc.

Note

This class adds drawing capability to node.node.BaseNode class. It should not be instantiated.

  • Created by: CH Foh (2021)

class node.draw.Drawing(simworld)

Bases: object

This class provides methods to perform persistent drawing for a node. This class is inherited by node.node.BaseNode, therefore the methods in this class are directly useable by a node instance. For example, to put a circle around a node, simply call:

import wx
...
my_shape = my_node.draw_circle(radius=10, pen=wx.BLUE_PEN, brush=wx.TRANSPARENT_BRUSH)
...
my_node.del_drawable(my_shape)  # remove the circle
...
my_node.clear_drawing()         # remove all drawables

The above will draw a blue circle around the node, and will follow the node if the node has moved to a new location. The circle will remain persistently around the node on the screen until the user simulation explicitly delete it or clear all shapes for the node (see above).

Note

To draw a shape or text on the map which is not necessary related to a node, please use sim.drawable.Drawable. This can be done by creating a drawable instance and then adding the drawable instance to your scenario using the methods provided by sim.scenario.BaseScenario.

Methods

clear_drawing()

Clear the drawing for this node by removing all drawables associated with this node.

del_circle(radius)

(Deprecated) Remove an earlier added circle for this node.

del_drawable(drawable)

Remove a specific drawable from the drawing list.

del_line(other_node)

(Deprecated) Remove an earlier added line for this node.

del_sector(radius, pointing_angle, width_angle)

(Deprecated) Remove an earlier added sector drawing.

del_text(dx, dy, text)

(Deprecated) Remove an earlier added text message.

draw_circle(radius[, pen, brush])

Put a circle around this node where the node is the center of the circle.

draw_line(other_node[, pen, brush])

Draw a line from this node to other_node.

draw_line_segments(points[, pen, brush])

Draw line segments around this node where (0,0) is the center of the node.

draw_sector(radius, pointing_angle, width_angle)

Draw a sector where its center is at this node, its radius is radius its pointing angle is pointing_angle, its width (in degree) is specified in width_angle.

draw_text(dx, dy, text, font[, foreground, …])

Draw a text at around this node.

__init__(simworld)

This is the default constructor which is called by node.node.BaseNode, there is no reason for user simulation to instantiate this class.

clear_drawing()

Clear the drawing for this node by removing all drawables associated with this node.

del_drawable(drawable)

Remove a specific drawable from the drawing list. The removed drawable will no longer be drawn on the screen in the future. If the drawable is not found, nothing will happen.

Parameters
drawablea drawable reference returned by a draw function

The drawable to be removed from the drawing list.

draw_circle(radius, pen=None, brush=None)

Put a circle around this node where the node is the center of the circle.

Parameters
radiusfloat

The radius of the circle to put around the node.

penwx.Pen, optional, default=None

The pen to draw the shape. If None is provided, it uses the predefined pen.

brushwx.Brush, optional, default=None

The brush to draw the shape. If None is provided, it uses the predefined brush.

Returns
Reference to the drawable instance

The instance should not be used directly in the user simulation. To remove this drawable from the drawing list, simple use this reference in del_drawable() method. If no drawable is created, None is returned.

draw_line(other_node, pen=None, brush=None)

Draw a line from this node to other_node.

This method is useful to show a connection between this node and another node. If the line already exists, nothing will happen.

Parameters
other_nodenode.node.BaseNode subclass

The node where the line to draw to from this node.

penwx.Pen, optional, default=None

The pen to draw the shape. If None is provided, it uses the predefined pen.

brushwx.Brush, optional, default=None

The brush to draw the shape. If None is provided, it uses the predefined brush.

Returns
Reference to the drawable instance

The instance should not be used directly in the user simulation. To remove this drawable from the drawing list, simple use this reference in del_drawable() method. If no drawable is created, None is returned.

draw_sector(radius, pointing_angle, width_angle, pen=None, brush=None)

Draw a sector where its center is at this node, its radius is radius its pointing angle is pointing_angle, its width (in degree) is specified in width_angle.

This method is useful to show the coverage of a beam.

Parameters
radiusfloat

The radius of the sector.

pointing_anglefloat

The pointing azimuth angle of the sector (in degrees).

width_anglefloat

The width angle of the sector (in degrees).

penwx.Pen, optional, default=None

The pen to draw the shape. If None is provided, it uses the predefined pen.

brushwx.Brush, optional, default=None

The brush to draw the shape. If None is provided, it uses the predefined brush.

Returns
Reference to the drawable instance

The instance should not be used directly in the user simulation. To remove this drawable from the drawing list, simple use this reference in del_drawable() method. If no drawable is created, None is returned.

draw_text(dx, dy, text, font, foreground=None, background=None)

Draw a text at around this node.

Use this method to show a text message that will following the node as it moves. If the text already exists, nothing will happen.

Parameters
dxint

Draw the text at this x offset.

dyint

Draw the text at this y offset.

textstr

The text message to draw.

penwx.Pen, optional, default=None

The pen to draw the shape. If None is provided, it uses the predefined pen.

brushwx.Brush, optional, default=None

The brush to draw the shape. If None is provided, it uses the predefined brush.

Returns
Reference to the drawable instance

The instance should not be used directly in the user simulation. To remove this drawable from the drawing list, simple use this reference in del_drawable() method. If no drawable is created, None is returned.

draw_line_segments(points, pen=None, brush=None)

Draw line segments around this node where (0,0) is the center of the node.

This method is useful to draw a series of connected straight lines around the node with a start point and an end point.

Parameters
pointslist of (x,y) tuple

A list of (x,y) tuples describing the lines to draw.

penwx.Pen, optional, default=None

The pen to draw the shape. If None is provided, it uses the predefined pen.

brushwx.Brush, optional, default=None

The brush to draw the shape. If None is provided, it uses the predefined brush.

Returns
Reference to the drawable instance

The instance should not be used directly in the user simulation. To remove this drawable from the drawing list, simple use this reference in del_drawable() method. If no drawable is created, None is returned.

del_circle(radius)

(Deprecated) Remove an earlier added circle for this node. If there is no such circle added to the node, nothing will happen.

Note

This method is deprecated and will be removed in the future. Please use del_drawable() instead.

Parameters
radiusfloat

The radius that the circle to be removed.

del_line(other_node)

(Deprecated) Remove an earlier added line for this node.

Note

This method is deprecated and will be removed in the future. Please use del_drawable() instead.

Parameters
other_nodenode.node.BaseNode subclass

The line that is connected to the other node. If found, this line will be removed from the drawing list.

del_sector(radius, pointing_angle, width_angle)

(Deprecated) Remove an earlier added sector drawing. If there is no such sector added to the node, nothing will happen.

Note

This method is deprecated and will be removed in the future. Please use del_drawable() instead.

Parameters
radiusfloat

The radius that the sector to be found for removal.

pointing_anglefloat

The pointing azimuth angle of the sector (in degrees) to be found for removal.

width_anglefloat

The width angle of the sector (in degrees) to be found for removal.

del_text(dx, dy, text)

(Deprecated) Remove an earlier added text message. The text message will be removed if all the provided properties match. If a match is not found, nothing will happen.

Note

This method is deprecated and will be removed in the future. Please use del_drawable() instead.

Parameters
dxint

The offset x of the text.

dyint

The offset y of the text.

textstr

The text message.