Ejemplo n.º 1
0
    def partPropertyChangedSlot(self, model_part, property_key, new_value):
        """Summary

        Args:
            model_part (Part): The model part
            property_key (TYPE): Description
            new_value (TYPE): Description

        Args:
            TYPE: Description
        """
        if self._model_part == model_part:
            self._model_props[property_key] = new_value
            if property_key == 'color':
                self.outline.setPen(getPenObj(new_value, _DEFAULT_WIDTH))
                for vhi in self._virtual_helix_item_hash.values():
                    vhi.updateAppearance()
                self.resize_handle_group.setPens(getPenObj(new_value, 0))
            elif property_key == 'is_visible':
                if new_value:
                    self.show()
                else:
                    self.hide()
            elif property_key == 'grid_type':
                self.griditem.setGridType(new_value)
Ejemplo n.º 2
0
    def updateAppearance(self):
        """Check item's current visibility, color and active state, and sets
        pen, brush, text according to style defaults.
        """
        is_visible, color = self._model_part.getVirtualHelixProperties(self._id_num, ['is_visible', 'color'])
        if is_visible:
            self.show()
        else:
            self.hide()
            return

        pwidth = styles.GRID_HELIX_STROKE_WIDTH if self.old_pen is None else SNAP_WIDTH

        if self.is_active:
            self._USE_PEN = getPenObj(styles.ACTIVE_STROKE, pwidth)
        else:
            self._USE_PEN = getPenObj(color, pwidth)

        self._TEXT_BRUSH = getBrushObj(styles.GRID_TEXT_COLOR)

        self._BRUSH = _BRUSH_DEFAULT
        self._USE_BRUSH = getBrushObj(color, alpha=150)

        self._label.setBrush(self._TEXT_BRUSH)
        self.setBrush(self._BRUSH)
        self.setPen(self._USE_PEN)
        self.setRect(_RECT)
Ejemplo n.º 3
0
    def resetItem(self, from_virtual_helix_item, is_fwd, from_index,
                  to_vh_id_num, prexoveritemgroup, color):
        """Summary

        Args:
            from_virtual_helix_item (cadnano.gui.views.pathview.virtualhelixitem.VirtualHelixItem): Description
            is_fwd (TYPE): Description
            from_index (TYPE): Description
            to_vh_id_num (TYPE): Description
            prexoveritemgroup (TYPE): Description
            color (TYPE): Description

        Returns:
            TYPE: Description
        """
        self.setParentItem(from_virtual_helix_item)
        self.resetTransform()
        self._id_num = from_virtual_helix_item.idNum()
        self.idx = from_index
        self.is_fwd = is_fwd
        self.to_vh_id_num = to_vh_id_num
        self._color = color
        self.prexoveritemgroup = prexoveritemgroup
        self._bond_item.hide()
        self._label_txt = lbt = None if to_vh_id_num is None else str(
            to_vh_id_num)
        self.setLabel(text=lbt)
        self._label.resetItem(is_fwd, color)

        phos = self._phos_item
        bonditem = self._bond_item

        if is_fwd:
            phos.setPath(FWDPHOS_PP)
            phos.setTransformOriginPoint(0, phos.boundingRect().center().y())
            phos.setPos(0.5 * BASE_WIDTH, BASE_WIDTH)
            phos.setPen(getNoPen())
            phos.setBrush(getBrushObj(color))
            bonditem.setPen(getPenObj(color, styles.PREXOVER_STROKE_WIDTH))
            self.setPos(from_index * BASE_WIDTH, -BASE_WIDTH)
        else:
            phos.setPath(REVPHOS_PP)
            phos.setTransformOriginPoint(0, phos.boundingRect().center().y())
            phos.setPos(0.5 * BASE_WIDTH, 0)
            phos.setPen(getPenObj(color, 0.25))
            phos.setBrush(getNoBrush())
            bonditem.setPen(
                getPenObj(color,
                          styles.PREXOVER_STROKE_WIDTH,
                          penstyle=Qt.DotLine,
                          capstyle=Qt.RoundCap))
            self.setPos(from_index * BASE_WIDTH, 2 * BASE_WIDTH)

        if to_vh_id_num is not None:
            inactive_alpha = PROX_ALPHA
            self.setBrush(getBrushObj(color, alpha=inactive_alpha))
        else:
            self.setBrush(getBrushObj(color, alpha=0))
        self.show()
Ejemplo n.º 4
0
    def resetItem(self, from_virtual_helix_item, is_fwd, from_index,
                  to_vh_id_num, prexoveritemgroup, color):
        """Summary

        Args:
            from_virtual_helix_item (cadnano.gui.views.pathview.virtualhelixitem.VirtualHelixItem): Description
            is_fwd (TYPE): Description
            from_index (TYPE): Description
            to_vh_id_num (TYPE): Description
            prexoveritemgroup (TYPE): Description
            color (TYPE): Description

        Returns:
            TYPE: Description
        """
        self.setParentItem(from_virtual_helix_item)
        self.resetTransform()
        self._id_num = from_virtual_helix_item.idNum()
        self.idx = from_index
        self.is_fwd = is_fwd
        self.to_vh_id_num = to_vh_id_num
        self._color = color
        self.prexoveritemgroup = prexoveritemgroup
        self._bond_item.hide()
        self._label_txt = lbt = None if to_vh_id_num is None else str(to_vh_id_num)
        self.setLabel(text=lbt)
        self._label.resetItem(is_fwd, color)

        phos = self._phos_item
        bonditem = self._bond_item

        if is_fwd:
            phos.setPath(FWDPHOS_PP)
            phos.setTransformOriginPoint(0, phos.boundingRect().center().y())
            phos.setPos(0.5*BASE_WIDTH, BASE_WIDTH)
            phos.setPen(getNoPen())
            phos.setBrush(getBrushObj(color))
            bonditem.setPen(getPenObj(color, styles.PREXOVER_STROKE_WIDTH))
            self.setPos(from_index*BASE_WIDTH, -BASE_WIDTH)
        else:
            phos.setPath(REVPHOS_PP)
            phos.setTransformOriginPoint(0, phos.boundingRect().center().y())
            phos.setPos(0.5*BASE_WIDTH, 0)
            phos.setPen(getPenObj(color, 0.25))
            phos.setBrush(getNoBrush())
            bonditem.setPen(getPenObj(color, styles.PREXOVER_STROKE_WIDTH,
                                      penstyle=Qt.DotLine, capstyle=Qt.RoundCap))
            self.setPos(from_index*BASE_WIDTH, 2*BASE_WIDTH)

        if to_vh_id_num is not None:
            inactive_alpha = PROX_ALPHA
            self.setBrush(getBrushObj(color, alpha=inactive_alpha))
        else:
            self.setBrush(getBrushObj(color, alpha=0))
        self.show()
Ejemplo n.º 5
0
    def __init__(self, handle_type, width, color, handle_group, parent):
        ''' parent is a :class:`QGraphicsItem` such as a :class:`NucleicAcidPartItem`
        '''
        super(HandleItem, self).__init__(parent)
        self.setAcceptHoverEvents(True)
        self._handle_type = handle_type
        self._group = handle_group
        self.width = w = width
        self.half_width = w/2
        self.align_offset = parent._BOUNDING_RECT_PADDING
        self.model_bounds = ()
        self.can_move_x = handle_group.translates_in & AxisEnum.X
        self.can_move_y = handle_group.translates_in & AxisEnum.Y

        self.setBrush(getBrushObj(styles.RESIZEHANDLE_FILL_COLOR))
        self.setPen(getPenObj(color, 0))
        self.setRect(QRectF(0, 0, w, w))

        self.label = HandleItemLabel(self)

        self.event_start_position = QPointF(0, 0)
        self.event_scene_start_position = QPointF(0, 0)

        if handle_type & (HandleEnum.LEFT | HandleEnum.RIGHT):
            self._resize_cursor = Qt.SizeHorCursor
        elif handle_type & (HandleEnum.TOP | HandleEnum.BOTTOM):
            self._resize_cursor = Qt.SizeVerCursor
        elif handle_type & (HandleEnum.TOP_LEFT | HandleEnum.BOTTOM_RIGHT):
            self._resize_cursor = Qt.SizeFDiagCursor
        elif handle_type & (HandleEnum.TOP_RIGHT | HandleEnum.BOTTOM_LEFT):
            self._resize_cursor = Qt.SizeBDiagCursor
        else:
            self._resize_cursor = Qt.ClosedHandCursor
Ejemplo n.º 6
0
 def hoverLeaveEvent(self, event: QGraphicsSceneHoverEvent):
     """
     Args:
         event: Description
     """
     self.setBrush(getBrushObj(styles.DEFAULT_GRID_DOT_COLOR))
     self.setPen(getPenObj(styles.DEFAULT_GRID_DOT_COLOR, 1.0))
