private void RemoveSelectedRenderFeatures()
        {
            using (var transaction = UndoRedoService.CreateTransaction())
            {
                var toRemove = SelectedRenderFeatures.Cast <RenderFeatureViewModel>().Select(x => x.RenderFeature).ToList();
                // Clear selection first, so we don't try to unselect items that don't exist anymore later.
                SelectedRenderFeatures.Clear();

                foreach (var renderFeature in toRemove)
                {
                    // Find index
                    var index = Asset.Asset.RenderFeatures.IndexOf(renderFeature);
                    if (index < 0)
                    {
                        continue;
                    }

                    // Remove
                    var itemIndex = new NodeIndex(index);
                    renderFeaturesNode.Remove(renderFeature, itemIndex);
                }

                UndoRedoService.SetName(transaction, "Delete render feature(s)");
            }
        }
        private void RemoveSelectedRenderStages()
        {
            using (var transaction = UndoRedoService.CreateTransaction())
            {
                var toRemove = SelectedRenderStages.Cast <RenderStageViewModel>().Select(x => x.RenderStage).ToList();
                // Clear selection first, so we don't try to unselect items that don't exist anymore later.
                SelectedRenderStages.Clear();

                foreach (var renderStage in toRemove)
                {
                    // Find index
                    var index = Asset.Asset.RenderStages.IndexOf(renderStage);
                    if (index < 0)
                    {
                        continue;
                    }

                    // Clear references to this object
                    Asset.PropertyGraph.ClearReferencesToObjects(renderStage.Id.Yield());

                    // Remove
                    var itemIndex = new NodeIndex(index);
                    renderStagesNode.Remove(renderStage, itemIndex);
                }

                UndoRedoService.SetName(transaction, "Delete render stage(s)");
            }
        }
        private void RemoveSelectedCameraSlots()
        {
            using (var transaction = UndoRedoService.CreateTransaction())
            {
                var toRemove = SelectedCameraSlots.Cast <GraphicsCompositorCameraSlotsViewModel>().Select(x => x.CameraSlot).ToList();
                // Clear selection first, so we don't try to unselect items that don't exist anymore later.
                SelectedCameraSlots.Clear();

                foreach (var viewModel in toRemove)
                {
                    // Find index
                    var index = Asset.Asset.Cameras.IndexOf(viewModel);
                    if (index < 0)
                    {
                        continue;
                    }

                    // Do not clear references to this object - camera slots in the scene asset should not change automatically!

                    // Remove
                    var itemIndex = new NodeIndex(index);
                    cameraSlotsNode.Remove(viewModel, itemIndex);
                }

                UndoRedoService.SetName(transaction, "Delete camera slot(s)");
            }
        }
        private void RemoveSelectedSharedRenderers()
        {
            using (var transaction = UndoRedoService.CreateTransaction())
            {
                var toRemove = SelectedSharedRenderers.OfType <SharedRendererBlockViewModel>().ToList();
                // Clear selection first, so we don't try to unselect items that don't exist anymore later.
                SelectedSharedRenderers.Clear();

                foreach (var viewModel in toRemove)
                {
                    // Find index
                    var index = Asset.Asset.SharedRenderers.IndexOf(viewModel.GetSharedRenderer());
                    if (index < 0)
                    {
                        continue;
                    }

                    // Remove
                    var itemIndex = new NodeIndex(index);
                    sharedRenderersNode.Remove(viewModel.GetSharedRenderer(), itemIndex);
                }

                UndoRedoService.SetName(transaction, "Delete renderer(s)");
            }
        }
Esempio n. 5
0
        private static void ClearMaterialList(IObjectNode materials)
        {
            var indices = materials.Indices.ToList();

            foreach (var index in indices)
            {
                var item = materials.Retrieve(index);
                materials.Remove(item, index);
            }
        }
Esempio n. 6
0
 private void SetMaterialEnabled(IObjectNode materialNode, Index index, bool value)
 {
     if (value)
     {
         var material = GetMaterial(materialNode, index);
         materialNode.Add(material, index);
     }
     else
     {
         var material = materialNode.Retrieve(index);
         materialNode.Remove(material, index);
     }
 }
        public void RemoveBlock(Block block)
        {
            // First, remove all links this block uses
            var i = 0;

            foreach (var link in method.Links.Values)
            {
                if (link.Source.Owner == block || link.Target.Owner == block)
                {
                    var linkItemIndex = new Index(i);
                    linksContent.Remove(link, linkItemIndex);

                    // Since we removed an item, fix index of next check
                    --i;
                }
            }

            // Remove
            var itemIndex = new Index(block.Id);

            blocksContent.Remove(block, itemIndex);
        }
