From a1c46e4b5b79bc001e641cace5a9f4a65727844d Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Thu, 14 Jan 2021 22:16:25 +0530 Subject: [PATCH 1/2] prevent overlap --- .../Graph/Workspaces/LayoutExtensions.cs | 56 ++++++++++++++++++- .../Search/NodeSearchElementViewModel.cs | 8 ++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/DynamoCore/Graph/Workspaces/LayoutExtensions.cs b/src/DynamoCore/Graph/Workspaces/LayoutExtensions.cs index 54b86564b63..b01b050f999 100644 --- a/src/DynamoCore/Graph/Workspaces/LayoutExtensions.cs +++ b/src/DynamoCore/Graph/Workspaces/LayoutExtensions.cs @@ -20,7 +20,7 @@ public static class LayoutExtensions /// /// Workspace on which graph layout will be performed. /// If true, skip initializing new undo action group. - internal static List DoGraphAutoLayout(this WorkspaceModel workspace, bool reuseUndoRedoGroup = false) + internal static List DoGraphAutoLayout(this WorkspaceModel workspace, bool reuseUndoRedoGroup = false, bool isNodeAutoComplete = false, Guid? originalNodeGUID = null) { if (workspace.Nodes.Count() < 2) return null; @@ -50,7 +50,13 @@ public static class LayoutExtensions // Run layout algorithm for each subgraph layoutSubgraphs.Skip(1).ToList().ForEach(g => RunLayoutSubgraph(g, isGroupLayout)); AvoidSubgraphOverlap(layoutSubgraphs); - SaveLayoutGraph(workspace, layoutSubgraphs); + if (isNodeAutoComplete) + { + SaveLayoutGraphForNodeAutoComplete(workspace, layoutSubgraphs, originalNodeGUID); + } + else { + SaveLayoutGraph(workspace, layoutSubgraphs); + } // Restore the workspace model selection information selection.ToList().ForEach(x => x.Select()); @@ -426,6 +432,52 @@ private static void SaveLayoutGraph(this WorkspaceModel workspace, List + /// This method pushes changes from the GraphLayout.Graph objects + /// back to the workspace models. + /// + private static void SaveLayoutGraphForNodeAutoComplete(this WorkspaceModel workspace, List layoutSubgraphs, Guid? originalNodeGUID) + { + var originalNode = workspace.Nodes.FirstOrDefault(n => n.GUID == originalNodeGUID); + GraphLayout.Graph originalNodegraph = layoutSubgraphs + .FirstOrDefault(g => g.FindNode(originalNode.GUID) != null); + GraphLayout.Node ogn = originalNodegraph.FindNode(originalNode.GUID); + double marginX = originalNode.X - ogn.X; + double marginY = originalNode.Y - ogn.Y; + + // Assign coordinates to nodes outside groups + foreach (var node in workspace.Nodes) + { + GraphLayout.Graph graph = layoutSubgraphs + .FirstOrDefault(g => g.FindNode(node.GUID) != null); + + if (graph != null) + { + GraphLayout.Node n = graph.FindNode(node.GUID); + double offsetY = graph.OffsetY; + if (node.GUID != originalNodeGUID ) + { + node.X = n.X; + node.Y = n.Y + n.NotesHeight + offsetY; + + } + node.ReportPosition(); + workspace.HasUnsavedChanges = true; + double noteOffset = -n.NotesHeight; foreach (NoteModel note in n.LinkedNotes) { diff --git a/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs b/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs index f12e86d637f..0b503ce9a08 100644 --- a/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs @@ -286,11 +286,12 @@ protected virtual void CreateAndConnectToPort(object parameter) dynamoViewModel.ExecuteCommand(new DynamoModel.CreateAndConnectNodeCommand(id, initialNode.GUID, Model.CreationName, 0, portModel.Index, adjustedX, 0, createAsDownStreamNode, false, true)); - // Clear current selections and select all input nodes as we need to perform Auto layout on only the input nodes. - DynamoSelection.Instance.ClearSelection(); var inputNodes = initialNode.InputNodes.Values.Where(x => x != null).Select(y => y.Item2); + // Clear current selections and select all input nodes as we need to perform Auto layout on only the input nodes. + DynamoSelection.Instance.ClearSelection(); DynamoSelection.Instance.Selection.AddRange(inputNodes); + DynamoSelection.Instance.Selection.Add(initialNode); } protected virtual bool CanCreateAndConnectToPort(object parameter) @@ -305,8 +306,9 @@ private void AutoLayoutNodes(object sender, EventArgs e) { var nodeView = (NodeView) sender; var dynamoViewModel = nodeView.ViewModel.DynamoViewModel; + var originalNodeId = nodeView.ViewModel.NodeModel.OutputNodes.Values.SelectMany(s => s.Select(t => t.Item2)).Distinct().FirstOrDefault().GUID; - dynamoViewModel.CurrentSpace.DoGraphAutoLayout(true); + dynamoViewModel.CurrentSpace.DoGraphAutoLayout(true, true, originalNodeId); DynamoSelection.Instance.ClearSelection(); From 98e9eea44f12351f2441a00dcb73c920f4e87adb Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Wed, 20 Jan 2021 20:24:57 +0530 Subject: [PATCH 2/2] comments --- src/DynamoCore/Graph/Workspaces/LayoutExtensions.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/DynamoCore/Graph/Workspaces/LayoutExtensions.cs b/src/DynamoCore/Graph/Workspaces/LayoutExtensions.cs index b01b050f999..cf472b7718e 100644 --- a/src/DynamoCore/Graph/Workspaces/LayoutExtensions.cs +++ b/src/DynamoCore/Graph/Workspaces/LayoutExtensions.cs @@ -50,6 +50,7 @@ public static class LayoutExtensions // Run layout algorithm for each subgraph layoutSubgraphs.Skip(1).ToList().ForEach(g => RunLayoutSubgraph(g, isGroupLayout)); AvoidSubgraphOverlap(layoutSubgraphs); + if (isNodeAutoComplete) { SaveLayoutGraphForNodeAutoComplete(workspace, layoutSubgraphs, originalNodeGUID); @@ -448,17 +449,10 @@ private static void SaveLayoutGraph(this WorkspaceModel workspace, List /// This method pushes changes from the GraphLayout.Graph objects - /// back to the workspace models. + /// back to the workspace models, but only for nodes placed by NodeAutocomplete. /// private static void SaveLayoutGraphForNodeAutoComplete(this WorkspaceModel workspace, List layoutSubgraphs, Guid? originalNodeGUID) { - var originalNode = workspace.Nodes.FirstOrDefault(n => n.GUID == originalNodeGUID); - GraphLayout.Graph originalNodegraph = layoutSubgraphs - .FirstOrDefault(g => g.FindNode(originalNode.GUID) != null); - GraphLayout.Node ogn = originalNodegraph.FindNode(originalNode.GUID); - double marginX = originalNode.X - ogn.X; - double marginY = originalNode.Y - ogn.Y; - // Assign coordinates to nodes outside groups foreach (var node in workspace.Nodes) { @@ -469,6 +463,7 @@ private static void SaveLayoutGraphForNodeAutoComplete(this WorkspaceModel works { GraphLayout.Node n = graph.FindNode(node.GUID); double offsetY = graph.OffsetY; + //skipping the original node to avoid jumping of node if (node.GUID != originalNodeGUID ) { node.X = n.X;