|
|
|
@ -18,6 +18,7 @@ from OpenGL.GL import (glBegin, glClearColor, glColor4f, glEnable,
|
|
|
|
|
|
|
|
|
|
from .exceptions import InvalidModeError, InvalidStateError |
|
|
|
|
from .mode import Mode |
|
|
|
|
from .points import PointSet |
|
|
|
|
|
|
|
|
|
class Color(Enum): |
|
|
|
|
BLUE = 0 |
|
|
|
@ -45,6 +46,7 @@ __HEIGHT = None
|
|
|
|
|
# function local. |
|
|
|
|
__current_mode = None |
|
|
|
|
__current_event = None |
|
|
|
|
__current_points = None |
|
|
|
|
__current_context = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -57,6 +59,25 @@ def set_drawing_context(ctx):
|
|
|
|
|
|
|
|
|
|
__current_context = ctx |
|
|
|
|
|
|
|
|
|
def set_current_points(points): |
|
|
|
|
""" |
|
|
|
|
Sets the point state variable that will be passed in to the paint_gl |
|
|
|
|
function, and further to the point painter functions in order to |
|
|
|
|
render the scene. |
|
|
|
|
|
|
|
|
|
Each time a point is added, removed, or edited this point set must be |
|
|
|
|
updated. |
|
|
|
|
|
|
|
|
|
@param points The PointSet representing the current scene. |
|
|
|
|
""" |
|
|
|
|
global __current_points |
|
|
|
|
|
|
|
|
|
if not isinstance(points, PointSet): |
|
|
|
|
raise ValueError("set_current_points must recieve a PointSet as its " + |
|
|
|
|
"argument.") |
|
|
|
|
|
|
|
|
|
__current_points = points |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_drawing_mode(mode): |
|
|
|
|
""" |
|
|
|
@ -137,11 +158,13 @@ def paint_gl():
|
|
|
|
|
raise InvalidStateError("Event must exist for ADD, EDIT, MOVE, " + |
|
|
|
|
"and DELETE") |
|
|
|
|
|
|
|
|
|
if (__current_mode in [Mode.ADD, Mode.EDIT, Mode.MOVE, Mode.DELETE] and |
|
|
|
|
__current_points is None): |
|
|
|
|
raise InvalidStateError("Points must exist for ADD, EDIT, MOVE, " + |
|
|
|
|
"and DELETE") |
|
|
|
|
|
|
|
|
|
if __current_mode is Mode.ADD: |
|
|
|
|
# TODO: This needs to be modified to instead take the point list |
|
|
|
|
# and redraw the entire list (which will have the new point |
|
|
|
|
# added) each click. |
|
|
|
|
draw_points(__current_event.x(), __current_event.y(), Color.BLUE) |
|
|
|
|
draw_points(__current_points, Color.BLUE) |
|
|
|
|
elif __current_mode is Mode.EDIT: |
|
|
|
|
raise NotImplementedError("Drawing for EDIT not implemented.") |
|
|
|
|
elif __current_mode is Mode.MOVE: |
|
|
|
@ -174,7 +197,7 @@ def __clamp_y(y):
|
|
|
|
|
return y_w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def draw_points(x, y, color): |
|
|
|
|
def draw_points(point_set, color): |
|
|
|
|
""" |
|
|
|
|
Simple point drawing function. |
|
|
|
|
|
|
|
|
@ -182,8 +205,7 @@ def draw_points(x, y, color):
|
|
|
|
|
function will draw the given point with the given |
|
|
|
|
color. |
|
|
|
|
|
|
|
|
|
@param x The x-coordinate. |
|
|
|
|
@param y The y-coordinate. |
|
|
|
|
@param point_set The PointSet to draw. |
|
|
|
|
@param color The Color Enum. |
|
|
|
|
""" |
|
|
|
|
global __current_context |
|
|
|
@ -202,8 +224,9 @@ def draw_points(x, y, color):
|
|
|
|
|
glColor4f(ct[0], ct[1], ct[2], ct[3]) |
|
|
|
|
|
|
|
|
|
glBegin(GL_POINTS) |
|
|
|
|
glVertex3f(__clamp_x(__current_event.x()), |
|
|
|
|
__clamp_y(__current_event.y()), |
|
|
|
|
for point in point_set.points: |
|
|
|
|
glVertex3f(__clamp_x(point[0]), |
|
|
|
|
__clamp_y(point[1]), |
|
|
|
|
0.0) # Z is currently fixed to 0 |
|
|
|
|
glEnd() |
|
|
|
|
|
|
|
|
|