Ejemplo n.º 7
0
 def __init__(self, is_fwd, pre_xover_item):
     """
     Args:
         is_fwd (bool): True if forward strand base, False if reverse.
         pre_xover_item (TYPE): Description
     """
     super(Triangle, self).__init__(pre_xover_item)
     color = pre_xover_item.color
     self.adapter = PropertyWrapperObject(self)
     self.setAcceptHoverEvents(True)
     self.setFiltersChildEvents(True)
     self._click_area = click_area = QGraphicsRectItem(PXI_RECT, self)
     click_area.setAcceptHoverEvents(True)
     click_area.setPen(getNoPen())
     click_area.hoverMoveEvent = self.hoverMoveEvent
     if is_fwd:
         # grad = QLinearGradient(0., 0., 0., 1.)
         # grad.setColorAt(0, getColorObj(color))
         # grad.setColorAt(1, Qt.black)
         # self.setBrush(grad)
         self.setBrush(getBrushObj(color, alpha=128))
         self.setPath(FWDPXI_PP)
         self.setPen(getNoPen())
         self._click_area.setPos(-0.5*IW, -0.75*IW)
     else:
         self.setPath(REVPXI_PP)
         self.setPen(getPenObj(color, 0.25, alpha=128))
         # grad = QLinearGradient(0., 0., 0., -1.)
         # grad.setColorAt(1, getColorObj(color))
         # grad.setColorAt(0, Qt.black)
         # self.setPen(getNoPen())
         # self.setBrush(grad)
         self._click_area.setPos(-0.5*IW, -0.25*IW)
Ejemplo n.º 8
0
 def hoverLeaveEvent(self, event: QGraphicsSceneHoverEvent):
     """
     Args:
         event: Description
     """
     self.setBrush(getBrushObj(styles.DEFAULT_GRID_DOT_COLOR))
     self.setPen(getPenObj(styles.DEFAULT_GRID_DOT_COLOR, 1.0))
Ejemplo n.º 9
0
    def partPropertyChangedSlot(self, model_part, property_key, new_value):
        """Summary

        Args:
            model_part (Part): The model part
            property_key (TYPE): Description
            new_value (TYPE): Description

        Returns:
            TYPE: Description
        """
        if self._model_part == model_part:
            self._model_props[property_key] = new_value
            if property_key == 'color':
                for vhi in self._virtual_helix_item_list:
                    vhi.handle().refreshColor()
                # self.grab_corner.setPen(getPenObj(new_value, 0))
                self.workplane.outline.setPen(getPenObj(new_value, 0))
                TLx, TLy, BRx, BRy = self._getVHRectasPoints()
                self.reconfigureRect((TLx, TLy), (BRx, BRy))
            elif property_key == 'is_visible':
                if new_value:
                    self.show()
                else:
                    self.hide()
            elif property_key == 'virtual_helix_order':
                vhi_dict = self._virtual_helix_item_hash
                new_list = [vhi_dict[id_num] for id_num in new_value]
                ztf = False
                self._setVirtualHelixItemList(new_list, zoom_to_fit=ztf)
            elif property_key == 'workplane_idxs':
                if hasattr(self, 'workplane'):
                    self.workplane.setIdxs(new_idxs=new_value)
Ejemplo n.º 10
0
    def __init__(self, rect, parent=None):
        super(QGraphicsEllipseItem, self).__init__(rect, parent)
        self._parent = parent
        self.setPen(getNoPen())

        iw = _ITEM_WIDTH = 3
        x = _RECT.width() - 2*rect_gain - 2*styles.SLICE_HELIX_STROKE_WIDTH - 1
        y = _RECT.center().y()
        prexo_items = {}
        fwd_angles = [0, 240, 120]
        fwd_colors = ['#cc0000', '#00cc00', '#0000cc']
        for i in range(len(fwd_angles)):
            item = QGraphicsEllipseItem(x, y, iw, iw, self)
            item.setPen(getNoPen())
            item.setBrush(getBrushObj(fwd_colors[i]))
            item.setTransformOriginPoint(_RECT.center())
            item.setRotation(fwd_angles[i])
            prexo_items[i] = item

        rev_angles = [150, 30, 270]
        rev_colors = ['#800000cc', '#80cc0000', '#8000cc00']
        # rev_colors = ['#ff00ff', '#3399ff', '#ff6600']
        for i in range(len(fwd_angles)):
            item = QGraphicsEllipseItem(x, y, iw, iw, self)
            item.setPen(getPenObj(rev_colors[i],0.5))
            item.setBrush(getNoBrush())
            item.setTransformOriginPoint(_RECT.center())
            item.setRotation(rev_angles[i])
            prexo_items[i] = item
    def __init__(self, part_instance: ObjectInstance, viewroot: GridRootItemT):
        """Summary

        Args:
            part_instance: ``ObjectInstance`` of the ``Part``
            viewroot: ``GridRootItem``
            parent: Default is ``None``
        """
        super(GridNucleicAcidPartItem, self).__init__(part_instance, viewroot)

        self._getActiveTool = viewroot.manager.activeToolGetter
        m_p = self._model_part
        self._controller = NucleicAcidPartItemController(self, m_p)
        self.scale_factor: float = self._RADIUS / m_p.radius()
        self.active_virtual_helix_item: GridVirtualHelixItem = None
        self.prexover_manager = PreXoverManager(self)
        self.hide()  # hide while until after attemptResize() to avoid flicker

        # set this to a token value
        self._rect: QRectF = QRectF(0., 0., 1000., 1000.)
        self.boundRectToModel()
        self.setPen(getNoPen())
        self.setRect(self._rect)

        self.setAcceptHoverEvents(True)

        # Cache of VHs that were active as of last call to activeGridChanged
        # If None, all grids will be redrawn and the cache will be filled.
        # Connect destructor. This is for removing a part from scenes.

        # initialize the NucleicAcidPartItem with an empty set of old coords
        self.setZValue(styles.ZPARTITEM)
        outline = QGraphicsRectItem(self)
        self.outline: QGraphicsRectItem = outline
        o_rect = self._configureOutline(outline)
        outline.setFlag(QGraphicsItem.ItemStacksBehindParent)
        outline.setZValue(styles.ZDESELECTOR)
        model_color = m_p.getColor()
        outline.setPen(getPenObj(model_color, _DEFAULT_WIDTH))

        GC_SIZE = 10
        self.grab_cornerTL: GrabCornerItem = GrabCornerItem(
            GC_SIZE, model_color, True, self)
        self.grab_cornerTL.setTopLeft(o_rect.topLeft())
        self.grab_cornerBR: GrabCornerItem = GrabCornerItem(
            GC_SIZE, model_color, True, self)
        self.grab_cornerBR.setBottomRight(o_rect.bottomRight())
        self.griditem: GridItem = GridItem(self,
                                           self._model_props['grid_type'])
        self.griditem.setZValue(1)
        self.grab_cornerTL.setZValue(2)
        self.grab_cornerBR.setZValue(2)

        # select upon creation
        for part in m_p.document().children():
            if part is m_p:
                part.setSelected(True)
            else:
                part.setSelected(False)
        self.show()
Ejemplo n.º 12
0
    def __init__(self,  part_item: SliceNucleicAcidPartItemT,
                        grid_type: EnumType):
        """previous_grid_bounds (tuple):  a tuple corresponding to the bounds of
        the grid.

        Args:
            part_item: Description
            grid_type: Description
        """
        super(GridItem, self).__init__(parent=part_item)
        self.setFlag(QGraphicsItem.ItemClipsChildrenToShape)

        self._path = None
        self.part_item = part_item
        self._path = QGraphicsPathItem(self)

        self.dots = (styles.DOT_SIZE, styles.DOT_SIZE / 2)
        # self.allow_snap = part_item.window().action_vhelix_snap.isChecked()
        self._draw_gridpoint_coordinates = False
        self.draw_lines = False
        self.points = []
        self.points_dict = dict()
        self.previous_grid_bounds = None
        self.bounds = None
        self.grid_type = None

        self.setPen(getPenObj(styles.GRAY_STROKE, styles.EMPTY_HELIX_STROKE_WIDTH))

        self.setGridType(grid_type)
        self.previous_grid_type = grid_type
Ejemplo n.º 13
0
    def __init__(self, part_item, grid_type):
        """Summary

        previous_grid_bounds (tuple):  a tuple corresponding to the bounds of
        the grid.

        Args:
            part_item (TYPE): Description
            grid_type (TYPE): Description
        """
        super(GridItem, self).__init__(parent=part_item)
        self.setFlag(QGraphicsItem.ItemClipsChildrenToShape)

        self._path = None
        self.part_item = part_item
        self._path = QGraphicsPathItem(self)

        self.dots = (styles.DOT_SIZE, styles.DOT_SIZE / 2)
        # self.allow_snap = part_item.window().action_vhelix_snap.isChecked()
        self._draw_gridpoint_coordinates = False
        self.draw_lines = False
        self.points = []
        self.points_dict = dict()
        self.previous_grid_bounds = None
        self.bounds = None
        self.grid_type = None

        self.setPen(
            getPenObj(styles.GRAY_STROKE, styles.EMPTY_HELIX_STROKE_WIDTH))

        self.setGridType(grid_type)
        self.previous_grid_type = grid_type
