-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Core.Data Serialization and Add Remember Node (#14111)
* Add Geometry support to the Data Parse / Stringify nodes * Add converters for Color, Image, and Location * missing comma * Add Remember Node * Move serialization logic to LibG * fix order bug * Fixed typo preventing Remember node from showing up in Dynamo library * Clean up * Temp remove ForgeUnits * Update tests * Add back in the Units support * Fix tests * Add icon * Add new types for solids * Add initial tests * Update tests * Add catch and resource strings * Add error check in test * Fix typos * Add mesh support back to convertor * Add os guards for System.Drawing * Missing using * remove unused variable * Fix post error update to remove the non-pointer message * Update tests * Remove the warning message intercept * Add missing test file * Added linter rule for obsolete Remember node. * Revert "Added linter rule for obsolete Remember node." This reverts commit 95c6a48. * PR comments * Update error handling and logging * Update bad merge conflict fix and update test --------- Co-authored-by: Craig Long <craig.long@autodesk.com> Co-authored-by: Long Nguyen <longnguyen.connect@gmail.com>
- Loading branch information
1 parent
fc0b585
commit 8af516c
Showing
32 changed files
with
48,857 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Libraries/CoreNodeModels/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using Dynamo.Graph; | ||
using Dynamo.Graph.Nodes; | ||
using Newtonsoft.Json; | ||
using ProtoCore.AST.AssociativeAST; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using VMDataBridge; | ||
|
||
namespace CoreNodeModels | ||
{ | ||
[NodeName("Remember")] | ||
[NodeDescription(nameof(Properties.Resources.RememberDescription), typeof(Properties.Resources))] | ||
[NodeCategory("Core.Data")] | ||
[InPortNames(">")] | ||
[InPortTypes("var[]..[]")] | ||
[InPortDescriptions(typeof(Properties.Resources), nameof(Properties.Resources.RememberInputToolTip))] | ||
[OutPortNames(">")] | ||
[OutPortTypes("var[]..[]")] | ||
[OutPortDescriptions(typeof(Properties.Resources), nameof(Properties.Resources.RememberOuputToolTip))] | ||
[IsDesignScriptCompatible] | ||
public class Remember : NodeModel | ||
{ | ||
private string cache = ""; | ||
|
||
public string Cache | ||
{ | ||
get { return cache; } | ||
set | ||
{ | ||
var valueToSet = value == null ? "" : value; | ||
if (valueToSet != cache) | ||
{ | ||
cache = valueToSet; | ||
MarkNodeAsModified(); | ||
} | ||
} | ||
} | ||
|
||
[JsonConstructor] | ||
private Remember(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts) | ||
{ | ||
PropertyChanged += OnPropertyChanged; | ||
} | ||
|
||
public Remember() | ||
{ | ||
RegisterAllPorts(); | ||
PropertyChanged += OnPropertyChanged; | ||
} | ||
|
||
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) | ||
{ | ||
switch (e.PropertyName) | ||
{ | ||
case nameof(State): | ||
if (State == ElementState.Warning) | ||
{ | ||
Cache = ""; | ||
} | ||
break; | ||
|
||
default: | ||
// Nothing to handle | ||
break; | ||
} | ||
} | ||
|
||
protected override void OnBuilt() | ||
{ | ||
base.OnBuilt(); | ||
DataBridge.Instance.RegisterCallback(GUID.ToString(), DataBridgeCallback); | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
PropertyChanged -= OnPropertyChanged; | ||
base.Dispose(); | ||
DataBridge.Instance.UnregisterCallback(GUID.ToString()); | ||
} | ||
|
||
private static readonly string BuiltinDictionaryTypeName = typeof(DesignScript.Builtin.Dictionary).FullName; | ||
private static readonly string BuiltinDictionaryGet = nameof(DesignScript.Builtin.Dictionary.ValueAtKey); | ||
|
||
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes) | ||
{ | ||
var resultAst = new List<AssociativeNode>(); | ||
|
||
var funtionInputs = new List<AssociativeNode> { inputAstNodes[0], AstFactory.BuildStringNode(Cache) }; | ||
|
||
//First build the function call | ||
var functionCall = AstFactory.BuildFunctionCall( | ||
new Func<object, string, Dictionary<string, object>>(DSCore.Data.Remember), funtionInputs); | ||
|
||
var functionCallIndent = AstFactory.BuildIdentifier(GUID + "_func"); | ||
|
||
resultAst.Add(AstFactory.BuildAssignment(functionCallIndent, functionCall)); | ||
|
||
//Next add the first key value pair to the output port | ||
var getFirstKey = AstFactory.BuildFunctionCall(BuiltinDictionaryTypeName, BuiltinDictionaryGet, | ||
new List<AssociativeNode> { functionCallIndent, AstFactory.BuildStringNode(">") }); | ||
|
||
resultAst.Add(AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), getFirstKey)); | ||
|
||
//Second get the key value pair to pass to the databridge callback | ||
var getSecondKey = AstFactory.BuildFunctionCall(BuiltinDictionaryTypeName, BuiltinDictionaryGet, | ||
new List<AssociativeNode> { functionCallIndent, AstFactory.BuildStringNode("Cache") }); | ||
|
||
resultAst.Add(AstFactory.BuildAssignment( | ||
AstFactory.BuildIdentifier(GUID + "_db"), | ||
DataBridge.GenerateBridgeDataAst(GUID.ToString(), getSecondKey))); | ||
|
||
return resultAst; | ||
} | ||
|
||
private void DataBridgeCallback(object callbackObject) | ||
{ | ||
if (DSCore.Data.CanObjectBeCached(callbackObject)) | ||
{ | ||
Cache = callbackObject as String; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.