Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
saintentropy committed Nov 13, 2023
1 parent 76174bd commit 72baac0
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 38 deletions.
8 changes: 3 additions & 5 deletions src/Libraries/CoreNodeModels/Remember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ namespace CoreNodeModels
[NodeDescription(nameof(Properties.Resources.RememberDescription), typeof(Properties.Resources))]
[NodeCategory("Core.Data")]
[InPortNames(">")]
[InPortTypes("object")]
[InPortTypes("var[]..[]")]
[InPortDescriptions(typeof(Properties.Resources), nameof(Properties.Resources.RememberInputToolTip))]
[OutPortNames(">")]
[OutPortTypes("object")]
[OutPortTypes("var[]..[]")]
[OutPortDescriptions(typeof(Properties.Resources), nameof(Properties.Resources.RememberOuputToolTip))]
[IsDesignScriptCompatible]
[DynamoServices.RegisterForTrace]
public class Remember : NodeModel
{
private string cache = "";

[JsonProperty("Cache")]
public string Cache
{
get { return cache; }
Expand Down Expand Up @@ -55,7 +53,7 @@ private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "State":
case nameof(State):
if (State == ElementState.Warning)
{
Cache = "";
Expand Down
66 changes: 44 additions & 22 deletions src/Libraries/CoreNodes/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static object DynamoJObjectToNative(JObject jObject)
case "dynamo.geometry:mesh-1.0.0":
return Mesh.FromJson(jObject.ToString());

//types supported by Goemetry.FromJson
//types supported by Geometry.FromJson
case "autodesk.math:point3d-1.0.0":
case "dynamo.geometry:sab-1.0.0":
case "dynamo.geometry:tsm-1.0.0":
Expand All @@ -110,34 +110,56 @@ private static object DynamoJObjectToNative(JObject jObject)

//Dynamo types
case "dynamo.graphics:color-1.0.0":
return Color.ByARGB(
(int)jObject["A"],
(int)jObject["R"],
(int)jObject["G"],
(int)jObject["B"]);
try
{
return Color.ByARGB(
(int)jObject["A"],
(int)jObject["R"],
(int)jObject["G"],
(int)jObject["B"]);
}
catch {
throw new FormatException(string.Format(Properties.Resources.Exception_Deserialize_Bad_Format, typeof(Color).FullName));
}

#if _WINDOWS
case "dynamo.graphics:png-1.0.0":

jObject.TryGetValue(ImageFormat.Png.ToString(), out var value);

if (value != null)
{
var stream = Convert.FromBase64String(value.ToString());

Bitmap bitmap;
using (var ms = new MemoryStream(stream))
bitmap = new Bitmap(Bitmap.FromStream(ms));

return bitmap;
try
{
var stream = Convert.FromBase64String(value.ToString());

Bitmap bitmap;
using (var ms = new MemoryStream(stream))
bitmap = new Bitmap(Bitmap.FromStream(ms));

return bitmap;
}
catch {
//Pass through to the next throw
}
}
#endif

throw new FormatException(string.Format(Properties.Resources.Exception_Deserialize_Bad_Format, "dynamo.graphics:png-1.0.0"));
#else
return null;

#endif
case "dynamo.data:location-1.0.0":
return DynamoUnits.Location.ByLatitudeAndLongitude(
(double)jObject["Latitude"],
(double)jObject["Longitude"],
(string)jObject["Name"]);
try
{
return DynamoUnits.Location.ByLatitudeAndLongitude(
(double)jObject["Latitude"],
(double)jObject["Longitude"],
(string)jObject["Name"]);
}
catch
{
throw new FormatException(string.Format(Properties.Resources.Exception_Deserialize_Bad_Format, typeof(DynamoUnits.Location).FullName));
}

default:
return null;
Expand Down Expand Up @@ -171,7 +193,7 @@ public static string StringifyJSON([ArbitraryDimensionArrayImport] object values
new ColorConveter(),
new LocationConverter(),
#if _WINDOWS
new ImageConverter(),
new PNGImageConverter(),
#endif
});
}
Expand Down Expand Up @@ -325,7 +347,7 @@ public override bool CanConvert(Type objectType)
#if NET6_0_OR_GREATER
[SupportedOSPlatform("windows")]
#endif
private class ImageConverter : JsonConverter
private class PNGImageConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
Expand Down Expand Up @@ -404,7 +426,7 @@ public static Dictionary<string, object> Remember([ArbitraryDimensionArrayImport
}
catch
{
throw new NotSupportedException(Properties.Resources.Exception_Deserialize_Unsupported_Type);
throw new NotSupportedException(Properties.Resources.Exception_Deserialize_Unsupported_Cache);
}

return new Dictionary<string, object>
Expand Down
15 changes: 12 additions & 3 deletions src/Libraries/CoreNodes/Properties/Resources.Designer.cs

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

7 changes: 5 additions & 2 deletions src/Libraries/CoreNodes/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@
<data name="EnumDateOfWeekWednesday" xml:space="preserve">
<value>Wednesday</value>
</data>
<data name="Exception_Deserialize_Unsupported_Type" xml:space="preserve">
<value>The stored data can not be rebuilt.</value>
<data name="Exception_Deserialize_Bad_Format" xml:space="preserve">
<value>The json for the type {0} was not formatted correctly</value>
</data>
<data name="Exception_Deserialize_Unsupported_Cache" xml:space="preserve">
<value>The stored data can not be loaded.</value>
</data>
<data name="Exception_Serialize_Unsupported_Type" xml:space="preserve">
<value>Cannot store data of type {0}.</value>
Expand Down
7 changes: 5 additions & 2 deletions src/Libraries/CoreNodes/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@
<data name="EnumDateOfWeekWednesday" xml:space="preserve">
<value>Wednesday</value>
</data>
<data name="Exception_Deserialize_Unsupported_Type" xml:space="preserve">
<value>The stored data can not be rebuilt.</value>
<data name="Exception_Deserialize_Bad_Format" xml:space="preserve">
<value>The json for the type {0} was not formatted correctly</value>
</data>
<data name="Exception_Deserialize_Unsupported_Cache" xml:space="preserve">
<value>The stored data can not be loaded.</value>
</data>
<data name="Exception_Serialize_Unsupported_Type" xml:space="preserve">
<value>Cannot store data of type {0}.</value>
Expand Down
19 changes: 15 additions & 4 deletions test/DynamoCoreTests/DSCoreDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ public void RoundTripForBoundingBoxReturnsSameResult()
// Verify objects match when serializing / de-serializing geometry type
AssertPreviewValue("abb39e07-db08-45cf-9438-478defffbf68", true);

// Verify current failure cases are all false
// Currently we do not support oriented BB.
// This test will verify current unsupported cases
AssertPreviewValue("eb9130a1-309c-492a-9679-28ad5ef8fddf", true);
}

Expand Down Expand Up @@ -243,6 +244,7 @@ public void RoundTripForVectorReturnsSameResult()
AssertPreviewValue("71efc8c5c0c74189901707c30e6d5903", true);
}

