public string GetOneLineXml(ref int XPos, int YPos) { StringBuilder sB = new StringBuilder(); //Determine all of the elements attached to our bus String ConnectedElements = ""; List <Sim_Element> Elements = new List <Sim_Element>(); foreach (Sim_Element Elem in Substation.Elements) { if (Elem is Sim_Bus == false && Elem.GetBuses().Contains(this)) { Elements.Add(Elem); ConnectedElements += (ConnectedElements == "" ? "" : ",") + Elem.TEID.ToString(); } } sB.AppendLine($"\t<{ElemType} IsVisible =\"true\" Bounds=\"{XPos},{YPos},{XWidth},8\" Orientation=\"Vertical\" Text=\"{Name}\" rdfID=\"{NodeGuid}\" BaseElement.ElemType=\"{ElemType}\" BaseElement.KVLevel=\"{Voltage}\" BaseElement.Name=\"{Name}\" BaseElement.TEID=\"{NodeTEID}\" BaseElement.Owner=\"{Owner.TEID}\" BaseElement.Operator=\"{Operator.TEID}\" BaseElement.Substation=\"{Substation.TEID}\" BaseElement.SubLongName=\"{Substation.Name}\" PUNElement=\"False\" BaseElement.SubName=\"{Substation.Name}\">"); foreach (Sim_Element Element in Elements) { sB.AppendLine($"\t\t<{Element.ElemType} rdfID=\"{Element.ElemGuid}\" TEID=\"{Element.TEID}\"/>"); } sB.Append($"\t</{ElemType}>"); return(sB.ToString()); }
/// <summary> /// Generate our one-line /// </summary> /// <param name="Substation"></param> /// <param name="TargetDirectory"></param> /// <returns></returns> public void GenerateOneLine(Sim_Substation Substation, String TargetDirectory) { //First, build our list of buses and connected equipment Dictionary <Sim_Bus, List <Sim_Element> > Elements = new Dictionary <Sim_Bus, List <Sim_Element> >(); Dictionary <Sim_Bus, int> ElementRight = new Dictionary <Sim_Bus, int>(); foreach (Sim_Bus Bus in Substation.Elements.OfType <Sim_Bus>()) { Elements.Add(Bus, new List <Sim_Element>()); } foreach (Sim_Element Elem in Substation.Elements) { if (Elem is Sim_Transformer) { Sim_TransformerWinding Winding1 = ((Sim_Transformer)Elem).Winding1; Sim_TransformerWinding Winding2 = ((Sim_Transformer)Elem).Winding2; if (Elements.ContainsKey(Winding1.Bus) && !Elements[Winding1.Bus].Contains(Winding1)) { Elements[Winding1.Bus].Add(Winding1); } if (Elements.ContainsKey(Winding2.Bus) && !Elements[Winding2.Bus].Contains(Winding2)) { Elements[Winding2.Bus].Add(Winding2); } } else if (Elem is Sim_Bus == false) { Sim_Bus Bus = Elem.GetBuses()[0]; if (Elements.ContainsKey(Bus) && !Elements[Bus].Contains(Elem)) { Elements[Bus].Add(Elem); } } } using (StreamWriter sW = new StreamWriter(Path.Combine(Config.OneLineFolder, Substation.Name + ".MM_OneLine"), false, new UTF8Encoding(false))) { sW.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>"); sW.WriteLine($"<One_Line BaseElement.ElemType=\"Substation\" BaseElement.TEID=\"{Substation.TEID}\" BaseElement.ConnectedLines=\"\" BaseElement.County=\"{Substation.Parent.Name}\" BaseElement.DisplayName=\"{Substation.Name}\" BaseElement.{Substation.ElemTypes} BaseElement.{Substation.KVLevels} BaseElement.Latitude=\"{Substation.Latitude}\" BaseElement.LatLong=\"{Substation.Latitude},{Substation.Longitude}\" BaseElement.Longitude=\"{Substation.Longitude}\" BaseElement.Operator=\"{Substation.Operator.TEID}\" BaseElement.Owner=\"{Substation.Owner.TEID}\" BaseElement.Permitted=\"true\" Font=\"Microsoft Sans Serif, 8.25pt\" BaseElement.Name=\"{Substation.Name}\" BaseElement.LongName=\"{Substation.Name}\">"); //Now, determine the Y coordinate of the bus int YVal = 50; foreach (Sim_Bus Bus in Elements.Keys) { Bus.Y = YVal; YVal += 50; } sW.WriteLine("<Elements>"); foreach (KeyValuePair <Sim_Bus, List <Sim_Element> > kvp in Elements) { int XVal = 50; foreach (Sim_Element Elem in kvp.Value) { if (Elem is Sim_TransformerWinding) { sW.WriteLine(((Sim_TransformerWinding)Elem).Transformer.GetOneLineXml(ref XVal, kvp.Key.Y)); } else { sW.WriteLine(Elem.GetOneLineXml(ref XVal, kvp.Key.Y)); } } ElementRight.Add(kvp.Key, XVal); } sW.WriteLine("</Elements>"); sW.WriteLine("<Nodes>"); foreach (Sim_Bus Bus in Elements.Keys) { int XVal = 25; Bus.XWidth = ElementRight[Bus]; sW.WriteLine(Bus.GetOneLineXml(ref XVal, Bus.Y)); } sW.WriteLine("</Nodes>"); sW.WriteLine("</One_Line>"); } }