From f925e59e7ffe3f2465b29ca1cc51e7abb32df83f Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Thu, 15 Aug 2019 17:32:08 -0700 Subject: [PATCH] More effective way to handle selection criteria --- clusterview/opengl_widget.py | 24 ++++++++++++++---------- clusterview/points.py | 22 ++++++++++++++-------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/clusterview/opengl_widget.py b/clusterview/opengl_widget.py index cd7f6b7..32d8377 100644 --- a/clusterview/opengl_widget.py +++ b/clusterview/opengl_widget.py @@ -230,7 +230,10 @@ def paint_gl(): if (__move_bb_top_left is not None and __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() + draw_points(__current_points, Color.GREY) 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 @@ -301,10 +304,6 @@ def highlight_selection(): top_left = get_bb_top_left() 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: if box_hit(point.x, point.y, top_left[0], top_left[1], bottom_right[0], bottom_right[1]): @@ -339,10 +338,9 @@ def highlight_selection(): # next mouse click. First mouse click will call # "remove_selection" to terminate movement. "remove_selection" # will also be called on mode change. - glVertex3f(__clamp_x(point.x), - __clamp_y(point.y), - 0.0) - glEnd() + point.select() + else: + point.unselect() def draw_selection_box(color): """ @@ -418,15 +416,21 @@ def draw_points(point_set, color): if not isinstance(color, Color): raise ValueError("Color must exist in the Color enumeration") - ct = COLOR_TO_RGBA[color] glViewport(0, 0, __WIDTH, __HEIGHT) glPointSize(__current_points.point_size) glBegin(GL_POINTS) - glColor3f(ct[0], ct[1], ct[2]) 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), __clamp_y(point.y), 0.0) # Z is currently fixed to 0 diff --git a/clusterview/points.py b/clusterview/points.py index 08b92fa..25bdb38 100644 --- a/clusterview/points.py +++ b/clusterview/points.py @@ -18,6 +18,7 @@ class Point: self.__point_size = point_size self.__x = x self.__y = y + self.__selected = False half_point = floor(point_size / 2) @@ -26,21 +27,21 @@ class Point: self.__bottom_right_corner = (self.__x + half_point, self.__y - half_point) - @property def x(self): return self.__x - @property def y(self): return self.__y - @property def point_size(self): return self.__point_size + @property + def selected(self): + return self.__selected def __eq__(self, other): """ @@ -65,7 +66,17 @@ class Point: return "POINT".format(self.__x, self.__y, 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): """ @@ -121,7 +132,6 @@ class PointSet: self.__attributes = {} self.__point_size = point_size - @property def points(self): """ @@ -131,12 +141,10 @@ class PointSet: for point in self.__points: yield point - @property def point_size(self): return self.__point_size - def add_point(self, x, y, attrs=[]): """ Adds a point in screen coordinates and an optional attribute to @@ -155,7 +163,6 @@ class PointSet: self.__points.add(point) self.__attributes[point] = attrs - def remove_point(self, x, y): """ Removes a point and it's attributes from the point set based @@ -183,7 +190,6 @@ class PointSet: for point in matched: self.__attributes.pop(point) - def attributes(self, point): """ Returns the attribute array for a given point.