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
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private static string CreateInputsAndOutputs(OpenNodeAnnotationEventArgs e)
{
sb.AppendLine("<tr class=\"table--border\">");
sb.AppendLine($"<td class=\"table--border\">{e.InputNames.ElementAt(i)}</td>");
sb.AppendLine($"<td class=\"table--border\">{GetTypeFromDescription(e.InputDescriptions.ElementAt(i))}</td>");
sb.AppendLine($"<td class=\"table--border\">{e.InputTypes.ElementAt(i)}</td>");
sb.AppendLine($"<td class=\"table--border\">{GetNthRowFromStringSplit(e.InputDescriptions.ElementAt(i), 0)}</td>");
sb.AppendLine($"<td class=\"table--border broken\">{GetDefaultValueFromDescription(e.InputDescriptions.ElementAt(i))}</td>");
sb.AppendLine(@"</tr>");
Expand All @@ -292,6 +292,7 @@ private static string CreateInputsAndOutputs(OpenNodeAnnotationEventArgs e)
sb.AppendLine(" <tr class=\"table--border\">");
sb.AppendLine($"<td class=\"table--border\">{e.OutputNames.ElementAt(i)}</td>");
sb.AppendLine($"<td class=\"table--border\">{GetNthRowFromStringSplit(e.OutputDescriptions.ElementAt(i), 0)}</td>");
sb.AppendLine($"<td class=\"table--border\">{e.OutputTypes.ElementAt(i)}</td>");
sb.AppendLine(@"</tr>");
}

Expand All @@ -302,13 +303,6 @@ private static string CreateInputsAndOutputs(OpenNodeAnnotationEventArgs e)
return sb.ToString();
}

private static string GetTypeFromDescription(string element)
{
var stringArr = element.Split(new string[] {"\r\n", "\r", "\n"}, StringSplitOptions.None);
if(stringArr.Length > 2) return stringArr[2];
return string.Empty;
}

private static string GetDefaultValueFromDescription(string element)
{
var stringArr = element.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
Expand Down
13 changes: 12 additions & 1 deletion src/DynamoCore/Graph/Nodes/PortModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@
/// contains the rank information of the type, e.g. Point[], or var[]..[].
/// </summary>
/// <returns>input port type</returns>
internal string GetInputPortType()

Check failure on line 472 in src/DynamoCore/Graph/Nodes/PortModel.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=DynamoDS_Dynamo&issues=AZ6op-HngGFG9rAQ4lBk&open=AZ6op-HngGFG9rAQ4lBk&pullRequest=17141
{
if (PortType == PortType.Output) return null;

Expand Down Expand Up @@ -515,12 +515,23 @@

try
{
return inPortAttribute?.PortTypes.ElementAt(Index);
var attrType = inPortAttribute?.PortTypes.ElementAt(Index);
if (attrType != null) return attrType;
}
catch (Exception e)
{
Log(e.Message);
}

// Fallback: infer from the port's default value node type.
return DefaultValue switch

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.

There are tests for GetInputPortType(). Please confirm that they cover the defaults for those cases when the NodeModel omits the InPortType

{
IntNode _ => "int",
DoubleNode _ => "double",
BooleanNode _ => "bool",
StringNode _ => "string",
_ => null
};
}
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Dynamo.ViewModels.DynamoViewModel.PythonEngineUpgradeToastRequested -> System.Ac
Dynamo.ViewModels.DynamoViewModel.ToastManager.get -> Dynamo.Wpf.UI.ToastManager
Dynamo.ViewModels.DynamoViewModel.ToastManager.set -> void
Dynamo.ViewModels.DynamoViewModel.ShowPythonEngineUpgradeCanvasToast(string message, bool stayOpen = true, string filePath = null) -> void
Dynamo.ViewModels.OpenNodeAnnotationEventArgs.InputTypes.get -> System.Collections.Generic.IEnumerable<string>
Dynamo.ViewModels.OpenNodeAnnotationEventArgs.OutputTypes.get -> System.Collections.Generic.IEnumerable<string>
Dynamo.ViewModels.PreferencesViewModel.AutoSyncDocumentBrowserIsChecked.get -> bool
Dynamo.ViewModels.PreferencesViewModel.AutoSyncDocumentBrowserIsChecked.set -> void
Dynamo.ViewModels.PreferencesViewModel.ShowPythonAutoMigrationNotificationIsChecked.get -> bool
Expand Down
15 changes: 14 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/DynamoViewModelEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ public class OpenNodeAnnotationEventArgs : OpenDocumentationLinkEventArgs
/// </summary>
public IEnumerable<string> OutputDescriptions { get; private set; }
/// <summary>
/// Collection of the nodes input port types.
/// </summary>
public IEnumerable<string> InputTypes { get; private set; }

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.

does it need to be added to the publid API?

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.

Yes. I think so. both InputTypes.get and OutputTypes.get are new public API

/// <summary>
/// Collection of the nodes output port types.
/// </summary>
public IEnumerable<string> OutputTypes { get; private set; }
Comment thread
johnpierson marked this conversation as resolved.
/// <summary>
/// Collection of the nodes collection of warnings/errors/infos.
/// </summary>
public IEnumerable<Info> NodeInfos { get; private set; }
Expand Down Expand Up @@ -247,33 +255,38 @@ private void SetOutputs(NodeModel nodeModel)
{
var outputNames = new List<string>();
var outputDescriptions = new List<string>();
var outputTypes = new List<string>();

var outputs = nodeModel.OutPorts;
foreach (var output in outputs)
{
outputNames.Add(output.Name);
outputDescriptions.Add(output.ToolTip);
outputTypes.Add(output.GetOutPortType() ?? string.Empty);
}

OutputNames = outputNames;
OutputDescriptions = outputDescriptions;
OutputTypes = outputTypes;
}

private void SetInputs(NodeModel nodeModel)
{
var inputNames = new List<string>();
var inputDescriptions = new List<string>();
var inputTypes = new List<string>();

var inputs = nodeModel.InPorts;
foreach (var input in inputs)
{
inputNames.Add(input.Name);
inputDescriptions.Add(input.ToolTip);
inputTypes.Add(input.GetInputPortType() ?? string.Empty);
}

InputNames = inputNames;
InputDescriptions = inputDescriptions;

InputTypes = inputTypes;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private static List<TypedParameter> BuildParameters(ArgumentSignatureNode signat
}
}

typeParams.Add(new TypedParameter(name));
typeParams.Add(new TypedParameter(name, arg.ArgumentType));
}

