From e780b2d3d5acfc84a6920483fd6015174812f38c Mon Sep 17 00:00:00 2001 From: Claire Kuang Date: Tue, 14 Nov 2023 08:47:16 +0000 Subject: [PATCH] refactor(rhino): removes DirectShapeToNative conversion (#3042) * uses basegeometries instead of displayvalue for ds rhino receive * removes directshape conversion --- .../UI/ConnectorBindingsRhino.Receive.cs | 23 +++++++++----- .../ConverterRhinoGh.BuiltElements.cs | 31 ------------------- .../ConverterRhinoGh.cs | 5 --- .../BuiltElements/Revit/DirectShape.cs | 2 +- 4 files changed, 17 insertions(+), 44 deletions(-) diff --git a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Receive.cs b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Receive.cs index 4a490669dd..977307967f 100644 --- a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Receive.cs +++ b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Receive.cs @@ -480,12 +480,16 @@ private void BakeObject( var attributes = new ObjectAttributes(); // handle display style - if (obj[@"displayStyle"] is Base display) + Base display = obj["displayStyle"] as Base ?? obj["@displayStyle"] as Base; + Base render = obj["renderMaterial"] as Base ?? obj["@renderMaterial"] as Base; + if (display != null) { if (converter.ConvertToNative(display) is ObjectAttributes displayAttribute) + { attributes = displayAttribute; + } } - else if (obj[@"renderMaterial"] is Base renderMaterial) + else if (render != null) { attributes.ColorSource = ObjectColorSource.ColorFromMaterial; } @@ -527,23 +531,28 @@ private void BakeObject( } if (parent != null) + { parent.Update(id.ToString()); + } else + { appObj.Update(id.ToString()); + } bakedCount++; // handle render material - if (obj[@"renderMaterial"] is Base render) + if (render != null) { - var convertedMaterial = converter.ConvertToNative(render); //Maybe wrap in try catch in case no conversion exists? - if (convertedMaterial is RenderMaterial rm) + var convertedMaterial = converter.ConvertToNative(render) as RenderMaterial; //Maybe wrap in try catch in case no conversion exists? + if (convertedMaterial != null) { - var rhinoObject = Doc.Objects.FindId(id); - rhinoObject.RenderMaterial = rm; + RhinoObject rhinoObject = Doc.Objects.FindId(id); + rhinoObject.RenderMaterial = convertedMaterial; rhinoObject.CommitChanges(); } } + break; case RhinoObject o: // this was prbly a block instance, baked during conversion diff --git a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs index d75605e793..664f30dd16 100644 --- a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs +++ b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs @@ -151,37 +151,6 @@ private RhinoViewport SetViewParams(RhinoViewport viewport, Base speckleView) return viewport; } - // direct shape - public List DirectShapeToNative(RV.DirectShape directShape, out List log) - { - log = new List(); - if (directShape.displayValue == null) - { - log.Add($"Skipping DirectShape {directShape.id} because it has no {nameof(directShape.displayValue)}"); - return null; - } - - if (directShape.displayValue.Count == 0) - { - log.Add($"Skipping DirectShape {directShape.id} because {nameof(directShape.displayValue)} was empty"); - return null; - } - - IEnumerable subObjects = directShape.displayValue.Select(ConvertToNative).Where(e => e != null); - - var nativeObjects = subObjects.ToList(); - - if (nativeObjects.Count == 0) - { - log.Add( - $"Skipping DirectShape {directShape.id} because {nameof(directShape.displayValue)} contained no convertable elements" - ); - return null; - } - - return nativeObjects; - } - // level public ApplicationObject LevelToNative(Level level) { diff --git a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs index 29c4e314bf..876058992f 100644 --- a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs +++ b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs @@ -473,10 +473,6 @@ public object ConvertToNative(Base @object) rhinoObj = CurveToNative(o.baseCurve); break; - case DirectShape o: - rhinoObj = DirectShapeToNative(o, out notes); - break; - case View3D o: rhinoObj = ViewToNative(o); break; @@ -675,7 +671,6 @@ public bool CanConvertToNative(Base @object) // This types are not supported in GH! case Pointcloud _: case ModelCurve _: - case DirectShape _: case View3D _: case Instance _: case GridLine _: diff --git a/Objects/Objects/BuiltElements/Revit/DirectShape.cs b/Objects/Objects/BuiltElements/Revit/DirectShape.cs index 80870b09aa..12f8dd8caf 100644 --- a/Objects/Objects/BuiltElements/Revit/DirectShape.cs +++ b/Objects/Objects/BuiltElements/Revit/DirectShape.cs @@ -47,7 +47,7 @@ public DirectShape(string name, string builtInCategory, List baseGeometrie public string elementId { get; set; } [DetachProperty] - public List baseGeometries { get; set; } + public List baseGeometries { get; set; } = new(); public string units { get; set; }