Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Jun 17, 2024
1 parent b51b3e4 commit edb7bb1
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ public interface IParameterValueExtractor
{
object? GetValue(IRevitParameter parameter);
double GetValueAsDouble(IRevitElement element, RevitBuiltInParameter builtInParameter);
bool TryGetValueAsDouble(IRevitElement element, RevitBuiltInParameter builtInParameter, [NotNullWhen(true)] out double? value);
bool TryGetValueAsDouble(
IRevitElement element,
RevitBuiltInParameter builtInParameter,
[NotNullWhen(true)] out double? value
);
int GetValueAsInt(IRevitElement element, RevitBuiltInParameter builtInParameter);
bool? GetValueAsBool(IRevitElement element, RevitBuiltInParameter builtInParameter);
string? GetValueAsString(IRevitElement element, RevitBuiltInParameter builtInParameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public SOBR.RevitColumn Convert(IRevitFamilyInstance target)
SOBR.RevitColumn speckleColumn =
new() { family = symbol.FamilyName, type = target.Document.GetElement(target.GetTypeId()).NotNull().Name };

//should these all be try?
if (
_parameterValueExtractor.TryGetValueAsRevitLevel(
target,
Expand All @@ -52,21 +53,41 @@ out var level
{
speckleColumn.level = _levelConverter.Convert(level);
}
//should these all be try?
if (
_parameterValueExtractor.TryGetValueAsRevitLevel(
target,
RevitBuiltInParameter.FAMILY_TOP_LEVEL_PARAM,
out var topLevel
)
)
{
speckleColumn.topLevel = _levelConverter.Convert(topLevel);
}

//should these all be try?
if (
_parameterValueExtractor.TryGetValueAsDouble(
target,
RevitBuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM,
out var baseOffset
)
)
{
speckleColumn.baseOffset = baseOffset.Value;
}

if ( _parameterValueExtractor.TryGetValueAsRevitLevel(target, RevitBuiltInParameter.FAMILY_TOP_LEVEL_PARAM, out var topLevel))
{
speckleColumn.topLevel = _levelConverter.Convert(topLevel);
}

if ( _parameterValueExtractor.TryGetValueAsDouble(target, RevitBuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM, out var baseOffset))
{
speckleColumn.baseOffset = baseOffset.Value;
}

if ( _parameterValueExtractor.TryGetValueAsDouble(target, RevitBuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM, out var topOffset))
{
speckleColumn.topOffset = topOffset.Value;
}
//should these all be try?
if (
_parameterValueExtractor.TryGetValueAsDouble(
target,
RevitBuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM,
out var topOffset
)
)
{
speckleColumn.topOffset = topOffset.Value;
}
speckleColumn.facingFlipped = target.FacingFlipped;
speckleColumn.handFlipped = target.HandFlipped;
speckleColumn.isSlanted = target.IsSlantedColumn;
Expand Down Expand Up @@ -111,7 +132,12 @@ out var level

return new SOG.Line(
basePoint,
new SOG.Point(basePoint.x, basePoint.y, topLevelElevation ?? 0 + topLevelOffset, _contextStack.Current.SpeckleUnits),
new SOG.Point(
basePoint.x,
basePoint.y,
topLevelElevation ?? 0 + topLevelOffset,
_contextStack.Current.SpeckleUnits
),
_contextStack.Current.SpeckleUnits
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ namespace Speckle.Converters.RevitShared;
public class RevitRootElementProvider : IRootElementProvider
{
private static readonly Type s_wrappedElementType = typeof(IRevitElement);

public Type GetRootType() => s_wrappedElementType;
}
50 changes: 37 additions & 13 deletions DUI3-DX/Sdk/Speckle.Converters.Common.Tests/FakeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public FakeType(string name)
{
Name = name;
}

public override object[] GetCustomAttributes(bool inherit) => throw new NotImplementedException();

public override bool IsDefined(Type attributeType, bool inherit) => throw new NotImplementedException();
Expand All @@ -32,15 +33,25 @@ public FakeType(string name)

protected override bool HasElementTypeImpl() => throw new NotImplementedException();

protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types,
ParameterModifier[] modifiers) =>
throw new NotImplementedException();
protected override PropertyInfo GetPropertyImpl(
string name,
BindingFlags bindingAttr,
Binder binder,
Type returnType,
Type[] types,
ParameterModifier[] modifiers
) => throw new NotImplementedException();

public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) => throw new NotImplementedException();

protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention,
Type[] types, ParameterModifier[] modifiers) =>
throw new NotImplementedException();
protected override MethodInfo GetMethodImpl(
string name,
BindingFlags bindingAttr,
Binder binder,
CallingConventions callConvention,
Type[] types,
ParameterModifier[] modifiers
) => throw new NotImplementedException();

public override MethodInfo[] GetMethods(BindingFlags bindingAttr) => throw new NotImplementedException();

Expand All @@ -62,18 +73,31 @@ protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAtt

protected override bool IsCOMObjectImpl() => throw new NotImplementedException();

public override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args,
ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) =>
throw new NotImplementedException();
public override object InvokeMember(
string name,
BindingFlags invokeAttr,
Binder binder,
object target,
object[] args,
ParameterModifier[] modifiers,
CultureInfo culture,
string[] namedParameters
) => throw new NotImplementedException();

public override Type UnderlyingSystemType { get; }

protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention,
Type[] types, ParameterModifier[] modifiers) =>
throw new NotImplementedException();
protected override ConstructorInfo GetConstructorImpl(
BindingFlags bindingAttr,
Binder binder,
CallingConventions callConvention,
Type[] types,
ParameterModifier[] modifiers
) => throw new NotImplementedException();

