/// <summary> /// Initializes a new <see cref="PickAndPlace.StackList"/> /// </summary> /// <param name="machineType">Machine type of the new stacklist</param> /// <exception cref="System.ArgumentNullException">Thrown when machineType is null</exception> private StackList(IMachine machineType) : this() { if (machineType != null) { StackType[] stackConfig = machineType.StackConfiguration; int stackCount = stackConfig.Length; stackControls = new StackControl[stackCount]; for (int i = 0; i < stackCount; i++) { StackControl newControl = new StackControl(stackConfig[i], i); newControl.Location = new Point(0, 28 + (newControl.Height + 4) * i); newControl.Name = "stackControl" + (i + 1).ToString(); newControl.TabIndex = i + 1; newControl.MaxSpeed = machineType.MaxSpeed; newControl.MinSpeed = machineType.MinSpeed; newControl.Speed = machineType.DefaultSpeed; newControl.ReelChanged += OnReelListChanged; stackControls[i] = newControl; this.Controls.Add(newControl); } } else { throw new ArgumentNullException("machineType"); } }
/*-------------------------------------------------------------*/ private void OnReelListChanged(StackControl sender, Reel sendersOldReel) { if (updateAllListsEvent != null) { updateAllListsEvent(sender, sendersOldReel); } }
/// <summary> /// Handler for the updateAllListEvent, this event occurs when one of the comboboxes of the stackcontrols is changed, /// When that happens the sendersOldReel and the senders new reel change position /// </summary> /// <param name="sender">Stackcontrol who started the update event</param> /// <param name="sendersOldReel">The old reel of the stackControl</param> private void UpdateAllListsEvent(StackControl sender, Reel sendersOldReel) { foreach (StackList stackList_ in stacklisters) { if (stackList_.UpdateAllLists(sender, sendersOldReel)) { return; //If the change has happend return, no need to check the ohters } } }
/// <summary> /// Changes the reel of one of the <see cref="PickAndPlace.StackControl"/> with the senders old reel /// </summary> /// <param name="sender">Sender who contains the new rail</param> /// <param name="sendersOldReel">Rail to exchange</param> /// <returns>True if the <see cref="PickAndPlace.StackControl"/> who contains the senders new reel is in this <see cref="PickAndPlace.StackList"/> else false</returns> public bool UpdateAllLists(StackControl sender, Reel sendersOldReel) { for (int i = 0; i < stackControls.Length; i++) { StackControl stackControl_ = stackControls[i]; if ((stackControl_.Reel == sender.Reel) && (stackControl_ != sender)) { stackControl_.ChangeReel(sendersOldReel); return(true); } } return(false); }