Skip to content
Merged
Show file tree
Hide file tree
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
226 changes: 172 additions & 54 deletions src/DynamoCore/Graph/Annotations/AnnotationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public class AnnotationModel : ModelBase

double lastExpandedWidth = 0;

/// <summary>
/// The default height of the group's content area when collapsed.
/// </summary>
public const double CollapsedContentHeight = 82;

#region Properties

/// <summary>
Expand Down Expand Up @@ -65,16 +70,13 @@ public class AnnotationModel : ModelBase
/// </summary>
public override double Width
{
get
{
return width;
}
get => width;
set
{
if (width == value) return;

width = value;
RaisePropertyChanged("Width");
RaisePropertyChanged(nameof(Width));
}
}

Expand All @@ -85,16 +87,46 @@ public override double Width
/// </summary>
public override double Height
{
get
{
return height;
}
get => height;
set
{
if (height == value) return;

height = value;
RaisePropertyChanged("Height");
RaisePropertyChanged(nameof(Height));
}
}

private double minWidthOnCollapsed;
/// <summary>
/// Gets or sets the minimum width of the group when it is collapsed.
/// This value equals the combined width of the group's proxy input and output ports.
/// </summary>
public double MinWidthOnCollapsed
{
get => minWidthOnCollapsed;
set
{
if (minWidthOnCollapsed == value) return;
minWidthOnCollapsed = value;
}
}

private double minCollapsedPortAreaHeight;
/// <summary>
/// Gets or sets the minimum height of the port area when the group is collapsed.
/// Used to calculate the total height of the collapsed group based on proxy ports
/// </summary>
public double MinCollapsedPortAreaHeight
{
get => minCollapsedPortAreaHeight;
set
{
if (minCollapsedPortAreaHeight != value)
{
minCollapsedPortAreaHeight = value;
RaisePropertyChanged(nameof(MinCollapsedPortAreaHeight));
}
}
}

Expand Down Expand Up @@ -339,7 +371,7 @@ public NodeModel PinnedNode
/// </summary>
public double WidthAdjustment
{
get { return widthAdjustment; }
get => widthAdjustment;
set
{
if (value == widthAdjustment) return;
Expand All @@ -348,6 +380,34 @@ public double WidthAdjustment
}
}

private double widthAdjustmentCollapsed;
/// <summary>
/// Gets or sets the width adjustment applied when the group is collapsed
/// </summary>
public double WidthAdjustmentCollapsed
{
get => widthAdjustmentCollapsed;
set
{
if (value == widthAdjustmentCollapsed) return;
widthAdjustmentCollapsed = value;
}
}

private double widthAdjustmentExpanded;
/// <summary>
/// Gets or sets the width adjustment applied when the group is expanded
/// </summary>
public double WidthAdjustmentExpanded
{
get => widthAdjustmentExpanded;
set
{
if (value == widthAdjustmentExpanded) return;
widthAdjustmentExpanded = value;
}
}

private double heightAdjustment;
/// <summary>
/// Adjustment margin to be added to the height of the
Expand All @@ -356,7 +416,7 @@ public double WidthAdjustment
/// </summary>
public double HeightAdjustment
{
get { return heightAdjustment; }
get => heightAdjustment;
set
{
if (value == heightAdjustment) return;
Expand All @@ -365,17 +425,51 @@ public double HeightAdjustment
}
}

private double heightAdjustmentCollapsed;
/// <summary>
/// Gets or sets the height adjustment applied when the group is collapsed
/// </summary>
public double HeightAdjustmentCollapsed
{
get => heightAdjustmentCollapsed;
set
{
if (value == heightAdjustmentCollapsed) return;
heightAdjustmentCollapsed = value;
}
}

private double heightAdjustmentExpanded;
/// <summary>
/// Gets or sets the height adjustment applied when the group is expanded
/// </summary>
public double HeightAdjustmentExpanded
{
get => heightAdjustmentExpanded;
set
{
if (value == heightAdjustmentExpanded) return;
heightAdjustmentExpanded = value;
}
}

