예제 #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);
                        }
                    }
                }
            }
        }
예제 #2
0
        private void ConstantVar_Click(object sender, RoutedEventArgs e)
        {
            if (Node == null || string.IsNullOrEmpty(Parameter))
            {
                return;
            }

            try
            {
                PropertyInfo info = null;

                if (Parameter.StartsWith("$Custom."))
                {
                    if (Node is GraphInstanceNode)
                    {
                        GraphInstanceNode gn = Node as GraphInstanceNode;

                        string cparam = Parameter.Replace("$Custom.", "");

                        var param = gn.GetCustomParameter(cparam);

                        if (param != null)
                        {
                            var cparent = Node.ParentGraph;

                            if (cparent != null)
                            {
                                cparent.SetParameterValue(Node.Id, cparam, param.Value, true, param.Type);
                                var nparam = cparent.GetParameterRaw(Node.Id, cparam);

                                //copy settings over
                                if (nparam != null)
                                {
                                    nparam.Description = param.Description;
                                    nparam.InputType   = param.InputType;
                                    nparam.Min         = param.Min;
                                    nparam.Max         = param.Max;
                                    nparam.Name        = param.Name;
                                }

                                FIcon.Opacity         = 0.25;
                                DefaultVar.IsEnabled  = true;
                                ConstantVar.IsEnabled = false;
                                FunctionVar.IsEnabled = false;
                            }
                            else
                            {
                                Log.Warn("Failed to promote to constant");
                            }
                        }
                        else
                        {
                            //log error
                            Log.Error("Could not find custom parameter: " + cparam);
                        }
                    }
                    else
                    {
                        Log.Warn("Failed to promote to constant");
                    }
                }
                else
                {
                    info = Node.GetType().GetProperty(Parameter);

                    if (info != null)
                    {
                        var pro = info.GetCustomAttribute <PromoteAttribute>();

                        NodeType t = NodeType.Float;
                        if (pro != null)
                        {
                            t = pro.ExpectedType;
                        }

                        var v = info.GetValue(Node);

                        var p = Node.ParentGraph;

                        p = p.ParentNode != null ? p.ParentNode.ParentGraph : p;

                        if (p != null)
                        {
                            p.SetParameterValue(Node.Id, Parameter, v, pro != null, t);

                            FIcon.Opacity         = 0.25;
                            DefaultVar.IsEnabled  = true;
                            ConstantVar.IsEnabled = false;
                            FunctionVar.IsEnabled = false;
                        }
                        else
                        {
                            Log.Warn("Failed to promote to constant");
                        }
                    }
                    else
                    {
                        Log.Warn("Failed to promote to constant");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
예제 #3
0
        private void CreateFunctionParameter(FunctionGraph g)
        {
            g.AssignParentNode(Node);

            try
            {
                PropertyInfo info = null;
                if (Parameter.StartsWith("$Custom."))
                {
                    if (Node is GraphInstanceNode)
                    {
                        GraphInstanceNode gn = Node as GraphInstanceNode;

                        string cparam = Parameter.Replace("$Custom.", "");

                        var param = gn.GetCustomParameter(cparam);

                        if (param != null)
                        {
                            var cparent = Node.ParentGraph;

                            g.ExpectedOutput = param.Type;

                            if (cparent != null)
                            {
                                cparent.SetParameterValue(Node.Id, cparam, g, true, param.Type);

                                FIcon.Opacity         = 1;
                                DefaultVar.IsEnabled  = true;
                                ConstantVar.IsEnabled = false;
                                FunctionVar.IsEnabled = false;
                            }
                            else
                            {
                                Log.Warn("Failed to promote to function");
                            }
                        }
                        else
                        {
                            //log error
                            Log.Error("Could not find custom parameter: " + cparam);
                        }
                    }
                    else
                    {
                        Log.Warn("Failed to promoto to function");
                    }
                }
                else
                {
                    info = Node.GetType().GetProperty(Parameter);
                    if (info == null)
                    {
                        Log.Warn("Failed to promote to function");
                        return;
                    }

                    var pro = info.GetCustomAttribute <PromoteAttribute>();

                    if (pro != null)
                    {
                        g.ExpectedOutput = pro.ExpectedType;
                    }

                    var p = Node.ParentGraph;

                    p = p.ParentNode != null ? p.ParentNode.ParentGraph : p;

                    if (p != null)
                    {
                        p.SetParameterValue(Node.Id, Parameter, g, true, g.ExpectedOutput);

                        FIcon.Opacity         = 1;
                        DefaultVar.IsEnabled  = true;
                        ConstantVar.IsEnabled = false;
                        FunctionVar.IsEnabled = false;
                    }
                    else
                    {
                        Log.Warn("Failed to promote to function");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
예제 #4
0
        private void FunctionVar_Click(object sender, RoutedEventArgs e)
        {
            if (Node == null || string.IsNullOrEmpty(Parameter))
            {
                return;
            }

            FunctionGraph g = new FunctionGraph(Node.Name + " - " + Parameter.Replace("$Custom.", "") + " Function", Node.Width, Node.Height);

            g.AssignParentNode(Node);

            try
            {
                PropertyInfo info = null;
                if (Parameter.StartsWith("$Custom."))
                {
                    if (Node is GraphInstanceNode)
                    {
                        GraphInstanceNode gn = Node as GraphInstanceNode;

                        string cparam = Parameter.Replace("$Custom.", "");

                        var param = gn.GetCustomParameter(cparam);

                        if (param != null)
                        {
                            var cparent = Node.ParentGraph;

                            if (cparent != null)
                            {
                                cparent = cparent.TopGraph();
                            }

                            g.ExpectedOutput = param.Type;

                            if (cparent != null)
                            {
                                cparent.SetParameterValue(Node.Id, cparam, g, true, param.Type);

                                FIcon.Opacity         = 1;
                                DefaultVar.IsEnabled  = true;
                                ConstantVar.IsEnabled = false;
                                FunctionVar.IsEnabled = false;
                            }
                            else
                            {
                                Log.Warn("Failed to promote to function");
                            }
                        }
                        else
                        {
                            //log error
                            Log.Error("Could not find custom parameter: " + cparam);
                        }
                    }
                    else
                    {
                        Log.Warn("Failed to promoto to function");
                    }
                }
                else
                {
                    info = Node.GetType().GetProperty(Parameter);
                    if (info == null)
                    {
                        Log.Warn("Failed to promote to function");
                        return;
                    }

                    var pro = info.GetCustomAttribute <PromoteAttribute>();

                    if (pro != null)
                    {
                        g.ExpectedOutput = pro.ExpectedType;
                    }

                    var p = Node.ParentGraph;

                    if (p != null)
                    {
                        p = p.TopGraph();
                    }

                    if (p != null)
                    {
                        var pg = p;

                        pg.SetParameterValue(Node.Id, Parameter, g, true, g.ExpectedOutput);

                        FIcon.Opacity         = 1;
                        DefaultVar.IsEnabled  = true;
                        ConstantVar.IsEnabled = false;
                        FunctionVar.IsEnabled = false;
                    }
                    else
                    {
                        Log.Warn("Failed to promote to function");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }