Exemple #1
0
    def __init__(self, model_part, parent):
        super(OutlineNucleicAcidPartItem, self).__init__(model_part, parent)
        self._controller = NucleicAcidPartItemController(self, model_part)
        self._model_part = model_part
        self.setExpanded(True)
        # properties
        temp_color = model_part.getColor()
        # outlinerview takes responsibility of overriding default part color
        if temp_color == "#000000":
            index = len(model_part.document().children()) - 1
            new_color = styles.PARTCOLORS[index % len(styles.PARTCOLORS)]
            model_part.setProperty('color', new_color)

        # item groups
        self._root_items = {}
        self._root_items['VHelixList'] = self.createRootPartItem('Virtual Helices', self)
        self._root_items['OligoList'] = self.createRootPartItem('Oligos', self)
        fs = model_part.document().filter_set
        if OutlineVirtualHelixItem.FILTER_NAME in fs:
            self._root_items['OligoList'].setFlags(DISABLE_FLAGS)
        else:
            self._root_items['VHelixList'].setFlags(DISABLE_FLAGS)
        # self._root_items['Modifications'] = self._createRootItem('Modifications', self)
        if model_part.is_active:
            print("should be active")
            self.activate()
    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()
    def __init__(self, model_part, parent):
        super(OutlineNucleicAcidPartItem, self).__init__(model_part, parent)
        self._controller = NucleicAcidPartItemController(self, model_part)
        self._model_part = model_part
        self.setExpanded(True)
        # properties
        temp_color = model_part.getColor()
        # outlinerview takes responsibility of overriding default part color
        if temp_color == "#000000":
            index = len(model_part.document().children()) - 1
            new_color = styles.PARTCOLORS[index % len(styles.PARTCOLORS)]
            model_part.setProperty('color', new_color)

        # item groups
        self._root_items = {}
        self._root_items['VHelixList'] = self.createRootPartItem('Virtual Helices', self)
        self._root_items['OligoList'] = self.createRootPartItem('Oligos', self)
        fs = model_part.document().filter_set
        if OutlineVirtualHelixItem.FILTER_NAME in fs:
            self._root_items['OligoList'].setFlags(DISABLE_FLAGS)
        else:
            self._root_items['VHelixList'].setFlags(DISABLE_FLAGS)
        # self._root_items['Modifications'] = self._createRootItem('Modifications', self)
        if model_part.is_active:
            print("should be active")
            self.activate()
    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
Exemple #5
0
 def __init__(self, **kwargs):
     """
     Args:
         model_part (NucleicAcidPart): The model part
         parent (:class:`PropertyEditorWidget`): The property editor
         key (str, optional): Default is ``None``
     """
     self.part_set = set()
     super(NucleicAcidPartSetItem, self).__init__(**kwargs)
     if self._key == "name":
         for outline_part in self.outlineViewObjList():
             model_part = outline_part.part()
             self.part_set.add(model_part)
             self._controller_list.append(
                 NucleicAcidPartItemController(self, model_part))
