Skip to content

Commit

Permalink
feat(mappings): family instance (#1862)
Browse files Browse the repository at this point in the history
* feat(mappings): add support for family instances from points or blocks

* feat(dui): safety check when opening views
  • Loading branch information
teocomi authored Nov 15, 2022
1 parent 7dca3d1 commit 923e047
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using Speckle.Newtonsoft.Json;
using static DesktopUI2.ViewModels.MappingViewModel;
using ApplicationObject = Speckle.Core.Models.ApplicationObject;
using Point = Rhino.Geometry.Point;

namespace SpeckleRhino
{
Expand Down Expand Up @@ -89,43 +90,49 @@ private List<Schema> GetObjectSchemas(RhinoObject obj)
if (existingSchema != null)
result.Add(existingSchema);


switch (obj.Geometry)
if (obj is InstanceObject)
{
result.Add(new RevitFamilyInstanceViewModel());
}
else
{
case Mesh m:
if (!result.Any(x => typeof(DirectShapeFreeformViewModel) == x.GetType()))
result.Add(new DirectShapeFreeformViewModel());
break;

case Brep b:
if (!result.Any(x => typeof(DirectShapeFreeformViewModel) == x.GetType()))
result.Add(new DirectShapeFreeformViewModel());
break;
//case Brep b:
// if (b.IsSurface) cats.Add(DirectShape); // TODO: Wall by face, totally faking it right now
// else cats.Add(DirectShape);
// break;
case Extrusion e:
if (e.ProfileCount > 1) break;
var crv = e.Profile3d(new ComponentIndex(ComponentIndexType.ExtrusionBottomProfile, 0));
if (!(crv.IsLinear() || crv.IsArc())) break;
if (crv.PointAtStart.Z != crv.PointAtEnd.Z) break;

if (!result.Any(x => typeof(RevitWallViewModel) == x.GetType()))
result.Add(new RevitWallViewModel());
break;

case Curve c:
if (c.IsLinear())
{
result.Add(new RevitBeamViewModel());
result.Add(new RevitBraceViewModel());
}

//if (c.IsLinear() && c.PointAtEnd.Z == c.PointAtStart.Z) cats.Add(Gridline);
//if (c.IsLinear() && c.PointAtEnd.X == c.PointAtStart.X && c.PointAtEnd.Y == c.PointAtStart.Y) cats.Add(Column);
//if (c.IsArc() && !c.IsCircle() && c.PointAtEnd.Z == c.PointAtStart.Z) cats.Add(Gridline);
break;
switch (obj.Geometry)
{
case Mesh m:
if (!result.Any(x => typeof(DirectShapeFreeformViewModel) == x.GetType()))
result.Add(new DirectShapeFreeformViewModel());
break;

case Brep b:
if (!result.Any(x => typeof(DirectShapeFreeformViewModel) == x.GetType()))
result.Add(new DirectShapeFreeformViewModel());
break;
case Extrusion e:
if (e.ProfileCount > 1) break;
var crv = e.Profile3d(new ComponentIndex(ComponentIndexType.ExtrusionBottomProfile, 0));
if (!(crv.IsLinear() || crv.IsArc())) break;
if (crv.PointAtStart.Z != crv.PointAtEnd.Z) break;

if (!result.Any(x => typeof(RevitWallViewModel) == x.GetType()))
result.Add(new RevitWallViewModel());
break;

case Curve c:
if (c.IsLinear())
{
result.Add(new RevitBeamViewModel());
result.Add(new RevitBraceViewModel());
}

//if (c.IsLinear() && c.PointAtEnd.Z == c.PointAtStart.Z) cats.Add(Gridline);
//if (c.IsLinear() && c.PointAtEnd.X == c.PointAtStart.X && c.PointAtEnd.Y == c.PointAtStart.Y) cats.Add(Column);
//if (c.IsArc() && !c.IsCircle() && c.PointAtEnd.Z == c.PointAtStart.Z) cats.Add(Gridline);
break;

case Point p:
result.Add(new RevitFamilyInstanceViewModel());
break;
}
}

return result;
Expand Down
30 changes: 27 additions & 3 deletions DesktopUI2/DesktopUI2/ViewModels/CommentViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ReactiveUI;
using DesktopUI2.Views;
using ReactiveUI;
using Speckle.Core.Api;
using Speckle.Core.Logging;
using Splat;
Expand Down Expand Up @@ -73,8 +74,31 @@ public CommentViewModel(CommentItem item, string streamId, Client client)

public void OpenCommentView()
{
Bindings.Open3DView(Comment.data.camPos, Comment.id);
Analytics.TrackEvent(Analytics.Events.DUIAction, new Dictionary<string, object>() { { "name", "Comment Open 3D View" } });
try
{
if (Comment.data != null && Comment.data.camPos != null)
{
Bindings.Open3DView(Comment.data.camPos, Comment.id);
Analytics.TrackEvent(Analytics.Events.DUIAction, new Dictionary<string, object>() { { "name", "Comment Open 3D View" } });
return;
}
}
catch (Exception ex)
{

}

//something went wrong
Avalonia.Threading.Dispatcher.UIThread.Post(() =>
{
MainUserControl.NotificationManager.Show(new PopUpNotificationViewModel()
{
Title = "Could not open view!",
Message = "Something went wrong",
Type = Avalonia.Controls.Notifications.NotificationType.Error,
});
});

}

public void OpenComment()
Expand Down
17 changes: 12 additions & 5 deletions DesktopUI2/DesktopUI2/ViewModels/MappingTool/MappingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,35 +272,42 @@ private void AddRevitInfoToSchema(List<Schema> schemas)
var wallFamilies = AvailableRevitTypes.Where(x => x.category == "Walls").ToList();
if (!wallFamilies.Any() || !AvailableRevitLevels.Any())
break;

var wallFamiliesViewModels = wallFamilies.GroupBy(x => x.family).Select(g => new RevitFamily(g.Key.ToString(), g.Select(y => y.type).ToList())).ToList();
o.Families = wallFamiliesViewModels;
o.Levels = AvailableRevitLevels;
updatedSchemas.Add(o);

break;

case RevitBeamViewModel o:
var beamFamilies = AvailableRevitTypes.Where(x => x.category == "Structural Framing").ToList();
if (!beamFamilies.Any() || !AvailableRevitLevels.Any())
break;

var beamFamiliesViewModels = beamFamilies.GroupBy(x => x.family).Select(g => new RevitFamily(g.Key.ToString(), g.Select(y => y.type).ToList())).ToList();
o.Families = beamFamiliesViewModels;
o.Levels = AvailableRevitLevels;
updatedSchemas.Add(o);

break;

case RevitBraceViewModel o:
var braceFamilies = AvailableRevitTypes.Where(x => x.category == "Structural Framing").ToList();
if (!braceFamilies.Any() || !AvailableRevitLevels.Any())
break;

var braceFamiliesViewModels = braceFamilies.GroupBy(x => x.family).Select(g => new RevitFamily(g.Key.ToString(), g.Select(y => y.type).ToList())).ToList();
o.Families = braceFamiliesViewModels;
o.Levels = AvailableRevitLevels;
updatedSchemas.Add(o);
break;

case RevitFamilyInstanceViewModel o:
var fiFamilies = AvailableRevitTypes.Where(x => x.placementType == "OneLevelBased").ToList();
if (!fiFamilies.Any() || !AvailableRevitLevels.Any())
break;
var fiFamiliesViewModels = fiFamilies.GroupBy(x => x.family).Select(g => new RevitFamily(g.Key.ToString(), g.Select(y => y.type).ToList())).ToList();
o.Families = fiFamiliesViewModels;
o.Levels = AvailableRevitLevels;
updatedSchemas.Add(o);
break;

case DirectShapeFreeformViewModel o:
updatedSchemas.Add(o);
break;
Expand Down
11 changes: 11 additions & 0 deletions DesktopUI2/DesktopUI2/ViewModels/MappingTool/Schemas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ public override string GetSerializedSchema()
}
}

