|
|
|
@ -53,9 +53,9 @@ __move_bb_bottom_right = None
|
|
|
|
|
# Below functions have to mark these as `global` so |
|
|
|
|
# the interpreter knows that the variables are not |
|
|
|
|
# function local. |
|
|
|
|
__current_mode = None |
|
|
|
|
__current_event = None |
|
|
|
|
__current_context = None |
|
|
|
|
__current_event = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_drawing_context(ctx): |
|
|
|
|
""" |
|
|
|
@ -66,29 +66,6 @@ def set_drawing_context(ctx):
|
|
|
|
|
|
|
|
|
|
__current_context = ctx |
|
|
|
|
|
|
|
|
|
def set_drawing_mode(mode): |
|
|
|
|
""" |
|
|
|
|
State management function. It is useful to look at the |
|
|
|
|
different drawing modes as modes in a state machine. |
|
|
|
|
|
|
|
|
|
Calling this function when a mode changes allows the |
|
|
|
|
OpenGL functions to take the correct drawing action |
|
|
|
|
on the OpenGL Widget. |
|
|
|
|
|
|
|
|
|
@param mode The current mode. |
|
|
|
|
""" |
|
|
|
|
global __current_context |
|
|
|
|
global __current_mode |
|
|
|
|
|
|
|
|
|
if __current_context is None: |
|
|
|
|
raise InvalidStateError("Drawing context must be set before setting " + |
|
|
|
|
"drawing mode") |
|
|
|
|
|
|
|
|
|
if not isinstance(mode, Mode): |
|
|
|
|
raise ValueError("Mode in set_drawing_mode must be of type Mode") |
|
|
|
|
|
|
|
|
|
__current_mode = mode |
|
|
|
|
|
|
|
|
|
def set_drawing_event(event): |
|
|
|
|
""" |
|
|
|
|
State machine event management function. |
|
|
|
@ -168,8 +145,8 @@ def resize_gl(w, h):
|
|
|
|
|
global __WIDTH |
|
|
|
|
global __HEIGHT |
|
|
|
|
|
|
|
|
|
__WIDTH = __current_context.width() |
|
|
|
|
__HEIGHT = __current_context.height() |
|
|
|
|
__WIDTH = __current_context.opengl_widget.width() |
|
|
|
|
__HEIGHT = __current_context.opengl_widget.height() |
|
|
|
|
|
|
|
|
|
def viewport_width(): |
|
|
|
|
return __WIDTH |
|
|
|
@ -184,24 +161,25 @@ def paint_gl():
|
|
|
|
|
on the current mode to determine what action to |
|
|
|
|
perform on the current event. |
|
|
|
|
""" |
|
|
|
|
if (__current_mode in [Mode.ADD, Mode.EDIT, Mode.MOVE, Mode.DELETE] and |
|
|
|
|
if (__current_context.mode in [Mode.ADD, Mode.EDIT, |
|
|
|
|
Mode.MOVE, Mode.DELETE] and |
|
|
|
|
__current_event is None): |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
if (__current_mode in [Mode.ADD, Mode.EDIT, Mode.DELETE] and |
|
|
|
|
if (__current_context.mode in [Mode.ADD, Mode.EDIT, Mode.DELETE] and |
|
|
|
|
PointManager.point_set.empty()): |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
if (__current_mode is Mode.ADD or |
|
|
|
|
__current_mode is Mode.DELETE or |
|
|
|
|
__current_mode is Mode.LOADED): |
|
|
|
|
if (__current_context.mode is Mode.ADD or |
|
|
|
|
__current_context.mode is Mode.DELETE or |
|
|
|
|
__current_context.mode is Mode.LOADED): |
|
|
|
|
|
|
|
|
|
draw_points(PointManager.point_set, Color.GREY) |
|
|
|
|
|
|
|
|
|
elif __current_mode is Mode.EDIT: |
|
|
|
|
elif __current_context.mode is Mode.EDIT: |
|
|
|
|
raise NotImplementedError("Drawing for EDIT not implemented.") |
|
|
|
|
|
|
|
|
|
elif __current_mode is Mode.MOVE: |
|
|
|
|
elif __current_context.mode is Mode.MOVE: |
|
|
|
|
# We have to repeatedly draw the points while we are showing the |
|
|
|
|
# move box. |
|
|
|
|
if not PointManager.point_set.empty(): |
|
|
|
|