Exemple #1
0
        /// <summary>
        /// Update our bus data
        /// </summary>
        /// <param name="BusData"></param>
        public void UpdateBusData(MM_Bus_Data[] BusData)
        {
            MM_Bus     FoundBus;
            MM_Element FoundElem;

            foreach (MM_Bus_Data InBus in BusData)
            {
                if (InBus != null)
                {
                    if (!MM_Repository.BusNumbers.TryGetValue(InBus.Bus_Num, out FoundBus))
                    {
                        MM_Repository.BusNumbers.Add(InBus.Bus_Num, FoundBus = new MM_Bus(InBus.Bus_Num));
                    }

                    MM_Repository.TEIDs.TryGetValue(InBus.TEID_Nd, out FoundElem);
                    MM_Server_Interface.UpdateBusData(InBus, FoundBus, FoundElem, true);
                }
            }
            if (BusData.Length > 0)
            {
                MM_Server_Interface.UpdateTimestamp(typeof(MM_Bus_Data));
            }
        }
        /// <summary>
        /// Determine our bus associated with this node
        /// </summary>
        public void DetermineAssociatedBus()
        {
            MM_Bus FoundBus = null;

            if (BaseElement.NearBus != null)
            {
                FoundBus = BaseElement.NearBus;
            }
            else
            {
                int MaxBuses = 0;
                Dictionary <MM_Bus, int> FoundBuses = new Dictionary <MM_Bus, int>();
                foreach (MM_OneLine_Element Elem in NodeTargets.Keys)
                {
                    bool Include = true;
                    if (Elem.BaseElement is MM_Line && ((MM_Line)Elem.BaseElement).MVAFlow <= MM_Repository.OverallDisplay.EnergizationThreshold)
                    {
                        Include = false;
                    }
                    else if (Elem.BaseElement is MM_Breaker_Switch && ((MM_Breaker_Switch)Elem.BaseElement).BreakerState == MM_Breaker_Switch.BreakerStateEnum.Open)
                    {
                        Include = false;
                    }
                    if (Include)
                    {
                        if (Elem.BaseElement.NearBus != null && !Elem.BaseElement.NearBus.Dead)
                        {
                            if (FoundBuses.ContainsKey(Elem.BaseElement.NearBus))
                            {
                                FoundBuses[Elem.BaseElement.NearBus]++;
                            }
                            else
                            {
                                FoundBuses.Add(Elem.BaseElement.NearBus, 1);
                            }
                        }
                        if (Elem.BaseElement.FarBus != null && !Elem.BaseElement.FarBus.Dead)
                        {
                            if (FoundBuses.ContainsKey(Elem.BaseElement.FarBus))
                            {
                                FoundBuses[Elem.BaseElement.FarBus]++;
                            }
                            else
                            {
                                FoundBuses.Add(Elem.BaseElement.FarBus, 1);
                            }
                        }
                    }

                    foreach (KeyValuePair <MM_Bus, int> kvp in FoundBuses)
                    {
                        if (kvp.Value > MaxBuses)
                        {
                            FoundBus = kvp.Key;
                            MaxBuses = kvp.Value;
                        }
                    }
                }
            }

            ((MM_Node)BaseElement).AssociatedBus = FoundBus;
        }
