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

add curve to direct shape conversions #37

Merged
merged 6 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -37,12 +37,20 @@
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\Geometry\PlaneConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\Geometry\PointConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\Geometry\PolylineConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\ToDirectShape\ArcToDirectShapeConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\ToDirectShape\CircleToDirectShapeConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\ToDirectShape\CurveToDirectShapeConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\ToDirectShape\EllipseToDirectShapeConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\ToDirectShape\LineToDirectShapeConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\ToDirectShape\PolycurveConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\ToDirectShape\PolylineConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\Geometry\VectorConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\RenderMaterialToHostConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\SurfaceConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\BaseTopLevelConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\BrepToHostTopLevelConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\DirectShapeTopLevelConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\ToDirectShape\ICurveToDirectShapeConverterToHostBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\LevelToHostTopLevelConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\GridlineToHostTopLevelConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\MeshToHostTopLevelConverter.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Objects;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.RevitShared.ToHost.TopLevel;

namespace Speckle.Converters.RevitShared.ToHost.Raw.Geometry;

[NameAndRankValue(nameof(SOG.Arc), 0)]
public class ArcToDirectShapeConverterToHost : CurveToDirectShapeConverterToHostBase<SOG.Arc>
{
public ArcToDirectShapeConverterToHost(
IRevitConversionContextStack contextStack,
ITypedConverter<ICurve, DB.CurveArray> curveConverter
)
: base(contextStack, curveConverter) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Objects;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.RevitShared.ToHost.TopLevel;

namespace Speckle.Converters.RevitShared.ToHost.Raw.Geometry;

[NameAndRankValue(nameof(SOG.Circle), 0)]
public class CircleToDirectShapeConverterToHost : CurveToDirectShapeConverterToHostBase<SOG.Circle>
{
public CircleToDirectShapeConverterToHost(
IRevitConversionContextStack contextStack,
ITypedConverter<ICurve, DB.CurveArray> curveConverter
)
: base(contextStack, curveConverter) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Objects;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.RevitShared.ToHost.TopLevel;

namespace Speckle.Converters.RevitShared.ToHost.Raw.Geometry;

[NameAndRankValue(nameof(SOG.Curve), 0)]
public class CurveToDirectShapeConverterToHost : CurveToDirectShapeConverterToHostBase<SOG.Curve>
{
public CurveToDirectShapeConverterToHost(
IRevitConversionContextStack contextStack,
ITypedConverter<ICurve, DB.CurveArray> curveConverter
)
: base(contextStack, curveConverter) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Objects;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Core.Models;

namespace Speckle.Converters.RevitShared.ToHost.TopLevel;

public abstract class CurveToDirectShapeConverterToHostBase<TCurve>
: ITypedConverter<TCurve, List<DB.GeometryObject>>,
IToHostTopLevelConverter
where TCurve : Base, ICurve
{
private readonly IRevitConversionContextStack _contextStack;
private readonly ITypedConverter<ICurve, DB.CurveArray> _curveConverter;

public CurveToDirectShapeConverterToHostBase(
IRevitConversionContextStack contextStack,
ITypedConverter<ICurve, DB.CurveArray> curveConverter
)
{
_contextStack = contextStack;
_curveConverter = curveConverter;
}

public List<DB.GeometryObject> Convert(TCurve target)
{
var converted = new List<DB.GeometryObject>();

DB.CurveArray curveArray = _curveConverter.Convert(target);
converted.AddRange(curveArray.Cast<DB.Curve>());

var genericModelCategory = _contextStack.Current.Document.Settings.Categories.get_Item(
DB.BuiltInCategory.OST_GenericModel
);

var revitDs = DB.DirectShape.CreateElement(_contextStack.Current.Document, genericModelCategory.Id);
if (target is Base speckleObject && speckleObject.applicationId != null)
{
revitDs.ApplicationId = speckleObject.applicationId;
}

revitDs.ApplicationDataId = Guid.NewGuid().ToString();
revitDs.SetShape(converted);
revitDs.Name = "CurveAsDirectShape";

return converted;
}

public object Convert(Base target) => Convert((TCurve)target);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Objects;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.RevitShared.ToHost.TopLevel;

namespace Speckle.Converters.RevitShared.ToHost.Raw.Geometry;

[NameAndRankValue(nameof(SOG.Ellipse), 0)]
public class EllipseToDirectShapeConverterToHost : CurveToDirectShapeConverterToHostBase<SOG.Ellipse>
{
public EllipseToDirectShapeConverterToHost(
IRevitConversionContextStack contextStack,
ITypedConverter<ICurve, DB.CurveArray> curveConverter
)
: base(contextStack, curveConverter) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Objects;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.RevitShared.ToHost.TopLevel;

namespace Speckle.Converters.RevitShared.ToHost.Raw.Geometry;

[NameAndRankValue(nameof(SOG.Line), 0)]
public class LineToDirectShapeConverterToHost : CurveToDirectShapeConverterToHostBase<SOG.Line>
{
public LineToDirectShapeConverterToHost(
IRevitConversionContextStack contextStack,
ITypedConverter<ICurve, DB.CurveArray> curveConverter
)
: base(contextStack, curveConverter) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Objects;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.RevitShared.ToHost.TopLevel;

namespace Speckle.Converters.RevitShared.ToHost.Raw.Geometry;

[NameAndRankValue(nameof(SOG.Polycurve), 0)]
public class PolycurveToDirectShapeConverterToHost : CurveToDirectShapeConverterToHostBase<SOG.Polycurve>
{
public PolycurveToDirectShapeConverterToHost(
IRevitConversionContextStack contextStack,
ITypedConverter<ICurve, DB.CurveArray> curveConverter
)
: base(contextStack, curveConverter) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Objects;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.RevitShared.ToHost.TopLevel;

namespace Speckle.Converters.RevitShared.ToHost.Raw.Geometry;

[NameAndRankValue(nameof(SOG.Polyline), 0)]
public class PolylineToDirectShapeConverterToHost : CurveToDirectShapeConverterToHostBase<SOG.Polyline>
{
public PolylineToDirectShapeConverterToHost(
IRevitConversionContextStack contextStack,
ITypedConverter<ICurve, DB.CurveArray> curveConverter
)
: base(contextStack, curveConverter) { }
}
Loading