private bool isExpanded = true;
/// <summary>
/// Returns whether or not the group is expanded.
/// </summary>
public bool IsExpanded
{
get { return isExpanded; }
get => isExpanded;
set
{
isExpanded = value;
UpdateBoundaryFromSelection();

// When collapsing, we defer this until after the collapsed layout
// is computed in CollapsedAnnotationRectangle_IsVisibleChanged.
if (isExpanded)
{
UpdateBoundaryFromSelection();
}
UpdateErrorAndWarningIconVisibility();
}
}
Expand Down Expand Up @@ -444,6 +538,21 @@ internal set
}
}

private bool isResizedWhileCollapsed;
/// <summary>
/// Gets or sets a value indicating whether the group was manually resized while collapsed
/// </summary>
public bool IsResizedWhileCollapsed
{
get => isResizedWhileCollapsed;
set
{
if (isResizedWhileCollapsed == value) return;
isResizedWhileCollapsed = value;
RaisePropertyChanged(nameof(IsResizedWhileCollapsed));
}
}

#endregion

/// <summary>
Expand Down Expand Up @@ -577,68 +686,72 @@ internal void UpdateGroupFrozenStatus()
/// Updates the group boundary based on the nodes / notes selection.
/// </summary>
internal void UpdateBoundaryFromSelection()
{
{
var selectedModelsList = nodes.ToList();

if (selectedModelsList.Any())
if (!selectedModelsList.Any())
{
var groupModels = selectedModelsList.OrderBy(x => x.X).ToList();
Width = 0;
Height = 0;
return;
}

//Shifting x by 10 and y to the height of textblock
var regionX = groupModels.Min(x => x.X) - ExtendSize;
//Increase the Y value by 10. This provides the extra space between
// a model and textbox. Otherwise there will be some overlap
var regionY = groupModels.Min(y => (y as NoteModel) == null ? (y.Y) : (y.Y - NoteYAdjustment)) -
ExtendSize - (TextBlockHeight == 0.0 ? MinTextHeight : TextBlockHeight);
var groupModels = selectedModelsList.OrderBy(x => x.X).ToList();

//calculates the distance between the nodes
var xDistance = groupModels.Max(x => (x.X + x.Width)) - regionX;
var yDistance = groupModels.Max(y => (y as NoteModel) == null ? (y.Y + y.Height) : (y.Y + y.Height - NoteYAdjustment)) - regionY;

// InitialTop is to store the Y value without the Textblock height
this.InitialTop = groupModels.Min(y => (y as NoteModel) == null ? (y.Y) : (y.Y - NoteYAdjustment));
//Shifting x by 10 and y to the height of textblock
var regionX = groupModels.Min(x => x.X) - ExtendSize;
//Increase the Y value by 10. This provides the extra space between
// a model and textbox. Otherwise there will be some overlap
var regionY = groupModels.Min(y => (y as NoteModel) == null ? (y.Y) : (y.Y - NoteYAdjustment)) -
ExtendSize - (TextBlockHeight == 0.0 ? MinTextHeight : TextBlockHeight);

//calculates the distance between the nodes
var xDistance = groupModels.Max(x => (x.X + x.Width)) - regionX;

// InitialTop is to store the Y value without the Textblock height
this.InitialTop = groupModels.Min(y => (y as NoteModel) == null ? (y.Y) : (y.Y - NoteYAdjustment));

bool positionChanged = regionX != X || regionY != Y;
this.X = regionX;
this.Y = regionY;

if (IsExpanded)
{
var yDistance = groupModels.Max(y => (y as NoteModel) == null ? (y.Y + y.Height) : (y.Y + y.Height - NoteYAdjustment)) - regionY;

var region = new Rect2D
{
X = regionX,
Y = regionY,
Width = xDistance + ExtendSize + WidthAdjustment,
Width = xDistance + ExtendSize + Math.Max(WidthAdjustment, 0),
Height = yDistance + ExtendSize + ExtendYHeight + HeightAdjustment - TextBlockHeight
};

bool positionChanged = region.X != X || region.Y != Y;

this.X = region.X;
this.Y = region.Y;
this.ModelAreaHeight = IsExpanded ? region.Height : ModelAreaHeight;
this.ModelAreaHeight = region.Height;
Height = this.ModelAreaHeight + TextBlockHeight;

if (IsExpanded)
{
Width = Math.Max(region.Width, TextMaxWidth + ExtendSize);
lastExpandedWidth = Width;
}
else
{
//If the annotation is not expanded, then it will remain the same width of the last time it was expanded
Width = lastExpandedWidth;
}
Width = Math.Max(region.Width, TextMaxWidth + ExtendSize);

//Initial Height is to store the Actual height of the group.
//that is the height should be the initial height without the textblock height.
if (this.InitialHeight <= 0.0)
this.InitialHeight = region.Height;

if (positionChanged)
{
RaisePropertyChanged(nameof(Position));
}
}
else
{
this.Width = 0;
this.Height = 0;
// Width is based on group content when collapsed
Width = Math.Max(
(!IsResizedWhileCollapsed ? xDistance : MinWidthOnCollapsed) + ExtendSize + WidthAdjustment,
TextMaxWidth + ExtendSize
);

ModelAreaHeight = MinCollapsedPortAreaHeight + CollapsedContentHeight + (IsResizedWhileCollapsed ? HeightAdjustment : 0);
Height = TextBlockHeight + ModelAreaHeight;
}

lastExpandedWidth = Width;

if (positionChanged)
{
RaisePropertyChanged(nameof(Position));
}
}

Expand Down Expand Up @@ -733,6 +846,9 @@ protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
case nameof(IsExpanded):
IsExpanded = Convert.ToBoolean(value);
break;
case nameof(IsResizedWhileCollapsed):
IsResizedWhileCollapsed = Convert.ToBoolean(value);
break;
}

