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

Update master #7

Merged
merged 5 commits into from
Jul 10, 2020
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
57 changes: 6 additions & 51 deletions src/DynamoCore/Graph/Annotations/AnnotationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,58 +290,26 @@ internal void UpdateBoundaryFromSelection()
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) - regionX;
var yDistance = groupModels.Max(x => x.Y) - regionY;

var widthandheight = CalculateWidthAndHeight();

var maxWidth = widthandheight.Item1;
var maxHeight = widthandheight.Item2;
var xDistance = groupModels.Max(x => (x.X + x.Width)) - regionX;
var yDistance = groupModels.Max(x => (x.Y + x.Height)) - regionY;

// InitialTop is to store the Y value without the Textblock height
this.InitialTop = groupModels.Min(y => y.Y);


var region = new Rect2D
{
X = regionX,
Y = regionY,
Width = xDistance + maxWidth + ExtendSize,
Height = yDistance + maxHeight + ExtendSize
Width = xDistance + ExtendSize,
Height = yDistance + ExtendSize + ExtendYHeight
};

this.X = region.X;
this.Y = region.Y;
this.Width = Math.Max(region.Width, TextMaxWidth + ExtendSize);
this.Height = region.Height;

//Calculate the boundary if there is any overlap
ModelBase overlap = null;
foreach (var nodesList in Nodes)
{
if (!region.Contains(nodesList.Rect))
{
overlap = nodesList;
if (overlap.Rect.Top < this.X ||
overlap.Rect.Bottom > region.Bottom) //Overlap in height - increase the region height
{
if (overlap.Rect.Bottom - region.Bottom > 0)
{
this.Height += overlap.Rect.Bottom - region.Bottom + ExtendSize + ExtendYHeight;
}
region.Height = this.Height;
}
if (overlap.Rect.Left < this.Y ||
overlap.Rect.Right > region.Right) //Overlap in width - increase the region width
{
if (overlap.Rect.Right - region.Right > 0)
{
this.Width += overlap.Rect.Right - region.Right + ExtendSize;
}
region.Width = this.Width;
}
}
}

//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)
Expand All @@ -358,20 +326,7 @@ internal void UpdateBoundaryFromSelection()
/// Group the Models based on Height and Width
/// </summary>
/// <returns> the width and height of the last model </returns>
private Tuple<Double,Double> CalculateWidthAndHeight()
{
var xgroup = Nodes.OrderBy(x => x.X).ToList();
var ygroup = Nodes.OrderBy(x => x.Y).ToList();
double yheight = ygroup.Last().Height;

//If the last model is Node, then increase the height so that
//node border does not overlap with the group
if (ygroup.Last() is NodeModel)
yheight = yheight + ExtendYHeight;

return Tuple.Create(xgroup.Last().Width, yheight);
}

#region Serialization/Deserialization Methods

protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
Expand Down
5 changes: 3 additions & 2 deletions src/Libraries/DSCPython/Encoders/ListEncodeDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ internal class ListEncoderDecoder : IPyObjectEncoder, IPyObjectDecoder
private static readonly Type[] decodableTypes = new Type[]
{
typeof(IList), typeof(ArrayList),
typeof(IList<>), typeof(List<>)
typeof(IList<>), typeof(List<>),
typeof(IEnumerable), typeof(IEnumerable<>)
};

public bool CanDecode(PyObject objectType, Type targetType)
Expand All @@ -30,7 +31,7 @@ public bool CanEncode(Type type)