//Waiting for upstream PR so that we can mark as [Category("UnitTests")]
[Test]
[Category("Failure")]
public void RoundTripForArcReturnsSameResult()
Expand All @@ -254,7 +256,9 @@ public void RoundTripForArcReturnsSameResult()
// Verify objects match when serializing / de-serializing geometry type
AssertPreviewValue("71efc8c5c0c74189901707c30e6d5903", true);

// Verify current failure cases are all false
// A known issue is that Arcs do not deserialize with the same start angle value.
// It is always zero although the curve topology is identical.
// This will verify the current known edge case.
AssertPreviewValue("82304dd5025948f8a5644a84a32d58d4", true);
}

Expand Down Expand Up @@ -293,7 +297,9 @@ public void RoundTripForEllipseArcReturnsSameResult()
// Verify objects match when serializing / de-serializing geometry type
AssertPreviewValue("a29aa179c7ae4069a6d9c6d2055ab845", true);

// Verify current failure cases are all false
// A known issue is that EllipseArcs do not deserialize with the same start angle value.
// It is always zero although the curve topology is identical.
// This will verify the current known edge case.
AssertPreviewValue("a73925f57d2c44d7994a2c4d77bf8581", true);
}

Expand All @@ -308,7 +314,10 @@ public void RoundTripForHelixReturnsSameResult()
// Verify objects match when serializing / de-serializing geometry type
AssertPreviewValue("b6a4919b3dd94eb79a7f0435d941d235", true);

// Verify current failure cases are all false
// A known issue is that Helix do not deserialize with the same type.
// It is always converted to nurbscurve (Same as SAB serialization).
// When the spiral GeoemtrySchema type is finalized we use it to support helix.
// This will verify the current known unsupported case.
AssertPreviewValue("1bbd147b429c43ab8fe46a00d691a024", true);
}

Expand Down Expand Up @@ -336,6 +345,7 @@ public void RoundTripForNurbsCurveReturnsSameResult()
AssertPreviewValue("423356e2c8f84e00aa6c50e9bdb72c98", true);
}

//Waiting for upstream PR so that we can mark as [Category("UnitTests")]
[Test]
[Category("Failure")]
public void RoundTripForPolyCurveReturnsSameResult()
Expand Down Expand Up @@ -384,6 +394,7 @@ public void RoundTripForPointReturnsSameResult()
AssertPreviewValue("71efc8c5c0c74189901707c30e6d5903", true);
}

//Waiting for upstream PR so that we can mark as [Category("UnitTests")]
[Test]
[Category("Failure")]
public void RoundTripForCylinderReturnsSameResult()
Expand Down

0 comments on commit 72baac0

Please sign in to comment.