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
66 changes: 62 additions & 4 deletions Elements/src/GridLine.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Elements.Geometry;
using Newtonsoft.Json;

namespace Elements
{
Expand All @@ -10,16 +12,57 @@
/// <example>
/// [!code-csharp[Main](../../Elements/test/GridLineTests.cs?name=example)]
/// </example>
public class GridLine : GeometricElement
// TODO: remove IDeserializationCallback implementation once we remove the Line and Geometry properties.
// Remove its usage from JsonInheritanceConverter..
[JsonConverter(typeof(Serialization.JSON.JsonInheritanceConverter), "discriminator")]
public class GridLine : GeometricElement, IDeserializationCallback
{
// TODO: Remove this flag once we remove the Line and Geometry properties.
private bool deserializationIsInProgress = false;

/// <summary>
/// Initializes a new instance of the GridLine class.
/// </summary>
public GridLine() : base()
{
deserializationIsInProgress = false;
}

// TODO: Remove this constructor once we remove the Line and Geometry properties.
[JsonConstructor]
private GridLine(BoundedCurve curve, Polyline geometry, Line line,
Transform @transform = null, Material @material = null, Representation @representation = null, bool @isElementDefinition = false, System.Guid @id = default, string @name = null)
: base(@transform, @material, @representation, @isElementDefinition, @id, @name)
{
deserializationIsInProgress = true;
if (curve != null)
{
Curve = curve;
}
else if (geometry != null)
{
Geometry = geometry;

Check warning on line 44 in Elements/src/GridLine.cs

View workflow job for this annotation

GitHub Actions / build-and-test

'GridLine.Geometry' is obsolete: 'We now use 'Curve' instead.'
}
else
{
Line = line;

Check warning on line 48 in Elements/src/GridLine.cs

View workflow job for this annotation

GitHub Actions / build-and-test

'GridLine.Line' is obsolete: 'We now use 'Curve' instead.'
}
}

/// <summary>
/// Line that runs from the start of the gridline to its end.
/// </summary>
[Obsolete("We now use 'Curve' instead.")]
public Line Line
{
get { return this.Curve as Line; }
set { this.Curve = value; }
set
{
if (!deserializationIsInProgress)
{
this.Curve = value;
}
}
}

/// <summary>
Expand All @@ -29,9 +72,16 @@
public Polyline Geometry
{
get { return this.Curve as Polyline; }
set { this.Curve = value; }
set
{
if (!deserializationIsInProgress)
{
this.Curve = value;
}
}
}


/// <summary>
/// Curve that runs from the start of the gridline to its end.
/// </summary>
Expand Down Expand Up @@ -77,7 +127,7 @@

var circleVertexTransform = GetCircleTransform();
var circle = new Arc(circleVertexTransform, Radius);

renderVertices.AddRange(circle.RenderVertices());

if (ExtensionBeginning > 0)
Expand Down Expand Up @@ -134,5 +184,13 @@
var circleCenter = this.GetCircleTransform();
texts.Add((circleCenter.Origin, circleCenter.ZAxis, circleCenter.XAxis, this.Name, color));
}

/// <summary>
/// This method is called after the object has been deserialized.
/// </summary>
public void OnDeserialization(object sender)
{
deserializationIsInProgress = false;
}
}
}
6 changes: 6 additions & 0 deletions Elements/src/Serialization/JSON/JsonInheritanceConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Runtime.Serialization;

namespace Elements.Serialization.JSON
{
Expand Down Expand Up @@ -417,6 +418,11 @@ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type o
}
}

if (obj is IDeserializationCallback callback)
{
callback.OnDeserialization(obj);
}

return obj;
}
catch (Exception ex)
Expand Down
Loading