Skip to content

Commit

Permalink
DYN-5965: introduce new string from nodes that accept numeric format …
Browse files Browse the repository at this point in the history
  • Loading branch information
mjkkirschner authored Nov 11, 2024
1 parent 5278181 commit 7ec4fc7
Show file tree
Hide file tree
Showing 44 changed files with 2,448 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## In Depth
This node will convert an oject to a string. The second input `format specifier` controls how numeric inputs are converted to their string representations.
This `format specifier` inputs should be one of the c# standard format numeric specifiers.

format specifiers should be in the form:
`<specifier><precision>` for example F1

Some commonly used format specifiers are:
```
G : general formatting G 1000.0 -> "1000"
F : fixed point notation F4 1000.0 -> "1000.0000"
N : number N2 1000 -> "1,000.00"
```

The default for this node is `G`, which will output a compact, but variable representation.

[see the microsoft documentation for more detailed information.](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#standard-format-specifiers)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## In Depth
This node will convert an oject to a string. The second input `format specifier` controls how numeric inputs are converted to their string representations.
This `format specifier` inputs should be one of the c# standard format numeric specifiers.

format specifiers should be in the form:
`<specifier><precision>` for example F1

Some commonly used format specifiers are:
```
G : general formatting G 1000.0 -> "1000"
F : fixed point notation F4 1000.0 -> "1000.0000"
N : number N2 1000 -> "1,000.00"
```

The default for this node is `G`, which will output a compact, but variable representation.

[see the microsoft documentation for more detailed information.](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#standard-format-specifiers)
10 changes: 5 additions & 5 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ private readonly static Lazy<PreferenceSettings>
/// </summary>
public static readonly DateTime DynamoDefaultTime = new DateTime(1977, 4, 12, 12, 12, 0, 0);

internal static readonly IEnumerable<string> InitialExperimentalLib_Namespaces =
[
"ProtoGeometry.dll:Autodesk.DesignScript.Geometry.PanelSurface"
];
#endregion

// The following settings are persistent between Dynamo sessions and are user-controllable
Expand Down Expand Up @@ -1186,11 +1190,7 @@ internal void InitializeNamespacesToExcludeFromLibrary()
{
if (!NamespacesToExcludeFromLibrarySpecified)
{
NamespacesToExcludeFromLibrary = new List<string>()
{
"ProtoGeometry.dll:Autodesk.DesignScript.Geometry.TSpline",
"ProtoGeometry.dll:Autodesk.DesignScript.Geometry.PanelSurface"
};
NamespacesToExcludeFromLibrary = InitialExperimentalLib_Namespaces.ToList();
NamespacesToExcludeFromLibrarySpecified = true;
}
}
Expand Down
19 changes: 18 additions & 1 deletion src/DynamoCore/Graph/Nodes/NodeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Xml;
using Autodesk.DesignScript.Runtime;
using Dynamo.Configuration;
using Dynamo.Engine;
using Dynamo.Engine.CodeGeneration;
using Dynamo.Graph.Connectors;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Nodes.ZeroTouch;
using Dynamo.Graph.Workspaces;
using Dynamo.Migration;
using Dynamo.Scheduler;
Expand Down Expand Up @@ -2869,6 +2870,22 @@ public bool ShouldDisplayPreview

protected bool ShouldDisplayPreviewCore { get; set; }

[Experimental("NM_ISEXPERIMENTAL_GLPYH")]
internal bool IsExperimental
{
get
{
//TODO switch on model type?
if (this is DSFunction ztnm)
{
return ztnm.Controller.Definition.IsExperimental;
}
else
{
return TypeLoadData.CheckExperimentalFromAttribute(GetType());
}
}
}
public event Action<NodeModel, RenderPackageCache> RenderPackagesUpdated;

private void OnRenderPackagesUpdated(RenderPackageCache packages)
Expand Down
12 changes: 11 additions & 1 deletion src/DynamoCore/Graph/Nodes/TypeLoadData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -95,6 +95,12 @@ public TypeLoadData(Type typeIn)

OutputParameters = Type.GetCustomAttributes<OutPortTypesAttribute>(false)
.SelectMany(x => x.PortTypes);
IsExperimental = CheckExperimentalFromAttribute(Type);
}

internal static bool CheckExperimentalFromAttribute(System.Type type)
{
return type.GetCustomAttributes<System.Diagnostics.CodeAnalysis.ExperimentalAttribute>(false).Any();
}

/// <summary>
Expand Down Expand Up @@ -166,5 +172,9 @@ public string Category
/// Indicates output parameters.
/// </summary>
public readonly IEnumerable<string> OutputParameters;
/// <summary>
/// Is this type experimental/unstable.
/// </summary>
internal bool IsExperimental;
}
}
42 changes: 30 additions & 12 deletions src/DynamoCore/Library/FunctionDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using Dynamo.Configuration;
using Dynamo.Graph.Nodes;
using Dynamo.Interfaces;
using Dynamo.Library;
Expand Down Expand Up @@ -145,7 +146,12 @@ public FunctionDescriptorParams()
/// <summary>
/// Indicates if the lacing strategy is disabled on the function
/// </summary>
public bool IsLacingDisabled { get; set; }
public bool IsLacingDisabled { get; set; }
//TODO - should this somehow contain more info - ExperimentalInfo{IsExperimental, ExperimentalMessage/url}?}
/// <summary>
/// Experimental/Unstable function
/// </summary>
internal bool IsExperimental { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -186,7 +192,7 @@ public FunctionDescriptor(FunctionDescriptorParams funcDescParams)
var type = funcDescParams.FunctionType;
var inputParameters = new List<Tuple<string, string>>();
//Add instance parameter as one of the inputs for instance method as well as properties.
if(type == FunctionType.InstanceMethod || type == FunctionType.InstanceProperty)
if (type == FunctionType.InstanceMethod || type == FunctionType.InstanceProperty)
inputParameters.Add(Tuple.Create(UnqualifedClassName.ToLower(), UnqualifedClassName));

if (Parameters.Any())
Expand All @@ -196,7 +202,7 @@ public FunctionDescriptor(FunctionDescriptorParams funcDescParams)
}