Esempio n. 8
0
        public override void RemoveItem(object value, NodeIndex index)
        {
            if (!RootNode.IsEnumerable)
            {
                throw new NodePresenterException($"{nameof(RootNodePresenter)}.{nameof(RemoveItem)} cannot be invoked on objects that are not collection.");
            }

            try
            {
                RootNode.Remove(value, index);
            }
            catch (Exception e)
            {
                throw new NodePresenterException("An error occurred while removing an item to the node, see the inner exception for more information.", e);
            }
        }
        public void RemoveParameter(Parameter parameter)
        {
            // Find index
            var index = method.Parameters.IndexOf(parameter);

            if (index < 0)
            {
                return;
            }

            // TODO: Cleanup references to this parameter

            // Remove
            var itemIndex = new Index(index);

            parametersContent.Remove(parameter, itemIndex);
        }
Esempio n. 10
0
        public void RemoveMethod(Method method)
        {
            // Find index
            var index = Asset.Methods.IndexOf(method);

            if (index < 0)
            {
                return;
            }

            // TODO: Cleanup references to this function

            // Remove
            var itemIndex = new NodeIndex(index);

            methodsContent.Remove(method, itemIndex);
        }
Esempio n. 11
0
        public void RemoveProperty(Property property)
        {
            // Find index
            var index = Asset.Properties.IndexOf(property);

            if (index < 0)
            {
                return;
            }

            // TODO: Cleanup references to this variable

            // Remove
            var itemIndex = new NodeIndex(index);

            propertiesContent.Remove(property, itemIndex);
        }
