Ejemplo n.º 1
0
    def OnMouseWheel(self, event: wx.MouseEvent):
        if self.selection_mode:
            return

        self.camera_interactor.mouse_wheel(event.GetWheelRotation(),
                                           event.GetWheelDelta(),
                                           event.ShiftDown(), event.AltDown(),
                                           event.ControlDown())
        self._x = self._y = -1
        self.Sync()
        self.Refresh()
Ejemplo n.º 2
0
    def OnMotion(self, event: wx.MouseEvent):
        x = event.GetX()
        y = event.GetY()
        if event.LeftIsDown():

            # Normal scene movement without selection
            if not self.selection_mode and self._x > -1 and self._y > -1:
                self.camera_interactor.mouse_motion(x - self._x, y - self._y,
                                                    event.ShiftDown(),
                                                    event.AltDown(),
                                                    event.ControlDown())
            self._x = x
            self._y = y

            # Left-mouse drag selection, movement disabled
            if self.selection_mode and self.selection_mode is GLSelectionControls.BOX and \
                    not self.selection_mode_depressed:
                if self.start_x == -1 and self.start_y == -1:
                    self.start_x = self._x
                    self.start_y = self._y
                self.camera.box_select.from_screen_coords(
                    (self.start_x, self.start_y), (self._x, self._y))

            self.Sync()
            self.Refresh()

        # Scene movement with selection enabled
        elif event.RightIsDown() and self.selection_mode:
            if self._x > -1 and self._y > -1:
                self.camera_interactor.mouse_motion(x - self._x, y - self._y,
                                                    event.ShiftDown(),
                                                    event.AltDown(),
                                                    event.ControlDown())
            self._x = x
            self._y = y

        # Reset mouse coordinates
        else:
            self._x = self._y = self.start_x = self.start_y = -1
        event.Skip()
Ejemplo n.º 3
0
    def OnLeftUp(self, event: MouseEvent):
        """
        Callback for left up events.

        @param event
        """
        # manage the selector box
        if self._selector is not None:
            self.Bind(EVT_MOTION, self._NullCallback)
            rect = self._selector
            # x, y = rect.GetPosition()     Not used
            # w, h = rect.GetSize()         Not used
            for shape in self._diagram.GetShapes():
                x0, y0 = shape.GetTopLeft()
                w0, h0 = shape.GetSize()
                if shape.GetParent() is None and \
                   rect.Inside(x0, y0) and \
                   rect.Inside(x0 + w0, y0) and \
                   rect.Inside(x0, y0 + h0) and \
                   rect.Inside(x0 + w0, y0 + h0):
                    shape.SetSelected(True)
                    shape.SetMoving(True)
                    self._selectedShapes.append(shape)
            rect.Detach()
            self._selector = None
        if not self._moving and self._clickedShape:
            clicked = self._clickedShape
            if not event.ControlDown():
                self.DeselectAllShapes()
                self._selectedShapes = [clicked]
                clicked.SetSelected(True)
                clicked.SetMoving(True)
            else:
                sel = not clicked.IsSelected()
                clicked.SetSelected(sel)
                clicked.SetMoving(sel)
                if sel and clicked not in self._selectedShapes:
                    self._selectedShapes.append(clicked)
                elif not sel and clicked in self._selectedShapes:
                    self._selectedShapes.remove(clicked)
            self._clickedShape = None
            self.Refresh()

        self._moving = False

        # normal event management
        self.GenericHandler(event, "OnLeftUp")
        if not self.__keepMoving:
            self.Bind(EVT_MOTION, self._NullCallback)
            self.Refresh()
Ejemplo n.º 4
0
    def OnLeftUp(self, event: MouseEvent):
        """
        Callback for left up events.

        Args:
            event:
        """
        if self._selector is not None:
            self.Bind(EVT_MOTION, self._NullCallback)
            self.clsLogger.debug(f'{self._selector=}')
            rect = self._selector

            for shape in self._diagram.GetShapes():
                x0, y0 = shape.GetTopLeft()
                w0, h0 = shape.GetSize()

                if shape.GetParent() is None and self._isShapeInRectangle(
                        rect, x0=x0, y0=y0, w0=w0, h0=h0):
                    shape.SetSelected(True)
                    shape.SetMoving(True)
                    self._selectedShapes.append(shape)
            rect.Detach()
            self._selector = cast(RectangleShape, None)
        if not self._moving and self._clickedShape:
            self.clsLogger.debug(f'{self._moving} {self._clickedShape}')
            clicked = self._clickedShape
            if not event.ControlDown():
                self.DeselectAllShapes()
                self._selectedShapes = [clicked]
                clicked.SetSelected(True)
                clicked.SetMoving(True)
            else:
                sel = not clicked.IsSelected()
                clicked.SetSelected(sel)
                clicked.SetMoving(sel)
                if sel and clicked not in self._selectedShapes:
                    self._selectedShapes.append(clicked)
                elif not sel and clicked in self._selectedShapes:
                    self._selectedShapes.remove(clicked)
            self._clickedShape = cast(Shape, None)
            self.Refresh()

        self._moving = False

        # normal event management
        self.GenericHandler(event, "OnLeftUp")
        if not self.__keepMoving:
            self.Bind(EVT_MOTION, self._NullCallback)
            self.Refresh()
Ejemplo n.º 5
0
    def OnLeftDown(self, event: MouseEvent):
        """
        Callback for left down events on the diagram.

        Args:
            event:
        """
        self.clsLogger.debug("DiagramFrame.OnLeftDown")

        # First, call the generic handler for OnLeftDown
        shape: ShapeEventHandler = self.GenericHandler(event, "OnLeftDown")
        self._clickedShape = cast(Shape, shape)  # store the last clicked shape
        if not event.GetSkipped():
            return
        if shape is None:
            self._BeginSelect(event)
            return

        # manage click and drag
        x, y = event.GetX(), event.GetY()
        self._lastMousePosition = (x, y)

        realShape: Shape = cast(Shape, shape)
        if not event.ControlDown() and not realShape.IsSelected():
            shapes = self._diagram.GetShapes()
            shapes.remove(shape)
            if isinstance(shape, SizerShape):
                # don't deselect the parent of a sizer
                # or its sizer's would be detached
                shapes.remove(shape.GetParent())
            elif isinstance(shape, ControlPoint):
                # don't deselect the line of a control point
                self.clsLogger.debug(f'{shape=}')
                for line in shape.GetLines():
                    shapes.remove(line)
            # do not call DeselectAllShapes, because we must ensure that
            # the sizer won't be deselected (because they are detached when they are deselected)
            # deselect every other shape
            for s in shapes:
                s.SetSelected(False)
                s.SetMoving(False)

            self._selectedShapes = [cast(Shape, shape)]
            cast(Shape, shape).SetSelected(True)
            cast(Shape, shape).SetMoving(True)
            self._clickedShape = cast(Shape, None)
            self.Refresh()

        self.Bind(EVT_MOTION, self.OnMove)
Ejemplo n.º 6
0
    def _BeginSelect(self, event: MouseEvent):
        """
        Create a selector box and manage it.

        @param  event
        """
        if not event.ControlDown():
            self.DeselectAllShapes()
        x, y = event.GetX(), event.GetY()  # event position has been modified
        self._selector = rect = RectangleShape(x, y, 0, 0)
        rect.SetDrawFrame(True)
        rect.SetBrush(TRANSPARENT_BRUSH)
        rect.SetMoving(True)
        self._diagram.AddShape(rect)
        self.PrepareBackground()
        self.Bind(EVT_MOTION, self._OnMoveSelector)