Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(civil3d/rhino): adds correct curves to displayvalue and receiving arcs as fallback in rhino #326

Merged
merged 3 commits into from
Oct 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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);
}
Loading