0% found this document useful (0 votes)
134 views200 pages

FRM Ed 2 Dynamic Addition

This document defines a class called frmEd2DynamicAddition that is used to display tabbed content for GOOSE subscriptions, control blocks, and other IEC 61850 configuration details. The class loads configuration data, handles events for configuration changes, and enables/disables buttons based on user permissions. It also defines methods for retrieving, setting, and updating the various configuration sections.

Uploaded by

saurabh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views200 pages

FRM Ed 2 Dynamic Addition

This document defines a class called frmEd2DynamicAddition that is used to display tabbed content for GOOSE subscriptions, control blocks, and other IEC 61850 configuration details. The class loads configuration data, handles events for configuration changes, and enables/disables buttons based on user permissions. It also defines methods for retrieving, setting, and updating the various configuration sections.

Uploaded by

saurabh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 200

using System;

using System.Collections;

using System.Collections.Generic;

using System.ComponentModel;

using System.Reflection;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

using IEDConfigurationTool.CustomControls;

using System.Xml;

using System.Data;

using System.IO;

using System.Data.SqlServerCe;

using System.Drawing.Printing;

using WeifenLuo.WinFormsUI.Docking;

namespace IEDConfigurationTool

/// <summary>

/// Form for tabbed display for GOOSE subscription, Control blocks etc

/// </summary>

public partial class frmEd2DynamicAddition : DockableDocument

/// <summary>

/// Constructor
/// </summary>

/// <param name="_MainForm"></param>

/// <param name="ied"></param>

public frmEd2DynamicAddition()

InitializeComponent();

base.iedDev = LablelClass.iedDevice;

[DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]

public static extern int GetScrollPos(int hWnd, int nBar);

[DllImport("user32.dll")]

static extern int SetScrollPos(IntPtr hWnd, int nBar, int nPos, bool bRedraw);

private const int SB_HORZ = 0x0;

private const int SB_VERT = 0x1;

/// <summary>

/// Form load event handler

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void frmIEC61850Configuration_Load(object sender, EventArgs e)

label9.Text = iedDev.IEDDeviceOrginalName;

label10.Text = iedDev.IEDDeviceInstanceName;
if (iedDev == null)

return;

SetGrpText();

Load61850Configuration();

Global.OnUpdateGOOSELibrary += new Global.IEDAdd(Global_OnIEDAdded);

Global.OnRenameIED += new Global.RenameIED(Global_OnRenameIED);

Global.OnIEC61850ConfigReload += new
Global.IEC61850ConfigReloadEventArgs(Global_OnIEC61850ConfigReload);

LoadimageListGooseLibrary();

LoadImageListIEDItems();

iedDev.OnIEDRenamed += new IEDDevice.RenameEventArgs(iedDev_OnIEDRenamed);

btnRetreive.Enabled = Global.CurrentUser.RetrieveConfigurations;

//sendCIDToolStripMenuItem.Enabled = Global.CurrentUser.DownloadConfigurations;

tsRemoveMapping.Enabled = Global.CurrentUser.IEC61850Configuration;

tspDatasetMoveUp.Enabled = Global.CurrentUser.IEC61850Configuration;

tspDatasetMoveDown.Enabled = Global.CurrentUser.IEC61850Configuration;

tspDatasetItemDelete.Enabled = Global.CurrentUser.IEC61850Configuration;

iedProperties.Enabled= Global.CurrentUser.IEC61850Configuration;

startupProperties.Enabled= Global.CurrentUser.IEC61850Configuration;

if (!Global.CurrentUser.IEC61850Configuration)

Disablebuttons();

}
tabMain.TabPages.Remove(pageProperties);

/// <summary>

/// Disables buttons

/// </summary>

void Disablebuttons()

btnAddDataSet.Enabled = false;

btnEditDs.Enabled = false;

btnAddLog.Enabled = false;

btnNewRCB.Enabled = false;

btnDeleteDataset.Enabled = false;

btnDeleteRCB.Enabled = false;

btnDeleteGOCB.Enabled = false;

btnDeleteLog.Enabled = false;

btnEditGOCB.Enabled = false;

btnEditLog.Enabled = false;

btnEditRCB.Enabled = false;

btnNewGOCB.Enabled = false;

btnCloneDataset.Enabled = false;
}

/// <summary>

/// Function to load each section of IEC 61850 details

/// </summary>

void Load61850Configuration()

if (iedDev.SCLConfiguration == null)

return;

if (iedDev.SCLConfiguration.IEDs.Count == 0)

return;

iedProperties.SelectedObject = iedDev.SCLConfiguration.IEDs[0];

if (iedDev.SCLConfiguration.IEDs[0].StartUpSettings == null)

iedDev.SCLConfiguration.IEDs[0].StartUpSettings = new StartUp();

if (iedDev.SCLConfiguration.IEDs[0].MUStartUpSettings == null)

iedDev.SCLConfiguration.IEDs[0].MUStartUpSettings = new MUStartUp();

if(iedDev.SCLConfiguration.IEDs[0].SMVStartUpSettings==null)

iedDev.SCLConfiguration.IEDs[0].SMVStartUpSettings = new SMVStartUp();

}
startupProperties.SelectedObject = iedDev.SCLConfiguration.IEDs[0].StartUpSettings;

FillGoosePublisherDetails("");

FillSubscriberInputs();

FillGooseSubscriberDetails();

FillReportControlBlocks("");

FillLogControlBlocks("");

FillDataSets("");

IEDConfigurationTool.DisplayUtil.FillLDevices(cmbLogicalDevices,
base.iedDev.SCLConfiguration.IEDs[0]);

/// <summary>

/// OnIEC61850ConfigReloa event handler of Global

/// </summary>

/// <param name="ied"></param>

void Global_OnIEC61850ConfigReload(IED ied)

try

// this.Invoke((MethodInvoker)delegate { ReloadIEDGOOSENode(ied); });

this.Invoke((MethodInvoker)delegate { Load61850Configuration(); });


}

catch { }

/// <summary>

/// OnRenameIED event handler of Global

/// </summary>

/// <param name="OldName"></param>

/// <param name="NewName"></param>

void Global_OnRenameIED(string OldName, string NewName)

try

Invoke((MethodInvoker)delegate { FillGooseSubscriberDetails(); });

catch { }

/// <summary>

/// This function renames old IED name to new IED name in treeview

/// </summary>

/// <param name="treeView"></param>

/// <param name="OldName"></param>

/// <param name="NewName"></param>

private void RenameIEDInTreeView(TreeView treeView, string OldName, string NewName)

{
for (int i = 0; i < treeView.Nodes.Count; i++)

if (treeView.Nodes[i].Text.Split('.')[0] == OldName)

treeView.Nodes[i].Text = NewName ;

/// <summary>

/// Sets the group box's text

/// </summary>

void SetGrpText()

iedProperties.SelectedObject = iedDev.SCLConfiguration.IEDs[0];

startupProperties.SelectedObject = iedDev.SCLConfiguration.IEDs[0].StartUpSettings;

BrowsableGridProperty(startupProperties.SelectedObject, "MIN_SMV_OUT", true);

BrowsableGridProperty(startupProperties.SelectedObject, "MAX_SMV_OUT", true);

BrowsableGridProperty(startupProperties.SelectedObject, "MAX_SV_STREAM", true);

BrowsableGridProperty(startupProperties.SelectedObject, "smvNetworkCardID", true);

BrowsableGridProperty(startupProperties.SelectedObject, "GOOSE_SIMULATION_BIT", true);


grpGOOSEPub.Text = "GOOSE Publishers of " + iedDev.IEDDeviceInstanceName;

grpGOOSESub.Text = "GOOSE Subscribers of " + iedDev.IEDDeviceInstanceName;

grpRCB.Text = "Report Control Blocks of " + iedDev.IEDDeviceInstanceName;

grpLog.Text = "Log Control Blocks of " + iedDev.IEDDeviceInstanceName;

grpDataSets.Text = "Datasets of " + iedDev.IEDDeviceInstanceName;

grpIEDDataItems.Text = "IED Data Items of " + iedDev.IEDDeviceInstanceName;

public void BrowsableGridProperty(object obj, string propertyName, bool isBrowsable)

PropertyDescriptor descriptor = TypeDescriptor.GetProperties(obj.GetType())[propertyName];

BrowsableAttribute attribute =
(BrowsableAttribute)descriptor.Attributes[typeof(BrowsableAttribute)];

FieldInfo fieldtoChange = attribute.GetType().GetField("browsable", BindingFlags.NonPublic |


BindingFlags.Instance);

if (fieldtoChange != null)

fieldtoChange.SetValue(attribute,isBrowsable);

startupProperties.Refresh();

/// <summary>

/// OnIEDRenamed event handler of iedDev

/// </summary>
/// <param name="OldIEDName"></param>

/// <param name="NewIEDName"></param>

void iedDev_OnIEDRenamed(string OldIEDName, string NewIEDName)

Invoke((MethodInvoker)SetGrpText);

/// <summary>

/// Loads images for imagelist imageListGooseLibrary

/// </summary>

private void LoadimageListGooseLibrary()

imageListGooseLibrary.Images.Add(Properties.Resources.G);

imageListGooseLibrary.Images.Add(Properties.Resources.DS);

imageListGooseLibrary.Images.Add(Properties.Resources.DS);

imageListGooseLibrary.Images.Add(Properties.Resources.DO);

imageListGooseLibrary.Images.Add(Properties.Resources.DO);

imageListGooseLibrary.Images.Add(Properties.Resources.boff);

imageListGooseLibrary.Images.Add(Properties.Resources.bon);

imageListGooseLibrary.Images.Add(Properties.Resources.tOff);

imageListGooseLibrary.Images.Add(Properties.Resources.tOn);

imageListGooseLibrary.Images.Add(Properties.Resources.Qoff);

imageListGooseLibrary.Images.Add(Properties.Resources.Qon);

imageListGooseLibrary.Images.Add(Properties.Resources.fOff);

imageListGooseLibrary.Images.Add(Properties.Resources.fOn);

imageListGooseLibrary.Images.Add(Properties.Resources.iOff);
imageListGooseLibrary.Images.Add(Properties.Resources.iOn);

imageListGooseLibrary.Images.Add(Properties.Resources.Eoff);

imageListGooseLibrary.Images.Add(Properties.Resources.EOn);

imageListGooseLibrary.Images.Add(Properties.Resources.Coff);

imageListGooseLibrary.Images.Add(Properties.Resources.coon);

imageListGooseLibrary.Images.Add(Properties.Resources.Struct);

imageListGooseLibrary.Images.Add(Properties.Resources.Struct);

imageListGooseLibrary.Images.Add(Properties.Resources.ooff);

imageListGooseLibrary.Images.Add(Properties.Resources.oOn);

imageListGooseLibrary.Images.Add(Properties.Resources.Soff);

imageListGooseLibrary.Images.Add(Properties.Resources.Son);

imageListGooseLibrary.Images.Add(Properties.Resources.dpoff);

imageListGooseLibrary.Images.Add(Properties.Resources.dpon);

imageListGooseLibrary.Images.Add(Properties.Resources.tcoff);

imageListGooseLibrary.Images.Add(Properties.Resources.tcon);

imageListGooseLibrary.Images.Add(Properties.Resources.etoff);

imageListGooseLibrary.Images.Add(Properties.Resources.eton);

imageListGooseLibrary.Images.Add(Properties.Resources.uoff);

imageListGooseLibrary.Images.Add(Properties.Resources.uon);

imageListGooseLibrary.Images.Add(Properties.Resources.unoff);

imageListGooseLibrary.Images.Add(Properties.Resources.unon);

imageListGooseLibrary.Images.Add(Properties.Resources.LN);

imageListGooseLibrary.Images.Add(Properties.Resources.FC);

imageListGooseLibrary.Images.Add(Properties.Resources.fcd);

imageListGooseLibrary.Images.Add(Properties.Resources.fcdoff);

imageListGooseLibrary.Images.Add(Properties.Resources.fcdon);

imageListGooseLibrary.Images.Add(Properties.Resources.IED);
//imageListGooseLibrary.Images.Add(Properties.Resources.smv);

/// <summary>

/// Loads images for imagelist imagelistIEDDataItems

/// </summary>

private void LoadImageListIEDItems()

imagelistIEDDataItems.Images.Add(Properties.Resources.G);

imagelistIEDDataItems.Images.Add(Properties.Resources.DS);

imagelistIEDDataItems.Images.Add(Properties.Resources.DS);

imagelistIEDDataItems.Images.Add(Properties.Resources.DO);

imagelistIEDDataItems.Images.Add(Properties.Resources.DO);

imagelistIEDDataItems.Images.Add(Properties.Resources.b);

imagelistIEDDataItems.Images.Add(Properties.Resources.b);

imagelistIEDDataItems.Images.Add(Properties.Resources.T);

imagelistIEDDataItems.Images.Add(Properties.Resources.T);

imagelistIEDDataItems.Images.Add(Properties.Resources.Q);

imagelistIEDDataItems.Images.Add(Properties.Resources.Q);

imagelistIEDDataItems.Images.Add(Properties.Resources.F);

imagelistIEDDataItems.Images.Add(Properties.Resources.F);

imagelistIEDDataItems.Images.Add(Properties.Resources.I);

imagelistIEDDataItems.Images.Add(Properties.Resources.I);

imagelistIEDDataItems.Images.Add(Properties.Resources.E);

imagelistIEDDataItems.Images.Add(Properties.Resources.E);

imagelistIEDDataItems.Images.Add(Properties.Resources.C);

imagelistIEDDataItems.Images.Add(Properties.Resources.C);

imagelistIEDDataItems.Images.Add(Properties.Resources.Struct);
imagelistIEDDataItems.Images.Add(Properties.Resources.Struct);

imagelistIEDDataItems.Images.Add(Properties.Resources.O);

imagelistIEDDataItems.Images.Add(Properties.Resources.O);

imagelistIEDDataItems.Images.Add(Properties.Resources.S);

imagelistIEDDataItems.Images.Add(Properties.Resources.S);

imagelistIEDDataItems.Images.Add(Properties.Resources.dp);

imagelistIEDDataItems.Images.Add(Properties.Resources.dp);

imagelistIEDDataItems.Images.Add(Properties.Resources.tc);

imagelistIEDDataItems.Images.Add(Properties.Resources.tc);

imagelistIEDDataItems.Images.Add(Properties.Resources.et);

imagelistIEDDataItems.Images.Add(Properties.Resources.et);

imagelistIEDDataItems.Images.Add(Properties.Resources.u);

imagelistIEDDataItems.Images.Add(Properties.Resources.u);

imagelistIEDDataItems.Images.Add(Properties.Resources.unknown);

imagelistIEDDataItems.Images.Add(Properties.Resources.unknown);

imagelistIEDDataItems.Images.Add(Properties.Resources.LN);

imagelistIEDDataItems.Images.Add(Properties.Resources.FC);

imagelistIEDDataItems.Images.Add(Properties.Resources.fcd);

imagelistIEDDataItems.Images.Add(Properties.Resources.BR);

imagelistIEDDataItems.Images.Add(Properties.Resources.UR);

imagelistIEDDataItems.Images.Add(Properties.Resources.IED);

imagelistIEDDataItems.Images.Add(Properties.Resources.smv);

imagelistIEDDataItems.Images.Add(Properties.Resources.DS);

imagelistIEDDataItems.Images.Add(Properties.Resources.DS);

/// <summary>
/// OnIEDAdded event handler of Global

/// </summary>

/// <param name="ied"></param>

void Global_OnIEDAdded(IED ied)

try

this.Invoke((MethodInvoker)delegate { AddIEDNode(ied); });

catch { }

/// <summary>

/// Adds IED 's IEDNodeGSE & IEDNodeSMV to treeviews

/// </summary>

/// <param name="ied"></param>

void AddIEDNode(IED ied)

if (ied == null)

return;

/// <summary>

/// This function loads the subscriber points


/// </summary>

private void FillSubscriberInputs()

try

// lstDigitalSubscribers.Items.Clear();

// lstAngSubscribers.Items.Clear();

ListViewItem item = new ListViewItem();

if (base.iedDev.SCLConfiguration == null)

return;

if (base.iedDev.SCLConfiguration.IEDs.Count == 0)

return;

if (iedDev.SCLConfiguration.IEDs[0] != null)

List<VI> sub = iedDev.SCLConfiguration.IEDs[0].AccessPoints[0].BooleanIEC61850Inputs;

if (sub != null)

for (int j = 0; j < sub.Count; j++)

// AddItemToSubScriberList(sub[j], lstDigitalSubscribers);

sub = iedDev.SCLConfiguration.IEDs[0].AccessPoints[0].AnalogFloatIEC61850Inputs;

if (sub != null)

for (int j = 0; j < sub.Count; j++)

{
// AddItemToSubScriberList(sub[j], lstAngSubscribers);

catch { }

/// <summary>

/// Adds the subscriber point to listview

/// </summary>

/// <param name="vi"></param>

/// <param name="lstView"></param>

private void AddItemToSubScriberList(VI vi, ListView lstView)

ListViewItem item = null;

string strLN = "";

strLN = vi.Path.Split('$')[0];

item = new ListViewItem(vi.Name);

if (item != null)

item.Tag = vi;

if (vi.IsMapped)

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, vi.MappedPath));

else
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));

lstView.Items.Add(item);

bool FillGOOSEPub=false;

/// <summary>

/// Fills GOOSE publisher details of an IED

/// </summary>

/// <param name="IEDName">IED Name</param>

private void FillGoosePublisherDetails(string ItemToSelect)

try

lstViewGOOSEPublisherConf.Items.Clear();

if (base.iedDev.SCLConfiguration == null)

return;

if (base.iedDev.SCLConfiguration.IEDs.Count == 0)

return;

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

LablelClass.ied = ied;

if (ied != null)

List<GSEControl> PublisherGoose = ied.AccessPoints[0].GetAllGSEControlBlocks();

if (PublisherGoose != null)

ListViewItem item;
for (int i = 0; i < PublisherGoose.Count; i++)

FillGOOSEPub = true;

item = new ListViewItem(PublisherGoose[i].CBLDeviceName + ".LLN0." +


PublisherGoose[i].name, 0);

item.Checked = PublisherGoose[i].IsPublisher;

if (PublisherGoose[i].DataSetName != null && PublisherGoose[i].DataSetName != "")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
PublisherGoose[i].CBLDeviceName + ".LLN0." + PublisherGoose[i].DataSetName));

item.SubItems[item.SubItems.Count - 1].Tag = "DS";

else

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));

item.SubItems[item.SubItems.Count - 1].Tag = "DS";

for (int j = 0; j < lstViewGOOSEPublisherConf.Columns.Count; j++)

if (lstViewGOOSEPublisherConf.Columns[j].Tag != null)

if (lstViewGOOSEPublisherConf.Columns[j].Tag.ToString() == "MAC")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
PublisherGoose[i].MACAddress));

item.SubItems[item.SubItems.Count - 1].Tag = "MAC";

else if (lstViewGOOSEPublisherConf.Columns[j].Tag.ToString() == "VLANID")

{
item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
PublisherGoose[i].VLANID));

item.SubItems[item.SubItems.Count - 1].Tag = "VLANID";

else if (lstViewGOOSEPublisherConf.Columns[j].Tag.ToString() == "APPID")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
PublisherGoose[i].APPIDComm));

item.SubItems[item.SubItems.Count - 1].Tag = "APPID";

else if (lstViewGOOSEPublisherConf.Columns[j].Tag.ToString() == "GOOSEID")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
PublisherGoose[i].ID));

item.SubItems[item.SubItems.Count - 1].Tag = "GOOSEID";

else if (lstViewGOOSEPublisherConf.Columns[j].Tag.ToString() ==
"VLANPRIORITY")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
PublisherGoose[i].VLANPRIORITY));

item.SubItems[item.SubItems.Count - 1].Tag = "VLANPRIORITY";

else if (lstViewGOOSEPublisherConf.Columns[j].Tag.ToString() == "DESC")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
PublisherGoose[i].desc));

item.SubItems[item.SubItems.Count - 1].Tag = "DESC";

else if (lstViewGOOSEPublisherConf.Columns[j].Tag.ToString() == "CONFREV")


{

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
PublisherGoose[i].confRev));

item.SubItems[item.SubItems.Count - 1].Tag = "CONFREV";

else if (lstViewGOOSEPublisherConf.Columns[j].Tag.ToString() == "MAXTIME")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
PublisherGoose[i].MaxTime.ToString()));

item.SubItems[item.SubItems.Count - 1].Tag = "MAXTIME";

else if (lstViewGOOSEPublisherConf.Columns[j].Tag.ToString() == "MINTIME")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
PublisherGoose[i].MinTime.ToString()));

item.SubItems[item.SubItems.Count - 1].Tag = "MINTIME";

//item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
PublisherGoose[i].IsPublisher ? "Yes" : "No"));

item.Tag = PublisherGoose[i];

lstViewGOOSEPublisherConf.Items.Add(item);

if (!PublisherGoose[i].IsPublisher)

item.ForeColor = Color.FromArgb(172, 168, 153);

