示例#1
0
        /// <summary>
        /// Looks for the DIs or checks if it is still available.
        /// </summary>
        /// <param name="foundDIs">list of link DI objects found.
        /// If shorter than the total number of links, then not all were found...
        /// If same size as the total number of links, the last item is the final DI.
        /// </param>
        void Look(out List <IDumpItem> foundDIs)
        {
            IDumpItem parent  = toHu.RootDI;
            int       linkIdx = 0;

            foundDIs = new List <IDumpItem>();
            while (parent != null && linkIdx < diIdent.Names.Count)
            {
                // look up the DI within the parent's child list
                string    linkName = diIdent.Names[linkIdx];
                IDumpItem linkDI   = null;
                foreach (var childDI in parent.Children)
                {
                    if (childDI != null && string.Compare(childDI.Name, linkName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        linkDI = childDI;
                        break;
                    }
                }
                // add the found link to the list, make it the new parent
                if (linkDI != null)
                {
                    foundDIs.Add(linkDI);
                    linkIdx++;
                    parent = linkDI;
                }
                else
                {
                    break;
                }
            }
        }
示例#2
0
        public bool ShowKey       = true;   // just for the root DI; whether to display the "key=" part

        public TreeRenderer(NodeHunter noHu, IDumpItem rootDI)
        {
            this.noHu   = noHu;
            this.bm     = noHu.Node.DataRepo;
            this.rootDI = rootDI;

            // setup the root DI
            var diInfo = new DIInfo(noHu, rootDI);

            diInfo.ShowKey     = ShowKey;
            diInfo.KeyOverride = KeyOverride;
            diInfos[rootDI]    = diInfo;
        }
示例#3
0
        // DumpItem subscriptions

        public void Publish(IDumpItem di)
        {
            DISubsInfo si;

            if (!diSubs.TryGetValue(di, out si))
            {
                si         = new DISubsInfo();
                diSubs[di] = si;

                // let the node know we need this DI to be published
                node.Publish(di);
            }

            si.RefCount++;
        }
示例#4
0
        public static Editor Create(IDumpItem di)
        {
            switch (di.Value.ValType)
            {
            case Variant.EValType.Int:
                return(new IntEditor(di));

            case Variant.EValType.String:
                return(new StringEditor(di));

            case Variant.EValType.Double:
            default:
                return(null);
            }
        }
示例#5
0
        public void Unpublish(IDumpItem di)
        {
            DISubsInfo si;

            if (diSubs.TryGetValue(di, out si))
            {
                si.RefCount--;
                if (si.RefCount <= 0)
                {
                    diSubs.Remove(di);

                    // let the node forget about this DI to be published
                    node.Unpublish(di);
                }
            }
        }
示例#6
0
文件: Node.cs 项目: pjanec/DID
        public void Unpublish(IDumpItem di)
        {
            DISubsInfo si;

            if (diSubs.TryGetValue(di, out si))
            {
                si.RefCount--;
                if (si.RefCount <= 0)
                {
                    //diSubs.Remove(di);
                    si.Expanded = false;
                    di.Expand   = si.Expanded;

                    //// make the server stop publishing this DI
                    //di.Expand = false;
                }
            }
        }
示例#7
0
文件: Node.cs 项目: pjanec/DID
        // DumpItem subscriptions
        // The di.Expand field controls whether thr server publishes the item or not
        // Set it to true only if at least one subscriber is subscribed.

        public void Publish(IDumpItem di)
        {
            DISubsInfo si;

            if (!diSubs.TryGetValue(di, out si))
            {
                si         = new DISubsInfo();
                diSubs[di] = si;


                //// make the server start publishing the DI
                //di.Expand = true;
            }

            si.Expanded = true;
            di.Expand   = si.Expanded;

            si.RefCount++;
        }
示例#8
0
文件: DIFormatter.cs 项目: pjanec/DID
        /// <summary>
        /// Returns the "value" part of the usual "key = value" textual representation of the dump item
        /// </summary>
        public static String ValToStr(IDumpItem di)
        {
            var pr = di.Value;

            switch (di.Type)
            {
            case EDIType.Invalid:
            {
                return($"Invalid");
            }

            case EDIType.Primitive:
            {
                return(PrimitiveToStr(pr));
            }

            case EDIType.Enum:
            {
                return($"Enum {di.TypeName} {pr.IntValue}");
            }

            case EDIType.Struct:
            {
                if (pr.ValType == Variant.EValType.Invalid)
                {
                    return($"Struct {di.TypeName}");
                }
                else                         // structure with a value => probably some artifical folded subtree (not an ordinary data struct header)
                {
                    return(PrimitiveToStr(pr));
                }
            }

            case EDIType.Array:
            {
                return($"Array ({di.ArraySize})");
            }

            default:
                return("<invalid>");
            }
        }
示例#9
0
文件: DIFormatter.cs 项目: pjanec/DID
        public static string str1(IDumpItem di, string keyOverride = null, bool showKey = true)
        {
            var key = "";

            if (!string.IsNullOrEmpty(keyOverride))
            {
                key = keyOverride + " = ";
            }
            else
            if (showKey)
            {
                key = DIFormatter.KeyToStr(di);
            }

            var value = DIFormatter.ValToStr(di);

            var s = $"{key}{value}";

            return(s);
        }
示例#10
0
        /// <summary>
        /// Looks for the topic or checks if it is still available.
        /// </summary>
        bool Look(out ITopic topic, out IDumpItem rootDI)
        {
            // topics having same type name
            var topics = (from t in noHu.Node.Topics where string.Compare(t.TypeName, topicIdent.TypeName, StringComparison.OrdinalIgnoreCase) == 0 select t);

            foreach (var t in topics)
            {
                var rdi = t.RootDI;
                if (rdi != null && string.Compare(rdi.Name, topicIdent.InstName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    topic  = t;
                    rootDI = rdi;
                    return(true);
                }
            }
            // topic or RootDi not found..
            topic  = null;
            rootDI = null;
            return(false);
        }
示例#11
0
文件: DIFormatter.cs 项目: pjanec/DID
        /// <summary>
        /// Returns the "key = " part of the usual "key = value" textual representation of the dump item
        /// </summary>
        /// <param name="includeSeparator">include '=' or space after the key </param>
        public static String KeyToStr(IDumpItem di, bool includeSeparator = true)
        {
            string s = "";

            if (di.ArrayIndex >= 0)
            {
                s += $"[{di.ArrayIndex}]";
                if (includeSeparator)
                {
                    s += " ";
                }
            }

            if (!String.IsNullOrEmpty(di.Name))
            {
                s += di.Name;
                if (includeSeparator)
                {
                    s += " = ";
                }
            }

            return(s);
        }
示例#12
0
        public void Tick()
        {
            ITopic    topic;
            IDumpItem rootDI;

            if (RootDI == null)              // try to look up the topic & its root item
            {
                if (Look(out topic, out rootDI))
                {
                    noHu.Publish(rootDI);
                    Topic  = topic;
                    RootDI = rootDI;
                }
            }
            else             // just checking if topic still exists
            {
                if (!Look(out topic, out rootDI))
                {
                    noHu.Unpublish(RootDI);
                    RootDI = null;
                    Topic  = null;
                }
            }
        }
示例#13
0
        protected void DrawDI(IDumpItem di)
        {
            if (di == null)
            {
                ImGui.Text("---");
                return;
            }

            DIInfo diInfo = null;

            if (!diInfos.TryGetValue(di, out diInfo))
            {
                diInfo      = new DIInfo(noHu, di);
                diInfos[di] = diInfo;
            }

            var  t      = di.Type;
            bool isTree = (di.Children.Count > 0) || (t != EDIType.Primitive);

            if (!AllowTree)
            {
                isTree = false;
            }

            // red color if dirty
            bool popColor = false;
            //if ( di.IsDirty )
            //{
            //	ImGui.PushStyleColor( ImGuiCol.Text,  new System.Numerics.Vector4( 1.0f, 0.4f, 0.4f, 1.0f ) );
            //	popColor = true;
            //}

            Action finalizeLine = () =>
            {
                if (popColor)
                {
                    ImGui.PopStyleColor();
                }
            };

            String s = DIFormatter.str1(di, diInfo.KeyOverride, diInfo.ShowKey);

            if (isTree)
            {
                bool nodeOpened = ImGui.TreeNodeEx(s, diInfo.Expanded ? ImGuiTreeNodeFlags.DefaultOpen : 0);
                diInfo.Expanded = nodeOpened;
                finalizeLine();

                if (di.Type == EDIType.Array)
                {
                    DrawArrayControls(diInfo);
                }

                if (AllowEdit)
                {
                    DrawEditControls(diInfo);
                }


                if (nodeOpened)
                {
                    // render subitems
                    for (int i = 0; i < di.Children.Count; i++)
                    {
                        IDumpItem subi = di.Children[i];
                        DrawDI(subi);
                    }

                    //// draw referenced dump items
                    //if( t == EDIType.DumpItem )
                    //{
                    //	var refDI = di.DumpItemVal;
                    //	if( refDI != null )
                    //	{
                    //		DITreeRenderer.DrawDI( refDI );
                    //	}
                    //}

                    ImGui.TreePop();
                }
            }
            else
            {
                string indent = "   ";

                ImGui.TextWrapped(indent + s);

                finalizeLine();

                if (AllowEdit)
                {
                    DrawEditControls(diInfo);
                }
            }
        }
示例#14
0
 public IntEditor(IDumpItem di)
     : base(di)
 {
     input = di.Value.IntValue.ToString();
 }
示例#15
0
 public Editor(IDumpItem di)
 {
     this.di = di;
 }
示例#16
0
 public DIInfo(NodeHunter noHu, IDumpItem di)
 {
     this.noHu = noHu;
     this.di   = di;
 }
示例#17
0
 public StringEditor(IDumpItem di)
     : base(di)
 {
     input = di.Value.StringValue;
 }