/// <summary> /// Returns the formatted text for a single superstate and its substates. /// For example, for DOT files this would be a subgraph containing nodes for all the substates. /// </summary> /// <param name="stateInfo">The superstate to generate text for</param> /// <returns>Description of the superstate, and all its substates, in the desired format</returns> public override string FormatOneCluster(SuperState stateInfo) { string stateRepresentationString = ""; var sourceName = stateInfo.StateName; StringBuilder label = new StringBuilder(sourceName); if ((stateInfo.EntryActions.Count > 0) || (stateInfo.ExitActions.Count > 0)) { label.Append("\\n----------"); label.Append(string.Concat(stateInfo.EntryActions.Select(act => "\\nentry / " + act))); label.Append(string.Concat(stateInfo.ExitActions.Select(act => "\\nexit / " + act))); } stateRepresentationString = "\n" + $"subgraph cluster{stateInfo.NodeName}" + "\n" + "\t{" + "\n" + $"\tlabel = \"{label.ToString()}\"" + "\n"; foreach (var subState in stateInfo.SubStates) { stateRepresentationString += FormatOneState(subState); } stateRepresentationString += "}\n"; return(stateRepresentationString); }
void AddSubstates(SuperState superState, IEnumerable <StateInfo> substates) { foreach (var subState in substates) { if (States.ContainsKey(subState.UnderlyingState.ToString())) { // This shouldn't happen } else if (subState.Substates.Any()) { SuperState sub = new SuperState(subState); States[subState.UnderlyingState.ToString()] = sub; superState.SubStates.Add(sub); sub.SuperState = superState; AddSubstates(sub, subState.Substates); } else { State sub = new State(subState); States[subState.UnderlyingState.ToString()] = sub; superState.SubStates.Add(sub); sub.SuperState = superState; } } }
/// <summary> /// Add superstates to the graph (states that have substates) /// </summary> /// <param name="machineInfo"></param> void AddSuperstates(StateMachineInfo machineInfo) { foreach (var stateInfo in machineInfo.States.Where(sc => (sc.Substates?.Count() > 0) && (sc.Superstate == null))) { SuperState state = new SuperState(stateInfo); States[stateInfo.UnderlyingState.ToString()] = state; AddSubstates(state, stateInfo.Substates); } }
/// <summary> /// Returns the formatted text for a single superstate and its substates. /// For example, for DOT files this would be a subgraph containing nodes for all the substates. /// </summary> /// <param name="stateInfo">The superstate to generate text for</param> /// <returns>Description of the superstate, and all its substates, in the desired format</returns> abstract internal string FormatOneCluster(SuperState stateInfo);
/// <summary> /// Returns the formatted text for a single superstate and its substates. /// For example, for DOT files this would be a subgraph containing nodes for all the substates. /// </summary> /// <param name="stateInfo">The superstate to generate text for</param> /// <returns>Description of the superstate, and all its substates, in the desired format</returns> public abstract string FormatOneCluster(SuperState stateInfo);