Exemplo n.º 1
0
        /// <summary>
        /// Load our one-line data
        /// </summary>
        /// <param name="ElementName"></param>
        /// <param name="ElementType"></param>
        /// <returns></returns>
        public MM_OneLine_Data LoadOneLineData(string ElementName, MM_OneLine_Data.enumElementType ElementType)
        {
            User.LastReceivedMessage = DateTime.Now;
            MM_OneLine_Data OutData = new MM_OneLine_Data();

            OutData.ElementName = ElementName;
            OutData.ElementType = ElementType;
            if (ElementType == MM_OneLine_Data.enumElementType.BreakerToBreaker)
            {
                ElementName = "__" + ElementName;
            }
            else if (ElementType == MM_OneLine_Data.enumElementType.CompanyWide)
            {
                ElementName = "___" + ElementName;
            }

            String TargetFilename = Path.Combine(Settings.Default.OneLineDirectory, ElementName + ".MM_OneLine");

            if (File.Exists(TargetFilename))
            {
                OutData.OneLineXml = File.ReadAllText(TargetFilename);
            }
            return(OutData);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load a one-line into memory
        /// </summary>
        /// <param name="BaseElement">The base element to be highlighting</param>
        /// <param name="HighlightElem">The element to highlight (e.g., line from the other substation)</param>
        public void LoadOneLine(MM_Element BaseElement, MM_Element HighlightElem)
        {
            OneLineIsLoading = true;
            if (!cmbSubstation.Items.Contains(BaseElement))
            {
                cmbSubstation.Items.Add(BaseElement.Name);
            }
            cmbSubstation.SelectedIndex = cmbSubstation.Items.IndexOf(BaseElement.Name);

            //First, clear all of our elements
            ShutDownQuery();
            DisplayElements.Clear();
            DisplayNodes.Clear();
            UnlinkedElements.Clear();
            Descriptors.Clear();
            SecondaryDescriptors.Clear();
            pnlElements.Controls.Clear();
            DisplayComponents.Clear();
            this.BaseElement = BaseElement;
            ElementsByTEID.Clear();

            //Now, load our one-line
            MM_OneLine_Data OLData = MM_Server_Interface.LoadOneLine(BaseElement);

            if (OLData.OneLineXml == null)
            {
                MessageBox.Show("The one line for " + BaseElement.ToString() + " could not be found.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Now, parse our elements
            XmlDocument xDoc = new XmlDocument();

            xDoc.LoadXml(OLData.OneLineXml);


            //Load in our elements
            if (xDoc.DocumentElement["Elements"] != null)
            {
                foreach (XmlElement xElem in xDoc.DocumentElement["Elements"])
                {
                    MM_OneLine_Element Elem = new MM_OneLine_Element(xElem);
                    if (Elem.Descriptor != null)
                    {
                        DisplayComponents.Add(Elem.Descriptor);
                        Descriptors.Add(Elem.BaseElement, Elem.Descriptor);
                    }
                    if (Elem.SecondaryDescriptor != null)
                    {
                        DisplayComponents.Add(Elem.SecondaryDescriptor);
                        SecondaryDescriptors.Add(Elem.BaseElement, Elem.SecondaryDescriptor);
                    }
                    DisplayComponents.Add(Elem);
                    ElementsByTEID.Add(Elem.BaseElement.TEID, Elem);
                    if (Elem.BaseElement is MM_Tie)
                    {
                        ElementsByTEID.Add(((MM_Tie)Elem.BaseElement).AssociatedLine.TEID, Elem);
                    }
                    DisplayElements.Add(Elem.BaseElement, Elem);
                    Elem.BaseElement.ValuesChanged += ElemValueChange;
                }
            }

            //Load in our nodes
            if (xDoc.DocumentElement["Nodes"] != null)
            {
                foreach (XmlElement xElem in xDoc.DocumentElement["Nodes"])
                {
                    MM_OneLine_Node Node = new MM_OneLine_Node(xElem, ElementsByTEID);
                    if (Node.Descriptor != null)
                    {
                        DisplayComponents.Add(Node.Descriptor);
                        Descriptors.Add(Node.BaseElement, Node.Descriptor);
                    }
                    if (Node.SecondaryDescriptor != null)
                    {
                        SecondaryDescriptors.Add(Node.BaseElement, Node.SecondaryDescriptor);
                        DisplayComponents.Add(Node.SecondaryDescriptor);
                    }
                    ElementsByTEID.Add(Node.BaseElement.TEID, Node);
                    DisplayComponents.Add(Node);
                    DisplayNodes.Add(Node.BaseElement, Node);
                    Node.BaseElement.ValuesChanged += ElemValueChange;
                    foreach (MM_OneLine_Node[] Pokes in Node.NodeTargets.Values)
                    {
                        foreach (MM_OneLine_Node Poke in Pokes)
                        {
                            DisplayComponents.Add(Poke);
                            if (Poke.ElemType == MM_OneLine_Element.enumElemTypes.PricingVector || Poke.IsJumper)
                            {
                                UnlinkedElements.Add(Poke);
                            }
                            if (Poke.Descriptor != null)
                            {
                                DisplayComponents.Add(Poke.Descriptor);
                                Descriptors.Add(Poke.BaseElement, Poke.Descriptor);
                            }
                            if (Poke.SecondaryDescriptor != null)
                            {
                                SecondaryDescriptors.Add(Poke.BaseElement, Poke.SecondaryDescriptor);
                                DisplayComponents.Add(Poke.SecondaryDescriptor);
                            }
                        }
                    }
                }
            }

            if (xDoc.DocumentElement["Unlinked_Elements"] != null)
            {
                foreach (XmlElement xElem in xDoc.DocumentElement["Unlinked_Elements"].ChildNodes)
                {
                    MM_OneLine_Element UnlinkedElement = new MM_OneLine_Element(xElem);
                    DisplayComponents.Add(UnlinkedElement);
                    UnlinkedElements.Add(UnlinkedElement);
                }
            }
            HighlightElement(HighlightElem);

            //Track our positions for our scroller, and create a new pseudo-element in the bottom right to make scrolling work
            MaxX = 0;
            MaxY = 0;

            foreach (MM_OneLine_Element Elem in DisplayComponents)
            {
                MaxX = Math.Max(MaxX, Elem.Bounds.Right);
                MaxY = Math.Max(MaxY, Elem.Bounds.Bottom);
            }

            HighlightElement(HighlightElem);

            //If we have an element, let's show it
            UpdateZoom();
            if (HighlightedElement != null)
            {
                using (Control ctl = new Control())
                {
                    Rectangle TargetBounds = HighlightedElement.Bounds;
                    if (HighlightedElement.Descriptor != null)
                    {
                        TargetBounds = Rectangle.Union(TargetBounds, HighlightedElement.Descriptor.Bounds);
                    }
                    if (HighlightedElement.SecondaryDescriptor != null)
                    {
                        TargetBounds = Rectangle.Union(TargetBounds, HighlightedElement.SecondaryDescriptor.Bounds);
                    }
                    ctl.Bounds = TargetBounds;
                    pnlElements.Controls.Add(ctl);
                    pnlElements.ScrollControlIntoView(ctl);
                    pnlElements.Controls.Remove(ctl);
                }
            }


            if (OneLineLoadCompleted != null)
            {
                OneLineLoadCompleted(this, EventArgs.Empty);
            }
            tmrUpdate.Enabled = true;
            pnlElements.Refresh();
            OneLineIsLoading = false;
        }