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

UI refresh group improvements #12019

Merged
merged 8 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 2 additions & 4 deletions src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
// to distinguish one build from another. AssemblyFileVersion is specified
// in AssemblyVersionInfo.cs so that it can be easily incremented by the
// automated build process.
[assembly: AssemblyVersion("2.13.0.2374")]
[assembly: AssemblyVersion("2.13.0.2443")]


// By default, the "Product version" shown in the file properties window is
Expand All @@ -64,6 +64,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyFileVersion("2.13.0.2374")]

[assembly: AssemblyFileVersion("2.13.0.2443")]
1 change: 1 addition & 0 deletions src/DynamoCore/DynamoCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ limitations under the License.
<Compile Include="Extensions\ExtensionData.cs" />
<Compile Include="Extensions\IExtensionStorageAccess.cs" />
<Compile Include="Extensions\LinterExtensionBase.cs" />
<Compile Include="Graph\Annotations\AnnotationModelExtensions.cs" />
<Compile Include="Graph\Connectors\ConnectorPinModel.cs" />
<Compile Include="Graph\Workspaces\PackageDependencyInfo.cs" />
<Compile Include="Graph\Nodes\NodeOutputData.cs" />
Expand Down
174 changes: 154 additions & 20 deletions src/DynamoCore/Graph/Annotations/AnnotationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ public override double Width
}
set
{
if (width == value) return;

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

private double height;
/// <summary>
/// Returns height of the group
/// Returns the full height of the group.
/// That means ModelAreaHeight + TextBlockHeight
/// </summary>
public override double Height
{
Expand All @@ -83,11 +86,29 @@ public override double Height
}
set
{
if (height == value) return;

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

private double modelAreaHeight;
/// <summary>
/// Returns the height of the area that all
/// model belonging to this group is encapsulated in.
/// </summary>
public double ModelAreaHeight
{
get { return modelAreaHeight; }
set
{
if (modelAreaHeight == value) return;
modelAreaHeight = value;
RaisePropertyChanged(nameof(ModelAreaHeight));
}
}

private string text;

/// <summary>
Expand Down Expand Up @@ -118,6 +139,20 @@ public string AnnotationText

}

private string annotationDescriptionText;
/// <summary>
/// Group description text
/// </summary>
public string AnnotationDescriptionText
{
get => annotationDescriptionText;
set
{
annotationDescriptionText = value;
RaisePropertyChanged(nameof(AnnotationDescriptionText));
}
}

private string background;
/// <summary>
/// Returns background of the group
Expand All @@ -132,7 +167,7 @@ public string Background
}
}

private IEnumerable<ModelBase> nodes;
private HashSet<ModelBase> nodes;
/// <summary>
/// Returns collection of models (nodes and notes) which the group contains
/// </summary>
Expand All @@ -141,15 +176,17 @@ public IEnumerable<ModelBase> Nodes
get { return nodes; }
set
{
nodes = value.ToList(); ;
nodes = value.ToHashSet<ModelBase>();
if (nodes != null && nodes.Any())
{
foreach (var model in nodes)
{
model.PropertyChanged +=model_PropertyChanged;
model.Disposed+=model_Disposed;
model.PropertyChanged += model_PropertyChanged;
model.Disposed += model_Disposed;
}
}
UpdateBoundaryFromSelection();
RaisePropertyChanged(nameof(Nodes));
}
}

Expand Down Expand Up @@ -243,33 +280,102 @@ public NodeModel PinnedNode
}
}

private double widthAdjustment;
/// <summary>
/// Adjustment margin to be added to the width of the
/// group. When set the width of the group will always
/// be set to Width + widthAdjustment
/// </summary>
public double WidthAdjustment
{
get { return widthAdjustment; }
set
{
if (value == widthAdjustment) return;
widthAdjustment = value;
UpdateBoundaryFromSelection();
}
}

private double heightAdjustment;
/// <summary>
/// Adjustment margin to be added to the height of the
/// group. When set the height of the group will always
/// be set to Height + heightAdjustment
/// </summary>
public double HeightAdjustment
{
get { return heightAdjustment; }
set
{
if (value == heightAdjustment) return;
heightAdjustment = value;
UpdateBoundaryFromSelection();
}
}

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