Ejemplo n.º 14
0
    def doHoneycomb(self, part_item, radius, bounds):
        """Summary

        Args:
            part_item (TYPE): Description
            radius (TYPE): Description
            bounds (TYPE): Description

        Returns:
            TYPE: Description
        """
        doLattice = HoneycombDnaPart.latticeCoordToPositionXY
        doPosition = HoneycombDnaPart.positionToLatticeCoordRound
        isEven = HoneycombDnaPart.isEvenParity
        x_l, x_h, y_l, y_h = bounds
        dot_size, half_dot_size = self.dots
        sf = part_item.scale_factor
        points = self.points
        row_l, col_l = doPosition(radius, x_l, -y_l, False, False, scale_factor=sf)
        row_h, col_h = doPosition(radius, x_h, -y_h, True, True, scale_factor=sf)
        # print(row_l, row_h, col_l, col_h)

        path = QPainterPath()
        is_pen_down = False
        draw_lines = self.draw_lines
        for i in range(row_l, row_h):
            for j in range(col_l, col_h+1):
                x, y = doLattice(radius, i, j, scale_factor=sf)
                if draw_lines:
                    if is_pen_down:
                        path.lineTo(x, -y)
                    else:
                        is_pen_down = True
                        path.moveTo(x, -y)
                """ +x is Left and +y is down
                origin of ellipse is Top Left corner so we subtract half in X
                and subtract in y
                """
                pt = GridPoint(x - half_dot_size,
                               -y - half_dot_size,
                               dot_size, self)
                pt.setPen(getPenObj(Qt.blue, 1.0))
                points.append(pt)
            is_pen_down = False
        # end for i
        # DO VERTICAL LINES
        if draw_lines:
            for j in range(col_l, col_h+1):
                # print("newcol")
                for i in range(row_l, row_h):
                    x, y = doLattice(radius, i, j, scale_factor=sf)
                    if is_pen_down and isEven(i, j):
                        path.lineTo(x, -y)
                        is_pen_down = False
                    else:
                        is_pen_down = True
                        path.moveTo(x, -y)
                is_pen_down = False
            # end for j
        self.setPath(path)
Ejemplo n.º 15
0
    def __init__(self, handle_type, width, color, handle_group, parent):
        ''' parent is a :class:`QGraphicsItem` such as a :class:`NucleicAcidPartItem`
        '''
        super(HandleItem, self).__init__(parent)
        self.setAcceptHoverEvents(True)
        self._handle_type = handle_type
        self._group = handle_group
        self.width = w = width
        self.half_width = w / 2
        self.align_offset = parent._BOUNDING_RECT_PADDING
        self.model_bounds = ()
        self.can_move_x = handle_group.translates_in & AxisEnum.X
        self.can_move_y = handle_group.translates_in & AxisEnum.Y

        self.setBrush(getBrushObj(styles.RESIZEHANDLE_FILL_COLOR))
        self.setPen(getPenObj(color, 0))
        self.setRect(QRectF(0, 0, w, w))

        self.label = HandleItemLabel(self)

        self.event_start_position = QPointF(0, 0)
        self.event_scene_start_position = QPointF(0, 0)

        if handle_type & (HandleEnum.LEFT | HandleEnum.RIGHT):
            self._resize_cursor = Qt.SizeHorCursor
        elif handle_type & (HandleEnum.TOP | HandleEnum.BOTTOM):
            self._resize_cursor = Qt.SizeVerCursor
        elif handle_type & (HandleEnum.TOP_LEFT | HandleEnum.BOTTOM_RIGHT):
            self._resize_cursor = Qt.SizeFDiagCursor
        elif handle_type & (HandleEnum.TOP_RIGHT | HandleEnum.BOTTOM_LEFT):
            self._resize_cursor = Qt.SizeBDiagCursor
        else:
            self._resize_cursor = Qt.ClosedHandCursor
Ejemplo n.º 16
0
 def __init__(self, is_fwd, pre_xover_item):
     """
     Args:
         is_fwd (bool): True if forward strand base, False if reverse.
         pre_xover_item (TYPE): Description
     """
     super(Triangle, self).__init__(pre_xover_item)
     color = pre_xover_item.color
     self.adapter = PropertyWrapperObject(self)
     self.setAcceptHoverEvents(True)
     self.setFiltersChildEvents(True)
     self._click_area = click_area = QGraphicsRectItem(PXI_RECT, self)
     click_area.setAcceptHoverEvents(True)
     click_area.setPen(getNoPen())
     click_area.hoverMoveEvent = self.hoverMoveEvent
     if is_fwd:
         # grad = QLinearGradient(0., 0., 0., 1.)
         # grad.setColorAt(0, getColorObj(color))
         # grad.setColorAt(1, Qt.black)
         # self.setBrush(grad)
         self.setBrush(getBrushObj(color, alpha=128))
         self.setPath(FWDPXI_PP)
         self.setPen(getNoPen())
         self._click_area.setPos(-0.5 * IW, -0.75 * IW)
     else:
         self.setPath(REVPXI_PP)
         self.setPen(getPenObj(color, 0.25, alpha=128))
         # grad = QLinearGradient(0., 0., 0., -1.)
         # grad.setColorAt(1, getColorObj(color))
         # grad.setColorAt(0, Qt.black)
         # self.setPen(getNoPen())
         # self.setBrush(grad)
         self._click_area.setPos(-0.5 * IW, -0.25 * IW)
 def resetPen(self, color: str, width: int = 0):
     """
     Args:
         color: color string
         width: Default is 0
     """
     pen = getPenObj(color, width)
     self.outline.setPen(pen)
Ejemplo n.º 18
0
    def __init__(self, is_fwd, parent=None):
        """Summary

        Args:
            is_fwd (TYPE): Description
            parent (None, optional): Description
        """
        super(PhosBond, self).__init__(parent)
        self.adapter = PropertyWrapperObject(self)
        color = parent.color
        if is_fwd:  # lighter solid
            self.setPen(getPenObj(color, 0.25, alpha=42, capstyle=Qt.RoundCap))
        else:  # darker, dotted
            self.setPen(getPenObj(color, 0.25,
                                  alpha=64,
                                  penstyle=Qt.DotLine,
                                  capstyle=Qt.RoundCap))
Ejemplo n.º 19
0
    def __init__(self, is_fwd, parent=None):
        """Summary

        Args:
            is_fwd (TYPE): Description
            parent (None, optional): Description
        """
        super(PhosBond, self).__init__(parent)
        self.adapter = PropertyWrapperObject(self)
        color = parent.color
        if is_fwd:  # lighter solid
            self.setPen(getPenObj(color, 0.25, alpha=42, capstyle=Qt.RoundCap))
        else:  # darker, dotted
            self.setPen(getPenObj(color, 0.25,
                                  alpha=64,
                                  penstyle=Qt.DotLine,
                                  capstyle=Qt.RoundCap))
Ejemplo n.º 20
0
 def refreshColor(self):
     """
     """
     part_color = self._model_part.getProperty('color')
     self._USE_PEN = getPenObj(part_color, styles.VIRTUALHELIXHANDLEITEM_STROKE_WIDTH)
     self._USE_BRUSH = getBrushObj(styles.DEFAULT_BRUSH_COLOR)
     self.setPen(self._USE_PEN)
     self.setBrush(self._USE_BRUSH)
     self.update(self.boundingRect())
Ejemplo n.º 21
0
    def resetItem(self, from_virtual_helix_item: PathVirtualHelixItemT,
                  is_fwd: bool, from_index: int, nearby_idxs: List[int],
                  to_vh_id_num: int, prexoveritem_manager: PreXoverManagerT):
        """Update this pooled PreXoverItem with current info.
        Called by PreXoverManager.

        Args:
            from_virtual_helix_item: the associated vh_item
            is_fwd: True if associated with fwd strand, False if rev strand
            from_index: idx of associated vh
            nearby_idxs:
            to_vh_id_num: id_num of the other vh
            prexoveritem_manager: the manager
        """
        # to_vh_item = from_virtual_helix_item.partItem().idToVirtualHelixItem(to_vh_id_num)
        self.setParentItem(from_virtual_helix_item)
        # self.setParentItem(to_vh_item)
        self.resetTransform()
        self._id_num = from_virtual_helix_item.idNum()
        self._model_part = from_virtual_helix_item.part()
        self.idx = from_index
        self.is_low = False
        self.is_high = False
        self.nearby_idxs = nearby_idxs
        self.is_fwd = is_fwd
        self.color = None
        self.is3p = None
        self.enter_pos = None
        self.exit_pos = None
        self.to_vh_id_num = to_vh_id_num
        self._label_txt = None
        self.prexoveritem_manager = prexoveritem_manager

        # todo: check here if xover present and disable
        result = self.setPathAppearance(from_virtual_helix_item)

        if result:
            self.setBrush(getNoBrush())
            if is_fwd:
                self.setPos(from_index * BASE_WIDTH,
                            -BASE_WIDTH - 0.1 * BASE_WIDTH)
            else:
                self.setPos(from_index * BASE_WIDTH, 2 * BASE_WIDTH)
            self.show()
            # label
            self._label_txt = lbt = None if to_vh_id_num is None else str(
                to_vh_id_num)
            self._label.resetItem(is_fwd, self.color)
            self.setLabel(text=lbt)

            # bond line
            bonditem = self._bond_item
            bonditem.setPen(
                getPenObj(self.color,
                          styles.PREXOVER_STROKE_WIDTH,
                          penstyle=Qt.DotLine))
            bonditem.hide()
