Skip to content

Commit

Permalink
Dui3 178 gridlines (#3554)
Browse files Browse the repository at this point in the history
add gridline conversion

Co-authored-by: Connor Ivy <connor@speckle.systems>
  • Loading branch information
connorivy and Connor Ivy authored Jul 3, 2024
1 parent a2954b1 commit 7451d8e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\Geometry\PolylineConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\Geometry\VectorConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\BaseTopLevelConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\GridlineToHostTopLevelConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\ModelCurveToSpeckleTopLevelConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\BeamConversionToSpeckle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\BoundarySegmentConversionToSpeckle.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Objects;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.RevitShared.ToSpeckle;

namespace Speckle.Converters.RevitShared.ToHost.TopLevel;

[NameAndRankValue(nameof(SOBE.GridLine), 0)]
internal class GridlineToHostTopLevelConverter : BaseTopLevelConverterToHost<SOBE.GridLine, DB.Grid>
{
private readonly ITypedConverter<ICurve, DB.CurveArray> _curveConverter;
private readonly IRevitConversionContextStack _contextStack;

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

public override DB.Grid Convert(SOBE.GridLine target)
{
DB.Curve curve = _curveConverter.Convert(target.baseLine).get_Item(0);

using DB.Grid revitGrid = curve switch
{
DB.Arc arc => DB.Grid.Create(_contextStack.Current.Document, arc),
DB.Line line => DB.Grid.Create(_contextStack.Current.Document, line),
_ => throw new SpeckleConversionException($"Grid line curve is of type {curve.GetType()} which is not supported")
};

if (!string.IsNullOrEmpty(target.label) && !GridNameIsTaken(target.label))
{
revitGrid.Name = target.label;
}

return revitGrid;
}

private bool GridNameIsTaken(string gridName)
{
using var collector = new DB.FilteredElementCollector(_contextStack.Current.Document);

IEnumerable<string> gridNames = collector
.WhereElementIsNotElementType()
.OfClass(typeof(DB.Grid))
.ToElements()
.Cast<DB.Grid>()
.Select(grid => grid.Name);

return gridNames.Contains(gridName);
}
}

0 comments on commit 7451d8e

Please sign in to comment.