예제 #1
0
        public GraphArrow(string key, string idElement, XmlElement xmlElement, List <GraphElement> graphElements, List <Element> elements, SortedList <string, XmlElement> id_XmlElements, SortedList <string, GraphElement> id_GraphElements, SortedList <string, Variable> variables)
        {
            this.element = new Arrow();
            this.key     = key;
            Point position = new Point(-1, -1);

            List <Point> locations = new List <Point>();

            foreach (XmlElement nodo in xmlElement)
            {
                switch (nodo.Name)
                {
                case "position":
                    position = new Point(System.Convert.ToInt32(nodo.ChildNodes[0].InnerText), System.Convert.ToInt32(nodo.ChildNodes[1].InnerText));
                    break;

                case "previous":
                    if ((nodo.ChildNodes[0].Name == "elementId") && (nodo.ChildNodes[1].Name == "connectorId"))
                    {
                        GraphElement prevElement = null;
                        try
                        {
                            prevElement = id_GraphElements[nodo.ChildNodes[0].InnerText];
                        }
                        catch
                        {
                            prevElement = GraphDiagram.CreateGraphElement(id_XmlElements[nodo.ChildNodes[0].InnerText], graphElements, elements, id_XmlElements, id_GraphElements, variables);
                            graphElements.Add(prevElement);
                            id_GraphElements.Add(nodo.ChildNodes[0].InnerText, prevElement);
                            elements.Add(prevElement.Element);
                        }
                        this.initConnector = prevElement.GetConnector(System.Convert.ToInt32(nodo.ChildNodes[1].InnerText));
                        this.previous.Add(this.initConnector);
                        if (this.previous[0].Parent is GraphConditional)
                        {
                            if (this.GetOutLine(id_XmlElements[nodo.ChildNodes[0].InnerText], idElement) == ConditionalOut.True)
                            {
                                ((GraphConditional)this.previous[0].Parent).AddNext(this.initConnector, this, ConditionalOut.True);
                            }
                            else
                            {
                                ((GraphConditional)this.previous[0].Parent).AddNext(this.initConnector, this, ConditionalOut.False);
                            }
                        }
                        else
                        {
                            this.previous[0].Parent.AddNext(this.initConnector, this);
                        }
                    }
                    break;

                case "next":
                    if ((nodo.ChildNodes[0].Name == "elementId") && (nodo.ChildNodes[1].Name == "connectorId"))
                    {
                        GraphElement nextElement = null;
                        try
                        {
                            nextElement = (GraphElement)id_GraphElements[nodo.ChildNodes[0].InnerText];
                        }
                        catch
                        {
                            nextElement = GraphDiagram.CreateGraphElement(id_XmlElements[nodo.ChildNodes[0].InnerText], graphElements, elements, id_XmlElements, id_GraphElements, variables);
                            graphElements.Add(nextElement);
                            id_GraphElements.Add(nodo.ChildNodes[0].InnerText, nextElement);
                            elements.Add(nextElement.Element);
                        }
                        this.next = nextElement.GetConnector(System.Convert.ToInt32(nodo.ChildNodes[1].InnerText));
                        this.next.Parent.AddPrevious(this.next, this);
                    }
                    break;

                case "points":
                    foreach (XmlElement location in nodo.ChildNodes)
                    {
                        if ((location.ChildNodes[0].Name == "x") && (location.ChildNodes[1].Name == "y"))
                        {
                            locations.Add(new Point(System.Convert.ToInt32(location.ChildNodes[0].InnerText), System.Convert.ToInt32(location.ChildNodes[1].InnerText)));
                        }
                    }
                    break;

                default:
                    throw new GraphException("Error al crear GraphStart");
                }
            }
            CreateArrowSurface(locations);
            this.Center = position;
        }