return base.UpdateValueCore(updateValueParams);
Expand Down Expand Up @@ -790,6 +906,7 @@ protected override void DeserializeCore(XmlElement element, SaveContext context)
this.InitialHeight = helper.ReadDouble("InitialHeight", DoubleValue);
this.IsSelected = helper.ReadBoolean(nameof(IsSelected), false);
this.IsExpanded = helper.ReadBoolean(nameof(IsExpanded), true);
this.IsResizedWhileCollapsed = helper.ReadBoolean(nameof(IsResizedWhileCollapsed), false);

if (IsSelected)
DynamoSelection.Instance.Selection.Add(this);
Expand Down Expand Up @@ -835,6 +952,7 @@ protected override void DeserializeCore(XmlElement element, SaveContext context)
RaisePropertyChanged(nameof(AnnotationText));
RaisePropertyChanged(nameof(Nodes));
RaisePropertyChanged(nameof(IsExpanded));
RaisePropertyChanged(nameof(IsResizedWhileCollapsed));
this.ReportPosition();
}

Expand Down
10 changes: 10 additions & 0 deletions src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public class ExtraAnnotationViewInfo
public string PinnedNode;
public double WidthAdjustment;
public double HeightAdjustment;
public double WidthAdjustmentCollapsed;
public double HeightAdjustmentCollapsed;
public double WidthAdjustmentExpanded;
public double HeightAdjustmentExpanded;
public bool IsResizedWhileCollapsed;

// TODO, Determine if these are required
public double Left;
Expand Down Expand Up @@ -2703,6 +2708,11 @@ private void LoadAnnotation(ExtraAnnotationViewInfo annotationViewInfo)
annotationModel.GUID = annotationGuidValue;
annotationModel.HeightAdjustment = annotationViewInfo.HeightAdjustment;
annotationModel.WidthAdjustment = annotationViewInfo.WidthAdjustment;
annotationModel.HeightAdjustmentCollapsed = annotationViewInfo.HeightAdjustmentCollapsed;
annotationModel.WidthAdjustmentCollapsed = annotationViewInfo.WidthAdjustmentCollapsed;
annotationModel.HeightAdjustmentExpanded = annotationViewInfo.HeightAdjustmentExpanded;
annotationModel.WidthAdjustmentExpanded = annotationViewInfo.WidthAdjustmentExpanded;
annotationModel.IsResizedWhileCollapsed = annotationViewInfo.IsResizedWhileCollapsed;
annotationModel.UpdateGroupFrozenStatus();

annotationModel.ModelBaseRequested += annotationModel_GetModelBase;
Expand Down
Loading
Loading