Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dui3/alpha' into DUI3-177-Levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor Ivy committed Jul 3, 2024
2 parents a8e8d1f + 7451d8e commit d974cef
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 @@ -38,6 +38,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\Geometry\VectorConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\BaseTopLevelConverterToHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\LevelToHostTopLevelConverter.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 d974cef

Please sign in to comment.