node.type module

Module type contains all node types to specify a node. Each type of nodes has its unique properties to control the behaviour of the nodes. Specifically, it contains properties to enable drawing of the node on the screen.

All node types are defined directly in this module. They are now encapsulated in a container class. The recommended way to import the node type classes is:

## use the name `NodeType` to encapsulate all node types
import node.type as NodeType

You can also import directly from node package:

from node import NodeType  # from `node` package

The user simulation can create a new node type specific for the simulation. The new node type must extend node.type.BaseType and implement corresponding abstract methods, for example:

import node.type as NodeType

class UFO(NodeType.BaseType):

    def __init__(self, node):
        super().__init__(node)

    ## this is an abstract method needed to reimplement
    def draw(self, dc, resolution):

        ## setup parameters
        pixels_per_meter = int(max(1,resolution/1000))
        pen_size = pixels_per_meter
        circle_radius = 3*pixels_per_meter
        wing_length = 3*pixels_per_meter

        ## setup pen and brush
        dc.SetPen(wx.Pen(self.color(), pen_size))
        dc.SetBrush(wx.Brush(self.color(),wx.TRANSPARENT))

        ## build a UFO shape with two wings, i.e. "--o--"
        ## default orientation is flying north (i.e. azimuth=0)
        pt0 = self._node.get("location")
        pt1 = XY(x=0, y=-wing_length-circle_radius)
        pt2 = XY(x=0, y=-circle_radius)
        pt3 = XY(x=0, y=+circle_radius)
        pt4 = XY(x=0, y=+wing_length+circle_radius)

        ## rotate and shift the UFO to pt0 for drawing
        for xy in [pt1,pt2,pt3,pt4]:
            xy.rotate_azimuth(self._node.get("direction").get_azimuth())
            xy.shift(pt0)
        dc.DrawCircle(pt0.x,pt0.y,circle_radius)
        dc.DrawLine(pt1.x, pt1.y, pt2.x, pt2.y)
        dc.DrawLine(pt3.x, pt3.y, pt4.x, pt4.y)

Note

  • Created by: CH Foh (2021)

List of Classes

BaseType

It is the base node type, all node types must extend this base class.

Hidden

It is a hidden node which will not show itself on the scenario.

BaseStation

It is a base station type.

Vehicle

It is a vehicle type.

Drone

It is a drone type.

RIS

It is a type of Reconfigurable Intelligent Surface (RIS).


class node.type.BaseType(node)

Bases: abc.ABC

This is an abstract base class of a node type, all node type must extend from this base class to inherit common methods.

Parameters
nodenode.node.BaseNode subclass

The node that sets to this type. All subclasses must call super().__init__(node) to properly initiate this super class. All subclasses can access the node by self._node stored in the super class.

Methods

draw(dc, resolution)

This is an abstract method for the subclass to implement how the node is shown on the screen.

draw_circle(dc, resolution[, radius_in_meter])

This method provides the subclass to conveniently draw a circle on the screen.

color

__init__(node)

Initialize self. See help(type(self)) for accurate signature.

color(color=None, reset=False)
draw_circle(dc, resolution, radius_in_meter=3)

This method provides the subclass to conveniently draw a circle on the screen.

Parameters
dcwx.DC

The device context of the scenario currently showing on the screen.

resolutionfloat

The map resolution in pixels per km.

radius_in_meterfloat, optional, default = 3

The radius of the circle in meters. Default input is 3 meters.

abstract draw(dc, resolution)

This is an abstract method for the subclass to implement how the node is shown on the screen.

Parameters
dcwx.DC

The device context of the scenario currently showing on the screen.

resolutionfloat

The map resolution in pixels per km.

class node.type.Hidden(node)

Bases: node.type.BaseType

Use this subclass for any node that will not show itself on the map.

Methods

draw(dc, resolution)

This node does not draw itself on the map as it is hidden.

draw_circle(dc, resolution[, radius_in_meter])

This method provides the subclass to conveniently draw a circle on the screen.

color

__init__(node)

Initialize self. See help(type(self)) for accurate signature.

draw(dc, resolution)

This node does not draw itself on the map as it is hidden.

class node.type.BaseStation(node)

Bases: node.type.BaseType

Use this subclass for base station node. A circle is drawn for this type of node.

Parameters
nodenode.node.BaseNode subclass

The node that sets to this type.

Methods

draw(dc, resolution)

It draws a small circle.

draw_circle(dc, resolution[, radius_in_meter])

This method provides the subclass to conveniently draw a circle on the screen.

color

__init__(node)

Initialize self. See help(type(self)) for accurate signature.

draw(dc, resolution)

It draws a small circle.

class node.type.Vehicle(node, length=3.5, width=2)

Bases: node.type.BaseType

Use this subclass for vehicle node. A triangle is drawn for this type of node, and the size of the triangle is customizable during initialization.

Parameters
nodenode.node.BaseNode subclass

The node that sets to this type.

lengthfloat

The length of the vehicle in meters.

widthfloat

The width of the vehicle in meters.

Methods

draw(dc, resolution)

It draws an isosceles triangle with the tip pointing to the moving direction.

draw_circle(dc, resolution[, radius_in_meter])

This method provides the subclass to conveniently draw a circle on the screen.

color

__init__(node, length=3.5, width=2)

Initialize self. See help(type(self)) for accurate signature.

draw(dc, resolution)

It draws an isosceles triangle with the tip pointing to the moving direction.

class node.type.RIS(node, width, depth=2)

Bases: node.type.BaseType

Methods

draw(dc, resolution)

It draws a circle on the map.

draw_circle(dc, resolution[, radius_in_meter])

This method provides the subclass to conveniently draw a circle on the screen.

color

set_colors

__init__(node, width, depth=2)

Initialize self. See help(type(self)) for accurate signature.

set_colors(face, body)
draw(dc, resolution)

It draws a circle on the map.

class node.type.Drone(node, size)

Bases: node.type.BaseType

Methods

draw(dc, resolution)

It draws a shape that looks like ‘-o-‘ on the map.

draw_circle(dc, resolution[, radius_in_meter])

This method provides the subclass to conveniently draw a circle on the screen.

color

__init__(node, size)

Initialize self. See help(type(self)) for accurate signature.

draw(dc, resolution)

It draws a shape that looks like ‘-o-‘ on the map.