if (lstViewGOOSEPublisherConf.Items.Count > 0)
{

btnPrintGOCB.Enabled = true;

btnDeleteGOCB.Enabled = true;

btnEditGOCB.Enabled = true;

btnEditGOCBDataset.Enabled = true;

if (ItemToSelect == "")

lstViewGOOSEPublisherConf.Items[0].Selected = true;

else

for (int i = 0; i < lstViewGOOSEPublisherConf.Items.Count; i++)

if (lstViewGOOSEPublisherConf.Items[i].Text == ItemToSelect)

lstViewGOOSEPublisherConf.Items[i].Selected = true;

lstViewGOOSEPublisherConf.Items[i].EnsureVisible();

break;

else

btnPrintGOCB.Enabled = false;

btnDeleteGOCB.Enabled = false;

btnEditGOCB.Enabled = false;
btnEditGOCBDataset.Enabled = false;

catch { }

finally

FillGOOSEPub = false;

/// <summary>

/// Fills GOOSE subscriber details of an IED

/// </summary>

/// <param name="IEDName">IED Name</param>

private void FillGooseSubscriberDetails()

try

grpGOOSESub.Text = "IEDs mapped to " + base.iedDev.IEDDeviceInstanceName;

lstViewGOOSESubscriberConf.Items.Clear();

if (base.iedDev.SCLConfiguration == null)

return;

if (base.iedDev.SCLConfiguration.IEDs.Count == 0)

return;

IED ied = base.iedDev.SCLConfiguration.IEDs[0];


if (ied != null)

if (ied.AccessPoints[0].BooleanIEC61850Inputs != null)

AddGOOSESubscriber(ied.AccessPoints[0].BooleanIEC61850Inputs);

if (ied.AccessPoints[0].AnalogFloatIEC61850Inputs != null)

AddGOOSESubscriber(ied.AccessPoints[0].AnalogFloatIEC61850Inputs);

if (lstViewGOOSESubscriberConf.Items.Count > 0)

lstViewGOOSESubscriberConf.Items[0].Selected = true;

btnEditsubscriber.Enabled = true;

else

btnEditsubscriber.Enabled = false;

if (!Global.CurrentUser.IEC61850Configuration)

Disablebuttons();

catch(Exception ex)

{
LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

/// <summary>

/// Adds the subscriber details to listview

/// </summary>

/// <param name="VI"></param>

void AddGOOSESubscriber(List<VI> VI)

bool Skip = false;

ListViewItem item = null;

for (int i = 0; i < VI.Count; i++)

Skip = false;

if (VI[i].IsMapped)

for (int j = 0; j < lstViewGOOSESubscriberConf.Items.Count; j++)

if (lstViewGOOSESubscriberConf.Items[j].SubItems[0].Text == VI[i].MappedIED &&

lstViewGOOSESubscriberConf.Items[j].SubItems[2].Text == VI[i].MappedGOOSE &&

lstViewGOOSESubscriberConf.Items[j].SubItems[1].Text == VI[i].MappedLDevice)

Skip = true;

break;

}
if (!Skip)

item = new ListViewItem(VI[i].MappedIED);

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, VI[i].MappedLDevice));

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, VI[i].MappedGOOSE));

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, VI[i].MappedDataSet));

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
VI[i].MappedMACAddress));

try

if (WorkSpace.CurrentProject.IEDDeviceCollection[VI[i].MappedIED] != null)

IED iedmapped =
WorkSpace.CurrentProject.IEDDeviceCollection[VI[i].MappedIED].SCLConfiguration.IEDs[0];

if (iedmapped != null)

LDevice ldev = iedmapped.AccessPoints[0].GetLDevice(VI[i].MappedLDevice);

if (ldev != null)

GSEControl gse = ldev.GetGooseControlBlock(VI[i].MappedGOOSE);

if (gse != null)

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
gse.MACAddress));

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, gse.VLANID));

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
gse.APPIDComm));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
gse.VLANPRIORITY));

catch { }

lstViewGOOSESubscriberConf.Items.Add(item);

bool FillRCBPub = false;

/// <summary>

/// Fills Report Control Blocks of an IED

/// </summary>

/// <param name="ItemToSelect"></param>

private void FillReportControlBlocks(string ItemToSelect)

try

lstRCB.Items.Clear();

FillRCBPub = true;

if (base.iedDev.SCLConfiguration == null)

return;

if (base.iedDev.SCLConfiguration.IEDs.Count == 0)
return;

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied != null)

//Buffered Reports

List<ReportControlBlock> rcbList = ied.AccessPoints[0].GetAllReportControlBlocks(true);

AddReportControlBlocksToLst(rcbList);

//Un Buffered Reports

rcbList = ied.AccessPoints[0].GetAllReportControlBlocks(false);

AddReportControlBlocksToLst(rcbList);

if (rcbList != null)

if (lstRCB.Items.Count > 0)

btnPrintRCB.Enabled = true;

btnDeleteRCB.Enabled = true;

btnEditRCB.Enabled = true;

btnEditRCBDataset.Enabled = true;

if (ItemToSelect == "")

lstRCB.Items[0].Selected = true;

else

for (int i = 0; i < lstRCB.Items.Count; i++)

{
if (lstRCB.Items[i].Text == ItemToSelect)

lstRCB.Items[i].Selected = true;

lstRCB.Items[i].EnsureVisible();

break;

else

btnPrintRCB.Enabled = false;

btnDeleteRCB.Enabled = false;

btnEditRCB.Enabled = false;

btnEditRCBDataset.Enabled = false;

if (!Global.CurrentUser.IEC61850Configuration)

Disablebuttons();

catch (Exception ex)

LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

}
finally

FillRCBPub = false;

/// <summary>

/// Add list of report control blocks to listview

/// </summary>

/// <param name="rcbList"></param>

private void AddReportControlBlocksToLst(List<ReportControlBlock> rcbList)

ListViewItem item;

for (int i = 0; i < rcbList.Count; i++)

item = new ListViewItem(rcbList[i].CBLDeviceName + "." + rcbList[i].prefix + rcbList[i].lnClass


+ rcbList[i].inst + "." + rcbList[i].name, 0);

item.Checked = rcbList[i].IsPublisher;

if (rcbList[i].DataSetName != null && rcbList[i].DataSetName != "")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, rcbList[i].CBLDeviceName +


"." + rcbList[i].prefix + rcbList[i].lnClass + rcbList[i].inst + "." + rcbList[i].DataSetName));

item.SubItems[item.SubItems.Count - 1].Tag = "DS";

else

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));

item.SubItems[item.SubItems.Count - 1].Tag = "DS";

}
for (int j = 0; j < lstRCB.Columns.Count; j++)

if (lstRCB.Columns[j].Tag != null)

if (lstRCB.Columns[j].Tag.ToString() == "ID")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, rcbList[i].ID));

item.SubItems[item.SubItems.Count - 1].Tag = "ID";

else if (lstRCB.Columns[j].Tag.ToString() == "ISBUF")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, rcbList[i].Buffered ?


"Buffered" : "Un Buffered"));

item.SubItems[item.SubItems.Count - 1].Tag = "ISBUF";

else if (lstRCB.Columns[j].Tag.ToString() == "BUFTIME")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
rcbList[i].BufferTime.ToString()));

item.SubItems[item.SubItems.Count - 1].Tag = "BUFTIME";

else if (lstRCB.Columns[j].Tag.ToString() == "INTPRD")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
rcbList[i].IntegrityPeriod.ToString()));

item.SubItems[item.SubItems.Count - 1].Tag = "INTPRD";

else if (lstRCB.Columns[j].Tag.ToString() == "NOINST")

{
item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
rcbList[i].NoOfInstances.ToString()));

item.SubItems[item.SubItems.Count - 1].Tag = "NOINST";

else if (lstRCB.Columns[j].Tag.ToString() == "OPT")

item.SubItems.Add(new
ListViewItem.ListViewSubItem(item,IEC61850Utililty.getBinaryFormatForRCBOptionsFields(rcbList[i].
OptFields)));

item.SubItems[item.SubItems.Count - 1].Tag = "OPT";

else if (lstRCB.Columns[j].Tag.ToString() == "TRIG")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
IEC61850Utililty.getBinaryFormatForRCBTriggerOptions(rcbList[i].TrgOps)));

item.SubItems[item.SubItems.Count - 1].Tag = "TRIG";

else if (lstRCB.Columns[j].Tag.ToString() == "DESC")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, rcbList[i].desc));

item.SubItems[item.SubItems.Count - 1].Tag = "DESC";

item.Tag = rcbList[i];

lstRCB.Items.Add(item);

if (!rcbList[i].IsPublisher)

{
item.ForeColor = Color.FromArgb(172, 168, 153);

bool FilllogPub = false;

/// <summary>

/// Fills Log Control Blocks of an IED

/// </summary>

/// <param name="ItemToSelect"></param>

private void FillLogControlBlocks(string ItemToSelect)

try

lstLogControlBlocks.Items.Clear();

FilllogPub = true;

if (base.iedDev.SCLConfiguration == null)

return;

if (base.iedDev.SCLConfiguration.IEDs.Count == 0)

return;

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied != null)

//Buffered Reports

List<LogControl> rcbList = ied.AccessPoints[0].GetAllLogControlBlocks();

for (int i = 0; i < rcbList.Count; i++)

{
ListViewItem item = new ListViewItem(rcbList[i].CBLDeviceName + "." + rcbList[i].prefix
+ rcbList[i].lnClass + rcbList[i].inst + "." + rcbList[i].name, 0);

item.Checked = rcbList[i].IsPublisher;

if (rcbList[i].DataSetName != null && rcbList[i].DataSetName != "")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
rcbList[i].CBLDeviceName + "." + rcbList[i].prefix + rcbList[i].lnClass + rcbList[i].inst + "." +
rcbList[i].DataSetName));

item.SubItems[item.SubItems.Count - 1].Tag = "DS";

else

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));

item.SubItems[item.SubItems.Count - 1].Tag = "DS";

for (int j = 0; j < lstLogControlBlocks.Columns.Count; j++)

if (lstLogControlBlocks.Columns[j].Tag != null)

if (lstLogControlBlocks.Columns[j].Tag.ToString() == "ID")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
rcbList[i].LogName));

item.SubItems[item.SubItems.Count - 1].Tag = "ID";

else if (lstLogControlBlocks.Columns[j].Tag.ToString() == "INTPRD")

{
item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
rcbList[i].IntegrityPeriod.ToString()));

item.SubItems[item.SubItems.Count - 1].Tag = "INTPRD";

else if (lstLogControlBlocks.Columns[j].Tag.ToString() == "TRIG")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
IEC61850Utililty.getBinaryFormatForRCBTriggerOptions(rcbList[i].TrgOps)));

item.SubItems[item.SubItems.Count - 1].Tag = "TRIG";

else if (lstLogControlBlocks.Columns[j].Tag.ToString() == "LOGE")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
rcbList[i].LogEnable.ToString()));

item.SubItems[item.SubItems.Count - 1].Tag = "DESC";

else if (lstLogControlBlocks.Columns[j].Tag.ToString() == "RSN")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
rcbList[i].ReasonCode.ToString()));

item.SubItems[item.SubItems.Count - 1].Tag = "DESC";

else if (lstLogControlBlocks.Columns[j].Tag.ToString() == "DESC")

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, rcbList[i].desc));

item.SubItems[item.SubItems.Count - 1].Tag = "DESC";

}
}

item.Tag = rcbList[i];

lstLogControlBlocks.Items.Add(item);

if (!rcbList[i].IsPublisher)

item.ForeColor = Color.FromArgb(172, 168, 153);

if (rcbList != null)

if (lstLogControlBlocks.Items.Count > 0)

btnPrintLog.Enabled = true;

// btnDeletel.Enabled = true;

btnPrintLog.Enabled = true;

btnEditDsLog.Enabled = true;

if (ItemToSelect == "")

lstLogControlBlocks.Items[0].Selected = true;

else

for (int i = 0; i < lstLogControlBlocks.Items.Count; i++)

if (lstLogControlBlocks.Items[i].Text == ItemToSelect)

{
lstLogControlBlocks.Items[i].Selected = true;

lstLogControlBlocks.Items[i].EnsureVisible();

break;

else

btnPrintLog.Enabled = false;

// btnDeleteRCB.Enabled = false;

btnPrintLog.Enabled = false;

btnEditDsLog.Enabled = false;

if (!Global.CurrentUser.IEC61850Configuration)

Disablebuttons();

catch (Exception ex)

LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

finally

{
FilllogPub = false;

bool FillDataset = false;

/// <summary>

/// Fills datasets

/// </summary>

/// <param name="TextSelect"></param>

private void FillDataSets(string TextSelect)

try

lstDataSets.Items.Clear();

trvDataSet.Nodes.Clear();

if (base.iedDev.SCLConfiguration == null)

return;

if (base.iedDev.SCLConfiguration.IEDs.Count == 0)

return;

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied != null)

FillDataset = true;

List<DataSet> datasets = ied.AccessPoints[0].GetAllDataSets();

if (datasets != null)

for (int i = 0; i < datasets.Count; i++)


{

ListViewItem item = new ListViewItem(datasets[i].DataSetLDeviceName + "." +


datasets[i].prefix + datasets[i].lnClass + datasets[i].lninst + "." + datasets[i].DataSetName);

item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
datasets[i].Description));

item.Tag = datasets[i];

item.ImageIndex = 1;

string refgoose = "";

string refrcb = "";

string refsmv = "";

LDevice ldev = ied.AccessPoints[0].GetLDevice(datasets[i].DataSetLDeviceName);

if (ldev != null)

Dictionary<string, string> refrencedCB =


ldev.GetGOOSEReferencesofDataset(datasets[i].DataSetName, datasets[i].prefix + datasets[i].lnClass
+ datasets[i].lninst);

foreach (string val in refrencedCB.Values)

if (refgoose == "")

refgoose += val;

else

refgoose += " , " + val;

refrencedCB = ldev.GetRCBReferencesofDataset(datasets[i].DataSetName,
datasets[i].prefix + datasets[i].lnClass + datasets[i].lninst);

foreach (string val in refrencedCB.Values)


{

if (refrcb == "")

refrcb += val;

else

refrcb += " , " + val;

refrencedCB = ldev.GetSMVReferencesofDataset(datasets[i].DataSetName,
datasets[i].prefix + datasets[i].lnClass + datasets[i].lninst);

foreach (string val in refrencedCB.Values)

if (refsmv == "")

refsmv += val;

else

refsmv += " , " + val;

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, refgoose));

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, refrcb));

item.SubItems.Add(new ListViewItem.ListViewSubItem(item, refsmv));

if (refgoose == "" && refrcb == "")

//item.ForeColor = Color.FromArgb(172, 168, 153);

lstDataSets.Items.Add(item);

}
}

if (TextSelect != "")

for (int i = 0; i < lstDataSets.Items.Count; i++)

if (lstDataSets.Items[i].Text == TextSelect)

lstDataSets.Items[i].Selected = true;

lstDataSets.Items[i].EnsureVisible();

btnDeleteDataset.Enabled = true;

btnCloneDataset.Enabled = true;

btnEditDs.Enabled = true;

return;

if (lstDataSets.Items.Count > 0)

lstDataSets.Items[0].Selected = true;

btnEditDs.Enabled = true;

btnDeleteDataset.Enabled = true;

btnCloneDataset.Enabled = true;

else

{
btnEditDs.Enabled = false;

btnDeleteDataset.Enabled = false;

btnCloneDataset.Enabled = false;

if (!Global.CurrentUser.IEC61850Configuration)

Disablebuttons();

catch (Exception ex)

LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

finally

FillDataset = false;

/// <summary>

/// SelectedIndexChanged event handler of lstDataSets

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstDataSets_SelectedIndexChanged(object sender, EventArgs e)

{
try

trvDataSet.Nodes.Clear();

if (lstDataSets.SelectedItems.Count == 1)

DataSet ds = (DataSet)lstDataSets.SelectedItems[0].Tag;

if (ds != null)

if (ds.Items.Count > 0)

trvDataSet.BeginUpdate();

trvDataSet.Nodes.Add(ds.DataSetName, ds.DataSetName, 1, 1);

DisplayUtil.FillDataSetItems(trvDataSet.Nodes[0], ds, false);

trvDataSet.Nodes[0].Expand();

trvDataSet.EndUpdate();

trvDataSet.Refresh();

if (sender != null)

SetLdeviceSelected(ds.DataSetLDeviceName);

else

}
}

catch { }

/// <summary>

/// Select the specified Ldevice in drop down list

/// </summary>

/// <param name="ldevice"></param>

private void SetLdeviceSelected(string ldevice)

for (int i = 0; i < cmbLogicalDevices.Items.Count; i++)

if (cmbLogicalDevices.Items[i].ToString() == ldevice)

cmbLogicalDevices.SelectedIndex = i;

break;

/// <summary>

/// SelectedIndexChanged event handler cmbLogicalDevices

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void cmbLogicalDevices_SelectedIndexChanged(object sender, EventArgs e)

if (cmbLogicalDevices.SelectedIndex > -1)


{

try

this.Cursor = Cursors.WaitCursor;

DisplayUtil.FillIEDDataItems(trvIEDDataItems, base.iedDev.SCLConfiguration.IEDs[0],
cmbLogicalDevices.Text);

this.Cursor = Cursors.Default;

catch { this.Cursor = Cursors.Default; }

/// <summary>

/// ItemDrag event handler of trvIEDDataItems

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void trvIEDDataItems_ItemDrag(object sender, ItemDragEventArgs e)

try

if (!Global.CurrentUser.IEC61850Configuration)

return;

int Level = (e.Item as TreeNode).Level;

if (Level >= 2)

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied != null)

