Example #1
0
 /// <summary>
 /// Initialize the MM permissions
 /// </summary>
 /// <param name="xConfig">The configuration element for this permissions.</param>
 public MM_Permissions(XmlElement xConfig)
 {
     if (xConfig == null)
     {
         return;
     }
     MM_Serializable.ReadXml(xConfig, this, false);
     BoilerplateText = xConfig.InnerText;
 }
Example #2
0
 /// <summary>
 /// Initialize a new node from an XML document
 /// </summary>
 /// <param name="ElementSource"></param>
 /// <param name="AddIfNew">Whether to add any new elements that may be created</param>
 public MM_Node(XmlElement ElementSource, bool AddIfNew)
     : base(ElementSource, AddIfNew)
 {
     this.ElemType = MM_Repository.FindElementType("Node");
     String[] splStr = (ElementSource.Attributes["ConnectedElements"]).Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
     ConnectedElements = new List <MM_Element>(splStr.Length);
     for (int a = 0; a < splStr.Length; a++)
     {
         ConnectedElements[a] = (MM_Element)MM_Serializable.RetrieveConvertedValue(typeof(MM_Element), splStr[a], this, AddIfNew);
     }
 }
Example #3
0
        /// <summary>
        /// Initialize a new key indicator level
        /// </summary>
        /// <param name="xElem"></param>
        /// <param name="InForm"></param>
        /// <param name="Click"></param>
        public MM_Key_Indicator_Label(XmlElement xElem, Form InForm, EventHandler Click)
        {
            if (!MM_Server_Interface.ISQse)
            {
                this.Tag = InForm;
            }
            InForm.Visible = false;
            this.Click    += Click;
            this.AutoSize  = true;
            this.Font      = MM_Repository.OverallDisplay.KeyIndicatorSimpleFont;

            MM_Serializable.ReadXml(xElem, this, true);
            this.BackColor = Color.Transparent;
        }
Example #4
0
        /// <summary>
        /// Initialize a new control panel
        /// </summary>
        /// <param name="SourceElement">Our source element</param>
        /// <param name="xConfiguration">The configuration for the control panel</param>
        /// <param name="OneLineViewer">The one-line viewer</param>
        public MM_ControlPanel(MM_OneLine_Element SourceElement, XmlElement xConfiguration, MM_OneLine_Viewer OneLineViewer)
        {
            //xConfiguration.InnerXml = Clipboard.GetText();
            this.OneLineViewer = OneLineViewer;
            InitializeComponent();
            this.xConfiguration = xConfiguration;
            this.SourceElement  = SourceElement;

            Keys CurKeys = Control.ModifierKeys;

            if (CurKeys == (Keys.Control | Keys.Shift | Keys.Alt))
            {
                Editable             = true;
                this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
            }
            else
            {
                Editable = false;
            }

            //Create our Communications view
            btnComm        = new Button();
            btnComm.Text   = "Comm";
            btnComm.Size   = new System.Drawing.Size(78, 17);
            btnComm.Font   = new System.Drawing.Font("Arial", 10);
            btnComm.Click += btnComm_Click;
            btnComm.Paint += btnComm_Paint;
            Controls.Add(btnComm);

            SizePanel            = new Panel();
            SizePanel.Location   = new Point(4, 4);
            SizePanel.AutoScroll = true;
            SizePanel.AutoSize   = false;
            SizePanel.HorizontalScroll.Enabled = true;
            SizePanel.VerticalScroll.Enabled   = true;
            SizePanel.HorizontalScroll.Visible = true;
            SizePanel.VerticalScroll.Visible   = true;
            Controls.Add(SizePanel);
            //Now, initialize the window, and sublements
            MM_Serializable.ReadXml(xConfiguration, this, false);
            this.Text = xConfiguration.Attributes["Title"].Value + " - " + SourceElement.BaseElement.SubLongName + " " + SourceElement.BaseElement.ElemType.Name + " " + SourceElement.BaseElement.Name;
            foreach (XmlElement xElem in xConfiguration.ChildNodes.OfType <XmlElement>())
            {
                if (xElem.Name != "DataSource")
                {
                    AddElement(SizePanel, xElem);
                }
            }
            btnComm.Location = new Point(DisplayRectangle.Width - btnComm.Width + 4, 2);//DisplayRectangle.Height - btnComm.Height);

            //If we are in editable mode, add in our propery page
            if (Editable)
            {
                PropertyGrid pG = new PropertyGrid();
                pG.Name   = "PropertyGrid";
                pG.Width  = 400;
                pG.Height = this.Height;
                pG.Left   = this.Width;
                pG.PropertyValueChanged += new PropertyValueChangedEventHandler(pG_PropertyValueChanged);
                this.Controls.Add(pG);
            }



            UpdateDisplay();
        }
