Esempio n. 1
0
        public void Set(Graph g, Dictionary <string, GraphParameterValue> values, bool showLabel = true, bool inlinePropertyLabels = false)
        {
            Clear();
            Dictionary <string, List <Tuple <PropertyLabel, UIElement> > > sorter = new Dictionary <string, List <Tuple <PropertyLabel, UIElement> > >();

            foreach (var k in values.Keys)
            {
                var v = values[k];

                if (v.IsFunction())
                {
                    continue;
                }

                string[] split = k.Split('.');

                var n = g.FindSubNodeById(split[0]);

                PropertyInfo nodeInfo = null;

                string customHeader = "";

                if (n != null)
                {
                    nodeInfo = n.GetType().GetProperty(split[1]);

                    if (nodeInfo == null && n is GraphInstanceNode)
                    {
                        //then it might be an underling custom parameter on the node
                        GraphInstanceNode inst = n as GraphInstanceNode;

                        var realParam = inst.GetCustomParameter(split[1]);

                        if (realParam != null)
                        {
                            //initiate custom header
                            //for proper underlying processing
                            //on the label
                            customHeader = "$Custom.";
                            //just set the parameter inputtype the same
                            //also ensure min and max are the same
                            v.InputType = realParam.InputType;
                            v.Max       = realParam.Max;
                            v.Min       = realParam.Min;
                            v.Section   = realParam.Section;
                        }
                    }
                }

                PropertyLabel     lbl = new PropertyLabel(v.Name, n, customHeader + split[1]);
                EditableAttribute ed  = null;
                if (nodeInfo != null)
                {
                    ed = nodeInfo.GetCustomAttribute <EditableAttribute>();
                }
                if (ed == null)
                {
                    ed = new EditableAttribute(GetParamInputType(v), v.Name, v.Section, v.Min, v.Max);
                }

                UIElement ele = BuildParamater(v, ed, v.GetType().GetProperty("Value"), nodeInfo);

                if (ele != null)
                {
                    string inherit = "";
                    if (g != null && g.ParentNode is GraphInstanceNode)
                    {
                        inherit = "Inherited ";
                    }

                    string sect = inherit + v.Section;
                    if (string.IsNullOrEmpty(v.Section))
                    {
                        sect = inherit + "Default";
                    }

                    List <Tuple <PropertyLabel, UIElement> > items = null;
                    if (sorter.TryGetValue(sect, out items))
                    {
                        items.Add(new Tuple <PropertyLabel, UIElement>(lbl, ele));
                    }
                    else
                    {
                        items = new List <Tuple <PropertyLabel, UIElement> >();
                        items.Add(new Tuple <PropertyLabel, UIElement>(lbl, ele));
                        sorter[sect] = items;
                    }
                }
            }

            List <string> keys = sorter.Keys.ToList();

            keys.Sort();

            foreach (string k in keys)
            {
                List <Tuple <PropertyLabel, UIElement> > items = sorter[k];

                if (showLabel)
                {
                    PropertySection sect = new PropertySection();
                    sect.Title = k;

                    if (!Stack.Children.Contains(sect) && sect.Parent == null)
                    {
                        Stack.Children.Add(sect);
                    }

                    foreach (var t in items)
                    {
                        if (!inlinePropertyLabels)
                        {
                            sect.Add(t.Item1);
                            sect.Add(t.Item2);
                        }
                        else
                        {
                            StackPanelAuto inlinePanel = new StackPanelAuto();
                            inlinePanel.Direction   = Orientation.Horizontal;
                            inlinePanel.HalfAndHalf = true;
                            inlinePanel.Children.Add(t.Item1);
                            inlinePanel.Children.Add(t.Item2);
                            sect.Add(inlinePanel);
                        }
                    }
                }
                else
                {
                    foreach (var t in items)
                    {
                        if (!inlinePropertyLabels)
                        {
                            Stack.Children.Add(t.Item1);
                            Stack.Children.Add(t.Item2);
                        }
                        else
                        {
                            StackPanelAuto inlinePanel = new StackPanelAuto();
                            inlinePanel.Direction   = Orientation.Horizontal;
                            inlinePanel.HalfAndHalf = true;
                            inlinePanel.Children.Add(t.Item1);
                            inlinePanel.Children.Add(t.Item2);
                            Stack.Children.Add(inlinePanel);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void Set(object n, string[] ignore = null, bool showLabel = true, bool inlinePropertyLabels = false)
        {
            Clear();

            PropertyInfo[] infos = n.GetType().GetProperties();

            Dictionary <string, List <Tuple <PropertyInfo, EditableAttribute> > > sorter = new Dictionary <string, List <Tuple <PropertyInfo, EditableAttribute> > >();

            for (int i = 0; i < infos.Length; i++)
            {
                EditableAttribute ed = infos[i].GetCustomAttribute <EditableAttribute>();
                if (ed != null)
                {
                    if (ignore != null && Array.IndexOf(ignore, infos[i].Name) > -1)
                    {
                        continue;
                    }

                    List <Tuple <PropertyInfo, EditableAttribute> > items = null;
                    string sect = ed.Section;

                    if (string.IsNullOrEmpty(sect))
                    {
                        sect = "Default";
                    }

                    if (sorter.TryGetValue(sect, out items))
                    {
                        items.Add(new Tuple <PropertyInfo, EditableAttribute>(infos[i], ed));
                    }
                    else
                    {
                        items = new List <Tuple <PropertyInfo, EditableAttribute> >();
                        items.Add(new Tuple <PropertyInfo, EditableAttribute>(infos[i], ed));
                        sorter[sect] = items;
                    }
                }
            }

            List <string> keys = sorter.Keys.ToList();

            keys.Sort();

            foreach (string k in keys)
            {
                List <Tuple <PropertyInfo, EditableAttribute> > items = sorter[k];

                if (showLabel)
                {
                    PropertySection sect = new PropertySection();
                    sect.Title = k;

                    if (!Stack.Children.Contains(sect) && sect.Parent == null)
                    {
                        Stack.Children.Add(sect);
                    }

                    foreach (var t in items)
                    {
                        string name = t.Item2.Name;
                        if (string.IsNullOrEmpty(name))
                        {
                            name = t.Item1.Name;
                        }

                        UIElement ele = BuildParamater(n, t.Item2, t.Item1);
                        if (ele != null)
                        {
                            StackPanelAuto inlinePanel = new StackPanelAuto();
                            inlinePanel.Direction   = Orientation.Horizontal;
                            inlinePanel.HalfAndHalf = true;

                            //special case to eliminate the labels for
                            //Parameter, CustomParameters, and CustomFunctions
                            if (!(n is GraphInstanceNode && t.Item1.Name.Equals("Parameters")) &&
                                !(n is GraphInstanceNode && t.Item1.Name.Equals("CustomParameters")) &&
                                !(n is Graph && t.Item1.Name.Equals("CustomParameters")) &&
                                !(n is Graph && t.Item1.Name.Equals("Parameters")) &&
                                !(n is Graph && t.Item1.Name.Equals("CustomFunctions")) &&
                                !(n is Graph && t.Item1.Name.Equals("ParameterFunctions")))
                            {
                                if (n is Node && t.Item1.GetCustomAttribute <PromoteAttribute>() != null)
                                {
                                    PropertyLabel pl = new PropertyLabel(name, n as Node, t.Item1.Name);
                                    if (!inlinePropertyLabels)
                                    {
                                        sect.Add(pl);
                                    }
                                    else
                                    {
                                        inlinePanel.Children.Add(pl);
                                    }
                                }
                                else
                                {
                                    PropertyLabel pl = new PropertyLabel(name, null, t.Item1.Name);
                                    if (!inlinePropertyLabels)
                                    {
                                        sect.Add(pl);
                                    }
                                    else
                                    {
                                        inlinePanel.Children.Add(pl);
                                    }
                                }
                            }

                            if (!inlinePropertyLabels)
                            {
                                sect.Add(ele);
                            }
                            else
                            {
                                inlinePanel.Children.Add(ele);
                                sect.Add(inlinePanel);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var t in items)
                    {
                        string name = t.Item2.Name;
                        if (string.IsNullOrEmpty(name))
                        {
                            name = t.Item1.Name;
                        }

                        UIElement ele = BuildParamater(n, t.Item2, t.Item1);
                        if (ele != null)
                        {
                            StackPanelAuto inlinePanel = new StackPanelAuto();
                            inlinePanel.Direction   = Orientation.Horizontal;
                            inlinePanel.HalfAndHalf = true;

                            //special case to eliminate the labels for
                            //Parameter, CustomParameters, and CustomFunctions
                            if (!(n is GraphInstanceNode && t.Item1.Name.Equals("Parameters")) &&
                                !(n is GraphInstanceNode && t.Item1.Name.Equals("CustomParameters")) &&
                                !(n is Graph && t.Item1.Name.Equals("CustomParameters")) &&
                                !(n is Graph && t.Item1.Name.Equals("Parameters")) &&
                                !(n is Graph && t.Item1.Name.Equals("CustomFunctions")) &&
                                !(n is Graph && t.Item1.Name.Equals("ParameterFunctions")))
                            {
                                if (n is Node)
                                {
                                    PropertyLabel pl = new PropertyLabel(name, n as Node, t.Item1.Name);
                                    if (!inlinePropertyLabels)
                                    {
                                        Stack.Children.Add(pl);
                                    }
                                    else
                                    {
                                        inlinePanel.Children.Add(pl);
                                    }
                                }
                                else
                                {
                                    PropertyLabel pl = new PropertyLabel(name, null, t.Item1.Name);
                                    if (!inlinePropertyLabels)
                                    {
                                        Stack.Children.Add(pl);
                                    }
                                    else
                                    {
                                        inlinePanel.Children.Add(pl);
                                    }
                                }
                            }

                            if (!inlinePropertyLabels)
                            {
                                Stack.Children.Add(ele);
                            }
                            else
                            {
                                inlinePanel.Children.Add(ele);
                                Stack.Children.Add(inlinePanel);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public void Set(Node n, List <GraphParameterValue> values, bool showLabel = true, bool inlinePropertyLabels = false)
        {
            Clear();
            Dictionary <string, List <GraphParameterValue> > sorter = new Dictionary <string, List <GraphParameterValue> >();

            //create a copy
            foreach (var p in values)
            {
                if (p.IsFunction())
                {
                    continue;
                }

                string sec = p.Section;
                if (string.IsNullOrEmpty(sec))
                {
                    sec = "Default";
                }
                List <GraphParameterValue> items = null;
                if (sorter.TryGetValue(sec, out items))
                {
                    items.Add(p);
                }
                else
                {
                    items = new List <GraphParameterValue>();
                    items.Add(p);
                    sorter[sec] = items;
                }
            }

            List <string> keys = sorter.Keys.ToList();

            keys.Sort();

            foreach (string k in keys)
            {
                List <GraphParameterValue> items = sorter[k];
                if (showLabel)
                {
                    PropertySection sect = new PropertySection();
                    sect.Title = k;

                    if (!Stack.Children.Contains(sect) && sect.Parent == null)
                    {
                        Stack.Children.Add(sect);
                    }

                    foreach (var v in items)
                    {
                        EditableAttribute ed  = new EditableAttribute(GetParamInputType(v), v.Name, v.Section, v.Min, v.Max);
                        UIElement         ele = BuildParamater(v, ed, v.GetType().GetProperty("Value"));

                        if (ele != null)
                        {
                            PropertyLabel lbl = new PropertyLabel(v.Name, n, "$Custom." + v.Name);

                            if (!inlinePropertyLabels)
                            {
                                sect.Add(lbl);
                                sect.Add(ele);
                            }
                            else
                            {
                                StackPanelAuto inlinePanel = new StackPanelAuto();
                                inlinePanel.Direction   = Orientation.Horizontal;
                                inlinePanel.HalfAndHalf = true;
                                inlinePanel.Children.Add(lbl);
                                inlinePanel.Children.Add(ele);
                                sect.Add(inlinePanel);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var v in items)
                    {
                        EditableAttribute ed  = new EditableAttribute(GetParamInputType(v), v.Name, v.Section, v.Min, v.Max);
                        UIElement         ele = BuildParamater(v, ed, v.GetType().GetProperty("Value"));

                        if (ele != null)
                        {
                            PropertyLabel lbl = new PropertyLabel(v.Name, n, "$Custom." + v.Name);

                            if (!inlinePropertyLabels)
                            {
                                Stack.Children.Add(lbl);
                                Stack.Children.Add(ele);
                            }
                            else
                            {
                                StackPanelAuto inlinePanel = new StackPanelAuto();
                                inlinePanel.Direction   = Orientation.Horizontal;
                                inlinePanel.HalfAndHalf = true;
                                inlinePanel.Children.Add(lbl);
                                inlinePanel.Children.Add(ele);
                                Stack.Children.Add(inlinePanel);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public void Set(Node n, List <GraphParameterValue> values, bool showLabel = true, bool inlinePropertyLabels = false)
        {
            Clear();
            Dictionary <string, List <GraphParameterValue> > sorter = new Dictionary <string, List <GraphParameterValue> >();

            //create a copy
            foreach (var p in values)
            {
                if (p.IsFunction())
                {
                    continue;
                }

                string sec = p.Section;
                if (string.IsNullOrEmpty(sec))
                {
                    sec = Properties.Resources.GRAPH_Default;
                }

                //try and convert name to localized string
                //convert the section name to localized string
                var    rm  = Properties.Resources.ResourceManager;
                string key = "GRAPH_" + sec.Replace(" ", "_");

                try
                {
                    string loc = rm.GetString(key);
                    if (!string.IsNullOrEmpty(loc))
                    {
                        sec = loc;
                    }
                }
                catch (Exception e)
                {
                }

                List <GraphParameterValue> items = null;
                if (sorter.TryGetValue(sec, out items))
                {
                    items.Add(p);
                }
                else
                {
                    items = new List <GraphParameterValue>();
                    items.Add(p);
                    sorter[sec] = items;
                }
            }

            List <string> keys = sorter.Keys.ToList();

            keys.Sort();

            foreach (string k in keys)
            {
                List <GraphParameterValue> items = sorter[k];
                if (showLabel)
                {
                    PropertySection sect = new PropertySection();
                    sect.Title = k;

                    if (!Stack.Children.Contains(sect) && sect.Parent == null)
                    {
                        Stack.Children.Add(sect);
                    }

                    foreach (var v in items)
                    {
                        EditableAttribute ed  = new EditableAttribute(GetParamInputType(v), v.Name, v.Section, v.Min, v.Max);
                        UIElement         ele = BuildParamater(v, ed, v.GetType().GetProperty("Value"));

                        if (ele != null)
                        {
                            string name = v.Name;
                            //try and convert name to localized string
                            //convert the section name to localized string
                            var    rm  = Properties.Resources.ResourceManager;
                            string key = "GRAPH_" + name.Replace(" ", "_");

                            try
                            {
                                string loc = rm.GetString(key);
                                if (!string.IsNullOrEmpty(loc))
                                {
                                    name = loc;
                                }
                            }
                            catch (Exception e)
                            {
                            }


                            PropertyLabel lbl = new PropertyLabel(name, n, "$Custom." + v.Name);

                            if (!inlinePropertyLabels)
                            {
                                sect.Add(lbl);
                                sect.Add(ele);
                            }
                            else
                            {
                                StackPanelAuto inlinePanel = new StackPanelAuto();
                                inlinePanel.Direction   = Orientation.Horizontal;
                                inlinePanel.HalfAndHalf = true;
                                inlinePanel.Children.Add(lbl);
                                inlinePanel.Children.Add(ele);
                                sect.Add(inlinePanel);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var v in items)
                    {
                        EditableAttribute ed  = new EditableAttribute(GetParamInputType(v), v.Name, v.Section, v.Min, v.Max);
                        UIElement         ele = BuildParamater(v, ed, v.GetType().GetProperty("Value"));

                        if (ele != null)
                        {
                            string name = v.Name;

                            //try and convert name to localized string
                            //convert the section name to localized string
                            var    rm  = Properties.Resources.ResourceManager;
                            string key = "GRAPH_" + name.Replace(" ", "_");

                            try
                            {
                                string loc = rm.GetString(key);
                                if (!string.IsNullOrEmpty(loc))
                                {
                                    name = loc;
                                }
                            }
                            catch (Exception e)
                            {
                            }

                            PropertyLabel lbl = new PropertyLabel(name, n, "$Custom." + v.Name);

                            if (!inlinePropertyLabels)
                            {
                                Stack.Children.Add(lbl);
                                Stack.Children.Add(ele);
                            }
                            else
                            {
                                StackPanelAuto inlinePanel = new StackPanelAuto();
                                inlinePanel.Direction   = Orientation.Horizontal;
                                inlinePanel.HalfAndHalf = true;
                                inlinePanel.Children.Add(lbl);
                                inlinePanel.Children.Add(ele);
                                Stack.Children.Add(inlinePanel);
                            }
                        }
                    }
                }
            }
        }