return typeParams;
Expand Down
23 changes: 23 additions & 0 deletions test/DynamoCoreWpf3Tests/NodeViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,32 @@
using System.Windows.Media;
using Dynamo.Controls;
using Dynamo.Graph;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Workspaces;
using Dynamo.Models;
using Dynamo.Selection;
using Dynamo.UI.Prompts;
using Dynamo.ViewModels;
using DynamoCoreWpfTests.Utility;
using NUnit.Framework;
using ProtoCore.AST.AssociativeAST;

namespace DynamoCoreWpfTests
{
public class NodeViewTests : DynamoTestUIBase
{
// adapted from: http://stackoverflow.com/questions/9336165/correct-method-for-using-the-wpf-dispatcher-in-unit-tests
private class DefaultValueInputTypeNode : NodeModel
{
internal DefaultValueInputTypeNode()
{
InPorts.Add(new PortModel(PortType.Input, this, new PortData("integer", "integer", AstFactory.BuildIntNode(1))));
InPorts.Add(new PortModel(PortType.Input, this, new PortData("number", "number", AstFactory.BuildDoubleNode(1.0))));
InPorts.Add(new PortModel(PortType.Input, this, new PortData("boolean", "boolean", AstFactory.BuildBooleanNode(true))));
InPorts.Add(new PortModel(PortType.Input, this, new PortData("text", "text", AstFactory.BuildStringNode("value"))));
RegisterAllPorts();
}
}

protected override void GetLibrariesToPreload(List<string> libraries)
{
Expand Down Expand Up @@ -361,6 +374,16 @@ public void InputPortType_NodeModelNode_AreCorrect()
Assert.AreEqual("System.Drawing.Bitmap", type);
}

[Test]
public void InputPortType_NodeModelNodeWithoutInPortTypes_FallsBackToDefaultValueType()
{
var node = new DefaultValueInputTypeNode();

CollectionAssert.AreEqual(
new[] { "int", "double", "bool", "string" },
node.InPorts.Select(port => port.GetInputPortType()));
}

[Test]
[Category("RegressionTests")]
public void GettingNodeNameDoesNotTriggerPropertyChangeCycle()
Expand Down
Loading