From 923e04794f66a9f29e021de4248ea0cf8f69fc7d Mon Sep 17 00:00:00 2001 From: Matteo Cominetti Date: Tue, 15 Nov 2022 18:27:16 +0000 Subject: [PATCH] feat(mappings): family instance (#1862) * feat(mappings): add support for family instances from points or blocks * feat(dui): safety check when opening views --- .../UI/MappingBindingsRhino.cs | 79 ++++++------ .../DesktopUI2/ViewModels/CommentViewModel.cs | 30 ++++- .../MappingTool/MappingsViewModel.cs | 17 ++- .../ViewModels/MappingTool/Schemas.cs | 11 ++ .../DesktopUI2/Views/MappingsControl.xaml | 6 +- .../ConverterRhinoGh.Other.cs | 59 +++++---- .../ConverterRhinoGh.cs | 19 ++- Objects/Objects/Other/Transform.cs | 119 +++++++++++------- 8 files changed, 218 insertions(+), 122 deletions(-) diff --git a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/MappingBindingsRhino.cs b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/MappingBindingsRhino.cs index 4c66f40448..4f300f3ca1 100644 --- a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/MappingBindingsRhino.cs +++ b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/MappingBindingsRhino.cs @@ -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 { @@ -89,43 +90,49 @@ private List 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; diff --git a/DesktopUI2/DesktopUI2/ViewModels/CommentViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/CommentViewModel.cs index a4ac43657c..3d895f0a23 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/CommentViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/CommentViewModel.cs @@ -1,4 +1,5 @@ -using ReactiveUI; +using DesktopUI2.Views; +using ReactiveUI; using Speckle.Core.Api; using Speckle.Core.Logging; using Splat; @@ -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() { { "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() { { "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() diff --git a/DesktopUI2/DesktopUI2/ViewModels/MappingTool/MappingsViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/MappingTool/MappingsViewModel.cs index 2ff918c826..49ab61a297 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/MappingTool/MappingsViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/MappingTool/MappingsViewModel.cs @@ -272,35 +272,42 @@ private void AddRevitInfoToSchema(List 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; diff --git a/DesktopUI2/DesktopUI2/ViewModels/MappingTool/Schemas.cs b/DesktopUI2/DesktopUI2/ViewModels/MappingTool/Schemas.cs index 1ec71187e4..5319aaa2e6 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/MappingTool/Schemas.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/MappingTool/Schemas.cs @@ -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"; diff --git a/DesktopUI2/DesktopUI2/Views/MappingsControl.xaml b/DesktopUI2/DesktopUI2/Views/MappingsControl.xaml index d0f0c65fe2..6f7f690d36 100644 --- a/DesktopUI2/DesktopUI2/Views/MappingsControl.xaml +++ b/DesktopUI2/DesktopUI2/Views/MappingsControl.xaml @@ -102,7 +102,7 @@ VerticalAlignment="Center" Foreground="Gray" Kind="InfoCircle" - ToolTip.Tip="Select a stream coming from Revit with types and levels then select how to map the currently selected objects when received in Revit" /> + ToolTip.Tip="Select a stream coming from Revit with types and levels then select some objects. CURRENT MAPPINGS: DirectShape from Brep and Mesh Wall from Extrusion Beam/Brace from Line Family Instance from Point or Block" /> + + + + diff --git a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.Other.cs b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.Other.cs index 556e439bf4..219414d26f 100644 --- a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.Other.cs +++ b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.Other.cs @@ -1,33 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; - -using Rhino.Geometry; +using Objects.Other; using Rhino.Display; using Rhino.DocObjects; +using Rhino.Geometry; using Rhino.Render; -using RH = Rhino.DocObjects; - -using Speckle.Core.Models; using Speckle.Core.Kits; -using Utilities = Speckle.Core.Models.Utilities; - -using Objects.Other; +using Speckle.Core.Models; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; using Arc = Objects.Geometry.Arc; using BlockDefinition = Objects.Other.BlockDefinition; using BlockInstance = Objects.Other.BlockInstance; -using DisplayStyle = Objects.Other.DisplayStyle; using Dimension = Objects.Other.Dimension; +using DisplayStyle = Objects.Other.DisplayStyle; using Hatch = Objects.Other.Hatch; using HatchLoop = Objects.Other.HatchLoop; using Line = Objects.Geometry.Line; using Plane = Objects.Geometry.Plane; using Point = Objects.Geometry.Point; using Polyline = Objects.Geometry.Polyline; +using RenderMaterial = Objects.Other.RenderMaterial; +using RH = Rhino.DocObjects; using Text = Objects.Other.Text; using Transform = Objects.Other.Transform; -using RenderMaterial = Objects.Other.RenderMaterial; +using Utilities = Speckle.Core.Models.Utilities; namespace Objects.Converter.RhinoGh { @@ -102,7 +99,7 @@ public Rhino.Render.RenderMaterial RenderMaterialToNative(RenderMaterial speckle { var commitInfo = GetCommitInfo(); var speckleName = $"{commitInfo} - {speckleMaterial.name}"; - + // check if the doc already has a material with speckle material name, or a previously created speckle material var existing = Doc.RenderMaterials.FirstOrDefault(x => x.Name == speckleMaterial.name); if (existing != null) @@ -113,7 +110,7 @@ public Rhino.Render.RenderMaterial RenderMaterialToNative(RenderMaterial speckle return existing; Rhino.Render.RenderMaterial rm; -//#if RHINO6 + //#if RHINO6 var rhinoMaterial = new RH.Material { Name = speckleName, @@ -122,7 +119,7 @@ public Rhino.Render.RenderMaterial RenderMaterialToNative(RenderMaterial speckle Transparency = 1 - speckleMaterial.opacity }; rm = Rhino.Render.RenderMaterial.CreateBasicMaterial(rhinoMaterial, Doc); -//#else + //#else //TODO Convert materials as PhysicallyBasedMaterial // var pbrRenderMaterial = RenderContentType.NewContentFromTypeId(ContentUuids.PhysicallyBasedMaterialType, Doc) as Rhino.Render.RenderMaterial; // RH.Material simulatedMaterial = pbrRenderMaterial.SimulatedMaterial(RenderTexture.TextureGeneration.Allow); @@ -136,8 +133,8 @@ public Rhino.Render.RenderMaterial RenderMaterialToNative(RenderMaterial speckle // // rm = Rhino.Render.RenderMaterial.FromMaterial(pbr.Material, Doc); // rm.Name = speckleName; -//#endif - + //#endif + Doc.RenderMaterials.Add(rm); return rm; @@ -149,11 +146,11 @@ public RenderMaterial RenderMaterialToSpeckle(RH.Material material) renderMaterial.name = material.Name ?? "default"; // default rhino material has no name or id #if RHINO6 - + renderMaterial.diffuse = material.DiffuseColor.ToArgb(); renderMaterial.emissive = material.EmissionColor.ToArgb(); renderMaterial.opacity = 1 - material.Transparency; - + // for some reason some default material transparency props are 1 when they shouldn't be - use this hack for now if ((renderMaterial.name.ToLower().Contains("glass") || renderMaterial.name.ToLower().Contains("gem")) && renderMaterial.opacity == 0) renderMaterial.opacity = 0.3; @@ -175,7 +172,7 @@ public RenderMaterial RenderMaterialToSpeckle(RH.Material material) renderMaterial.roughness = pbrMaterial.Roughness; } #endif - + return renderMaterial; } @@ -414,8 +411,8 @@ public DisplayMaterial RenderMaterialToDisplayMaterial(RenderMaterial material) var displayMaterial = new DisplayMaterial(rhinoMaterial); return displayMaterial; } - - + + public RenderMaterial DisplayMaterialToSpeckle(DisplayMaterial material) { var speckleMaterial = new RenderMaterial(); @@ -424,7 +421,7 @@ public RenderMaterial DisplayMaterialToSpeckle(DisplayMaterial material) speckleMaterial.opacity = 1.0 - material.Transparency; return speckleMaterial; } - + public Rhino.Geometry.Transform TransformToNative(Transform speckleTransform, string units = null) { var u = units ?? speckleTransform.units; @@ -459,7 +456,7 @@ public Transform TransformToSpeckle(Rhino.Geometry.Transform t, string units = n t.M30, t.M31, t.M32, t.M33 }; return new Transform(transformArray, ModelUnits); } - + // Text public Text TextToSpeckle(TextEntity text) { @@ -515,7 +512,7 @@ public TextEntity TextToNative(Text text) Base sourceAppProps = text[RhinoPropName] as Base; if (sourceAppProps != null) { - var scaleProps = new List() { + var scaleProps = new List() { "TextHeight" }; foreach (var scaleProp in scaleProps) { @@ -569,7 +566,7 @@ public Dimension DimensionToSpeckle(Rhino.Geometry.Dimension dimension) var angularDimension = new AngleDimension() { units = ModelUnits, measurement = (Math.PI / 180) * dimension.NumericValue }; angularDimension.position = PointToSpeckle(angularDimPoint); - angularDimension.measured = new List() { lineStart, lineEnd}; + angularDimension.measured = new List() { lineStart, lineEnd }; if (o.GetDisplayLines(o.DimensionStyle, o.DimensionScale, out Rhino.Geometry.Line[] lines, out Rhino.Geometry.Arc[] arcs)) { angularDimension.displayValue = lines.Select(l => LineToSpeckle(l) as ICurve).ToList(); @@ -616,7 +613,7 @@ public Dimension DimensionToSpeckle(Rhino.Geometry.Dimension dimension) _dimension.value = dimension.PlainText; _dimension.richText = dimension.RichText; _dimension.textPosition = PointToSpeckle(textPoint); - + // set rhino props var style = dimension.DimensionStyle.HasName ? dimension.DimensionStyle.Name : String.Empty; if (!string.IsNullOrEmpty(style)) props["DimensionStyleName"] = style; @@ -645,7 +642,7 @@ public Rhino.Geometry.Dimension RhinoDimensionToNative(Dimension dimension) DistanceDimension linearDimension = dimension as DistanceDimension; var start = PointToNative(linearDimension.measured[0]).Location; var end = PointToNative(linearDimension.measured[1]).Location; - bool isRotated = sourceAppProps["AnnotationType"] as string == AnnotationType.Rotated.ToString() ? true : false ; + bool isRotated = sourceAppProps["AnnotationType"] as string == AnnotationType.Rotated.ToString() ? true : false; if (isRotated) _dimension = LinearDimension.Create(AnnotationType.Rotated, dimensionStyle, plane, Vector3d.XAxis, start, end, position, 0); else @@ -705,7 +702,7 @@ public Rhino.Geometry.Dimension DimensionToNative(Dimension dimension) case LengthDimension o: switch (o.measured) { - case Line l: + case Line l: var radialLine = LineToNative(l); var radialDimension = RadialDimension.Create(style, AnnotationType.Radius, plane, radialLine.PointAtStart, radialLine.PointAtEnd, position); _dimension = radialDimension; diff --git a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs index 991eedd7b4..a9c51458cb 100644 --- a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs +++ b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs @@ -319,20 +319,37 @@ private Base MappingToSpeckle(string mapping, RhinoObject @object) var height = topCrv.PointAtStart.Z - bottomCrv.PointAtStart.Z; o.height = height; o.baseLine = CurveToSpeckle(bottomCrv); - break; + case RevitBeam o: o.baseLine = CurveToSpeckle((RH.Curve)@object.Geometry); break; + case RevitBrace o: o.baseLine = CurveToSpeckle((RH.Curve)@object.Geometry); break; + case DirectShape o: o.baseGeometries = new List { BrepToSpeckle((RH.Brep)@object.Geometry) }; break; + case FreeformElement o: o.baseGeometries = new List { BrepToSpeckle((RH.Brep)@object.Geometry) }; break; + + case FamilyInstance o: + if (@object.Geometry is Rhino.Geometry.Point p) + { + o.basePoint = PointToSpeckle(p); + } + else if (@object is InstanceObject) + { + var block = BlockInstanceToSpeckle(@object as InstanceObject); + o.basePoint = block.GetInsertionPoint(); + o.rotation = block.transform.rotationZ; + } + break; + default: break; } diff --git a/Objects/Objects/Other/Transform.cs b/Objects/Objects/Other/Transform.cs index f66a48aa7a..a7bd2006da 100644 --- a/Objects/Objects/Other/Transform.cs +++ b/Objects/Objects/Other/Transform.cs @@ -1,11 +1,14 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Objects.Geometry; +using Objects.Geometry; using Speckle.Core.Kits; using Speckle.Core.Logging; using Speckle.Core.Models; using Speckle.Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using Vector = Objects.Geometry.Vector; namespace Objects.Other { @@ -18,31 +21,57 @@ namespace Objects.Other /// public class Transform : Base { - public double[ ] value { get; set; } = { 1d, 0d, 0d, 0d, + public double[] value { get; set; } = { 1d, 0d, 0d, 0d, 0d, 1d, 0d, 0d, 0d, 0d, 1d, 0d, 0d, 0d, 0d, 1d }; public string units { get; set; } - [JsonIgnore] public double[ ] translation => value.Subset(3, 7, 11, 15); + [JsonIgnore] + public double[] translation => value.Subset(3, 7, 11, 15); + + [JsonIgnore] + public double rotationZ + { + + get + { + + var matrix = new Matrix4x4( + (float)value[0], (float)value[1], (float)value[2], (float)value[3], + (float)value[4], (float)value[5], (float)value[6], (float)value[7], + (float)value[8], (float)value[9], (float)value[10], (float)value[11], + (float)value[12], (float)value[13], (float)value[14], (float)value[15]); + + if (Matrix4x4.Decompose(matrix, out Vector3 _scale, out Quaternion _rotation, out Vector3 _translation)) + { + return Math.Acos(_rotation.W) * 2; + } + else + { + return 0; + } + } + } + - [JsonIgnore] public double[ ] scaling => value.Subset(0, 1, 2, 4, 5, 6, 8, 9, 10); + [JsonIgnore] public double[] scaling => value.Subset(0, 1, 2, 4, 5, 6, 8, 9, 10); [JsonIgnore] - public bool isIdentity => value[ 0 ] == 1d && value[ 5 ] == 1d && value[ 10 ] == 1d && value[ 15 ] == 1d && - value[ 1 ] == 0d && value[ 2 ] == 0d && value[ 3 ] == 0d && - value[ 4 ] == 0d && value[ 6 ] == 0d && value[ 7 ] == 0d && - value[ 8 ] == 0d && value[ 9 ] == 0d && value[ 11 ] == 0d && - value[ 12 ] == 0d && value[ 13 ] == 0d && value[ 14 ] == 0d; + public bool isIdentity => value[0] == 1d && value[5] == 1d && value[10] == 1d && value[15] == 1d && + value[1] == 0d && value[2] == 0d && value[3] == 0d && + value[4] == 0d && value[6] == 0d && value[7] == 0d && + value[8] == 0d && value[9] == 0d && value[11] == 0d && + value[12] == 0d && value[13] == 0d && value[14] == 0d; - [JsonIgnore] public bool isScaled => !( value[ 0 ] == 1d && value[ 5 ] == 1d && value[ 10 ] == 1d ); + [JsonIgnore] public bool isScaled => !(value[0] == 1d && value[5] == 1d && value[10] == 1d); public Transform() { } - public Transform(double[ ] value, string units = null) + public Transform(double[] value, string units = null) { this.value = value; this.units = units; @@ -56,10 +85,10 @@ public Transform(double[ ] value, string units = null) /// /// /// - public Transform(double[ ] x, double[ ] y, double[ ] z, double[ ] translation, string units = null) + public Transform(double[] x, double[] y, double[] z, double[] translation, string units = null) { this.units = units; - value = new[ ] + value = new[] { x[ 0 ], y[ 0 ], z[ 0 ], translation[ 0 ], x[ 1 ], y[ 1 ], z[ 1 ], translation[ 1 ], @@ -74,7 +103,7 @@ public Transform(double[ ] x, double[ ] y, double[ ] z, double[ ] translation, s /// The 3x3 sub-matrix /// The last column of the matrix (the last element being the divisor which is almost always 1) /// - public void Deconstruct(out double[ ] scaling, out double[ ] translation, out string units) + public void Deconstruct(out double[] scaling, out double[] translation, out string units) { scaling = this.scaling; translation = this.translation; @@ -86,12 +115,12 @@ public void Deconstruct(out double[ ] scaling, out double[ ] translation, out st /// public List ApplyToPoints(List points) { - if ( points.Count % 3 != 0 ) + if (points.Count % 3 != 0) throw new SpeckleException( $"Cannot apply transform as the points list is malformed: expected length to be multiple of 3"); var transformed = new List(points.Count); - for ( var i = 0; i < points.Count; i += 3 ) - transformed.AddRange(ApplyToPoint(new List(3) { points[ i ], points[ i + 1 ], points[ i + 2 ] })); + for (var i = 0; i < points.Count; i += 3) + transformed.AddRange(ApplyToPoint(new List(3) { points[i], points[i + 1], points[i + 2] })); return transformed; } @@ -102,8 +131,8 @@ public List ApplyToPoints(List points) public List ApplyToPoints(List points) { var transformed = new List(points.Count); - for ( var i = 0; i < points.Count; i++ ) - transformed.Add(ApplyToPoint(points[ i ])); + for (var i = 0; i < points.Count; i++) + transformed.Add(ApplyToPoint(points[i])); return transformed; } @@ -116,7 +145,7 @@ public Point ApplyToPoint(Point point) { var (x, y, z, units) = point; var newCoords = ApplyToPoint(new List { x, y, z }); - return new Point(newCoords[ 0 ], newCoords[ 1 ], newCoords[ 2 ], point.units, point.applicationId); + return new Point(newCoords[0], newCoords[1], newCoords[2], point.units, point.applicationId); } /// @@ -125,9 +154,9 @@ public Point ApplyToPoint(Point point) public List ApplyToPoint(List point) { var transformed = new List(); - for ( var i = 0; i < 16; i += 4 ) - transformed.Add(point[ 0 ] * value[ i ] + point[ 1 ] * value[ i + 1 ] + point[ 2 ] * value[ i + 2 ] + - value[ i + 3 ]); + for (var i = 0; i < 16; i += 4) + transformed.Add(point[0] * value[i] + point[1] * value[i + 1] + point[2] * value[i + 2] + + value[i + 3]); return new List(3) { @@ -142,7 +171,7 @@ public Vector ApplyToVector(Vector vector) { var newCoords = ApplyToVector(new List { vector.x, vector.y, vector.z }); - return new Geometry.Vector(newCoords[ 0 ], newCoords[ 1 ], newCoords[ 2 ], vector.units, vector.applicationId); + return new Geometry.Vector(newCoords[0], newCoords[1], newCoords[2], vector.units, vector.applicationId); } /// @@ -150,11 +179,11 @@ public Vector ApplyToVector(Vector vector) /// public List ApplyToVector(List vector) { - var newPoint = new List(4) {vector[ 0 ], vector[ 1 ], vector[ 2 ], 1}; + var newPoint = new List(4) { vector[0], vector[1], vector[2], 1 }; - for ( var i = 0; i < 16; i += 4 ) - newPoint[ i / 4 ] = newPoint[ 0 ] * value[ i ] + newPoint[ 1 ] * value[ i + 1 ] + - newPoint[ 2 ] * value[ i + 2 ]; + for (var i = 0; i < 16; i += 4) + newPoint[i / 4] = newPoint[0] * value[i] + newPoint[1] * value[i + 1] + + newPoint[2] * value[i + 2]; return new List(3) { newPoint[ 0 ], newPoint[ 1 ], newPoint[ 2 ] }; @@ -168,12 +197,12 @@ public List ApplyToCurves(List curves, out bool success) { success = true; var transformed = new List(); - foreach ( var curve in curves ) + foreach (var curve in curves) { - if ( curve is ITransformable c ) + if (curve is ITransformable c) { c.TransformTo(this, out ITransformable tc); - transformed.Add(( ICurve )tc); + transformed.Add((ICurve)tc); } else success = false; @@ -190,16 +219,16 @@ public List ApplyToCurves(List curves, out bool success) /// public static Transform operator *(Transform t1, Transform t2) { - var result = new double[ 16 ]; + var result = new double[16]; var row = 0; - for ( var i = 0; i < 16; i += 4 ) + for (var i = 0; i < 16; i += 4) { - for ( var j = 0; j < 4; j++ ) + for (var j = 0; j < 4; j++) { - result[ i + j ] = t1.value[ i ] * t2.value[ j ] + - t1.value[ i + 1 ] * t2.value[ j + 4 ] + - t1.value[ i + 2 ] * t2.value[ j + 8 ] + - t1.value[ i + 3 ] * t2.value[ j + 12 ]; + result[i + j] = t1.value[i] * t2.value[j] + + t1.value[i + 1] * t2.value[j + 4] + + t1.value[i + 2] * t2.value[j + 8] + + t1.value[i + 3] * t2.value[j + 12]; } } @@ -210,12 +239,12 @@ t1.value[ i + 2 ] * t2.value[ j + 8 ] + static class ArrayUtils { // create a subset from a specific list of indices - public static T[ ] Subset(this T[ ] array, params int[ ] indices) + public static T[] Subset(this T[] array, params int[] indices) { - var subset = new T[ indices.Length ]; - for ( var i = 0; i < indices.Length; i++ ) + var subset = new T[indices.Length]; + for (var i = 0; i < indices.Length; i++) { - subset[ i ] = array[ indices[ i ] ]; + subset[i] = array[indices[i]]; } return subset;