Exemple #1
0
        /*************************************/
        /**** Public Methods              ****/
        /*************************************/

        public virtual void SetItem(object item, bool sendNotification = true, bool updateOriginal = true)
        {
            if (item == null)
            {
                return;
            }

            if (updateOriginal)
            {
                m_OriginalItem = item;
            }
            SelectedItem = FromGeneric(item as dynamic);

            List <ParamInfo> oldInputs  = InputParams.ToList();
            List <ParamInfo> oldOutputs = OutputParams.ToList();

            SetComponentDetails();

            SetInputs();
            SetOutputs();

            SetInputSelectionMenu();
            SetOutputSelectionMenu();

            CompileMethod();
            CompileInputGetters();
            CompileOutputSetters();

            if (sendNotification)
            {
                MarkAsModified(new CallerUpdate
                {
                    Cause           = CallerUpdateCause.ItemSelected,
                    ComponentUpdate = new ComponentUpdate {
                        Name = Name, Description = Description
                    },
                    InputUpdates  = InputParams.Changes(oldInputs).Where(x => x.Param.IsSelected).ToList(),
                    OutputUpdates = OutputParams.Changes(oldOutputs).Where(x => x.Param.IsSelected).ToList()
                });
            }
        }
Exemple #2
0
        /*************************************/

        protected bool RestoreItem(object selectedItem, List <ParamInfo> inputParams, List <ParamInfo> outputParams)
        {
            // Finally Set the item
            SetItem(selectedItem, false);

            // Make sure that saved selection is copied over
            if (inputParams != null)
            {
                SelectInputs(inputParams.GroupBy(x => x.Name).Select(g => g.First()).ToDictionary(x => x.Name, x => x.IsSelected));
            }
            if (outputParams != null)
            {
                SelectOutputs(outputParams.GroupBy(x => x.Name).Select(g => g.First()).ToDictionary(x => x.Name, x => x.IsSelected));
            }

            // Look for changes
            CallerUpdate update = new CallerUpdate
            {
                Cause           = CallerUpdateCause.ReadFromSave,
                ComponentUpdate = new ComponentUpdate {
                    Name = Name, Description = Description
                },
                InputUpdates  = InputParams.Changes(inputParams).Where(x => x.Param.IsSelected).ToList(),
                OutputUpdates = OutputParams.Changes(outputParams).Where(x => x.Param.IsSelected).ToList()
            };

            // Record warnings if changes happened
            List <IParamUpdate> paramUpdates = update.InputUpdates.Concat(update.OutputUpdates).ToList();

            if (paramUpdates.Count > 0)
            {
                Engine.Reflection.Compute.RecordWarning("This component was upgraded. Here's the resulting changes: \n"
                                                        + paramUpdates.Select(x => "  - " + x.IToText()).Aggregate((a, b) => a + "\n" + b));
            }

            // Send the notification
            MarkAsModified(update);

            return(true);
        }
Exemple #3
0
        /*************************************/
        /**** Public Methods              ****/
        /*************************************/

        public bool CollectOutputTypes(List <object> objects = null)
        {
            if (objects == null)
            {
                objects = m_DataAccessor.GetAllData(0);
            }

            // Do not update if the list of input is empty or if user has manually selected outputs
            if (objects.Count == 0)
            {
                return(false);
            }

            // Save old outputs
            List <ParamInfo> oldOutputs = OutputParams.ToList();

            // Collect the new output params
            OutputParams = Engine.UI.Query.OutputParams(objects);

            // Compile the setters
            CompileOutputSetters();

            // Create the output menu
            SetOutputSelectionMenu();

            // Mark as modified if output have changed
            List <IParamUpdate> changes = OutputParams.Changes(oldOutputs).Where(x => x.Param.IsSelected).ToList();

            if (changes.Count > 0)
            {
                MarkAsModified(new CallerUpdate {
                    Cause = CallerUpdateCause.ItemSelected, OutputUpdates = changes
                });
            }

            return(true);
        }