|
|
@ -12,7 +12,12 @@ that widget. |
|
|
|
|
|
|
|
|
|
|
|
from enum import Enum |
|
|
|
from enum import Enum |
|
|
|
|
|
|
|
|
|
|
|
from OpenGL.GL import glClearColor, glEnable, GL_LIGHT0, GL_LIGHTING |
|
|
|
from OpenGL.GL import (glBegin, glClearColor, glColor4f, glEnable, |
|
|
|
|
|
|
|
glEnd, GL_LIGHT0, GL_LIGHTING, GL_POINTS, |
|
|
|
|
|
|
|
glVertex3f) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from clusterview.exceptions import InvalidStateError |
|
|
|
|
|
|
|
from clusterview.mode import InvalidMode, Mode |
|
|
|
|
|
|
|
|
|
|
|
class Color(Enum): |
|
|
|
class Color(Enum): |
|
|
|
BLUE = 0 |
|
|
|
BLUE = 0 |
|
|
@ -22,6 +27,37 @@ COLOR_TO_RGBA = { |
|
|
|
Color.BLUE: (0, 128, 255, 255) |
|
|
|
Color.BLUE: (0, 128, 255, 255) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__current_mode = None |
|
|
|
|
|
|
|
__current_event = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_drawing_mode(mode, event=None): |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
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. |
|
|
|
|
|
|
|
@param event The current event (Mostly used for passing coordinates). |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
if not isinstance(mode, Mode): |
|
|
|
|
|
|
|
raise ValueError("Mode in set_drawing_mode must be of type Mode") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__current_mode = mode |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if event is not None: |
|
|
|
|
|
|
|
__current_event = event |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_current_mode(): |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
Returns the current mode according to the OpenGL Widget. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
return __current_mode |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def initialize_gl(): |
|
|
|
def initialize_gl(): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Initializes the OpenGL context on the Window. |
|
|
|
Initializes the OpenGL context on the Window. |
|
|
@ -35,6 +71,28 @@ def initialize_gl(): |
|
|
|
glClearColor(255, 255, 255, 0) |
|
|
|
glClearColor(255, 255, 255, 0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def paint_gl(): |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
Stock PaintGL function from OpenGL that switches |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
__current_event is None): |
|
|
|
|
|
|
|
raise InvalidStateError("Event must exist for ADD, EDIT, MOVE, " + |
|
|
|
|
|
|
|
"and DELETE") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __current_mode is Mode.ADD: |
|
|
|
|
|
|
|
raise NotImplementedError("Drawing for ADD not implemented.") |
|
|
|
|
|
|
|
elif __current_mode is Mode.EDIT: |
|
|
|
|
|
|
|
raise NotImplementedError("Drawing for EDIT not implemented.") |
|
|
|
|
|
|
|
elif __current_mode is Mode.MOVE: |
|
|
|
|
|
|
|
raise NotImplementedError("Drawing for MOVE not implemented.") |
|
|
|
|
|
|
|
elif __current_mode is Mode.DELETE: |
|
|
|
|
|
|
|
raise NotImplementedError("Drawing for DELETE not implemented.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def draw_point(x, y, color): |
|
|
|
def draw_point(x, y, color): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Simple point drawing function. |
|
|
|
Simple point drawing function. |
|
|
@ -50,3 +108,10 @@ def draw_point(x, y, color): |
|
|
|
|
|
|
|
|
|
|
|
if not isinstance(color, Color): |
|
|
|
if not isinstance(color, Color): |
|
|
|
raise ValueError("Color must exist in the Color enumeration") |
|
|
|
raise ValueError("Color must exist in the Color enumeration") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ct = COLOR_TO_RGBA[color] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glBegin(GL_POINTS) |
|
|
|
|
|
|
|
glColor4f(ct[0], ct[1], ct[2], ct[3]) |
|
|
|
|
|
|
|
glVertex3f(x, y, 0.0) # Z is currently fixed to 0 |
|
|
|
|
|
|
|
glEnd() |
|
|
|