Esempio n. 12
0
        public void ChangeChildElementLayoutProperties([NotNull] UIElement child, PanelCommandMode mode)
        {
            if (child == null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            using (var transaction = Editor.UndoRedoService.CreateTransaction())
            {
                var canvas = AssetSidePanel as Canvas;
                if (canvas != null)
                {
                    var pinOrigin = GetDependencyPropertyValue(child, Canvas.PinOriginPropertyKey);
                    switch (mode)
                    {
                    case PanelCommandMode.PinTopLeft:
                        pinOrigin.X = 0.0f;
                        pinOrigin.Y = 0.0f;
                        break;

                    case PanelCommandMode.PinTop:
                        pinOrigin.X = 0.5f;
                        pinOrigin.Y = 0.0f;
                        break;

                    case PanelCommandMode.PinTopRight:
                        pinOrigin.X = 1.0f;
                        pinOrigin.Y = 0.0f;
                        break;

                    case PanelCommandMode.PinLeft:
                        pinOrigin.X = 0.0f;
                        pinOrigin.Y = 0.5f;
                        break;

                    case PanelCommandMode.PinCenter:
                        pinOrigin.X = 0.5f;
                        pinOrigin.Y = 0.5f;
                        break;

                    case PanelCommandMode.PinRight:
                        pinOrigin.X = 1.0f;
                        pinOrigin.Y = 0.5f;
                        break;

                    case PanelCommandMode.PinBottomLeft:
                        pinOrigin.X = 0.0f;
                        pinOrigin.Y = 1.0f;
                        break;

                    case PanelCommandMode.PinBottom:
                        pinOrigin.X = 0.5f;
                        pinOrigin.Y = 1.0f;
                        break;

                    case PanelCommandMode.PinBottomRight:
                        pinOrigin.X = 1.0f;
                        pinOrigin.Y = 1.0f;
                        break;

                    case PanelCommandMode.PinFront:
                        pinOrigin.Z = 1.0f;
                        break;

                    case PanelCommandMode.PinMiddle:
                        pinOrigin.Z = 0.5f;
                        break;

                    case PanelCommandMode.PinBack:
                        pinOrigin.Z = 0.0f;
                        break;

                    default:
                        throw new ArgumentException($"{mode} is not a supported mode.", nameof(mode));
                    }
                    SetDependencyPropertyValue(child, Canvas.PinOriginPropertyKey, pinOrigin);
                    Editor.UndoRedoService.SetName(transaction, $"Change Pin Origin of {UIEditorBaseViewModel.GetDisplayName(child)}");
                    return;
                }

                var grid = AssetSidePanel as GridBase;
                if (grid != null)
                {
                    PropertyKey <int> propertyKey;
                    int offset;
                    switch (mode)
                    {
                    case PanelCommandMode.MoveUp:
                        propertyKey = GridBase.RowPropertyKey;
                        offset      = -1;
                        break;

                    case PanelCommandMode.MoveDown:
                        propertyKey = GridBase.RowPropertyKey;
                        offset      = 1;
                        break;

                    case PanelCommandMode.MoveLeft:
                        propertyKey = GridBase.ColumnPropertyKey;
                        offset      = -1;
                        break;

                    case PanelCommandMode.MoveRight:
                        propertyKey = GridBase.ColumnPropertyKey;
                        offset      = 1;
                        break;

                    case PanelCommandMode.MoveBack:
                        propertyKey = GridBase.LayerPropertyKey;
                        offset      = -1;
                        break;

                    case PanelCommandMode.MoveFront:
                        propertyKey = GridBase.LayerPropertyKey;
                        offset      = 1;
                        break;

                    default:
                        throw new ArgumentException($"{mode} is not a supported mode.", nameof(mode));
                    }

                    var currentValue = GetDependencyPropertyValue(child, propertyKey);
                    var newValue     = Math.Max(0, currentValue + offset);
                    SetDependencyPropertyValue(child, propertyKey, newValue);
                    Editor.UndoRedoService.SetName(transaction, $"Move {UIEditorBaseViewModel.GetDisplayName(child)}");
                    return;
                }

                var stackPanel = AssetSidePanel as StackPanel;
                if (stackPanel != null)
                {
                    var collection = AssetSidePanel.Children;
                    var index      = collection.IndexOf(child);
                    if (index == -1)
                    {
                        throw new InvalidOperationException("The given element is not a child of this panel.");
                    }

                    int newIndex;
                    switch (mode)
                    {
                    case PanelCommandMode.MoveDown:
                        newIndex = index + 1;
                        if (newIndex >= collection.Count)
                        {
                            return;
                        }
                        break;

                    case PanelCommandMode.MoveUp:
                        newIndex = index - 1;
                        if (newIndex < 0)
                        {
                            return;
                        }
                        break;

                    default:
                        throw new ArgumentException($"{mode} is not a supported mode.", nameof(mode));
                    }

                    // FIXME: review if this is fine doing it that way or if we need to do it the same way as when moving elements around
                    childrenNode.Remove(child, new NodeIndex(index));
                    childrenNode.Add(child, new NodeIndex(newIndex));
                    Editor.UndoRedoService.SetName(transaction, $"Move {UIEditorBaseViewModel.GetDisplayName(child)}");
                }
            }
        }
Esempio n. 13
0
        /// <inheritdoc />
        protected override void Initialize()
        {
            base.Initialize();

            var invalidIndices = new Stack <int>();

            for (var i = 0; i < Asset.ChildrenIds.Count; i++)
            {
                var childId    = Asset.ChildrenIds[i];
                var childScene = Session.GetAssetById(childId) as SceneViewModel;
                if (childScene == null)
                {
                    // Mark this id for deletion
                    invalidIndices.Push(i);
                    continue;
                }

                // We trust the child's Parent property. Let's check the relationship or fix it.
                var parentValue     = childScene.parentNode.Retrieve();
                var parentReference = AttachedReferenceManager.GetAttachedReference(parentValue);
                if (parentReference?.Id != Id)
                {
                    // Mark this id for deletion
                    invalidIndices.Push(i);
                    // If the parent is already initialized and the child is connected, there is nothing to do
                    if (childScene.Parent?.isInitialized == true)
                    {
                        Debug.Assert(childScene.Parent.Children.Contains(childScene));
                    }
                    else
                    {
                        // Otherwise: fixup the parent child relationship
                        FixupParentChild(childScene, parentReference);
                    }
                }
                else
                {
                    // Everything good
                    childScene.parent = this;
                    Children.Add(childScene);
                }
            }
            foreach (var index in invalidIndices)
            {
                childrenNode.Remove(Asset.ChildrenIds[index], new NodeIndex(index));
            }

            if (Parent?.isInitialized == true)
            {
                Debug.Assert(Parent.Children.Contains(this));
            }
            else
            {
                var parentValue     = parentNode.Retrieve();
                var parentReference = AttachedReferenceManager.GetAttachedReference(parentValue);
                FixupParentChild(this, parentReference);
            }

            Children.CollectionChanged += ChildrenCollectionChanged;
            childrenNode.ItemChanged   += ChildrenNodeItemChanged;
            parentNode.ValueChanged    += ParentNodeValueChanged;
            isInitialized = true;
        }