Allow easy visualisation of states using yUML :)
This would need to be an addin or something, but it would be nice to have a way of visualising states as a diagram. Perhaps using http://yuml.me activity diagrams (until State diagrams are implemented).
1 comment
-
Jesse
commented
I did this but for Graphviz () using dot.
Add this to StateMachine.cs/// <summary>
/// Writes a visual representation of the FSM to be used in Graphviz.
/// </summary>
public string ToDot()
{
string ret = "digraph G {";foreach (var stateRepresentation in _stateConfiguration)
{
ret += loop(stateRepresentation.Value);
}ret += " }";
return (ret);
}private string loop(StateRepresentation value)
{
string s = "";
foreach (TTrigger trigger in value.PermittedTriggers)
{
TriggerBehaviour triggerBehaviour;
if (value.TryFindHandler(trigger, out triggerBehaviour))
{
TState destination;
if (triggerBehaviour.ResultsInTransitionFrom(value.UnderlyingState, new object[0], out destination))
{
var transition = new Transition(value.UnderlyingState, destination, trigger);
s += value.UnderlyingState + " -> " + transition.Destination + " [fontsize=10, label=\"" + trigger + "\"]" + ";";
}
}
}
return (s);
}