From dc96648ca9ec1dd5e236f96ba526e1cc9b1c2d6c Mon Sep 17 00:00:00 2001 From: t-tellro Date: Thu, 4 Aug 2022 12:54:18 -0500 Subject: [PATCH] DYN-4833-Group-NodesAlignment Before this fix all the alignment calculations were considering all the nodes selected then also was considering the Group (AnnotationModel), so when aligning to Left, Right, X-Distribute, Y-Distribute the Group was being moved some pixels so the right, left or over X-axis and Y-axis. My fix was not considering the Group in the selected items so if we are trying to align all the nodes inside the Group, the group location won't change (just if is necessary in some cases like Left or Right alignment). --- .../ViewModels/Core/WorkspaceViewModel.cs | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs index f7846fa2fd7..d548ba7d110 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs @@ -1007,7 +1007,7 @@ private static bool IsInRegion(Rect2D region, ILocatable locatable, bool fullyEn public double GetSelectionAverageX() { - return DynamoSelection.Instance.Selection.Where((x) => x is ILocatable) + return DynamoSelection.Instance.Selection.Where((x) => !(x is AnnotationModel) && x is ILocatable) .Cast() .Select((x) => x.CenterX) .Average(); @@ -1015,7 +1015,7 @@ public double GetSelectionAverageX() public double GetSelectionAverageY() { - return DynamoSelection.Instance.Selection.Where((x) => x is ILocatable) + return DynamoSelection.Instance.Selection.Where((x) => !(x is AnnotationModel) && x is ILocatable) .Cast() .Select((x) => x.CenterY) .Average(); @@ -1023,7 +1023,7 @@ public double GetSelectionAverageY() public double GetSelectionMinX() { - return DynamoSelection.Instance.Selection.Where((x) => x is ILocatable) + return DynamoSelection.Instance.Selection.Where((x) => !(x is AnnotationModel) && x is ILocatable) .Cast() .Select((x) => x.X) .Min(); @@ -1031,7 +1031,7 @@ public double GetSelectionMinX() public double GetSelectionMinY() { - return DynamoSelection.Instance.Selection.Where((x) => x is ILocatable) + return DynamoSelection.Instance.Selection.Where((x) => !(x is AnnotationModel) && x is ILocatable) .Cast() .Select((x) => x.Y) .Min(); @@ -1039,7 +1039,7 @@ public double GetSelectionMinY() public double GetSelectionMaxX() { - return DynamoSelection.Instance.Selection.Where((x) => x is ILocatable) + return DynamoSelection.Instance.Selection.Where((x) => !(x is AnnotationModel) && x is ILocatable) .Cast() .Select((x) => x.X + x.Width) .Max(); @@ -1047,7 +1047,7 @@ public double GetSelectionMaxX() public double GetSelectionMaxLeftX() { - return DynamoSelection.Instance.Selection.Where((x) => x is ILocatable) + return DynamoSelection.Instance.Selection.Where((x) => !(x is AnnotationModel) && x is ILocatable) .Cast() .Select((x) => x.X) .Max(); @@ -1055,7 +1055,7 @@ public double GetSelectionMaxLeftX() public double GetSelectionMaxY() { - return DynamoSelection.Instance.Selection.Where((x) => x is ILocatable) + return DynamoSelection.Instance.Selection.Where((x) => !(x is AnnotationModel) && x is ILocatable) .Cast() .Select((x) => x.Y + x.Height) .Max(); @@ -1063,7 +1063,7 @@ public double GetSelectionMaxY() public double GetSelectionMaxTopY() { - return DynamoSelection.Instance.Selection.Where((x) => x is ILocatable) + return DynamoSelection.Instance.Selection.Where((x) => !(x is AnnotationModel) && x is ILocatable) .Cast() .Select((x) => x.Y) .Max(); @@ -1081,7 +1081,7 @@ public void AlignSelected(object parameter) IEnumerable models = selection.OfType(); WorkspaceModel.RecordModelsForModification(models.ToList(), Model.UndoRecorder); - var toAlign = DynamoSelection.Instance.Selection.OfType().ToList(); + var toAlign = DynamoSelection.Instance.Selection.OfType().Where(node => !(node is AnnotationModel)).ToList(); switch (alignType) { @@ -1163,7 +1163,8 @@ public void AlignSelected(object parameter) break; case "VerticalDistribute": { - if (DynamoSelection.Instance.Selection.Count <= 2) return; + var nodesSelected = DynamoSelection.Instance.Selection.Where(node => !(node is AnnotationModel) && node is ILocatable); + if (nodesSelected.Count() <= 2) return; var yMin = GetSelectionMinY(); var yMax = GetSelectionMaxY(); @@ -1172,14 +1173,14 @@ public void AlignSelected(object parameter) var span = yMax - yMin; var nodeHeightSum = - DynamoSelection.Instance.Selection.Where(y => y is ILocatable) + nodesSelected.Where(y => y is ILocatable) .Cast() .Sum((y) => y.Height); if (span > nodeHeightSum) { spacing = (span - nodeHeightSum) - /(DynamoSelection.Instance.Selection.Count - 1); + /(nodesSelected.Count() - 1); } var cursor = yMin; @@ -1192,7 +1193,8 @@ public void AlignSelected(object parameter) break; case "HorizontalDistribute": { - if (DynamoSelection.Instance.Selection.Count <= 2) return; + var nodesSelected = DynamoSelection.Instance.Selection.Where(node => !(node is AnnotationModel) && node is ILocatable); + if (nodesSelected.Count() <= 2) return; var xMin = GetSelectionMinX(); var xMax = GetSelectionMaxX(); @@ -1200,7 +1202,7 @@ public void AlignSelected(object parameter) var spacing = 0.0; var span = xMax - xMin; var nodeWidthSum = - DynamoSelection.Instance.Selection.Where((x) => x is ILocatable) + nodesSelected.Where((x) => x is ILocatable) .Cast() .Sum((x) => x.Width); @@ -1211,7 +1213,7 @@ public void AlignSelected(object parameter) if (span > nodeWidthSum) { spacing = (span - nodeWidthSum) - /(DynamoSelection.Instance.Selection.Count - 1); + /(nodesSelected.Count() - 1); } var cursor = xMin;