Exemple #6
0
class OutlineNucleicAcidPartItem(CNOutlinerItem, AbstractPartItem):
    FILTER_NAME = "part"

    def __init__(self, model_part, parent):
        super(OutlineNucleicAcidPartItem, self).__init__(model_part, parent)
        self._controller = NucleicAcidPartItemController(self, model_part)
        self._model_part = model_part
        self.setExpanded(True)
        # properties
        temp_color = model_part.getColor()
        # outlinerview takes responsibility of overriding default part color
        if temp_color == "#000000":
            index = len(model_part.document().children()) - 1
            new_color = styles.PARTCOLORS[index % len(styles.PARTCOLORS)]
            model_part.setProperty('color', new_color)

        # item groups
        self._root_items = {}
        self._root_items['VHelixList'] = self.createRootPartItem('Virtual Helices', self)
        self._root_items['OligoList'] = self.createRootPartItem('Oligos', self)
        fs = model_part.document().filter_set
        if OutlineVirtualHelixItem.FILTER_NAME in fs:
            self._root_items['OligoList'].setFlags(DISABLE_FLAGS)
        else:
            self._root_items['VHelixList'].setFlags(DISABLE_FLAGS)
        # self._root_items['Modifications'] = self._createRootItem('Modifications', self)
        if model_part.is_active:
            print("should be active")
            self.activate()
    # end def

    ### PRIVATE SUPPORT METHODS ###
    def __repr__(self):
        return "OutlineNucleicAcidPartItem %s" % self._cn_model.getProperty('name')

    ### PUBLIC SUPPORT METHODS ###
    def rootItems(self) -> Dict[str, RootPartItem]:
        return self._root_items
    # end def

    def part(self) -> NucleicAcidPartT:
        return self._cn_model
    # end def

    def itemType(self) -> EnumType:
        return ItemEnum.NUCLEICACID
    # end def

    def isModelSelected(self, document: DocT) -> bool:
        """Make sure the item is selected in the model
        TODO implement Part selection

        Args:
            document (Document): reference the the model :class:`Document`
        """
        return False
    # end def

    ### SLOTS ###
    def partRemovedSlot(self, part: NucleicAcidPartT):
        self._controller.disconnectSignals()
        self._cn_model = None
        self._controller = None
    # end def

    def partOligoAddedSlot(self, part: NucleicAcidPartT, oligo: OligoT):
        if self._viewroot.are_signals_enabled:
            m_o = oligo
            m_o.oligoRemovedSignal.connect(self.partOligoRemovedSlot)
            o_i = OutlineOligoItem(m_o, self._root_items['OligoList'])
            self._oligo_item_hash[m_o] = o_i
    # end def

    def partOligoRemovedSlot(self, part: NucleicAcidPartT, oligo: OligoT):
        m_o = oligo
        m_o.oligoRemovedSignal.disconnect(self.partOligoRemovedSlot)
        o_i = self._oligo_item_hash[m_o]
        o_i.parent().removeChild(o_i)
        del self._oligo_item_hash[m_o]
    # end def

    def partVirtualHelixAddedSlot(self, part: NucleicAcidPartT,
                                        id_num: int,
                                        virtual_helix: VirtualHelixT,
                                        neighbors: List[int]):
        if self._viewroot.are_signals_enabled:
            tw = self.treeWidget()
            tw.is_child_adding += 1
            vh_i = OutlineVirtualHelixItem(id_num, self._root_items['VHelixList'])
            self._virtual_helix_item_hash[id_num] = vh_i
            tw.is_child_adding -= 1

    def partVirtualHelixRemovingSlot(self, part: NucleicAcidPartT,
                                            id_num: int,
                                            virtual_helix: VirtualHelixT,
                                            neigbors: List[int]):
        vh_i = self._virtual_helix_item_hash.get(id_num)
        # in case a OutlineVirtualHelixItem Object is cleaned up before this happends
        if vh_i is not None:
            del self._virtual_helix_item_hash[id_num]
            vh_i.parent().removeChild(vh_i)
    # end def

    def partPropertyChangedSlot(self, part: NucleicAcidPartT, key: str, new_value: Any):
        if self._cn_model == part:
            self.setValue(key, new_value)
            if key == 'virtual_helix_order':
                vhi_dict = self._virtual_helix_item_hash
                self.treeWidget().document()
                new_list = [vhi_dict[id_num] for id_num in new_value]
                # 0. record what was selected
                selected_list = [(x, x.isSelected()) for x in new_list]
                root_vhi = self._root_items['VHelixList']
                # 1. move the items
                root_vhi.takeChildren()
                for vhi in new_list:
                    root_vhi.addChild(vhi)
                # 2. now reselect the previously selected.
                # could also query the model
                for vhi, was_selected in selected_list:
                    if was_selected:
                        vhi.setSelected(True)
    # end def

    def partSelectedChangedSlot(self, part: NucleicAcidPartT, is_selected: bool):
        # print("part", is_selected)
        self.setSelected(is_selected)
    # end def

    def partVirtualHelixPropertyChangedSlot(self, part: NucleicAcidPartT,
                                                id_num: int,
                                                virtual_helix: VirtualHelixT,
                                                keys: KeyT,
                                                values: ValueT):
        if self._cn_model == part:
            vh_i = self._virtual_helix_item_hash[id_num]
            for key, val in zip(keys, values):
                if key in CNOutlinerItem.PROPERTIES:
                    vh_i.setValue(key, val)
    # end def

    def partVirtualHelicesSelectedSlot(self, part: NucleicAcidPartT,
                                            vh_set: Set[int],
                                            is_adding: bool):
        """ is_adding (bool): adding (True) virtual helices to a selection
        or removing (False)
        """
        vhi_hash = self._virtual_helix_item_hash
        tw = self.treeWidget()
        model = tw.model()
        selection_model = tw.selectionModel()
        top_idx = tw.indexOfTopLevelItem(self)
        top_midx = model.index(top_idx, 0)
        vh_list = self._root_items['VHelixList']
        root_midx = model.index(self.indexOfChild(vh_list), 0, top_midx)
        tw.selection_filter_disabled = True
        if is_adding:
            flag = QItemSelectionModel.Select
            for id_num in vh_set:
                vhi = vhi_hash.get(id_num)
                # selecting a selected item will deselect it, so check
                idx = vh_list.indexOfChild(vhi)
                qmodel_idx = model.index(idx, 0, root_midx)
                if not vhi.isSelected() and not selection_model.isSelected(qmodel_idx):
                    # print("++++++slot Sselect outlinerview", vh_set)
                    selection_model.select(qmodel_idx, flag)
        else:
            flag = QItemSelectionModel.Deselect
            for id_num in vh_set:
                vhi = vhi_hash.get(id_num)
                # deselecting a deselected item will select it, so check
                idx = vh_list.indexOfChild(vhi)
                qmodel_idx = model.index(idx, 0, root_midx)
                if vhi.isSelected() and selection_model.isSelected(qmodel_idx):
                    # print("-----slot deselect outlinerview", vh_set)
                    selection_model.select(qmodel_idx, flag)
        tw.selection_filter_disabled = False
    # end def

    def partActiveVirtualHelixChangedSlot(self, part: NucleicAcidPartT, id_num: int):
        vhi = self._virtual_helix_item_hash.get(id_num, None)
        # if vhi is not None:
        self.setActiveVirtualHelixItem(vhi)
    # end def

    def partActiveChangedSlot(self, part: NucleicAcidPartT, is_active: bool):
        if part == self._cn_model:
            self.activate() if is_active else self.deactivate()
    # end def

    def setActiveVirtualHelixItem(self, new_active_vhi: OutlineVirtualHelixItem):
        current_vhi = self.active_virtual_helix_item
        if new_active_vhi != current_vhi:
            if current_vhi is not None:
                current_vhi.deactivate()
            if new_active_vhi is not None:
                new_active_vhi.activate()
            self.active_virtual_helix_item = new_active_vhi