Exemple #3
0
        /// <summary>
        /// Every second, update our labels
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tmrUpdateLabels_Tick(object sender, EventArgs e)
        {
            try
            {
                //Start the timer if needed
                if (!tmrUpdate.Enabled)
                {
                    tmrUpdate.Enabled = true;
                }
                if (BreakerSwitch == null)
                {
                    return;
                }
                MM_Bus NearBus = BreakerSwitch.NearBus;
                MM_Bus FarBus  = BreakerSwitch.FarBus;

                //Determine the state of our system
                if (float.IsNaN(FreqI[0]) && float.IsNaN(FreqZ[0]))
                {
                    State = enumSynchroscopeState.DataMissingBoth;
                }
                else if (float.IsNaN(FreqI[0]) || FreqI[0] == 0)
                {
                    State = enumSynchroscopeState.DataMissingNear;
                }
                else if (float.IsNaN(FreqZ[0]) || FreqZ[0] == 0)
                {
                    State = enumSynchroscopeState.DataMissingFar;
                }
                else if (NearBus == null || FarBus == null)
                {
                    State = enumSynchroscopeState.DifferentIsland;
                }
                else if (NearBus != null && FarBus != null && NearBus.IslandNumber != FarBus.IslandNumber)
                {
                    State = enumSynchroscopeState.DifferentIsland;
                }
                else if (NearBus != null && FarBus != null && NearBus.IslandNumber == FarBus.IslandNumber)
                {
                    State = (!BreakerSwitch.Open) ? enumSynchroscopeState.SameIsland : enumSynchroscopeState.BreakerOpenToClose;
                }
                else
                {
                    State = enumSynchroscopeState.Unknown;
                }

                //Update the labels
                LabelStation.Text = BreakerSwitch.Substation.Name;
                LabelCBID.Text    = BreakerSwitch.Name;

                if (State == enumSynchroscopeState.DataMissingNear || State == enumSynchroscopeState.DataMissingBoth)
                {
                    LabelFreqI.Text = "--";
                    LabelKVI.Text   = "--";
                }
                else
                {
                    if (State == enumSynchroscopeState.DifferentIsland)
                    {
                        LabelFreqI.Text = FreqI[0].ToString("0.000°");
                        LabelKVI.Text   = GeneratorBus != null?GeneratorBus.Estimated_kV.ToString("0.00") : NearBus == null ? VoltI[Tmr].ToString("0.00") : NearBus.Estimated_kV.ToString("0.00");
                    }
                    else if (State == enumSynchroscopeState.SameIsland)
                    {
                        LabelFreqI.Text = FreqZ[0].ToString("0.000°");
                        LabelKVI.Text   = (NearBus == null || NearBus.Estimated_kV <= 1) ? VoltI[Tmr].ToString("0.00") : NearBus.Estimated_kV.ToString("0.00");
                    }
                }

                if (State == enumSynchroscopeState.DataMissingFar || State == enumSynchroscopeState.DataMissingBoth)
                {
                    LabelFreqZ.Text = "--";
                    LabelKVZ.Text   = "--";
                }
                else
                {
                    LabelFreqZ.Text = FreqZ[0].ToString("0.000°");
                    LabelKVZ.Text   = (FarBus == null || FarBus.Estimated_kV <= 1) ? VoltZ[Tmr].ToString("0.00") : FarBus.Estimated_kV.ToString("0.00");
                }

                if (State == enumSynchroscopeState.SameIsland || State == enumSynchroscopeState.DifferentIsland)
                {
                    LabelPhaseDiff.Text = (NearBus != null && FarBus != null) ? (NearBus.Island.Frequency - FarBus.Island.Frequency).ToString("0.000°") : (FreqI[0] - FreqZ[0]).ToString("0.000°");
                }
                else
                {
                    LabelPhaseDiff.Text = "--";
                }

                LabelCB.Refresh();
            }
            catch { }
        }
Exemple #4
0
 /// <summary>
 /// Assign our synchroscope
 /// </summary>
 /// <param name="GeneratorBus"></param>
 /// <param name="GeneratorIsland"></param>
 /// <param name="TimeReference"></param>
 public void AssignSynchroscope(MM_Bus GeneratorBus, MM_Island GeneratorIsland, DateTime TimeReference)
 {
     AssignSynchroscope(GeneratorBus, GeneratorIsland);
 }
Exemple #5
0
 /// <summary>
 /// Assign our synchroscope
 /// </summary>
 /// <param name="GeneratorBus"></param>
 /// <param name="GeneratorIsland"></param>
 public void AssignSynchroscope(MM_Bus GeneratorBus, MM_Island GeneratorIsland)
 {
     this.GeneratorBus    = GeneratorBus;
     this.GeneratorIsland = GeneratorIsland;
 }
