private IEnumerable <ArrowShape> GetArrowsConnectedTo(CompetitionClassState state) { var shapes = new HashSet <ArrowShape>(); foreach (ArrowShape incoming in GetIncomingArrowsFor(state)) { shapes.Add(incoming); } foreach (ArrowShape outgoing in GetOutgoingArrowsFor(state)) { shapes.Add(outgoing); } return(shapes); }
private static ICollection<CompetitionClassState> StatesInRange(CompetitionClassState first, CompetitionClassState lastInclusive) { IEnumerable<CompetitionClassState> enumValues = Enum.GetValues(typeof (CompetitionClassState)) .Cast<CompetitionClassState>() .SkipWhile(s => s != first) .TakeWhile(s => s != lastInclusive); var states = new HashSet<CompetitionClassState>(enumValues) { lastInclusive }; return states; }
private void SetState(CompetitionClassState newState) { if (classState != newState) { Log.Info($"Entering state: {newState}."); classState = newState; StateTransitioned?.Invoke(this, new EventArgs<CompetitionClassState>(classState)); } }
private void ExecuteExclusiveIfStateIn(CompetitionClassState stateAllowed, [NotNull] Action action) { ExecuteExclusiveIfStateIn(new[] { stateAllowed }, action); }
private static Tuple<CompetitionClassState, CompetitionClassState> GetTransition(CompetitionClassState from, CompetitionClassState to) { return new Tuple<CompetitionClassState, CompetitionClassState>(from, to); }
private void MarkSelectedShapes([CanBeNull] CompetitionClassState? previousState, CompetitionClassState nextState) { ArrowShape previousToNextArrow = null; if (previousState != null) { Tuple<CompetitionClassState, CompetitionClassState> previousToNextKey = GetTransition(previousState.Value, nextState); if (arrows.TransitionTable.ContainsKey(previousToNextKey)) { previousToNextArrow = arrows.TransitionTable[previousToNextKey]; } } if (blocks.Table.ContainsKey(nextState)) { blocks.Table[nextState].State = ShapeState.Selected; if (previousToNextArrow != null) { previousToNextArrow.State = ShapeState.Selected; } } }
private void MarkCandidateShapes(CompetitionClassState nextState) { foreach (CompetitionClassState state in AllStatesExcept(nextState)) { Tuple<CompetitionClassState, CompetitionClassState> key = GetTransition(nextState, state); if (arrows.TransitionTable.ContainsKey(key)) { if (blocks.Table[state].State != ShapeState.Disabled && arrows.TransitionTable[key].State != ShapeState.Disabled) { blocks.Table[state].State = ShapeState.Candidate; arrows.TransitionTable[key].State = ShapeState.Candidate; } } } }
private bool CanTransitionFromTo(CompetitionClassState previousState, CompetitionClassState nextState) { Tuple<CompetitionClassState, CompetitionClassState> previousToNextKey = GetTransition(previousState, nextState); return arrows.TransitionTable.ContainsKey(previousToNextKey) && blocks.Table.ContainsKey(nextState) && blocks.Table[nextState].State != ShapeState.Disabled; }
private void UpdateShapeStatesForTransition([CanBeNull] CompetitionClassState? previousState, CompetitionClassState nextState) { ResetShapeStates(); MarkCandidateShapes(nextState); MarkSelectedShapes(previousState, nextState); }
public void TransitionTo(CompetitionClassState nextState) { if (nextState == activeState) { return; } if (!CanTransitionFromTo(activeState, nextState)) { Log.Warn($"Unsupported transition from {activeState} to {nextState}: no path available."); seenUnsupportedTransition = true; } UpdateShapeStatesForTransition(activeState, nextState); activeState = nextState; Invalidate(); }
public TextBlock GetBlockForState(CompetitionClassState state) { if (Table.ContainsKey(state)) { return Table[state]; } throw ExceptionFactory.CreateNotSupportedExceptionFor(state); }
private IEnumerable<ArrowShape> GetOutgoingArrowsFor(CompetitionClassState state) { return from pair in TransitionTable where pair.Key.Item1 == state select pair.Value; }
private IEnumerable<ArrowShape> GetArrowsConnectedTo(CompetitionClassState state) { var shapes = new HashSet<ArrowShape>(); foreach (ArrowShape incoming in GetIncomingArrowsFor(state)) { shapes.Add(incoming); } foreach (ArrowShape outgoing in GetOutgoingArrowsFor(state)) { shapes.Add(outgoing); } return shapes; }
private Tuple<Tuple<CompetitionClassState, CompetitionClassState>, ArrowShape> ComposeTransition( CompetitionClassState fromState, CompetitionClassState toState, HorizontalAlignment side, VerticalAlignment fromConnection, VerticalAlignment toConnection, int depth = 1) { Tuple<CompetitionClassState, CompetitionClassState> transition = GetTransition(fromState, toState); TextBlock fromBlock = owner.blocks.GetBlockForState(fromState); TextBlock toBlock = owner.blocks.GetBlockForState(toState); PointF fromPoint = GetPointFor(fromBlock, side, fromConnection); PointF toPoint = GetPointFor(toBlock, side, toConnection); ArrowShape arrow = CreateArrowFor(side, fromPoint, toPoint, depth); return Tuple.Create(transition, arrow); }
private IEnumerable <ArrowShape> GetOutgoingArrowsFor(CompetitionClassState state) { return(from pair in TransitionTable where pair.Key.Item1 == state select pair.Value); }
private Tuple <Tuple <CompetitionClassState, CompetitionClassState>, ArrowShape> ComposeTransition(CompetitionClassState fromState, CompetitionClassState toState, HorizontalAlignment side, VerticalAlignment fromConnection, VerticalAlignment toConnection, int depth = 1) { Tuple <CompetitionClassState, CompetitionClassState> transition = GetTransition(fromState, toState); TextBlock fromBlock = owner.blocks.GetBlockForState(fromState); TextBlock toBlock = owner.blocks.GetBlockForState(toState); PointF fromPoint = GetPointFor(fromBlock, side, fromConnection); PointF toPoint = GetPointFor(toBlock, side, toConnection); ArrowShape arrow = CreateArrowFor(side, fromPoint, toPoint, depth); return(Tuple.Create(transition, arrow)); }