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

Dui3 178 gridlines #3554

Merged
merged 1 commit into from
Jul 3, 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 @@ -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);
}
}
Loading