public Loc(ILoc loc, ILocState state) { Id = loc.Id; Description = loc.Description; Owner = loc.Owner; if (state != null) { Speed = state.Speed.Actual; SpeedText = state.GetSpeedText(); StateText = state.GetStateText(); IsAssigned = state.CurrentBlock.Actual != null; IsCurrentRouteDurationExceeded = state.IsCurrentRouteDurationExceeded; IsControlledAutomatically = state.ControlledAutomatically.Actual; Direction = state.Direction.Actual.ToString().ToLower(); HasPossibleDeadlock = state.PossibleDeadlock.Actual; } }
/// <summary> /// Update this node from it's state. Only actually make changes if apply is set. /// </summary> /// <returns>True if the state has changed such that a re-ordering is needed.</returns> private bool DoUpdateFromState(bool apply, out bool routeDurationExceededDetected) { var isAssigned = IsAssigned; var isCurrentRouteDurationExceeded = locState.IsCurrentRouteDurationExceeded; var newImageIndex = isAssigned ? (isCurrentRouteDurationExceeded ? 1 : 0) : 2; var oldImageIndex = ImageIndex; if (apply) { this.SetText(locState.Description); speedCell.SetText(locState.GetSpeedText()); stateCell.SetText(locState.GetStateText()); ownerCell.SetText(locState.Owner); advCell.SetText(locState.CommandStationInfo); if (locState.ControlledAutomatically.IsConsistent) { var isChecked = locState.ControlledAutomatically.Actual; if (isChecked != Checked) { Checked = isChecked; } } var group = isAssigned ? groups[0] : groups[1]; var textColor = isAssigned ? (isCurrentRouteDurationExceeded ? Color.Red : DefaultForeColor) : Color.Gray; if (oldImageIndex != newImageIndex) { ImageIndex = newImageIndex; ForeColor = textColor; Group = group; } } routeDurationExceededDetected = ((oldImageIndex != newImageIndex) && (newImageIndex == 1)); return((oldImageIndex != newImageIndex) && ((oldImageIndex == 2) || (newImageIndex == 2))); }