Example #5
0
        /// <summary>
        /// Add an element to our display
        /// </summary>
        /// <param name="ParentControl"></param>
        /// <param name="xElem"></param>
        private void AddElement(Control ParentControl, XmlElement xElem)
        {
            Control NewCtl = null;

            if (xElem.Name == "Label")
            {
                NewCtl          = new Label();
                NewCtl.AutoSize = true;
                NewCtl.Text     = "?";
            }
            else if (xElem.Name == "TextBox")
            {
                NewCtl            = new TextBox();
                NewCtl.KeyPress  += new KeyPressEventHandler(NewCtl_KeyPress);
                NewCtl.LostFocus += new EventHandler(NewCtl_LostFocus);
                NewCtl.BackColor  = Color.Black;
                NewCtl.ForeColor  = Color.White;
                NewCtl.GotFocus  += new EventHandler(NewCtl_GotFocus);
            }
            else if (xElem.Name == "CheckBox")
            {
                NewCtl          = new CheckBox();
                NewCtl.Text     = "";
                NewCtl.AutoSize = true;
            }
            else if (xElem.Name == "Button")
            {
                NewCtl = new Button();
            }
            else if (xElem.Name == "Synchroscope")
            {
                MM_Element[] NodeElems = OneLineViewer.ElementNodes(SourceElement);
                NewCtl = new MM_OneLine_Synchroscope((MM_Breaker_Switch)SourceElement.BaseElement, (MM_Node)NodeElems[0], (MM_Node)NodeElems[1]);
            }
            else if (xElem.Name == "GeneratorControlPanel")
            {
                NewCtl       = new MM_Generator_ControlPanel(SourceElement, OneLineViewer);
                this.Closed += ((MM_Generator_ControlPanel)NewCtl).Generator_ControlPanel_Close;
                Panel TempPanel = new Panel();
                TempPanel.Size       = NewCtl.Size;
                TempPanel.AutoSize   = true;
                TempPanel.AutoScroll = true;
                TempPanel.Margin     = new System.Windows.Forms.Padding(0);
                NewCtl.Margin        = new System.Windows.Forms.Padding(0);
                TempPanel.Controls.Add(NewCtl);
                NewCtl = TempPanel;
            }
            else if (xElem.Name == "GroupBox")
            {
                if (Editable || !xElem.HasAttribute("IfTrue") || (bool)SourceElement.BaseElement.GetType().GetField(xElem.Attributes["IfTrue"].Value).GetValue(SourceElement.BaseElement))
                {
                    NewCtl           = new GroupBox();
                    NewCtl.ForeColor = Color.White;
                    foreach (XmlElement xSubElem in xElem.ChildNodes)
                    {
                        AddElement(NewCtl, xSubElem);
                    }
                    (NewCtl as GroupBox).AutoSize = true;
                }
            }
            else if (xElem.Name == "TabControl")
            {
                NewCtl = new TabControl();
                foreach (XmlElement xSubElem in xElem.ChildNodes)
                {
                    if (xSubElem.Name == "TabPage")
                    {
                        TabPage NewPage = new TabPage(xSubElem.Attributes["Title"].Value);
                        (NewCtl as TabControl).TabPages.Add(NewPage);
                        foreach (XmlElement xSubElem2 in xSubElem.ChildNodes)
                        {
                            AddElement(NewPage, xSubElem2);
                        }
                    }
                }
            }
            if (xElem.HasAttribute("OnClick") || (xElem.Name == "CheckBox" && xElem.HasAttribute("OnChange")))
            {
                NewCtl.Click += new EventHandler(NewCtl_Click);
            }


            //Go through and deserialize all attributes on our element
            if (NewCtl == null)
            {
                return;
            }

            if (Editable && NewCtl is GroupBox == false && NewCtl is TabPage == false)
            {
                NewCtl.BackColor  = Color.Purple;
                NewCtl.MouseDown += new MouseEventHandler(NewCtl_MouseDown);
                NewCtl.MouseMove += new MouseEventHandler(NewCtl_MouseMove);
                NewCtl.MouseUp   += new MouseEventHandler(NewCtl_MouseUp);
            }
            MM_Serializable.ReadXml(xElem, NewCtl, false);

            NewCtl.Top += 4;
            NewCtl.Tag  = xElem;

            if (NewCtl is GroupBox)
            {
                //Shift to the right as needed
                int RightMost = 0;
                foreach (Control ctl in SizePanel.Controls)
                {
                    if (ctl != btnComm)
                    {
                        RightMost = Math.Max(ctl.Right, RightMost);
                    }
                }
                NewCtl.Left = RightMost + 4;
            }

            DisplayedControls.Add(xElem, NewCtl);
            ParentControl.Controls.Add(NewCtl);
        }
Example #6
0
        /// <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);
        }