InputParameters = inputParameters;
ReturnType = funcDescParams.ReturnType;
ReturnType = funcDescParams.ReturnType;
Type = type;
ReturnKeys = funcDescParams.ReturnKeys;
IsVarArg = funcDescParams.IsVarArg;
Expand All @@ -206,6 +212,7 @@ public FunctionDescriptor(FunctionDescriptorParams funcDescParams)
IsBuiltIn = funcDescParams.IsBuiltIn;
IsPackageMember = funcDescParams.IsPackageMember;
IsLacingDisabled = funcDescParams.IsLacingDisabled;
IsExperimental = funcDescParams.IsExperimental || CheckIfFunctionIsMarkedExperimentalByPrefs(this);
}

/// <summary>
Expand Down Expand Up @@ -320,28 +327,28 @@ public string Category
{
var categoryBuf = new StringBuilder();
categoryBuf.Append(GetRootCategory());

//if this is not BuiltIn function search NodeCategoryAttribute for it
if (ClassName!=null)
if (ClassName != null)
{
//get function assembly
var asm = AppDomain.CurrentDomain.GetAssemblies()
.Where(x => x.GetName().Name == Path.GetFileNameWithoutExtension(Assembly))
.ToArray();

if (asm.Any() && asm.First().GetType(ClassName)!=null)
if (asm.Any() && asm.First().GetType(ClassName) != null)
{
//get class type of function
var type = asm.First().GetType(ClassName);

//get NodeCategoryAttribute for this function if it was been defined
var nodeCat = type.GetMethods().Where(x=>x.Name==FunctionName)
.Select(x => x.GetCustomAttribute(typeof (NodeCategoryAttribute)))
.Where(x=>x!=null)
var nodeCat = type.GetMethods().Where(x => x.Name == FunctionName)
.Select(x => x.GetCustomAttribute(typeof(NodeCategoryAttribute)))
.Where(x => x != null)
.Cast<NodeCategoryAttribute>()
.Select(x=>x.ElementCategory)
.Select(x => x.ElementCategory)
.FirstOrDefault();

//if attribute is found compose node category string with last part from attribute
if (!string.IsNullOrEmpty(nodeCat) && (
nodeCat == LibraryServices.Categories.Constructors
Expand All @@ -353,7 +360,7 @@ public string Category
}
}
}

switch (Type)
{
case FunctionType.Constructor:
Expand Down Expand Up @@ -567,5 +574,16 @@ private string GetRootCategory()

return string.IsNullOrEmpty(Namespace) ? filename : filename + "." + Namespace;
}
private bool CheckIfFunctionIsMarkedExperimentalByPrefs(FunctionDescriptor fd)
{
if (PreferenceSettings.InitialExperimentalLib_Namespaces.
Where(x => x.StartsWith(fd.Assembly + ":")).Select(x => x.Split(":").LastOrDefault()).Any(nsp => fd.QualifiedName.StartsWith(nsp)))
{
return true;
}
return false;
}
internal bool IsExperimental { get;}
}

}
4 changes: 2 additions & 2 deletions src/DynamoCore/Library/LibraryServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,9 @@ private void ImportProcedure(string library, ProcedureNode proc)
IsBuiltIn = pathManager.PreloadedLibraries.Contains(library)
|| library.StartsWith(PathManager.BuiltinPackagesDirectory),
IsPackageMember = packagedLibraries.Contains(library),
IsLacingDisabled = isLacingDisabled
IsLacingDisabled = isLacingDisabled,
IsExperimental = (methodAttribute?.IsExperimental).GetValueOrDefault()|| (classAttribute?.IsExperimental).GetValueOrDefault()
});