/// <summary>
/// Checks if this group contains any nested groups.
/// </summary>
public bool HasNestedGroups => nodes.OfType<AnnotationModel>().Any();

#endregion

/// <summary>
/// Initializes a new instance of the <see cref="AnnotationModel"/> class.
/// </summary>
/// <param name="nodes">The nodes.</param>
/// <param name="notes">The notes.</param>
public AnnotationModel(IEnumerable<NodeModel> nodes, IEnumerable<NoteModel> notes)
public AnnotationModel(IEnumerable<NodeModel> nodes, IEnumerable<NoteModel> notes) : this(nodes, notes, new List<AnnotationModel>()) { }

/// <summary>
/// Initializes a new instance of the <see cref="AnnotationModel"/> class.
/// </summary>
/// <param name="nodes">The nodes that belongs to this group.</param>
/// <param name="notes">The notes that belongs to this group.</param>
/// <param name="groups">The groups that belongs to this group</param>
public AnnotationModel(IEnumerable<NodeModel> nodes, IEnumerable<NoteModel> notes, IEnumerable<AnnotationModel> groups)
{
var nodeModels = nodes as NodeModel[] ?? nodes.ToArray();
var noteModels = notes as NoteModel[] ?? notes.ToArray();
var groupModels = groups as AnnotationModel[] ?? groups.ToArray();
DeletedModelBases = new List<ModelBase>();
this.Nodes = nodeModels.Concat(noteModels.Cast<ModelBase>()).ToList();
this.Nodes = nodeModels
.Concat(noteModels.Cast<ModelBase>())
.Concat(groupModels.Cast<ModelBase>())
.ToList();

UpdateBoundaryFromSelection();
}


private void model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "Position":
UpdateBoundaryFromSelection();
{
case "Position":
UpdateBoundaryFromSelection();
break;
case "Text":
UpdateBoundaryFromSelection();
break;
break;
case nameof(ModelBase.Height):
case nameof(ModelBase.Width):
UpdateBoundaryFromSelection();
break;
}
}

Expand Down Expand Up @@ -304,7 +410,8 @@ internal void UpdateBoundaryFromSelection()
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.Y) - ExtendSize - (TextBlockHeight == 0.0 ? MinTextHeight : TextBlockHeight);
var regionY = groupModels.Min(y => y.Y) -
ExtendSize - (TextBlockHeight == 0.0 ? MinTextHeight : TextBlockHeight);

//calculates the distance between the nodes
var xDistance = groupModels.Max(x => (x.X + x.Width)) - regionX;
Expand All @@ -318,14 +425,15 @@ internal void UpdateBoundaryFromSelection()
{
X = regionX,
Y = regionY,
Width = xDistance + ExtendSize,
Height = yDistance + ExtendSize + ExtendYHeight
Width = xDistance + ExtendSize + WidthAdjustment,
Height = yDistance + ExtendSize + ExtendYHeight + HeightAdjustment - TextBlockHeight
};

this.X = region.X;
this.Y = region.Y;
this.Width = Math.Max(region.Width, TextMaxWidth + ExtendSize);
this.Height = region.Height;
this.ModelAreaHeight = IsExpanded ? region.Height : ModelAreaHeight;
this.Height = this.ModelAreaHeight + TextBlockHeight;

//Initial Height is to store the Actual height of the group.
//that is the height should be the initial height without the textblock height.
Expand Down Expand Up @@ -362,6 +470,9 @@ protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
case "TextBlockText":
AnnotationText = value;
break;
case nameof(AnnotationDescriptionText):
AnnotationDescriptionText = value;
break;
}

