Browse Source

More effective way to handle selection criteria

tb-init-ui-render
Taylor Bockman 5 years ago
parent
commit
f925e59e7f
  1. 24
      clusterview/opengl_widget.py
  2. 22
      clusterview/points.py

24
clusterview/opengl_widget.py

@ -230,7 +230,10 @@ def paint_gl():
if (__move_bb_top_left is not None and if (__move_bb_top_left is not None and
__move_bb_bottom_right is not None): __move_bb_bottom_right is not None):
# Mark points that are selected in the bounding box
# and draw them using the normal function
highlight_selection() highlight_selection()
draw_points(__current_points, Color.GREY)
if __move_bb_top_left is None and __move_bb_bottom_right is None: if __move_bb_top_left is None and __move_bb_bottom_right is None:
# Currently this fires all the time - not great. Needs to only fire # Currently this fires all the time - not great. Needs to only fire
@ -301,10 +304,6 @@ 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()
ct = COLOR_TO_RGBA[Color.BLUE]
glBegin(GL_POINTS)
glColor3f(ct[0], ct[1], ct[2])
for point in __current_points.points: for point in __current_points.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]):
@ -339,10 +338,9 @@ def highlight_selection():
# next mouse click. First mouse click will call # next mouse click. First mouse click will call
# "remove_selection" to terminate movement. "remove_selection" # "remove_selection" to terminate movement. "remove_selection"
# will also be called on mode change. # will also be called on mode change.
glVertex3f(__clamp_x(point.x), point.select()
__clamp_y(point.y), else:
0.0) point.unselect()
glEnd()
def draw_selection_box(color): def draw_selection_box(color):
""" """
@ -418,15 +416,21 @@ def draw_points(point_set, 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]
glViewport(0, 0, __WIDTH, __HEIGHT) glViewport(0, 0, __WIDTH, __HEIGHT)
glPointSize(__current_points.point_size) glPointSize(__current_points.point_size)
glBegin(GL_POINTS) glBegin(GL_POINTS)
glColor3f(ct[0], ct[1], ct[2])
for point in point_set.points: for point in point_set.points:
if point.selected:
blue = COLOR_TO_RGBA[Color.BLUE]
glColor3f(blue[0], blue[1], blue[2])
else:
ct = COLOR_TO_RGBA[color]
glColor3f(ct[0], ct[1], ct[2])
glVertex3f(__clamp_x(point.x), glVertex3f(__clamp_x(point.x),
__clamp_y(point.y), __clamp_y(point.y),
0.0) # Z is currently fixed to 0 0.0) # Z is currently fixed to 0

22
clusterview/points.py

@ -18,6 +18,7 @@ class Point:
self.__point_size = point_size self.__point_size = point_size
self.__x = x self.__x = x
self.__y = y self.__y = y
self.__selected = False
half_point = floor(point_size / 2) half_point = floor(point_size / 2)
@ -26,21 +27,21 @@ class Point:
self.__bottom_right_corner = (self.__x + half_point, self.__bottom_right_corner = (self.__x + half_point,
self.__y - half_point) self.__y - half_point)
@property @property
def x(self): def x(self):
return self.__x return self.__x
@property @property
def y(self): def y(self):
return self.__y return self.__y
@property @property
def point_size(self): def point_size(self):
return self.__point_size return self.__point_size
@property
def selected(self):
return self.__selected
def __eq__(self, other): def __eq__(self, other):
""" """
@ -65,7 +66,17 @@ class Point:
return "POINT<X :{} Y: {} SIZE: {}>".format(self.__x, return "POINT<X :{} Y: {} SIZE: {}>".format(self.__x,
self.__y, self.__y,
self.__point_size) self.__point_size)
def select(self):
"""
Selects the point.
"""
self.__selected = True
def unselect(self):
"""
Unselects the point.
"""
self.__selected = False
def hit(self, x, y): def hit(self, x, y):
""" """
@ -121,7 +132,6 @@ class PointSet:
self.__attributes = {} self.__attributes = {}
self.__point_size = point_size self.__point_size = point_size
@property @property
def points(self): def points(self):
""" """
@ -131,12 +141,10 @@ class PointSet:
for point in self.__points: for point in self.__points:
yield point yield point
@property @property
def point_size(self): def point_size(self):
return self.__point_size return self.__point_size
def add_point(self, x, y, attrs=[]): def add_point(self, x, y, attrs=[]):
""" """
Adds a point in screen coordinates and an optional attribute to Adds a point in screen coordinates and an optional attribute to
@ -155,7 +163,6 @@ class PointSet:
self.__points.add(point) self.__points.add(point)
self.__attributes[point] = attrs self.__attributes[point] = attrs
def remove_point(self, x, y): def remove_point(self, x, y):
""" """
Removes a point and it's attributes from the point set based Removes a point and it's attributes from the point set based
@ -183,7 +190,6 @@ class PointSet:
for point in matched: for point in matched:
self.__attributes.pop(point) self.__attributes.pop(point)
def attributes(self, point): def attributes(self, point):
""" """
Returns the attribute array for a given point. Returns the attribute array for a given point.

Loading…
Cancel
Save