Ejemplo n.º 22
0
    def resetItem(self, from_virtual_helix_item: PathVirtualHelixItemT,
                        is_fwd: bool,
                        from_index: int,
                        nearby_idxs: List[int],
                        to_vh_id_num: int,
                        prexoveritem_manager: PreXoverManagerT):
        """Update this pooled PreXoverItem with current info.
        Called by PreXoverManager.

        Args:
            from_virtual_helix_item: the associated vh_item
            is_fwd: True if associated with fwd strand, False if rev strand
            from_index: idx of associated vh
            nearby_idxs:
            to_vh_id_num: id_num of the other vh
            prexoveritem_manager: the manager
        """
        # to_vh_item = from_virtual_helix_item.partItem().idToVirtualHelixItem(to_vh_id_num)
        self.setParentItem(from_virtual_helix_item)
        # self.setParentItem(to_vh_item)
        self.resetTransform()
        self._id_num = from_virtual_helix_item.idNum()
        self._model_part = from_virtual_helix_item.part()
        self.idx = from_index
        self.is_low = False
        self.is_high = False
        self.nearby_idxs = nearby_idxs
        self.is_fwd = is_fwd
        self.color = None
        self.is3p = None
        self.enter_pos = None
        self.exit_pos = None
        self.to_vh_id_num = to_vh_id_num
        self._label_txt = None
        self.prexoveritem_manager = prexoveritem_manager

        # todo: check here if xover present and disable
        result = self.setPathAppearance(from_virtual_helix_item)

        if result:
            self.setBrush(getNoBrush())
            if is_fwd:
                self.setPos(from_index*BASE_WIDTH, -BASE_WIDTH - 0.1*BASE_WIDTH)
            else:
                self.setPos(from_index*BASE_WIDTH, 2*BASE_WIDTH)
            self.show()
            # label
            self._label_txt = lbt = None if to_vh_id_num is None else str(to_vh_id_num)
            self._label.resetItem(is_fwd, self.color)
            self.setLabel(text=lbt)

            # bond line
            bonditem = self._bond_item
            bonditem.setPen(getPenObj(  self.color,
                                        styles.PREXOVER_STROKE_WIDTH,
                                        penstyle=Qt.DotLine))
            bonditem.hide()
Ejemplo n.º 23
0
    def setPathAppearance(
            self, from_virtual_helix_item: PathVirtualHelixItemT) -> bool:
        """Sets the PainterPath according to the index (low = Left, high = Right)
            and strand position (top = Up, bottom = Down).

            Args:
                from_virtual_helix_item:
            """
        part = self._model_part
        idx = self.idx
        is_fwd = self.is_fwd
        id_num = self._id_num
        strand_type = StrandEnum.FWD if is_fwd else StrandEnum.REV

        # relative position info
        bpr = from_virtual_helix_item.getProperty('bases_per_repeat')
        self.is_low = is_low = idx + 1 in self.nearby_idxs or (
            idx + 1) % bpr in self.nearby_idxs
        self.is_high = is_high = idx - 1 in self.nearby_idxs or (
            idx - 1) % bpr in self.nearby_idxs

        # check strand for xover and color
        if part.hasStrandAtIdx(id_num, idx)[strand_type]:
            strand = part.getStrand(self.is_fwd, id_num, idx)
            if strand.hasXoverAt(idx):
                return False
            self.color = strand.getColor() if strand is not None else EMPTY_COL
        else:
            self.color = EMPTY_COL

        if is_low and is_high:
            path = (_FWD_DUAL_PATH, _REV_DUAL_PATH)[strand_type]
            raise NotImplementedError("Dual xovers not yet supported")
        elif is_low:
            path = (_FWD_LO_PATH, _REV_LO_PATH)[strand_type]
            self.is3p = True if is_fwd else False
            self.enter_pos = _FWD_LO_PTS[0][-1] if is_fwd else _REV_LO_PTS[0][
                -1]
            self.exit_pos = _FWD_LO_PTS[0][-1] if is_fwd else _REV_LO_PTS[0][-1]
        elif is_high:
            path = (_FWD_HI_PATH, _REV_HI_PATH)[strand_type]
            self.is3p = False if is_fwd else True
            self.enter_pos = _FWD_HI_PTS[0][-1] if is_fwd else _REV_HI_PTS[0][
                -1]
            self.exit_pos = _FWD_HI_PTS[0][-1] if is_fwd else _REV_HI_PTS[0][-1]
        else:
            # print("unpaired PreXoverItem at {}[{}]".format(self._id_num, self.idx), self.nearby_idxs)
            return False
        self._tick_marks.setPen(
            getPenObj(self.color,
                      styles.PREXOVER_STROKE_WIDTH,
                      capstyle=Qt.FlatCap,
                      joinstyle=Qt.RoundJoin))
        self._tick_marks.setPath(path)
        self._tick_marks.show()
        return True
Ejemplo n.º 24
0
    def _updateFloatPen(self):
        """Summary

        Returns:
            TYPE: Description
        """
        pen_width = styles.PATH_STRAND_STROKE_WIDTH
        pen = getPenObj(_PENCIL_COLOR, pen_width)
        pen.setCapStyle(Qt.FlatCap)
        self.setPen(pen)
Ejemplo n.º 25
0
    def hoverEnterEvent(self, event: QGraphicsSceneHoverEvent):
        """Summary

        Args:
            event: Description
        """
        self.setBrush(getBrushObj(styles.ACTIVE_GRID_DOT_COLOR))
        self.setPen(getPenObj(styles.ACTIVE_GRID_DOT_COLOR, 1.0))
        part_item = self.grid.part_item
        part_item._getActiveTool()
Ejemplo n.º 26
0
    def hoverEnterEvent(self, event):
        """Summary

        Args:
            event (QGraphicsSceneHoverEvent): Description
        """
        self.setBrush(getBrushObj(styles.ACTIVE_GRID_DOT_COLOR))
        self.setPen(getPenObj(styles.ACTIVE_GRID_DOT_COLOR, 1.0))
        part_item = self.grid.part_item
        part_item._getActiveTool()
Ejemplo n.º 27
0
    def _updateFloatPen(self):
        """Summary

        Returns:
            TYPE: Description
        """
        pen_width = styles.PATH_STRAND_STROKE_WIDTH
        pen = getPenObj(_PENCIL_COLOR, pen_width)
        pen.setCapStyle(Qt.FlatCap)
        self.setPen(pen)
Ejemplo n.º 28
0
    def hoverEnterEvent(self, event):
        """Summary

        Args:
            event (QGraphicsSceneHoverEvent): Description
        """
        self.setBrush(getBrushObj(styles.ACTIVE_GRID_DOT_COLOR))
        self.setPen(getPenObj(styles.ACTIVE_GRID_DOT_COLOR, 1.0))
        self.grid.part_item.vhi_hint_item.setPos(
            self.scenePos() - QPointF(_RADIUS - DELTA, _RADIUS - DELTA))
Ejemplo n.º 29
0
    def __init__(self, model_part_instance, viewroot, parent):
        """parent should always be pathrootitem

        Args:
            model_part_instance (TYPE): Description
            viewroot (TYPE): Description
            parent (TYPE): Description
        """
        super(PathNucleicAcidPartItem, self).__init__(model_part_instance,
                                                      viewroot, parent)
        self.setAcceptHoverEvents(True)

        self._getActiveTool = viewroot.manager.activeToolGetter
        self.active_virtual_helix_item = None
        m_p = self._model_part
        self._controller = NucleicAcidPartItemController(self, m_p)
        self.prexover_manager = PreXoverManager(self)
        self._virtual_helix_item_list = []
        self._initModifierRect()
        self._proxy_parent = ProxyParentItem(self)
        self._proxy_parent.setFlag(QGraphicsItem.ItemHasNoContents)
        self._scale_2_model = m_p.baseWidth() / _BASE_WIDTH
        self._scale_2_Qt = _BASE_WIDTH / m_p.baseWidth()

        # self._rect = QRectF()
        self._vh_rect = QRectF()
        # self.setPen(getPenObj(styles.ORANGE_STROKE, 0))
        self.setPen(getNoPen())
        # self.setRect(self._rect)

        self.outline = outline = PathRectItem(self)
        outline.setFlag(QGraphicsItem.ItemStacksBehindParent)
        self.setZValue(styles.ZPART)
        self._proxy_parent.setZValue(styles.ZPART)
        outline.setZValue(styles.ZDESELECTOR)
        self.outline.setPen(getPenObj(m_p.getColor(), _DEFAULT_WIDTH))
        o_rect = self._configureOutline(outline)
        model_color = m_p.getColor()

        self.resize_handle_group = ResizeHandleGroup(
            o_rect,
            _HANDLE_SIZE,
            model_color,
            True,
            # HandleType.LEFT |
            HandleType.RIGHT,
            self)

        self.model_bounds_hint = m_b_h = QGraphicsRectItem(self)
        m_b_h.setBrush(getBrushObj(styles.BLUE_FILL, alpha=32))
        m_b_h.setPen(getNoPen())
        m_b_h.hide()

        self.workplane = PathWorkplaneItem(m_p, self)
        self.hide()  # show on adding first vh
