コード例 #1
0
        /// <summary>
        /// Initialize a new CIM Line
        /// </summary>
        /// <param name="ElementSource">The XML source for this line</param>
        /// <param name="AddIfNew">Whether to add any new elements that may be created</param>
        public MM_Line(XmlElement ElementSource, bool AddIfNew)
            : base(ElementSource, AddIfNew)
        {
            this.ElemType = MM_Repository.FindElementType("Line");

            if (ElementSource.HasAttribute("Contingencies"))
            {
                String[] splStr = ElementSource.Attributes["Contingencies"].Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string str in splStr)
                {
                    MM_Contingency con = null;
                    MM_Repository.Contingencies.TryGetValue(str, out con);
                    if (con != null && !Contingencies.Any(c => con.Name == c.Name))
                    {
                        this.Contingencies.Add(con);
                    }
                }
            }
        }
コード例 #2
0
ファイル: MM_Element.cs プロジェクト: sylvainr/MacomberMap
        /// <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);
        }