AddImportedFunctions(library, new[] { function });
}

Expand Down
5 changes: 5 additions & 0 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3399,6 +3399,11 @@ private NodeModelSearchElement AddNodeTypeToSearch(TypeLoadData typeLoadData)
{
return null;
}
if(PreferenceSettings.InitialExperimentalLib_Namespaces.
Select(x => x.Split(":").LastOrDefault()).Any(x => x.Contains(typeLoadData.Category))){
//TODO safer way to set this?
typeLoadData.IsExperimental = true;
}

var node = new NodeModelSearchElement(typeLoadData);
SearchModel?.Add(node);
Expand Down
19 changes: 14 additions & 5 deletions src/DynamoCore/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/DynamoCore/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -920,4 +920,7 @@ This package likely contains an assembly that is blocked. You will need to load
<data name="InputNodeRenameHint" xml:space="preserve">
<value>default input name, rename me!</value>
</data>
</root>
<data name="DocsExperimentalPrefixMessage" xml:space="preserve">
<value>This node is currently experimental. Its behavior, name, and signature are subject to change.</value>
</data>
</root>
5 changes: 4 additions & 1 deletion src/DynamoCore/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -923,4 +923,7 @@ This package likely contains an assembly that is blocked. You will need to load
<data name="InputNodeRenameHint" xml:space="preserve">
<value>default input name, rename me!</value>
</data>
</root>
<data name="DocsExperimentalPrefixMessage" xml:space="preserve">
<value>This node is currently experimental. Its behavior, name, and signature are subject to change.</value>
</data>
</root>
1 change: 1 addition & 0 deletions src/DynamoCore/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2782,6 +2782,7 @@ static Dynamo.Properties.Resources.DescriptionResource1.get -> string
static Dynamo.Properties.Resources.DirectoryNotFound.get -> string
static Dynamo.Properties.Resources.DisplayEngineFailureMessageDescription.get -> string
static Dynamo.Properties.Resources.DllLoadException.get -> string
static Dynamo.Properties.Resources.DocsExperimentalPrefixMessage.get -> string
static Dynamo.Properties.Resources.DownloadLatestButton.get -> string
static Dynamo.Properties.Resources.DSFunctionNodeDescription.get -> string
static Dynamo.Properties.Resources.DulicatedPackage.get -> string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected NodeModelSearchElementBase(TypeLoadData typeLoadData)
{
ElementType |= ElementTypes.BuiltIn;
}
IsExperimental = typeLoadData.IsExperimental;
}
}
}
10 changes: 10 additions & 0 deletions src/DynamoCore/Search/SearchElements/NodeSearchElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Dynamo.Configuration;
using Dynamo.Graph.Nodes;
using Dynamo.Properties;

namespace Dynamo.Search.SearchElements
{
Expand All @@ -19,6 +20,7 @@ public abstract class NodeSearchElement : ISearchEntry, ISource<NodeModel>, IClo
private SearchElementGroup group;
private string assembly;
private bool isVisibleInSearch = true;
internal virtual bool IsExperimental { get; set; }

internal AutoCompletionNodeElementInfo AutoCompletionNodeElementInfo { get; set; } = new AutoCompletionNodeElementInfo();

Expand Down Expand Up @@ -141,7 +143,15 @@ public string Description
get
{
if (string.IsNullOrEmpty(description))
{
return Configurations.NoDescriptionAvailable;
}
if (IsExperimental)
{
return $"{Resources.DocsExperimentalPrefixMessage}" +
$"{Environment.NewLine}{Environment.NewLine}{description}";
}


return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class ZeroTouchSearchElement : NodeSearchElement
/// </summary>
internal FunctionDescriptor Descriptor => functionDescriptor;

internal override bool IsExperimental => functionDescriptor.IsExperimental;

/// <summary>
/// Initializes a new instance of the <see cref="ZeroTouchSearchElement"/> class
/// with the DesignScript function description
Expand Down
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,7 @@ Dynamo.ViewModels.NodeViewModel.InPorts.set -> void
Dynamo.ViewModels.NodeViewModel.IsCustomFunction.get -> bool
Dynamo.ViewModels.NodeViewModel.IsDisplayingLabels.get -> bool
Dynamo.ViewModels.NodeViewModel.IsDisplayingLabels.set -> void
Dynamo.ViewModels.NodeViewModel.IsExperimental.get -> bool
Dynamo.ViewModels.NodeViewModel.IsFrozen.get -> bool
Dynamo.ViewModels.NodeViewModel.IsFrozen.set -> void
Dynamo.ViewModels.NodeViewModel.IsFrozenExplicitly.get -> bool
Expand Down
Loading

0 comments on commit 7ec4fc7

Please sign in to comment.