shapes module

synopsis:Module contains classes that represent shapes available in the application, ie. rectangles, cylinders, cylinder sectors, and polygons; it also contains the TCoordSys class, representing model coordinate system box. All classes contained in this module are descendants of an abstarct class TShape.
class shapes.TCoordSys(colour='black', width=1, minx=0, miny=0, maxx=620, maxy=620, margx=20, margy=20, model_min_x=0.0, model_min_y=0.0, model_max_x=10.0, model_max_y=10.0, ticintmetx=1.0, ticintmety=1.0, ticlenx=5, ticleny=5, grid=False, grid_colour='grey', round_digits=2)

Bases: shapes.TRect

Class represents the coordinates system.

Parameters:
  • colour (string) – coordinate system box outline colour.
  • width (integer) – coordinate system box outline width.
  • minx (integer) – minimal x coordinate of coordinate system box in pixels.
  • miny (integer) – minimal y coordinate of coordinate system box in pixels.
  • maxx (integer) – maxmial x coordinate of coordinate system box in pixels.
  • maxy (integer) – maximal y coordinate of coordinate system box in pixels.
  • margx (integer) – coordinate system box margin in x direction.
  • margy (integer) – coordinate system box margin in y direction.
  • model_min_x (float) – minimal visible x coordinate in metres.
  • model_min_y (float) – minimal visible y coordinate in metres.
  • model_max_x (float) – maximal visible x coordinate in metres.
  • model_max_y (float) – maximal visible y coordinate in metres.
  • ticintmetx (float) – tick interval in x direction in metres.
  • ticintmety (float) – tick interval in y direction in metres.
  • ticlenx (integer) – x-ticks length in pixels.
  • ticleny (integer) – x-ticks length in pixels.
  • grid (boolean) – grid diplay toggle.
  • grid_colour (string) – grid lines colour.
  • round_digits (integer) – tick labels precision.
display_settings_update()

Update display settings.

draw(canvas)

Draw the coordinate system box on a canvas.

Parameters:canvas (tkinter.Canvas) – canvas on which to draw the coordinate system box.
draw_grid(canvas)

Draw coordinate system grid on a canvas.

Parameters:canvas (tkinter.Canvas) – canvas on which to draw the grid.
draw_ticks(canvas, grid=False)

Draw the axis ticks on a canvas.

Parameters:
  • canvas (tkinter.Canvas) – canvas on which to draw the ticks.
  • grid (boolean) – grid diplay toggle.
label_round(label, digits)

Round axis labels.

Parameters:
  • label (float) – label too be rounded.
  • digits (integer) – rounding precision.
model_size_update()

Update model size.

obscure_protruding_edges(canvas)

Obscure edges protruding from model area with background-coloured rectangles.

Parameters:canvas (tkinter.Canvas) – canvas on which to perform the obscuring.
toggle_grid(state)

Toggle displaying of the coordinate system grid.

Parameters:state (boolean) – new grid state.
window_size_update()

Update window size.

write_axis_labels(canvas)

Write axis labels on a canvas.

Parameters:canvas (tkinter.Canvas) – canvas on which to draw the grid.
class shapes.TCylin(centre=None, radius=None, centre_x=None, centre_y=None, colour='black', fill='', width=1, material='pec', centre_mod=None, radius_mod=None)

Bases: shapes.TShape

Class represents a cylinder.

Parameters:
  • centre (TPoint) – cylinder centre in pixels.
  • radius (float) – cylinder radius in pixels.
  • centre_x (integer) – cylinder centre x coordinate in pixels.
  • centre_y (integer) – cylinder centre y coordinate in pixels.
  • colour (string) – shape outline colour.
  • fill (string) – shape fill colour.
  • width (integer) – shape outline width in pixels.
  • material (string) – shape material.
  • centre_mod (TPoint) – cylinder centre in metres.
  • radius_mod (float) – cylinder radius in metres.
area()

Calculate cylinder area.

Return type:float
draw(canvas)

Draw the cylinder on a canvas.

Parameters:canvas (tkinter.Canvas) – canvas on which to draw the cylinder.
draw_to_image(image, colour)

Draw the cylinder to a png image file.

Parameters:
  • image (PIL.Image) – png image.
  • colour (tuple) – shape colour.
update_model_positions()

Recalculate model positions of the cylinder from its window positions.

update_window_positions()

Recalculate window positions of the cylinder from its model positions.

visible(min_model, max_model)

Determine whether the cylinder lies within the visible model area.

Parameters:
  • min_model (TPoint) – lower left visible model corner.
  • max_model (TPoint) – upper right visible model corner.
Return type:

boolean

class shapes.TCylinSector(centre=None, radius=None, centre_x=None, centre_y=None, colour='black', fill='', width=1, boundary_pt1=None, boundary_pt2=None, start=None, extent=None, material='pec', centre_mod=None, radius_mod=None)

Bases: shapes.TShape

Class represents a cylinder sector.

Parameters:
  • centre (TPoint) – cylinder centre in pixels.
  • radius (float) – cylinder radius in pixels.
  • centre_x (integer) – cylinder centre x coordinate in pixels.
  • centre_y (integer) – cylinder centre y coordinate in pixels.
  • colour (string) – shape outline colour.
  • fill (string) – shape fill colour.
  • width (integer) – shape outline width in pixels.
  • boundary_pt1 (TPoint) – sector first boundary point.
  • boundary_pt2 (TPoint) – sector first boundary point.
  • start (float) – angle between positive x direction and first sector radius.
  • extent (float) – angle between first and second sector radius.
  • material (string) – shape material.
  • centre_mod (TPoint) – cylinder centre in metres.
  • radius_mod (float) – cylinder radius in metres.
