/// <summary> /// Return the angle between this substation and another, in radians /// </summary> /// <param name="Substation">The other substation</param> /// <returns>Angle, in radians</returns> public float AngleTo(MM_Substation Substation) { float DeltaX = Substation.LngLat.X - LngLat.X; float DeltaY = Substation.LngLat.Y - LngLat.Y; return((float)Math.Atan2(DeltaY, DeltaX)); }
/// <summary> /// Return the number of lines connecting a substation /// </summary> /// <param name="Sub">The substation to check</param> /// <returns></returns> private int CountLines(MM_Substation Sub) { int Count = 0; foreach (MM_Line Line in MM_Repository.Lines.Values) { if (Line.ConnectedStations[0] == Sub || Line.ConnectedStations[1] == Sub) { Count++; } } return(Count); }
/// <summary> /// Produce a description for this line, based on the core station (e.g., Line X to [other station]) /// </summary> /// <param name="CoreStation"></param> /// <returns></returns> public string MenuDescription(MM_Substation CoreStation) { MM_Substation MVAFlowDir = MVAFlowDirection; if (IsSeriesCompensator) { return("SeriesCompensator " + this.Name + " (" + this.LinePercentageText + ")"); } else if (MVAFlowDir == null) { return(this.ElemType.Name + " " + this.Name + " with " + (this.Substation1 == CoreStation ? Substation2.LongName : Substation1.LongName) + " (" + this.LinePercentageText + ")"); } else { return(this.ElemType.Name + " " + this.Name + (MVAFlowDir == CoreStation ? " from " : " to ") + (this.Substation1 == CoreStation ? Substation2.LongName : Substation1.LongName) + " (" + this.LinePercentageText + ")"); } }
private void MoveOutside(MM_Substation Sub) { //Take our substation's lat/long, and find the closest state inflection point PointF ClosestPoint = PointF.Empty; float ClosestDistance = float.NaN; foreach (PointF PtToCheck in MM_Repository.Counties["STATE"].Coordinates) { if (float.IsNaN(ClosestDistance) || CalculateDistance(ConnectedStations[0].LngLat, PtToCheck) < ClosestDistance) { ClosestDistance = CalculateDistance(ConnectedStations[0].LngLat, PtToCheck); ClosestPoint = PtToCheck; } } //Now, move that substation to the opposite side of the state border Sub.LngLat = new PointF((2f * ClosestPoint.X) - ConnectedStations[0].LngLat.X, (2f * ClosestPoint.Y) - ConnectedStations[0].LngLat.Y); }
/// <summary> /// Return the distance between this substation and another, in miles /// </summary> /// <param name="Substation">The other substation</param> /// <returns>Distance, in miles.</returns> public float DistanceTo(MM_Substation Substation) { return(DistanceTo(Substation.LngLat)); }
/// <summary> /// Create a new element based on its definition /// </summary> /// <param name="xElem">The definition for the element</param> /// <param name="Prefix">The prefix for the element, if any</param> /// <param name="AddIfNew">Whether to add a new element to our master repository</param> /// <returns></returns> public static MM_Element CreateElement(XmlElement xElem, string Prefix, bool AddIfNew) { MM_Element OutElement = null; String ElemType; if (xElem.HasAttribute("ElemType")) { ElemType = String.IsNullOrEmpty(Prefix) ? xElem.Attributes["ElemType"].Value : xElem.HasAttribute(Prefix + ".ElemType") ? xElem.Attributes[Prefix + ".ElemType"].Value : Prefix; } else { ElemType = xElem.Name; } if (Prefix == "EPSMeter") { OutElement = new MM_EPSMeter(); OutElement.ElemType = MM_Repository.FindElementType(Prefix); } else if (xElem.HasAttribute("BaseElement.IsSeriesCompensator") && XmlConvert.ToBoolean(xElem.Attributes["BaseElement.IsSeriesCompensator"].Value)) { OutElement = new MM_Line(); } else if (ElemType == "Breaker" || ElemType == "Switch") { OutElement = new MM_Breaker_Switch(); } else if (ElemType == "DCTie") { OutElement = new MM_Tie(); } else if (ElemType == "Tie") { OutElement = new MM_Tie(); } else if (ElemType == "ElectricalBus") { OutElement = new MM_Electrical_Bus(); } else if (ElemType == "Line") { OutElement = new MM_Line(); } else if (ElemType == "Load" || ElemType.Equals("LaaR", StringComparison.CurrentCultureIgnoreCase)) { OutElement = new MM_Load(); } else if (ElemType == "Unit") { OutElement = new MM_Unit(); } else if (ElemType == "Capacitor" || ElemType == "Reactor") { OutElement = new MM_ShuntCompensator(); } else if (ElemType == "Transformer") { OutElement = new MM_Transformer(); } else if (ElemType == "TransformerWinding") { OutElement = new MM_TransformerWinding(); } else if (ElemType == "StaticVarCompensator") { OutElement = new MM_StaticVarCompensator(); } else if (ElemType == "Node") { OutElement = new MM_Node(); } else if (ElemType == "BusbarSection") { OutElement = new MM_Bus(); } else if (ElemType == "PricingVector") { OutElement = new MM_PricingVector(); ((MM_PricingVector)OutElement).EPSMeter = (MM_EPSMeter)CreateElement(xElem, "EPSMeter", false); } else if (ElemType == "EPSMeter") { OutElement = new MM_EPSMeter(); } else if (ElemType == "County" || ElemType == "State") { OutElement = new MM_Boundary(); } else if (ElemType == "Company") { OutElement = new MM_Company(); } else if (ElemType == "Flowgate") { OutElement = new MM_Flowgate(); } else if (ElemType == "Contingency") { OutElement = new MM_Contingency(); } else if (ElemType == "Substation") { OutElement = new MM_Substation(); } else if (ElemType == "VoltageLevel") { //OutElement = new MM_KVLevel(); } else { OutElement = new MM_Element(); } OutElement.ElemType = MM_Repository.FindElementType(ElemType); //Now, pull in our attributes foreach (XmlAttribute xAttr in xElem.Attributes) { if ((String.IsNullOrEmpty(Prefix) && xAttr.Name.IndexOf('.') == -1)) { MM_Serializable.AssignValue(xAttr.Name, xAttr.Value, OutElement, AddIfNew); } else if (!String.IsNullOrEmpty(Prefix) && xAttr.Name.StartsWith(Prefix + ".")) { MM_Serializable.AssignValue(xAttr.Name.Substring(xAttr.Name.IndexOf('.') + 1), xAttr.Value, OutElement, AddIfNew); } } if (xElem.HasAttribute("Contingencies")) { String[] splStr = xElem.Attributes["Contingencies"].Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (OutElement.Contingencies == null || OutElement.Contingencies.Count == 0) { OutElement.Contingencies = new List <MM_Contingency>(); } else { OutElement.Contingencies = OutElement.Contingencies.ToList(); } foreach (string str in splStr) { MM_Contingency con = null; MM_Repository.Contingencies.TryGetValue(str, out con); if (con != null && !OutElement.Contingencies.Any(c => c.Name == con.Name)) { OutElement.Contingencies.Add(con); } } } //If we're a transformer, pull in our windings if (ElemType == "Transformer") { List <MM_TransformerWinding> Windings = new List <MM_TransformerWinding>(); foreach (XmlElement xWind in xElem.SelectNodes("Winding")) { Windings.Add(MM_Element.CreateElement(xWind, "BaseElement", AddIfNew) as MM_TransformerWinding); } if (xElem.HasAttribute("BaseElement.KVLevel1")) { Windings[0].Voltage = XmlConvert.ToSingle(xElem.Attributes["BaseElement.KVLevel1"].Value.Split(' ')[0]); } if (xElem.HasAttribute("BaseElement.KVLevel2")) { Windings[1].Voltage = XmlConvert.ToSingle(xElem.Attributes["BaseElement.KVLevel2"].Value.Split(' ')[0]); } (OutElement as MM_Transformer).Windings = Windings.ToArray(); } //If we're a line, check for series compensator status to upgrade our type if (OutElement is MM_Line && xElem.HasAttribute("BaseElement.IsSeriesCompensator") && XmlConvert.ToBoolean(xElem.Attributes["BaseElement.IsSeriesCompensator"].Value)) { OutElement.ElemType = MM_Repository.FindElementType("SeriesCompensator"); } //Return our new element return(OutElement); }