Exemplo n.º 1
0
        /// <summary>
        /// This method shows the information to edit all values pre-configured for SMV,
        /// SMVControl and SMVoptions classes.
        /// </summary>
        /// <param name="sMVControl">
        /// Sampled Value Controls class.
        /// </param>
        /// <param name="sMVOptions">
        /// Sampled Value Options class.
        /// </param>
        /// <param name="smv">
        /// Sampled Value class.
        /// </param>
        /// <param name="treeSCL">
        /// TreeNode reference
        /// </param>
        public void SMVHandler(object sMVControl, object sMVOptions, string[] smv, TreeNode treeSCL)
        {
            tSampledValueControl sMVCtrl = (tSampledValueControl)sMVControl;

            sMVCtrl.datSet = this.datSet.SelectedItem.ToString();
            SCL sCL = (SCL)treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Tag;
            tSampledValueControlSmvOpts sMVOpts = (tSampledValueControlSmvOpts)sMVOptions;
            TreeNode nodeSMVControl             = new TreeNode();
            TreeNode nodeSMV;

            nodeSMVControl.Name = sMVCtrl.name;
            nodeSMVControl.Text = sMVCtrl.name;
            nodeSMVControl.Tag  = sMVCtrl;
            TreeNode nodetSMV;
            tSMV     tsmv = new tSMV();

            if (this.objectManagement.AddObjectToArrayObjectOfParentObject(sMVCtrl, treeSCL.Tag))
            {
                if (treeSCL.TreeView.SelectedNode.Tag is tLN0)
                {
                    tLN0     ln0       = (tLN0)treeSCL.Tag;
                    TreeNode parentSMV = new TreeNode();
                    parentSMV.Name = "tSampledValueControl[]";
                    parentSMV.Text = "SampledValueControl";
                    parentSMV.Tag  = ln0.SampledValueControl;
                    treeSCL.Nodes.Add(parentSMV);
                    treeSCL = parentSMV;
                }
                else
                {
                    treeSCL = treeSCL.TreeView.SelectedNode;
                }
                treeSCL.Nodes.Add(nodeSMVControl);
                this.objectManagement.AddObjectToSCLObject(sMVOpts, sMVCtrl);
                TreeNode nodeOP = new TreeNode();
                nodeOP.Name = "SMVOpts";
                nodeOP.Text = "SMVOpts";
                nodeOP.Tag  = sMVOpts;
                nodeSMVControl.Nodes.Add(nodeOP);
            }
            treeViewSCL.CreateCommNode(sCL, treeSCL);
            TreeNode connAPRef = new TreeNode();

            for (int i = 0; i < sCL.Communication.SubNetwork.Length; i++)
            {
                connAPRef = treeViewSCL.SeekAssociation(treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"].Nodes["tSubNetwork[]"].Nodes[i].Nodes, apParentName, iedParentName, "apName", "iedName");
                if (connAPRef == null && sCL.Communication.SubNetwork[i].ConnectedAP == null)
                {
                    treeViewSCL.CreateConnectedNode(sCL, treeSCL, apParentName, iedParentName, i);
                    connAPRef = treeViewSCL.SeekAssociation(treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"].Nodes["tSubNetwork[]"].Nodes[i].Nodes, apParentName, iedParentName, "apName", "iedName");
                }
                if (connAPRef != null)
                {
                    tsmv.cbName = sMVCtrl.name;
                    tsmv.ldInst = smv[0];
                    tsmv.desc   = smv[5];
                    nodeSMV     = new TreeNode();
                    this.objectManagement.AddObjectToArrayObjectOfParentObject(tsmv, connAPRef.Tag);
                    if (connAPRef.Nodes["tSMV[]"] == null)
                    {
                        tConnectedAP tconn = (tConnectedAP)connAPRef.Tag;
                        nodeSMV.Text = "SMV";
                        nodeSMV.Name = "tSMV[]";
                        nodeSMV.Tag  = tconn.SMV;
                        connAPRef.Nodes.Add(nodeSMV);
                    }
                    else
                    {
                        nodeSMV = connAPRef.Nodes["tSMV[]"];
                    }
                    nodetSMV      = new TreeNode();
                    nodetSMV.Text = sMVCtrl.name;
                    nodetSMV.Name = smv[0] + "." + sMVCtrl.name;
                    nodetSMV.Tag  = tsmv;
                    nodeSMV.Nodes.Add(nodetSMV);
                    AttributeReferences aReferences = new AttributeReferences();
                    aReferences.Insert(tsmv, nodeSMVControl);
                    tAddress taddr = new tAddress();
                    this.objectManagement.AddObjectToSCLObject(taddr, tsmv);
                    TreeNode nodeAddress = new TreeNode();
                    nodeAddress.Text = "Address";
                    nodeAddress.Name = "Address";
                    nodeAddress.Tag  = taddr;
                    nodetSMV.Nodes.Add(nodeAddress);
                    TreeNode nodetP = new TreeNode();
                    nodetP.Name = "tP[]";
                    nodetP.Text = "P";
                    nodeAddress.Nodes.Add(nodetP);
                    Utils utilsOM = new Utils();

                    tP            t_mac  = new tP();
                    tP_MACAddress t_mac_ = new tP_MACAddress();
                    this.objectManagement.EmptySourcetoDestinyObject(t_mac_, t_mac);
                    t_mac.Value = this.mac.Text;
                    utilsOM.AddTPTreeNode(t_mac, "tP_mac", "tP", taddr, nodetP);

                    tP       t_app  = new tP();
                    tP_APPID t_app_ = new tP_APPID();
                    this.objectManagement.EmptySourcetoDestinyObject(t_app_, t_app);
                    t_app.Value = this.appID.Text;
                    utilsOM.AddTPTreeNode(t_app, "tP_app", "tP", taddr, nodetP);

                    tP t_vlap = new tP();
                    tP_VLANPRIORITY t_vlap_ = new tP_VLANPRIORITY();
                    this.objectManagement.EmptySourcetoDestinyObject(t_vlap_, t_vlap);
                    t_vlap.Value = this.vLANP.Text;
                    utilsOM.AddTPTreeNode(t_vlap, "tP_vlanp", "tP", taddr, nodetP);

                    tP        t_vlani  = new tP();
                    tP_VLANID t_vlani_ = new tP_VLANID();
                    this.objectManagement.EmptySourcetoDestinyObject(t_vlani_, t_vlani);
                    t_vlani.Value = this.vLANI.Text;
                    utilsOM.AddTPTreeNode(t_vlani, "tP_vlani", "tP", taddr, nodetP);
                }
            }
        }
        /// <summary>
        /// This method draws the Communication nodes on the main tree.
        /// </summary>
        private void DrawCommunication()
        {
            // Add a tCommunication object to SCL
            if (this.scl.Communication == null)
            {
                tCommunication communication = new tCommunication();
                this.scl.Communication = communication;
                nodeComm      = new TreeNode();
                nodeComm.Name = "tCommunication";
                nodeComm.Tag  = this.scl.Communication;
                nodeComm.Text = "tCommunication";
                treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes.Add(nodeComm);
            }
            else
            {
                nodeComm = this.treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"];
            }
            // Add a Subnetwork
            if (this.treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"].Nodes["tSubNetwork[]"] == null)
            {
                nodeSubNetwork      = new TreeNode();
                nodeSubNetwork.Name = "tSubNetwork[]";
                nodeSubNetwork.Tag  = this.scl.Communication.SubNetwork;
                nodeSubNetwork.Text = "SubNetwork";
                treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"].Nodes.Add(nodeSubNetwork);
            }
            else
            {
                nodeSubNetwork = this.treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"].Nodes["tSubNetwork[]"];
            }
            if (this.treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"].Nodes["tSubNetwork[]"].Nodes[this.nameSubNet.Text] == null &&
                this.GetNodeName(nodeSubNetwork.Nodes, nameSubNet.Text, "name") == null)
            {
                int sni = this.scl.Communication.AddSubNetwork(this.nameSubNet.Text, this.descSubNet.Text);
                if (sni >= 0)
                {
                    nodetSubNetwork      = new TreeNode();
                    nodetSubNetwork.Name = this.scl.Communication.SubNetwork[sni].name;
                    nodetSubNetwork.Text = "tSubNetwork";
                    nodetSubNetwork.Tag  = this.scl.Communication.SubNetwork[sni];
                    treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"].Nodes["tSubNetwork[]"].Nodes.Add(nodetSubNetwork);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Subnetwork couldn't be added. Verify if it already exist and try again",
                                                         "Subnetwork wasn't added",
                                                         System.Windows.Forms.MessageBoxButtons.OK,
                                                         System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
            else
            {
                nodetSubNetwork = this.treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"].Nodes["tSubNetwork[]"].Nodes[this.GetNodeName(nodeSubNetwork.Nodes, nameSubNet.Text, "name")];
            }
            if (this.treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"].Nodes["tSubNetwork[]"].Nodes[nodetSubNetwork.Name].Nodes["tConnectedAP[]"] == null)
            {
                nodeComm      = new TreeNode();
                nodeComm.Name = "tConnectedAP[]";
                nodeComm.Tag  = this.scl.Communication.SubNetwork[nodetSubNetwork.Index].ConnectedAP;
                nodeComm.Text = "ConnectedAP";
                treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"]
                .Nodes["tSubNetwork[]"].Nodes[nodetSubNetwork.Name].Nodes.Add(nodeComm);
            }
            else
            {
                nodeComm = this.treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"].Nodes["tSubNetwork[]"].Nodes[nodetSubNetwork.Name].Nodes["tConnectedAP[]"];
            }

            this.treeViewSCL = new TreeViewSCL();
            connap.apName    = this.apName;
            connap.iedName   = this.iedName;
            if (this.treeViewSCL.SeekAssociation(this.treeSCL.TreeView.Nodes["root"]
                                                 .Nodes["SCL"].Nodes["tCommunication"]
                                                 .Nodes["tSubNetwork[]"].Nodes[nodetSubNetwork.Name]
                                                 .Nodes, this.apName, this.iedName) == null)
            {
                // Create tAddress
                tP[]  tp  = new tP[6];
                tP_IP _ip = new tP_IP();
                _ip.Value = this.ip.Text;
                tp[0]     = _ip;

                tP_IPSUBNET _subnet = new tP_IPSUBNET();
                _subnet.Value = this.mask.Text;
                tp[1]         = _subnet;

                tP_IPGATEWAY _gate = new tP_IPGATEWAY();
                _gate.Value = this.gateway.Text;
                tp[2]       = _gate;

                tP_OSITSEL _tsel = new tP_OSITSEL();
                _tsel.Value = this.tsel.Text;
                tp[3]       = _tsel;

                tP_OSISSEL _ssel = new tP_OSISSEL();
                _ssel.Value = this.ssel.Text;
                tp[4]       = _ssel;

                tP_OSIPSEL _psel = new tP_OSIPSEL();
                _psel.Value = this.psel.Text;
                tp[5]       = _psel;

                tAddress addr = new tAddress();
                addr.P = tp;

                tIED ied  = this.scl.IED[this.scl.GetIED(this.iedName)];
                int  api  = ied.GetAP(this.apName);
                int  capi = this.scl.Communication
                            .SubNetwork[nodetSubNetwork.Index].AddConnectedAP(ied, api, addr, null);
                if (capi >= 0)
                {
                    AttributeReferences refe = new AttributeReferences();
                    nodetConnected      = new TreeNode();
                    nodetConnected.Name = "tConnectedAP" + this.iedName + this.apName;
                    nodetConnected.Tag  = this.scl.Communication.SubNetwork[nodetSubNetwork.Index].ConnectedAP[capi];
                    nodetConnected.Text = "tConnectedAP";
                    treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"]
                    .Nodes["tSubNetwork[]"].Nodes[nodetSubNetwork.Name]
                    .Nodes["tConnectedAP[]"].Nodes.Add(nodetConnected);
                    refe.Insert(this.scl.Communication.SubNetwork[nodetSubNetwork.Index].ConnectedAP[capi],
                                this.treeSCL.TreeView.SelectedNode);

                    // Add Nodes for tAddress and tP
                    TreeNode nodeAddress = new TreeNode();
                    nodeAddress.Name = "Adress";
                    nodeAddress.Tag  = address;
                    nodeAddress.Text = "Address";
                    treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"]
                    .Nodes["tSubNetwork[]"].Nodes[nodetSubNetwork.Name]
                    .Nodes["tConnectedAP[]"].Nodes[nodetConnected.Name].Nodes.Add(nodeAddress);
                    nodeP.Name = "tP[]";
                    nodeP.Text = "P";
                    treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"]
                    .Nodes["tSubNetwork[]"].Nodes[nodetSubNetwork.Name]
                    .Nodes["tConnectedAP[]"].Nodes[nodetConnected.Name]
                    .Nodes["Adress"].Nodes.Add(nodeP);

                    Utils.AddTPTreeNode(_ip, nodeP);
                    Utils.AddTPTreeNode(_subnet, nodeP);
                    Utils.AddTPTreeNode(_gate, nodeP);
                    Utils.AddTPTreeNode(_tsel, nodeP);
                    Utils.AddTPTreeNode(_psel, nodeP);
                    Utils.AddTPTreeNode(_ssel, nodeP);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("ConnectedAP couldn't be added. Verify if it already exist and try again",
                                                         "ConnectedAP wasn't added",
                                                         System.Windows.Forms.MessageBoxButtons.OK,
                                                         System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
            else
            {
                nodetConnected = this.treeViewSCL.SeekAssociation(this.treeSCL.TreeView.Nodes["root"].Nodes["SCL"].Nodes["tCommunication"].Nodes["tSubNetwork[]"].Nodes[nodetSubNetwork.Name].Nodes["tConnectedAP[]"].Nodes, this.apName, this.iedName, "apName", "iedName");
            }
        }