public bool TryDecode<T>(PyObject pyObj, out T value)
{
if (!PySequence.IsSequenceType(pyObj))
if (!PyIter.IsIterable(pyObj))
{
value = default;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,7 @@ public void Initialize(string dynamoCorePath)
}

// If IronPython.Std folder is excluded from DynamoCore (which could be user mistake or integrator exclusion)
// Or if the execution path is different than Dynamo root folder
if (!Directory.Exists(pythonLibDir) || pythonLibDir != executionPath)
if (!Directory.Exists(pythonLibDir))
{
// Try to load IronPython from extension package
pythonLibDir = Path.Combine((new DirectoryInfo(Path.GetDirectoryName(executionPath))).Parent.FullName, IronPythonEvaluator.packageExtraFolderName, IronPythonEvaluator.PythonLibName);
Expand Down
1 change: 0 additions & 1 deletion src/Libraries/DSIronPython/IronPythonEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ private static string PythonStandardLibPath()
pythonLibDir = Path.Combine(Path.GetDirectoryName(executionPath), PythonLibName);

// If IronPython.Std folder is excluded from DynamoCore (which could be user mistake or integrator exclusion)
// Or if the execution path is different than Dynamo root folder
if (!Directory.Exists(pythonLibDir))
{
// Try to load IronPython from extension package
Expand Down
3 changes: 3 additions & 0 deletions test/DynamoCoreTests/DynamoCoreTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@
<Compile Include="Extensions\ExtensionLoaderTest.cs" />
<Compile Include="Extensions\ExtensionManagerTest.cs" />
<Compile Include="Graph\Connectors\ConnectorModelTests.cs" />
<Compile Include="Graph\Nodes\NodeAttributesTests.cs" />
<Compile Include="Graph\Nodes\NodeModelTests.cs" />
<Compile Include="Graph\Workspaces\CustomNodeWorkspaceModelTests.cs" />
<Compile Include="Graph\Workspaces\HomeWorkspaceModelTests.cs" />
<Compile Include="HomgeneousListTests.cs" />
<Compile Include="AtLevelTest.cs" />
<Compile Include="AttributeTest.cs" />
Expand Down
151 changes: 151 additions & 0 deletions test/DynamoCoreTests/Graph/Nodes/NodeAttributesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using System;
using System.Linq;
using CoreNodeModels.Properties;
using Dynamo.Graph.Nodes;
using NUnit.Framework;

namespace Dynamo.Tests
{
/// <summary>
/// This file contains tests for the classes in the Attributes file.
/// </summary>
[TestFixture]
class NodeAttributesTests
{
[Test]
[Category("UnitTests")]
public void NodeSearchTagsAttributeConstructorTest()
{
//resourceType is null
string tagsID = "tagsID";
Type resourceType = null;

Assert.Throws<ArgumentNullException>(() => _ = new NodeSearchTagsAttribute(tagsID, resourceType));
}

[Test]
[Category("UnitTests")]
public void NodeDescriptionAttributeConstructorTest()
{
//resourceType is null
Assert.Throws<ArgumentNullException>(() => _ = new NodeDescriptionAttribute("", null));

//resourceType is valid
string descriptionResourceID = "WatchNodeDescription";
Type resourceType = typeof(Resources);

var attr = new NodeDescriptionAttribute(descriptionResourceID, resourceType);
Assert.AreEqual(Resources.WatchNodeDescription, attr.ElementDescription);

//resourceType is valid but descriptionResourceID is not
descriptionResourceID = "Nil";
resourceType = typeof(Resources);

attr = new NodeDescriptionAttribute(descriptionResourceID, resourceType);
Assert.AreEqual(descriptionResourceID, attr.ElementDescription);
}

[Test]
[Category("UnitTests")]
public void DoNotLoadOnPlatformsAttributeConstructorTest()
{
//values is null
var attr = new DoNotLoadOnPlatformsAttribute(null);
Assert.AreEqual(null, attr.Values);

//values is valid
attr = new DoNotLoadOnPlatformsAttribute(new string[] { "" });
Assert.AreEqual(1, attr.Values.Length);
}

[Test]
[Category("UnitTests")]
public void NodeObsoleteAttributeConstructorTest()
{
//base with message
var attr = new NodeObsoleteAttribute("Message");
Assert.AreEqual("Message", attr.Message);

//resourceType is null
Assert.Throws<ArgumentNullException>(() => _ = new NodeObsoleteAttribute("", null));

//resourceType is valid
string descriptionResourceID = "WatchNodeDescription";
Type resourceType = typeof(Resources);

attr = new NodeObsoleteAttribute(descriptionResourceID, resourceType);
Assert.AreEqual(Resources.WatchNodeDescription, attr.Message);

//resourceType is valid but descriptionResourceID is not
descriptionResourceID = "Nil";
resourceType = typeof(Resources);

attr = new NodeObsoleteAttribute(descriptionResourceID, resourceType);
Assert.AreEqual(descriptionResourceID, attr.Message);
}

[Test]
[Category("UnitTests")]
public void InPortNamesAttributeConstructorTest()
{
//resourceType is null
var attr = new InPortNamesAttribute(null, new string[] { "" });
Assert.AreEqual(0, attr.PortNames.Count());

//resourceType is valid
string[] resourceNames = { "WatchNodeDescription" };
Type resourceType = typeof(Resources);

attr = new InPortNamesAttribute(resourceType, resourceNames);
Assert.AreEqual(1, attr.PortNames.Count());
}

[Test]
[Category("UnitTests")]
public void InPortTypesAttributeConstructorTest()
{
//resourceType is null
var attr = new InPortTypesAttribute(null, new string[] { "" });
Assert.AreEqual(0, attr.PortTypes.Count());

//resourceType is valid
string[] resourceNames = { "WatchNodeDescription" };
Type resourceType = typeof(Resources);

attr = new InPortTypesAttribute(resourceType, resourceNames);
Assert.AreEqual(1, attr.PortTypes.Count());
}

[Test]
[Category("UnitTests")]
public void OutPortNamesAttributeConstructorTest()
{
//resourceType is null
var attr = new OutPortNamesAttribute(null, new string[] { "" });
Assert.AreEqual(0, attr.PortNames.Count());

//resourceType is valid
string[] resourceNames = { "WatchNodeDescription" };
Type resourceType = typeof(Resources);

attr = new OutPortNamesAttribute(resourceType, resourceNames);
Assert.AreEqual(1, attr.PortNames.Count());
}

[Test]
[Category("UnitTests")]
public void OutPortTypesAttributeConstructorTest()
{
//resourceType is null
var attr = new OutPortTypesAttribute(null, new string[] { "" });
Assert.AreEqual(0, attr.PortTypes.Count());

//resourceType is valid
string[] resourceNames = { "WatchNodeDescription" };
Type resourceType = typeof(Resources);

attr = new OutPortTypesAttribute(resourceType, resourceNames);
Assert.AreEqual(1, attr.PortTypes.Count());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.IO;
using System.Linq;
using Dynamo.Graph.Workspaces;
using NUnit.Framework;

namespace Dynamo.Tests
{
/// <summary>
/// Class containing tests for the CustomNodeWorkspaceModel class
/// </summary>
[TestFixture]
class CustomNodeWorkspaceModelTests : DynamoModelTestBase
{
public void OpenTestFile(string folder, string fileName)
{
var examplePath = Path.Combine(TestDirectory, folder, fileName);
OpenModel(examplePath);
}

[Test]
[Category("UnitTests")]
public void OnPropertyNameChangedTest()
{
OpenTestFile(@"core\CustomNodes", "add_Read_only.dyf");
var nodeWorkspace = CurrentDynamoModel.Workspaces.FirstOrDefault(x => x is CustomNodeWorkspaceModel);
Assert.IsNotNull(nodeWorkspace);

OpenTestFile(@"core\CustomNodes", "TestAdd.dyn");
var homeWorkspace = CurrentDynamoModel.CurrentWorkspace as HomeWorkspaceModel;
Assert.NotNull(homeWorkspace);

//Changes the Name property so that the event is raised
nodeWorkspace.Name = "NewNodeName";

var resultNode = homeWorkspace.Nodes.FirstOrDefault(x => x.Name == "NewNodeName");
Assert.IsNotNull(resultNode);
}

[Test]
[Category("UnitTests")]
public void GetSharedNameTest()
{
var fileName = "add_Read_only";
OpenTestFile(@"core\CustomNodes", fileName+".dyf");
var nodeWorkspace = CurrentDynamoModel.Workspaces.FirstOrDefault(x => x is CustomNodeWorkspaceModel);
Assert.IsNotNull(nodeWorkspace);

var result = nodeWorkspace.GetSharedName();
Assert.AreEqual(fileName,result);

//Set fileName to null to simulate it is not a saved file
nodeWorkspace.FileName = null;
var expected = nodeWorkspace.Name;

result = nodeWorkspace.GetSharedName();

Assert.AreEqual(expected,result);
}
}
}
Loading