public class RevitFamilyInstanceViewModel : RevitBasicViewModel
{
public override string Name => "Family Instance";

public override string GetSerializedSchema()
{
var obj = new FamilyInstance(null, SelectedFamily.Name, SelectedType, new RevitLevel(SelectedLevel));
return Operations.Serialize(obj);
}
}

public class DirectShapeFreeformViewModel : Schema
{
public override string Name => "DirectShape";
Expand Down
6 changes: 5 additions & 1 deletion DesktopUI2/DesktopUI2/Views/MappingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
VerticalAlignment="Center"
Foreground="Gray"
Kind="InfoCircle"
ToolTip.Tip="Select a stream coming from Revit with types and levels&#x0a;then select how to map the currently selected objects&#x0a;when received in Revit" />
ToolTip.Tip="Select a stream coming from Revit with types and levels&#x0a;then select some objects.&#x0a;&#x0a;CURRENT MAPPINGS:&#x0a;DirectShape from Brep and Mesh&#x0a;Wall from Extrusion&#x0a;Beam/Brace from Line&#x0a;Family Instance from Point or Block" />
<TextBlock
Margin="5,0"
VerticalAlignment="Center"
Expand Down Expand Up @@ -174,6 +174,10 @@
<DataTemplate DataType="{x:Type s:RevitBraceViewModel}">
<map:RevitBasic />
</DataTemplate>
<!-- FAMILY INSTANCE -->
<DataTemplate DataType="{x:Type s:RevitFamilyInstanceViewModel}">
<map:RevitBasic />
</DataTemplate>
<!-- DIRECTSHAPE -->
<DataTemplate DataType="{x:Type s:DirectShapeFreeformViewModel}">
<StackPanel Orientation="Vertical" Spacing="5">
Expand Down
Loading

0 comments on commit 923e047

Please sign in to comment.