Ejemplo n.º 30
0
    def doSquare(self, part_item, radius, bounds):
        """Summary

        Args:
            part_item (TYPE): Description
            radius (TYPE): Description
            bounds (TYPE): Description

        Returns:
            TYPE: Description
        """
        doLattice = SquareDnaPart.latticeCoordToPositionXY
        doPosition = SquareDnaPart.positionToLatticeCoordRound
        x_l, x_h, y_l, y_h = bounds
        dot_size, half_dot_size = self.dots
        sf = part_item.scale_factor
        points = self.points
        row_l, col_l = doPosition(radius, x_l, -y_l, scale_factor=sf)
        row_h, col_h = doPosition(radius, x_h, -y_h, scale_factor=sf)
        # print(row_l, row_h, col_l, col_h)

        path = QPainterPath()
        is_pen_down = False
        draw_lines = self.draw_lines

        for i in range(row_l, row_h + 1):
            for j in range(col_l, col_h + 1):
                x, y = doLattice(radius, i, j, scale_factor=sf)
                if draw_lines:
                    if is_pen_down:
                        path.lineTo(x, -y)
                    else:
                        is_pen_down = True
                        path.moveTo(x, -y)
                """ +x is Left and +y is down
                origin of ellipse is Top Left corner so we subtract half in X
                and subtract in y
                """
                pt = GridPoint(x - half_dot_size, -y - half_dot_size, dot_size,
                               self)
                pt.setPen(getPenObj(Qt.blue, 1.0))
                points.append(pt)
            is_pen_down = False  # pen up
        # DO VERTICAL LINES
        if draw_lines:
            for j in range(col_l, col_h + 1):
                for i in range(row_l, row_h + 1):
                    x, y = doLattice(radius, i, j, scale_factor=sf)
                    if is_pen_down:
                        path.lineTo(x, -y)
                    else:
                        is_pen_down = True
                        path.moveTo(x, -y)
                is_pen_down = False  # pen up
        self.setPath(path)
Ejemplo n.º 31
0
    def doSquare(self,  part_item: GridNucleicAcidPartItemT,
                        radius: float,
                        bounds: RectT):
        """
        Args:
            part_item: Description
            radius: Description
            bounds: Description
        """
        doLattice = SquareDnaPart.latticeCoordToModelXY
        doPosition = SquareDnaPart.positionToLatticeCoordRound
        x_l, x_h, y_l, y_h = bounds
        dot_size, half_dot_size = self.dots
        sf = part_item.scale_factor
        points = self.points
        row_l, col_l = doPosition(radius, x_l, -y_l, scale_factor=sf)
        row_h, col_h = doPosition(radius, x_h, -y_h, scale_factor=sf)
        # print(row_l, row_h, col_l, col_h)

        path = QPainterPath()
        is_pen_down = False
        draw_lines = self.draw_lines

        for i in range(row_l, row_h + 1):
            for j in range(col_l, col_h + 1):
                x, y = doLattice(radius, i, j, scale_factor=sf)
                if draw_lines:
                    if is_pen_down:
                        path.lineTo(x, -y)
                    else:
                        is_pen_down = True
                        path.moveTo(x, -y)
                """+x is Left and +y is down
                origin of ellipse is Top Left corner so we subtract half in X
                and subtract in y
                """
                pt = GridPoint(x - half_dot_size,
                               -y - half_dot_size,
                               dot_size, self)
                pt.setPen(getPenObj(Qt.blue, 1.0))
                points.append(pt)
            is_pen_down = False  # pen up
        # DO VERTICAL LINES
        if draw_lines:
            for j in range(col_l, col_h + 1):
                for i in range(row_l, row_h + 1):
                    x, y = doLattice(radius, i, j, scale_factor=sf)
                    if is_pen_down:
                        path.lineTo(x, -y)
                    else:
                        is_pen_down = True
                        path.moveTo(x, -y)
                is_pen_down = False  # pen up
        self.setPath(path)
Ejemplo n.º 32
0
    def resetPen(self, color, width=0):
        """Summary

        Args:
            color (TYPE): Description
            width (int, optional): Description

        Returns:
            TYPE: Description
        """
        pen = getPenObj(color, width)
        self.setPen(pen)
Ejemplo n.º 33
0
    def __init__(self, boxtype: QGraphicsItem,
                    constraint: str,
                    viewroot: PathRootItemT):
        """
        Args:
            boxtype: :class:`EndpointHandleSelectionBox` or
                :class:`VirtualHelixHandleSelectionBox` instance
            constraint: ``x`` or ``y``. Default to ``y`` (up and down)
            viewroot: view root item and object parent

        """
        super(SelectionItemGroup, self).__init__(viewroot)
        self.viewroot: PathRootItemT = viewroot
        self.setFiltersChildEvents(True)

        # LOOK at Qt Source for deprecated code to replace this behavior
        # self.setHandlesChildEvents(True) # commented out NC

        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.setFlag(QGraphicsItem.ItemIsFocusable)  # for keyPressEvents
        self.setFlag(QGraphicsItem.ItemHasNoContents)

        self._rect = QRectF()
        self._PEN = getPenObj(styles.BLUE_STROKE,
                              styles.PATH_SELECTBOX_STROKE_WIDTH)

        self.selectionbox = boxtype(self)

        self._drag_enable = False
        self._dragged = False

        self._r0 = 0  # save original mousedown
        self._r = 0  # latest position for moving

        # self._lastKid = 0

        # this keeps track of mousePressEvents within the class
        # to aid in intellignetly removing items from the group
        self._added_to_press_list = False

        self._pending_to_add_dict = {}

        if constraint == 'y':
            self.getR = self.selectionbox.getY
            self.translateR = self.selectionbox.translateY
        else:
            self.getR = self.selectionbox.getX
            self.translateR = self.selectionbox.translateX

        self._normal_select = True

        self.setZValue(styles.ZPATHSELECTION)
Ejemplo n.º 34
0
    def updateProperty(self):
        part_color = self.part().getProperty('color')

        self._USE_PEN = getPenObj(part_color, styles.SLICE_HELIX_STROKE_WIDTH)
        self._OUT_OF_SLICE_PEN = getPenObj(part_color, styles.SLICE_HELIX_STROKE_WIDTH)
        self._USE_BRUSH = getBrushObj(part_color, alpha=128)
        self._OUT_OF_SLICE_BRUSH = getBrushObj(part_color, alpha=64)

        if self.part().crossSectionType() == LatticeType.HONEYCOMB:
            self._USE_PEN = getPenObj(styles.BLUE_STROKE, styles.SLICE_HELIX_STROKE_WIDTH)
            self._OUT_OF_SLICE_PEN = getPenObj(styles.BLUE_STROKE,\
                                          styles.SLICE_HELIX_STROKE_WIDTH)

        if self.part().partType() == PartType.NUCLEICACIDPART:
            self._OUT_OF_SLICE_BRUSH = self._OUT_OF_SLICE_BRUSH_DEFAULT
            # self._USE_BRUSH = getBrushObj(part_color, lighter=180)
            self._USE_BRUSH = getBrushObj(part_color, alpha=150)

        self._label.setBrush(self._OUT_OF_SLICE_TEXT_BRUSH)
        self.setBrush(self._OUT_OF_SLICE_BRUSH)
        self.setPen(self._OUT_OF_SLICE_PEN)
        self.setRect(self._RECT)
Ejemplo n.º 35
0
    def __init__(self, boxtype: QGraphicsItem, constraint: str,
                 viewroot: PathRootItemT):
        """
        Args:
            boxtype: :class:`EndpointHandleSelectionBox` or
                :class:`VirtualHelixHandleSelectionBox` instance
            constraint: ``x`` or ``y``. Default to ``y`` (up and down)
            viewroot: view root item and object parent

        """
        super(SelectionItemGroup, self).__init__(viewroot)
        self.viewroot: PathRootItemT = viewroot
        self.setFiltersChildEvents(True)

        # LOOK at Qt Source for deprecated code to replace this behavior
        # self.setHandlesChildEvents(True) # commented out NC

        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.setFlag(QGraphicsItem.ItemIsFocusable)  # for keyPressEvents
        self.setFlag(QGraphicsItem.ItemHasNoContents)

        self._rect = QRectF()
        self._PEN = getPenObj(styles.BLUE_STROKE,
                              styles.PATH_SELECTBOX_STROKE_WIDTH)

        self.selectionbox = boxtype(self)

        self._drag_enable = False
        self._dragged = False

        self._r0 = 0  # save original mousedown
        self._r = 0  # latest position for moving

        # self._lastKid = 0

        # this keeps track of mousePressEvents within the class
        # to aid in intellignetly removing items from the group
        self._added_to_press_list = False

        self._pending_to_add_dict = {}

        if constraint == 'y':
            self.getR = self.selectionbox.getY
            self.translateR = self.selectionbox.translateY
        else:
            self.getR = self.selectionbox.getX
            self.translateR = self.selectionbox.translateX

        self._normal_select = True

        self.setZValue(styles.ZPATHSELECTION)
