/// <summary>
        /// Convert the graph into a string representation, using the specified style.
        /// </summary>
        /// <param name="style"></param>
        /// <returns></returns>
        public string ToGraph(GraphStyleBase style)
        {
            string dirgraphText = style.GetPrefix().Replace("\n", System.Environment.NewLine);

            // Start with the clusters
            foreach (var state in States.Values.Where(x => x is SuperState))
            {
                dirgraphText += style.FormatOneCluster((SuperState)state).Replace("\n", System.Environment.NewLine);
            }

            // Next process all non-cluster states
            foreach (var state in States.Values)
            {
                if ((state is SuperState) || (state is Decision) || (state.SuperState != null))
                {
                    continue;
                }
                dirgraphText += style.FormatOneState(state).Replace("\n", System.Environment.NewLine);
            }

            // Finally, add decision nodes
            foreach (var dec in Decisions)
            {
                dirgraphText += style.FormatOneDecisionNode(dec.NodeName, dec.Method.Description)
                                .Replace("\n", System.Environment.NewLine);
            }

            // now build behaviours
            List <string> transits = style.FormatAllTransitions(Transitions);

            foreach (var transit in transits)
            {
                dirgraphText += System.Environment.NewLine + transit;
            }

            // Add initial transition if present
            var initialStateName = initialState.UnderlyingState.ToString();

            dirgraphText += System.Environment.NewLine + $" init [label=\"\", shape=point];";
            dirgraphText += System.Environment.NewLine + $" init -> \"{initialStateName}\"[style = \"solid\"]";

            dirgraphText += System.Environment.NewLine + "}";

            return(dirgraphText);
        }
Exemple #2
0
        /// <summary>
        /// Convert the graph into a string representation, using the specified style.
        /// </summary>
        /// <param name="style"></param>
        /// <returns></returns>
        public string ToGraph(GraphStyleBase style)
        {
            string dirgraphText = style.GetPrefix().Replace("\n", System.Environment.NewLine);

            // Start with the clusters
            foreach (var state in States.Values.Where(x => x is SuperState))
            {
                dirgraphText += style.FormatOneCluster((SuperState)state).Replace("\n", System.Environment.NewLine);
            }

            // Next process all non-cluster states
            foreach (var state in States.Values)
            {
                if ((state is SuperState) || (state is Decision) || (state.SuperState != null))
                {
                    continue;
                }

                dirgraphText += style.FormatOneState(state).Replace("\n", System.Environment.NewLine);
            }

            // Finally, add decision nodes
            foreach (var dec in Decisions)
            {
                dirgraphText += style.FormatOneDecisionNode(dec.NodeName, dec.Method.Description)
                                .Replace("\n", System.Environment.NewLine);
            }

            // now build behaviours
            List <string> transits = style.FormatAllTransitions(Transitions);

            foreach (var transit in transits)
            {
                dirgraphText += System.Environment.NewLine + transit;
            }

            dirgraphText += System.Environment.NewLine + "}";

            return(dirgraphText);
        }