Esempio n. 1
0
        private void AddParameterGroupAsExpanedRows()
        {
            foreach (var input in Inputs)
            {
                var subParameterRow = new OperatorParameterViewRow(new List <OperatorPart>()
                {
                    input
                });
                subParameterRow.XParameterNameButton.Content = input.Name;
                subParameterRow.XInputControls.Children.Add(new GroupInputControl(new List <OperatorPart>()
                {
                    input
                }));

                if (input.Type == FunctionType.Float)
                {
                    if (!input.IsMultiInput)
                    {
                        subParameterRow.XParameterValue.Children.Add(new FloatParameterControl(input));
                    }
                }
                else if (input.Type == FunctionType.Text)
                {
                    var paramEdit = new TextParameterValue(input);
                    subParameterRow.XParameterValue.Children.Add(paramEdit);
                }
                else if (input.Type == FunctionType.Scene)
                {
                    var paramEdit = new SceneParameterValue(input);
                    subParameterRow.XParameterValue.Children.Add(paramEdit);
                }
                XParameterRowsPanel.Children.Add(subParameterRow);
            }
        }
Esempio n. 2
0
        public OperatorParameterView(Operator op)
        {
            var watch = new Stopwatch();

            watch.Start();

            InitializeComponent();
            Operator = op;

            var binding = new Binding("Namespace");

            binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            binding.Source = op.Definition;
            binding.Path   = new PropertyPath("Namespace");
            NamespaceTextBox.SetBinding(TextBox.TextProperty, binding);

            binding = new Binding("Type");
            binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            binding.Source = op.Definition;
            binding.Path   = new PropertyPath("Name");
            TypeTextBox.SetBinding(TextBox.TextProperty, binding);


            binding = new Binding("OperatorName")
            {
                Mode = BindingMode.OneWay
            };
            binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            binding.Source = op;
            binding.Path   = new PropertyPath("Name");
            XNameTextBox.XTextEdit.SetBinding(TextBox.TextProperty, binding);
            XNameTextBox.EditingStartedEvent += () =>
            {
                _opStateEntry = new UpdateOperatorPropertiesCommand.Entry(op);
                _updateOperatorPropertiesCommand = new UpdateOperatorPropertiesCommand(op, _opStateEntry);
            };
            XNameTextBox.EditingUpdatedEvent += (o, ev) =>
            {
                _updateOperatorPropertiesCommand.ChangeEntries[0].Name = XNameTextBox.textEditButton.XTextEdit.Text;
                _updateOperatorPropertiesCommand.Do();
            };
            XNameTextBox.EditingCompletedEvent += () =>
            {
                App.Current.UndoRedoStack.Add(_updateOperatorPropertiesCommand);
                _updateOperatorPropertiesCommand = new UpdateOperatorPropertiesCommand(op, _opStateEntry);
            };
            XParameterStackPanel = new StackPanel();
            XParameterStackPanel.Children.Clear();

            // find groups
            var inputGroups = from input in op.Inputs
                              group input by input.Name.Split(new[] { '.' })[0] into g
                              select new { Name = g.Key, Inputs = g.ToArray() };

            foreach (var group in inputGroups)
            {
                var singleParameterRow = new OperatorParameterViewRow(group.Inputs.ToList());
                singleParameterRow.XParameterNameButton.Content = group.Name;

                singleParameterRow.XInputControls.Children.Add(new GroupInputControl(group.Inputs.ToList())); // This is slooww (half of operator selection time)

                // Single Parameter
                if (group.Inputs.Length == 1)
                {
                    XParameterStackPanel.Children.Add(singleParameterRow);

                    var input = group.Inputs[0];
                    if (input.Type == FunctionType.Float)
                    {
                        if (!input.IsMultiInput)
                        {
                            var metaInput  = input.Parent.GetMetaInput(input);
                            var enumValues = metaInput.EnumValues;

                            // ENUM - Parameter
                            if (enumValues.Count > 0)
                            {
                                var newEnumControl = new EnumParameterValue(input);
                                singleParameterRow.ResetToDefaultEvent += newEnumControl.ResetToDefaultHandler;
                                singleParameterRow.XParameterValue.Children.Add(newEnumControl);
                            }

                            // Single Float Parameter
                            else
                            {
                                FloatParameterControl newFloatControl = new FloatParameterControl(input);
                                singleParameterRow.XParameterValue.Children.Add(newFloatControl);
                                singleParameterRow.ResetToDefaultEvent     += newFloatControl.ParameterRow_ResetSingleParameterHandler;
                                singleParameterRow.StartManipulationEvent  += newFloatControl.ParameterRow_StartManipulationHandler;
                                singleParameterRow.UpdateManipulationEvent += newFloatControl.ParameterRow_UpdateManipulaitonHandler;
                                singleParameterRow.EndManipulationEvent    += newFloatControl.ParameterRow_EndManipulationHandler;
                            }
                        }
                    }
                    else if (input.Type == FunctionType.Text)
                    {
                        var paramEdit = new TextParameterValue(input);
                        if (input.Name.EndsWith("Text"))
                        {
                            singleParameterRow.XAdditionalContent.Child = paramEdit;
                        }
                        else
                        {
                            singleParameterRow.XParameterValue.Children.Add(paramEdit);
                        }
                    }
                    else if (input.Type == FunctionType.Scene)
                    {
                        var paramEdit = new SceneParameterValue(input);
                        singleParameterRow.XParameterValue.Children.Add(paramEdit);
                    }
                    else if (input.Type == FunctionType.Image)
                    {
                        var paramEdit = new ImageParameterValue(input);
                        singleParameterRow.XParameterValue.Children.Add(paramEdit);
                    }
                    else if (input.Type == FunctionType.Dynamic)
                    {
                        var paramEdit = new DynamicParameterValue(input);
                        singleParameterRow.XParameterValue.Children.Add(paramEdit);
                    }
                    else if (input.Type == FunctionType.Generic)
                    {
                        var paramEdit = new GenericParameterValue(input);
                        singleParameterRow.XParameterValue.Children.Add(paramEdit);
                    }
                    else if (input.Type == FunctionType.Mesh)
                    {
                        var paramEdit = new MeshParameterValue(input);
                        singleParameterRow.XParameterValue.Children.Add(paramEdit);
                    }
                }

                // Float Parameter Groups
                else
                {
                    if (group.Inputs.Length == 4 &&
                        group.Inputs[0].Name.EndsWith(".R") &&
                        group.Inputs[1].Name.EndsWith(".G") &&
                        group.Inputs[2].Name.EndsWith(".B") &&
                        group.Inputs[3].Name.EndsWith(".A"))
                    {
                        var rgbaControl = new RgbaParameterValue(group.Inputs);
                        singleParameterRow.ResetToDefaultEvent     += rgbaControl.ResetToDefaultHandler;
                        singleParameterRow.StartManipulationEvent  += rgbaControl.StartManipulationHandler;
                        singleParameterRow.UpdateManipulationEvent += rgbaControl.UpdateManipulationHandler;
                        singleParameterRow.EndManipulationEvent    += rgbaControl.EndManipulationHandler;
                        singleParameterRow.XParameterValue.Children.Add(rgbaControl);
                    }
                    else
                    {
                        var vectorControl = new VectorNParameterValue(group.Inputs);

                        singleParameterRow.StartManipulationEvent  += vectorControl.StartManipulationHandler;
                        singleParameterRow.UpdateManipulationEvent += vectorControl.UpdateManipulationHandler;
                        singleParameterRow.EndManipulationEvent    += vectorControl.EndManipulationHandler;
                        singleParameterRow.ResetToDefaultEvent     += vectorControl.ResetToDefaultHandler;
                        singleParameterRow.XParameterValue.Children.Add(vectorControl);
                    }

                    var parameterGroupComponent = new ParameterGroup(group.Inputs);
                    parameterGroupComponent.XParameterGroupPanel.Children.Add(singleParameterRow);
                    XParameterStackPanel.Children.Add(parameterGroupComponent);
                }
            }

            var descriptionBox = new ICSharpCode.AvalonEdit.Editing.TextArea();

            descriptionBox.ToolTip    = "Operator description. Click to edit";
            descriptionBox.Foreground = Brushes.Gray;
            descriptionBox.Margin     = new Thickness(4, 6, 4, 4);
            descriptionBox.MinHeight  = 40;
            descriptionBox.FontSize   = 13;

            DescriptionDoc              = new TextDocument(op.Definition.Description);
            DescriptionDoc.TextChanged += HandleDescriptionChange;
            descriptionBox.Document     = DescriptionDoc;
            XParameterStackPanel.Children.Add(descriptionBox);

            XParameterScrollViewer.Content = XParameterStackPanel;
            App.Current.OperatorPresetManager.FilterPresetsForSelectedOperator();

            watch.Stop();
        }