Ejemplo n.º 36
0
    def setPathAppearance(self, from_virtual_helix_item: PathVirtualHelixItemT) -> bool:
            """Sets the PainterPath according to the index (low = Left, high = Right)
            and strand position (top = Up, bottom = Down).

            Args:
                from_virtual_helix_item:
            """
            part = self._model_part
            idx = self.idx
            is_fwd = self.is_fwd
            id_num = self._id_num
            strand_type = StrandEnum.FWD if is_fwd else StrandEnum.REV

            # relative position info
            bpr = from_virtual_helix_item.getProperty('bases_per_repeat')
            self.is_low = is_low = idx+1 in self.nearby_idxs or (idx+1) % bpr in self.nearby_idxs
            self.is_high = is_high = idx-1 in self.nearby_idxs or (idx-1) % bpr in self.nearby_idxs

            # check strand for xover and color
            if part.hasStrandAtIdx(id_num, idx)[strand_type]:
                strand = part.getStrand(self.is_fwd, id_num, idx)
                if strand.hasXoverAt(idx):
                    return False
                self.color = strand.getColor() if strand is not None else EMPTY_COL
            else:
                self.color = EMPTY_COL

            if is_low and is_high:
                path = (_FWD_DUAL_PATH, _REV_DUAL_PATH)[strand_type]
                raise NotImplementedError("Dual xovers not yet supported")
            elif is_low:
                path = (_FWD_LO_PATH, _REV_LO_PATH)[strand_type]
                self.is3p = True if is_fwd else False
                self.enter_pos = _FWD_LO_PTS[0][-1] if is_fwd else _REV_LO_PTS[0][-1]
                self.exit_pos = _FWD_LO_PTS[0][-1] if is_fwd else _REV_LO_PTS[0][-1]
            elif is_high:
                path = (_FWD_HI_PATH, _REV_HI_PATH)[strand_type]
                self.is3p = False if is_fwd else True
                self.enter_pos = _FWD_HI_PTS[0][-1] if is_fwd else _REV_HI_PTS[0][-1]
                self.exit_pos = _FWD_HI_PTS[0][-1] if is_fwd else _REV_HI_PTS[0][-1]
            else:
                # print("unpaired PreXoverItem at {}[{}]".format(self._id_num, self.idx), self.nearby_idxs)
                return False
            self._tick_marks.setPen(getPenObj(  self.color,
                                                styles.PREXOVER_STROKE_WIDTH,
                                                capstyle=Qt.FlatCap,
                                                joinstyle=Qt.RoundJoin))
            self._tick_marks.setPath(path)
            self._tick_marks.show()
            return True
Ejemplo n.º 37
0
    def setSnapOrigin(self, is_snap: bool):
        """Used to toggle an item as the snap origin. See :class:`SelectGridTool`.

        Args:
            is_snap (bool): True if this should be the snap origin, False otherwise.
        """
        if is_snap:
            op = self.pen()
            if self.old_pen is None:
                self.old_pen = op
            self.setPen(getPenObj(op.color().name(), SNAP_WIDTH))
        else:
            self.setPen(self.old_pen)
            self.old_pen = None
    def __init__(self, part_instance: ObjectInstance, viewroot: PathRootItemT):
        """parent should always be ``PathRootItem``

        Args:
            part_instance:  ``ObjectInstance`` of the ``Part``
            viewroot: ``PathRootItem`` and parent object
        """
        super(PathNucleicAcidPartItem, self).__init__(part_instance, viewroot)
        self.setAcceptHoverEvents(True)

        self._getActiveTool = viewroot.manager.activeToolGetter
        self.active_virtual_helix_item: PathVirtualHelixItem = None
        m_p = self._model_part
        self._controller = NucleicAcidPartItemController(self, m_p)
        self.prexover_manager: PreXoverManager = PreXoverManager(self)
        self._virtual_helix_item_list = []
        self._initModifierRect()
        self._proxy_parent = ProxyParentItem(self)
        self._proxy_parent.setFlag(QGraphicsItem.ItemHasNoContents)
        self._scale_2_model: float = m_p.baseWidth() / _BASE_WIDTH
        self._scale_2_Qt: float = _BASE_WIDTH / m_p.baseWidth()

        self._vh_rect: QRectF = QRectF()
        self.setPen(getNoPen())

        self.outline: PathRectItem = PathRectItem(self)
        outline = self.outline
        outline.setFlag(QGraphicsItem.ItemStacksBehindParent)
        self.setZValue(styles.ZPART)
        self._proxy_parent.setZValue(styles.ZPART)
        outline.setZValue(styles.ZDESELECTOR)
        self.outline.setPen(getPenObj(m_p.getColor(), _DEFAULT_WIDTH))
        o_rect = self._configureOutline(outline)
        model_color = m_p.getColor()

        self.resize_handle_group: ResizeHandleGroup = ResizeHandleGroup(
            o_rect,
            _HANDLE_SIZE,
            model_color,
            True,
            # HandleEnum.LEFT |
            HandleEnum.RIGHT,
            self)

        self.model_bounds_hint = m_b_h = QGraphicsRectItem(self)
        m_b_h.setBrush(getBrushObj(styles.BLUE_FILL, alpha=32))
        m_b_h.setPen(getNoPen())
        m_b_h.hide()

        self.hide()  # show on adding first vh
    def partPropertyChangedSlot(self, part: NucleicAcidPartT, key: str, new_value):
        """Slot

        Args:
            part: The model part
            key: Description
            new_value: Description
        """
        if self._model_part == part:
            self._model_props[key] = new_value
            if key == 'color':
                self.outline.setPen(getPenObj(new_value, _DEFAULT_WIDTH))
                for vhi in self._virtual_helix_item_hash.values():
                    vhi.updateAppearance()
                self.grab_cornerTL.setPen(getPenObj(new_value, 0))
                self.grab_cornerBR.setPen(getPenObj(new_value, 0))
            elif key == 'is_visible':
                if new_value:
                    self.show()
                else:
                    self.hide()
            elif key == 'grid_type':
                self.griditem.setGridType(new_value)
Ejemplo n.º 40
0
    def __init__(self,  part_instance: ObjectInstance,
                        viewroot: PathRootItemT):
        """parent should always be ``PathRootItem``

        Args:
            part_instance:  ``ObjectInstance`` of the ``Part``
            viewroot: ``PathRootItem`` and parent object
        """
        super(PathNucleicAcidPartItem, self).__init__(part_instance, viewroot)
        self.setAcceptHoverEvents(True)

        self._getActiveTool = viewroot.manager.activeToolGetter
        self.active_virtual_helix_item: PathVirtualHelixItem = None
        m_p = self._model_part
        self._controller = NucleicAcidPartItemController(self, m_p)
        self.prexover_manager: PreXoverManager = PreXoverManager(self)
        self._virtual_helix_item_list = []
        self._initModifierRect()
        self._proxy_parent = ProxyParentItem(self)
        self._proxy_parent.setFlag(QGraphicsItem.ItemHasNoContents)
        self._scale_2_model: float = m_p.baseWidth()/_BASE_WIDTH
        self._scale_2_Qt: float = _BASE_WIDTH / m_p.baseWidth()

        self._vh_rect: QRectF = QRectF()
        self.setPen(getNoPen())

        self.outline: PathRectItem = PathRectItem(self)
        outline = self.outline
        outline.setFlag(QGraphicsItem.ItemStacksBehindParent)
        self.setZValue(styles.ZPART)
        self._proxy_parent.setZValue(styles.ZPART)
        outline.setZValue(styles.ZDESELECTOR)
        self.outline.setPen(getPenObj(m_p.getColor(), _DEFAULT_WIDTH))
        o_rect = self._configureOutline(outline)
        model_color = m_p.getColor()

        self.resize_handle_group: ResizeHandleGroup = ResizeHandleGroup(
                                                        o_rect, _HANDLE_SIZE,
                                                        model_color, True,
                                                        # HandleEnum.LEFT |
                                                        HandleEnum.RIGHT,
                                                        self)

        self.model_bounds_hint = m_b_h = QGraphicsRectItem(self)
        m_b_h.setBrush(getBrushObj(styles.BLUE_FILL, alpha=32))
        m_b_h.setPen(getNoPen())
        m_b_h.hide()

        self.hide()  # show on adding first vh
Ejemplo n.º 41
0
    def __init__(self, boxtype, constraint='y', parent=None):
        """Summary

        Args:
            boxtype (TYPE): Description
            constraint (str, optional): Description
            parent (None, optional): Description
        """
        super(SelectionItemGroup, self).__init__(parent)
        self.viewroot = parent
        self.setFiltersChildEvents(True)

        # LOOK at Qt Source for deprecated code to replace this behavior
        # self.setHandlesChildEvents(True) # commented out NC

        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.setFlag(QGraphicsItem.ItemIsFocusable)  # for keyPressEvents
        self.setFlag(QGraphicsItem.ItemHasNoContents)

        self._rect = QRectF()
        self._PEN = getPenObj(styles.BLUE_STROKE,
                              styles.PATH_SELECTBOX_STROKE_WIDTH)

        self.selectionbox = boxtype(self)

        self._drag_enable = False
        self._dragged = False

        self._r0 = 0  # save original mousedown
        self._r = 0  # latest position for moving

        # self._lastKid = 0

        # this keeps track of mousePressEvents within the class
        # to aid in intellignetly removing items from the group
        self._added_to_press_list = False

        self._pending_to_add_dict = {}

        if constraint == 'y':
            self.getR = self.selectionbox.getY
            self.translateR = self.selectionbox.translateY
        else:
            self.getR = self.selectionbox.getX
            self.translateR = self.selectionbox.translateX

        self._normal_select = True

        self.setZValue(styles.ZPATHSELECTION)
