void recursiveAddLine(NodeBase n, TreeNode tn) { if ((n.GetChildNodes().Length > 0)) { if (n is NodeVL) { foreach (NodeBase nb in n.GetChildNodes()) { ListViewItem li = this.listView_Goose.Items.Add(makeRow(nb)); li.Tag = nb.Tag; } } else { foreach (NodeBase nb in n.GetChildNodes()) { recursiveAddLine(nb, tn); } } } else { ListViewItem li = this.listView_Goose.Items.Add(makeRow(n)); li.Tag = n; if (n.Tag is Data) { addCustomCell(n.Tag as Data); } } }
void makeTree_dataNode(NodeBase nb, TreeNode tn) { foreach (NodeBase b in nb.GetChildNodes()) { TreeNode tn2 = tn.Nodes.Add(b.Name); tn2.Tag = b; b.Tag = tn2; Node_StateChanged(b, new EventArgs()); b.StateChanged += new EventHandler(Node_StateChanged); if (b.FC.Count > 0) { tn2.ToolTipText = "FC="; for (int i = 0; i < b.FC.Count; i++) { tn2.ToolTipText += b.FC[i]; if (i != b.FC.Count - 1) { tn2.ToolTipText += ","; } } } makeTree_dataNode(b, tn2); } }
private void myTreeView_Goose_AfterSelect(object sender, TreeViewEventArgs e) { ListViewItem li; listViewGoose_Clear(); NodeBase n = (NodeBase)e.Node.Tag; if (n != null) { li = this.listView_Goose.Items.Add(makeRow(n)); li.Tag = n; if (n.Tag is Data) { addCustomCell(n.Tag as Data); } if (n.GetChildNodes().Length > 0) { this.listView_Goose.Items.Add(new ListViewItem(new string[] { "------------- CHILD NODES -------------", "-------------", "-------------", "-------------" })); recursiveAddLine(n, e.Node); } } }
void recursiveLinkDA(NodeBase source, NodeBase target, NodeFC fc) { NodeBase linkedDa = target.LinkChildNodeByName(source); // Set FC if (linkedDa is NodeData && !(linkedDa is NodeDO)) { (linkedDa as NodeData).SCL_FCDesc = fc.Name; } // Check DO / DA types if (linkedDa != source) { // We are in a DA once again // That means this is a DO and not a DA // We have to create DO and add it to the iec model (target) // and replace linkedDa with this object NodeDO ido = new NodeDO(source.Name); ido.IsIecModel = true; target.RemoveChildNode(source); linkedDa = target.AddChildNode(ido); } foreach (NodeBase newSource in source.GetChildNodes()) { recursiveLinkDA(newSource, linkedDa, fc); } }
void recursiveAddLine(NodeBase n, TreeNode tn) { if ((n.GetChildNodes().Length > 0)) { if (n is NodeVL) { foreach (NodeBase nb in n.GetChildNodes()) { ListViewItem li = this.listView_data.Items.Add(makeRow(nb)); li.Tag = nb.Tag; } } else { if (tn.Text == "lists") { foreach (NodeBase nb in n.GetChildNodes()) { ListViewItem li = this.listView_data.Items.Add(makeRow(nb)); li.Tag = nb.Tag; } } if (n is NodeFile || tn.Text == "files") { foreach (NodeBase nb in n.GetChildNodes()) { ListViewItem li = this.listView_data.Items.Add(makeRow(nb)); li.Tag = nb.Tag; } } else { foreach (NodeBase nb in n.GetChildNodes()) { recursiveAddLine(nb, tn); } } } } else { ListViewItem li = this.listView_data.Items.Add(makeRow(n)); li.Tag = n.Tag; } }
void resetModelObjects(NodeBase nb) { nb.SCLServerModelObject = null; foreach (NodeBase n in nb.GetChildNodes()) { // Recursion resetModelObjects(n); } }
public override void SaveModel(List <String> lines, bool fromSCL) { // DA(<data attribute name> <nb of array elements> <type> <FC> <trigger options> <sAddr>)[=value]; // Constructed> // DA(<data attribute name> <nb of array elements> 27 <FC> <trigger options> <sAddr>){…} if (isLeaf() || (isArray() && _childNodes[0].isLeaf())) { string line = "DA(" + Name; int nrElem = getArraySize(); line += " " + nrElem + " " + MapLibiecType(DataType) + " " + MapLibiecFC(SCL_FCDesc) + " " + MapTrgOps() + " " + sAddr + ")"; bool writeVal = false; // Some conditions for writing the value if (Name == "ctlModel") { writeVal = true; } // Finish the line if (writeVal) { line += " value=" + StringValue; } lines.Add(line); } else { // Constructed int nrElem = 0; NodeBase nextnb = this; if (isArray()) { nrElem = getArraySize(); // Array has got an artificial level with array members, this is not part of model definition if (_childNodes.Count > 0) { nextnb = _childNodes[0]; } } lines.Add("DA(" + Name + " " + nrElem + " 27 " + MapLibiecFC(SCL_FCDesc) + " " + MapTrgOps() + " " + sAddr + "){"); foreach (NodeBase b in nextnb.GetChildNodes()) { b.SaveModel(lines, fromSCL); } lines.Add("}"); } }
void InitializeValues(NodeBase nb) { if (nb.isLeaf() && (nb is NodeData && !(nb is NodeDO))) { NodeData nd = nb as NodeData; if (nd.SCLServerModelObject != null) { // Initial value exist (from SCL file) DataAttribute da = (DataAttribute)nd.SCLServerModelObject; if (nd.DataValue != null) { da.UpdateValue(server, nd.DataValue); } nd.DataType = (scsm_MMS_TypeEnum)da.GetMmsValueType(); logger.LogDebug("InitializeValues: " + nd.IecAddress + ", Type: " + nd.DataType.ToString()); } /*else * { * NodeBase arr = nd.findArray(); * if (arr != null) * { * if (arr is NodeData) * { * // Array in Attribute * DataAttribute da = (DataAttribute)arr.SCLServerModelObject; * } * else * { * // Array in DataObject * } * } * }*/ } else { foreach (NodeBase child in nb.GetChildNodes()) { // Recursion InitializeValues(child); } } }
internal ControllableSignalsDialog(NodeBase data /*, EventHandler onNVListChanged)*/) { InitializeComponent(); this.data = data; this.TopMost = true; button2.Enabled = false; button3.Enabled = false; Iec61850State iecs = data.GetIecs(); NodeBase[] datacns = data.GetChildNodes(); foreach (NodeLN datacn in datacns) { NodeBase[] nfccns = datacn.GetChildNodes(); foreach (NodeFC nfccn in nfccns) { if (nfccn.Name == "CO") { NodeBase[] ndatacns = nfccn.GetChildNodes(); foreach (NodeDO ndatacn in ndatacns) { if (ndatacn.Name.Contains("SPCSO") || ndatacn.Name.Contains("RcdTrg") || ndatacn.Name.Contains("Pos")) { NodeBase ctlval = iecs.DataModel.ied.FindNodeByAddress(ndatacn.CommAddress.Domain + "/" + ndatacn.CommAddress.Variable + "$Oper$ctlVal"); NodeBase desc = iecs.DataModel.ied.FindNodeByAddress(ndatacn.CommAddress.Domain + "/" + ndatacn.CommAddress.Variable.Replace("$CO$", "$DC$") + "$d"); if (ctlval != null) { ListViewItem item = new ListViewItem(new[] { ctlval.IecAddress, ((desc != null) ? (desc as NodeData).StringValue : ""), }); item.Tag = ctlval; listView1.Items.Add(item); } } } } } } }
void Node_StateChanged(object sender, EventArgs e) { if (treeView1.InvokeRequired) { OnValueCallback d = new OnValueCallback(Node_StateChanged); if (!this.Disposing) { this.Invoke(d, new object[] { sender, e }); } } else { NodeBase b = (sender as NodeBase); if (b.Tag is TreeNode) { TreeNode tn = (b.Tag as TreeNode); int firsticon = 0; if (b.GetType() == typeof(NodeLN)) { firsticon = 5; } else if (b.GetType() == typeof(NodeFC)) { firsticon = 6; } else if (b.GetType() == typeof(NodeData)) { if (b.GetChildNodes().Length == 0) { // Leaf firsticon = 8; } else { firsticon = 7; } } tn.ImageIndex = firsticon + ((int)b.NodeState) * 4; tn.SelectedImageIndex = firsticon + ((int)b.NodeState) * 4; treeView1.Invalidate(tn.Bounds); } } }
void makeTree_listNode(NodeBase nb, TreeNode tn, MyTreeView tv) { foreach (NodeBase b in nb.GetChildNodes()) { TreeNode tn2 = (tn != null) ? tn.Nodes.Add(b.Name) : tv.Nodes.Add(b.Name); tn2.Tag = b; //tn2.Tag = b.Tag; // b.Tag = tn2; tn2.ImageIndex = 1; tn2.SelectedImageIndex = 1; NodeBase[] bcn = b.GetChildNodes(); if (bcn.Length == 0) { tn2.ImageIndex = 2; tn2.SelectedImageIndex = 2; } foreach (NodeBase b2 in bcn) { TreeNode tn3 = tn2.Nodes.Add(b2.CommAddress.Variable); tn3.Tag = b2; //tn3.Tag = b2.Tag; tn3.ImageIndex = 1; tn3.SelectedImageIndex = 1; NodeBase[] b2cn = b2.GetChildNodes(); if (b2cn.Length > 0) { makeTree_listNode(b2, tn3, null); } else { tn3.ImageIndex = 2; tn3.SelectedImageIndex = 2; } } } }
void makeTree_fileNode(NodeBase nb, TreeNode tn) { foreach (NodeBase b in nb.GetChildNodes()) { TreeNode tn2 = tn.Nodes.Add(b.Name); tn2.Tag = b; b.Tag = tn2; if (b is NodeFile && (b as NodeFile).isDir) { tn2.ImageIndex = 29; tn2.SelectedImageIndex = 29; } else { tn2.ImageIndex = 4; tn2.SelectedImageIndex = 4; } (b as NodeFile).DirectoryUpdated += Node_DirectoryUpdated; makeTree_fileNode(b, tn2); } }
void makeTree_reportNode(NodeBase nb, TreeNode tn) { foreach (NodeBase b in nb.GetChildNodes()) { TreeNode tn2 = tn.Nodes.Add(b.Name); tn2.Tag = b; b.Tag = tn2; tn2.ImageIndex = 4; tn2.SelectedImageIndex = 4; foreach (NodeBase b2 in b.GetChildNodes()) { TreeNode tn3 = tn2.Nodes.Add(b2.CommAddress.Variable); tn3.Tag = b2; tn3.ImageIndex = 7; tn3.SelectedImageIndex = 7; /*Node_StateChanged(b2, new EventArgs()); * b2.StateChanged += new EventHandler(Node_StateChanged);*/ } } }
public override void SaveModel(List <String> lines, bool fromSCL) { // Syntax: DO(<data object name> <nb of array elements>){…} int nrElem = 0; NodeBase nextnb = this; if (isArray()) { nrElem = getArraySize(); // Array has got an artificial level with array members, this is not part of model definition if (_childNodes.Count > 0) { nextnb = _childNodes[0]; } } lines.Add("DO(" + Name + " " + nrElem.ToString() + "){"); foreach (NodeBase b in nextnb.GetChildNodes()) { b.SaveModel(lines, fromSCL); } lines.Add("}"); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { foreach (ListViewItem l in this.listView_data.Items) { if (l.Tag is TreeNode) { if ((l.Tag as TreeNode).Tag is NodeData) { ((l.Tag as TreeNode).Tag as NodeData).ValueChanged -= new EventHandler(Node_ValueChanged); } } } this.listView_data.Items.Clear(); ListViewItem li; NodeBase n = (NodeBase)e.Node.Tag; li = this.listView_data.Items.Add(makeRow(n)); li.Tag = e.Node; if (n.GetChildNodes().Length > 0) { this.listView_data.Items.Add(new ListViewItem(new string[] { "------------- CHILD NODES -------------", "-------------", "-------------", "-------------" })); recursiveAddLine(n, e.Node); } }
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button == MouseButtons.Right && e.Node != null) { NodeBase n = (NodeBase)e.Node.Tag; ContextMenuStrip menu = new ContextMenuStrip(); ToolStripItem item; if (n != null) { if (n is NodeVL) { if ((n as NodeVL).Defined) { if ((n as NodeVL).Activated) { item = menu.Items.Add("Deactivate Reports"); item.Tag = n; item.Click += new EventHandler(OnDeactivateNVLClick); } else { item = menu.Items.Add("Activate Reports"); item.Tag = n; item.Click += new EventHandler(OnActivateNVLClick); } } else { item = menu.Items.Add("Send Define Report Request"); item.Tag = n; item.Click += new EventHandler(OnDefineNVLClick); } if ((n as NodeVL).Deletable) { item = menu.Items.Add("Delete Report"); item.Tag = n; item.Click += new EventHandler(OnDeleteNVLClick); } } else if (e.Node.Text == "lists" && n.GetIecs().ied.DefineNVL) { item = menu.Items.Add("Add New Name List"); item.Tag = n; listsNode = e.Node; item.Click += new EventHandler(OnAddNVLClick); } else if (e.Node.Text == "files") { item = menu.Items.Add("Read File List"); item.Tag = n; listsNode = e.Node; item.Click += new EventHandler(OnFileListClick); } if (n is NodeFile && (n as NodeFile).isDir) { item = menu.Items.Add("Read File List"); item.Tag = n; listsNode = e.Node; item.Click += new EventHandler(OnFileListClick); } if (n is NodeFile && !(n as NodeFile).isDir && !(n as NodeFile).FileReady) { item = menu.Items.Add("Get File"); item.Tag = n; listsNode = e.Node; item.Click += new EventHandler(OnFileGetClick); } if (n is NodeFile && !(n as NodeFile).isDir && (n as NodeFile).FileReady) { item = menu.Items.Add("Save File"); item.Tag = n; listsNode = e.Node; item.Click += new EventHandler(OnFileSaveClick); } if (n is NodeData && n.Name == "ctlVal") { item = menu.Items.Add("Send Command (Writes)"); item.Tag = n; item.Click += new EventHandler(OnSendCommandClick); item = menu.Items.Add("Send Command (Structure)"); item.Tag = n; item.Click += new EventHandler(OnSendCommandAsStructureClick); } if (n is NodeData || n is NodeFC) { item = menu.Items.Add("Read Data"); item.Tag = n; item.Click += new EventHandler(OnReadDataClick); } if (n is NodeData && n.GetChildNodes().Length == 0) { item = menu.Items.Add("Write Data"); item.Tag = n; item.Click += new EventHandler(OnWriteDataClick); } } if (menu.Items.Count > 0) { menu.Show((Control)sender, e.Location); } } }
int recursiveReadData(NodeBase nd, GOOSE_ASN1_Model.Data t, NodeBase ndcn, int id, DateTime captureTime) { int _id = id; if (t == null) { return(-1); } if (t.Array != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.array; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Array_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.array; (nb as NodeGData).DataValue = t.Array; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Binarytime != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.array; (nd as NodeGData).DataValue = t.Binarytime; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Binarytime_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.binary_time; (nb as NodeGData).DataValue = t.Binarytime; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Bitstring != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.bit_string; (nd as NodeGData).DataValue = t.Bitstring.Value; (nd as NodeGData).DataParam = t.Bitstring.TrailBitsCnt; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Bitstring_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.bit_string; (nb as NodeGData).DataValue = t.Bitstring.Value; (nb as NodeGData).DataParam = t.Bitstring.TrailBitsCnt; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.isBooleanSelected()) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.boolean; (nd as NodeGData).DataValue = t.Boolean; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Boolean_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.boolean; (nb as NodeGData).DataValue = t.Boolean; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.BooleanArray != null) { return(0); } else if (t.Floatingpoint != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.floating_point; (nd as NodeGData).DataValue = t.Floatingpoint; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Floatingpoint_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.floating_point; (nb as NodeGData).DataValue = t.Floatingpoint; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Generalizedtime != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.generalized_time; (nd as NodeGData).DataValue = t.Generalizedtime; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Generalizedtime_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.generalized_time; (nb as NodeGData).DataValue = t.Generalizedtime; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.isIntegerSelected()) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.integer; (nd as NodeGData).DataValue = t.Integer; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Integer_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.integer; (nb as NodeGData).DataValue = t.Integer; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.MMSString != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.mMSString; (nd as NodeGData).DataValue = t.MMSString; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("MMSString_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.mMSString; (nb as NodeGData).DataValue = t.MMSString; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Octetstring != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.octet_string; (nd as NodeGData).DataValue = t.Octetstring; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Octetstring_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.octet_string; (nb as NodeGData).DataValue = t.Octetstring; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Structure != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.structure; NodeBase[] nd1 = nd.GetChildNodes(); int i = 0; int j = 0; foreach (GOOSE_ASN1_Model.Data data in t.Structure.Value) { j = recursiveReadData(nd1[i++], data, null, j, captureTime); } return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Structure_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.structure; NodeBase nb1 = ndcn.AddChildNode(nb); int i = 0; foreach (GOOSE_ASN1_Model.Data data in t.Structure.Value) { i = recursiveReadData(null, data, nb1, i, captureTime); } return(++_id); } else { return(-1); } } else if (t.isUnsignedSelected()) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.unsigned; (nd as NodeGData).DataValue = t.Unsigned; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Unsigned_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.unsigned; (nb as NodeGData).DataValue = t.Unsigned; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Utctime != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.utc_time; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Utctime_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.utc_time; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Visiblestring != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.visible_string; (nd as NodeGData).DataValue = t.Visiblestring; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Utctime_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.visible_string; (nb as NodeGData).DataValue = t.Visiblestring; return(++_id); } else { return(-1); } } else { return(-1); } }
void makeIedModelFromIecModel(Iec61850Model model, NodeBase iec) { foreach (NodeBase child in iec.GetChildNodes()) { if ((child is NodeData && !(child is NodeDO)) || child is NodeVLM) { // First DataAttribute child // Create the whole path down to Ied List <NodeBase> path = new List <NodeBase>(); NodeBase nb = child.Parent; while (nb != null && !(nb is NodeIed)) { path.Add(nb); nb = nb.Parent; } NodeBase subtree = model.ied; string fc = ""; if (child is NodeData && !(child is NodeDO)) { fc = (child as NodeData).SCL_FCDesc; if (String.IsNullOrEmpty(fc)) { logger.LogError("FC is empty for DataAttribute: " + child.IecAddress); continue; } } path.Reverse(); foreach (NodeBase pnb in path) { if (pnb is NodeLD) { subtree = subtree.AddChildNode(new NodeLD(pnb.Name)); } else if (pnb is NodeLN) { subtree = subtree.AddChildNode(new NodeLN(pnb.Name)); // Inserting the FC level if (!String.IsNullOrEmpty(fc)) // due to VLM { subtree = subtree.AddChildNode(new NodeFC(fc)); } } else if (pnb is NodeDO) { subtree = subtree.AddChildNode(new NodeDO(pnb.Name)); } else if (pnb is NodeRCB) { subtree = subtree.AddChildNode(new NodeRCB(pnb.Name)); (subtree as NodeRCB).isBuffered = (pnb as NodeRCB).isBuffered; if ((pnb as NodeRCB).isBuffered) { model.brcbs.AddChildNode(new NodeLD(path[0].Name)).LinkChildNodeByName(subtree); } else { model.urcbs.AddChildNode(new NodeLD(path[0].Name)).LinkChildNodeByName(subtree); } } else if (pnb is NodeVL) { //subtree = subtree.AddChildNode(new NodeVL(pnb.Name)); model.lists.AddChildNode(new NodeLD(path[0].Name)).LinkChildNodeByName(pnb); } } if (!(child is NodeVLM)) { subtree.LinkChildNodeByName(child); } else { // Fill the gap -> find the link for VLM nodes (child as NodeVLM).LinkedNode = model.iec.FindSubNode(child.Name); if ((child as NodeVLM).LinkedNode == null) { logger.LogWarning("DataSet " + child.Parent.IecAddress + ": node " + child.Name + " not found in the model!"); } } } else { // Recursive call makeIedModelFromIecModel(model, child); } } }
private void CreateSDO_DA(NodeBase dataObject, NodeBase doType) { // for each DA in the DOType foreach (var dataAttribute in doType.GetChildNodes()) { if (dataAttribute is NodeDO) { // SDO (sub Data Object) NodeBase subDoType = null; try { subDoType = _dataObjectTypes.Single(dot => dot.Name.Equals((dataAttribute as NodeDO).SCL_Type)); } catch (Exception e) { logger.LogError("SCL Parser: SDO type template not found: " + (dataAttribute as NodeDO).SCL_Type + ", for DO type: " + doType.Name + ", for LN type: " + doType.Parent.Name + ", in node: " + dataObject.Parent.Name + ", Exception: " + e.Message); continue; } NodeDO subDataObject = new NodeDO(dataAttribute.Name); subDataObject.SCL_ArraySize = (dataAttribute as NodeDO).SCL_ArraySize; dataObject.AddChildNode(subDataObject); if (subDataObject.SCL_ArraySize > 0) { for (int i = 0; i < subDataObject.SCL_ArraySize; i++) { NodeDO arrDataObject = new NodeDO("[" + i.ToString() + "]"); subDataObject.AddChildNode(arrDataObject); arrDataObject.SCL_UpperDOName = dataObject.Name; foreach (var dataAttribute2 in subDoType.GetChildNodes()) { if (dataAttribute2 is NodeDO) { CreateSDO_DA(arrDataObject, subDoType); } else { CreateDataAttributesIEC(arrDataObject, dataAttribute2); } } } } else { foreach (var dataAttribute2 in subDoType.GetChildNodes()) { if (dataAttribute2 is NodeDO) { CreateSDO_DA(subDataObject, subDoType); } else { CreateDataAttributesIEC(subDataObject, dataAttribute2); } } } } if (dataAttribute is NodeData && !(dataAttribute is NodeDO)) { CreateDataAttributesIEC(dataObject, dataAttribute); } } }
/// <summary> /// Creates a logical node (LN) and all of its children, including /// FCs, DO's, and DA's /// </summary> /// <param name="reader"></param> /// <returns> a LN node </returns> private NodeLN CreateLogicalNode2(XmlReader reader) { reader.Read(); var prefix = reader.GetAttribute("prefix"); var lnClass = reader.GetAttribute("lnClass"); var inst = reader.GetAttribute("inst"); var type = reader.GetAttribute("lnType"); // LN name is a combination of prefix, lnCLass, and inst var name = !String.IsNullOrWhiteSpace(prefix) ? String.Concat(prefix, lnClass, inst) : String.Concat(lnClass, inst); NodeLN logicalNode = new NodeLN(name); logicalNode.TypeId = type; Hashtable functionalConstraints = new Hashtable(); NodeBase nodeType; try { nodeType = _nodeTypes.Single(nt => nt.Name.Equals(type)); } catch (Exception e) { logger.LogError("SCL Parser: LN type template not found: " + type.ToString() + ", for Node: " + name.ToString() + ", Exception: " + e.Message); return(null); } // for each DO in the LNodeType foreach (var dataObject in nodeType.GetChildNodes()) { NodeBase doType = null; try { doType = _dataObjectTypes.Single(dot => dot.Name.Equals((dataObject as NodeDO).SCL_Type)); } catch (Exception e) { logger.LogError("SCL Parser: DO type template not found: " + (dataObject as NodeDO).SCL_Type + ", for LN type: " + nodeType.Name + ", in node: " + name.ToString() + ", Exception: " + e.Message); continue; } // for each DA in the DOType foreach (var dataAttribute in doType.GetChildNodes()) { var fc = (dataAttribute as NodeData).SCL_FCDesc; (dataAttribute as NodeData).SCL_DOName = dataObject.Name; NodeData newNode = new NodeData(dataAttribute.Name); newNode.SCL_Type = (dataAttribute as NodeData).SCL_Type; newNode.SCL_BType = (dataAttribute as NodeData).SCL_BType; newNode.SCL_DOName = (dataAttribute as NodeData).SCL_DOName; newNode.SCL_FCDesc = (dataAttribute as NodeData).SCL_FCDesc; // when the type is specified (ie. when it's a struct), get the struct child nodes if (!String.IsNullOrWhiteSpace(newNode.SCL_Type)) { var dataType = _dataAttributeTypes.Single(dat => dat.Name.Equals((newNode.SCL_Type))); foreach (NodeBase child in dataType.GetChildNodes()) { var tempChild = new NodeData(child.Name); tempChild.SCL_BType = (child as NodeData).SCL_BType; if (!String.IsNullOrWhiteSpace((child as NodeData).SCL_Type)) { var subDataType = _dataAttributeTypes.Single(dat => dat.Name.Equals((child as NodeData).SCL_Type)); foreach (NodeBase subChild in subDataType.GetChildNodes()) { var tempSubChild = new NodeData(subChild.Name); tempSubChild.SCL_BType = (subChild as NodeData).SCL_BType; tempChild.AddChildNode(subChild); } } newNode.AddChildNode(tempChild); } } if (!functionalConstraints.ContainsKey(fc)) { NodeFC nodeFC = new NodeFC(fc); nodeFC.ForceAddChildNode(newNode); functionalConstraints.Add(fc, nodeFC); } else { (functionalConstraints[fc] as NodeBase).ForceAddChildNode(newNode); } } } // for each hashtable element foreach (var key in functionalConstraints.Keys) { var doList = new List <NodeDO>(); // for each data attribute of the functional constraint foreach (var da in (functionalConstraints[key] as NodeBase).GetChildNodes()) { var doName = (da as NodeData).SCL_DOName; if (doList.Exists(x => x.Name.Equals(doName))) { doList.Single(x => x.Name.Equals(doName)).AddChildNode(da); } else { var temp = new NodeDO(doName); temp.AddChildNode(da); doList.Add(temp); } } var nodeFC = new NodeFC(key as string); foreach (NodeDO x in doList) { nodeFC.AddChildNode(x); } nodeFC.SortImmediateChildren(); // alphabetical logicalNode.AddChildNode(nodeFC); } logicalNode.SortImmediateChildren(); // alphabetical return(logicalNode); }
internal void makeTree(Iec61850State iecs) { if (treeView1.InvokeRequired) { OnNodeCallback d = new OnNodeCallback(makeTree); this.Invoke(d, new object[] { iecs }); } else { treeView1.ImageList = new ImageList(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Resource1)); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("computer")))); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("calculator")))); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("database")))); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("page_white_text")))); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("page_white_text_width")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN1")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC1")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO1")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA1")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN2")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC2")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO2")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA2")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN3")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC3")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO3")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA3")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN4")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC4")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO4")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA4")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN5")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC5")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO5")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA5")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN6")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC6")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO6")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA6")))); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("folder")))); treeView1.Nodes.Clear(); TreeNode n = treeView1.Nodes.Add(iecs.ied.Name + " = " + toolStripComboBox_Hostname.Text + ", Vendor = " + (iecs.ied as NodeIed).VendorName + ", Model = " + (iecs.ied as NodeIed).ModelName + ", Revision = " + (iecs.ied as NodeIed).Revision + ", DefineNVL = " + (iecs.ied as NodeIed).DefineNVL ); NodeBase nb = iecs.ied; n.Tag = nb; n.ImageIndex = 0; foreach (NodeBase b in nb.GetChildNodes()) { TreeNode tn2 = n.Nodes.Add(b.Name); tn2.Tag = b; tn2.ImageIndex = 1; tn2.SelectedImageIndex = 1; TreeNode tn3 = tn2.Nodes.Add("Data"); tn3.Tag = b; tn3.ImageIndex = 2; tn3.SelectedImageIndex = 2; makeTree_dataNode(b, tn3); NodeBase lb = iecs.lists.FindChildNode(b.Name); if (lb != null) { tn3 = tn2.Nodes.Add("DataSets"); tn3.Tag = lb; tn3.ImageIndex = 3; tn3.SelectedImageIndex = 3; makeTree_listNode(lb, tn3); } NodeBase rb = iecs.reports.FindChildNode(b.Name); if (rb != null) { tn3 = tn2.Nodes.Add("Reports"); tn3.Tag = rb; tn3.ImageIndex = 3; tn3.SelectedImageIndex = 3; makeTree_reportNode(rb, tn3); } } nb = iecs.files; TreeNode tn4 = n.Nodes.Add("Files"); tn4.Tag = iecs.files; tn4.ImageIndex = 3; tn4.SelectedImageIndex = 3; makeTree_fileNode(nb, tn4); } }
private void processDOI(string LNNodeLnType, string LNNodeCnName, XmlNode LNNodeCn, NodeBase LNNb, XmlNodeList LNodeTypeNodes, XmlNodeList DOTypeNodes, XmlNodeList DATypeNodes) { // Process Instantiated Data Object foreach (XmlNode LNNodeTypeNodesNd in LNodeTypeNodes) { foreach (XmlNode LNNodeTypeNodesNdCn in LNNodeTypeNodesNd.ChildNodes) { if (LNNodeCnName == getStringAttribute(LNNodeTypeNodesNdCn, "name") && LNNodeLnType == getStringAttribute(LNNodeTypeNodesNd, "id")) { foreach (XmlNode DOTypeNodesNd in DOTypeNodes) { if (getStringAttribute(LNNodeTypeNodesNdCn, "type") == getStringAttribute(DOTypeNodesNd, "id")) { foreach (XmlNode DOTypeNodesNdCn in DOTypeNodesNd.ChildNodes) { if (DOTypeNodesNdCn.Name == "DA") { NodeBase LNFC = LNNb.AddChildNode(new NodeFC(getStringAttribute(DOTypeNodesNdCn, "fc"))); NodeBase LNFCCn = LNFC.AddChildNode(new NodeData(getStringAttribute(LNNodeTypeNodesNdCn, "name"))); NodeData Nd = new NodeData(getStringAttribute(DOTypeNodesNdCn, "name")); Nd.DataType = getVarDataType(getStringAttribute(DOTypeNodesNdCn, "bType")); NodeBase DOCn = LNFCCn.AddChildNode(Nd); if (Nd.DataType == scsm_MMS_TypeEnum.structure) { processStructDAType(DOCn, getStringAttribute(DOTypeNodesNdCn, "type"), DATypeNodes); } } } } } } } } foreach (XmlNode LNNodeCnNd in LNNodeCn.ChildNodes) { if (LNNodeCnNd.Name == "DAI") { if (getStringAttribute(LNNodeCnNd, "name") == "d") { foreach (XmlNode LNNodeCnNdCn in LNNodeCnNd) { if (LNNodeCnNdCn.Name == "Val") { NodeBase FCNb = LNNb.FindChildNode("DC"); if (FCNb != null) { NodeBase[] FCNbCn = FCNb.GetChildNodes(); if (FCNbCn.Length > 0) { foreach (NodeBase DO in FCNbCn) { if (DO.Name == LNNodeCnName) { NodeBase[] DOCn = DO.GetChildNodes(); if (DOCn.Length > 0) { foreach (NodeBase DA in DOCn) { if (DA.Name == "d") { (DA as NodeData).DataValue = LNNodeCnNdCn.InnerText; } } } } } } } int i = 0; } } } } } }