return base.UpdateValueCore(updateValueParams);
Expand All @@ -373,6 +484,7 @@ void SerializeCore(XmlElement element, SaveContext context)
XmlElementHelper helper = new XmlElementHelper(element);
helper.SetAttribute("guid", this.GUID);
helper.SetAttribute("annotationText", this.AnnotationText);
helper.SetAttribute(nameof(AnnotationDescriptionText), this.AnnotationDescriptionText);
helper.SetAttribute("left", this.X);
helper.SetAttribute("top", this.Y);
helper.SetAttribute("width", this.Width);
Expand All @@ -381,7 +493,7 @@ void SerializeCore(XmlElement element, SaveContext context)
helper.SetAttribute("InitialTop", this.InitialTop);
helper.SetAttribute("InitialHeight", this.InitialHeight);
helper.SetAttribute("TextblockHeight", this.TextBlockHeight);
helper.SetAttribute("backgrouund", (this.Background == null ? "" : this.Background.ToString()));
helper.SetAttribute("backgrouund", (this.Background == null ? "" : this.Background.ToString()));
//Serialize Selected models
XmlDocument xmlDoc = element.OwnerDocument;
foreach (var guids in this.Nodes.Select(x => x.GUID))
Expand All @@ -400,7 +512,8 @@ protected override void DeserializeCore(XmlElement element, SaveContext context)
{
XmlElementHelper helper = new XmlElementHelper(element);
this.GUID = helper.ReadGuid("guid", this.GUID);
this.annotationText = helper.ReadString("annotationText", Resources.GroupDefaultText);
this.annotationText = helper.ReadString("annotationText", Resources.GroupNameDefaultText);
this.AnnotationDescriptionText = helper.ReadString(nameof(AnnotationDescriptionText), Resources.GroupDefaultText);
this.X = helper.ReadDouble("left", DoubleValue);
this.Y = helper.ReadDouble("top", DoubleValue);
this.width = helper.ReadDouble("width", DoubleValue);
Expand Down Expand Up @@ -450,10 +563,13 @@ protected override void DeserializeCore(XmlElement element, SaveContext context)
/// <param name="checkOverlap"> checkoverlap determines whether the selected model is
/// completely inside that group</param>
internal void AddToSelectedModels(ModelBase model, bool checkOverlap = false)
{
{
//if (model.BelongsToGroup) return;

var list = this.Nodes.ToList();
if (model.GUID == this.GUID) return;
if (list.Where(x => x.GUID == model.GUID).Any()) return;
if (!CheckModelIsInsideGroup(model, checkOverlap)) return;
if (!CheckModelIsInsideGroup(model, checkOverlap)) return;
list.Add(model);
this.Nodes = list;
this.UpdateBoundaryFromSelection();
Expand Down Expand Up @@ -481,6 +597,11 @@ public override void Select()
{
foreach (var models in Nodes)
{
if (models is AnnotationModel annotationModel)
{
annotationModel.Select();
continue;
}
models.IsSelected = true;
}

Expand All @@ -502,6 +623,19 @@ public override void Deselect()
base.Deselect();
}

/// <summary>
/// Checks if the provided modelbase belongs
/// to this group.
/// </summary>
/// <param name="modelBase">modelbase to check if belongs to this group</param>
/// <returns></returns>
public bool ContainsModel(ModelBase modelBase)
{
if (modelBase is null) return false;

return nodes.Contains(modelBase);
}

/// <summary>
/// Implementation of Dispose method
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions src/DynamoCore/Graph/Annotations/AnnotationModelExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dynamo.Graph.Annotations
{
internal static class AnnotationModelExtensions
{
/// <summary>
/// Checks if any of the provided groups contains the provided
/// ModelBase.
/// </summary>
/// <param name="groups"></param>
/// <param name="modelBase"></param>
/// <returns></returns>
internal static bool ContainsModel(this IEnumerable<AnnotationModel> groups, ModelBase modelBase)
{
return groups.Any(g => g.ContainsModel(modelBase));
}
}
}
1 change: 1 addition & 0 deletions src/DynamoCore/Graph/ModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public abstract class ModelBase : NotificationObject, ISelectable, ILocatable, I

private Guid guid;
private bool isSelected;
private bool belongsToGroup;
private double x;
private double y;
private double height = 100;
Expand Down
Loading