def resizeSelection(self, delta, use_undostack=True): """ Moves the selected idxs by delta by first iterating over all strands to calculate new idxs (method will return if snap-to behavior would create illegal state), then applying a resize command to each strand. """ resize_list = [] # calculate new idxs for strandset_dict in self._selection_dict.values(): for strand, selected in strandset_dict.items(): part = strand.virtualHelix().part() idxL, idxH = strand.idxs() newL, newH = strand.idxs() deltaL = deltaH = delta # process xovers to get revised delta if selected[0] and strand.connectionLow(): newL = part.xoverSnapTo(strand, idxL, delta) if newL == None: return deltaH = newL-idxL if selected[1] and strand.connectionHigh(): newH = part.xoverSnapTo(strand, idxH, delta) if newH == None: return deltaL = newH-idxH # process endpoints if selected[0] and not strand.connectionLow(): newL = idxL + deltaL if selected[1] and not strand.connectionHigh(): newH = idxH + deltaH if newL > newH: # check for illegal state return resize_list.append((strand, newL, newH)) # end for # end for # execute the resize commands if use_undostack: self.undoStack().beginMacro("Resize Selection") for strand, idxL, idxH in resize_list: Strand.resize(strand, (idxL, idxH), use_undostack) if use_undostack: self.undoStack().endMacro()
def resizeSelection(self, delta, use_undostack=True): """ Moves the selected idxs by delta by first iterating over all strands to calculate new idxs (method will return if snap-to behavior would create illegal state), then applying a resize command to each strand. """ resize_list = [] # calculate new idxs for strandset_dict in self._selection_dict.values(): for strand, selected in strandset_dict.items(): part = strand.virtualHelix().part() idxL, idxH = strand.idxs() newL, newH = strand.idxs() deltaL = deltaH = delta # process xovers to get revised delta if selected[0] and strand.connectionLow(): newL = part.xoverSnapTo(strand, idxL, delta) if newL == None: return deltaH = newL - idxL if selected[1] and strand.connectionHigh(): newH = part.xoverSnapTo(strand, idxH, delta) if newH == None: return deltaL = newH - idxH # process endpoints if selected[0] and not strand.connectionLow(): newL = idxL + deltaL if selected[1] and not strand.connectionHigh(): newH = idxH + deltaH if newL > newH: # check for illegal state return resize_list.append((strand, newL, newH)) # end for # end for # execute the resize commands if use_undostack: self.undoStack().beginMacro("Resize Selection") for strand, idxL, idxH in resize_list: Strand.resize(strand, (idxL, idxH), use_undostack) if use_undostack: self.undoStack().endMacro()
def resizeSelection(self, delta: int, use_undostack: bool = True): """Moves the selected idxs by delta by first iterating over all strands to calculate new idxs (method will return if snap-to behavior would create illegal state), then applying a resize command to each strand. Args: delta: use_undostack: optional, default is ``True`` """ resize_list = [] vh_set = set() # calculate new idxs part = None for strandset_dict in self._selection_dict.values(): for strand, selected in strandset_dict.items(): if part is None: part = strand.part() idx_low, idx_high = strand.idxs() new_low, new_high = strand.idxs() delta_low = delta_high = delta # process xovers to get revised delta if selected[0] and strand.connectionLow(): new_low = part.xoverSnapTo(strand, idx_low, delta) if new_low is None: return delta_high = new_low - idx_low if selected[1] and strand.connectionHigh(): new_high = part.xoverSnapTo(strand, idx_high, delta) if new_high is None: return delta_low = new_high - idx_high # process endpoints if selected[0] and not strand.connectionLow(): new_low = idx_low + delta_low if selected[1] and not strand.connectionHigh(): new_high = idx_high + delta_high if new_low > new_high: # check for illegal state return vh_set.add(strand.idNum()) resize_list.append((strand, new_low, new_high)) # end for # end for # execute the resize commands us = self.undoStack() if use_undostack: us.beginMacro("Resize Selection") for strand, idx_low, idx_high in resize_list: Strand.resize(strand, (idx_low, idx_high), use_undostack, update_segments=False) if resize_list: cmd = RefreshSegmentsCommand(part, vh_set) if use_undostack: us.push(cmd) else: cmd.redo() if use_undostack: us.endMacro()
def resizeSelection(self, delta, use_undostack=True): """ Moves the selected idxs by delta by first iterating over all strands to calculate new idxs (method will return if snap-to behavior would create illegal state), then applying a resize command to each strand. Args: delta (float): use_undostack (bool): optional, default is True """ resize_list = [] vh_set = set() # calculate new idxs part = None for strandset_dict in self._selection_dict.values(): for strand, selected in strandset_dict.items(): if part is None: part = strand.part() idx_low, idx_high = strand.idxs() new_low, new_high = strand.idxs() delta_low = delta_high = delta # process xovers to get revised delta if selected[0] and strand.connectionLow(): new_low = part.xoverSnapTo(strand, idx_low, delta) if new_low is None: return delta_high = new_low - idx_low if selected[1] and strand.connectionHigh(): new_high = part.xoverSnapTo(strand, idx_high, delta) if new_high is None: return delta_low = new_high - idx_high # process endpoints if selected[0] and not strand.connectionLow(): new_low = idx_low + delta_low if selected[1] and not strand.connectionHigh(): new_high = idx_high + delta_high if new_low > new_high: # check for illegal state return vh_set.add(strand.idNum()) resize_list.append((strand, new_low, new_high)) # end for # end for # execute the resize commands us = self.undoStack() if use_undostack: us.beginMacro("Resize Selection") for strand, idx_low, idx_high in resize_list: Strand.resize(strand, (idx_low, idx_high), use_undostack, update_segments=False) if resize_list: cmd = RefreshSegmentsCommand(part, vh_set) if use_undostack: us.push(cmd) else: cmd.redo() if use_undostack: us.endMacro()