Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-4833-Group-NodesAlignment #13174

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,63 +1007,63 @@ 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<ILocatable>()
.Select((x) => x.CenterX)
.Average();
}

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<ILocatable>()
.Select((x) => x.CenterY)
.Average();
}

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<ILocatable>()
.Select((x) => x.X)
.Min();
}

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<ILocatable>()
.Select((x) => x.Y)
.Min();
}

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<ILocatable>()
.Select((x) => x.X + x.Width)
.Max();
}

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<ILocatable>()
.Select((x) => x.X)
.Max();
}

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<ILocatable>()
.Select((x) => x.Y + x.Height)
.Max();
}

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<ILocatable>()
.Select((x) => x.Y)
.Max();
Expand All @@ -1081,7 +1081,7 @@ public void AlignSelected(object parameter)
IEnumerable<ModelBase> models = selection.OfType<ModelBase>();
WorkspaceModel.RecordModelsForModification(models.ToList(), Model.UndoRecorder);

var toAlign = DynamoSelection.Instance.Selection.OfType<ILocatable>().ToList();
var toAlign = DynamoSelection.Instance.Selection.OfType<ILocatable>().Where(node => !(node is AnnotationModel)).ToList();

switch (alignType)
{
Expand Down Expand Up @@ -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();
Expand All @@ -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<ILocatable>()
.Sum((y) => y.Height);

if (span > nodeHeightSum)
{
spacing = (span - nodeHeightSum)
/(DynamoSelection.Instance.Selection.Count - 1);
/(nodesSelected.Count() - 1);
}

var cursor = yMin;
Expand All @@ -1192,15 +1193,16 @@ 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();

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<ILocatable>()
.Sum((x) => x.Width);

Expand All @@ -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;
Expand Down