Beispiel #1
0
    def createToolHoverMoveEvent(self, tool: CreateSliceToolT,
                                 part_item: SliceNucleicAcidPartItemT,
                                 event: QGraphicsSceneHoverEvent):
        if self.grid.grid_type == GridEnum.HONEYCOMB:
            positionToLatticeCoord = HoneycombDnaPart.positionModelToLatticeCoord
        else:
            positionToLatticeCoord = SquareDnaPart.positionModelToLatticeCoord
        coordinates = positionToLatticeCoord(
            part_item.part().radius(),
            event.scenePos().x(),
            event.scenePos().y(),
            scale_factor=part_item.scale_factor)
        latticeCoordToXY = HoneycombDnaPart.latticeCoordToQtXY if self.grid.grid_type is GridEnum.HONEYCOMB \
                else SquareDnaPart.latticeCoordToQtXY
        coordinate_string = '(%s, %s)' % coordinates
        coordiate_scaled_pos = '(%s, %s)' % latticeCoordToXY(
            DEFAULT_RADIUS, coordinates[0], coordinates[1],
            part_item.scale_factor)
        coordiate_pos = '(%s, %s)' % latticeCoordToXY(
            DEFAULT_RADIUS, coordinates[0], coordinates[1])
        position_string = '(%s, %s)' % (event.scenePos().x(),
                                        event.scenePos().y())

        part_item.updateStatusBar('%s @ %s (%s) - %s' %
                                  (coordinate_string, coordiate_scaled_pos,
                                   coordiate_pos, position_string))
        part_item.createToolHoverMove(tool, event)
Beispiel #2
0
    def selectOrSnap(self,  part_item: SliceNucleicAcidPartItemT,
                            target_item: SliceVirtualHelixItem,
                            event: QGraphicsSceneMouseEvent):
        """
        Args:
            part_item:
            target_item: Description
            event: Description

        Deleted Parameters:
            snap_to_item (SliceVirtualHelixItem or GridEvent): Item to snap
                selection to
        """
        self.setPartItem(part_item)
        if (self.snap_origin_item is not None and event.modifiers() == Qt.AltModifier):
            self.doSnap(part_item, target_item)
            self.individual_pick = False
        else:  # just do a selection
            if event.modifiers() != Qt.ShiftModifier:
                self.modelClear()   # deselect if shift isn't held

            if isinstance(target_item, SliceVirtualHelixItem):
                # NOTE: individual_pick seems not needed.
                # it's supposed to allow for single item picking
                # self.individual_pick = True

                if self.snap_origin_item is not None:
                    self.snap_origin_item.setSnapOrigin(False)
                    self.snap_origin_item = None

                doc = self.manager.document
                part = part_item.part()
                doc.addVirtualHelicesToSelection(part, [target_item.idNum()])
    def selectOrSnap(self, part_item: SliceNucleicAcidPartItemT,
                     target_item: SliceVirtualHelixItem,
                     event: QGraphicsSceneMouseEvent):
        """
        Args:
            part_item:
            target_item: Description
            event: Description

        Deleted Parameters:
            snap_to_item (SliceVirtualHelixItem or GridEvent): Item to snap
                selection to
        """
        self.setPartItem(part_item)
        if (self.snap_origin_item is not None
                and event.modifiers() == Qt.AltModifier):
            self.doSnap(part_item, target_item)
            self.individual_pick = False
        else:  # just do a selection
            if event.modifiers() != Qt.ShiftModifier:
                self.modelClear()  # deselect if shift isn't held

            if isinstance(target_item, SliceVirtualHelixItem):
                # NOTE: individual_pick seems not needed.
                # it's supposed to allow for single item picking
                # self.individual_pick = True

                if self.snap_origin_item is not None:
                    self.snap_origin_item.setSnapOrigin(False)
                    self.snap_origin_item = None

                doc = self.manager.document
                part = part_item.part()
                doc.addVirtualHelicesToSelection(part, [target_item.idNum()])
Beispiel #4
0
    def createToolHoverMoveEvent(self,  tool: CreateSliceToolT,
                                        part_item: SliceNucleicAcidPartItemT,
                                        event: QGraphicsSceneHoverEvent):
        if self.grid.grid_type == GridEnum.HONEYCOMB:
            positionToLatticeCoord = HoneycombDnaPart.positionModelToLatticeCoord
        else:
            positionToLatticeCoord = SquareDnaPart.positionModelToLatticeCoord
        coordinates = positionToLatticeCoord(part_item.part().radius(),
                                             event.scenePos().x(),
                                             event.scenePos().y(),
                                             scale_factor=part_item.scale_factor)
        latticeCoordToXY = HoneycombDnaPart.latticeCoordToQtXY if self.grid.grid_type is GridEnum.HONEYCOMB \
                else SquareDnaPart.latticeCoordToQtXY
        coordinate_string = '(%s, %s)' % coordinates
        coordiate_scaled_pos = '(%s, %s)' % latticeCoordToXY(DEFAULT_RADIUS, coordinates[0], coordinates[1], part_item.scale_factor)
        coordiate_pos = '(%s, %s)' % latticeCoordToXY(DEFAULT_RADIUS, coordinates[0], coordinates[1])
        position_string = '(%s, %s)' % (event.scenePos().x(), event.scenePos().y())

        part_item.updateStatusBar('%s @ %s (%s) - %s' % (coordinate_string, coordiate_scaled_pos, coordiate_pos, position_string))
        part_item.createToolHoverMove(tool, event)