Exemple #6
0
        /// <summary>
        /// Handle our panel being painted
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PanelPaint(object sender, PaintEventArgs e)
        {
            try
            {
                if (Data_Integration.SimulatorStatus != MM_Simulation_Time.enumSimulationStatus.Running && (DateTime.Now.Second % 2) == 0)
                {
                    e.Graphics.Clear(Color.FromArgb(50, 0, 0));
                }

                //Determine our zoom
                e.Graphics.ScaleTransform(ZoomLevel, ZoomLevel);

                //Draw our header bar
                Rectangle HeaderRect = new Rectangle(pnlElements.DisplayRectangle.Left, pnlElements.DisplayRectangle.Top, pnlElements.DisplayRectangle.Width, 40);
                if (HeaderRect.IntersectsWith(e.ClipRectangle))
                {
                    MM_OneLine_Element.DrawHeader(e.Graphics, HeaderRect, BaseElement);
                }

                e.Graphics.TranslateTransform(pnlElements.AutoScrollPosition.X, pnlElements.AutoScrollPosition.Y);

                //Draw our arrows
                if (arrowsToolStripMenuItem.Checked)
                {
                    foreach (MM_OneLine_Element Elem in DisplayElements.Values)
                    {
                        if (Elem.DescriptorArrow || (Elem.Descriptor != null && Elem.Descriptor.DescriptorArrow))
                        {
                            if (Elem.ParentElement != null)
                            {
                                MM_OneLine_Element.DrawArrow(e.Graphics, Elem.ParentElement.Bounds, Elem.Bounds);
                            }
                            if (Elem.Descriptor != null)
                            {
                                MM_OneLine_Element.DrawArrow(e.Graphics, Elem.Bounds, Elem.Descriptor.Bounds);
                            }
                            if (Elem.SecondaryDescriptor != null)
                            {
                                MM_OneLine_Element.DrawArrow(e.Graphics, Elem.Bounds, Elem.SecondaryDescriptor.Bounds);
                            }
                        }
                    }
                }

                //Write out our node paths
                foreach (MM_OneLine_Node Node in DisplayNodes.Values)
                {
                    if (Node.NodePaths != null)
                    {
                        Node.DetermineAssociatedBus();
                        if (mnuNodeToElementLines.Checked)
                        {
                            foreach (KeyValuePair <MM_OneLine_Element, GraphicsPath> gpNode in Node.NodePaths)
                            {
                                MM_AlarmViolation_Type WorstViol = null;
                                if (IsFlashing && MM_Repository.OverallDisplay.NodeToElementViolations)
                                {
                                    foreach (MM_AlarmViolation Viol in gpNode.Key.BaseElement.Violations.Values)
                                    {
                                        if (WorstViol == null || Viol.Type.Priority < WorstViol.Priority)
                                        {
                                            WorstViol = Viol.Type;
                                        }
                                    }
                                    MM_Bus NearBus = gpNode.Key.BaseElement.NearBus;
                                    MM_Bus FarBus  = gpNode.Key.BaseElement.FarBus;
                                    if (NearBus != null)
                                    {
                                        foreach (MM_AlarmViolation Viol in NearBus.Violations.Values)
                                        {
                                            if (WorstViol == null || Viol.Type.Priority < WorstViol.Priority)
                                            {
                                                WorstViol = Viol.Type;
                                            }
                                        }
                                    }
                                    if (FarBus != null)
                                    {
                                        foreach (MM_AlarmViolation Viol in FarBus.Violations.Values)
                                        {
                                            if (WorstViol == null || Viol.Type.Priority < WorstViol.Priority)
                                            {
                                                WorstViol = Viol.Type;
                                            }
                                        }
                                    }
                                }
                                Color DrawColor = WorstViol == null ? Node.KVLevel.Energized.ForeColor : WorstViol.ForeColor;
                                using (Pen DrawPen = new Pen(DrawColor))
                                    e.Graphics.DrawPath(DrawPen, gpNode.Value);
                            }
                        }
                    }
                }

                //Write out our elements, nodes, and unlinked elements
                foreach (MM_OneLine_Element Elem in DisplayElements.Values)
                {
                    // if (e.ClipRectangle.IntersectsWith(Elem.Bounds))
                    Elem.PaintElement(e.Graphics, this, IsFlashing);
                }
                foreach (MM_OneLine_Node Node in DisplayNodes.Values)
                {
                    // if (e.ClipRectangle.IntersectsWith(Node.Bounds))
                    Node.PaintElement(e.Graphics, this, IsFlashing);
                }
                foreach (MM_OneLine_Element UnlinkedElem in UnlinkedElements)
                {
                    // if (e.ClipRectangle.IntersectsWith(UnlinkedElem.Bounds))
                    UnlinkedElem.PaintElement(e.Graphics, this, IsFlashing);
                }

                //Write out our descriptors and secondary descriptors
                foreach (MM_OneLine_Element Elem in Descriptors.Values)
                {
                    //  if (e.ClipRectangle.IntersectsWith(Elem.Bounds))
                    Elem.PaintElement(e.Graphics, this, IsFlashing);
                }
                foreach (MM_OneLine_Element Elem in SecondaryDescriptors.Values)
                {
                    //if (e.ClipRectangle.IntersectsWith(Elem.Bounds))
                    Elem.PaintElement(e.Graphics, this, IsFlashing);
                }

                //If we have a highlighted element, let's make it visible
                int HighlightRadius = 20;
                if (HighlightedElement != null)
                {
                    using (Pen HighlightPen = new Pen(Color.White, 3)
                    {
                        DashStyle = DashStyle.Custom, DashPattern = IsFlashing ? new float[] { 1, 2, 3 } : new float[] { 3, 2, 1 }
                    })
                        e.Graphics.DrawEllipse(HighlightPen, HighlightedElement.Bounds.Left - HighlightRadius, HighlightedElement.Bounds.Top - HighlightRadius, HighlightedElement.Bounds.Width + HighlightRadius + HighlightRadius, HighlightedElement.Bounds.Height + HighlightRadius + HighlightRadius);
                }

                //Highlight any elements with pending changes
                MM_OneLine_Element FoundElem;
                if (ValueChanges.Count > 0)
                {
                    using (Pen HighlightPen = new Pen(Color.White, 3))
                        foreach (MM_Element Elem in ValueChanges.Keys.ToArray())
                        {
                            if (DisplayElements.TryGetValue(Elem, out FoundElem))
                            {
                                e.Graphics.DrawRectangle(HighlightPen, FoundElem.Bounds.Left - HighlightRadius, FoundElem.Bounds.Top - HighlightRadius, FoundElem.Bounds.Width + HighlightRadius + HighlightRadius, FoundElem.Bounds.Height + HighlightRadius + HighlightRadius);
                                e.Graphics.DrawLine(HighlightPen, FoundElem.Bounds.Left - HighlightRadius, FoundElem.Bounds.Top - HighlightRadius, FoundElem.Bounds.Left, FoundElem.Bounds.Top);
                                e.Graphics.DrawLine(HighlightPen, FoundElem.Bounds.Right + HighlightRadius, FoundElem.Bounds.Top - HighlightRadius, FoundElem.Bounds.Right, FoundElem.Bounds.Top);
                                e.Graphics.DrawLine(HighlightPen, FoundElem.Bounds.Left - HighlightRadius, FoundElem.Bounds.Bottom + HighlightRadius, FoundElem.Bounds.Left, FoundElem.Bounds.Bottom);
                                e.Graphics.DrawLine(HighlightPen, FoundElem.Bounds.Right + HighlightRadius, FoundElem.Bounds.Bottom + HighlightRadius, FoundElem.Bounds.Right, FoundElem.Bounds.Bottom);
                            }
                        }
                }
                e.Graphics.TranslateTransform(-pnlElements.AutoScrollPosition.X, -pnlElements.AutoScrollPosition.Y);
            }
            catch
            {
            }
        }