class OutlineNucleicAcidPartItem(CNOutlinerItem, AbstractPartItem):
    FILTER_NAME = "part"

    def __init__(self, model_part, parent):
        super(OutlineNucleicAcidPartItem, self).__init__(model_part, parent)
        self._controller = NucleicAcidPartItemController(self, model_part)
        self._model_part = model_part
        self.setExpanded(True)
        # properties
        temp_color = model_part.getColor()
        # outlinerview takes responsibility of overriding default part color
        if temp_color == "#000000":
            index = len(model_part.document().children()) - 1
            new_color = styles.PARTCOLORS[index % len(styles.PARTCOLORS)]
            model_part.setProperty('color', new_color)

        # item groups
        self._root_items = {}
        self._root_items['VHelixList'] = self.createRootPartItem('Virtual Helices', self)
        self._root_items['OligoList'] = self.createRootPartItem('Oligos', self)
        fs = model_part.document().filter_set
        if OutlineVirtualHelixItem.FILTER_NAME in fs:
            self._root_items['OligoList'].setFlags(DISABLE_FLAGS)
        else:
            self._root_items['VHelixList'].setFlags(DISABLE_FLAGS)
        # self._root_items['Modifications'] = self._createRootItem('Modifications', self)
        if model_part.is_active:
            print("should be active")
            self.activate()
    # end def

    ### PRIVATE SUPPORT METHODS ###
    def __repr__(self):
        return "OutlineNucleicAcidPartItem %s" % self._cn_model.getProperty('name')

    ### PUBLIC SUPPORT METHODS ###
    def rootItems(self) -> Dict[str, RootPartItem]:
        return self._root_items
    # end def

    def part(self) -> NucleicAcidPartT:
        return self._cn_model
    # end def

    def itemType(self) -> EnumType:
        return ItemEnum.NUCLEICACID
    # end def

    def isModelSelected(self, document: DocT) -> bool:
        """Make sure the item is selected in the model
        TODO implement Part selection

        Args:
            document (Document): reference the the model :class:`Document`
        """
        return False
    # end def

    ### SLOTS ###
    def partRemovedSlot(self, part: NucleicAcidPartT):
        self._controller.disconnectSignals()
        self._cn_model = None
        self._controller = None

        # NOTE: This is here to make sure it lives in a view.
        # only exists in outliner view.
        self._viewroot.window().toggleNewPartButtons(True)
    # end def

    def partOligoAddedSlot(self, part: NucleicAcidPartT, oligo: OligoT):
        if self._viewroot.are_signals_enabled:
            m_o = oligo
            m_o.oligoRemovedSignal.connect(self.partOligoRemovedSlot)
            o_i = OutlineOligoItem(m_o, self._root_items['OligoList'])
            self._oligo_item_hash[m_o] = o_i
    # end def

    def partOligoRemovedSlot(self, part: NucleicAcidPartT, oligo: OligoT):
        m_o = oligo
        m_o.oligoRemovedSignal.disconnect(self.partOligoRemovedSlot)
        o_i = self._oligo_item_hash[m_o]
        o_i.parent().removeChild(o_i)
        del self._oligo_item_hash[m_o]
    # end def

    def partVirtualHelixAddedSlot(self, part: NucleicAcidPartT,
                                        id_num: int,
                                        virtual_helix: VirtualHelixT,
                                        neighbors: List[int]):
        if self._viewroot.are_signals_enabled:
            tw = self.treeWidget()
            tw.is_child_adding += 1
            vh_i = OutlineVirtualHelixItem(id_num, self._root_items['VHelixList'])
            self._virtual_helix_item_hash[id_num] = vh_i
            tw.is_child_adding -= 1

    def partVirtualHelixRemovingSlot(self, part: NucleicAcidPartT,
                                            id_num: int,
                                            virtual_helix: VirtualHelixT,
                                            neigbors: List[int]):
        vh_i = self._virtual_helix_item_hash.get(id_num)
        # in case a OutlineVirtualHelixItem Object is cleaned up before this happends
        if vh_i is not None:
            del self._virtual_helix_item_hash[id_num]
            vh_i.parent().removeChild(vh_i)
    # end def

    def partPropertyChangedSlot(self, part: NucleicAcidPartT, key: str, new_value: Any):
        if self._cn_model == part:
            self.setValue(key, new_value)
            if key == 'virtual_helix_order':
                vhi_dict = self._virtual_helix_item_hash
                self.treeWidget().document()
                new_list = [vhi_dict[id_num] for id_num in new_value]
                # 0. record what was selected
                selected_list = [(x, x.isSelected()) for x in new_list]
                root_vhi = self._root_items['VHelixList']
                # 1. move the items
                root_vhi.takeChildren()
                for vhi in new_list:
                    root_vhi.addChild(vhi)
                # 2. now reselect the previously selected.
                # could also query the model
                for vhi, was_selected in selected_list:
                    if was_selected:
                        vhi.setSelected(True)
    # end def

    def partSelectedChangedSlot(self, part: NucleicAcidPartT, is_selected: bool):
        # print("part", is_selected)
        self.setSelected(is_selected)
    # end def

    def partVirtualHelixPropertyChangedSlot(self, part: NucleicAcidPartT,
                                                id_num: int,
                                                virtual_helix: VirtualHelixT,
                                                keys: KeyT,
                                                values: ValueT):
        if self._cn_model == part:
            vh_i = self._virtual_helix_item_hash[id_num]
            for key, val in zip(keys, values):
                if key in CNOutlinerItem.PROPERTIES:
                    vh_i.setValue(key, val)
    # end def

    def partVirtualHelicesSelectedSlot(self, part: NucleicAcidPartT,
                                            vh_set: Set[int],
                                            is_adding: bool):
        """ is_adding (bool): adding (True) virtual helices to a selection
        or removing (False)
        """
        vhi_hash = self._virtual_helix_item_hash
        tw = self.treeWidget()
        model = tw.model()
        selection_model = tw.selectionModel()
        top_idx = tw.indexOfTopLevelItem(self)
        top_midx = model.index(top_idx, 0)
        vh_list = self._root_items['VHelixList']
        root_midx = model.index(self.indexOfChild(vh_list), 0, top_midx)
        tw.selection_filter_disabled = True
        if is_adding:
            flag = QItemSelectionModel.Select
            for id_num in vh_set:
                vhi = vhi_hash.get(id_num)
                # selecting a selected item will deselect it, so check
                idx = vh_list.indexOfChild(vhi)
                qmodel_idx = model.index(idx, 0, root_midx)
                if not vhi.isSelected() and not selection_model.isSelected(qmodel_idx):
                    # print("++++++slot Sselect outlinerview", vh_set)
                    selection_model.select(qmodel_idx, flag)
        else:
            flag = QItemSelectionModel.Deselect
            for id_num in vh_set:
                vhi = vhi_hash.get(id_num)
                # deselecting a deselected item will select it, so check
                idx = vh_list.indexOfChild(vhi)
                qmodel_idx = model.index(idx, 0, root_midx)
                if vhi.isSelected() and selection_model.isSelected(qmodel_idx):
                    # print("-----slot deselect outlinerview", vh_set)
                    selection_model.select(qmodel_idx, flag)
        tw.selection_filter_disabled = False
    # end def

    def partActiveVirtualHelixChangedSlot(self, part: NucleicAcidPartT, id_num: int):
        vhi = self._virtual_helix_item_hash.get(id_num, None)
        # if vhi is not None:
        self.setActiveVirtualHelixItem(vhi)
    # end def

    def partActiveChangedSlot(self, part: NucleicAcidPartT, is_active: bool):
        if part == self._cn_model:
            self.activate() if is_active else self.deactivate()
    # end def

    def setActiveVirtualHelixItem(self, new_active_vhi: OutlineVirtualHelixItem):
        current_vhi = self.active_virtual_helix_item
        if new_active_vhi != current_vhi:
            if current_vhi is not None:
                current_vhi.deactivate()
            if new_active_vhi is not None:
                new_active_vhi.activate()
            self.active_virtual_helix_item = new_active_vhi