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
45 changes: 39 additions & 6 deletions src/DynamoCore/Graph/ModelBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel;
using System.Xml;
using Dynamo.Core;
Expand Down Expand Up @@ -71,13 +71,18 @@ public abstract class ModelBase : NotificationObject, ISelectable, ILocatable, I
/// </summary>
public event EventHandler<CancelEventArgs> DeletionStarted;

internal static readonly double DefaultHeight = 100;
internal static readonly double DefaultWidth = 100;

private Guid guid;
private bool isSelected;
private bool belongsToGroup;
private double x;
private double y;
private double height = 100;
private double width = 100;
private double height = DefaultHeight;
private double width = DefaultWidth;
private double heightBorder = DefaultHeight;
private double widthBorder = DefaultWidth;

/// <summary>
/// X coordinate of center point.
Expand Down Expand Up @@ -164,7 +169,6 @@ public Point2D Position
/// <summary>
/// The height of the object.
/// </summary>
[JsonIgnore]
public virtual double Height
{
get { return height; }
Expand All @@ -178,7 +182,6 @@ public virtual double Height
/// <summary>
/// The width of the object.
/// </summary>
[JsonIgnore]
public virtual double Width
{
get { return width; }
Expand All @@ -189,6 +192,36 @@ public virtual double Width
}
}

/// <summary>Add commentMore actions
/// The width of the object.
/// </summary>
public virtual double WidthBorder
{
get { return widthBorder; }
set
{
if (value > 0)
{
widthBorder = value;
}
}
}

/// <summary>
/// The height of the object.
/// </summary>
public virtual double HeightBorder
{
get { return heightBorder; }
set
{
if (value > 0)
{
heightBorder = value;
}
}
}

/// <summary>
/// The bounds of the object.
/// </summary>
Expand Down Expand Up @@ -486,4 +519,4 @@ public interface ILocatable
/// </summary>
void ReportPosition();
}
}
}
8 changes: 8 additions & 0 deletions src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public class ExtraNodeViewInfo
public string Name;
public double X;
public double Y;
public double Width = ModelBase.DefaultWidth;
public double Height = ModelBase.DefaultWidth;
public double WidthBorder;
public double HeightBorder;
public bool ShowGeometry;
public bool Excluded;
public bool IsSetAsInput;
Expand Down Expand Up @@ -2495,6 +2499,10 @@ private void LoadNodes(IEnumerable<ExtraNodeViewInfo> nodeViews, double offsetX
nodeModel.X = nodeViewInfo.X + offsetX;
nodeModel.Y = nodeViewInfo.Y + offsetY;
}
nodeModel.Width = nodeViewInfo.Width;
nodeModel.Height = nodeViewInfo.Height;
nodeModel.WidthBorder = nodeViewInfo.WidthBorder;
nodeModel.HeightBorder = nodeViewInfo.HeightBorder;
nodeModel.IsFrozen = nodeViewInfo.Excluded;
nodeModel.IsSetAsInput = nodeViewInfo.IsSetAsInput;
nodeModel.IsSetAsOutput = nodeViewInfo.IsSetAsOutput;
Expand Down
8 changes: 8 additions & 0 deletions src/DynamoCore/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,10 @@ Dynamo.Graph.Workspaces.ExtraNodeViewInfo.ShowGeometry -> bool
Dynamo.Graph.Workspaces.ExtraNodeViewInfo.UserDescription -> string
Dynamo.Graph.Workspaces.ExtraNodeViewInfo.X -> double
Dynamo.Graph.Workspaces.ExtraNodeViewInfo.Y -> double
Dynamo.Graph.Workspaces.ExtraNodeViewInfo.Width -> double
Dynamo.Graph.Workspaces.ExtraNodeViewInfo.Height -> double
Dynamo.Graph.Workspaces.ExtraNodeViewInfo.WidthBorder -> double
Dynamo.Graph.Workspaces.ExtraNodeViewInfo.HeightBorder -> double
Dynamo.Graph.Workspaces.ExtraNoteViewInfo
Dynamo.Graph.Workspaces.ExtraNoteViewInfo.ExtraNoteViewInfo() -> void
Dynamo.Graph.Workspaces.ExtraNoteViewInfo.Id -> string
Expand Down Expand Up @@ -3060,6 +3064,10 @@ virtual Dynamo.Graph.ModelBase.ShouldSerializeY() -> bool
virtual Dynamo.Graph.ModelBase.UpdateValueCore(Dynamo.Graph.UpdateValueParams updateValueParams) -> bool
virtual Dynamo.Graph.ModelBase.Width.get -> double
virtual Dynamo.Graph.ModelBase.Width.set -> void
virtual Dynamo.Graph.ModelBase.WidthBorder.get -> double
virtual Dynamo.Graph.ModelBase.WidthBorder.set -> void
virtual Dynamo.Graph.ModelBase.HeightBorder.get -> double
virtual Dynamo.Graph.ModelBase.HeightBorder.set -> void
virtual Dynamo.Graph.Nodes.FunctionCallNodeController<T>.AssignIdentifiersForFunctionCall(Dynamo.Graph.Nodes.NodeModel model, ProtoCore.AST.AssociativeAST.AssociativeNode rhs, System.Collections.Generic.List<ProtoCore.AST.AssociativeAST.AssociativeNode> resultAst) -> void
virtual Dynamo.Graph.Nodes.FunctionCallNodeController<T>.BuildAstForPartialMultiOutput(Dynamo.Graph.Nodes.NodeModel model, ProtoCore.AST.AssociativeAST.AssociativeNode rhs, System.Collections.Generic.List<ProtoCore.AST.AssociativeAST.AssociativeNode> resultAst) -> void
virtual Dynamo.Graph.Nodes.FunctionCallNodeController<T>.BuildOutputAst(Dynamo.Graph.Nodes.NodeModel model, System.Collections.Generic.List<ProtoCore.AST.AssociativeAST.AssociativeNode> inputAstNodes, System.Collections.Generic.List<ProtoCore.AST.AssociativeAST.AssociativeNode> resultAst) -> void
Expand Down
8 changes: 8 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,14 @@ Dynamo.ViewModels.NodeViewModel.X.get -> double
Dynamo.ViewModels.NodeViewModel.X.set -> void
Dynamo.ViewModels.NodeViewModel.Y.get -> double
Dynamo.ViewModels.NodeViewModel.Y.set -> void
Dynamo.ViewModels.NodeViewModel.Width.get -> double
Dynamo.ViewModels.NodeViewModel.Width.set -> void
Dynamo.ViewModels.NodeViewModel.Height.get -> double
Dynamo.ViewModels.NodeViewModel.Height.set -> void
Dynamo.ViewModels.NodeViewModel.WidthBorder.get -> double
Dynamo.ViewModels.NodeViewModel.WidthBorder.set -> void
Dynamo.ViewModels.NodeViewModel.HeightBorder.get -> double
Dynamo.ViewModels.NodeViewModel.HeightBorder.set -> void
Dynamo.ViewModels.NodeViewModel.ZIndex.get -> int
Dynamo.ViewModels.NodeViewModel.ZIndex.set -> void
Dynamo.ViewModels.NoteEventArgs
Expand Down
51 changes: 51 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/NodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,57 @@ public double Y
}
}

