How to use the gaphas.item.NW function in gaphas

To help you get started, we’ve selected a few gaphas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / items / line.py View on Github external
def _keep_handle_in_parent_state(self, handle):
        canvas = self.canvas
        parent = canvas.get_parent(self)
        solver = canvas.solver
        if parent is None:
            return
        handle_pos = ItemProjection(handle.pos, self, self.parent)
        constraint = KeepPointWithinConstraint(parent.handles()[NW].pos, parent.handles()[SE].pos,
                                               handle_pos, lambda: parent.border_width)
        solver.add_constraint(constraint)
        self._waypoint_constraints.append(constraint)
github gaphor / gaphor / gaphor / diagram / general / simpleitem.py View on Github external
def draw(self, context):
        cr = context.cairo
        nw = self._handles[NW]
        style = self.style

        rx = self.width / 2.0
        ry = self.height / 2.0

        cr.move_to(self.width, ry)
        path_ellipse(cr, rx, ry, self.width, self.height)
        # cr.set_source_rgba(*style.fill_color)
        # cr.fill_preserve()
        cr.set_source_rgba(*style("color"))
        cr.set_line_width(style("line-width"))
        cr.stroke()
github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / utils / gap_helper.py View on Github external
:param canvas: Canvas to find relative position in
    :param item: Item to find relative position to parent
    :param handle: Handle of item to find relative position to
    :return: Relative position (x, y)
    """
    from gaphas.item import NW

    if isinstance(item, ConnectionView):
        return item.canvas.get_matrix_i2i(item, item.parent).transform_point(*handle.pos)

    parent = canvas.get_parent(item)
    if parent:
        return item.canvas.get_matrix_i2i(item, parent).transform_point(*handle.pos)
    else:
        return item.canvas.get_matrix_i2c(item).transform_point(*item.handles()[NW].pos)
github DLR-RM / RAFCON / source / rafcon / mvc / mygaphas / items / state.py View on Github external
def handle_set_rel_pos(item, handle_pos, new_pos, parent_abs_pos, old_size=None):
                projection = canvas.project(item, handle_pos)
                projection[0].value = parent_abs_pos[0] + new_pos[0]
                projection[1].value = parent_abs_pos[1] + new_pos[1]
                if isinstance(item, StateView) and old_size:
                    item.handles()[SE].pos.x = item.handles()[NW].pos.x + old_size[0]
                    item.handles()[SE].pos.y = item.handles()[NW].pos.y + old_size[1]
github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / items / state.py View on Github external
def add_keep_rect_within_constraint(canvas, parent, child):
        solver = canvas.solver

        child_nw = ItemProjection(child.handles()[NW].pos, child, parent)
        child_se = ItemProjection(child.handles()[SE].pos, child, parent)
        constraint = KeepRectangleWithinConstraint(parent.handles()[NW].pos, parent.handles()[SE].pos,
                                                   child_nw, child_se, child, lambda: parent.border_width)
        solver.add_constraint(constraint)
        parent.keep_rect_constraints[child] = constraint
github DLR-RM / RAFCON / source / awesome_tool / mvc / views / gap / scope.py View on Github external
input_handle = Handle(left_center, connectable=True, movable=False)
        self._handles.append(input_handle)
        self._input_handle = input_handle
        input_port = PointPort(input_handle.pos)
        self._input_port = input_port
        self._ports.append(input_port)
        
        output_handle = Handle(right_center, connectable=True, movable=False)
        self._handles.append(output_handle)
        self._output_handle = output_handle
        output_port = PointPort(output_handle.pos)
        self._output_port = output_port
        self._ports.append(output_port)

        self.constraint(line=(input_handle.pos, (self._handles[NW].pos, self._handles[SW].pos)), align=0.5)
        self.constraint(line=(output_handle.pos, (self._handles[NE].pos, self._handles[SE].pos)), align=0.5)
github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / tools.py View on Github external
def on_button_release(self, event):
        """Write back changes

        If one or more items have been moved, the new position are stored in the corresponding meta data and a signal
        notifying the change is emitted.

        :param event: The button event
        """
        affected_models = {}

        for inmotion in self._movable_items:
            inmotion.move((event.x, event.y))
            rel_pos = gap_helper.calc_rel_pos_to_parent(self.view.canvas, inmotion.item,
                                                        inmotion.item.handles()[NW])
            if isinstance(inmotion.item, StateView):
                state_v = inmotion.item
                state_m = state_v.model
                self.view.canvas.request_update(state_v)
                if state_m.get_meta_data_editor()['rel_pos'] != rel_pos:
                    state_m.set_meta_data_editor('rel_pos', rel_pos)
                    affected_models[state_m] = ("position", True, state_v)
            elif isinstance(inmotion.item, NameView):
                state_v = inmotion.item
                state_m = self.view.canvas.get_parent(state_v).model
                self.view.canvas.request_update(state_v)
                if state_m.get_meta_data_editor()['name']['rel_pos'] != rel_pos:
                    state_m.set_meta_data_editor('name.rel_pos', rel_pos)
                    affected_models[state_m] = ("name_position", False, state_v)
            elif isinstance(inmotion.item, TransitionView):
                transition_v = inmotion.item
github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / tools.py View on Github external
def on_button_release(self, event):
        """Write back changes

        If one or more items have been moved, the new position are stored in the corresponding meta data and a signal
        notifying the change is emitted.

        :param event: The button event
        """
        affected_models = {}

        for inmotion in self._movable_items:
            inmotion.move((event.x, event.y))
            rel_pos = gap_helper.calc_rel_pos_to_parent(self.view.canvas, inmotion.item,
                                                        inmotion.item.handles()[NW])
            if isinstance(inmotion.item, StateView):
                state_v = inmotion.item
                state_m = state_v.model
                self.view.canvas.request_update(state_v)
                if state_m.get_meta_data_editor()['rel_pos'] != rel_pos:
                    state_m.set_meta_data_editor('rel_pos', rel_pos)
                    affected_models[state_m] = ("position", True, state_v)
            elif isinstance(inmotion.item, NameView):
                state_v = inmotion.item
                state_m = self.view.canvas.get_parent(state_v).model
                self.view.canvas.request_update(state_v)
                if state_m.get_meta_data_editor()['name']['rel_pos'] != rel_pos:
                    state_m.set_meta_data_editor('name.rel_pos', rel_pos)
                    affected_models[state_m] = ("name_position", False, state_v)
            elif isinstance(inmotion.item, TransitionView):
                transition_v = inmotion.item
github gaphor / gaphor / gaphor / diagram / classes / interface.py View on Github external
self._folded = folded

        if folded == Folded.NONE:
            movable = True
        else:
            if self._folded == Folded.PROVIDED:
                icon_size = self.RADIUS_PROVIDED * 2
            else:  # required interface or assembly icon mode
                icon_size = self.RADIUS_REQUIRED * 2

            self.min_width, self.min_height = icon_size, icon_size
            self.width, self.height = icon_size, icon_size

            # update only h_se handle - rest of handles should be updated by
            # constraints
            h_nw = self._handles[NW]
            h_se = self._handles[SE]
            h_se.pos.x = h_nw.pos.x + self.min_width
            h_se.pos.y = h_nw.pos.y + self.min_height

            movable = False

        for h in self._handles:
            h.movable = movable

        self.update_shapes()
github gaphor / gaphor / gaphor / diagram / classes / interface.py View on Github external
def __init__(self, id=None):
        ClassItem.__init__(self, id)
        self._folded = self.FOLDED_NONE
        self._angle = 0
        old_f = self._name.is_visible
        self._name.is_visible = lambda: old_f() and self._folded != self.FOLDED_ASSEMBLY

        handles = self._handles
        h_nw = handles[NW]
        h_ne = handles[NE]
        h_sw = handles[SW]
        h_se = handles[SE]

        # edge of element define default element ports
        self._ports = [
            InterfacePort(h_nw.pos, h_ne.pos, self, 0),
            InterfacePort(h_ne.pos, h_se.pos, self, pi / 2),
            InterfacePort(h_se.pos, h_sw.pos, self, pi),
            InterfacePort(h_sw.pos, h_nw.pos, self, pi * 1.5)
        ]

        self.watch('subject.ownedAttribute', self.on_class_owned_attribute) \
            .watch('subject.ownedOperation', self.on_class_owned_operation) \
            .watch('subject.supplierDependency')