private void AddTreeNode(TreeNode parent, AbTagItem[] items, string parentName, bool showDataGrid) { foreach (var item in items) { TreeNode treeNode = new TreeNode(item.Name); treeNode.Name = string.IsNullOrEmpty(parentName) ? item.Name : parentName + "." + item.Name; treeNode.ImageKey = GetIamgeKeyByTag(item); treeNode.SelectedImageKey = GetIamgeKeyByTag(item); treeNode.Tag = item; parent.Nodes.Add(treeNode); if (item.IsStruct) { OperateResult <AbTagItem[]> read = GetStruct(item); if (!read.IsSuccess) { continue; } item.Members = read.Content; if (item.ArrayDimension == 0) { AddTreeNode(treeNode, read.Content, treeNode.Name, false); } else if (item.ArrayDimension == 1) { for (int i = 0; i < item.ArrayLength[0]; i++) { TreeNode treeNodeChild = new TreeNode(item.Name + $"[{i}]"); treeNodeChild.Name = string.IsNullOrEmpty(parentName) ? item.Name + $"[{i}]" : parentName + "." + item.Name + $"[{i}]"; treeNodeChild.ImageKey = GetIamgeKeyByTag(item); treeNodeChild.SelectedImageKey = GetIamgeKeyByTag(item); AbTagItem abTag = new AbTagItem( ); abTag.Name = item.Name + $"[{i}]"; abTag.InstanceID = item.InstanceID; abTag.SymbolType = item.SymbolType; abTag.IsStruct = item.IsStruct; abTag.ArrayDimension = 0; abTag.ArrayLength = item.ArrayLength; abTag.Members = AbTagItem.CloneBy(item.Members); treeNodeChild.Tag = abTag; AddTreeNode(treeNodeChild, read.Content, treeNodeChild.Name, false); treeNode.Nodes.Add(treeNodeChild); } } else { } } } if (showDataGrid) { RenderDataGridView(items); } }
private OperateResult <AbTagItem[]> GetStruct(AbTagItem tagItem) { int typeCode = tagItem.SymbolType & 0x0fff; if (dictStructDefine.ContainsKey(typeCode)) { return(OperateResult.CreateSuccessResult(AbTagItem.CloneBy(dictStructDefine[typeCode]))); } OperateResult <AbTagItem[]> read = allenBradleyNet.StructTagEnumerator(tagItem); if (read.IsSuccess) { dictStructDefine.Add(typeCode, AbTagItem.CloneBy(read.Content)); } return(read); }