Beispiel #5
0
    def createToolMousePress(self, tool: CreateSliceToolT,
                             part_item: SliceNucleicAcidPartItemT,
                             event: QGraphicsSceneMouseEvent):
        """Called by :meth:`mousePressEvent` when clicking on the grid

        Args:
            tool: The tool that is being used
            part_item:
            event: The event that the mouse click triggered
        """
        part_item = self.grid.part_item
        tool = part_item._getActiveTool()
        if tool.FILTER_NAME not in part_item.part().document().filter_set:
            app_window = part_item.window()
            app_window.showFilterHints(True, filter_name='virtual_helix')
            return
        part = part_item.part()
        part.setSelected(True)
        alt_event = GridEvent(self, self.offset)
        part_item.setLastHoveredItem(self)
        part_item.createToolMousePress(tool, event, alt_event)
Beispiel #6
0
    def createToolMousePress(self,  tool: CreateSliceToolT,
                                    part_item: SliceNucleicAcidPartItemT,
                                    event: QGraphicsSceneMouseEvent):
        """Called by :meth:`mousePressEvent` when clicking on the grid

        Args:
            tool: The tool that is being used
            part_item:
            event: The event that the mouse click triggered
        """
        part_item = self.grid.part_item
        tool = part_item._getActiveTool()
        if tool.FILTER_NAME not in part_item.part().document().filter_set:
            app_window = part_item.window()
            app_window.showFilterHints(True, filter_name='virtual_helix')
            return
        part = part_item.part()
        part.setSelected(True)
        alt_event = GridEvent(self, self.offset)
        part_item.setLastHoveredItem(self)
        part_item.createToolMousePress(tool, event, alt_event)
    def doSnap(self, part_item: SliceNucleicAcidPartItemT,
               snap_to_item: SliceVirtualHelixItem):
        """
        Args:
            part_item:
            snap_to_item: Item to snap
                selection to
        """
        # print("snapping")
        origin = self.snap_origin_item.getCenterScenePos()

        # xy = part_item.mapFromScene(snap_to_item.scenePos())
        # xy2 = part_item.mapFromScene(self.snap_origin_item.scenePos())
        # print("snapping from:", xy2.x(), xy2.y())
        # print("snapped to:", xy.x(), xy.y())

        if isinstance(snap_to_item, SliceVirtualHelixItem):
            self.setVirtualHelixItem(snap_to_item)
            destination = self.findNearestPoint(part_item, origin)
        else:  # GridEvent
            destination = snap_to_item.pos()
            print("GridEvent", destination)

        origin = part_item.mapFromScene(origin)
        if destination is None:
            destination = origin
        if origin == destination:
            # snap clockwise
            destination = self.findNextPoint(part_item, origin)
        if origin is None or destination is None:
            print("o", origin, "d", destination)
        delta = destination - origin
        dx, dy = delta.x(), delta.y()
        group = self.group
        pos = group.pos() + delta
        self.group.setPos(pos)
        self.moveSelection(dx, dy, False, use_undostack=True)
        self.hideLineItem()
Beispiel #8
0
    def doSnap(self, part_item: SliceNucleicAcidPartItemT,
                    snap_to_item: SliceVirtualHelixItem):
        """
        Args:
            part_item:
            snap_to_item: Item to snap
                selection to
        """
        # print("snapping")
        origin = self.snap_origin_item.getCenterScenePos()

        # xy = part_item.mapFromScene(snap_to_item.scenePos())
        # xy2 = part_item.mapFromScene(self.snap_origin_item.scenePos())
        # print("snapping from:", xy2.x(), xy2.y())
        # print("snapped to:", xy.x(), xy.y())

        if isinstance(snap_to_item, SliceVirtualHelixItem):
            self.setVirtualHelixItem(snap_to_item)
            destination = self.findNearestPoint(part_item, origin)
        else:  # GridEvent
            destination = snap_to_item.pos()
            print("GridEvent", destination)

        origin = part_item.mapFromScene(origin)
        if destination is None:
            destination = origin
        if origin == destination:
            # snap clockwise
            destination = self.findNextPoint(part_item, origin)
        if origin is None or destination is None:
            print("o", origin, "d", destination)
        delta = destination - origin
        dx, dy = delta.x(), delta.y()
        group = self.group
        pos = group.pos() + delta
        self.group.setPos(pos)
        self.moveSelection(dx, dy, False, use_undostack=True)
        self.hideLineItem()
Beispiel #9
0
 def createToolHoverLeaveEvent(self, tool: CreateSliceToolT,
                               part_item: SliceNucleicAcidPartItemT,
                               event: QGraphicsSceneHoverEvent):
     part_item.createToolHoverLeave(tool, event)
Beispiel #10
0
 def selectToolHoverLeaveEvent(self, tool: SelectSliceToolT,
                               part_item: SliceNucleicAcidPartItemT,
                               event: QGraphicsSceneHoverEvent):
     part_item.selectToolHoverLeave(tool, event)
Beispiel #11
0
 def createToolHoverLeaveEvent(self, tool: CreateSliceToolT,
                                     part_item: SliceNucleicAcidPartItemT,
                                     event: QGraphicsSceneHoverEvent):
     part_item.createToolHoverLeave(tool, event)
Beispiel #12
0
 def selectToolHoverLeaveEvent(self, tool: SelectSliceToolT,
                                     part_item: SliceNucleicAcidPartItemT,
                                     event: QGraphicsSceneHoverEvent):
     part_item.selectToolHoverLeave(tool, event)