Ejemplo n.º 42
0
    def __init__(self, boxtype, constraint='y', parent=None):
        """Summary

        Args:
            boxtype (TYPE): Description
            constraint (str, optional): Description
            parent (None, optional): Description
        """
        super(SelectionItemGroup, self).__init__(parent)
        self.viewroot = parent
        self.setFiltersChildEvents(True)

        # LOOK at Qt Source for deprecated code to replace this behavior
        # self.setHandlesChildEvents(True) # commented out NC

        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.setFlag(QGraphicsItem.ItemIsFocusable)  # for keyPressEvents
        self.setFlag(QGraphicsItem.ItemHasNoContents)

        self._rect = QRectF()
        self._PEN = getPenObj(styles.BLUE_STROKE,
                              styles.PATH_SELECTBOX_STROKE_WIDTH)

        self.selectionbox = boxtype(self)

        self._drag_enable = False
        self._dragged = False

        self._r0 = 0  # save original mousedown
        self._r = 0  # latest position for moving

        # self._lastKid = 0

        # this keeps track of mousePressEvents within the class
        # to aid in intellignetly removing items from the group
        self._added_to_press_list = False

        self._pending_to_add_dict = {}

        if constraint == 'y':
            self.getR = self.selectionbox.getY
            self.translateR = self.selectionbox.translateY
        else:
            self.getR = self.selectionbox.getX
            self.translateR = self.selectionbox.translateX

        self._normal_select = True

        self.setZValue(styles.ZPATHSELECTION)
Ejemplo n.º 43
0
    def _updateBoundingRect(self):
        """
        Updates the bounding rect to the size of the childrenBoundingRect,
        and refreshes the addBases and removeBases buttons accordingly.

        Called by partZDimensionsChangedSlot and partPropertyChangedSlot
        """
        self.setPen(getPenObj(self.modelColor(), 0))
        self.resetBrush(styles.DEFAULT_BRUSH_COLOR, styles.DEFAULT_ALPHA)

        # self.setRect(self.childrenBoundingRect())
        _p = _BOUNDING_RECT_PADDING
        temp_rect = self._vh_rect.adjusted(-_p/2, -_p, _p, -_p/2)
        self.grab_corner.setTopLeft(temp_rect.topLeft())
        self.setRect(temp_rect)
Ejemplo n.º 44
0
    def __init__(self, width, color, is_resizable, parent):
        super(GrabCornerItem, self).__init__(parent)
        self.setRect(QRectF(0, 0, width, width))
        self.width = width
        self.half_width = width/2
        self.offset = QPointF(width, width)
        self.offset_x = QPointF(width, 0)
        self.offset_y = QPointF(0, width)
        self.align_offset = self.parentItem()._BOUNDING_RECT_PADDING

        self.is_grabbing = False
        self.setBrush(getBrushObj(FILL_COLOR))
        self.setPen(getPenObj(color, 0))
        self.is_resizable = is_resizable
        self.model_bounds = ()
        self.corner_type = TOP_LEFT
Ejemplo n.º 45
0
 def _updateColor(self, strand):
     oligo = strand.oligo()
     color = SELECT_COLOR if self.isSelected() else oligo.getColor()
     if oligo.shouldHighlight():
         alpha = 128
         pen_width = styles.PATH_STRAND_HIGHLIGHT_STROKE_WIDTH
     else:
         pen_width = styles.PATH_STRAND_STROKE_WIDTH
         alpha = None
     self.xover_3p_end._updateColor(strand)
     pen = getPenObj(color, pen_width, alpha=alpha, capstyle=Qt.FlatCap)
     brush = getBrushObj(color, alpha=alpha)
     self.setPen(pen)
     self._low_cap.updateHighlight(brush)
     self._high_cap.updateHighlight(brush)
     self._dual_cap.updateHighlight(brush)
Ejemplo n.º 46
0
 def _updateColor(self, strand):
     oligo = strand.oligo()
     color = SELECT_COLOR if self.isSelected() else oligo.getColor()
     if oligo.shouldHighlight():
         alpha = 128
         pen_width = styles.PATH_STRAND_HIGHLIGHT_STROKE_WIDTH
     else:
         pen_width = styles.PATH_STRAND_STROKE_WIDTH
         alpha = None
     self.xover_3p_end._updateColor(strand)
     pen = getPenObj(color, pen_width, alpha=alpha, capstyle=Qt.FlatCap)
     brush = getBrushObj(color, alpha=alpha)
     self.setPen(pen)
     self._low_cap.updateHighlight(brush)
     self._high_cap.updateHighlight(brush)
     self._dual_cap.updateHighlight(brush)
Ejemplo n.º 47
0
    def __init__(self, width, color, is_resizable, parent):
        super(GrabCornerItem, self).__init__(parent)
        self.setRect(QRectF(0, 0, width, width))
        self.width = width
        self.half_width = width / 2
        self.offset = QPointF(width, width)
        self.offset_x = QPointF(width, 0)
        self.offset_y = QPointF(0, width)
        self.align_offset = self.parentItem()._BOUNDING_RECT_PADDING

        self.is_grabbing = False
        self.setBrush(getBrushObj(FILL_COLOR))
        self.setPen(getPenObj(color, 0))
        self.is_resizable = is_resizable
        self.model_bounds = ()
        self.corner_type = TOP_LEFT
Ejemplo n.º 48
0
    def resetItem(self, from_virtual_helix_item, is_fwd, from_index, nearby_idxs,
                  to_vh_id_num, prexoveritem_manager):
        """Update this pooled PreXoverItem with current info.
        Called by PreXoverManager.

        Args:
            from_virtual_helix_item (cadnano.views.pathview.virtualhelixitem.VirtualHelixItem): the associated vh_item
            is_fwd (bool): True if associated with fwd strand, False if rev strand
            from_index (int): idx of associated vh
            to_vh_id_num (int): id_num of the other vh
            prexoveritem_manager (cadnano.views.pathview.prexoermanager.PreXoverManager): the manager
        """
        self.setParentItem(from_virtual_helix_item)
        self.resetTransform()
        self._id_num = from_virtual_helix_item.idNum()
        self._model_vh = from_virtual_helix_item.cnModel()
        self.idx = from_index
        self.is_low = False
        self.is_high = False
        self.nearby_idxs = nearby_idxs
        self.is_fwd = is_fwd
        self.color = None
        self.is3p = None
        self.enter_pos = None
        self.exit_pos = None
        self.to_vh_id_num = to_vh_id_num
        self.prexoveritem_manager = prexoveritem_manager

        # todo: check here if xover present and disable
        result = self.setPathAppearance(from_virtual_helix_item)

        if result:
            self.setBrush(getNoBrush())
            if is_fwd:
                self.setPos(from_index*BASE_WIDTH, -BASE_WIDTH)
            else:
                self.setPos(from_index*BASE_WIDTH, 2*BASE_WIDTH)
            self.show()
            # label
            self._label_txt = lbt = None if to_vh_id_num is None else str(to_vh_id_num)
            self.setLabel(text=lbt)
            self._label.resetItem(is_fwd, self.color)

            # bond line
            bonditem = self._bond_item
            bonditem.setPen(getPenObj(self.color, styles.PREXOVER_STROKE_WIDTH))
            bonditem.hide()
Ejemplo n.º 49
0
    def __init__(self, radius, rect, virtual_helix_item, is_active):
        """Summary

        Args:
            radius (TYPE): Description
            rect (TYPE): Description
            virtual_helix_item (VirtualHelixItem): Description
            is_active (TYPE): Description
        """
        super(PreXoverItemGroup, self).__init__(rect, virtual_helix_item)

        self._radius = radius
        self._rect = rect
        self.virtual_helix_item = virtual_helix_item
        self.model_part = virtual_helix_item.part()
        self.id_num = virtual_helix_item.idNum()
        self.is_active = is_active
        self.active_wedge_gizmo = WedgeGizmo(radius, rect, self)
        self.fwd_prexover_items = fwd_pxis = {}
        self.rev_prexover_items = rev_pxis = {}
        self._colors = self._getColors()
        self.addItems()
        self.setPen(getNoPen())
        z = styles.ZPXIGROUP + 10 if is_active else styles.ZPXIGROUP
        self.setZValue(z)
        self.setTransformOriginPoint(rect.center())

        bpr, tpr, eulerZ = virtual_helix_item.getProperty(
            ['bases_per_repeat', 'turns_per_repeat', 'eulerZ'])

        self.setRotation(-eulerZ)  # add 180

        # for baseNearestPoint
        fwd_pos, rev_pos = [], []
        step_size = self.virtual_helix_item.getProperty('bases_per_repeat')
        for i in range(int(step_size)):
            fwd_pos.append(
                (fwd_pxis[i].scenePos().x(), fwd_pxis[i].scenePos().y()))
            rev_pos.append(
                (rev_pxis[i].scenePos().x(), rev_pxis[i].scenePos().y()))
        self.fwd_pos_array = np.asarray(fwd_pos)
        self.rev_pos_array = np.asarray(rev_pos)
        self.baseNearLine = QGraphicsLineItem(self)
        self.baseNearLine.setPen(
            getPenObj("#000000", 0.25, capstyle=Qt.RoundCap))
