|
@@ -5,6 +5,7 @@ using PixiEditor.AvaloniaUI.ViewModels.Nodes;
|
|
|
using PixiEditor.ChangeableDocument.Actions;
|
|
|
using PixiEditor.ChangeableDocument.Actions.Generated;
|
|
|
using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
|
|
|
+using PixiEditor.ChangeableDocument.ChangeInfos.NodeGraph;
|
|
|
using PixiEditor.Numerics;
|
|
|
|
|
|
namespace PixiEditor.AvaloniaUI.ViewModels.Document;
|
|
@@ -14,6 +15,7 @@ internal class NodeGraphViewModel : ViewModelBase, INodeGraphHandler
|
|
|
public DocumentViewModel DocumentViewModel { get; }
|
|
|
public ObservableCollection<INodeHandler> AllNodes { get; } = new();
|
|
|
public ObservableCollection<NodeConnectionViewModel> Connections { get; } = new();
|
|
|
+ public ObservableCollection<NodeFrameViewModelBase> Frames { get; } = new();
|
|
|
public StructureTree StructureTree { get; } = new();
|
|
|
public INodeHandler? OutputNode { get; private set; }
|
|
|
|
|
@@ -48,6 +50,32 @@ internal class NodeGraphViewModel : ViewModelBase, INodeGraphHandler
|
|
|
StructureTree.Update(this);
|
|
|
}
|
|
|
|
|
|
+ public void AddFrame(Guid frameId, IEnumerable<Guid> nodes)
|
|
|
+ {
|
|
|
+ var frame = new NodeFrameViewModel(frameId, AllNodes.Where(x => nodes.Contains(x.Id)));
|
|
|
+
|
|
|
+ Frames.Add(frame);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void AddZone(Guid frameId, string internalName, Guid startId, Guid endId)
|
|
|
+ {
|
|
|
+ var start = AllNodes.First(x => x.Id == startId);
|
|
|
+ var end = AllNodes.First(x => x.Id == endId);
|
|
|
+
|
|
|
+ var zone = new NodeZoneViewModel(frameId, internalName, start, end);
|
|
|
+
|
|
|
+ Frames.Add(zone);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void RemoveFrame(Guid guid)
|
|
|
+ {
|
|
|
+ var frame = Frames.FirstOrDefault(x => x.Id == guid);
|
|
|
+
|
|
|
+ if (frame == null) return;
|
|
|
+
|
|
|
+ Frames.Remove(frame);
|
|
|
+ }
|
|
|
+
|
|
|
public void SetConnection(NodeConnectionViewModel connection)
|
|
|
{
|
|
|
var existingInputConnection = Connections.FirstOrDefault(x => x.InputProperty == connection.InputProperty);
|
|
@@ -147,6 +175,11 @@ internal class NodeGraphViewModel : ViewModelBase, INodeGraphHandler
|
|
|
Internals.ActionAccumulator.AddActions(new NodePosition_Action(node.Id, newPos));
|
|
|
}
|
|
|
|
|
|
+ public void UpdatePropertyValue(INodeHandler node, string property, object? value)
|
|
|
+ {
|
|
|
+ Internals.ActionAccumulator.AddFinishedActions(new UpdatePropertyValue_Action(node.Id, property, value));
|
|
|
+ }
|
|
|
+
|
|
|
public void EndChangeNodePosition()
|
|
|
{
|
|
|
Internals.ActionAccumulator.AddFinishedActions(new EndNodePosition_Action());
|
|
@@ -154,7 +187,29 @@ internal class NodeGraphViewModel : ViewModelBase, INodeGraphHandler
|
|
|
|
|
|
public void CreateNode(Type nodeType)
|
|
|
{
|
|
|
- Internals.ActionAccumulator.AddFinishedActions(new CreateNode_Action(nodeType, Guid.NewGuid()));
|
|
|
+ IAction change;
|
|
|
+
|
|
|
+ if (nodeType == typeof(ModifyImageLeftNode) || nodeType == typeof(ModifyImageRightNode))
|
|
|
+ {
|
|
|
+ change = new CreateModifyImageNodePair_Action(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ change = new CreateNode_Action(nodeType, Guid.NewGuid());
|
|
|
+ }
|
|
|
+
|
|
|
+ Internals.ActionAccumulator.AddFinishedActions(change);
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: Remove this
|
|
|
+ public void CreateNodeFrameAroundEverything()
|
|
|
+ {
|
|
|
+ CreateNodeFrame(AllNodes);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void CreateNodeFrame(IEnumerable<INodeHandler> nodes)
|
|
|
+ {
|
|
|
+ Internals.ActionAccumulator.AddFinishedActions(new CreateNodeFrame_Action(Guid.NewGuid(), nodes.Select(x => x.Id)));
|
|
|
}
|
|
|
|
|
|
public void ConnectProperties(INodePropertyHandler? start, INodePropertyHandler? end)
|