public override string Name { get; }
[SuppressMessage("Naming", "CA1720:Identifier contains type name")] public override Guid GUID { get; } = Guid.Empty;

[SuppressMessage("Naming", "CA1720:Identifier contains type name")]
public override Guid GUID { get; } = Guid.Empty;
public override Module Module { get; }
public override Assembly Assembly { get; }
public override string FullName { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class RootToSpeckleConverterTests
private readonly Mock<IRootConvertManager> _rootConvertManager;
private readonly Mock<IProxyMapper> _proxyMapper;
private readonly Mock<IRootElementProvider> _rootElementProvider;

public RootToSpeckleConverterTests()
{
_rootConvertManager = _repository.Create<IRootConvertManager>();
Expand Down Expand Up @@ -44,14 +44,16 @@ public void Convert_BaseType()

_proxyMapper.Setup(x => x.GetMappedTypeFromHostType(targetType)).Returns((Type?)null);
_proxyMapper.Setup(x => x.GetMappedTypeFromProxyType(targetType)).Returns((Type?)null);



_rootConvertManager.Setup(x => x.IsSubClass(baseType, targetType)).Returns(true);
_proxyMapper.Setup(x => x.CreateProxy(baseType, target)).Returns(wrappedTarget);
_rootConvertManager.Setup(x => x.Convert(baseType, wrappedTarget)).Returns(converted);

var rootToSpeckleConverter =
new RootToSpeckleConverter(_proxyMapper.Object, _rootConvertManager.Object, _rootElementProvider.Object);
var rootToSpeckleConverter = new RootToSpeckleConverter(
_proxyMapper.Object,
_rootConvertManager.Object,
_rootElementProvider.Object
);
var testConverted = rootToSpeckleConverter.Convert(target);

testConverted.Should().BeSameAs(converted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public RootConvertManager(IFactory<IToSpeckleTopLevelConverter> toSpeckle)
}

public Type GetTargetType(object target) => target.GetType();

public bool IsSubClass(Type baseType, Type childType) => baseType.IsAssignableFrom(childType);

public Base Convert(Type type, object obj)
Expand Down
12 changes: 9 additions & 3 deletions DUI3-DX/Sdk/Speckle.Converters.Common/RootToSpeckleConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ public class RootToSpeckleConverter : IRootToSpeckleConverter

private readonly Type _revitElementType;

public RootToSpeckleConverter(IProxyMapper proxyMapper, IRootConvertManager rootConvertManager, IRootElementProvider rootElementProvider)
public RootToSpeckleConverter(
IProxyMapper proxyMapper,
IRootConvertManager rootConvertManager,
IRootElementProvider rootElementProvider
)
{
_proxyMapper = proxyMapper;
_rootConvertManager = rootConvertManager;
Expand All @@ -30,12 +34,14 @@ public Base Convert(object target)
//try to fallback to element type
if (_rootConvertManager.IsSubClass(_revitElementType, revitType))
{
return _rootConvertManager.Convert(_rootElementProvider.GetRootType(), _proxyMapper.CreateProxy(_rootElementProvider.GetRootType(), target));
return _rootConvertManager.Convert(
_rootElementProvider.GetRootType(),
_proxyMapper.CreateProxy(_rootElementProvider.GetRootType(), target)
);
}
throw new NotSupportedException($"No wrapper found for Revit type: {revitType.Name}");
}
var (wrappedType, wrappedObject) = wrapper;
return _rootConvertManager.Convert(wrappedType, wrappedObject);
}

}

0 comments on commit edb7bb1

Please sign in to comment.