Exemplo n.º 1
0
    def draw_data_flow(self, from_pos, to_pos, width, waypoints=None, selected=False, depth=0):
        """Draw a data flow connection between two ports

        The ports can be input, output or scoped ports and are only specified by their position. Optional waypoints
        allow non-direct connection.

        :param tuple from_pos: Starting position
        :param tuple to_pos: Ending position
        :param float width: A measure for the width of a transition line
        :param list waypoints: A list of optional waypoints to connect in between
        :param bool selected: Whether the transition shell be shown as active/selected
        :param in tdepth: The Z layer
        """
        if not waypoints:
            waypoints = []
        # "Generate" unique ID for each object
        id = self.name_counter
        self.name_counter += 1

        glPushName(id)
        width /= 1.3
        self._set_closest_stroke_width(width)

        color = self.data_flow_color if not selected else self.data_flow_selected_color
        color.set()

        points = [from_pos]
        points.extend(waypoints)

        last_p = to_pos  # Transition endpoint
        sec_last_p = points[len(points) - 1]  # Point before endpoint
        # Calculate max possible arrow length
        length = min(width / 1.2, dist(sec_last_p, last_p) / 2.)
        mid, p2, p3 = self._calculate_arrow_points(last_p, sec_last_p, length)
        self._draw_triangle(last_p, p2, p3, depth, fill_color=color)

        points.append(mid)

        # Draw the transitions as simple straight line connecting start- way- and endpoints
        glBegin(GL_LINE_STRIP)
        for point in points:
            glVertex3f(point[0], point[1], depth)
        glEnd()

        self._set_closest_stroke_width(width / 1.5)
        for waypoint in waypoints:
            self._draw_circle(waypoint[0], waypoint[1], width / 6., depth + 1, fill_color=color)

        glPopName()

        return id
Exemplo n.º 2
0
    def draw_transition(self, from_pos, to_pos, width, waypoints=None, selected=False, depth=0):
        """Draw a state with the given properties

        This method is called by the controller to draw the specified transition.

        :param tuple from_pos: Starting position
        :param tuple to_pos: Ending position
        :param float width: A measure for the width of a transition line
        :param list waypoints: A list of optional waypoints to connect in between
        :param bool selected: Whether the transition shell be shown as active/selected
        :param float depth: The Z layer
        :return: The OpenGL id of the transition
        :rtype: int
        """
        if not waypoints:
            waypoints = []
        # "Generate" unique ID for each object
        id = self.name_counter
        self.name_counter += 1

        glPushName(id)
        self._set_closest_stroke_width(width)

        color = self.transition_color if not selected else self.transition_selected_color
        color.set()

        points = [from_pos]
        points.extend(waypoints)

        last_p = to_pos  # Transition endpoint
        sec_last_p = points[len(points) - 1]  # Point before endpoint
        # Calculate max possible arrow length
        length = min(width, dist(sec_last_p, last_p) / 2.)
        mid, p2, p3 = self._calculate_arrow_points(last_p, sec_last_p, length)
        self._draw_triangle(last_p, p2, p3, depth, fill_color=color)

        points.append(mid)

        # Draw the transitions as simple straight line connecting start- way- and endpoints
        glBegin(GL_LINE_STRIP)
        for point in points:
            glVertex3f(point[0], point[1], depth)
        glEnd()

        self._set_closest_stroke_width(width / 1.5)
        for waypoint in waypoints:
            self._draw_circle(waypoint[0], waypoint[1], width / 6., depth + 1, fill_color=color)

        glPopName()

        return id