Ejemplo n.º 50
0
    def __init__(self, radius, rect, virtual_helix_item, is_active):
        """Summary

        Args:
            radius (TYPE): Description
            rect (TYPE): Description
            virtual_helix_item (VirtualHelixItem): Description
            is_active (TYPE): Description
        """
        super(PreXoverItemGroup, self).__init__(rect, virtual_helix_item)

        self._radius = radius
        self._rect = rect
        self.virtual_helix_item = virtual_helix_item
        self.model_part = virtual_helix_item.part()
        self.id_num = virtual_helix_item.idNum()
        self.is_active = is_active
        self.active_wedge_gizmo = WedgeGizmo(radius, rect, self)
        self.fwd_prexover_items = fwd_pxis = {}
        self.rev_prexover_items = rev_pxis = {}
        self._colors = self._getColors()
        self.addItems()
        self.setPen(getNoPen())
        z = styles.ZPXIGROUP + 10 if is_active else styles.ZPXIGROUP
        self.setZValue(z)
        self.setTransformOriginPoint(rect.center())

        bpr, tpr, eulerZ = virtual_helix_item.getProperty(['bases_per_repeat',
                                                           'turns_per_repeat',
                                                           'eulerZ'])

        self.setRotation(-eulerZ)  # add 180

        # for baseNearestPoint
        fwd_pos, rev_pos = [], []
        step_size = self.virtual_helix_item.getProperty('bases_per_repeat')
        for i in range(int(step_size)):
            fwd_pos.append((fwd_pxis[i].scenePos().x(),
                            fwd_pxis[i].scenePos().y()))
            rev_pos.append((rev_pxis[i].scenePos().x(),
                            rev_pxis[i].scenePos().y()))
        self.fwd_pos_array = np.asarray(fwd_pos)
        self.rev_pos_array = np.asarray(rev_pos)
        self.baseNearLine = QGraphicsLineItem(self)
        self.baseNearLine.setPen(getPenObj("#000000", 0.25, capstyle=Qt.RoundCap))
Ejemplo n.º 51
0
    def __init__(self,  tool: SelectGridTool,
                        parent: GridNucleicAcidPartItemT = None):
        """
        Args:
            tool: the selection tool
            parent: default is ``None``. a :class:`GridNucleicAcidPartItem`
        """
        super(GridSelectionGroup, self).__init__(parent)
        self.tool = tool
        self.setFiltersChildEvents(True)
        self.setFlag(QGraphicsItem.ItemIsFocusable)  # for keyPressEvents
        self.setFlag(QGraphicsItem.ItemIsMovable)

        self.bounding_rect_item = bri = QGraphicsRectItem(tool)
        bri.hide()
        bri.setPen(getPenObj(_SELECT_COLOR, _SELECT_PEN_WIDTH))

        self.setZValue(styles.ZSELECTION)

        self.drag_start_position = QPointF()
        self.drag_last_position = QPointF()
Ejemplo n.º 52
0
    def __init__(self, tool, parent=None):
        """Summary

        Args:
            tool (TYPE): Description
            parent (None, optional): Description
        """
        super(SliceSelectionGroup, self).__init__(parent)
        self.tool = tool
        self.setFiltersChildEvents(True)
        self.setFlag(QGraphicsItem.ItemIsFocusable)  # for keyPressEvents
        self.setFlag(QGraphicsItem.ItemIsMovable)

        self.bounding_rect_item = bri = QGraphicsRectItem(tool)
        bri.hide()
        bri.setPen(getPenObj(_SELECT_COLOR, _SELECT_PEN_WIDTH))

        self.setZValue(styles.ZSELECTION)

        self.drag_start_position = QPointF()
        self.drag_last_position = QPointF()
Ejemplo n.º 53
0
    def setTextAndStyle(self, text, outline=False):
        """Summary

        Args:
            text (TYPE): Description
            outline (bool, optional): Description

        Returns:
            TYPE: Description
        """
        str_txt = str(text)
        self._tbr = tBR = self._FM.tightBoundingRect(str_txt)
        half_label_H = tBR.height() / 2.0
        half_label_W = tBR.width() / 2.0

        labelX = BASE_WIDTH/2.0 - half_label_W
        if str_txt == '1':  # adjust for the number one
            labelX -= tBR.width()

        labelY = half_label_H if self.is_fwd else (BASE_WIDTH - tBR.height())/2

        self.setPos(labelX, labelY)
        self.setText(str_txt)

        if outline:
            self.setFont(self._XO_BOLD)
            self.setBrush(getBrushObj('#ff0000'))
        else:
            self.setFont(self._XO_FONT)
            self.setBrush(getBrushObj('#666666'))

        if outline:
            r = QRectF(self._tbr).adjusted(-half_label_W, 0,
                                           half_label_W, half_label_H)
            self._outline.setRect(r)
            self._outline.setPen(getPenObj('#ff0000', 0.25))
            self._outline.setY(2*half_label_H)
            self._outline.show()
        else:
            self._outline.hide()
Ejemplo n.º 54
0
    def showWedge(self, angle, color,
                  extended=False, rev_gradient=False, outline_only=False):
        """Summary

        Args:
            angle (TYPE): Description
            color (TYPE): Description
            extended (bool, optional): Description
            rev_gradient (bool, optional): Description
            outline_only (bool, optional): Description
        """
        # Hack to keep wedge in front
        # self.setRotation(self.pre_xover_item_group.rotation())

        self._last_params = (angle, color, extended, rev_gradient, outline_only)
        radius = self._radius
        span = self.pre_xover_item_group.partCrossoverSpanAngle() / 2
        radius_adjusted = radius + (_WEDGE_RECT_GAIN / 2)

        tip = QPointF(radius_adjusted, radius_adjusted)
        EXT = 1.35 if extended else 1.0

        # print("wtf", tip, pos)
        base_p2 = QPointF(1, 1)

        line0 = QLineF(tip, QPointF(base_p2))
        line1 = QLineF(tip, QPointF(base_p2))
        line2 = QLineF(tip, QPointF(base_p2))

        quad_scale = 1 + (.22*(span - 5) / 55)  # lo+(hi-lo)*(val-min)/(max-min)
        line0.setLength(radius_adjusted * EXT*quad_scale)  # for quadTo control point
        line1.setLength(radius_adjusted * EXT)
        line2.setLength(radius_adjusted * EXT)
        line0.setAngle(angle)
        line1.setAngle(angle - span)
        line2.setAngle(angle + span)

        path = QPainterPath()

        if outline_only:
            self.setPen(getPenObj(color, 0.5, alpha=128, capstyle=Qt.RoundCap))
            path.moveTo(line1.p2())
            path.quadTo(line0.p2(), line2.p2())
        else:
            gradient = QRadialGradient(tip, radius_adjusted * EXT)
            color1 = getColorObj(color, alpha=80)
            color2 = getColorObj(color, alpha=0)
            if rev_gradient:
                color1, color2 = color2, color1

            if extended:
                gradient.setColorAt(0, color1)
                gradient.setColorAt(radius_adjusted / (radius_adjusted * EXT), color1)
                gradient.setColorAt(radius_adjusted / (radius_adjusted * EXT) + 0.01, color2)
                gradient.setColorAt(1, color2)
            else:
                gradient.setColorAt(0, getColorObj(color, alpha=50))
            brush = QBrush(gradient)
            self.setBrush(brush)

            path.moveTo(line1.p1())
            path.lineTo(line1.p2())
            path.quadTo(line0.p2(), line2.p2())
            path.lineTo(line2.p1())

        self.setPath(path)
        self.show()
Ejemplo n.º 55
0
    GridVirtualHelixItemT
)
from cadnano.cntypes import (
    KeyT,
    ValueT
)

# set up default, hover, and active drawing styles
_RADIUS = styles.GRID_HELIX_RADIUS
_RECT = QRectF(0, 0, 2 * _RADIUS, 2 * _RADIUS)
_FONT = styles.GRID_NUM_FONT
_ZVALUE = styles.ZGRIDHELIX
_BRUSH_DEFAULT = getBrushObj(styles.GRID_FILL)
_USE_TEXT_BRUSH = getBrushObj(styles.USE_TEXT_COLOR)

_HOVER_PEN = getPenObj('#ffffff', 128)
_HOVER_BRUSH = getBrushObj('#ffffff', alpha=5)

SNAP_WIDTH = 3


class GridVirtualHelixItem(AbstractVirtualHelixItem, QGraphicsEllipseItem):
    """The VirtualHelixItem is an individual circle that gets drawn in the GridView
    as a child of the NucleicAcidPartItem. Taken as a group, many GridHelix
    instances make up the crossection of the NucleicAcidPart. Clicking on a GridHelix
    adds a VirtualHelix to the PlasmidPart. The GridHelix then changes appearence
    and paints its corresponding VirtualHelix number.

    Attributes:
        FILTER_NAME (str): Belongs to the filter class 'virtual_helix'.
        is_active (bool): Does the item have focus.