area()

Calculate cylinder sector area.

Return type:float
draw(canvas)

Draw the cylinder sector on a canvas.

Parameters:canvas (tkinter.Canvas) – canvas on which to draw the cylinder sector.
draw_to_image(image, colour)

Draw the cylinder sector to a png image file.

Parameters:
  • image (PIL.Image) – png image.
  • colour (tuple) – shape colour.
update_model_positions()

Recalculate model positions of the cylinder sector from its window positions.

update_window_positions()

Recalculate window positions of the cylinder sector from its model positions.

visible(min_model, max_model)

Determine whether the cylinder sector lies within the visible model area.

Parameters:
  • min_model (TPoint) – lower left visible model corner.
  • max_model (TPoint) – upper right visible model corner.
Return type:

boolean

class shapes.TPolygon(points=[], colour='black', fill='', width=1, material='pec', points_mod=[])

Bases: shapes.TShape

Class represents a polygon.

Parameters:
  • points (list of TPoint) – list of polygon vertices in window coordinates system.
  • colour (string) – shape outline colour.
  • fill (string) – shape fill colour.
  • width (integer) – shape outline width in pixels.
  • material (string) – shape material.
  • points_mod (list of TPoint) – list of polygon vertices in model coordinates system.
add_vertex(**kwargs)

Add a vertex to the polygon.

Parameters:
  • x (integer) – vertex x coordinate in pixels.
  • y (integer) – vertex y coordinate in pixels.
  • x_mod (float) – vertex x coordinate in metres.
  • y_mod (float) – vertex y coordinate in metres.
area()

Calculate cylinder sector area.

Return type:float
draw(canvas)

Draw the polygon on a canvas.

Parameters:canvas (tkinter.Canvas) – canvas on which to draw the polygon.
draw_to_image(image, colour)

Draw the polygon to a png image file.

Parameters:
  • image (PIL.Image) – png image.
  • colour (tuple) – shape colour.
edit_vertex(*, vertex_num, x, y)

Edit seleted vertex coordimates.

Parameters:
  • vertex_num (integer) – list index of a vertex to be modified.
  • x (float) – new vertex x coordinate.
  • y (float) – new vertex y coordinate.
remove_vertex(vertex_num)

Remove a vertex from the polygon.

Parameters:vertex_num (integer) – index of a vertex to be removed.
unwrap_points()

Unwrap list of points into a list of alternating x and y coordinates.

update_model_positions()

Recalculate model positions of the polygon from its window positions.

update_window_positions()

Recalculate window positions of the polygon from its model positions.

visible(min_model, max_model)

Determine whether the polygon lies within the visible model area.

Parameters:
  • min_model (TPoint) – lower left visible model corner.
  • max_model (TPoint) – upper right visible model corner.
Return type:

boolean

class shapes.TRect(point1=None, point2=None, point1_x=None, point1_y=None, point2_x=None, point2_y=None, colour='black', fill='', width=1, material='pec', point1_mod=None, point2_mod=None)

Bases: shapes.TShape

Class represents a rectangle.

Parameters:
  • point1 (TPoint) – lower left rectangle point in pixels.
  • point2 (TPoint) – upper right rectangle point in pixels.
  • point1_x (integer) – lower left rectangle point x coordinate in pixels.
  • point1_y (integer) – lower left rectangle point y coordinate in pixels.
  • point2_x (integer) – upper right rectangle point x coordinate in pixels.
  • point2_y (integer) – upper right rectangle point y coordinate in pixels.
  • colour (string) – shape outline colour.
  • fill (string.) – shape fill colour.
  • width (integer) – shape outline width in pixels.
  • material (string) – shape material.
  • point1_mod (TPoint) – lower left rectangle point in metres.
  • point2_mod (TPoint) – upper right rectangle point in metres.
area()

Calculate rectangle area.

Return type:float
draw(canvas)

Draw the rectangle on a canvas.

Parameters:canvas (tkinter.Canvas) – canvas on which to draw the rectangle.
draw_to_image(image, colour)

Draw the rectangle to a png image file.

Parameters:
  • image (PIL.Image) – png image.
  • colour (tuple) – shape colour.
update_model_positions()

Recalculate model positions of the rectangle from its window positions.

update_window_positions()

Recalculate window positions of the rectangle from its model positions.

visible(min_model, max_model)

Determine whether the rectangle lies within the visible model area.

Parameters:
  • min_model (TPoint) – lower left visible model corner.
  • max_model (TPoint) – upper right visible model corner.
Return type:

boolean

class shapes.TShape(width=None, colour=None, fill='', material='pec', shape_type='None')

Bases: abc.ABC

An abstract base class for shapes (i.e. rectangles, cylinders, cylinder sectors, and polygons).

Parameters:
  • width (integer) – shape outline width in pixels.
  • colour (string) – shape outline colour.
  • fill (string) – shape fill colour.
  • material (string) – shape material.
  • shape_type (string) – shape type (ie. rectangle, cylinder etc.).
area()

Calculate shape area.

Return type:float
draw()

Draw a shape.

draw_to_image(image, colour)

Draw the shape to a png image file.

Parameters:
  • image (PIL.Image) – png image.
  • colour (tuple) – shape colour.
update_model_positions()

Recalculate model positions of the shape from its window positions.

update_window_positions()

Recalculate window positions of the shape from its model positions.

visible(min_model, max_model)

Determine whether the shape lies within the visible model area.

Parameters:
  • min_model (TPoint) – lower left visible model corner.
  • max_model (TPoint) – upper right visible model corner.
Return type:

boolean