Skip to content

Commit

Permalink
Merge branch 'dev' into claire/cnx-678-extended-properties-missing-fr…
Browse files Browse the repository at this point in the history
…om-a-tin-surface
  • Loading branch information
clairekuang authored Oct 25, 2024
2 parents 0ef574f + af7bc47 commit 260d66e
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Base Convert(object target)
properties = GetCivilEntityProperties(civilEntity);
}

var objectConverter = _toSpeckle.ResolveConverter(type, true);
var objectConverter = _toSpeckle.ResolveConverter(type);

try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Objects;
using Speckle.Sdk.Models;

namespace Speckle.Converters.Civil3dShared.Helpers;
Expand Down Expand Up @@ -63,4 +64,42 @@ IConverterSettingsStore<Civil3dConversionSettings> converterSettings
return null;
}
}

/// <summary>
/// Processes a list of ICurves for suitable display value curves.
/// </summary>
/// <param name="iCurves"></param>
/// <returns>
/// List of simple curves: lines, polylines, and arcs.
/// Null if no suitable display curves were found.
/// </returns>
public List<Base>? ProcessICurvesForDisplay(List<ICurve>? iCurves)
{
if (iCurves is null)
{
return null;
}

List<Base> result = new();
foreach (ICurve curve in iCurves)
{
switch (curve)
{
case SOG.Line:
case SOG.Polyline:
case SOG.Arc:
result.Add((Base)curve);
break;
case SOG.Polycurve polycurve:
List<Base>? processedSegments = ProcessICurvesForDisplay(polycurve.segments);
if (processedSegments is not null)
{
result.AddRange(processedSegments);
}
break;
}
}

return result.Count > 0 ? result : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public Base Convert(CDB.Entity target)

// extract display value.
// If object has no display but has basecurves, use basecurves for display instead (for viewer selection)
List<Base>? display = _displayValueExtractor.GetDisplayValue(target) ?? baseCurves?.Select(o => (Base)o).ToList();
List<Base>? display =
_displayValueExtractor.GetDisplayValue(target) ?? _displayValueExtractor.ProcessICurvesForDisplay(baseCurves);
if (display is not null)
{
civilObject["displayValue"] = display;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Base Convert(object target)
throw new ValidationException($"Target object is not a db element, it's a {target.GetType()}");
}

var objectConverter = _toSpeckle.ResolveConverter(target.GetType(), true);
var objectConverter = _toSpeckle.ResolveConverter(target.GetType());

Base result = objectConverter.Convert(target);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Speckle.Converters.Common;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Sdk.Common;
using Speckle.Sdk.Common.Exceptions;
Expand All @@ -14,20 +14,23 @@ public class FallbackToHostTopLevelConverter
private readonly ITypedConverter<SOG.Point, RG.Point> _pointConverter;
private readonly ITypedConverter<SOG.Line, RG.LineCurve> _lineConverter;
private readonly ITypedConverter<SOG.Polyline, RG.PolylineCurve> _polylineConverter;
private readonly ITypedConverter<SOG.Arc, RG.ArcCurve> _arcConverter;
private readonly ITypedConverter<SOG.Mesh, RG.Mesh> _meshConverter;
private readonly IConverterSettingsStore<RhinoConversionSettings> _settingsStore;

public FallbackToHostTopLevelConverter(
ITypedConverter<SOG.Point, RG.Point> pointConverter,
ITypedConverter<SOG.Line, RG.LineCurve> lineConverter,
ITypedConverter<SOG.Polyline, RG.PolylineCurve> polylineConverter,
ITypedConverter<SOG.Arc, RG.ArcCurve> arcConverter,
ITypedConverter<SOG.Mesh, RG.Mesh> meshConverter,
IConverterSettingsStore<RhinoConversionSettings> settingsStore
)
{
_pointConverter = pointConverter;
_lineConverter = lineConverter;
_polylineConverter = polylineConverter;
_arcConverter = arcConverter;
_meshConverter = meshConverter;
_settingsStore = settingsStore;
}
Expand All @@ -43,6 +46,7 @@ IConverterSettingsStore<RhinoConversionSettings> settingsStore
{
SOG.Line line => _lineConverter.Convert(line),
SOG.Polyline polyline => _polylineConverter.Convert(polyline),
SOG.Arc arc => _arcConverter.Convert(arc),
SOG.Mesh mesh => _meshConverter.Convert(mesh),
SOG.Point point => _pointConverter.Convert(point),
_ => throw new ConversionException($"Found unsupported fallback geometry: {item.GetType()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ConverterManager<T>(ConcurrentDictionary<string, Type> converterTyp
{
public string Name => typeof(T).Name;

public T ResolveConverter(Type type, bool recursive = false)
public T ResolveConverter(Type type, bool recursive = true)
{
var currentType = type;
while (true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Speckle.Converters.Common.Registration;
namespace Speckle.Converters.Common.Registration;

public interface IConverterManager<T>
{
public string Name { get; }
public T ResolveConverter(Type type, bool recursive = false);
public T ResolveConverter(Type type, bool recursive = true);
}

0 comments on commit 260d66e

Please sign in to comment.