public List <Gate> GetSelectedGates() { List <Gate> selected = null; if (_selectedItems.HasValue) { selected = new List <Gate>(); for (int i = _selectedItems.Value.BeginColumn; i <= _selectedItems.Value.EndColumn; i++) { for (int j = _selectedItems.Value.BeginRow; j <= _selectedItems.Value.EndRow; j++) { if ((_steps[i].Gates[j].Begin >= _selectedItems.Value.BeginRow) && (_steps[i].Gates[j].End <= _selectedItems.Value.EndRow)) { Gate oldGate = _steps[i].Gates[j]; if (oldGate.Name != GateName.Empty) { selected.Add(oldGate.Copy(_selectedItems.Value.BeginRow)); } j = oldGate.End; } } } if (selected.Count < 2) { throw new Exception("Too few gates selected. Composite gate can be created from at least 2 gates."); } } else { throw new Exception("No items selected."); } return(selected); }
private void CutCopy(bool cut) { if (_selectedItems.HasValue) { _clipboard = new List <List <Gate> >(); _clipboardSelection = new Selection( 0, _selectedItems.Value.RowSpan - 1, 0, _selectedItems.Value.ColumnSpan - 1); for (int i = _selectedItems.Value.BeginColumn; i <= _selectedItems.Value.EndColumn; i++) { List <Gate> current = new List <Gate>(); _clipboard.Add(current); for (int j = _selectedItems.Value.BeginRow; j <= _selectedItems.Value.EndRow; j++) { if ((_steps[i].Gates[j].Begin >= _selectedItems.Value.BeginRow) && (_steps[i].Gates[j].End <= _selectedItems.Value.EndRow)) { Gate oldGate = _steps[i].Gates[j]; current.Add(oldGate.Copy(_selectedItems.Value.BeginRow)); if (cut && oldGate.Name != GateName.Empty) { for (; j <= oldGate.End; j++) { RegisterRefModel gateRef = GetRefFromOffset(j); Gate newGate = new EmptyGate(gateRef); _steps[i].SetGate(newGate); } } j = oldGate.End; } } } } }