diff options
-rw-r--r-- | grc/src/grc/gui/elements/Connection.py | 59 | ||||
-rw-r--r-- | grc/src/grc/gui/elements/FlowGraph.py | 12 | ||||
-rw-r--r-- | grc/src/grc/gui/elements/Utils.py | 27 | ||||
-rw-r--r-- | grc/src/grc_gnuradio/utils/extract_docs.py | 2 |
4 files changed, 44 insertions, 56 deletions
diff --git a/grc/src/grc/gui/elements/Connection.py b/grc/src/grc/gui/elements/Connection.py index 70bc1132d..2d99518a8 100644 --- a/grc/src/grc/gui/elements/Connection.py +++ b/grc/src/grc/gui/elements/Connection.py @@ -49,72 +49,38 @@ class Connection(Element): self._source_rot = None self._sink_coor = None self._source_coor = None - - sink = self.get_sink() - source = self.get_source() - #get the source coordinate - x1, y1 = 0, 0 - connector_length = source.get_connector_length() - if source.get_rotation() == 0: - x1 = 0 + connector_length - elif source.get_rotation() == 90: - y1 = 0 - connector_length - elif source.get_rotation() == 180: - x1 = 0 - connector_length - elif source.get_rotation() == 270: - y1 = 0 + connector_length - self.x1, self.y1 = x1, y1 - + connector_length = self.get_source().get_connector_length() + self.x1, self.y1 = Utils.get_rotated_coordinate((connector_length, 0), self.get_source().get_rotation()) #get the sink coordinate - x2, y2 = 0, 0 - connector_length = sink.get_connector_length() + CONNECTOR_ARROW_HEIGHT - if sink.get_rotation() == 0: - x2 = 0 - connector_length - elif sink.get_rotation() == 90: - y2 = 0 + connector_length - elif sink.get_rotation() == 180: - x2 = 0 + connector_length - elif sink.get_rotation() == 270: - y2 = 0 - connector_length - self.x2, self.y2 = x2, y2 - + connector_length = self.get_sink().get_connector_length() + CONNECTOR_ARROW_HEIGHT + self.x2, self.y2 = Utils.get_rotated_coordinate((-connector_length, 0), self.get_sink().get_rotation()) #build the arrow - if sink.get_rotation() == 0: - self.arrow = [(0, 0), (0-CONNECTOR_ARROW_HEIGHT, 0-CONNECTOR_ARROW_BASE/2), (0-CONNECTOR_ARROW_HEIGHT, 0+CONNECTOR_ARROW_BASE/2)] - elif sink.get_rotation() == 90: - self.arrow = [(0, 0), (0-CONNECTOR_ARROW_BASE/2, 0+CONNECTOR_ARROW_HEIGHT), (0+CONNECTOR_ARROW_BASE/2, 0+CONNECTOR_ARROW_HEIGHT)] - elif sink.get_rotation() == 180: - self.arrow = [(0, 0), (0+CONNECTOR_ARROW_HEIGHT, 0-CONNECTOR_ARROW_BASE/2), (0+CONNECTOR_ARROW_HEIGHT, 0+CONNECTOR_ARROW_BASE/2)] - elif sink.get_rotation() == 270: - self.arrow = [(0, 0), (0-CONNECTOR_ARROW_BASE/2, 0-CONNECTOR_ARROW_HEIGHT), (0+CONNECTOR_ARROW_BASE/2, 0-CONNECTOR_ARROW_HEIGHT)] - + self.arrow = [(0, 0), + Utils.get_rotated_coordinate((-CONNECTOR_ARROW_HEIGHT, -CONNECTOR_ARROW_BASE/2), self.get_sink().get_rotation()), + Utils.get_rotated_coordinate((-CONNECTOR_ARROW_HEIGHT, CONNECTOR_ARROW_BASE/2), self.get_sink().get_rotation()), + ] self._update_after_move() def _update_after_move(self): """Calculate coordinates.""" - self.clear() - #source connector source = self.get_source() X, Y = source.get_connector_coordinate() x1, y1 = self.x1 + X, self.y1 + Y self.add_line((x1, y1), (X, Y)) - #sink connector sink = self.get_sink() X, Y = sink.get_connector_coordinate() x2, y2 = self.x2 + X, self.y2 + Y self.add_line((x2, y2), (X, Y)) - #adjust arrow self._arrow = [(x+X, y+Y) for x,y in self.arrow] - #add the horizontal and vertical lines in this connection if abs(source.get_connector_direction() - sink.get_connector_direction()) == 180: #2 possible point sets to create a 3-line connector - mid_x, mid_y = (x1 + x2)/2, (y1 + y2)/2 + mid_x, mid_y = (x1 + x2)/2.0, (y1 + y2)/2.0 points = [((mid_x, y1), (mid_x, y2)), ((x1, mid_y), (x2, mid_y))] #source connector -> points[0][0] should be in the direction of source (if possible) if Utils.get_angle_from_coordinates((x1, y1), points[0][0]) != source.get_connector_direction(): points.reverse() @@ -123,9 +89,10 @@ class Connection(Element): #points[0][0] -> source connector should not be in the direction of source if Utils.get_angle_from_coordinates(points[0][0], (x1, y1)) == source.get_connector_direction(): points.reverse() #create 3-line connector - self.add_line((x1, y1), points[0][0]) - self.add_line(points[0][0], points[0][1]) - self.add_line((x2, y2), points[0][1]) + p1, p2 = map(int, points[0][0]), map(int, points[0][1]) + self.add_line((x1, y1), p1) + self.add_line(p1, p2) + self.add_line((x2, y2), p2) else: #2 possible points to create a right-angled connector points = [(x1, y2), (x2, y1)] diff --git a/grc/src/grc/gui/elements/FlowGraph.py b/grc/src/grc/gui/elements/FlowGraph.py index 956615bd2..b4d835277 100644 --- a/grc/src/grc/gui/elements/FlowGraph.py +++ b/grc/src/grc/gui/elements/FlowGraph.py @@ -24,6 +24,7 @@ from grc import Utils from grc.Constants import * from grc.Actions import * import Colors +import Utils from grc.gui.ParamsDialog import ParamsDialog from Element import Element from grc.elements import FlowGraph as _FlowGraph @@ -266,15 +267,13 @@ class FlowGraph(Element): """ if not self.get_selected_blocks(): return False #determine the number of degrees to rotate - direction = {DIR_LEFT: 90, DIR_RIGHT:270}[direction] - cos_r = {0: 1, 90: 0, 180: -1, 270: 0}[direction] - sin_r = {0: 0, 90: 1, 180: 0, 270: -1}[direction] + rotation = {DIR_LEFT: 90, DIR_RIGHT:270}[direction] #initialize min and max coordinates min_x, min_y = self.get_selected_block().get_coordinate() max_x, max_y = self.get_selected_block().get_coordinate() #rotate each selected block, and find min/max coordinate for selected_block in self.get_selected_blocks(): - selected_block.rotate(direction) + selected_block.rotate(rotation) #update the min/max coordinate x, y = selected_block.get_coordinate() min_x, min_y = min(min_x, x), min(min_y, y) @@ -284,9 +283,8 @@ class FlowGraph(Element): #rotate the blocks around the center point for selected_block in self.get_selected_blocks(): x, y = selected_block.get_coordinate() - x, y = x - ctr_x, y - ctr_y - x, y = (x*cos_r + y*sin_r + ctr_x, -x*sin_r + y*cos_r + ctr_y) - selected_block.set_coordinate((x, y)) + x, y = Utils.get_rotated_coordinate((x - ctr_x, y - ctr_y), rotation) + selected_block.set_coordinate((x + ctr_x, y + ctr_y)) return True def remove_selected(self): diff --git a/grc/src/grc/gui/elements/Utils.py b/grc/src/grc/gui/elements/Utils.py index 49af965e5..602a7c546 100644 --- a/grc/src/grc/gui/elements/Utils.py +++ b/grc/src/grc/gui/elements/Utils.py @@ -19,6 +19,28 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA ##@package grc.gui.elements.Utils #Shared functions for flow graph elements. +from grc.Constants import POSSIBLE_ROTATIONS + +def get_rotated_coordinate(coor, rotation): + """! + Rotate the coordinate by the given rotation. + @param coor the coordinate x, y tuple + @param rotation the angle in degrees + @return the rotated coordinates + """ + #handles negative angles + rotation = (rotation + 360)%360 + assert rotation in POSSIBLE_ROTATIONS + #determine the number of degrees to rotate + cos_r, sin_r = { + 0: (1, 0), + 90: (0, 1), + 180: (-1, 0), + 270: (0, -1), + }[rotation] + x, y = coor + return (x*cos_r + y*sin_r, -x*sin_r + y*cos_r) + def get_angle_from_coordinates((x1,y1), (x2,y2)): """! Given two points, calculate the vector direction from point1 to point2, directions are multiples of 90 degrees. @@ -26,9 +48,9 @@ def get_angle_from_coordinates((x1,y1), (x2,y2)): @param (x2,y2) the coordinate of point 2 @return the direction in degrees """ - if y1 == y2:#0 or 180 + if y1 == y2:#0 or 180 if x2 > x1: return 0 - else: return 180 + else: return 180 else:#90 or 270 if y2 > y1: return 270 else: return 90 @@ -36,6 +58,7 @@ def get_angle_from_coordinates((x1,y1), (x2,y2)): def xml_encode(string): """ Encode a string into an xml safe string by replacing special characters. + Needed for gtk pango markup in labels. @param string the input string @return output string with safe characters """ diff --git a/grc/src/grc_gnuradio/utils/extract_docs.py b/grc/src/grc_gnuradio/utils/extract_docs.py index c9c872ef5..55c7b7834 100644 --- a/grc/src/grc_gnuradio/utils/extract_docs.py +++ b/grc/src/grc_gnuradio/utils/extract_docs.py @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA ##@package grc_gnuradio.utils.extract_docs #Extract documentation from the gnuradio doxygen files. -from grc_gnuradio.Constants import * +from grc_gnuradio.Constants import DOCS_DIR from lxml import etree import os |