/// <summary>
/// Returns or set the Width of the NodeView.
/// </summary>
[JsonProperty(Order = 9)]
public double Width
{
get { return NodeModel.Width; }
set
{
NodeModel.Width = value;
}
}

/// <summary>
/// Returns or set the Height of the NodeView.
/// </summary>
[JsonProperty(Order = 10)]
public double Height
{
get { return NodeModel.Height; }
set
{
NodeModel.Height = value;
}
}
/// <summary>
/// Returns or set the Width of the Node's border that is added inside the NodeView.
/// </summary>
[JsonProperty(Order = 11)]
public double WidthBorder
{
get { return NodeModel.WidthBorder; }
set
{
NodeModel.WidthBorder = value;
}
}

/// <summary>
/// Returns or set the Height of the Node's border that is added inside the NodeView.
/// </summary>
[JsonProperty(Order = 12)]
public double HeightBorder
{
get { return NodeModel.HeightBorder; }
set
{
NodeModel.HeightBorder = value;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this extra dimension for borders? Can't we calculate borders based on node height and width? How and when are these 2 different?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current nodeBorder is a WPF Border element added from row=1 to 5, column = 0 to 3 (NodeView has in total 6 rows and 3 columns) so based in that usually WPF Grids starts from row=0 you will notice by seeing the image below that the NodeView.Width, NodeView.Height (in green color) will not match NodeBorder.Width and NodeBorder.Height (the red rectangle), remember the nodeBorder is auto-calculated based in the content of row 1 to 5 and column 0 to 3.
Then when I was trying to reduce the calls to Measure() and Arrange() noticed that setting The NodeView size and setting the NodeBorder size reduced the total calls from 7 to 1 (due that probably when WPF is rendering the nodeBorder is increasing size several times due to the controls added in those specific rows, columns, so setting the size will avoid the extra calls to Measure).

image

One possible solution for not serializing the NodeBorder size could be setting the NodeBorder localtion from row 0 to 5 and column 0 to 3 but we will need to do several changes in NodeView.xaml (now that everything is in code behind in NodeView.xaml.cs) like Collapsing the customNodeBorders (instead of hiding them like currently is happening) and we will need to do testing in several nodes and custom nodes.

[JsonIgnore]
public ImageSource ImageSource
{
Expand Down
38 changes: 31 additions & 7 deletions src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,8 @@ public NodeView()
Unloaded += OnNodeViewUnloaded;
nodeBackground.Loaded += NodeViewReady;

nodeBorder.SizeChanged += OnSizeChanged;
nodeBorder.SizeChanged += OnSizeChangedBorder;
this.SizeChanged += OnSizeChangedNodeView;
DataContextChanged += OnDataContextChanged;

Panel.SetZIndex(this, 1);
Expand Down Expand Up @@ -1555,7 +1556,8 @@ private void OnNodeViewUnloaded(object sender, RoutedEventArgs e)
EditableNameBox.LostFocus -= EditableNameBox_OnLostFocus;
EditableNameBox.KeyDown -= EditableNameBox_KeyDown;
optionsButton.Click -= DisplayNodeContextMenu;
nodeBorder.SizeChanged -= OnSizeChanged;
nodeBorder.SizeChanged -= OnSizeChangedBorder;
this.SizeChanged -= OnSizeChangedNodeView;
nodeBackground.Loaded -= NodeViewReady;

if (previewControl != null)
Expand All @@ -1577,13 +1579,20 @@ private void OnNodeViewUnloaded(object sender, RoutedEventArgs e)
/// </summary>
/// <param name="sender"></param>
/// <param name="eventArgs"></param>
private void OnSizeChanged(object sender, EventArgs eventArgs)
private void OnSizeChangedBorder(object sender, SizeChangedEventArgs e)
{
if (ViewModel == null || ViewModel.PreferredSize.HasValue) return;
if (ViewModel != null)
{
ViewModel.WidthBorder = e.NewSize.Width;
ViewModel.HeightBorder = e.NewSize.Height;
}
}

var size = new[] { ActualWidth, nodeBorder.ActualHeight };
if (ViewModel.SetModelSizeCommand.CanExecute(size))
private void OnSizeChangedNodeView(object sender, SizeChangedEventArgs e)
{
if (ViewModel != null)
{
var size = new[] { e.NewSize.Width, e.NewSize.Height };
ViewModel.SetModelSizeCommand.Execute(size);
}
}
Expand All @@ -1610,6 +1619,21 @@ private void OnDataContextChanged(object sender, DependencyPropertyChangedEventA

ViewModel = e.NewValue as NodeViewModel;

//This code should be only executed when loading a graph, if the node is being added to the workspace manually then the Width and Height should be auto-calculated.
//The default Width and Height values for nodes is 100 so only should be executed on graph loading if both values are 100
if (ViewModel.Width > NodeModel.DefaultWidth && ViewModel.Height > NodeModel.DefaultHeight)
{
Width = ViewModel.Width;
Height = ViewModel.Height;
}

if (ViewModel.WidthBorder > NodeModel.DefaultWidth && ViewModel.HeightBorder > NodeModel.DefaultHeight)
{
nodeBorder.Width = ViewModel.WidthBorder;
nodeBorder.Height = ViewModel.HeightBorder;
}


//Set NodeIcon
if (ViewModel.ImageSource == null)
{
Expand Down Expand Up @@ -1645,7 +1669,7 @@ private void OnDataContextChanged(object sender, DependencyPropertyChangedEventA
nodeBorder.Height = size.Height;
nodeBorder.RenderSize = size;
}

private void SetCustomNodeVisuals()
{
customNodeBorder0 = new Border()
Expand Down
9 changes: 7 additions & 2 deletions test/DynamoCoreWpf3Tests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public void NodeViewSerializationPropertiesTest()
var workSpaceJobject = JObject.Parse(ViewModel.CurrentSpaceViewModel.ToJson());
JObject nodeViewModelJobject = JObject.Parse(workSpaceJobject["NodeViews"][0].ToString());

Assert.AreEqual(8, nodeViewModelJobject.Properties().Count(), "The number of Serialized properties is not the expected");
Assert.AreEqual(12, nodeViewModelJobject.Properties().Count(), "The number of Serialized properties is not the expected");

bool explicitOrder =
nodeViewModelJobject.Properties().ElementAt(0).Name == GetJsonPropertydName<NodeViewModel>(nameof(NodeViewModel.Id)) &&
Expand All @@ -422,7 +422,12 @@ public void NodeViewSerializationPropertiesTest()
nodeViewModelJobject.Properties().ElementAt(4).Name == GetJsonPropertydName<NodeViewModel>(nameof(NodeViewModel.IsFrozenExplicitly)) &&
nodeViewModelJobject.Properties().ElementAt(5).Name == GetJsonPropertydName<NodeViewModel>(nameof(NodeViewModel.IsVisible)) &&
nodeViewModelJobject.Properties().ElementAt(6).Name == GetJsonPropertydName<NodeViewModel>(nameof(NodeViewModel.X)) &&
nodeViewModelJobject.Properties().ElementAt(7).Name == GetJsonPropertydName<NodeViewModel>(nameof(NodeViewModel.Y));
nodeViewModelJobject.Properties().ElementAt(7).Name == GetJsonPropertydName<NodeViewModel>(nameof(NodeViewModel.Y)) &&
nodeViewModelJobject.Properties().ElementAt(8).Name == GetJsonPropertydName<NodeViewModel>(nameof(NodeViewModel.Width)) &&
nodeViewModelJobject.Properties().ElementAt(9).Name == GetJsonPropertydName<NodeViewModel>(nameof(NodeViewModel.Height)) &&
nodeViewModelJobject.Properties().ElementAt(10).Name == GetJsonPropertydName<NodeViewModel>(nameof(NodeViewModel.WidthBorder)) &&
nodeViewModelJobject.Properties().ElementAt(11).Name == GetJsonPropertydName<NodeViewModel>(nameof(NodeViewModel.HeightBorder));


Assert.IsTrue(explicitOrder, "The order of the properties is not the expected");
}
Expand Down
38 changes: 27 additions & 11 deletions test/core/dummy_node/2080_JSONTESTCRASH undo_redo.dyn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Uuid": "edd9e95c-26a5-4ec2-bd1b-ca2a80bc827b",
"Uuid": "5ddc6800-cca5-493e-8a33-f6450038ca11",
"IsCustomNode": false,
"Description": "",
"Name": "2080_JSONTESTCRASH undo_redo",
Expand All @@ -13,11 +13,11 @@
"ConcreteType": "Dynamo.Graph.Nodes.UNKNOWNTYPE, DynamoCore",
"NodeType": "CodeBlockNode",
"Code": "4;",
"Id": "158f8f25ddb746c88323ae262e87611e",
"Id": "875b287444604b9d976d8d0473692552",
"Inputs": [],
"Outputs": [
{
"Id": "cddfa508b4a246fd94f79792d303cbf5",
"Id": "8079554f4ddf46c49480b1bd4b3d45e4",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
Expand All @@ -31,18 +31,26 @@
},
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"Id": "6cbd0760736f4235a03b38fb359e9957",
"Height": 127.0,
"Width": 154.0,
"WidthBorder": 156.0,
"HeightBorder": 117.0,
"Id": "4371809e0640406a9c99d62e2bba0826",
"NodeType": "CodeBlockNode",
"Inputs": [],
"Outputs": [
{
"Id": "8234ec6cc018433da0605ddfb17cdc2b",
"Id": "2766199ea67e45cb8741617b209eb292",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
"KeepListStructure": false,
"Height": 16.345,
"Width": 100.0,
"WidthBorder": 100.0,
"HeightBorder": 100.0
}
],
"Replication": "Disabled",
Expand All @@ -63,7 +71,7 @@
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.19.0.4737",
"Version": "3.6.0.6885",
"RunType": "Automatic",
"RunPeriod": "1000"
},
Expand All @@ -82,24 +90,32 @@
"ConnectorPins": [],
"NodeViews": [
{
"Id": "158f8f25ddb746c88323ae262e87611e",
"Id": "875b287444604b9d976d8d0473692552",
"Name": "Code Block",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"ShowGeometry": true,
"X": 179.8,
"Y": 160.39999999999992
"Y": 160.39999999999992,
"Width": 154.0,
"Height": 167.0,
"WidthBorder": 156.0,
"HeightBorder": 161.0
},
{
"Id": "6cbd0760736f4235a03b38fb359e9957",
"Id": "4371809e0640406a9c99d62e2bba0826",
"Name": "Code Block",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"ShowGeometry": true,
"X": 76.8,
"Y": 162.4
"Y": 162.4,
"Width": 154.0,
"Height": 127.0,
"WidthBorder": 156.0,
"HeightBorder": 117.0
}
],
"Annotations": [],
Expand Down
Loading