Skip to content

Commit

Permalink
Updates dev with changes in main (#2816)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanRynne authored Aug 4, 2023
2 parents a669b50 + 799cdd0 commit b0c6987
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 71 deletions.
16 changes: 12 additions & 4 deletions ConnectorRevit/ConnectorRevit/TypeMapping/ElementTypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private async Task<bool> ShouldShowCustomMappingDialog(string listBoxSelection,
{
return true;
}
else if (listBoxSelection == ConnectorBindingsRevit.forNewTypes && numNewTypes > 0)
else if (listBoxSelection == ConnectorBindingsRevit.forNewTypes && numNewTypes > 0)
{
return true;
}
Expand All @@ -130,12 +130,20 @@ private async Task<bool> ShouldShowCustomMappingDialog(string listBoxSelection,

private static async Task<bool> ShowMissingIncomingTypesDialog()
{
return await Dispatcher.UIThread.InvokeAsync<bool>(() =>
var response = await Dispatcher.UIThread.InvokeAsync<bool>(() =>
{
Analytics.TrackEvent(Analytics.Events.DUIAction, new Dictionary<string, object> { { "name", "Type Map" }, { "method", "Missing Types Dialog" } });
var mappingView = new MissingIncomingTypesDialog();
return mappingView.ShowDialog<bool>();
return mappingView.ShowDialog<bool>(); ;
}).ConfigureAwait(false);

if (response)
Analytics.TrackEvent(Analytics.Events.DUIAction, new Dictionary<string, object> { { "name", "Type Map" }, { "method", "Dialog Accept" } });
else
Analytics.TrackEvent(Analytics.Events.DUIAction, new Dictionary<string, object> { { "name", "Type Map" }, { "method", "Dialog Ignore" } });


return response;
}

private async Task ShowCustomMappingDialog(TypeMap? currentMapping, HostTypeContainer hostTypesContainer, int numNewTypes)
Expand Down Expand Up @@ -271,7 +279,7 @@ public HostTypeContainer GetHostTypesAndAddIncomingTypes(TypeMap currentTypeMap,
{
var settings = new JsonSerializerSettings
{
Converters = {
Converters = {
new AbstractConverter<RevitMappingValue, ISingleValueToMap>(),
new AbstractConverter<RevitHostType, ISingleHostType>(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public override void PreviewSend(StreamState state, ProgressViewModel progress)
try
{
var converter = (ISpeckleConverter)Activator.CreateInstance(Converter.GetType());
var filterObjs = GetSelectionFilterObjectsWithDesignOptions(converter, state.Filter);
var filterObjs = GetSelectionFilterObjects(converter, state.Filter);
foreach (var filterObj in filterObjs)
{
var descriptor = ConnectorRevitUtils.ObjectDescriptor(filterObj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,6 @@ private List<Document> GetLinkedDocuments()
return docs;
}

/// <summary>
/// Given the filter in use by a stream returns the document elements that match it.
/// The elements returned are filtered by Design Option based on setting value
/// </summary>
/// <param name="filter"></param>
/// <returns></returns>
private List<Element> GetSelectionFilterObjectsWithDesignOptions(
ISpeckleConverter converter,
ISelectionFilter filter
)
{
var selection = GetSelectionFilterObjects(converter, filter);

if (filter.Slug != "manual")
{
selection = FilterHiddenDesignOptions(selection);
}

return selection;
}

private static List<Element> FilterHiddenDesignOptions(List<Element> selection)
{
using var collector = new FilteredElementCollector(CurrentDoc.Document);
Expand Down Expand Up @@ -265,16 +244,31 @@ private List<Element> GetSelectionFilterObjects(ISpeckleConverter converter, ISe
return GetManualSelection(filter, allDocs);

case "all":
return GetEverything(currentDoc, allDocs);
selection = GetEverything(currentDoc, allDocs);
return FilterHiddenDesignOptions(selection);

case "category":
return GetSelectionByCategory(filter, currentDoc, allDocs);
selection = GetSelectionByCategory(filter, currentDoc, allDocs);
return FilterHiddenDesignOptions(selection);

case "filter":
return GetSelectionByFilter(filter, allDocs);
selection = GetSelectionByFilter(filter, allDocs);
return FilterHiddenDesignOptions(selection);

case "view":
return GetSelectionByView(converter, filter, currentDoc, allDocs);
var selectedViews = GetSelectedViews(filter, currentDoc);
selection = GetSelectionFromViews(selectedViews, allDocs);
if (selectedViews.Count == 1)
{
// if the user is sending a single view, then we pass it to the converter in order for the converter
// to retreive element meshes that are specific to that view
converter.SetContextDocument(selectedViews[0]);
return selection;
}
else
{
return FilterHiddenDesignOptions(selection);
}

case "schedule":
return GetScheduleSelection(filter, currentDoc);
Expand All @@ -283,10 +277,14 @@ private List<Element> GetSelectionFilterObjects(ISpeckleConverter converter, ISe
return GetSelectionByProjectInfo(filter, currentDoc);

case "workset":
return GetSelectionByWorkset(filter, currentDoc, allDocs);
selection = GetSelectionByWorkset(filter, currentDoc, allDocs);
return FilterHiddenDesignOptions(selection);

case "param":
return GetSelectionByParameter(filter, allDocs, selection);

default:
throw new SpeckleException($"Unknown ISelectionFilterSlug, {filter.Slug}");
}
}
catch (Exception ex)
Expand All @@ -296,8 +294,6 @@ private List<Element> GetSelectionFilterObjects(ISpeckleConverter converter, ISe
ex
);
}

return selection;
}

private static List<Element> GetManualSelection(ISelectionFilter filter, List<Document> allDocs)
Expand Down Expand Up @@ -433,33 +429,12 @@ private static List<Element> GetSelectionByFilter(ISelectionFilter filter, List<
return selection;
}

private static List<Element> GetSelectionByView(
ISpeckleConverter converter,
ISelectionFilter filter,
Document currentDoc,
private static List<Element> GetSelectionFromViews(
List<View> views,
List<Document> allDocs
)
{
var selection = new List<Element>();
var viewFilter = filter as ListSelectionFilter;
using var collector = new FilteredElementCollector(currentDoc);
using var scheduleExclusionFilter = new ElementClassFilter(typeof(ViewSchedule), true);
var views = collector
.WhereElementIsNotElementType()
.OfClass(typeof(View))
.WherePasses(scheduleExclusionFilter)
.Cast<View>()
.Where(x => viewFilter.Selection.Contains(x.Title))
.Where(x => !x.IsTemplate)
.ToList();

// if the user is sending a single view, then we pass it to the converter in order for the converter
// to retreive element meshes that are specific to that view
if (views.Count == 1)
{
converter.SetContextDocument(views[0]);
}

foreach (var view in views)
{
selection.Add(view);
Expand All @@ -481,6 +456,22 @@ List<Document> allDocs
return selection;
}

private static List<View> GetSelectedViews(ISelectionFilter filter, Document currentDoc)
{
var selection = new List<Element>();
var viewFilter = filter as ListSelectionFilter;
using var collector = new FilteredElementCollector(currentDoc);
using var scheduleExclusionFilter = new ElementClassFilter(typeof(ViewSchedule), true);
return collector
.WhereElementIsNotElementType()
.OfClass(typeof(View))
.WherePasses(scheduleExclusionFilter)
.Cast<View>()
.Where(x => viewFilter.Selection.Contains(x.Title))
.Where(x => !x.IsTemplate)
.ToList();
}

private static List<Element> GetScheduleSelection(ISelectionFilter filter, Document currentDoc)
{
var selection = new List<Element>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override async Task<string> SendStream(StreamState state, ProgressViewMod
var streamId = state.StreamId;
var client = state.Client;

var selectedObjects = GetSelectionFilterObjectsWithDesignOptions(converter, state.Filter);
var selectedObjects = GetSelectionFilterObjects(converter, state.Filter);
state.SelectedObjectIds = selectedObjects.Select(x => x.UniqueId).ToList();

if (!selectedObjects.Any())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System;
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

using Autodesk.Revit.DB;
using DB = Autodesk.Revit.DB;

using Speckle.Core.Models;

using Objects.Geometry;
using Objects.Other;
using Speckle.Core.Models.Extensions;
using BlockInstance = Objects.Other.BlockInstance;
using Transform = Objects.Other.Transform;
using Mesh = Objects.Geometry.Mesh;
Expand All @@ -18,7 +16,7 @@ namespace Objects.Converter.Revit
{
public partial class ConverterRevit
{
public ApplicationObject BlockInstanceToNative(BlockInstance instance, Transform transform = null)
public ApplicationObject? BlockInstanceToNative(BlockInstance instance, Transform? transform = null)
{
var docObj = GetExistingElementByApplicationId(instance.applicationId);
var appObj = new ApplicationObject(instance.id, instance.speckle_type) { applicationId = instance.applicationId };
Expand Down Expand Up @@ -52,6 +50,7 @@ public ApplicationObject BlockInstanceToNative(BlockInstance instance, Transform
var meshes = new List<Mesh>();
var curves = new List<DB.Curve>();
var blocks = new List<BlockInstance>();

foreach (var geometry in instance.typedDefinition.geometry)
{
switch (geometry)
Expand All @@ -65,6 +64,7 @@ public ApplicationObject BlockInstanceToNative(BlockInstance instance, Transform
appObj.Update(logItem: $"Could not convert block brep to native, using mesh fallback value instead");
meshes.AddRange(tbrep.displayValue);
}

break;
case Mesh mesh:
mesh.TransformTo(transform, out Mesh tmesh);
Expand All @@ -86,18 +86,32 @@ public ApplicationObject BlockInstanceToNative(BlockInstance instance, Transform
{
appObj.Update(logItem: $"Could not convert block curve to native: {e.Message}");
}

break;
case BlockInstance blk:
blocks.Add(blk);
break;
case { }:
var displayValue = geometry.GetDetachedProp("displayValue") as IList ?? Array.Empty<object>();
foreach (var d in displayValue)
{
if (d is Mesh m)
{
m.TransformTo(transform, out Mesh tm);
meshes.Add(tm);
}
//TODO: Ideally, we'd support more geometry types here too, but this switch statement is getting messy!
}
break;
}
}

var ids = new List<ElementId>();
int skippedBreps = breps.Count;
breps.ForEach(o =>
{
var ds = TryDirectShapeToNative(o, ToNativeMeshSettingEnum.Default).Converted.FirstOrDefault() as DB.DirectShape;
var ds =
TryDirectShapeToNative(o, ToNativeMeshSettingEnum.Default).Converted.FirstOrDefault() as DB.DirectShape;
if (ds != null)
{
ids.Add(ds.Id);
Expand All @@ -108,12 +122,13 @@ public ApplicationObject BlockInstanceToNative(BlockInstance instance, Transform
int skippedMeshes = meshes.Count;
meshes.ForEach(o =>
{
var ds = TryDirectShapeToNative(o, ToNativeMeshSettingEnum.Default).Converted.FirstOrDefault() as DB.DirectShape;
var ds =
TryDirectShapeToNative(o, ToNativeMeshSettingEnum.Default).Converted.FirstOrDefault() as DB.DirectShape;
if (ds != null)
{
ids.Add(ds.Id);
skippedMeshes--;
}
}
});

int skippedCurves = curves.Count;
Expand Down Expand Up @@ -150,16 +165,25 @@ public ApplicationObject BlockInstanceToNative(BlockInstance instance, Transform
try
{
group = Doc.Create.NewGroup(ids);
group.GroupType.Name = $"SpeckleBlock_{RemoveProhibitedCharacters(instance.typedDefinition.name)}_{instance.applicationId ?? instance.id}";
string skipped = $"{(skippedBreps > 0 ? $"{skippedBreps} breps " : "")}{(skippedMeshes > 0 ? $"{skippedMeshes} meshes " : "")}{(skippedCurves > 0 ? $"{skippedCurves} curves " : "")}{(skippedBlocks > 0 ? $"{skippedBlocks} blocks " : "")}";
if (!string.IsNullOrEmpty(skipped)) appObj.Update(logItem: $"Skipped {skipped}");
group.GroupType.Name =
$"SpeckleBlock_{RemoveProhibitedCharacters(instance.typedDefinition.name)}_{instance.applicationId ?? instance.id}";
string skipped =
$"{(skippedBreps > 0 ? $"{skippedBreps} breps " : "")}{(skippedMeshes > 0 ? $"{skippedMeshes} meshes " : "")}{(skippedCurves > 0 ? $"{skippedCurves} curves " : "")}{(skippedBlocks > 0 ? $"{skippedBlocks} blocks " : "")}";
if (!string.IsNullOrEmpty(skipped))
appObj.Update(logItem: $"Skipped {skipped}");
var state = isUpdate ? ApplicationObject.State.Updated : ApplicationObject.State.Created;
appObj.Update(status: state, createdId: group.UniqueId, convertedItem: group, logItem: $"Assigned name: {group.GroupType.Name}");
appObj.Update(
status: state,
createdId: group.UniqueId,
convertedItem: group,
logItem: $"Assigned name: {group.GroupType.Name}"
);
}
catch
{
appObj.Update(status: ApplicationObject.State.Failed, logItem: $"Group could not be created");
}

return appObj;
}
}
Expand Down

0 comments on commit b0c6987

Please sign in to comment.