-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dui3/alpha' into DUI3-326-Add-Civil3d-2023-Converter
- Loading branch information
Showing
6 changed files
with
171 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.Common.Objects; | ||
using Speckle.Core.Models; | ||
|
||
namespace Speckle.Converters.RevitShared; | ||
|
||
public class RevitRootToHostConverter : IRootToHostConverter | ||
{ | ||
private readonly IConverterResolver<IToHostTopLevelConverter> _converterResolver; | ||
|
||
public RevitRootToHostConverter(IConverterResolver<IToHostTopLevelConverter> converterResolver) | ||
{ | ||
_converterResolver = converterResolver; | ||
} | ||
|
||
public object Convert(Base target) | ||
{ | ||
var objectConverter = _converterResolver.GetConversionForType(target.GetType()); | ||
|
||
if (objectConverter == null) | ||
{ | ||
throw new SpeckleConversionException($"No conversion found for {target.GetType().Name}"); | ||
} | ||
|
||
return objectConverter.Convert(target) | ||
?? throw new SpeckleConversionException($"Conversion of object with type {target.GetType()} returned null"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...s/Revit/Speckle.Converters.RevitShared/ToHost/TopLevel/GridlineToHostTopLevelConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...ters/Revit/Speckle.Converters.RevitShared/ToHost/TopLevel/LevelToHostTopLevelConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.RevitShared.Helpers; | ||
using Speckle.Converters.RevitShared.ToSpeckle; | ||
using Speckle.Converters.RevitShared.Services; | ||
|
||
namespace Speckle.Converters.RevitShared.ToHost.ToLevel; | ||
|
||
[NameAndRankValue(nameof(SOBE.Level), 0)] | ||
public class LevelToHostTopLevelConverter : BaseTopLevelConverterToHost<SOBE.Level, DB.Level> | ||
{ | ||
private readonly IRevitConversionContextStack _contextStack; | ||
private readonly ScalingServiceToHost _scalingService; | ||
|
||
public LevelToHostTopLevelConverter(IRevitConversionContextStack contextStack, ScalingServiceToHost scalingService) | ||
{ | ||
_contextStack = contextStack; | ||
_scalingService = scalingService; | ||
} | ||
|
||
public override DB.Level Convert(SOBE.Level target) | ||
{ | ||
using var documentLevelCollector = new DB.FilteredElementCollector(_contextStack.Current.Document); | ||
var docLevels = documentLevelCollector.OfClass(typeof(DB.Level)).ToElements().Cast<DB.Level>(); | ||
|
||
// POC : I'm not really understanding the linked use case for this. Do we want to bring this over? | ||
|
||
//bool elevationMatch = true; | ||
////level by name component | ||
//if (target is RevitLevel speckleRevitLevel && speckleRevitLevel.referenceOnly) | ||
//{ | ||
// //see: https://speckle.community/t/revit-connector-levels-and-spaces/2824/5 | ||
// elevationMatch = false; | ||
// if (GetExistingLevelByName(docLevels, target.name) is DB.Level existingLevelWithSameName) | ||
// { | ||
// return existingLevelWithSameName; | ||
// } | ||
//} | ||
|
||
DB.Level revitLevel; | ||
var targetElevation = _scalingService.ScaleToNative(target.elevation, target.units); | ||
|
||
if (GetExistingLevelByElevation(docLevels, targetElevation) is DB.Level existingLevel) | ||
{ | ||
revitLevel = existingLevel; | ||
} | ||
else | ||
{ | ||
revitLevel = DB.Level.Create(_contextStack.Current.Document, targetElevation); | ||
revitLevel.Name = target.name; | ||
|
||
if (target is SOBR.RevitLevel rl && rl.createView) | ||
{ | ||
using var viewPlan = CreateViewPlan(target.name, revitLevel.Id); | ||
} | ||
} | ||
|
||
return revitLevel; | ||
} | ||
|
||
private static DB.Level GetExistingLevelByElevation(IEnumerable<DB.Level> docLevels, double elevation) | ||
{ | ||
return docLevels.FirstOrDefault(l => Math.Abs(l.Elevation - elevation) < RevitConversionContextStack.TOLERANCE); | ||
} | ||
|
||
private DB.ViewPlan CreateViewPlan(string name, DB.ElementId levelId) | ||
{ | ||
using var collector = new DB.FilteredElementCollector(_contextStack.Current.Document); | ||
var vt = collector | ||
.OfClass(typeof(DB.ViewFamilyType)) | ||
.First(el => ((DB.ViewFamilyType)el).ViewFamily == DB.ViewFamily.FloorPlan); | ||
|
||
var view = DB.ViewPlan.Create(_contextStack.Current.Document, vt.Id, levelId); | ||
view.Name = name; | ||
|
||
return view; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters