/// <summary> /// Determine the worst violation for an element, against the tally of the worst and the current /// </summary> /// <param name="CurrentViolation"></param> /// <returns></returns> public MM_AlarmViolation_Type WorstViolation(MM_AlarmViolation_Type CurrentViolation) { MM_AlarmViolation_Type CurWorst = WorstViolationOverall; if (Data_Integration.Permissions.OTS == true && this is MM_Bus && this.Substation != null) //r-rtst { return(this.Substation.WorstViolation(CurrentViolation)); //r-rtst } if (CurrentViolation == null) { return(WorstViolationOverall); } else if (CurWorst == null) { return(CurrentViolation); } else if (CurWorst.Priority < CurrentViolation.Priority) { return(CurWorst); } else { return(CurrentViolation); } }
/// <summary> /// Determine the appropriate display parameter for the substation /// </summary> /// <param name="CallingObject">The calling object</param> /// <param name="ShownViolations">The shown violations</param> public MM_DisplayParameter SubstationDisplay(Dictionary <MM_AlarmViolation, ListViewItem> ShownViolations, Object CallingObject) { //TODO: Update this to include energization state MM_AlarmViolation_Type WorstViol = this.WorstVisibleViolation(ShownViolations, CallingObject); if (WorstViol == null) { return(MM_Repository.SubstationDisplay); } else { return(WorstViol); } }
/// <summary> /// Update with our new violation viewer, and set everything up. /// </summary> /// <param name="ViolViewer">The violation viewer</param> public void SetViolationViews(MM_Violation_Viewer ViolViewer) { this.violView = ViolViewer; foreach (ListViewItem l in this.lvSearch.Items) { MM_Element Elem = l.Tag as MM_Element; //If we have a violation, let's add it in. MM_AlarmViolation_Type WorstViol = Elem.WorstVisibleViolation(violView.ShownViolations, this.Parent); if (WorstViol != null) { l.ImageIndex = WorstViol.ViolationIndex; } } }
/// <summary> /// Determine the appropriate display parameter for the line /// </summary> public MM_DisplayParameter LineDisplay(Dictionary <MM_AlarmViolation, ListViewItem> ShownViolations, Object CallingObject, bool Blink) { if (!Blink || ShownViolations == null) { return(LineEnergizationState); } MM_AlarmViolation_Type WorstViol = this.WorstVisibleViolation(ShownViolations, CallingObject); if (WorstViol == null) { return(LineEnergizationState); } return(WorstViol); }
private void DrawVisibleViolations() { foreach (var violation in _violationViewer.ShownViolations) { var violationKey = violation.Key; var violationValue = violation.Value; MM_AlarmViolation_Type worstVisibleViolation = null; try { worstVisibleViolation = violationKey.SubstationOrLine.WorstVisibleViolation(_violationViewer.ShownViolations, null); if (worstVisibleViolation == null) { continue; } } catch (Exception exp) { continue; } var brush = Surface.Brushes.GetBrush(worstVisibleViolation.ForeColor); float violationWidth = worstVisibleViolation.Width; if (violationKey.SubstationOrLine is MM_Line) { var line = violationKey.SubstationOrLine as MM_Line; var lineStart = line.Coordinates.First(); var lineEnd = line.Coordinates.Last(); var pixelStart = ConvertPoint(lineStart); var pixelEnd = ConvertPoint(lineEnd); _target.AntialiasMode = AntialiasMode.PerPrimitive; _target.DrawLine(pixelStart, pixelEnd, brush, violationWidth); } else if (violationKey.SubstationOrLine is MM_Substation) { var station = violationKey.SubstationOrLine as MM_Substation; var center = ConvertPoint(station.LngLat); _target.AntialiasMode = AntialiasMode.Aliased; _target.FillRectangle(new RawRectangleF(center.X - violationWidth, center.Y - violationWidth, center.X + violationWidth, center.Y + violationWidth), brush); } } }
/// <summary> /// Handle the row post-paint, in order to show violations when they occur. /// </summary> /// <param name="e"></param> protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e) { try { MM_Element ThisElem = (Rows[e.RowIndex].Cells["TEID"].Value as MM_Element); if (ThisElem == null) { return; } MM_AlarmViolation_Type ViolType = ThisElem.WorstVisibleViolation(violView.ShownViolations, this.Parent); if (ViolType != null) { e.Graphics.DrawImage(MM_Repository.ViolationImages.Images[ViolType.ViolationIndex], new Rectangle(e.RowBounds.Location, new Size(this.RowHeadersWidth, e.RowBounds.Height))); } else if (ThisElem.FindNotes().Length > 0) { e.Graphics.DrawImage(MM_Repository.ViolationImages.Images["Note"], new Rectangle(e.RowBounds.Location, new Size(this.RowHeadersWidth, e.RowBounds.Height))); } base.OnRowPostPaint(e); } catch (Exception) { } }
/// <summary> /// Add a value to our elements /// </summary> /// <param name="Title"></param> /// <param name="OutObj"></param> /// <param name="Nodes"></param> /// <param name="OutViolation"></param> private TreeNode AddValue(String Title, Object OutObj, TreeNodeCollection Nodes, out MM_AlarmViolation_Type OutViolation) { TreeNode NewNode; OutViolation = null; if (OutObj == null) { return(null); } else if (OutObj is Point) { NewNode = Nodes.Add(Title); NewNode.Nodes.Add("Latitude: " + ((PointF)OutObj).X); NewNode.Nodes.Add("Longitude: " + ((PointF)OutObj).Y); } else if (OutObj is MM_Substation) { NewNode = Nodes.Add(Title + ": " + (OutObj as MM_Substation).DisplayName()); } else if (OutObj is MM_Element) { NewNode = Nodes.Add(Title + ": " + (OutObj as MM_Element).Name); } else if (OutObj is MM_DisplayParameter) { NewNode = Nodes.Add(Title + ": " + (OutObj as MM_DisplayParameter).Name); } else if (OutObj is Single[]) { NewNode = Nodes.Add(Title); Single[] TSystemWiderse = (Single[])OutObj; String[] Descriptor = new string[TSystemWiderse.Length]; if (TSystemWiderse.Length == 2) { Descriptor[0] = "From: "; Descriptor[1] = "To: "; } else if (TSystemWiderse.Length == 3) { Descriptor[0] = "Norm: "; Descriptor[1] = "2 Hour: "; Descriptor[2] = "15 Min: "; } else { for (int a = 0; a < TSystemWiderse.Length; a++) { Descriptor[a] = a.ToString("#,##0") + ": "; } } for (int a = 0; a < TSystemWiderse.Length; a++) { NewNode.Nodes.Add(Descriptor[a] + TSystemWiderse[a].ToString()); } } else if (OutObj is IEnumerable && (OutObj is String == false)) { NewNode = Nodes.Add(Title); MM_AlarmViolation_Type ThisViol = null; foreach (Object obj in (IEnumerable)OutObj) { AddValue(GetName(obj), obj, NewNode.Nodes, out ThisViol); OutViolation = MM_AlarmViolation_Type.WorstViolation(ThisViol, OutViolation); } if (OutViolation != null) { NewNode.Text = "[" + OutViolation.Acronym + "] " + NewNode.Text; NewNode.ForeColor = OutViolation.ForeColor; } } else { NewNode = Nodes.Add(Title + ": " + OutObj.ToString()); } NewNode.Tag = OutObj; if (OutObj is MM_Element) { MM_AlarmViolation_Type WorstViol = (OutObj as MM_Element).WorstViolationOverall; if (WorstViol != null) { NewNode.Text = "[" + WorstViol.Acronym + "] " + NewNode.Text; NewNode.ForeColor = WorstViol.ForeColor; OutViolation = MM_AlarmViolation_Type.WorstViolation(OutViolation, WorstViol); } if ((OutObj as MM_Element).FindNotes().Length > 0) { NewNode.NodeFont = new Font(NewNode.NodeFont, FontStyle.Italic); } } return(NewNode); }
private bool IsVisible(SubstationProxy proxy, int zoomLevel) { if (proxy.Substation == null) { return(false); } var substation = proxy.Substation; bool isInternal = substation.IsInternal; if (MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.HideExternalElements && !isInternal) { return(false); } if (proxy.Substation.KVLevels.Count == 0) { return(false); } var maxKv = proxy.Substation.KVLevels.OrderByDescending(kv => kv.Nominal).FirstOrDefault(); if (maxKv == null) { return(false); } // if (maxKv.StationNames <= zoomLevel) // return true; MM_AlarmViolation_Type WorstViolation = null; if (MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.Units && substation.HasUnits) { return(true); } if (MM_Repository.SubstationDisplay.ShowAutoTransformersOut && substation.HasOutagedAutoTransformer) { return(true); } if (MM_Repository.SubstationDisplay.ShowFrequencyControl && substation.FrequencyControlStatus != MM_Substation.enumFrequencyControlStatus.None) { return(true); } if (((WorstViolation = substation.WorstVisibleViolation(_violationViewer.ShownViolations, Surface)) != null) && (WorstViolation.NetworkMap_Substation != MM_AlarmViolation_Type.DisplayModeEnum.Never)) { return(true); } if (false && MM_Repository.SubstationDisplay.ShowSubsOnLines && (zoomLevel >= MM_Repository.OverallDisplay.StationNames)) // show substations connected to visible lines. { return(true); } if (MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.HideNonBlackstartElements && substation.IsBlackstart == false) { return(false); } if (MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.HideNonOperatorElements && Array.IndexOf(substation.Operators, MM_Repository.OverallDisplay.DisplayCompany) == -1) { return(false); } if (MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.None) { return(false); } if ((MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.Capacitors || MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.CapacitorsAvailable || MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.CapacitorsOnline) && !substation.ElemTypes.Contains(MM_Repository.FindElementType("Capacitor"))) { return(false); } if ((MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.Reactors || MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.ReactorsAvailable || MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.ReactorsOnline) && !substation.ElemTypes.Contains(MM_Repository.FindElementType("Reactor"))) { return(false); } if (MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.Loads && !substation.ElemTypes.Contains(MM_Repository.FindElementType("Load"))) { return(false); } if (MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.LAARs && !substation.ElemTypes.Contains(MM_Repository.FindElementType("LAAR"))) { return(false); } if (MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.Transformers && !substation.ElemTypes.Contains(MM_Repository.FindElementType("Transformer"))) { return(false); } if (MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.Units && !substation.ElemTypes.Contains(MM_Repository.FindElementType("Unit"))) { return(false); } if (MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.CapacitorsAvailable) { foreach (MM_ShuntCompensator Shunt in substation.ShuntCompensators) { if (Shunt.ElemType.Name == "Capacitor" && Shunt.Open) { return(true); } } } else if (MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.CapacitorsOnline) { foreach (MM_ShuntCompensator Shunt in substation.ShuntCompensators) { if (Shunt.ElemType.Name == "Capacitor" && !Shunt.Open) { return(true); } } } else if (MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.ReactorsAvailable) { foreach (MM_ShuntCompensator Shunt in substation.ShuntCompensators) { if (Shunt.ElemType.Name == "Reactor" && Shunt.Open) { return(true); } } } else if (MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.ReactorsOnline) { foreach (MM_ShuntCompensator Shunt in substation.ShuntCompensators) { if (Shunt.ElemType.Name == "Reactor" && !Shunt.Open) { return(true); } } } else if (MM_Repository.SubstationDisplay.ShowSubstations == MM_Substation_Display.SubstationViewEnum.StaticVarCompensators) { return(substation.ElemTypes.Contains(MM_Repository.FindElementType("StaticVarCompensator"))); } return(true); }
/// <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 { } }
/// <summary> /// Determine the worst violation type within the substation /// </summary> public MM_AlarmViolation_Type WorstVisibleViolation(Dictionary <MM_AlarmViolation, ListViewItem> ShownViolations, Object CallingForm) { MM_AlarmViolation_Type WorstViolation = null; try { if (CallingForm is MM_Mini_Map) { foreach (MM_AlarmViolation Viol in Violations.Values) { if ((Viol.Type.MiniMap == MM_AlarmViolation_Type.DisplayModeEnum.Always) || ((Viol.Type.MiniMap == MM_AlarmViolation_Type.DisplayModeEnum.WhenSelected) && (ShownViolations.ContainsKey(Viol)))) { if ((WorstViolation == null) || (Viol.Type.ViolationIndex < WorstViolation.ViolationIndex)) { WorstViolation = Viol.Type; } } } } else if (this is MM_Line) { foreach (MM_AlarmViolation Viol in Violations.Values) { if ((Viol.Type.NetworkMap_Line == MM_AlarmViolation_Type.DisplayModeEnum.Always) || ((Viol.Type.NetworkMap_Line == MM_AlarmViolation_Type.DisplayModeEnum.WhenSelected) && (ShownViolations.ContainsKey(Viol)))) { if ((WorstViolation == null) || (Viol.Type.ViolationIndex < WorstViolation.ViolationIndex)) { WorstViolation = Viol.Type; } } } foreach (var contingency in Contingencies) { foreach (MM_AlarmViolation Viol in contingency.Violations.Values) { if ((Viol.Type.NetworkMap_Line == MM_AlarmViolation_Type.DisplayModeEnum.Always) || ((Viol.Type.NetworkMap_Line == MM_AlarmViolation_Type.DisplayModeEnum.WhenSelected) && (ShownViolations.ContainsKey(Viol)))) { if ((WorstViolation == null || Viol.Type.ViolationIndex < WorstViolation.ViolationIndex) && (Viol.ViolatedElement == this || Viol.Contingency != null)) { WorstViolation = Viol.Type; } } } } } else if (this is MM_Substation) { foreach (MM_AlarmViolation Viol in Violations.Values) { if ((Viol.Type.NetworkMap_Substation == MM_AlarmViolation_Type.DisplayModeEnum.Always) || ((Viol.Type.NetworkMap_Substation == MM_AlarmViolation_Type.DisplayModeEnum.WhenSelected) && (ShownViolations.ContainsKey(Viol)))) { if ((WorstViolation == null) || (Viol.Type.ViolationIndex < WorstViolation.ViolationIndex)) { WorstViolation = Viol.Type; } } } } else if (this is MM_Node && Violations.Count == 0 && ShownViolations.Count > 0) { foreach (MM_AlarmViolation Viol in ShownViolations.Keys) { if (Viol.ViolatedElement.ElemType.Name == "BusbarSection" && Viol.ViolatedElement.Substation.Equals(this.Substation) && Viol.ViolatedElement.Name.Equals(this.Name)) { if ((Viol.Type.OneLineElement == MM_AlarmViolation_Type.DisplayModeEnum.Always) || ((Viol.Type.OneLineElement == MM_AlarmViolation_Type.DisplayModeEnum.WhenSelected))) { if ((WorstViolation == null) || (Viol.Type.ViolationIndex < WorstViolation.ViolationIndex)) { WorstViolation = Viol.Type; } } } } } else { foreach (MM_AlarmViolation Viol in Violations.Values) { if ((Viol.Type.OneLineElement == MM_AlarmViolation_Type.DisplayModeEnum.Always) || ((Viol.Type.OneLineElement == MM_AlarmViolation_Type.DisplayModeEnum.WhenSelected) && (ShownViolations.ContainsKey(Viol)))) { if ((WorstViolation == null) || (Viol.Type.ViolationIndex < WorstViolation.ViolationIndex)) { WorstViolation = Viol.Type; } } } } } catch (Exception ex) { MM_System_Interfaces.LogError(ex); } return(WorstViolation); }