|
|
@ -21,7 +21,7 @@ from OpenGL.GL import (glBegin, glClearColor, glColor3f, glEnable, |
|
|
|
|
|
|
|
|
|
|
|
from .exceptions import handle_exceptions, InvalidModeError, InvalidStateError |
|
|
|
from .exceptions import handle_exceptions, InvalidModeError, InvalidStateError |
|
|
|
from .mode import Mode |
|
|
|
from .mode import Mode |
|
|
|
from .points import PointSet |
|
|
|
from .point_manager import PointManager |
|
|
|
|
|
|
|
|
|
|
|
class Color(Enum): |
|
|
|
class Color(Enum): |
|
|
|
BLUE = 0 |
|
|
|
BLUE = 0 |
|
|
@ -55,10 +55,8 @@ __move_bb_bottom_right = None |
|
|
|
# function local. |
|
|
|
# function local. |
|
|
|
__current_mode = None |
|
|
|
__current_mode = None |
|
|
|
__current_event = None |
|
|
|
__current_event = None |
|
|
|
__current_points = None |
|
|
|
|
|
|
|
__current_context = None |
|
|
|
__current_context = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_drawing_context(ctx): |
|
|
|
def set_drawing_context(ctx): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Sets the drawing context so that drawing functions can properly |
|
|
|
Sets the drawing context so that drawing functions can properly |
|
|
@ -68,26 +66,6 @@ def set_drawing_context(ctx): |
|
|
|
|
|
|
|
|
|
|
|
__current_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): |
|
|
|
def set_drawing_mode(mode): |
|
|
|
""" |
|
|
|
""" |
|
|
|
State management function. It is useful to look at the |
|
|
|
State management function. It is useful to look at the |
|
|
@ -128,7 +106,6 @@ def set_drawing_event(event): |
|
|
|
if event is not None: |
|
|
|
if event is not None: |
|
|
|
__current_event = event |
|
|
|
__current_event = event |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_move_bb_top_left(x, y): |
|
|
|
def set_move_bb_top_left(x, y): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Called to set the move bounding box's top left corner. |
|
|
|
Called to set the move bounding box's top left corner. |
|
|
@ -140,7 +117,6 @@ def set_move_bb_top_left(x, y): |
|
|
|
|
|
|
|
|
|
|
|
__move_bb_top_left = (x, y) |
|
|
|
__move_bb_top_left = (x, y) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_move_bb_bottom_right(x, y): |
|
|
|
def set_move_bb_bottom_right(x, y): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Called to set the move bounding box's bottom right corner. |
|
|
|
Called to set the move bounding box's bottom right corner. |
|
|
@ -152,15 +128,12 @@ def set_move_bb_bottom_right(x, y): |
|
|
|
|
|
|
|
|
|
|
|
__move_bb_bottom_right = (x, y) |
|
|
|
__move_bb_bottom_right = (x, y) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_bb_top_left(): |
|
|
|
def get_bb_top_left(): |
|
|
|
return __move_bb_top_left |
|
|
|
return __move_bb_top_left |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_bb_bottom_right(): |
|
|
|
def get_bb_bottom_right(): |
|
|
|
return __move_bb_bottom_right |
|
|
|
return __move_bb_bottom_right |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reset_move_bbs(): |
|
|
|
def reset_move_bbs(): |
|
|
|
global __move_bb_top_left |
|
|
|
global __move_bb_top_left |
|
|
|
global __move_bb_bottom_right |
|
|
|
global __move_bb_bottom_right |
|
|
@ -185,7 +158,6 @@ def resize_gl(w, h): |
|
|
|
""" |
|
|
|
""" |
|
|
|
global __WIDTH |
|
|
|
global __WIDTH |
|
|
|
global __HEIGHT |
|
|
|
global __HEIGHT |
|
|
|
global __current_points |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__WIDTH = __current_context.width() |
|
|
|
__WIDTH = __current_context.width() |
|
|
|
__HEIGHT = __current_context.height() |
|
|
|
__HEIGHT = __current_context.height() |
|
|
@ -208,7 +180,7 @@ def paint_gl(): |
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
if (__current_mode in [Mode.ADD, Mode.EDIT, Mode.DELETE] and |
|
|
|
if (__current_mode in [Mode.ADD, Mode.EDIT, Mode.DELETE] and |
|
|
|
__current_points is None): |
|
|
|
PointManager.point_set.empty()): |
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
if __current_mode is Mode.ADD or __current_mode is Mode.DELETE: |
|
|
|
if __current_mode is Mode.ADD or __current_mode is Mode.DELETE: |
|
|
@ -217,7 +189,7 @@ def paint_gl(): |
|
|
|
# the point set, which will be redrawn here. This action |
|
|
|
# the point set, which will be redrawn here. This action |
|
|
|
# is the same as adding a point since we just draw what is in |
|
|
|
# is the same as adding a point since we just draw what is in |
|
|
|
# the point set. |
|
|
|
# the point set. |
|
|
|
draw_points(__current_points, Color.GREY) |
|
|
|
draw_points(PointManager.point_set, Color.GREY) |
|
|
|
|
|
|
|
|
|
|
|
elif __current_mode is Mode.EDIT: |
|
|
|
elif __current_mode is Mode.EDIT: |
|
|
|
raise NotImplementedError("Drawing for EDIT not implemented.") |
|
|
|
raise NotImplementedError("Drawing for EDIT not implemented.") |
|
|
@ -225,8 +197,8 @@ def paint_gl(): |
|
|
|
elif __current_mode is Mode.MOVE: |
|
|
|
elif __current_mode is Mode.MOVE: |
|
|
|
# We have to repeatedly draw the points while we are showing the |
|
|
|
# We have to repeatedly draw the points while we are showing the |
|
|
|
# move box. |
|
|
|
# move box. |
|
|
|
if __current_points is not None: |
|
|
|
if not PointManager.point_set.empty(): |
|
|
|
draw_points(__current_points, Color.GREY) |
|
|
|
draw_points(PointManager.point_set, Color.GREY) |
|
|
|
|
|
|
|
|
|
|
|
draw_selection_box(Color.BLACK) |
|
|
|
draw_selection_box(Color.BLACK) |
|
|
|
|
|
|
|
|
|
|
@ -236,8 +208,7 @@ def paint_gl(): |
|
|
|
# Mark points that are selected in the bounding box |
|
|
|
# Mark points that are selected in the bounding box |
|
|
|
# and draw them using the normal function |
|
|
|
# and draw them using the normal function |
|
|
|
highlight_selection() |
|
|
|
highlight_selection() |
|
|
|
draw_points(__current_points, Color.GREY) |
|
|
|
draw_points(PointManager.point_set, Color.GREY) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __clamp_x(x): |
|
|
|
def __clamp_x(x): |
|
|
|
""" |
|
|
|
""" |
|
|
@ -296,7 +267,7 @@ def highlight_selection(): |
|
|
|
top_left = get_bb_top_left() |
|
|
|
top_left = get_bb_top_left() |
|
|
|
bottom_right = get_bb_bottom_right() |
|
|
|
bottom_right = get_bb_bottom_right() |
|
|
|
|
|
|
|
|
|
|
|
for point in __current_points.points: |
|
|
|
for point in PointManager.point_set.points: |
|
|
|
if box_hit(point.x, point.y, top_left[0], top_left[1], |
|
|
|
if box_hit(point.x, point.y, top_left[0], top_left[1], |
|
|
|
bottom_right[0], bottom_right[1]): |
|
|
|
bottom_right[0], bottom_right[1]): |
|
|
|
|
|
|
|
|
|
|
@ -358,7 +329,6 @@ def draw_selection_box(color): |
|
|
|
|
|
|
|
|
|
|
|
glEnd() |
|
|
|
glEnd() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clear_selection(): |
|
|
|
def clear_selection(): |
|
|
|
""" |
|
|
|
""" |
|
|
|
A helper designed to be called from the main window |
|
|
|
A helper designed to be called from the main window |
|
|
@ -366,10 +336,8 @@ def clear_selection(): |
|
|
|
and mode files. This way you dont have to do something |
|
|
|
and mode files. This way you dont have to do something |
|
|
|
before the selection clears. |
|
|
|
before the selection clears. |
|
|
|
""" |
|
|
|
""" |
|
|
|
global __current_points |
|
|
|
if not PointManager.point_set.empty(): |
|
|
|
|
|
|
|
PointManager.point_set.clear_selection() |
|
|
|
if __current_points is not None: |
|
|
|
|
|
|
|
__current_points.clear_selection() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def draw_points(point_set, color): |
|
|
|
def draw_points(point_set, color): |
|
|
|
""" |
|
|
|
""" |
|
|
@ -393,8 +361,7 @@ def draw_points(point_set, color): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glViewport(0, 0, __WIDTH, __HEIGHT) |
|
|
|
glViewport(0, 0, __WIDTH, __HEIGHT) |
|
|
|
glPointSize(__current_points.point_size) |
|
|
|
glPointSize(PointManager.point_set.point_size) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glBegin(GL_POINTS) |
|
|
|
glBegin(GL_POINTS) |
|
|
|
for point in point_set.points: |
|
|
|
for point in point_set.points: |
|
|
|