{
trvIEDDataItems.PaintSelectedNodes();

trvIEDDataItems.SelectedNode = (TreeNode)e.Item;

object objItemDragged = ((TreeNode)e.Item).Tag;

IEDDataItemDrag = true;

this.Cursor = Cursors.Default;

trvIEDDataItems.DoDragDrop(trvIEDDataItems.SelectedNodes, DragDropEffects.Copy);

Point point = GetTreeViewScrollPos(trvIEDDataItems);

catch { }

/// <summary>

/// Gets scrollbar position of treeview

/// </summary>

/// <param name="treeView"></param>

/// <returns></returns>

private Point GetTreeViewScrollPos(TreeView treeView)

return new Point(

GetScrollPos((int)treeView.Handle, SB_HORZ),

GetScrollPos((int)treeView.Handle, SB_VERT));

bool IEDDataItemDrag = false;

bool dragInDataset = false;


/// <summary>

/// DragEnter event handler of trvDataSet

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void trvDataSet_DragEnter(object sender, DragEventArgs e)

if (e.Data.GetDataPresent(typeof(System.Collections.ArrayList)) && IEDDataItemDrag)

e.Effect = DragDropEffects.Copy;

else

if (e.Data.GetDataPresent(typeof(System.Collections.ArrayList)) && dragInDataset)

e.Effect = DragDropEffects.Copy;

else

e.Effect = DragDropEffects.None;

/// <summary>

/// DragDrop event handler of trvDataSet

/// </summary>

/// <param name="sender"></param>


/// <param name="e"></param>

private void trvDataSet_DragDrop(object sender, DragEventArgs e)

try

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

IED iedSel = base.iedDev.SCLConfiguration.IEDs[0];

string selectedIED = base.iedDev.IEDDeviceInstanceName;

if (lstDataSets.SelectedItems.Count == 0)

MessageBox.Show("Please select a dataset from the list to modify.", "Warning",


MessageBoxButtons.OK, MessageBoxIcon.Warning);

return;

DataSet ds = (DataSet)lstDataSets.SelectedItems[0].Tag;

if (ds == null)

MessageBox.Show("Please select a valid dataset from the list to modify.", "Warning",


MessageBoxButtons.OK, MessageBoxIcon.Warning);

return;

bool DataSetAdded = false;

if (e.Data.GetDataPresent(typeof(System.Collections.ArrayList)) && IEDDataItemDrag)


{

DataSetAdded = false;

IEDDataItemDrag = false;

TreeNode nodeDestination = trvDataSet.HitTest(trvDataSet.PointToClient(new Point(e.X,


e.Y))).Node;

System.Collections.ArrayList nodeList =
e.Data.GetData(typeof(System.Collections.ArrayList)) as System.Collections.ArrayList;

string strRef = "";

string strCurrentFCDA = "";

string strPath1 = "";

int Cursize = 0;

List<FCDA> fcdaList = new List<FCDA>();

List<FCDA> fcdaListParent = new List<FCDA>();

List<FCDA> fcdaListChild = new List<FCDA>();

TreeNode nodeParent = null;

foreach (object node in nodeList)

if (nodeParent == null)

nodeParent = (TreeNode)node;

nodeParent = nodeParent.Parent;

fcdaList.Add(DataSetEditUtil.CreateFCDAElement((TreeNode)node,
cmbLogicalDevices.Text));

while (nodeParent.Level != 0)

fcdaListParent.Add(DataSetEditUtil.CreateFCDAElement((TreeNode)nodeParent,
cmbLogicalDevices.Text));

nodeParent = nodeParent.Parent;

nodeParent = (TreeNode)node;
foreach (TreeNode nodec in nodeParent.Nodes)

FindChildNodeFCDA(nodec, fcdaListChild);

strCurrentFCDA = fcdaList[fcdaList.Count - 1].ldInst + "/" + fcdaList[fcdaList.Count -


1].prefix + fcdaList[fcdaList.Count - 1].lnClass + fcdaList[fcdaList.Count - 1].lnInst + "$" +
fcdaList[fcdaList.Count - 1].fc;

if (fcdaList[fcdaList.Count - 1].doname != null)

strCurrentFCDA += "$" + fcdaList[fcdaList.Count - 1].doname.Replace('.', '$');

if (fcdaList[fcdaList.Count - 1].daname != null)

strCurrentFCDA += "$" + fcdaList[fcdaList.Count - 1].daname.Replace('.', '$');

foreach (FCDA fcda in fcdaListParent)

if (ds.CheckDuplicateFCDA(fcda, ref strPath1))

MessageBox.Show("fcda element('" + strPath1 + "') containing the selected \ndata


item('" + strCurrentFCDA + "') is present in the dataset.", "Warning", MessageBoxButtons.OK,
MessageBoxIcon.Error);

return;

foreach (FCDA fcda in fcdaListChild)

if (ds.CheckDuplicateFCDA(fcda, ref strPath1))


{

MessageBox.Show("Data item('" + strPath1 + "') inside the selected \nfcda


element('" + strCurrentFCDA + "') is present in the dataset.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

return;

Cursize = IEC61850Utililty.GetSizeOfDataSet(ds);

if (IEC61850Utililty.IsDataSetRefInGoose(ds, ref strRef, iedSel ))

List<DataSet> dsOthers = GetAllOtherDatasetRefByGOOSE(iedSel.IEDInstanceName,


ds.DataSetName);

foreach (DataSet dss in dsOthers)

foreach (FCDA fcda in fcdaListParent)

if (dss.CheckDuplicateFCDA(fcda, ref strPath1))

MessageBox.Show("fcda element('" + strPath1 + "') containing the selected \


ndata item('" + strCurrentFCDA + "') is present in another \ndataset '" + dss.DataSetLDeviceName +
".LLN0." + dss.DataSetName + "' which is refrenced by a GOOSE.", "Warning",
MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

foreach (FCDA fcda in fcdaListChild)

if (dss.CheckDuplicateFCDA(fcda, ref strPath1))

{
MessageBox.Show("Data item('" + strPath1 + "') inside the selected \nfcda
element('" + strCurrentFCDA + "') is present in another \ndataset '" + dss.DataSetLDeviceName +
".LLN0." + dss.DataSetName + "' which is refrenced by a GOOSE.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

return;

foreach (FCDA fcda in fcdaList)

if (dss.CheckDuplicateFCDA(fcda, ref strPath1))

MessageBox.Show("FCDA item('" + strPath1 + "') is present in another \ndataset


'" + dss.DataSetLDeviceName + ".LLN0." + dss.DataSetName + "' which is refrenced by a GOOSE.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

if (Cursize > IEC61850Utililty.MaxAllowedDataSetSizeForGOOSE)

MessageBox.Show("No more items can be added to this dataset.\nThe size of the


dataset is exceeded the maximum allowed for a GOOSE.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

return;

int size = 0;

foreach (FCDA fcda in fcdaList)

size += IEC61850Utililty.GetSizeofFCDA(fcda);
if (Cursize + size > IEC61850Utililty.MaxAllowedDataSetSizeForGOOSE)

MessageBox.Show("Adding this elemet will exceed the maximum size of the


dataset referenced by a goose .", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

if (IEC61850Utililty.IsDatasetRefInRCB(ds, ref strRef,iedSel ))

if (Cursize > IEC61850Utililty.MaxAllowedDataSetSizeForRCB)

MessageBox.Show("No more items can be added to this dataset.\nThe size of the


dataset is exceeded the maximum allowed for a RCB.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

return;

int size = 0;

foreach (FCDA fcda in fcdaList)

size += IEC61850Utililty.GetSizeofFCDA(fcda);

if (Cursize + size > IEC61850Utililty.MaxAllowedDataSetSizeForRCB)

MessageBox.Show("Adding this elemet will exceed the maximum size of the


dataset referenced by a report control block .", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

return;

}
}

string strPath = "";

foreach (FCDA fcda in fcdaList)

if (ds != null)

//FCDA fcda = DataSetEditUtil.CreateFCDAElement((TreeNode)node,


cmbLogicalDevices.Text);

if (fcda != null)

if (!ds.CheckDuplicateFCDA(fcda, ref strPath))

DataSetAdded = true;

ds.Items.Add(fcda);

Global.ProjectSaveRequired = true;

else

MessageBox.Show("Duplicate FCDA element '" + strPath + "' in the dataset!.",


"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

break;

}
}

if (DataSetAdded)

lstDataSets_SelectedIndexChanged(null, null);

//SetScrollPos((IntPtr)trvDataSet.Handle, SB_VERT, 200, true);

if (trvDataSet.Nodes.Count > 0)

if (trvDataSet.Nodes[0].Nodes.Count > 0)

trvDataSet.Nodes[0].Nodes[trvDataSet.Nodes[0].Nodes.Count - 1].EnsureVisible();

else if (e.Data.GetDataPresent(typeof(System.Collections.ArrayList)) && dragInDataset)

dragInDataset = false;

DataSetAdded = false;

TreeNode nodeDestination = trvDataSet.HitTest(trvDataSet.PointToClient(new Point(e.X,


e.Y))).Node;

if (nodeDestination.Level == 0)

return;

nodeDestination.ForeColor = Color.Black;

// System.Collections.ArrayList nodeList =
e.Data.GetData(typeof(System.Collections.ArrayList)) as System.Collections.ArrayList;

if (trvDataSet.SelectedNodes.Contains(nodeDestination))

return;
}

if (trvDataSet.SelectedNodes.Count == 0)

return;

trvDataSet.skipSelect = true;

int index = 0;

TreeNode nodeFirst = (TreeNode)trvDataSet.SelectedNodes[0];

if (nodeDestination.Index < nodeFirst.Index)

for (int i = 0; i < trvDataSet.SelectedNodes.Count; i++)

TreeNode node = (TreeNode)trvDataSet.SelectedNodes[i];

if (node.Index == 0)

return;

//if (node.Index < node.Parent.Nodes.Count - 1)

//{

FCDA dobject = (FCDA)node.Tag;

ds.Items.RemoveAt(node.Index);

index = nodeDestination.Index;

ds.Items.Insert(index, dobject);

trvDataSet.Nodes[0].Nodes.RemoveAt(node.Index);

trvDataSet.Nodes[0].Nodes.Insert(index, node);

Global.ProjectSaveRequired = true;

DataSetAdded = true;

//}

}
else if (nodeDestination.Index > nodeFirst.Index)

for (int i = trvDataSet.SelectedNodes.Count - 1; i >= 0; i--)

TreeNode node = (TreeNode)trvDataSet.SelectedNodes[i];

if (node.Index == node.Parent.Nodes.Count - 1)

return;

// if (node.Index < node.Parent.Nodes.Count - 1)

//{

FCDA dobject = (FCDA)node.Tag;

ds.Items.RemoveAt(node.Index);

index = nodeDestination.Index;

ds.Items.Insert(index, dobject);

trvDataSet.Nodes[0].Nodes.RemoveAt(node.Index);

trvDataSet.Nodes[0].Nodes.Insert(index, node);

Global.ProjectSaveRequired = true;

DataSetAdded = true;

// }

trvDataSet.SelectedNode = trvDataSet.Nodes[0].Nodes[index];

if (DataSetAdded)

iedSel.AccessPoints[0].UpdateDataset(ds.DataSetName, ds.DataSetLDeviceName,
ds.prefix + ds.lnClass + ds.lninst, ds);

string gooseRef = "";

if (IEC61850Utililty.IsDataSetRefInGoose(ds, ref gooseRef, iedSel))


{

this.Cursor = Cursors.WaitCursor;

DisplayUtil.UpdateIEDNodeGSE(iedSel);

Global.NotifyReloadIEDGOOSENode(iedSel);

this.Cursor = Cursors.Default;

if (IEC61850Utililty.IsDataSetRefInSMV(ds, ref gooseRef, iedSel))

this.Cursor = Cursors.WaitCursor;

DisplayUtil.UpdateIEDNodeSMV(iedSel);

Global.NotifyReloadIEDSmvNode(iedSel);

this.Cursor = Cursors.Default;

// UpdateReportDataset(ds);

//if (trvDataSet.Nodes.Count > 0)

// ResetNodeForeColor(trvDataSet.Nodes[0].Nodes);

catch (Exception ex)

LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

finally { this.Cursor = Cursors.Default; trvDataSet.skipSelect = false; }

/// <summary>

/// Gets the list of DataSets referenced by GOOSE except the specified one
/// </summary>

/// <param name="IEDName"></param>

/// <param name="DSSkip"></param>

/// <returns></returns>

private List<DataSet> GetAllOtherDatasetRefByGOOSE(string IEDName, string DSSkip)

List<DataSet> dsResult = new List<DataSet>();

IED ied;

string gseRef = "";

ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied != null)

List<DataSet> dsList = ied.AccessPoints[0].GetAllDataSets();

foreach (DataSet ds in dsList)

if (ds.DataSetName != DSSkip)

if (IEC61850Utililty.IsDataSetRefInGoose(ds, ref gseRef, ied))

dsResult.Add(ds);

return dsResult;
}

/// <summary>

/// Finds the FCDA element of treenode and adds to list

/// </summary>

/// <param name="node"></param>

/// <param name="fcdaListChild"></param>

private void FindChildNodeFCDA(TreeNode node, List<FCDA> fcdaListChild)

try

fcdaListChild.Add(DataSetEditUtil.CreateFCDAElement(node, cmbLogicalDevices.Text));

foreach (TreeNode nodeChild in node.Nodes)

FindChildNodeFCDA(nodeChild, fcdaListChild);

catch { }

/// <summary>

/// Click event handler of btnEditGOCB. Pops up the form for editing a GOOSE control block.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnEditGOCB_Click(object sender, EventArgs e)

{
try

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

//if (trvProject.SelectedNode.Level == 2)

if (lstViewGOOSEPublisherConf.SelectedItems.Count == 1)

frmEditGOOSE frmedit = new frmEditGOOSE();

frmedit.cblock = (GSEControl)lstViewGOOSEPublisherConf.SelectedItems[0].Tag;

GSEControl beforeedit = (GSEControl)frmedit.cblock.Clone();

frmedit.ied = base.iedDev.SCLConfiguration.IEDs[0];

frmedit.edit = true;

if (frmedit.ShowDialog() == DialogResult.OK && !


IEC61850Utililty.IsGSEControlBlockSame(beforeedit, frmedit.cblock))

FillGoosePublisherDetails(lstViewGOOSEPublisherConf.SelectedItems[0].Text);

// GooseSubTabIEDName = "";

if (beforeedit.DataSetName != frmedit.cblock.DataSetName)

this.Cursor = Cursors.WaitCursor;

DisplayUtil.UpdateIEDNodeGSE(frmedit.ied);
Global.NotifyReloadIEDGOOSENode(frmedit.ied);

Global.ProjectSaveRequired = true;

if (frmedit != null)

frmedit.Dispose();

else

MessageBox.Show("Please select a GOOSE control bolck.", "Message",


MessageBoxButtons.OK, MessageBoxIcon.Warning);

catch { }

finally

this.Cursor = Cursors.Default;

/// <summary>

/// MouseDoubleClick event handler of lstViewGOOSEPublisherConf

/// </summary>

/// <param name="sender"></param>


/// <param name="e"></param>

private void lstViewGOOSEPublisherConf_MouseDoubleClick(object sender, MouseEventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

return;

if (lstViewGOOSEPublisherConf.SelectedItems.Count == 1 && btnEditGOCB.Enabled)

btnEditGOCB_Click(null, null);

/// <summary>

/// Click event handler of btnEditRCB.Pops up the form for editing a Report control block.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnEditRCB_Click(object sender, EventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (lstRCB.SelectedItems.Count == 1)

frmAddRCB frmrcb = new frmAddRCB();

frmrcb.ied = base.iedDev.SCLConfiguration.IEDs[0];

frmrcb.bedit = true;
frmrcb.rcbEdit = (ReportControlBlock)lstRCB.SelectedItems[0].Tag;

ReportControlBlock beforeedit = (ReportControlBlock)frmrcb.rcbEdit.Clone();

if (frmrcb.ied != null)

if (frmrcb.ShowDialog() == DialogResult.OK && !


IEC61850Utililty.IsReportControlBlockSame(beforeedit, frmrcb.rcbEdit))

FillReportControlBlocks(lstRCB.SelectedItems[0].Text );

this.Cursor = Cursors.Default;

Global.ProjectSaveRequired = true;

/// <summary>

/// MouseDoubleClick event handler of lstRCB

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstRCB_MouseDoubleClick(object sender, MouseEventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

return;

if (lstRCB.SelectedItems.Count == 1 && btnEditRCB.Enabled)

btnEditRCB_Click(null, null);
}

/// <summary>

/// Click event handler of btnNewRCB.Pops up the form for adding a Report control block.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnNewRCB_Click(object sender, EventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

frmAddRCB frmrcb = new frmAddRCB();

frmrcb.ied = base.iedDev.SCLConfiguration.IEDs[0];

frmrcb.bedit = false;

if (frmrcb.ied != null)

if (frmrcb.ShowDialog() == DialogResult.OK)

FillReportControlBlocks(frmrcb.AddedRCB);

FillDataSets(lstDataSets.SelectedItems.Count > 0 ? lstDataSets.SelectedItems[0].Text : "");

Global.ProjectSaveRequired = true;

if (frmrcb != null)
frmrcb.Dispose();

/// <summary>

/// Click event handler of btnDeleteRCB. Deletes the selected Report control block

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnDeleteRCB_Click(object sender, EventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (lstRCB.SelectedItems.Count == 0)

MessageBox.Show("Please select a report control block to delete.", "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

bool bRcbDelete = false;

if (MessageBox.Show("Do you want to delete the selected Report Control Block/s?",


"Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)

return;

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied != null)
{

for (int i = 0; i < lstRCB.SelectedItems.Count; i++)

if (lstRCB.SelectedItems[i].Tag != null)

ReportControlBlock rpt = (ReportControlBlock)lstRCB.SelectedItems[i].Tag;

if (rpt != null)

if (rpt.Orginal)

MessageBox.Show("You can not delete the original Report control block '" +
rpt.name + "'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

continue;

LDevice ldev = ied.AccessPoints[0].GetLDevice(rpt.CBLDeviceName);

if (ldev != null)

if (ldev.RemoveReportControlBlock(rpt.name, rpt.prefix + rpt.lnClass + rpt.inst))

Global.NotifyLogWindow("Report Control Block '" + rpt.name + "' deleted from '"


+ ldev.inst + "/" + rpt.prefix + rpt.lnClass + rpt.inst + "' of IED '" + ied.IEDInstanceName + "'");

bRcbDelete = true;

}
if (bRcbDelete)

FillReportControlBlocks("");

FillDataSets(lstDataSets.SelectedItems.Count > 0 ? lstDataSets.SelectedItems[0].Text : "");

Global.ProjectSaveRequired = true;

/// <summary>

/// Click event handler of btnNewGOCB.Pops up form for adding GOOSE control block.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnNewGOCB_Click(object sender, EventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

frmLogicalDevices frmLDevice = new frmLogicalDevices();

frmLDevice.ied = base.iedDev.SCLConfiguration.IEDs[0];

if (frmLDevice.ied != null)

if (frmLDevice.ShowDialog() == DialogResult.OK)

{
frmEditGOOSE frmGSE = new frmEditGOOSE();

frmGSE.edit = false;

frmGSE.ied = frmLDevice.ied;

frmGSE.LDevice = frmLDevice.LDeivce;

//Saving for Goose list state for undo opration

LDevice ldev = frmLDevice.ied.AccessPoints[0].GetLDevice(frmGSE.LDevice);

if (ldev != null)

if (frmGSE.ShowDialog() == DialogResult.OK)

FillGoosePublisherDetails("");

Global.NotifyLogWindow("GOOSE Control Block '" + frmGSE.txtGOOSECBName.Text


+ "' added to '" + frmGSE.ied.IEDInstanceName + "/" + frmGSE.LDevice + "'");

// GooseSubTabIEDName = "";

this.Cursor = Cursors.WaitCursor;

DisplayUtil.UpdateIEDNodeGSE(frmGSE.ied);

FillDataSets(lstDataSets.SelectedItems.Count > 0 ?
lstDataSets.SelectedItems[0].Text : "");

this.Cursor = Cursors.Default;

Global.ProjectSaveRequired = true;

Global.NotifyReloadIEDGOOSENode(frmGSE.ied);

if (frmGSE != null)

frmGSE.Dispose();

}
if (frmLDevice != null)

frmLDevice.Dispose();

/// <summary>

/// FormClosing event handler of frmIEC61850Configuratio

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void frmIEC61850Configuration_FormClosing(object sender, FormClosingEventArgs e)

Global.OnUpdateGOOSELibrary -= (Global_OnIEDAdded);

Global.OnRenameIED -= (Global_OnRenameIED);

if (iedDev != null)

iedDev.OnIEDRenamed -= (iedDev_OnIEDRenamed);

/// <summary>

/// Click event handler of btnAddDataSet

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnAddDataSet_Click(object sender, EventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);
return;

frmAddDataSet frmadd = new frmAddDataSet();

frmadd.ied = iedDev.SCLConfiguration.IEDs[0];

if (frmadd.ied != null)

//if (frmadd.ied.AccessPoints[0].GetAllDataSets().Count >= 48)

//{

// MessageBox.Show("The number of maximum datasets allowed in an IED is 48 .",


"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

// return;

//}

if (frmadd.ShowDialog() == DialogResult.OK)

FillDataSets(frmadd.DataSetRef);

Global.ProjectSaveRequired = true;

if (frmadd != null)

frmadd.Dispose();

/// <summary>

/// Click event handler of btnDeleteDataset.Deletes the selected dataset.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>


private void btnDeleteDataset_Click(object sender, EventArgs e)

try

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (lstDataSets.SelectedItems.Count == 0)

MessageBox.Show("Please select a dataset to delete.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

string gooseRef = "";

bool DsDeleted = false;

IED ied = iedDev.SCLConfiguration.IEDs[0];

if (ied != null)

if (MessageBox.Show("Do you want to delete the selected dataset/s from " +


ied.IEDInstanceName + "?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
DialogResult.No)

return;

bool DoNotShowMsg = false;

for (int i = 0; i < lstDataSets.SelectedItems.Count; i++)

{
DataSet ds = ied.AccessPoints[0].GetDataSet(lstDataSets.SelectedItems[i].Text.Split('.')
[0], lstDataSets.SelectedItems[i].Text.Split('.')[2], lstDataSets.SelectedItems[i].Text.Split('.')[1]);

if (ds != null)

if (ds.Orginal)

MessageBox.Show("You can not delete the original dataset '" + ds.DataSetName +


"'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

continue;

LDevice ldev = ied.AccessPoints[0].GetLDevice(ds.DataSetLDeviceName);

if (ldev != null)

string[] strName = lstDataSets.SelectedItems[i].Text.Split('.');

string strReference = "";

Dictionary<string, string> refrencedgoose =


ldev.GetGOOSEReferencesofDataset(ds.DataSetName, ds.prefix + ds.lnClass + ds.lninst);

foreach (string val in refrencedgoose.Values)

if (strReference == "")

strReference += "GOOSE: " + val;

else

strReference += " , " + val;

Dictionary<string, string> refrencedrcb =


ldev.GetRCBReferencesofDataset(ds.DataSetName, ds.prefix + ds.lnClass + ds.lninst);

bool entry = true;

foreach (string val in refrencedrcb.Values)


{

if (strReference == "")

strReference += "RCB: " + val;

entry = false;

else

if (entry)

entry = false;

strReference += "\nRCB: " + val;

else

strReference += " , " + val;

Dictionary<string, string> refrencedSmv =


ldev.GetSMVReferencesofDataset(ds.DataSetName, ds.prefix + ds.lnClass + ds.lninst);

entry = true;

foreach (string val in refrencedSmv.Values)

if (strReference == "")

strReference += "SMV: " + val;


entry = false;

else

if (entry)

entry = false;

strReference += "\nSMV: " + val;

else

strReference += " , " + val;

if (strReference != "")

if (!DoNotShowMsg)

CustomMessageBox frmMsg = new CustomMessageBox();

frmMsg.displayCheckBox = lstDataSets.SelectedItems.Count > 1 ? true : false;

frmMsg.ErrorMessage = "Dataset '" + lstDataSets.SelectedItems[i].Text + "' can


not be deleted.\nIt is referenced by \n" + strReference + "";

if (frmMsg.ShowDialog() == DialogResult.OK)

DoNotShowMsg = frmMsg.DoNotShow;

}
}

// MessageBox.Show("Dataset '" + lstDataSets.SelectedItems[i].Text + "' can not


be deleted.\nIt is referenced by \n" + strReference + "", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

continue;

if (ldev.RemoveDataSet(ds.DataSetName, strName[1]))

Global.NotifyLogWindow("Dataset '" + ds.DataSetName + "' deleted from '" +


ds.DataSetLDeviceName + "/" + strName[1] + "' of IED '" + ied.IEDInstanceName + "'");

DsDeleted = true;

Global.ProjectSaveRequired = true;

if (DsDeleted)

FillDataSets("");

catch { }

/// <summary>

/// Click event handler of btnDeleteGOCB.Deletes selected GOOSE control blocks.

/// </summary>
/// <param name="sender"></param>

/// <param name="e"></param>

private void btnDeleteGOCB_Click(object sender, EventArgs e)

try

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (lstViewGOOSEPublisherConf.SelectedItems.Count > 0)

bool deleteGOOSE = false;

bool DoNotShowMsg = false;

IED ied = iedDev.SCLConfiguration.IEDs[0];

if (ied != null)

if (MessageBox.Show("Do you want to delete the selected GOOSE Control Block/s from
'" + ied.IEDInstanceName + "'?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.No)

return;

for (int i = 0; i < lstViewGOOSEPublisherConf.SelectedItems.Count; i++)

if (lstViewGOOSEPublisherConf.SelectedItems[i].Tag != null)

GSEControl gse = (GSEControl)lstViewGOOSEPublisherConf.SelectedItems[i].Tag;


string map = "";

if (gse.Orginal)

MessageBox.Show("You can not delete the original GOOSE control block '" +
gse.name + "'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

continue;

if (IEC61850Utililty.IsGOOSEUsedForMapping(gse, ied.IEDInstanceName, ref map))

if (!DoNotShowMsg)

CustomMessageBox frmMsg = new CustomMessageBox();

frmMsg.displayCheckBox = lstViewGOOSEPublisherConf.SelectedItems.Count
> 1 ? true : false;

frmMsg.ErrorMessage = "The selected GOOSE Control Block '" +


lstViewGOOSEPublisherConf.SelectedItems[i].Text + "' is used for mapping.\nYou can not delete this
GOOSE Control Block .";

if (frmMsg.ShowDialog() == DialogResult.OK)

DoNotShowMsg = frmMsg.DoNotShow;

//MessageBox.Show("The selected GOOSE Control Block '" +


lstViewGOOSEPublisherConf.SelectedItems[i].Text + "' is used for mapping.\nYou can not delete this
GOOSE Control Block .", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

continue;

LDevice ldev = ied.AccessPoints[0].GetLDevice(gse.CBLDeviceName);

if (ldev != null)

{
if (ldev.RemoveGSEControlBlock(gse.name))

deleteGOOSE = true;

Global.NotifyLogWindow("GOOSE Control Block '" + gse.name + "' deleted


from '" + ied.IEDInstanceName + "/" + gse.CBLDeviceName + "$LLN0'");

Global.ProjectSaveRequired = true;

if (deleteGOOSE)

//this.Cursor = Cursors.WaitCursor;

//IED_Config_Tool.V4.DisplayUtil.UpdateIEDNodeGSE(IED_Config_Tool.V4.ProjectUtil.project.IEDs[IE
D_Config_Tool.V4.ProjectUtil.SelectedIEDName]);

FillDataSets(lstDataSets.SelectedItems.Count > 0 ?
lstDataSets.SelectedItems[0].Text : "");

this.Cursor = Cursors.Default;

string strSelect = "";

//try

//{

// if (lstViewGOOSEPublisherConf.SelectedItems[0].Index <
lstViewGOOSEPublisherConf.Items.Count - 1)

// {

// strSelect =
lstViewGOOSEPublisherConf.Items[lstViewGOOSEPublisherConf.SelectedItems[0].Index + 1].Text;

// }

//}
//catch { }

FillGoosePublisherDetails(strSelect);

DisplayUtil.UpdateIEDNodeGSE(ied);

Global.NotifyReloadIEDGOOSENode(ied);

else

MessageBox.Show("Please select a GOOSE control bolck.", "Message",


MessageBoxButtons.OK, MessageBoxIcon.Warning);

catch { }

/// <summary>

/// Click event handler of btnEditGOCBDataset to navigate to dataset page with dataset of
GOOSE control block selected.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnEditGOCBDataset_Click(object sender, EventArgs e)

if (lstViewGOOSEPublisherConf.SelectedItems.Count == 1)

if (lstViewGOOSEPublisherConf.SelectedItems[0].Tag is GSEControl )

GSEControl gocb = (GSEControl)lstViewGOOSEPublisherConf.SelectedItems[0].Tag;


if (gocb.DataSetName != null)

for (int i = 0; i < tabMain.TabCount; i++)

if (tabMain.TabPages[i].Name == "pageDatasets")

tabMain.SelectedIndex = i;

string fulldsName = gocb.CBLDeviceName + ".LLN0." + gocb.DataSetName;

IEC61850Utililty.SetSelectItem(fulldsName, lstDataSets);

/// <summary>

/// Click event handler of btnEditRCBDataset to navigate to dataset page with dataset of Report
control block selected.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnEditRCBDataset_Click(object sender, EventArgs e)

if (lstRCB.SelectedItems.Count == 1 && lstRCB.SelectedItems[0].Tag is ReportControlBlock )

ReportControlBlock rcb = (ReportControlBlock)lstRCB.SelectedItems[0].Tag;

if (rcb.DataSetName == null || rcb.DataSetName == "")

{
return;

string fulldsName = rcb.CBLDeviceName + "." + rcb.prefix + rcb.lnClass + rcb.inst + "." +


rcb.DataSetName;

if (rcb.DataSetName != null)

for (int i = 0; i < tabMain.TabCount; i++)

if (tabMain.TabPages[i].Name == "pageDatasets")

tabMain.SelectedIndex = i;

IEC61850Utililty.SetSelectItem(fulldsName, lstDataSets);

/// <summary>

/// MouseUp event handler of lstRCB

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstRCB_MouseUp(object sender, MouseEventArgs e)

try

ListViewItem item = lstRCB.GetItemAt(e.X, e.Y);


if (item == null)

btnEditRCBDataset.Enabled = false;

btnDeleteRCB.Enabled = false;

btnEditRCB.Enabled = false;

return;

if (lstRCB.SelectedItems.Count > 0)

btnDeleteRCB.Enabled = true;

if (lstRCB.SelectedItems.Count == 1)

btnEditRCBDataset.Enabled = true;

btnEditRCB.Enabled = true;

else

btnEditRCB.Enabled = false;

btnEditRCBDataset.Enabled = false;

else

btnDeleteRCB.Enabled = false;

btnEditRCB.Enabled = false;

btnEditRCBDataset.Enabled = false;

}
if (!Global.CurrentUser.IEC61850Configuration)

Disablebuttons();

catch { }

/// <summary>

/// MouseUp event handler of lstViewGOOSEPublisherConf

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstViewGOOSEPublisherConf_MouseUp(object sender, MouseEventArgs e)

try

ListViewItem item = lstViewGOOSEPublisherConf.GetItemAt(e.X, e.Y);

if (item == null)

btnEditGOCBDataset.Enabled = false;

btnDeleteGOCB.Enabled = false;

btnEditGOCB.Enabled = false;

return;

if (lstViewGOOSEPublisherConf.SelectedItems.Count > 0)

{
btnDeleteGOCB.Enabled = true;

if (lstViewGOOSEPublisherConf.SelectedItems.Count == 1)

btnEditGOCBDataset.Enabled = true;

btnEditGOCB.Enabled = true;

else

btnEditGOCB.Enabled = false;

btnEditGOCBDataset.Enabled = false;

else

btnDeleteGOCB.Enabled = false;

btnEditGOCB.Enabled = false;

btnEditGOCBDataset.Enabled = false;

if (!Global.CurrentUser.IEC61850Configuration)

Disablebuttons();

catch { }

}
/// <summary>

/// MouseUp event handler of lstDataSets

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstDataSets_MouseUp(object sender, MouseEventArgs e)

ListViewItem item = lstDataSets.GetItemAt(e.X, e.Y);

if (item == null)

btnEditDs.Enabled = false;

btnDeleteDataset.Enabled = false;

btnCloneDataset.Enabled = false;

trvDataSet.Nodes.Clear();

return;

if (lstDataSets.SelectedItems.Count == 1)

btnEditDs.Enabled = true;

btnCloneDataset.Enabled = true;

btnDeleteDataset.Enabled = true;

else

btnEditDs.Enabled = false;

btnCloneDataset.Enabled = false;

if (lstDataSets.SelectedItems.Count == 0)
btnDeleteDataset.Enabled = false;

else

btnDeleteDataset.Enabled = true;

if (!Global.CurrentUser.IEC61850Configuration)

Disablebuttons();

/// <summary>

/// Click event handler of btnCloneDataset

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnCloneDataset_Click(object sender, EventArgs e)

if (lstDataSets.SelectedItems.Count == 0)

MessageBox.Show("Please select a dataset to clone.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (lstDataSets.SelectedItems[0].Text != "")

frmAddDataSet frmadd = new frmAddDataSet();

frmadd.ied = iedDev.SCLConfiguration.IEDs[0];

if (frmadd.ied != null)

{
//if (frmadd.ied.AccessPoints[0].GetAllDataSets().Count >= 48)

//{

// MessageBox.Show("The number of maximum datasets allowed in an IED is 48 .",


"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

// return;

//}

frmadd.Clone = true;

frmadd.DataSetToClone =
frmadd.ied.AccessPoints[0].GetDataSet(lstDataSets.SelectedItems[0].Text.Split('.')[0],
lstDataSets.SelectedItems[0].Text.Split('.')[2], lstDataSets.SelectedItems[0].Text.Split('.')[1]);//
IED_Config_Tool.V4.ProjectUtil.GetDataSet(IED_Config_Tool.V4.ProjectUtil.SelectedIEDName,
lstDataSets.SelectedItems[0].Text);

if (frmadd.ShowDialog() == DialogResult.OK)

FillDataSets(frmadd.DataSetRef);

Global.ProjectSaveRequired = true;

if (frmadd != null)

frmadd.Dispose();

/// <summary>

/// DragEnter event handler of lstDigitalSubscribers

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstDigitalSubscribers_DragEnter(object sender, DragEventArgs e)


{

VI vi = new VI();

CustomListView lstView = ((CustomListView)sender);

ListViewItem itemDestination = lstView.HitTest(lstView.PointToClient(new Point(e.X,


e.Y))).Item;

System.Windows.Forms.ListViewItem.ListViewSubItem subitemDestination =
lstView.HitTest(lstView.PointToClient(new Point(e.X, e.Y))).SubItem;

if (e.Data.GetDataPresent(typeof(TreeNode)))

if (lstView.Items.Count > 0)

lstView.IsDragValid = true;

e.Effect = DragDropEffects.Copy;

else

lstView.IsDragValid = false;

e.Effect = DragDropEffects.None;

/// <summary>

/// DragDrop event handler of lstDigitalSubscribers

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstDigitalSubscribers_DragDrop(object sender, DragEventArgs e)

{
try

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

CustomListView listView = ((CustomListView)sender);

listView.Invalidate();

if (e.Data.GetDataPresent(typeof(TreeNode)))

TreeNode nodeSource = e.Data.GetData(typeof(TreeNode)) as TreeNode;

TreeNode nodeParent = nodeSource;

while (nodeParent.Level != 0)

nodeParent = nodeParent.Parent;

IED ied = iedDev.SCLConfiguration.IEDs[0];

/* if (ied != null)

if (listView ==lstDigitalSubscribers)

if (ied.AccessPoints[0].BooleanIEC61850Inputs.Count == 0)

MessageBox.Show("No virtual inputs present in the selected subscriber.",


"Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;

else if (listView == lstAngSubscribers)

if (ied.AccessPoints[0].AnalogFloatIEC61850Inputs.Count == 0)

MessageBox.Show("No virtual inputs present in the selected subscriber.",


"Message", MessageBoxButtons.OK, MessageBoxIcon.Information);

return;

}*/

if (nodeParent.Text.Split('.')[0] == iedDev.SCLConfiguration.IEDs[0].IEDInstanceName )

MessageBox.Show("Publisher and Subsciber can not be same.", "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error);

Global.NotifyLogWindow("Publisher and Subsciber can not be same");

return;

ListViewItem itemDestination = listView.HitTest(listView.PointToClient(new Point(e.X,


e.Y))).Item;

if (itemDestination != null)

DoGooseMapping(nodeSource, itemDestination);

FillGooseSubscriberDetails();

}
catch(Exception ex)

LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

/// <summary>

/// This function does the goose subscription mapping

/// </summary>

/// <param name="nodeSource"></param>

/// <param name="itemDestination"></param>

private void DoGooseMapping(TreeNode nodeSource, ListViewItem itemDestination)

TreeNode nodeParent = nodeSource;

TreeNode nodeFCDA = nodeSource;

while (nodeParent.Level != 1)

nodeParent = nodeParent.Parent;

while (nodeFCDA.Level != 3)

nodeFCDA = nodeFCDA.Parent;

GSEControl cb = (GSEControl)nodeParent.Tag;

DA da = null;

BDA bda = null;

FCDA fcda = null;

object objectValue = nodeSource.Tag;


string objectType = "";

if (nodeSource.Tag is DA)

da = (DA)nodeSource.Tag;

objectType = da.bType;

else if (nodeSource.Tag is BDA)

bda = (BDA)nodeSource.Tag;

objectType = bda.bType;

else if (nodeSource.Tag is FCDA)

fcda = (FCDA)nodeSource.Tag;

if (fcda.DORef.Count == 1)

if (fcda.DORef[0].doType.DAItems.Count == 1)

objectType = GetDataTypeFromDOType(fcda.DORef[0].doType);

IED ied = iedDev.SCLConfiguration.IEDs[0];

if (ied == null)

return;
}

VI vi = (VI)itemDestination.Tag;

if (!vi.IsMapped)

if (vi.bType == objectType)

vi.MappedDataSet = cb.DataSetName;

vi.MappedGOOSE = cb.name;

vi.MappedLDevice = cb.CBLDeviceName;

vi.MappedIED = nodeParent.Parent.Text;

vi.MappedPath = IEC61850Utililty.ConvertNodePathToDaPath(nodeSource.FullPath);
//nodeSource.FullPath; //vi.MappedIED + "." + vi.MappedLDevice + "." + vi.MappedGOOSE + "\\" +
vi.MappedDataSet + "\\" + da.Path.Substring(da.Path.IndexOf('/')+1);

vi.IsMapped = true;

vi.MappedValue = objectValue;

if (nodeFCDA.Tag != null)

if (nodeFCDA.Tag is FCDA)

vi.MappedFCDA = (FCDA)nodeFCDA.Tag;

//vi.CB = (IED_Config_Tool.V4.GSEControl)cb.Clone();

itemDestination.SubItems.Add(new ListViewItem.ListViewSubItem(itemDestination,
vi.MappedPath));
Global.NotifyLogWindow(vi.MappedPath + " mapped to " + itemDestination.Text + " (" +
vi.Path + ")" + " of IED " + ied.IEDInstanceName );

itemDestination.SubItems[1].Text = vi.MappedPath;

if (nodeSource.Tag is DA || nodeSource.Tag is BDA)

nodeSource.ImageIndex = DisplayUtil.ImageIndex(vi.bType, true);

nodeSource.SelectedImageIndex = DisplayUtil.ImageIndex(vi.bType, true);

else if (nodeSource.Tag is FCDA)

nodeSource.ImageIndex = 39;

nodeSource.SelectedImageIndex = 39;

Global.ProjectSaveRequired = true ;

else

if (nodeSource.Tag is DA)

MessageBox.Show(da.name + " 's Data type ('" + da.bType + "') does not match with " +
vi.Name + " 's " + "Data type ('" + vi.bType + "').", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

Global.NotifyLogWindow(da.name + " 's Data type ('" + da.bType + "') does not match
with " + vi.Name + " 's " + "Data type ('" + vi.bType + "').");

else if (nodeSource.Tag is BDA)

{
MessageBox.Show(bda.name + " 's Data type ('" + bda.bType + "') does not match with
" + vi.Name + " 's " + "Data type ('" + vi.bType + "').", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

Global.NotifyLogWindow(bda.name + " 's Data type ('" + bda.bType + "') does not
match with " + vi.Name + " 's " + "Data type ('" + vi.bType + "').");

else if (nodeSource.Tag is FCDA)

MessageBox.Show("Mapping between different datatypes is not allowed.\n" +


fcda.ldInst + "/" + fcda.prefix + fcda.lnClass + fcda.lnInst + "$" + fcda.fc + "$" +
fcda.doname.Replace('.', '$') + "$" + fcda.daname.Replace('.', '$') + " 's Data type ('" + objectType + "')
does not match with " + vi.Name + " 's " + "Data type ('" + vi.bType + "').", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

Global.NotifyLogWindow("Mapping between different datatypes is not allowed." +


fcda.ldInst + "/" + fcda.prefix + fcda.lnClass + fcda.lnInst + "$" + fcda.fc + "$" +
fcda.doname.Replace('.', '$') + "$" + fcda.daname.Replace('.', '$') + " 's Data type ('" + objectType + "')
does not match with " + vi.Name + " 's " + "Data type ('" + vi.bType + "').");

else

MessageBox.Show(vi.Name + " is already mapped.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

/// <summary>

/// Gets the datatype from DOType

/// </summary>

/// <param name="doType"></param>

/// <returns></returns>

private string GetDataTypeFromDOType(DOType doType)


{

string strType = "";

if (doType!=null && doType.DAItems != null)

if (doType.DAItems.Count > 0)

if (doType.DAItems[0] is DA)

if (((DA)doType.DAItems[0]).bType == "Struct")

strType = GetDataTypeFromDAType(((DA)doType.DAItems[0]).daType);

else

strType = ((DA)doType.DAItems[0]).bType;

else if (doType.DAItems[0] is SDO)

strType = GetDataTypeFromDOType(((SDO)doType.DAItems[0]).doType);

return strType;

/// <summary>
/// Gets the datatype from DAType

/// </summary>

/// <param name="daType"></param>

/// <returns></returns>

private string GetDataTypeFromDAType(DAType daType)

string strType = "";

if (daType!=null && daType.BDAItems != null)

if (daType.BDAItems.Count > 0)

if (daType.BDAItems[0].bType == "Struct")

strType = GetDataTypeFromDAType(daType.BDAItems[0].daType);

else

strType = daType.BDAItems[0].bType;

return strType;

ListViewItem itemselected;

int iSel = 0;

/// <summary>

/// Checks whether atleast one item of listview is mapped


/// </summary>

/// <param name="lstView"></param>

/// <returns></returns>

private bool AtleasOneItemIsMapped(ListView lstView)

for (int i = 0; i < lstView.SelectedItems.Count; i++)

VI vi = (VI)lstView.SelectedItems[i].Tag;

if (vi.IsMapped)

return true;

return false;

/// <summary>

/// MouseDown event handler of lstDigitalSubscribers

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstDigitalSubscribers_MouseDown(object sender, MouseEventArgs e)

try

if (e.Button == MouseButtons.Left)

System.Windows.Forms.ListViewItem item =
((CustomListView)sender).HitTest(e.Location).Item;

if (item != null)

{
if (item.Tag != null)

System.Drawing.Rectangle trc = new System.Drawing.Rectangle(item.Bounds.X,


item.Bounds.Y, ((CustomListView)sender).Columns[0].Width, item.Bounds.Height);

if (trc.Contains(e.Location))

VI vi = (VI)item.Tag;

toolTipSubscriber.Show(vi.Path, ((CustomListView)sender), e.Location, 2000);

catch { }

/// <summary>

/// KeyDown event handler of lstDigitalSubscribers

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstDigitalSubscribers_KeyDown(object sender, KeyEventArgs e)

if (e.Control)

if (e.KeyCode == Keys.A)

DisplayUtil.SelectAllItems(((ListView)sender));

}
}

/// <summary>

/// Exports the CID file with all configuration changes

/// </summary>

/// <param name="IEDName"></param>

/// <param name="File"></param>

/// <param name="skipGooseMapping"></param>

/// <returns></returns>

private bool ExportCIDFile(string IEDName, string File,bool skipGooseMapping)

try

SCL scl = WorkSpace.CurrentProject.IEDDeviceCollection[IEDName].SCLConfiguration;

if (scl == null)

MessageBox.Show("No SCL configuration found for "+


IEDName ,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);

return false;

IED ied = scl.IEDs[0];

if (ied == null)

MessageBox.Show("Please select a IED from project.", "Message",


MessageBoxButtons.OK, MessageBoxIcon.Information);

return false ;
}

//ied.IPAddress = WorkSpace.CurrentProject.IEDDeviceCollection[IEDName].IPAddress;

XmlDocument xdoc = new XmlDocument();

if (ied.IEDFileContents.Trim() != "")

try

xdoc.LoadXml(ProjectUtil.DecompressText(ied.IEDFileContents));

catch

MessageBox.Show("Loading IED file contents for " + IEDName + " failed.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

Global.NotifyLogWindow("Loading IED file contents for " + IEDName + " failed.");

return false ;

else

MessageBox.Show("IED file contents not found for " + IEDName, "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error);

Global.NotifyLogWindow("IED file contents not found for " + IEDName);

return false;

if (!ValidateMappingReference(ied,ied.AccessPoints[0].BooleanIEC61850Inputs))

MessageBox.Show("Some of boolean mapping references are invalid.", "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error);

return false ;
}

if (!ValidateMappingReference(ied, ied.AccessPoints[0].AnalogFloatIEC61850Inputs))

MessageBox.Show("Some of analog mapping references are invalid.", "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error);

return false;

if (!ValidateSMVMappingReference(ied))

MessageBox.Show("SMV subscription mapping references is invalid.", "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error);

return false;

ExportCIDUtil.UpdateDataSetInfo(xdoc, ied);

ExportCIDUtil.UpdateLogControlBlockInfo(xdoc, ied);

ExportCIDUtil.UpdateReportControlBlockInfo(xdoc, ied);

ExportCIDUtil.UpdateGooseControlBlockInfo(xdoc, ied);

ExportCIDUtil.UpdateSMVControlBlockInfo(xdoc, ied);

ExportCIDUtil.ClearOtherIEDPrivateInfoAndUpdateIP(xdoc, scl);

xdoc.Save(File);

return true ;

}
catch (Exception ex)

MessageBox.Show("Exporting CID file failed.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

Global.NotifyLogWindow(ex.Message);

LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

return false ;

/// <summary>

/// Validates for goose mapping reference

/// </summary>

/// <param name="ied"></param>

/// <param name="vis"></param>

/// <returns></returns>

bool ValidateMappingReference(IED ied,List<VI> vis)

if (ied == null)

return false;

foreach (VI vi in vis)

if (vi.IsMapped)

IEDDevice iedev= WorkSpace.CurrentProject.IEDDeviceCollection[vi.MappedIED];

if (iedev != null)

GSEControl gsemapped =
iedev.SCLConfiguration.IEDs[0].AccessPoints[0].GetGSEControl(vi.MappedGOOSE,
vi.MappedLDevice);
if (gsemapped == null)

return false;

else

TreeNode node = iedev.SCLConfiguration.IEDs[0].IEDNodeGSE;

if (node != null)

TreeNode nodeda = DisplayUtil.GetNode(node.Nodes, vi.MappedPath);

if (nodeda == null)

return false;

else

return false;

return true;

/// <summary>

/// Validates for SMV mapping reference

/// </summary>

/// <param name="ied"></param>


/// <returns></returns>

bool ValidateSMVMappingReference(IED ied)

if (ied == null)

return false;

foreach (SMVStream stream in ied.AccessPoints[0].smvStream)

if (stream!=null && stream.IsMapped)

IEDDevice iedev = WorkSpace.CurrentProject.IEDDeviceCollection[stream.MappedIED];

if (iedev != null)

if (stream.MappedCB != null)

SMVControl smvmapped =
iedev.SCLConfiguration.IEDs[0].AccessPoints[0].GetSMVControl(stream.MappedCB.name,
stream.MappedCB.CBLDeviceName);

if (smvmapped == null)

return false;

if (smvmapped.DataSetName != stream.MappedCB.DataSetName)

return false;

else
{

return false;

return true;

/// <summary>

/// Click event handler of sendCIDToolStripMenuItem . Sends the CID file to device

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void sendCIDToolStripMenuItem_Click(object sender, EventArgs e)

if (iedDev == null)

MessageBox.Show("Invalid IED", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

if (iedDev.SCLConfiguration == null)

MessageBox.Show("Invalid SCL configuration", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (iedDev.SCLConfiguration.IEDs[0].IniFileContents == null ||
iedDev.SCLConfiguration.IEDs[0].IniFileContents.Trim() == "")
{

MessageBox.Show("ini file not found in IED instance.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (!ProjectUtil.ValidateIEDFtpCommunicationProperties(iedDev))

return;

if (!ProjectUtil.IsTargetDeviceExpected(iedDev.IEDDeviceOrginalName, iedDev.IPAddress))

return;

ProjectUtil.CreateNecessaryFolders();

Serializer<SCL> serializeIED = new Serializer<SCL>();

if (!serializeIED.Serialize(Global.UserDataFolder + "\\Temp\\sclconfig.scl",
iedDev.SCLConfiguration))

MessageBox.Show("Serializing of SCL configuration failed.", "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

if (ExportCIDFile(iedDev.IEDDeviceInstanceName, Global.UserDataFolder + "\\Temp\\" +


iedDev.IEDDeviceOrginalName + ".scd", false))

iedDev.SCLConfiguration.IEDs[0].StartUpSettings.IEDName =
iedDev.IEDDeviceInstanceName;

iedDev.SCLConfiguration.IEDs[0].StartUpSettings.SCLFileName =
iedDev.IEDDeviceOrginalName + ".scd";

List<ftp.FtpFileInfo> fileinfo = new List<IEDConfigurationTool.ftp.FtpFileInfo>();

fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder + "\\Temp\\"


+ iedDev.IEDDeviceOrginalName + ".scd", "Applications/" + iedDev.IEDDeviceOrginalName + ".scd"));
if (!ProjectUtil.ExportStartupFile(Global.UserDataFolder + "\\Temp\\StartUp.ini",
iedDev.SCLConfiguration.IEDs[0]))

MessageBox.Show("Exporting startup file failed.See log window for more details",


"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

if (!ProjectUtil.ExportIniMapFile(Global.UserDataFolder + "\\Temp\\" +
iedDev.IEDDeviceOrginalName + ".ini", iedDev.SCLConfiguration.IEDs[0]))

MessageBox.Show("Exporting ini file failed.See log window for more details", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

bool smvSubscribed = false;

if (System.IO.File.Exists(Global.UserDataFolder + "\\Temp\\StartUp.ini"))

fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder + "\\Temp\\


StartUp.ini", "Applications/StartUp.ini"));

if (System.IO.File.Exists(Global.UserDataFolder + "\\Temp\\" +
iedDev.IEDDeviceOrginalName + ".ini"))

fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder + "\\


Temp\\" + iedDev.IEDDeviceOrginalName + ".ini", "Applications/" + iedDev.IEDDeviceOrginalName +
".ini"));

if (iedDev.IEDDeviceOrginalName == "MU")

if (!ProjectUtil.ExportMUStartupFile(Global.UserDataFolder + "\\Temp\\MUStartUp.ini",
iedDev.SCLConfiguration.IEDs[0]))

{
MessageBox.Show("Exporting MUStartUp file failed.See log window for more details",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

if (System.IO.File.Exists(Global.UserDataFolder + "\\Temp\\MUStartUp.ini"))

fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder + "\\


Temp\\MUStartUp.ini", "Applications/MUStartUp.ini"));

else

//Check for SMV subscription

if (iedDev.SCLConfiguration.IEDs[0].AccessPoints[0].smvStream.Count == 1)

IEDDevice remotesmvied = null;

if (iedDev.SCLConfiguration.IEDs[0].AccessPoints[0].smvStream[0].IsMapped)

smvSubscribed = true;

remotesmvied =
WorkSpace.CurrentProject.IEDDeviceCollection[iedDev.SCLConfiguration.IEDs[0].AccessPoints[0].sm
vStream[0].MappedIED];

if (remotesmvied != null)

//
remotesmvied.SCLConfiguration.IEDs[0].AccessPoints[0].GetSMVControl(iedDev.SCLConfiguration.IE
Ds[0].AccessPoints[0].smvStream[0].

if (ExportCIDFile(remotesmvied.IEDDeviceInstanceName, Global.UserDataFolder +
"\\Temp\\" + remotesmvied.IEDDeviceOrginalName + ".scd", true))

//Adding remote IED to list for uploading


fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder +
"\\Temp\\" + remotesmvied.IEDDeviceOrginalName + ".scd", "Applications/" +
remotesmvied.IEDDeviceOrginalName + ".scd"));

else

MessageBox.Show("Exporting SCD file of remote IED " +


remotesmvied.IEDDeviceInstanceName + " failed ", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

return;

iedDev.SCLConfiguration.IEDs[0].SMVStartUpSettings.SCLFileName = remotesmvied !=
null ? Global.FtpDirectory + remotesmvied.IEDDeviceOrginalName + ".scd" : "UNKNOWN";

iedDev.SCLConfiguration.IEDs[0].SMVStartUpSettings.IEDName = remotesmvied !=
null ? remotesmvied.IEDDeviceInstanceName : "UNKNOWN";

iedDev.SCLConfiguration.IEDs[0].SMVStartUpSettings.AccessPointName =
remotesmvied != null ? remotesmvied.SCLConfiguration.IEDs[0].AccessPoints[0].name :
"UNKNOWN";

iedDev.SCLConfiguration.IEDs[0].SMVStartUpSettings.RemoteSMVID =
iedDev.SCLConfiguration.IEDs[0].AccessPoints[0].smvStream[0].IsMapped ?
iedDev.SCLConfiguration.IEDs[0].AccessPoints[0].smvStream[0].MappedCB.ID : "NO_SV_MAPPING";

// grdSmvStartup.SelectedObject =
iedDev.SCLConfiguration.IEDs[0].SMVStartUpSettings;

if (!ProjectUtil.ExportSMVStartupFile(Global.UserDataFolder + "\\Temp\\
SMVStartUp.ini", iedDev.SCLConfiguration.IEDs[0]))

MessageBox.Show("Exporting SMVStartUp file failed.See log window for more


details", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;

//Adding SMV startup file to list for uploading

if (System.IO.File.Exists(Global.UserDataFolder + "\\Temp\\SMVStartUp.ini"))

fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder + "\\


Temp\\SMVStartUp.ini", "Applications/SMVStartUp.ini"));

ProjectUtil.WriteAppRestartFile(Global.UserDataFolder + "\\Temp\\svmap.cfg",
smvSubscribed ? "1" : "0");

if (System.IO.File.Exists(Global.UserDataFolder + "\\Temp\\svmap.cfg"))

fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder + "\\Temp\\


svmap.cfg", "Applications/svmap.cfg"));

fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder + "\\Temp\\


sclconfig.scl", "Applications/sclconfig.scl"));

if (ProjectUtil.UploadFilesToFtpServer(fileinfo, iedDev, "Downloading 61850 configuration


files", false,true ))

//Notify Firmware

bool wasIEDOnline = iedDev.IsOnline;

if (!iedDev.IsOnline)

MainForm.ConnectToFirmware(iedDev);

if (iedDev.IsOnline)

iedDev.WriteToSharedMemIndex(Global.IEC_61850_CONFIG_TO_FIRMWARE, "INT",
"1");

System.Threading.Thread.Sleep(200);

if (!wasIEDOnline)

iedDev.DisConnect();
}

else

MessageBox.Show("Downloading of configuration files were successfull.But notifying


of configuration \nupdate failed because could not connect to firmware.", "Warning",
MessageBoxButtons.OK, MessageBoxIcon.Warning);

if (MessageBox.Show("61850 configuration downloaded successfully.Do you want to soft


restart.", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
System.Windows.Forms.DialogResult.Yes)

// ProjectUtil.WriteAppRestartFile(Global.UserDataFolder + "\\Temp\\
ApplicationChange.cfg", "SOFTRESTART,61850APP\nSNTP," + iedDev.SNTPServerAddress);

ProjectUtil.WriteAppRestartFile(Global.UserDataFolder + "\\Temp\\
ApplicationChange.cfg", "SOFTRESTART,61850APP\nSNTP1," + iedDev.SNTPServerAddress + "\
nSNTP2," + iedDev.SNTP2ServerAddress);

fileinfo = new List<IEDConfigurationTool.ftp.FtpFileInfo>();

fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder + "\\


Temp\\ApplicationChange.cfg", "ApplicationChange.cfg"));

if (ProjectUtil.UploadFilesToFtpServer(fileinfo, iedDev, "Sending Soft Restart


command", false, true))

ProjectUtil.ShowWaitScreen(30, "Applying Soft Restart..");

else

MessageBox.Show("Exporting SCD file of IED " + iedDev.IEDDeviceInstanceName + " failed ",


"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;

/// <summary>

/// DragOver event handler of trvDataSet

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void trvDataSet_DragOver(object sender, DragEventArgs e)

if (e.Data.GetDataPresent(typeof(System.Collections.ArrayList)) && dragInDataset)

//ResetNodeForeColore(trvDataSet.Nodes[0].Nodes );

Point p = trvDataSet.PointToClient(new Point(e.X, e.Y));

TreeNode node = trvDataSet.GetNodeAt(p.X, p.Y);

if (node.PrevVisibleNode != null)

node.PrevVisibleNode.ForeColor = Color.Black;

if (node.NextVisibleNode != null)

node.NextVisibleNode.ForeColor = Color.Black;

if (node != null)

if (node.Level != 0)

{
node.ForeColor = Color.Red;

nodeLastRed = node;

TreeNode nodeLastRed;

/// <summary>

/// DragLeave event handler of trvDataSet

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void trvDataSet_DragLeave(object sender, EventArgs e)

if (nodeLastRed != null)

// CtrlPressed = false;

nodeLastRed.ForeColor = Color.Black;

if (trvDataSet.Nodes.Count > 0)

ResetNodeForeColor(trvDataSet.Nodes[0].Nodes);

/// <summary>

/// Resets all nodes' color to block

/// </summary>

/// <param name="nodes"></param>


private void ResetNodeForeColor(TreeNodeCollection nodes)

foreach (TreeNode node in nodes)

node.ForeColor = Color.Black;

/// <summary>

/// NodeMouseClick event handler of trvDataSet

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void trvDataSet_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)

if (e.Button == MouseButtons.Right)

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied != null)

trvDataSet.SelectedNode = e.Node;

if (e.Node.Level == 1)

trvDataSet.ContextMenuStrip = DatasetContextMenu;

if (trvDataSet.SelectedNodes.Count > 1)

tspDatasetMoveDown.Enabled = false;

tspDatasetMoveUp.Enabled = false;
}

else

if (Global.CurrentUser.IEC61850Configuration)

tspDatasetMoveDown.Enabled = true;

tspDatasetMoveUp.Enabled = true;

else

trvDataSet.ContextMenuStrip = null;

/// <summary>

/// ItemDrag event handler of trvDataSet

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void trvDataSet_ItemDrag(object sender, ItemDragEventArgs e)

try

int Level = (e.Item as TreeNode).Level;

if (!Global.CurrentUser.IEC61850Configuration)

return;
// Util.editTracking

if (Level == 1)

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied != null)

trvDataSet.PaintSelectedNodes();

trvDataSet.SelectedNode = (TreeNode)e.Item;

dragInDataset = true;

this.Cursor = Cursors.Default;

trvDataSet.DoDragDrop(trvDataSet.SelectedNodes, DragDropEffects.Copy);

Point point = GetTreeViewScrollPos(trvDataSet);

// project.LocalGooseScrollBarPosition = point;

catch { }

bool CtrlPressed = false;

/// <summary>

/// KeyUp event handler of trvDataSet

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void trvDataSet_KeyUp(object sender, KeyEventArgs e)

CtrlPressed = e.Control;
}

/// <summary>

/// KeyDown event handler of trvDataSet

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void trvDataSet_KeyDown(object sender, KeyEventArgs e)

CtrlPressed = e.Control;

if (e.KeyCode == Keys.Delete)

if (trvDataSet.SelectedNode != null)

if (trvDataSet.SelectedNode.Level == 1)

tspDatasetItemDelete_Click(null, null);

/// <summary>

/// Click event handler of tspDatasetItemDelete

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void tspDatasetItemDelete_Click(object sender, EventArgs e)

{
try

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (trvDataSet.SelectedNode.Level == 1)

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied == null)

return;

DataSet ds = ied.AccessPoints[0].GetDataSet(lstDataSets.SelectedItems[0].Text.Split('.')
[0], lstDataSets.SelectedItems[0].Text.Split('.')[2], lstDataSets.SelectedItems[0].Text.Split('.')[1]);

string gooseRef = "";

if (ds != null)

bool delete = false;

for (int i = 0; i < trvDataSet.SelectedNodes.Count; i++)

trvDataSet.skipSelect = true;

string MappedRef = "";


bool IsMapped = false;

if (IEC61850Utililty.IsDataSetRefInGoose(ds, ref gooseRef, ied))

string[] strSplit = gooseRef.Split('$');

if (strSplit.Length == 2)

string goosename = strSplit[1];

string goosenode = ds.DataSetLDeviceName + "." + goosename;

IED iedIn;

for (int x = 0; x < WorkSpace.CurrentProject.IEDDeviceCollection.Count ; x++)

if (iedDev.IEDDeviceInstanceName !=
WorkSpace.CurrentProject.IEDDeviceCollection[x].IEDDeviceInstanceName)

if
(WorkSpace.CurrentProject.IEDDeviceCollection[x].SCLConfiguration.IEDs.Count > 0)

iedIn =
WorkSpace.CurrentProject.IEDDeviceCollection[x].SCLConfiguration.IEDs[0];

for (int ipcnt = 0; ipcnt <


iedIn.AccessPoints[0].BooleanIEC61850Inputs.Count; ipcnt++)

if (iedIn.AccessPoints[0].BooleanIEC61850Inputs[ipcnt].IsMapped)

if (CheckTreeNodeForMapping(iedDev.IEDDeviceInstanceName,
goosenode, iedIn.AccessPoints[0].BooleanIEC61850Inputs[ipcnt].MappedPath,
(TreeNode)trvDataSet.SelectedNodes[i]))

{
MappedRef =
iedIn.AccessPoints[0].BooleanIEC61850Inputs[ipcnt].Name + " of " + iedIn.IEDInstanceName;

IsMapped = true;

if (IsMapped)

MessageBox.Show("Selected FCDA '" +


((TreeNode)trvDataSet.SelectedNodes[i]).FullPath + "' used for mapping to '" + MappedRef + "'.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

continue;

if (ds.Items.Count == 1)

MessageBox.Show("You can not delete all the fcda elements of this dataset \n
since it is referenced by GOOSE '" + gooseRef + "'", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

//UpdateCapabilityMeters(ds);

return;

if (IEC61850Utililty.IsDatasetRefInRCB(ds, ref gooseRef,ied ))

{
if (ds.Items.Count == 1)

MessageBox.Show("You can not delete all the fcda elements of this dataset \n
since it is referenced by Report Control Block '" + gooseRef + "'", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

// UpdateCapabilityMeters(ds);

return;

if (ds.Items.Contains((FCDA)((TreeNode)trvDataSet.SelectedNodes[i]).Tag))

ds.Items.Remove((FCDA)((TreeNode)trvDataSet.SelectedNodes[i]).Tag);

trvDataSet.Nodes[0].Nodes.Remove((TreeNode)trvDataSet.SelectedNodes[i]);

delete = true;

Global.ProjectSaveRequired = true;

// IEDConfigTabIEDName = "";

// GooseSubTabIEDName = "";

if (delete)

//IED_Config_Tool.V4.ProjectUtil.project.IEDs[IED_Config_Tool.V4.ProjectUtil.SelectedIEDName].Acc
essPoints[0].UpdateDataset(ds.DataSetName, ds.DataSetLDeviceName, ds.prefix + ds.lnClass +
ds.lninst, ds);

if (IEC61850Utililty.IsDataSetRefInGoose(ds, ref gooseRef,ied ))

{
this.Cursor = Cursors.WaitCursor;

DisplayUtil.UpdateIEDNodeGSE(ied );

Global.NotifyReloadIEDGOOSENode(ied);

this.Cursor = Cursors.Default;

if (IEC61850Utililty.IsDataSetRefInSMV(ds, ref gooseRef, ied ))

this.Cursor = Cursors.WaitCursor;

DisplayUtil.UpdateIEDNodeSMV(ied );

Global.NotifyReloadIEDSmvNode(ied);

this.Cursor = Cursors.Default;

//UpdateReportDataset(ds);

// UpdateCapabilityMeters(ds);

trvDataSet.SelectedNodes.Clear();

trvDataSet.SelectedNodes.Add(trvDataSet.SelectedNode);

trvDataSet.SetLastNode(trvDataSet.SelectedNode);

trvDataSet.PaintSelectedNodes();

catch (Exception ex)

LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

finally { trvDataSet.skipSelect = false; }


}

/// <summary>

/// Recursively checks node or any child node is mapped

/// </summary>

/// <param name="goosepath">GOOSE node path</param>

/// <param name="MappedPath">Mapped path</param>

/// <param name="node">Tree Node</param>

/// <returns></returns>

private bool CheckTreeNodeForMapping(string IEDName, string goosepath, string MappedPath,


TreeNode node)

if (node.Nodes.Count == 0)

if (IEC61850Utililty.ConvertNodePathToDaPath(IEDName + "\\" + goosepath + "\\" +


IEC61850Utililty.GetNodeFullPath(node)) == MappedPath)

return true;

else

foreach (TreeNode nodein in node.Nodes)

if (CheckTreeNodeForMapping(IEDName, goosepath, MappedPath, nodein))

return true;

return false;

}
/// <summary>

/// Click event handler of tspDatasetMoveUp.Moves up the selected item.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void tspDatasetMoveUp_Click(object sender, EventArgs e)

try

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied == null)

return;

if (trvDataSet.SelectedNode.Level == 1)

DataSet dataset = (DataSet)trvDataSet.SelectedNode.Parent.Tag;

if (dataset != null)

trvDataSet.skipSelect = true;

int index = 0;
for (int i = 0; i < trvDataSet.SelectedNodes.Count; i++)

TreeNode node = (TreeNode)trvDataSet.SelectedNodes[i];

if (node.Index == 0)

return;

if (node.Index > 0)

FCDA dobject = (FCDA)node.Tag;

dataset.Items.RemoveAt(node.Index);

index = node.Index - 1;

dataset.Items.Insert(index, dobject);

trvDataSet.Nodes[0].Nodes.RemoveAt(node.Index);

trvDataSet.Nodes[0].Nodes.Insert(index, node);

Global.ProjectSaveRequired = true;

ied.AccessPoints[0].UpdateDataset(dataset.DataSetName,
dataset.DataSetLDeviceName, dataset.prefix + dataset.lnClass + dataset.lninst, dataset);

string gooseRef = "";

if (IEC61850Utililty.IsDataSetRefInGoose(dataset, ref gooseRef, ied))

this.Cursor = Cursors.WaitCursor;

DisplayUtil.UpdateIEDNodeGSE(ied);

Global.NotifyReloadIEDGOOSENode(ied);

this.Cursor = Cursors.Default;

if (IEC61850Utililty.IsDataSetRefInSMV(dataset, ref gooseRef, ied))

{
this.Cursor = Cursors.WaitCursor;

DisplayUtil.UpdateIEDNodeSMV(ied);

Global.NotifyReloadIEDSmvNode(ied);

this.Cursor = Cursors.Default;

//UpdateReportDataset(dataset);

trvDataSet.SelectedNode = trvDataSet.Nodes[0].Nodes[index];

//trvDataSet.skipSelect = false;

catch (Exception ex)

LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

finally

trvDataSet.skipSelect = false;

/// <summary>

/// Click event handler of tspDatasetMoveDown.Moves down the selected item.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void tspDatasetMoveDown_Click(object sender, EventArgs e)


{

try

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied == null)

return;

if (trvDataSet.SelectedNode.Level == 1)

DataSet dataset = (DataSet)trvDataSet.SelectedNode.Parent.Tag;

if (dataset != null)

trvDataSet.skipSelect = true;

int index = 0;

for (int i = trvDataSet.SelectedNodes.Count - 1; i >= 0; i--)

TreeNode node = (TreeNode)trvDataSet.SelectedNodes[i];

if (node.Index == node.Parent.Nodes.Count - 1)

return;

if (node.Index < node.Parent.Nodes.Count - 1)


{

FCDA dobject = (FCDA)node.Tag;

dataset.Items.RemoveAt(node.Index);

index = node.Index + 1;

dataset.Items.Insert(index, dobject);

trvDataSet.Nodes[0].Nodes.RemoveAt(node.Index);

trvDataSet.Nodes[0].Nodes.Insert(index, node);

Global.ProjectSaveRequired = true;

string gooseRef = "";

ied.AccessPoints[0].UpdateDataset(dataset.DataSetName,
dataset.DataSetLDeviceName, dataset.prefix + dataset.lnClass + dataset.lninst, dataset);

if (IEC61850Utililty.IsDataSetRefInGoose(dataset, ref gooseRef, ied))

this.Cursor = Cursors.WaitCursor;

DisplayUtil.UpdateIEDNodeGSE(ied);

Global.NotifyReloadIEDGOOSENode(ied);

this.Cursor = Cursors.Default;

if (IEC61850Utililty.IsDataSetRefInSMV(dataset, ref gooseRef, ied))

this.Cursor = Cursors.WaitCursor;

DisplayUtil.UpdateIEDNodeSMV(ied);

Global.NotifyReloadIEDSmvNode(ied);

this.Cursor = Cursors.Default;

//UpdateReportDataset(dataset);
trvDataSet.SelectedNode = trvDataSet.Nodes[0].Nodes[index];

catch (Exception ex)

LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

finally { trvDataSet.skipSelect = false; }

/// <summary>

/// Click event handler of btnPrintGOCB.Prints GOOSE control blocks details

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnPrintGOCB_Click(object sender, EventArgs e)

IEDConfigurationTool.PrintUtil.PrintDataFromListView(lstViewGOOSEPublisherConf, "GOOSE
control blocks details for " + iedDev.IEDDeviceInstanceName);

/// <summary>

/// Click event handler of btnPrintRCB.Prints Report control blocks details

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnPrintRCB_Click(object sender, EventArgs e)

{
IEDConfigurationTool.PrintUtil.PrintDataFromListView(lstRCB, "Report control blocks details
for " + iedDev.IEDDeviceInstanceName);

/// <summary>

/// Click event handler of btnEditLog.Pops up window for editing Log Control block.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnEditLog_Click(object sender, EventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (lstLogControlBlocks.SelectedItems.Count == 1 && lstLogControlBlocks.SelectedItems[0].Tag


is LogControl )

if (base.iedDev.SCLConfiguration != null && base.iedDev.SCLConfiguration.IEDs.Count > 0)

frmAddLogControl frmlog = new frmAddLogControl();

frmlog.ied = base.iedDev.SCLConfiguration.IEDs[0];

frmlog.bedit = true;

frmlog.logEdit = (LogControl)lstLogControlBlocks.SelectedItems[0].Tag;

LogControl beforeedit = (LogControl)frmlog.logEdit.Clone();

if (frmlog.ied != null)

{
if (frmlog.ShowDialog() == DialogResult.OK && !
IEC61850Utililty.IsLogControlBlockSame(beforeedit, frmlog.logEdit))

FillLogControlBlocks(lstLogControlBlocks.SelectedItems[0].Text);

this.Cursor = Cursors.Default;

Global.ProjectSaveRequired = true;

/// <summary>

/// MouseDoubleClick event handler of lstLogControlBlocks.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstLogControlBlocks_MouseDoubleClick(object sender, MouseEventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

return;

btnEditLog_Click(null, null);

/// <summary>
/// Checks whether the SMVControl is mapped in the specified IED

/// </summary>

/// <param name="cb"></param>

/// <param name="IED"></param>

/// <returns></returns>

private bool IsMappedInSMVStream(SMVControl cb, string IED)

IED sub = base.iedDev.SCLConfiguration.IEDs[0];

if (sub == null)

return false;

for (int i = 0; i < sub.AccessPoints[0].smvStream.Count; i++)

if (sub.AccessPoints[0].smvStream[i].IsMapped)

if (sub.AccessPoints[0].smvStream[i].MappedCB.name == cb.name &&


sub.AccessPoints[0].smvStream[i].MappedCB.CBLDeviceName == cb.CBLDeviceName &&

sub.AccessPoints[0].smvStream[i].MappedIED == IED)

return true;

return false;

/// <summary>

/// Updates count of analog & quality based on the datatype

/// </summary>

/// <param name="datatype"></param>

/// <param name="analogcount"></param>


/// <param name="qualitycount"></param>

/// <param name="analogfound"></param>

/// <param name="qualityfound"></param>

/// <returns></returns>

bool UpdateCount(string datatype, ref int analogcount, ref int qualitycount, ref bool
analogfound, ref bool qualityfound)

if (datatype == "INT32" || datatype == "FLOAT32")

analogcount++;

if (!analogfound)

analogfound = true;

qualityfound = false;

return true;

else

return false;

else if (datatype == "Quality")

qualitycount++;

if (!qualityfound)

analogfound = false;

qualityfound = true;
return true;

else

return false;

return false;

/// <summary>

/// Gets leaf elements of a treenode

/// </summary>

/// <param name="node"></param>

/// <param name="NodeList"></param>

void GetLeafElements(TreeNode node, ref List<TreeNode> NodeList)

if (NodeList == null)

NodeList = new List<TreeNode>();

if (node.Nodes.Count > 0)

foreach (TreeNode nodein in node.Nodes)

GetLeafElements(nodein, ref NodeList);

else
{

NodeList.Add(node);

/// <summary>

/// Gets count of INT32 from the treenode

/// </summary>

/// <param name="node"></param>

/// <param name="count"></param>

void GetCountOfINT32(TreeNode node, ref int count)

if (node.Nodes.Count > 0)

for (int i = 0; i < node.Nodes.Count; i++)

GetCountOfINT32(node.Nodes[i], ref count);

else

if (node.Tag != null)

if (node.Tag is DA)

DA da = (DA)node.Tag;

if (da.bType == "INT32")
{

count++;

else if (node.Tag is BDA)

BDA bda = (BDA)node.Tag;

if (bda.bType == "INT32")

count++;

/// <summary>

/// Updates stream treenode based on mapped stream

/// </summary>

/// <param name="nodeStream"></param>

/// <param name="stream"></param>

private void UpdateSmvStreamNode(TreeNode nodeStream, SMVStream stream)

nodeStream.Nodes.Clear();

for (int i = 0; i < stream.Values.Count; i++)

nodeStream.Nodes.Add(stream.Values[i].Name + " - " + stream.Values[i].MappedPath);

nodeStream.Nodes[nodeStream.Nodes.Count - 1].Tag = stream.Values[i];


}

/// <summary>

/// Checks whether same SMV ID is used by any subscribed smv

/// </summary>

/// <param name="ied"></param>

/// <param name="SMVID"></param>

/// <param name="Stream"></param>

/// <returns></returns>

private bool IsSameSMVIDPreset(IED ied, string SMVID, ref string Stream)

if (ied != null)

for (int i = 0; i < ied.AccessPoints[0].smvStream.Count; i++)

if (ied.AccessPoints[0].smvStream[i].IsMapped)

if (ied.AccessPoints[0].smvStream[i].MappedCB.ID == SMVID)

Stream = ied.AccessPoints[0].smvStream[i].Name;

return true;

return false;

}
/// <summary>

/// Updates SMV stream with mapped node

/// </summary>

/// <param name="node"></param>

/// <param name="stream"></param>

private void UpdateSMVStream(TreeNode node, SMVStream stream)

if (node.Nodes.Count > 0)

for (int i = 0; i < node.Nodes.Count; i++)

UpdateSMVStream(node.Nodes[i], stream);

else

if (node.Tag != null)

bool addRow = false;

VI vi = null;

if (node.Tag is DA)

DA da = (DA)node.Tag;

if (da.bType == "INT32" || da.bType == "FLOAT32")

addRow = true;

vi = new VI();
vi.Name = "SV " + Convert.ToString(stream.Values.Count + 1);

vi.MappedPath = IEC61850Utililty.ConvertNodePathToDaPath(node.FullPath);

//vi.Selected = true;

vi.Value = da;

else if (node.Tag is BDA)

BDA bda = (BDA)node.Tag;

if (bda.bType == "INT32" || bda.bType == "FLOAT32")

addRow = true;

vi = new VI();

vi.Name = "SV " + Convert.ToString(stream.Values.Count + 1);

vi.MappedPath = IEC61850Utililty.ConvertNodePathToDaPath(node.FullPath);

// vi.Selected = true;

vi.Value = bda;

else if (node.Tag is FCDA)

FCDA fcda = (FCDA)node.Tag;

if(fcda.DORef.Count>0)

string datattype = GetDataTypeFromDOType(fcda.DORef[0].doType);

if (datattype == "INT32" || datattype == "FLOAT32")

{
addRow = true;

vi = new VI();

vi.Name = "SV " + Convert.ToString(stream.Values.Count + 1);

vi.MappedPath = IEC61850Utililty.ConvertNodePathToDaPath(node.FullPath);

// vi.Selected = true;

vi.Value = fcda;

if (addRow)

stream.Values.Add(vi);

int MaxSelectableSMVStreamItems = 8;

bool check = false;

/// <summary>

/// AfterCheck event handler of trvSMVSubscriber

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void trvSMVSubscriber_AfterCheck(object sender, TreeViewEventArgs e)

{
if (!check)

check = true;

if (e.Node.Level == 0)

if (e.Node.Nodes.Count == 0)

e.Node.Checked = false;

check = false;

return;

int cnt = 0;

if (e.Node.Nodes.Count >= MaxSelectableSMVStreamItems)

cnt = MaxSelectableSMVStreamItems;

else

cnt = e.Node.Nodes.Count;

for (int i = 0; i < cnt; i++)

e.Node.Nodes[i].Checked = e.Node.Checked;

if (e.Node.Nodes[i].Tag is VI)

VI vi = (VI)e.Node.Nodes[i].Tag;

vi.Selected = e.Node.Checked;

Global.ProjectSaveRequired = true;

if (e.Node.Nodes.Count > MaxSelectableSMVStreamItems)


{

for (int i = MaxSelectableSMVStreamItems; i < e.Node.Nodes.Count; i++)

e.Node.Nodes[i].Checked = false;

if (e.Node.Nodes[i].Tag is VI)

VI vi = (VI)e.Node.Nodes[i].Tag;

vi.Selected = false;

else

if (e.Node.Tag is VI)

if (GetCountofCheckedNodes(e.Node.Parent) > MaxSelectableSMVStreamItems)

e.Node.Checked = false;

check = false;

return;

VI vi = (VI)e.Node.Tag;

vi.Selected = e.Node.Checked;

e.Node.Parent.Checked = IsAtleastOneNodeChecked(e.Node.Parent);

Global.ProjectSaveRequired = true;

}
}

check = false;

/// <summary>

/// Get count of checked nodes in treenode

/// </summary>

/// <param name="nodePar"></param>

/// <returns></returns>

private int GetCountofCheckedNodes(TreeNode nodePar)

int iCnt = 0;

foreach (TreeNode node in nodePar.Nodes)

if (node.Checked)

iCnt++;

return iCnt;

/// <summary>

/// Checks whether atleast one node is checked in child nodes

/// </summary>

/// <param name="nodePar"></param>

/// <returns></returns>

private bool IsAtleastOneNodeChecked(TreeNode nodePar)

foreach (TreeNode node in nodePar.Nodes)


{

if (node.Checked)

return true;

return false;

/// <summary>

/// Click event handler of btnEditsubscriber

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnEditsubscriber_Click(object sender, EventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (lstViewGOOSESubscriberConf.SelectedItems.Count > 0)

frmMACAddress frm = new frmMACAddress();

// string IEDName = trvProject.SelectedNode.Text;

frm.strMACAddress = lstViewGOOSESubscriberConf.SelectedItems[0].SubItems[4].Text;

if (frm.ShowDialog() == DialogResult.OK)

IED ied = base.iedDev.SCLConfiguration.IEDs[0];


if (ied != null)

if (ied.AccessPoints[0].BooleanIEC61850Inputs != null)

for (int i = 0; i < ied.AccessPoints[0].BooleanIEC61850Inputs.Count; i++)

if (ied.AccessPoints[0].BooleanIEC61850Inputs[i].IsMapped)

for (int j = 0; j < lstViewGOOSESubscriberConf.Items.Count; j++)

if (lstViewGOOSESubscriberConf.SelectedItems[0].SubItems[0].Text ==
ied.AccessPoints[0].BooleanIEC61850Inputs[i].MappedIED &&

lstViewGOOSESubscriberConf.SelectedItems[0].SubItems[2].Text ==
ied.AccessPoints[0].BooleanIEC61850Inputs[i].MappedGOOSE)

ied.AccessPoints[0].BooleanIEC61850Inputs[i].MappedMACAddress =
frm.strMACAddress;

if (ied.AccessPoints[0].AnalogFloatIEC61850Inputs != null)

for (int i = 0; i < ied.AccessPoints[0].AnalogFloatIEC61850Inputs.Count; i++)

if (ied.AccessPoints[0].AnalogFloatIEC61850Inputs[i].IsMapped)

for (int j = 0; j < lstViewGOOSESubscriberConf.Items.Count; j++)


{

if (lstViewGOOSESubscriberConf.SelectedItems[0].SubItems[0].Text ==
ied.AccessPoints[0].AnalogFloatIEC61850Inputs[i].MappedIED &&

lstViewGOOSESubscriberConf.SelectedItems[0].SubItems[2].Text ==
ied.AccessPoints[0].AnalogFloatIEC61850Inputs[i].MappedGOOSE)

ied.AccessPoints[0].AnalogFloatIEC61850Inputs[i].MappedMACAddress =
frm.strMACAddress;

FillGooseSubscriberDetails();

/// <summary>

/// MouseDoubleClick event handler of lstViewGOOSESubscriberConf

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstViewGOOSESubscriberConf_MouseDoubleClick(object sender, MouseEventArgs


e)

if (!Global.CurrentUser.IEC61850Configuration)
{

return;

btnEditsubscriber_Click(null, null);

/// <summary>

/// Click event handler of btnEditDsLog. Navigates to dataset page with dataset of the log
control block selected.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnEditDsLog_Click(object sender, EventArgs e)

if (lstLogControlBlocks.SelectedItems.Count == 1 && lstLogControlBlocks.SelectedItems[0].Tag


!=null )

LogControl log = (LogControl)lstLogControlBlocks.SelectedItems[0].Tag;

if (log.DataSetName == null || log.DataSetName == "")

return;

string fulldsName = log.CBLDeviceName + "." + log.prefix + log.lnClass + log.inst + "." +


log.DataSetName;

if (log.DataSetName != null)

for (int i = 0; i < tabMain.TabCount; i++)

if (tabMain.TabPages[i].Name == "pageDatasets")

{
tabMain.SelectedIndex = i;

IEC61850Utililty.SetSelectItem(fulldsName, lstDataSets);

/// <summary>

/// Click event handler of btnPrintLog.Prints log control blocks details.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnPrintLog_Click(object sender, EventArgs e)

IEDConfigurationTool.PrintUtil.PrintDataFromListView(lstLogControlBlocks, "Log control


blocks details for " + iedDev.IEDDeviceInstanceName);

/// <summary>

/// Click event handler of btnAddSMV.Pop ups forms for selecting logical device and then
sampled value details

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnAddSMV_Click(object sender, EventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

{
MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);

return;

frmLogicalDevices frmLDevice = new frmLogicalDevices();

frmLDevice.ied = base.iedDev.SCLConfiguration.IEDs[0];

if (frmLDevice.ied != null)

if (frmLDevice.ShowDialog() == DialogResult.OK)

frmEditSMV frmsmv = new frmEditSMV();

frmsmv.edit = false;

frmsmv.ied = frmLDevice.ied;

frmsmv.LDevice = frmLDevice.LDeivce;

if (frmsmv.ShowDialog() == DialogResult.OK)

// FillSMVPublisherDetails("");

Global.NotifyLogWindow("SMV Control Block '" + frmsmv.txtSmvCBName.Text + "'


added to '" + frmsmv.ied .IEDInstanceName + "/" + frmsmv.LDevice + "'");

this.Cursor = Cursors.WaitCursor;

DisplayUtil.UpdateIEDNodeSMV(frmsmv.ied);

FillDataSets(lstDataSets.SelectedItems.Count > 0 ? lstDataSets.SelectedItems[0].Text :


"");

this.Cursor = Cursors.Default;

Global.ProjectSaveRequired = true;

Global.NotifyReloadIEDSmvNode(frmsmv.ied);

if (frmsmv != null)

frmsmv.Dispose();
}

if (frmLDevice != null)

frmLDevice.Dispose();

/// <summary>

/// Click event handler of btnAddLog.Pop ups form for adding log control block

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnAddLog_Click(object sender, EventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

frmAddLogControl frmlog = new frmAddLogControl();

frmlog.ied = base.iedDev.SCLConfiguration.IEDs[0];

frmlog.bedit = false;

if (frmlog.ied != null)

if (frmlog.ShowDialog() == DialogResult.OK)

FillLogControlBlocks(frmlog.AddedLog);
//FillDataSets(lstDataSets.SelectedItems.Count > 0 ? lstDataSets.SelectedItems[0].Text :
"");

Global.ProjectSaveRequired = true;

if (frmlog != null)

frmlog.Dispose();

/// <summary>

/// Click event handler of btnDeleteLog

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnDeleteLog_Click(object sender, EventArgs e)

if (!Global.CurrentUser.IEC61850Configuration)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (lstLogControlBlocks.SelectedItems.Count == 0)

MessageBox.Show("Please select a log control block to delete.", "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

bool bRcbDelete = false;


if (MessageBox.Show("Do you want to delete the selected Log Control Block/s?", "Confirm",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)

return;

IED ied = base.iedDev.SCLConfiguration.IEDs[0];

if (ied != null)

for (int i = 0; i < lstLogControlBlocks.SelectedItems.Count; i++)

if (lstLogControlBlocks.SelectedItems[i].Tag != null)

LogControl log = (LogControl)lstLogControlBlocks.SelectedItems[i].Tag;

if (log != null)

if (log.Orginal)

MessageBox.Show("You can not delete the original Log control block '" + log.name
+ "'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

continue;

LDevice ldev = ied.AccessPoints[0].GetLDevice(log.CBLDeviceName);

if (ldev != null)

if (ldev.RemoveLogControlBlock(log.name, log.prefix + log.lnClass + log.inst))

Global.NotifyLogWindow("Log Control Block '" + log.name + "' deleted from '" +


ldev.inst + "/" + log.prefix + log.lnClass + log.inst + "' of IED '" + ied.IEDInstanceName + "'");

bRcbDelete = true;

}
}

if (bRcbDelete)

FillLogControlBlocks("");

//FillDataSets(lstDataSets.SelectedItems.Count > 0 ? lstDataSets.SelectedItems[0].Text :


"");

Global.ProjectSaveRequired = true;

/// <summary>

/// Click event handler of btnRetreive. Retrieves startup settings from device.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnRetreive_Click(object sender, EventArgs e)

if (!Global.CurrentUser.RetrieveConfigurations)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (!ProjectUtil.IsTargetDeviceExpected(iedDev.IEDDeviceOrginalName, iedDev.IPAddress))

return;
ProjectUtil.CreateNecessaryFolders();

List<ftp.FtpFileInfo> fileinfo = new List<IEDConfigurationTool.ftp.FtpFileInfo>();

fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder + "\\Temp\\


StartUp.ini", "Applications/StartUp.ini"));

if (ProjectUtil.DownLoadFilesFromFtpServer(fileinfo, iedDev, "Retreiving startup file",


false,true ))

ProjectUtil.LoadStartupFile(Global.UserDataFolder + "\\Temp\\StartUp.ini",
iedDev.SCLConfiguration.IEDs[0]);

startupProperties.SelectedObject = iedDev.SCLConfiguration.IEDs[0].StartUpSettings;

iedProperties.SelectedObject = iedDev.SCLConfiguration.IEDs[0];

/// <summary>

/// Click event handler of btnRetrieveMUStartup. Retrieves MU startup settings from device.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnRetrieveMUStartup_Click(object sender, EventArgs e)

if (!Global.CurrentUser.RetrieveConfigurations)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (!ProjectUtil.IsTargetDeviceExpected(iedDev.IEDDeviceOrginalName, iedDev.IPAddress))

return;

ProjectUtil.CreateNecessaryFolders();
List<ftp.FtpFileInfo> fileinfo = new List<IEDConfigurationTool.ftp.FtpFileInfo>();

fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder + "\\Temp\\


SMVStartUp.ini", "Applications/SMVStartUp.ini"));

if (ProjectUtil.DownLoadFilesFromFtpServer(fileinfo, iedDev, "Retreiving SMV startup file",


false,true ))

ProjectUtil.LoadMUStartupFile(Global.UserDataFolder + "\\Temp\\SMVStartUp.ini",
iedDev.SCLConfiguration.IEDs[0]);

// muStartup.SelectedObject = iedDev.SCLConfiguration.IEDs[0].MUStartUpSettings;

/// <summary>

/// Click event handler of btnRetrieveSMVStartup. Retrieves SMV startup settings from device.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnRetrieveSMVStartup_Click(object sender, EventArgs e)

if (!Global.CurrentUser.RetrieveConfigurations)

MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

return;

if (!ProjectUtil.IsTargetDeviceExpected(iedDev.IEDDeviceOrginalName, iedDev.IPAddress))

return;

ProjectUtil.CreateNecessaryFolders();

List<ftp.FtpFileInfo> fileinfo = new List<IEDConfigurationTool.ftp.FtpFileInfo>();


fileinfo.Add(new IEDConfigurationTool.ftp.FtpFileInfo(Global.UserDataFolder + "\\Temp\\
SMVStartUp.ini", "Applications/SMVStartUp.ini"));

if (ProjectUtil.DownLoadFilesFromFtpServer(fileinfo, iedDev, "Retreiving SMVStartUp file",


false,true ))

ProjectUtil.LoadSMVStartupFile(Global.UserDataFolder + "\\Temp\\SMVStartUp.ini",
iedDev.SCLConfiguration.IEDs[0]);

// grdSmvStartup.SelectedObject = iedDev.SCLConfiguration.IEDs[0].SMVStartUpSettings;

private void pageLeafAddition_Click(object sender, EventArgs e)

private void MouseDownEvent(object sender, MouseEventArgs e)

try

TreeView tree = (TreeView)sender;

TreeNode node = tree.GetNodeAt(e.X, e.Y);

tree.SelectedNode = node;

DoDragDrop(node, DragDropEffects.Move);

catch
{

private void DragDropEffectEvent(object sender, DragEventArgs e)

try

Point targetPoint = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));

TreeNode targetNode = ((TreeView)sender).GetNodeAt(targetPoint);

TreeNode draggedNode = e.Data.GetData(typeof(TreeNode)) as TreeNode;

if (targetNode.Level == 1)

targetNode.Nodes.Add((TreeNode)draggedNode.Clone());

targetNode.Expand();

//remveOriginalNode

draggedNode.Remove();

catch (Exception ex)

{
MessageBox.Show(ex.ToString());

private void DragEnterEvent(object sender, DragEventArgs e)

e.Effect = DragDropEffects.Move;

string clickchange = "";

private void toolStripMenuItem1_Click(object sender, EventArgs e)

//if (clickchange == "treeView2" && treeView2.SelectedNode.Level == 2)

//{

// treeView2.Nodes.Remove(treeView2.SelectedNode);

//}

//else if (clickchange == "treeView3" && treeView3.SelectedNode.Level == 2)

//{

// treeView3.Nodes.Remove(treeView3.SelectedNode);

//}

//else if (clickchange == "treeView4" && treeView4.SelectedNode.Level == 2)

//{

// treeView4.Nodes.Remove(treeView4.SelectedNode);

//}

//else if (clickchange == "treeView5" && treeView5.SelectedNode.Level == 2)


//{

// treeView5.Nodes.Remove(treeView5.SelectedNode);

//}

//else if (clickchange == "treeView6" && treeView6.SelectedNode.Level == 2)

//{

// treeView6.Nodes.Remove(treeView6.SelectedNode);

//}

//else if (clickchange == "treeView7" && treeView7.SelectedNode.Level == 2)

//{

// treeView7.Nodes.Remove(treeView7.SelectedNode);

//}

//else if (clickchange == "treeView8" && treeView8.SelectedNode.Level == 2)

//{

// treeView8.Nodes.Remove(treeView8.SelectedNode);

//}

//else if (clickchange == "treeView9" && treeView9.SelectedNode.Level == 2)

//{

// treeView9.Nodes.Remove(treeView9.SelectedNode);

//}

//else if (clickchange == "treeView10" && treeView10.SelectedNode.Level == 2)

//{

// treeView10.Nodes.Remove(treeView10.SelectedNode);

//}

public string newkalkiaddress = "";

public string newshmaddress = "";


public string changekakliaddress = "";

public string changeshmaddress = "";

private void toolStripMenuItem2_Click(object sender, EventArgs e)

private void button2_Click(object sender, EventArgs e)

ArrayList list_1 = new ArrayList();

string str_frm = "";

int rowindex = 0;

private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)

//try

//{

// if (e.ColumnIndex == 0 && e.Button == MouseButtons.Right)

// {

// this.dataGridView1.Rows[e.RowIndex].Selected = true;
// this.rowindex = e.RowIndex;

// this.dataGridView1.CurrentCell = this.dataGridView1.Rows[e.RowIndex].Cells[1];

// this.contextMenuStrip3.Show(this.dataGridView1, e.Location);

// contextMenuStrip3.Show(Cursor.Position);

// }

// if (e.ColumnIndex == 4 && e.Button == MouseButtons.Right)

// {

// this.dataGridView1.Rows[e.RowIndex].Selected = true;

// this.rowindex = e.RowIndex;

// this.dataGridView1.CurrentCell = this.dataGridView1.Rows[e.RowIndex].Cells[1];

// this.contextMenuStrip4.Show(this.dataGridView1, e.Location);

// contextMenuStrip4.Show(Cursor.Position);

// }

//}

//catch { }

private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs


e)

if (e.ColumnIndex < 0 || e.RowIndex < 0)

return;

}
private void toolStripMenuItem3_Click(object sender, EventArgs e)

//if (!this.dataGridView1.Rows[this.rowindex].IsNewRow)

//{

// this.dataGridView1.Rows.RemoveAt(this.rowindex);

//}

private void contextMenuStrip4_ItemClicked(object sender, ToolStripItemClickedEventArgs e)

// this.dataGridView1.Rows[this.rowindex].Cells[4].Value = e.ClickedItem.Text;

private void button4_Click(object sender, EventArgs e)

//initializing the variables

string GP_extref_path = "";

string[] dummy = new string[4];

ArrayList GP_arlst = new ArrayList();


public static string SV_shmtype = "";

public static string SV_shmaddress = "";

string SV_extref_path = "";

string[] SV_dummy = new string[4];

ArrayList SV_arlst = new ArrayList();

ArrayList integer = new ArrayList();

ArrayList quality = new ArrayList();

ArrayList integer_2 = new ArrayList();

ArrayList quality_2 = new ArrayList();

ArrayList combined = new ArrayList();

int i_2 = 0;

int q_2 = 0;

public static string GP_shmtype = "";

public static string GP_shmaddress = "";

ArrayList list_ieds = new ArrayList();

ArrayList samelist_ied_ldins_srcCBName = new ArrayList();

//ArrayList goose_datatype = new ArrayList();

//ArrayList goose_shm = new ArrayList();

//ArrayList goose_srcbname = new ArrayList();

void IEC_Export()

if (File.Exists(LablelClass.pathname + "\\IEC_EXPORT.txt"))
{

File.Delete(LablelClass.pathname + "\\IEC_EXPORT.txt");

StreamWriter sw = new StreamWriter(LablelClass.pathname + "\\IEC_EXPORT.txt");

sw.WriteLine(LablelClass.pathname + "\\" + openFileDialog1.SafeFileName);

sw.WriteLine(LablelClass.pathname + "\\" + "StartUp.ini");

sw.WriteLine(LablelClass.pathname + "\\" + openFileDialog1.SafeFileName.Replace(".scd",


"").Replace(".iid", "").Replace(".cid", "") + ".ini");

sw.WriteLine(LablelClass.pathname + "\\" +"GOOSESUBMAPPING.txt");

sw.WriteLine(LablelClass.pathname + "\\" +"METER_COMM_DB.txt");

sw.Close();

ArrayList repeat_dataset = new ArrayList();

ArrayList repeat_daname = new ArrayList();

TreeNode trvfcd = new TreeNode();

TreeNode trvolddatset = new TreeNode();

ArrayList addlisttrv = new ArrayList();

TreeNode trvoldied = new TreeNode();

static frmProgress frmprog = new frmProgress();

static System.ComponentModel.BackgroundWorker backGroundSaveThread = new


System.ComponentModel.BackgroundWorker();

static bool saveSuccess = false;

static void backGroundSaveThread_DoWork(object sender,


System.ComponentModel.DoWorkEventArgs e)
{

try

if (e.Argument is Project)

Project projecttoSave = e.Argument as Project;

projecttoSave.Version = new Project().Version;

Serializer<Project> serializeproject = new Serializer<Project>();

if (!System.IO.Directory.Exists(projecttoSave.ProjectPath))

try

System.IO.Directory.CreateDirectory(projecttoSave.ProjectPath);

catch (Exception ex)

MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

e.Result = "Fail";

return;

serializeproject.Serialize(projecttoSave.ProjectPath + "\\" + projecttoSave.Name +


".bhelproj", projecttoSave);

foreach (IEDDevice ieddev in projecttoSave.IEDDeviceCollection)

Serializer<IEDDevice> ied = new Serializer<IEDDevice>();

if (!System.IO.Directory.Exists(projecttoSave.ProjectPath + "\\" +
ieddev.IEDDeviceInstanceName))
{

try

System.IO.Directory.CreateDirectory(projecttoSave.ProjectPath + "\\" +
ieddev.IEDDeviceInstanceName);

catch (Exception ex)

MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

e.Result = "Fail";

return;

ied.Serialize(projecttoSave.ProjectPath + "\\" + ieddev.IEDDeviceInstanceName + "\\" +


ieddev.IEDDeviceInstanceName + ".iedc", ieddev);

if (ieddev.Type == IEDDevice.IEDType.Local)

if (!System.IO.Directory.Exists(projecttoSave.ProjectPath + "\\" +
ieddev.IEDDeviceInstanceName + "\\" + Global.DRFolder))

System.IO.Directory.CreateDirectory(projecttoSave.ProjectPath + "\\" +
ieddev.IEDDeviceInstanceName + "\\" + Global.DRFolder);

string[] directories = System.IO.Directory.GetDirectories(projecttoSave.ProjectPath);

foreach (string strDir in directories)

{
string IEDFolderName = strDir.Substring(strDir.LastIndexOf('\\') + 1);

if (!projecttoSave.IEDs.Contains(IEDFolderName))

try

//Deleting IED folder which are not in project

System.IO.Directory.Delete(strDir, true);

catch (Exception ex)

MessageBox.Show(ex.Message + "\nDeleting of IED folder " + IEDFolderName + "


failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

catch (Exception ex)

LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

}
}

/// <summary>

/// RunWorkerCompleted event handler of BackgroundWorker thread backGroundSaveThread

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

static void backGroundSaveThread_RunWorkerCompleted(object sender,


System.ComponentModel.RunWorkerCompletedEventArgs e)

saveSuccess = true;

if (e.Result != null && e.Result.ToString() == "Fail")

saveSuccess = false;

MessageBox.Show("Saving project failed.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

Global.NotifyChangeEnableStatus(true);

if (frmprog != null)

frmprog.autoclose = true;

frmprog.Close();

private void frmEd2IEC61850Configuration_Enter(object sender, EventArgs e)


{

string split1 = label10.Text;

LablelClass.pathname = WorkSpace.CurrentProject.ProjectPath + "\\" + split1;

private void iednames_preconfigured_KeyPress(object sender, KeyPressEventArgs e)

e.Handled = true;

private void exportAndSendEd2ConfigurationWithoutGooseToolStripMenuItem_Click(object


sender, EventArgs e)

private bool ExportCIDFile_Ed2withoutGoose(string IEDName, string File, bool


skipGooseMapping)

try

SCL scl = WorkSpace.CurrentProject.IEDDeviceCollection[IEDName].SCLConfiguration;

if (scl == null)

MessageBox.Show("No SCL configuration found for " + IEDName, "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error);

return false;

IED ied = scl.IEDs[0];


if (ied == null)

MessageBox.Show("Please select a IED from project.", "Message",


MessageBoxButtons.OK, MessageBoxIcon.Information);

return false;

XmlDocument xdoc = new XmlDocument();

if (ied.IEDFileContents.Trim() != "")

try

xdoc.LoadXml(ProjectUtil.DecompressText(ied.IEDFileContents));

catch

MessageBox.Show("Loading IED file contents for " + IEDName + " failed.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

Global.NotifyLogWindow("Loading IED file contents for " + IEDName + " failed.");

return false;

else

MessageBox.Show("IED file contents not found for " + IEDName, "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error);

Global.NotifyLogWindow("IED file contents not found for " + IEDName);

return false;

}
ExportCIDUtil.UpdateDataSetInfo(xdoc, ied);

ExportCIDUtil.UpdateLogControlBlockInfo(xdoc, ied);

ExportCIDUtil.UpdateReportControlBlockInfo(xdoc, ied);

ExportCIDUtil.UpdateGooseControlBlockInfo(xdoc, ied);

xdoc.Save(File);

return true;

catch (Exception ex)

MessageBox.Show("Exporting CID file failed.", "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error);

Global.NotifyLogWindow(ex.Message);

LoggerUtil.Instance.WriteToLog(ex.Message + "\t" + ex.StackTrace);

return false;

private void pageED2GooseSubscription_Click(object sender, EventArgs e)

private void exportCIDToolStripMenuItem_Click(object sender, EventArgs e)

{
}

private void customButton1_Click(object sender, EventArgs e)

FolderBrowserDialog save = new FolderBrowserDialog();

XmlDocument xdoc = new XmlDocument();

if (save.ShowDialog() == DialogResult.OK)

try

xdoc.Load(LablelClass.editdynamicsclpath);

UpdateDataSetInfo(xdoc, LablelClass.ied);

UpdateReportControlBlockInfo(xdoc, LablelClass.ied);

UpdateGooseControlBlockInfo(xdoc, LablelClass.ied);

catch

MessageBox.Show("Loading IED file contents for " + LablelClass.editdynamicsclpath + "


failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

Global.NotifyLogWindow("Loading IED file contents for " + LablelClass.editdynamicsclpath


+ " failed.");

string IEDFolderName =
LablelClass.editdynamicsclpath.Substring(LablelClass.editdynamicsclpath.LastIndexOf('\\') + 1);

xdoc.Save(save.SelectedPath + "\\" + IEDFolderName);


this.Close();

/// <summary>

/// Updates the Dataset info for all logical nodes of all logical devices in the IED

/// </summary>

/// <param name="xdoc">XMLDocument of the IED</param>

/// <param name="IEDName">IED Name</param>

public static void UpdateDataSetInfo(XmlDocument xdoc, IED ied)

//IED ied =
WorkspaceManagement.WorkSpace.CurrentProject.IEDCollection[IEDName].SCLConfiguration.IEDs[
0];

if (ied == null)

return;

XmlNodeList xmlLN;

List<LDevice> LogicalDevices = ied.AccessPoints[0].LogicalDevices;

for (int i = 0; i < LogicalDevices.Count; i++)

for (int j = 0; j < LogicalDevices[i].LN0s.Count; j++)

xmlLN = xdoc.SelectNodes("/*[local-name()='SCL']" +

"/*[local-name()='IED'][@name='" + ied.IEDOriginalName + "']" +

"/*[local-name()='AccessPoint'][@name='" + ied.AccessPoint + "']" +

"/*[local-name()='Server']" +
"/*[local-name()='LDevice'][@inst='" + LogicalDevices[i].inst + "']" +

"/*[local-name()='LN0']");

if (xmlLN.Count > 0)

//Removing existing Datasets

for (int x = 0; x < xmlLN[0].ChildNodes.Count; x++)

if (xmlLN[0].ChildNodes[x].Name == "DataSet")

xmlLN[0].RemoveChild(xmlLN[0].ChildNodes[x]);

x--;

//inserting new Dataset

for (int iDataSet = LogicalDevices[i].LN0s[j].DataSets.Count - 1; iDataSet >= 0;


iDataSet--)

Dictionary<string, string> refrencedgoose =


LogicalDevices[i].GetGOOSEPublisherReferencesofDataset(LogicalDevices[i].LN0s[j].DataSets[iDataSe
t].DataSetName, "LLN0");

Dictionary<string, string> refrencedrcb =


LogicalDevices[i].GetRCBPublisherReferencesofDataset(LogicalDevices[i].LN0s[j].DataSets[iDataSet].
DataSetName, "LLN0");

Dictionary<string, string> refrencedsmv =


LogicalDevices[i].GetSMVPublisherReferencesofDataset(LogicalDevices[i].LN0s[j].DataSets[iDataSet].
DataSetName, "LLN0");

if (refrencedgoose.Count == 0 && refrencedrcb.Count == 0 && refrencedsmv.Count


== 0)

continue;

CreateDataSetElement(xdoc, xmlLN[0], LogicalDevices[i].LN0s[j].DataSets[iDataSet]);

}
}

for (int j = 0; j < LogicalDevices[i].LNs.Count; j++)

xmlLN = xdoc.SelectNodes("/*[local-name()='SCL']" +

"/*[local-name()='IED'][@name='" + ied.IEDOriginalName + "']" +

"/*[local-name()='AccessPoint'][@name='" + ied.AccessPoint + "']" +

"/*[local-name()='Server']" +

"/*[local-name()='LDevice'][@inst='" + LogicalDevices[i].inst + "']" +

"/*[local-name()='LN'][@lnClass='" + LogicalDevices[i].LNs[j].lnClass + "' and


@inst='" + LogicalDevices[i].LNs[j].inst + "' and @prefix ='" + LogicalDevices[i].LNs[j].prefix + "']");

if (xmlLN.Count > 0)

//Removing existing Datasets

for (int x = 0; x < xmlLN[0].ChildNodes.Count; x++)

if (xmlLN[0].ChildNodes[x].Name == "DataSet")

xmlLN[0].RemoveChild(xmlLN[0].ChildNodes[x]);

x--;

//inserting new Dataset

for (int iDataSet = LogicalDevices[i].LNs[j].DataSets.Count - 1; iDataSet >= 0; iDataSet--)

Dictionary<string, string> refrencedrcb =


LogicalDevices[i].GetRCBPublisherReferencesofDataset(LogicalDevices[i].LNs[j].DataSets[iDataSet].D
ataSetName, LogicalDevices[i].LNs[j].DataSets[iDataSet].prefix +
LogicalDevices[i].LNs[j].DataSets[iDataSet].lnClass +
LogicalDevices[i].LNs[j].DataSets[iDataSet].lninst);

if (refrencedrcb.Count == 0)

continue;

CreateDataSetElement(xdoc, xmlLN[0], LogicalDevices[i].LNs[j].DataSets[iDataSet]);

/// <summary>

/// Creates dataset element and FCDA elements for the dataset

/// </summary>

/// <param name="xdoc">XMLDocument of the IED</param>

/// <param name="xmlnode">XML node to which Dataset node is added as a child</param>

/// <param name="ds">Dataset details</param>

public static void CreateDataSetElement(XmlDocument xdoc, XmlNode xmlnode, DataSet ds)

if (ds != null)

if (ds.Items.Count == 0)

return;

XmlNode xmlDocFragment = xdoc.CreateNode(XmlNodeType.Element, "DataSet",


"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributename = xdoc.CreateAttribute("name");

attributename.Value = ds.DataSetName;

xmlDocFragment.Attributes.Append(attributename);
XmlAttribute attributedesc = xdoc.CreateAttribute("desc");

attributedesc.Value = ds.Description;

xmlDocFragment.Attributes.Append(attributedesc);

XmlNode xmlDataset = xmlnode.InsertBefore(xmlDocFragment, xmlnode.FirstChild);

List<FCDA> fcda = ds.Items;

for (int j = fcda.Count - 1; j >= 0; j--)

xmlDocFragment = xdoc.CreateNode(XmlNodeType.Element, "FCDA",


"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributeldInst = xdoc.CreateAttribute("ldInst");

attributeldInst.Value = fcda[j].ldInst;

xmlDocFragment.Attributes.Append(attributeldInst);

XmlAttribute attributelnClass = xdoc.CreateAttribute("lnClass");

attributelnClass.Value = fcda[j].lnClass;

xmlDocFragment.Attributes.Append(attributelnClass);

XmlAttribute attributefc = xdoc.CreateAttribute("fc");

attributefc.Value = fcda[j].fc;

xmlDocFragment.Attributes.Append(attributefc);

XmlAttribute attributeprefix = xdoc.CreateAttribute("prefix");

attributeprefix.Value = fcda[j].prefix;

xmlDocFragment.Attributes.Append(attributeprefix);

if (fcda[j].lnClass != "LLN0")

XmlAttribute attributelnInst = xdoc.CreateAttribute("lnInst");

attributelnInst.Value = fcda[j].lnInst;

xmlDocFragment.Attributes.Append(attributelnInst);

}
XmlAttribute attributedoName = xdoc.CreateAttribute("doName");

XmlAttribute attributedaName = xdoc.CreateAttribute("daName");

if (fcda[j].doname != null && fcda[j].doname != "")

attributedoName.Value = fcda[j].doname;

xmlDocFragment.Attributes.Append(attributedoName);

if (fcda[j].daname != null && fcda[j].daname != "")

attributedaName.Value = fcda[j].daname;

xmlDocFragment.Attributes.Append(attributedaName);

xmlDataset.InsertBefore(xmlDocFragment, xmlDataset.FirstChild);

/// <summary>

/// Updates the Report control block info for all logical nodes of all logical devices in the IED

/// </summary>

/// <param name="xdoc">XMLDocument of the IED</param>

/// <param name="IEDName">IED Name</param>

public static void UpdateReportControlBlockInfo(XmlDocument xdoc, IED ied)

XmlNodeList xmlLN;
DataSet ds;

//IED ied =
WorkspaceManagement.WorkSpace.CurrentProject.IEDCollection[IEDName].SCLConfiguration.IEDs[
0];

if (ied == null)

return;

List<LDevice> LogicalDevices = ied.AccessPoints[0].LogicalDevices;

for (int i = 0; i < LogicalDevices.Count; i++)

for (int j = 0; j < LogicalDevices[i].LN0s.Count; j++)

xmlLN = xdoc.SelectNodes("/*[local-name()='SCL']" +

"/*[local-name()='IED'][@name='" + ied.IEDOriginalName + "']" +

"/*[local-name()='AccessPoint'][@name='" + ied.AccessPoint + "']" +

"/*[local-name()='Server']" +

"/*[local-name()='LDevice'][@inst='" + LogicalDevices[i].inst + "']" +

"/*[local-name()='LN0']");

if (xmlLN.Count > 0)

//Removing existing Reports

for (int x = 0; x < xmlLN[0].ChildNodes.Count; x++)

if (xmlLN[0].ChildNodes[x].Name == "ReportControl")

xmlLN[0].RemoveChild(xmlLN[0].ChildNodes[x]);

x--;

}
XmlNode xmlLastDataSet = xmlLN[0];

for (int x = 0; x < xmlLN[0].ChildNodes.Count; x++)

if (xmlLN[0].ChildNodes[x].Name == "DataSet")

xmlLastDataSet = xmlLN[0].ChildNodes[x];

//inserting new ReportControl

for (int iRpt = LogicalDevices[i].LN0s[j].Reports.Count - 1; iRpt >= 0; iRpt--)

ds = null;

if (LogicalDevices[i].LN0s[j].Reports[iRpt].IsPublisher)

ds =
LogicalDevices[i].GetDataSet(LogicalDevices[i].LN0s[j].Reports[iRpt].DataSetName, "LLN0");

if (ds != null)

if (ds.Items.Count > 0)

CreateReportControlBlockElement(xdoc, xmlLN[0], xmlLastDataSet,


LogicalDevices[i].LN0s[j].Reports[iRpt]);

else

Global.NotifyLogWindow("Report Control Block '" +


LogicalDevices[i].LN0s[j].Reports[iRpt].CBLDeviceName + "/" +
LogicalDevices[i].LN0s[j].Reports[iRpt].prefix + LogicalDevices[i].LN0s[j].Reports[iRpt].lnClass +
LogicalDevices[i].LN0s[j].Reports[iRpt].inst + "$" + LogicalDevices[i].LN0s[j].Reports[iRpt].name + "' is
discarded from cid file since it's dataset '" + LogicalDevices[i].LN0s[j].Reports[iRpt].DataSetName + "'
has no fcda elements");

else

Global.NotifyLogWindow("Report Control Block '" +


LogicalDevices[i].LN0s[j].Reports[iRpt].CBLDeviceName + "/" +
LogicalDevices[i].LN0s[j].Reports[iRpt].prefix + LogicalDevices[i].LN0s[j].Reports[iRpt].lnClass +
LogicalDevices[i].LN0s[j].Reports[iRpt].inst + "$" + LogicalDevices[i].LN0s[j].Reports[iRpt].name + "' is
discarded from cid file since it has a invalid dataset '" +
LogicalDevices[i].LN0s[j].Reports[iRpt].DataSetName + "'");

for (int j = 0; j < LogicalDevices[i].LNs.Count; j++)

xmlLN = xdoc.SelectNodes("/*[local-name()='SCL']" +

"/*[local-name()='IED'][@name='" + ied.IEDOriginalName + "']" +

"/*[local-name()='AccessPoint'][@name='" + ied.AccessPoint + "']" +

"/*[local-name()='Server']" +

"/*[local-name()='LDevice'][@inst='" + LogicalDevices[i].inst + "']" +

"/*[local-name()='LN'][@lnClass='" + LogicalDevices[i].LNs[j].lnClass + "' and


@inst='" + LogicalDevices[i].LNs[j].inst + "' and @prefix ='" + LogicalDevices[i].LNs[j].prefix + "']");

if (xmlLN.Count > 0)

//Removing existing Reports

for (int x = 0; x < xmlLN[0].ChildNodes.Count; x++)


{

if (xmlLN[0].ChildNodes[x].Name == "ReportControl")

xmlLN[0].RemoveChild(xmlLN[0].ChildNodes[x]);

x--;

XmlNode xmlLastDataSet = xmlLN[0];

for (int x = 0; x < xmlLN[0].ChildNodes.Count; x++)

if (xmlLN[0].ChildNodes[x].Name == "DataSet")

xmlLastDataSet = xmlLN[0].ChildNodes[x];

//inserting new ReportControl

for (int iRpt = LogicalDevices[i].LNs[j].Reports.Count - 1; iRpt >= 0; iRpt--)

ds = null;

if (LogicalDevices[i].LNs[j].Reports[iRpt].IsPublisher)

ds =
LogicalDevices[i].GetDataSet(LogicalDevices[i].LNs[j].Reports[iRpt].DataSetName,
LogicalDevices[i].LNs[j].prefix + LogicalDevices[i].LNs[j].lnClass + LogicalDevices[i].LNs[j].inst);

if (ds != null)

if (ds.Items.Count > 0)

{
CreateReportControlBlockElement(xdoc, xmlLN[0], xmlLastDataSet,
LogicalDevices[i].LNs[j].Reports[iRpt]);

else

Global.NotifyLogWindow("Report Control Block '" +


LogicalDevices[i].LNs[j].Reports[iRpt].CBLDeviceName + "/" +
LogicalDevices[i].LNs[j].Reports[iRpt].prefix + LogicalDevices[i].LNs[j].Reports[iRpt].lnClass +
LogicalDevices[i].LNs[j].Reports[iRpt].inst + "$" + LogicalDevices[i].LNs[j].Reports[iRpt].name + "' is
discarded from cid file since it's dataset '" + LogicalDevices[i].LNs[j].Reports[iRpt].DataSetName + "'
has no fcda elements");

else

Global.NotifyLogWindow("Report Control Block '" +


LogicalDevices[i].LNs[j].Reports[iRpt].CBLDeviceName + "/" +
LogicalDevices[i].LNs[j].Reports[iRpt].prefix + LogicalDevices[i].LNs[j].Reports[iRpt].lnClass +
LogicalDevices[i].LNs[j].Reports[iRpt].inst + "$" + LogicalDevices[i].LNs[j].Reports[iRpt].name + "' is
discarded from cid file since it has a invalid dataset '" +
LogicalDevices[i].LNs[j].Reports[iRpt].DataSetName + "'");

/// <summary>

/// Creates Report control block element

/// </summary>
/// <param name="xdoc">XMLDocument of the IED</param>

/// <param name="xmlNodeLN">Parent XML node in which Report control block is inserted
</param>

/// <param name="xmlNodelastDS">Last dataset node after which Report control block is
inserted</param>

/// <param name="rcb">ReportControlBlock details</param>

public static void CreateReportControlBlockElement(XmlDocument xdoc, XmlNode xmlNodeLN,


XmlNode xmlNodelastDS, ReportControlBlock rcb)

if (rcb.DataSetName != null)

if (rcb.DataSetName.Trim() != "")

XmlNode xmlDocNodeRcb = xdoc.CreateNode(XmlNodeType.Element, "ReportControl",


"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributename = xdoc.CreateAttribute("name");

attributename.Value = rcb.name;

xmlDocNodeRcb.Attributes.Append(attributename);

XmlAttribute attributedesc = xdoc.CreateAttribute("desc");

attributedesc.Value = rcb.desc;

xmlDocNodeRcb.Attributes.Append(attributedesc);

XmlAttribute attributeds = xdoc.CreateAttribute("datSet");

attributeds.Value = rcb.DataSetName;

xmlDocNodeRcb.Attributes.Append(attributeds);

XmlAttribute attributeintergper = xdoc.CreateAttribute("intgPd");


attributeintergper.Value = rcb.IntegrityPeriod.ToString();

xmlDocNodeRcb.Attributes.Append(attributeintergper);

XmlAttribute attributeappid = xdoc.CreateAttribute("rptID");

attributeappid.Value = rcb.ID;

xmlDocNodeRcb.Attributes.Append(attributeappid);

XmlAttribute attributeconf = xdoc.CreateAttribute("confRev");

attributeconf.Value = rcb.confRev;

xmlDocNodeRcb.Attributes.Append(attributeconf);

XmlAttribute attributebuufferd = xdoc.CreateAttribute("buffered");

attributebuufferd.Value = rcb.Buffered.ToString().ToLower();

xmlDocNodeRcb.Attributes.Append(attributebuufferd);

XmlAttribute attributebuuffertime = xdoc.CreateAttribute("bufTime");

attributebuuffertime.Value = rcb.BufferTime.ToString().ToLower();

xmlDocNodeRcb.Attributes.Append(attributebuuffertime);

XmlNode xmlNodeTrgOps = xdoc.CreateNode(XmlNodeType.Element, "TrgOps",


"http://www.iec.ch/61850/2003/SCL");

if (rcb.TrgOps.dchg)

XmlAttribute attributedchg = xdoc.CreateAttribute("dchg");

attributedchg.Value = rcb.TrgOps.dchg.ToString().ToLower();

xmlNodeTrgOps.Attributes.Append(attributedchg);

if (rcb.TrgOps.qchg)

XmlAttribute attributeqchg = xdoc.CreateAttribute("qchg");

attributeqchg.Value = rcb.TrgOps.qchg.ToString().ToLower();

xmlNodeTrgOps.Attributes.Append(attributeqchg);
}

if (rcb.TrgOps.dupd)

XmlAttribute attributedupd = xdoc.CreateAttribute("dupd");

attributedupd.Value = rcb.TrgOps.dupd.ToString().ToLower();

xmlNodeTrgOps.Attributes.Append(attributedupd);

if (rcb.TrgOps.period)

XmlAttribute attributeperiod = xdoc.CreateAttribute("period");

attributeperiod.Value = rcb.TrgOps.period.ToString().ToLower();

xmlNodeTrgOps.Attributes.Append(attributeperiod);

//if (rcb.TrgOps.gi)

//{

// XmlAttribute attributegi = xdoc.CreateAttribute("gi");

// attributegi.Value = rcb.TrgOps.gi.ToString().ToLower();

// xmlNodeTrgOps.Attributes.Append(attributegi);

//}

xmlDocNodeRcb.AppendChild(xmlNodeTrgOps);

XmlNode xmlNodeOptFields = xdoc.CreateNode(XmlNodeType.Element, "OptFields",


"http://www.iec.ch/61850/2003/SCL");

if (rcb.OptFields.seqNum)

XmlAttribute attributeseqNum = xdoc.CreateAttribute("seqNum");

attributeseqNum.Value = rcb.OptFields.seqNum.ToString().ToLower();

xmlNodeOptFields.Attributes.Append(attributeseqNum);
}

if (rcb.OptFields.timeStamp)

XmlAttribute attributetimeStamp = xdoc.CreateAttribute("timeStamp");

attributetimeStamp.Value = rcb.OptFields.timeStamp.ToString().ToLower();

xmlNodeOptFields.Attributes.Append(attributetimeStamp);

if (rcb.OptFields.dataSet)

XmlAttribute attributedataSet = xdoc.CreateAttribute("dataSet");

attributedataSet.Value = rcb.OptFields.dataSet.ToString().ToLower();

xmlNodeOptFields.Attributes.Append(attributedataSet);

if (rcb.OptFields.reasonCode)

XmlAttribute attributereasonCode = xdoc.CreateAttribute("reasonCode");

attributereasonCode.Value = rcb.OptFields.reasonCode.ToString().ToLower();

xmlNodeOptFields.Attributes.Append(attributereasonCode);

if (rcb.OptFields.dataRef)

XmlAttribute attributedataRef = xdoc.CreateAttribute("dataRef");

attributedataRef.Value = rcb.OptFields.dataRef.ToString().ToLower();

xmlNodeOptFields.Attributes.Append(attributedataRef);

if (rcb.OptFields.entryID && rcb.Buffered)

{
XmlAttribute attributeentryID = xdoc.CreateAttribute("entryID");

attributeentryID.Value = rcb.OptFields.entryID.ToString().ToLower();

xmlNodeOptFields.Attributes.Append(attributeentryID);

if (rcb.OptFields.configRef)

XmlAttribute attributeconfigRef = xdoc.CreateAttribute("configRef");

attributeconfigRef.Value = rcb.OptFields.configRef.ToString().ToLower();

xmlNodeOptFields.Attributes.Append(attributeconfigRef);

if (rcb.OptFields.bufOvfl && rcb.Buffered)

XmlAttribute attributebufOvfl = xdoc.CreateAttribute("bufOvfl");

attributebufOvfl.Value = rcb.OptFields.bufOvfl.ToString().ToLower();

xmlNodeOptFields.Attributes.Append(attributebufOvfl);

xmlDocNodeRcb.AppendChild(xmlNodeOptFields);

XmlNode xmlNodeRptEnabled = xdoc.CreateNode(XmlNodeType.Element, "RptEnabled",


"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributemax = xdoc.CreateAttribute("max");

attributemax.Value = rcb.NoOfInstances.ToString().ToLower();

xmlNodeRptEnabled.Attributes.Append(attributemax);

xmlDocNodeRcb.AppendChild(xmlNodeRptEnabled);

xmlNodeLN.InsertAfter(xmlDocNodeRcb, xmlNodelastDS);
}

else

Global.NotifyLogWindow("Report Control Block '" + rcb.CBLDeviceName + "/" + rcb.prefix


+ rcb.lnClass + rcb.inst + "$" + rcb.name + "' is discarded from cid file since it has blank dataset
name");

else

Global.NotifyLogWindow("Report Control Block '" + rcb.CBLDeviceName + "/" + rcb.prefix +


rcb.lnClass + rcb.inst + "$" + rcb.name + "' is discarded from cid file since it has blank dataset name");

/// <summary>

/// Updates the GOOSE control block info for all logical devices in the IED

/// </summary>

/// <param name="xdoc">XMLDocument of the IED</param>

/// <param name="IEDName">IED Name</param>

public static void UpdateGooseControlBlockInfo(XmlDocument xdoc, IED ied)

// IED ied =
WorkspaceManagement.WorkSpace.CurrentProject.IEDCollection[IEDName].SCLConfiguration.IEDs[
0];

if (ied == null)

return;

XmlNodeList xmlLN;

List<LDevice> LogicalDevices = ied.AccessPoints[0].LogicalDevices;


XmlNodeList nodeConnectedAP = xdoc.SelectNodes("/*[local-name()='SCL']/*[local-
name()='Communication']/*" +

"[local-name()='SubNetwork']/*[local-name()='ConnectedAP'][@iedName='" +
ied.IEDOriginalName + "' and @apName='" + ied.AccessPoint + "']");

if (nodeConnectedAP != null)

if (nodeConnectedAP.Count > 0)

//Removing all GSE from addressing section

for (int icnt = 0; icnt < nodeConnectedAP[0].ChildNodes.Count; icnt++)

if (nodeConnectedAP[0].ChildNodes[icnt].Name == "GSE")

nodeConnectedAP[0].RemoveChild(nodeConnectedAP[0].ChildNodes[icnt]);

icnt--;

for (int i = 0; i < LogicalDevices.Count; i++)

for (int j = 0; j < LogicalDevices[i].LN0s.Count; j++)

xmlLN = xdoc.SelectNodes("/*[local-name()='SCL']" +

"/*[local-name()='IED'][@name='" + ied.IEDOriginalName + "']" +

"/*[local-name()='AccessPoint'][@name='" + ied.AccessPoint + "']" +


"/*[local-name()='Server']" +

"/*[local-name()='LDevice'][@inst='" + LogicalDevices[i].inst + "']" +

"/*[local-name()='LN0']");

if (xmlLN.Count > 0)

//Removing existing Goose

for (int x = 0; x < xmlLN[0].ChildNodes.Count; x++)

if (xmlLN[0].ChildNodes[x].Name == "GSEControl")

xmlLN[0].RemoveChild(xmlLN[0].ChildNodes[x]);

x--;

XmlNode nodeLast = null;

for (int y = xmlLN[0].ChildNodes.Count - 1; y >= 0; y--)

if (xmlLN[0].ChildNodes[y].Name == "DOI")

nodeLast = xmlLN[0].ChildNodes[y];

break;

if (xmlLN[0].ChildNodes[y].Name == "LogControl")

nodeLast = xmlLN[0].ChildNodes[y];

break;

}
if (xmlLN[0].ChildNodes[y].Name == "ReportControl")

nodeLast = xmlLN[0].ChildNodes[y];

break;

if (xmlLN[0].ChildNodes[y].Name == "DataSet")

nodeLast = xmlLN[0].ChildNodes[y];

break;

DataSet ds = null;

//inserting new Goose

for (int iGoose = LogicalDevices[i].LN0s[j].GooseControlBlocks.Count - 1; iGoose >= 0;


iGoose--)

ds = null;

if (LogicalDevices[i].LN0s[j].GooseControlBlocks[iGoose].IsPublisher)

ds =
LogicalDevices[i].GetDataSet(LogicalDevices[i].LN0s[j].GooseControlBlocks[iGoose].DataSetName,
"LLN0");

if (ds != null)

if (ds.Items.Count == 0)

Global.NotifyLogWindow("GOOSE Control Block '" +


LogicalDevices[i].LN0s[j].GooseControlBlocks[iGoose].CBLDeviceName + "/LLN0$" +
LogicalDevices[i].LN0s[j].GooseControlBlocks[iGoose].name + "' is discarded from cid file since it's
dataset '" + LogicalDevices[i].LN0s[j].GooseControlBlocks[iGoose].DataSetName + "' has no fcda
elements");

continue;

CreateGooseElement(xdoc, xmlLN[0], nodeLast,


LogicalDevices[i].LN0s[j].GooseControlBlocks[iGoose]);

for (int iGoose = 0; iGoose < LogicalDevices[i].LN0s[j].GooseControlBlocks.Count;


iGoose++)

if (nodeConnectedAP.Count > 0)

if (LogicalDevices[i].LN0s[j].GooseControlBlocks[iGoose].IsPublisher)

CreateGooseAddressingSection(xdoc, nodeConnectedAP[0],
LogicalDevices[i].LN0s[j].GooseControlBlocks[iGoose]);

/// <summary>

/// Creates GOOSE control block


/// </summary>

/// <param name="xdoc">XMLDocument of IED</param>

/// <param name="lnNode">XML node to which GOOSE node is added as a child</param>

/// <param name="xmlnode">XML node after which GOOSE node is inserted</param>

/// <param name="gse">GOOSE details</param>

public static void CreateGooseElement(XmlDocument xdoc, XmlNode lnNode, XmlNode


xmlnode, GSEControl gse)

if (gse.DataSetName != null)

if (gse.DataSetName.Trim() != "")

XmlNode xmlDocFragment = xdoc.CreateNode(XmlNodeType.Element, "GSEControl",


"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributename = xdoc.CreateAttribute("name");

attributename.Value = gse.name;

xmlDocFragment.Attributes.Append(attributename);

XmlAttribute attributeappid = xdoc.CreateAttribute("appID");

attributeappid.Value = gse.ID;

xmlDocFragment.Attributes.Append(attributeappid);

XmlAttribute attributeds = xdoc.CreateAttribute("datSet");

attributeds.Value = gse.DataSetName;

xmlDocFragment.Attributes.Append(attributeds);

XmlAttribute attributeconf = xdoc.CreateAttribute("confRev");

attributeconf.Value = gse.confRev;

xmlDocFragment.Attributes.Append(attributeconf);
XmlAttribute attributedesc = xdoc.CreateAttribute("desc");

attributedesc.Value = gse.desc;

xmlDocFragment.Attributes.Append(attributedesc);

lnNode.InsertAfter(xmlDocFragment, xmlnode);

else

Global.NotifyLogWindow("GOOSE Control Block '" + gse.CBLDeviceName + "/LLN0$" +


gse.name + "' is discarded from cid file since it has blank dataset name");

else

Global.NotifyLogWindow("GOOSE Control Block '" + gse.CBLDeviceName + "/LLN0$" +


gse.name + "' is discarded from cid file since it has blank dataset name");

/// <summary>

/// Creates the GSE element in GOOSE addressing section

/// </summary>

/// <param name="xdoc">XmlDocument of IED</param>

/// <param name="xmlnode">XML node to which GSE node is added as a child</param>

/// <param name="gse"></param>

public static void CreateGooseAddressingSection(XmlDocument xdoc, XmlNode xmlnode,


GSEControl gse)

if (gse.DataSetName != null)
{

if (gse.DataSetName.Trim() != "")

//Creating GSE node

XmlNode xmlNodeGSE = xdoc.CreateNode(XmlNodeType.Element, "GSE",


"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributeldInst = xdoc.CreateAttribute("ldInst");

attributeldInst.Value = gse.CBLDeviceName;

xmlNodeGSE.Attributes.Append(attributeldInst);

XmlAttribute attributecbName = xdoc.CreateAttribute("cbName");

attributecbName.Value = gse.name;

xmlNodeGSE.Attributes.Append(attributecbName);

XmlAttribute attributedesc = xdoc.CreateAttribute("desc");

attributedesc.Value = gse.desc;

xmlNodeGSE.Attributes.Append(attributedesc);

//Creating Address node

XmlNode xmlNodeAddress = xdoc.CreateNode(XmlNodeType.Element, "Address",


"http://www.iec.ch/61850/2003/SCL");

XmlNode xmlNodeP1 = xdoc.CreateNode(XmlNodeType.Element, "P",


"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributetype1 = xdoc.CreateAttribute("type");

attributetype1.Value = "MAC-Address";

xmlNodeP1.Attributes.Append(attributetype1);

xmlNodeP1.InnerText = gse.MACAddress;

XmlNode xmlNodeP2 = xdoc.CreateNode(XmlNodeType.Element, "P",


"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributetype2 = xdoc.CreateAttribute("type");

attributetype2.Value = "APPID";

xmlNodeP2.Attributes.Append(attributetype2);
xmlNodeP2.InnerText = gse.APPIDComm;

XmlNode xmlNodeP3 = xdoc.CreateNode(XmlNodeType.Element, "P",


"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributetype3 = xdoc.CreateAttribute("type");

attributetype3.Value = "VLAN-ID";

xmlNodeP3.Attributes.Append(attributetype3);

xmlNodeP3.InnerText = gse.VLANID;

XmlNode xmlNodeP4 = xdoc.CreateNode(XmlNodeType.Element, "P",


"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributetype4 = xdoc.CreateAttribute("type");

attributetype4.Value = "VLAN-PRIORITY";

xmlNodeP4.Attributes.Append(attributetype4);

xmlNodeP4.InnerText = gse.VLANPRIORITY;

xmlNodeAddress.AppendChild(xmlNodeP1);

xmlNodeAddress.AppendChild(xmlNodeP2);

xmlNodeAddress.AppendChild(xmlNodeP3);

xmlNodeAddress.AppendChild(xmlNodeP4);

//Creating MinTime node

XmlNode xmlNodeMin = xdoc.CreateNode(XmlNodeType.Element, "MinTime",


"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributeunit = xdoc.CreateAttribute("unit");

attributeunit.Value = "s";

xmlNodeMin.Attributes.Append(attributeunit);

XmlAttribute attributemultiplier = xdoc.CreateAttribute("multiplier");

attributemultiplier.Value = "m";

xmlNodeMin.Attributes.Append(attributemultiplier);

xmlNodeMin.InnerText = gse.MinTime.ToString();

//Creating MaxTime node


XmlNode xmlNodeMax = xdoc.CreateNode(XmlNodeType.Element, "MaxTime",
"http://www.iec.ch/61850/2003/SCL");

XmlAttribute attributemaxunit = xdoc.CreateAttribute("unit");

attributemaxunit.Value = "s";

xmlNodeMax.Attributes.Append(attributemaxunit);

XmlAttribute attributemaxmultiplier = xdoc.CreateAttribute("multiplier");

attributemaxmultiplier.Value = "m";

xmlNodeMax.Attributes.Append(attributemaxmultiplier);

xmlNodeMax.InnerText = gse.MaxTime.ToString();

//Adding Address,MinTime,MaxTime nodes to GSE node

xmlNodeGSE.AppendChild(xmlNodeAddress);

xmlNodeGSE.AppendChild(xmlNodeMin);

xmlNodeGSE.AppendChild(xmlNodeMax);

xmlnode.InsertAfter(xmlNodeGSE, xmlnode.LastChild);

}
}

You might also like