Example #1
0
 internal void To(DrawIOComponent tc, string text)
 {
     destinationComponent.Add(new DrawIOComponentLink(tc, text));
     tc.From(this);
 }
Example #2
0
 private void From(DrawIOComponent parentNode)
 {
     parents.Add(parentNode);
 }
Example #3
0
        public DrawIOComponent[] FlowchartBuilder(string[] lines)
        {
            string[] starticons     = new string[] { "((", "(", "[", "<" };
            string[] endicons       = new string[] { "))", ")", "]", ">" };
            string[] componenttypes = new string[] { "OVAL", "ROUNDRECT", "RECTANGLE", "DIAMOND" };

            List <DrawIOComponent> component = new List <DrawIOComponent> {
            };

            Dictionary <string, DrawIOComponent> componentMap = new Dictionary <string, DrawIOComponent>();

            //each line should be filtered to type of link or shape
            // link contains a --

            foreach (var line in lines)
            {
                if (line.Trim().Length == 0)
                {
                    continue;
                }
                if (line.Trim().StartsWith("graph "))
                {
                    DrawIOComponent.LR = line.Trim().Substring(6).Equals("LR");
                    continue;
                }

                if (!line.Contains("--"))
                {
                    // this is a component
                    //loop over the component and speparate text and Key

                    var isKey    = true;
                    var isQuoted = false;

                    DrawIOComponent ct = null;


                    var text          = "";
                    var key           = "";
                    var componentType = "";
                    //identify location of Symbol


                    int startIconIdx = -1;
                    int iconpos      = -1;

                    for (int i = 0; i < starticons.Length; i++)
                    {
                        var tmpIdx = line.IndexOf(starticons[i]);
                        if (tmpIdx > -1)
                        {
                            if (tmpIdx < startIconIdx || startIconIdx == -1)
                            {
                                startIconIdx = tmpIdx;
                                iconpos      = i;
                            }
                        }
                    }


                    key = line.Substring(0, startIconIdx);
                    int symbolstart = startIconIdx + starticons[iconpos].Length;
                    int symbolend   = line.IndexOf(endicons[iconpos]);
                    text = line.Substring(symbolstart, symbolend - symbolstart).Trim();
                    if (text.StartsWith("\"") && text.EndsWith("\""))
                    {
                        text = text.Substring(1, text.Length - 2);
                    }


                    componentType = componenttypes[iconpos];



                    switch (componentType)
                    {
                    case "RECTANGLE":
                        ct = new Rectangle(0, 0, 100, 50);
                        break;

                    case "ROUNDRECT":
                        ct = new RoundedRectangle(0, 0, 100, 50);
                        break;

                    case "OVAL":
                        ct = new Circle(0, 0, 100);
                        break;

                    case "DIAMOND":
                        ct = new Rectangle(0, 0, 100, 50);
                        break;
                    }

                    //design
                    string addlInfo = line.Substring(symbolend + endicons[iconpos].Length);
                    if (addlInfo.Length > 0)
                    {
                        string[] addInfoArr = addlInfo.Split(';');
                        foreach (string addl in addInfoArr)
                        {
                            if (addl.Trim().StartsWith("#"))
                            {
                                ct.Fill(addl);
                            }
                            else
                            {
                                ct.AddCustomStyle(addl);
                            }
                        }
                    }


                    Console.WriteLine(key + " :  " + text + " : " + ct.GetType());
                    ct.Text(text);
                    component.Add(ct);
                    componentMap.Add(key, ct);
                }
            }


            foreach (var line in lines)
            {
                if (line.Contains("--"))
                {
                    // Links can be --XXX--> or -->

                    // split by -->
                    int index         = line.IndexOf("-->");
                    var toComponent   = line.Substring(index + 3);
                    var fromComponent = line.Substring(0, index);

                    var fromIdx = fromComponent.IndexOf("--");

                    var text = "";

                    if (fromIdx > 0 - 1)
                    {
                        //the text is blank
                        fromComponent = fromComponent.Substring(0, fromIdx);
                        var toIdx = line.IndexOf("-->");

                        text = line.Substring(fromIdx + 2, toIdx - fromComponent.Length - 2).Replace("\"", "");
                    }


                    var fc = componentMap[fromComponent];
                    var tc = componentMap[toComponent];
                    fc.To(tc, text);
                    // link fromComponent to toComponent
                    // Remove from parent list since it no longer is a parent but a chile ement

                    component.Remove(tc);
                }
            }

            return(component.ToArray());
        }