From 65ea64323464b6b25d409fc1198dfe2d2939a622 Mon Sep 17 00:00:00 2001 From: Reynold Chan Date: Tue, 19 Jul 2022 05:08:20 -0400 Subject: [PATCH] feat(Tekla Structures + Revit) Tekla structures mesh conversion revit (#1421) * WIP Convert direct meshes from Tekla To Revit * no message * commit save for T4 for csproj * xml gen working * T4 xml file generation working for Tekla Structures * fully functioning objects for direct mesh conversion if direct mesh exist * WIP (feat) Tekla Structures recieving Meshes * Finish Tekla Recieving Meshes Direct Shapes * Fixes for receiving as direct mesh in Tekla Structures * Method to set OST category of DirectMesh * fix merge Co-authored-by: Alan Rynne Co-authored-by: Erron Estrado <92844367+eestrado@users.noreply.github.com> --- .../ConnectorBindingsRevit2 .Settings.cs | 1 + .../ConnectorBindingsRevit2.Receive.cs | 1 - .../ConnectorTeklaStructures2021.csproj | 13 ++ .../ConnectorTeklaStructures2021/Manifest.xml | 38 ++++ .../ManifestGenerator.tt | 56 ++++++ .../ManifestGenerator.xml | 141 ++++++++++++++ .../ConnectorTeklaStructuresShared.projitems | 1 + .../ConnectorBindingsTeklaStructure.Send.cs | 9 + ...onnectorBindingsTeklaStructure.Settings.cs | 23 +++ ...onnectorBindingsTeklaStructures.Receive.cs | 10 +- .../Util/ConnectorTeklaStructuresUtils.cs | 3 + ConnectorTeklaStructures/Manifest.xml | 38 ++++ ConnectorTeklaStructures/logo.png | Bin 0 -> 4209 bytes .../ConverterRevitShared/ConverterRevit.cs | 64 ++++++- .../ConverterRevitShared.projitems | 1 + .../ConvertDirectTeklaMeshElements.cs | 17 ++ .../ConverterTeklaStructures.cs | 31 +++- .../ConverterTeklaStructuresShared.projitems | 1 + .../Partial Classes/ConvertDirectShapeMesh.cs | 173 ++++++++++++++++++ 19 files changed, 612 insertions(+), 9 deletions(-) create mode 100644 ConnectorTeklaStructures/ConnectorTeklaStructures2021/Manifest.xml create mode 100644 ConnectorTeklaStructures/ConnectorTeklaStructures2021/ManifestGenerator.tt create mode 100644 ConnectorTeklaStructures/ConnectorTeklaStructures2021/ManifestGenerator.xml create mode 100644 ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Settings.cs create mode 100644 ConnectorTeklaStructures/Manifest.xml create mode 100644 ConnectorTeklaStructures/logo.png create mode 100644 Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertDirectTeklaMeshElements.cs create mode 100644 Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertDirectShapeMesh.cs diff --git a/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2 .Settings.cs b/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2 .Settings.cs index ae8726253a..4a1e6cfb27 100644 --- a/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2 .Settings.cs +++ b/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2 .Settings.cs @@ -38,6 +38,7 @@ public override List GetSettings() new ListBoxSetting {Slug = "reference-point", Name = "Reference Point", Icon ="LocationSearching", Values = referencePoints, Description = "Sends or receives stream objects in relation to this document point"}, new CheckBoxSetting {Slug = "linkedmodels-send", Name = "Send Linked Models", Icon ="Link", IsChecked= false, Description = "Include Linked Models in the selection filters when sending"}, new CheckBoxSetting {Slug = "linkedmodels-receive", Name = "Receive Linked Models", Icon ="Link", IsChecked= false, Description = "Include Linked Models when receiving NOTE: elements from linked models will be received in the current document"}, + new CheckBoxSetting {Slug = "recieve-objects-mesh", Name = "Receive Objects as Direct Mesh", Icon = "Link", IsChecked = false, Description = "Recieve the stream as a Meshes only"}, new MultiSelectBoxSetting { Slug = "disallow-join", Name = "Disallow Join For Elements", Icon = "CallSplit", Description = "Determine which objects should not be allowed to join by default when receiving", Values = new List() { ArchitecturalWalls, StructuralWalls, StructuralFraming } }, new ListBoxSetting {Slug = "pretty-mesh", Name = "Mesh Import Method", Icon ="ChartTimelineVarient", Values = prettyMeshOptions, Description = "Determines the display style of imported meshes"}, diff --git a/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Receive.cs b/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Receive.cs index 6d280ff774..0ccd25d9ac 100644 --- a/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Receive.cs +++ b/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Receive.cs @@ -172,7 +172,6 @@ private List ConvertReceivedObjects(List obj var receiveLinkedModelsSetting = (CurrentSettings.FirstOrDefault(x => x.Slug == "linkedmodels-receive") as CheckBoxSetting); var receiveLinkedModels = receiveLinkedModelsSetting != null ? receiveLinkedModelsSetting.IsChecked : false; - foreach (var @base in objects) { if (progress.CancellationTokenSource.Token.IsCancellationRequested) diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/ConnectorTeklaStructures2021.csproj b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/ConnectorTeklaStructures2021.csproj index 185d56f43a..9f90813162 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/ConnectorTeklaStructures2021.csproj +++ b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/ConnectorTeklaStructures2021.csproj @@ -124,6 +124,19 @@ PreserveNewest + + + TextTemplatingFileGenerator + ManifestGenerator.xml + + + True + True + ManifestGenerator.tt + + + + diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/Manifest.xml b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/Manifest.xml new file mode 100644 index 0000000000..72e92ddce0 --- /dev/null +++ b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/Manifest.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/ManifestGenerator.tt b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/ManifestGenerator.tt new file mode 100644 index 0000000000..088d998f46 --- /dev/null +++ b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/ManifestGenerator.tt @@ -0,0 +1,56 @@ +<#@ template language="C#" #> +<#@ output extension=".xml"#> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ import namespace="System.IO" #> +<# + var buildPath = $@".\bin\Debug"; + var files = Directory.EnumerateFiles(buildPath, "*.dll"); + var x = 4; + +#> + + + + + + + + + + + + + + + + + + + + + + + + + + + +<# + foreach (var path in files) + { +#> + " Target="%BinariesTargetDirectory%"/> +<# + } +#> + + + + + + \ No newline at end of file diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/ManifestGenerator.xml b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/ManifestGenerator.xml new file mode 100644 index 0000000000..5674e0e02d --- /dev/null +++ b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/ManifestGenerator.xml @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/ConnectorTeklaStructuresShared.projitems b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/ConnectorTeklaStructuresShared.projitems index 17e29c2b7f..b1015eb8fe 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/ConnectorTeklaStructuresShared.projitems +++ b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/ConnectorTeklaStructuresShared.projitems @@ -11,6 +11,7 @@ + diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Send.cs b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Send.cs index 682a83afb6..7a0b3482fa 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Send.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Send.cs @@ -1,5 +1,6 @@ using DesktopUI2; using DesktopUI2.Models; +using DesktopUI2.Models.Settings; using DesktopUI2.ViewModels; using Speckle.ConnectorTeklaStructures.Util; using Speckle.Core.Api; @@ -22,6 +23,8 @@ public partial class ConnectorBindingsTeklaStructures : ConnectorBindings { #region sending + private List CurrentSettings { get; set; } + public override async System.Threading.Tasks.Task SendStream(StreamState state, ProgressViewModel progress) { //throw new NotImplementedException(); @@ -31,6 +34,12 @@ public override async System.Threading.Tasks.Task SendStream(StreamState converter.SetContextDocument(Model); Exceptions.Clear(); + var settings = new Dictionary(); + CurrentSettings = state.Settings; + foreach (var setting in state.Settings) + settings.Add(setting.Slug, setting.Selection); + converter.SetConverterSettings(settings); + var commitObj = new Base(); int objCount = 0; diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Settings.cs b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Settings.cs new file mode 100644 index 0000000000..4f9b5fc31c --- /dev/null +++ b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Settings.cs @@ -0,0 +1,23 @@ +using DesktopUI2; +using DesktopUI2.Models; +using DesktopUI2.ViewModels; +using System.Collections.Generic; +using System.Text; +using DesktopUI2.Models.Settings; +using System.Linq; + +namespace Speckle.ConnectorTeklaStructures.UI +{ + public partial class ConnectorBindingsTeklaStructures : ConnectorBindings +{ + public override List GetSettings() + { + + + return new List + { + new CheckBoxSetting {Slug = "recieve-objects-mesh", Name = "Receive Objects as Direct Mesh", Icon = "Link", IsChecked = false, Description = "Recieve the stream as a Meshes only"} + }; + } + } +} diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Receive.cs b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Receive.cs index 9752c9741e..23e396ad2c 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Receive.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Receive.cs @@ -19,10 +19,6 @@ namespace Speckle.ConnectorTeklaStructures.UI public partial class ConnectorBindingsTeklaStructures : ConnectorBindings { - public override List GetSettings() - { - return new List(); - } #region receiving public override async Task ReceiveStream(StreamState state, ProgressViewModel progress) { @@ -33,6 +29,12 @@ public override async Task ReceiveStream(StreamState state, Progres converter.SetContextDocument(Model); //var previouslyRecieveObjects = state.ReceivedObjects; + var settings = new Dictionary(); + CurrentSettings = state.Settings; + foreach (var setting in state.Settings) + settings.Add(setting.Slug, setting.Selection); + converter.SetConverterSettings(settings); + if (converter == null) { throw new Exception("Could not find any Kit!"); diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/Util/ConnectorTeklaStructuresUtils.cs b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/Util/ConnectorTeklaStructuresUtils.cs index b53fc7eafd..99a47f046e 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/Util/ConnectorTeklaStructuresUtils.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/Util/ConnectorTeklaStructuresUtils.cs @@ -6,6 +6,8 @@ using System.Linq; using Speckle.ConnectorTeklaStructures.UI; using Tekla.Structures.Model; +using Speckle.Core.Models; + namespace Speckle.ConnectorTeklaStructures.Util { class ConnectorTeklaStructuresUtils @@ -37,6 +39,7 @@ class ConnectorTeklaStructuresUtils } return _categories; } + #region Get List Names diff --git a/ConnectorTeklaStructures/Manifest.xml b/ConnectorTeklaStructures/Manifest.xml new file mode 100644 index 0000000000..72e92ddce0 --- /dev/null +++ b/ConnectorTeklaStructures/Manifest.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ConnectorTeklaStructures/logo.png b/ConnectorTeklaStructures/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..278859bc8c854fdf43145ca9361a50d8ead9db90 GIT binary patch literal 4209 zcmeHK`8$+t`yad-SsI=!QOLtsl00Qg3>ix^BWt$APzVjOW*;qkf8YDKuj4-M>$=Y6^EuD^I?p@V+VYwZzZ5?R z1QJ3bOl(0QE;ums`HlfIjS0Gi zB}B;@TTaPt7M3|XQ=V#P&hTOih#IUEk9H@dujK7W-MZ^h_A1owm}FSdDOGZSk2a)iHK1XOZ^ zO;y}%3MlVpUhjhW<0s=!$-_NNI-Z^q{NSmXKfDDYjGg)d@sJ|g91ni>$5rLw98BJO z(Vvda^k!9(c|AdG8@t&}@2_X1r^m&3GjdkYtvY&o#f)&uz_m-gUOJ>$*E;4u;pE-C zo5ukM{|{HHGD`;Jj9EIF$9Ytgsnl=c-OCZ%+j<({(=#P!s?(#fE?L~?BaPuIQ8glpvlmbxC9Cu1EGQ8G1&AOcanwJTQ!c&l`X|TN3A?$--Hv(XCV<8i%F7fMS(UXqXi}ivU z`Z@RfG}Ps}2W6A-kngVj>AyW-4KhUm=@)qQ zP%A4@Gc5dNo{-_e&S?mhxf)AO0xeHG$I&ZCr(4KLes&bNGV&yt%-Q@#J@|DaIu^n; z_!a}5xkYG60X%=IpJ%Xfom?plA$Nn8d#%j>-R>Ns7XyieMhcZG(8f#4 zStxNK42Bvg>W#%vQ?*vpF!M!j=87tO&o!9oi#!0*hPnasgeCBmDnMU_cDuGR>(9$#V6$-cL8O6FTOW(Du-F1|A6+cIklSH-Rahllg zX%+R@1#_$5bt&b#XK&`U(A2>49=R<1P$opW_+Z=6pz8ysq`B@zs2hN08FTfku`==s zHX@QkxdoXX0M>};vQ=p07<*^VSOkuAHW;Nuj!{>m6#|sLkedJ^BR^AWXC1-&2}z0o z4L6hHw)+d1uy4-K(%2O45~UlT$pw2KjIduz0T9qvn?m6X3f0+Q^2*#12?#cj%AA-N zZh_0qBmS*RC&72E^vQcX)LTGqq}OOMAx|zxz_R4B6m(tJJG^CD7iiatqI-_A!yoBZ zJ377TfX!$i?Dd6|>={O}X^+35_$0^n{a2rxa@^hcjr z^4+Zco;bTSzRHoNRBh16Jh1HDiVey$T;_gB)52@2b7@2g)s|w zC*oTx;`>^%rRpx8=1`mGP&;w?TPi-JHNDgu8jr)DOjjSE{tgGz+qc8j_8W?VE!m54|bBrOLTm|Iw=Z)=e z;cFCG^g)L7RJYY?$p*j;lB^TiL!f8sfJm_7Y< z&*@@L8lxr}!I^!C9}W*r#%TxT3v;RJX9BD!pw!!Ub7HN~ze~T!7Pkhn8_7)fkIuf^ zqHi*;Xw8|dDfbn@-`{}}dRpi(Vg}t}Zv%MJ?$**C)CQ}L`u)^Y@wFY|B_CW}AMiW; zlqMfAlpsaTKVx&(TEB;dP$;aKqnoaQZNW)*M#4)JF5h3%e z{-*Z>2Mb!{?#)MfYVHJ|J{XZ6e%AH(h?o;$hgfa&1gAt%-?_ zoG&MzKgoSewAXmGiqHLsRxzbCh>NxfAKn!Nmog^y$saS*_^2(5suYR8$KVflIU0m)biUfC)}ng zj`Im<$3Chsfzy^KV}hf|)5HNYg2nLoL#^Kd#WqOUli+%;O`F^B=5w`R9dot?@~{(1 zG@b?etJ|<0Z{+>lcdLM?JDgDV|8c)a!U!s;u%C-h(PmQ>%H$2lisW^Ua76XliNlGKxd#)Z8vT>3& z^~}y3zEgv4@qyAt(7ojTksT$7!-cpeH2X>q`u>7C3o9w|a7(09>sIH$ i^-uowzy0Zz3~*!v=hGs2jhI1)`;exVCUtQ4$NvLffF4Q! literal 0 HcmV?d00001 diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevit.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevit.cs index 7ce06c75fd..731c7eab11 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevit.cs +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevit.cs @@ -9,6 +9,8 @@ using BERC = Objects.BuiltElements.Revit.Curve; using DB = Autodesk.Revit.DB; using STR = Objects.Structural; +using GE = Objects.Geometry; +using System; namespace Objects.Converter.Revit { @@ -306,9 +308,66 @@ private string GetElemInfo(object o) return ""; } + private BuiltInCategory GetObjectCategory(Base @object) + { + switch(@object) + { + case BE.Beam _: + case BE.Brace _: + case BE.TeklaStructures.TeklaContourPlate _: + return BuiltInCategory.OST_StructuralFraming; + case BE.TeklaStructures.Bolts _: + return BuiltInCategory.OST_StructConnectionBolts; + case BE.TeklaStructures.Welds _: + return BuiltInCategory.OST_StructConnectionWelds; + case BE.Floor _: + return BuiltInCategory.OST_Floors; + case BE.Ceiling _: + return BuiltInCategory.OST_Ceilings; + case BE.Column _: + return BuiltInCategory.OST_Columns; + case BE.Pipe _: + return BuiltInCategory.OST_PipeSegments; + case BE.Rebar _: + return BuiltInCategory.OST_Rebar; + case BE.Topography _: + return BuiltInCategory.OST_Topography; + case BE.Wall _: + return BuiltInCategory.OST_Walls; + case BE.Roof _: + return BuiltInCategory.OST_Roofs; + case BE.Duct _: + return BuiltInCategory.OST_FabricationDuctwork; + case BE.CableTray _: + return BuiltInCategory.OST_CableTray; + default: + return BuiltInCategory.OST_GenericModel; + } + } public object ConvertToNative(Base @object) { + // Get settings for receive direct meshes , assumes objects aren't nested like in Tekla Structures + Settings.TryGetValue("recieve-objects-mesh", out string recieveModelMesh); + if (bool.Parse(recieveModelMesh) == true) + { + try + { + List displayValues = new List { }; + var meshes = @object.GetType().GetProperty("displayValue").GetValue(@object) as List; + //dynamic property = propInfo; + //List meshes = (List)property; + var cat = GetObjectCategory(@object); + return DirectShapeToNative(meshes, cat); + } + catch + { + + } + + + + } //Family Document if (Doc.IsFamilyDocument) { @@ -348,7 +407,6 @@ public object ConvertToNative(Base @object) case Geometry.Brep o: return DirectShapeToNative(o); - case Geometry.Mesh mesh: switch (ToNativeMeshSetting) { @@ -374,8 +432,8 @@ public object ConvertToNative(Base @object) case BER.AdaptiveComponent o: return AdaptiveComponentToNative(o); - case BE.TeklaStructures.TeklaBeam o: - return TeklaBeamToNative(o); + //case BE.TeklaStructures.TeklaBeam o: + // return TeklaBeamToNative(o); case BE.Beam o: return BeamToNative(o); diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevitShared.projitems b/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevitShared.projitems index 5dcb904d01..9e55deba68 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevitShared.projitems +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevitShared.projitems @@ -20,6 +20,7 @@ + diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertDirectTeklaMeshElements.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertDirectTeklaMeshElements.cs new file mode 100644 index 0000000000..8f8a6b45c7 --- /dev/null +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertDirectTeklaMeshElements.cs @@ -0,0 +1,17 @@ +using Autodesk.Revit.DB; +using Objects.Other; +using System; +using System.Collections.Generic; +using System.Linq; +using DB = Autodesk.Revit.DB; +using Mesh = Objects.Geometry.Mesh; + +namespace Objects.Converter.Revit +{ + public partial class ConverterRevit + { + public IList TeklaMeshToNative(Mesh displayMesh){ + return MeshToNative(displayMesh); + } + } +} diff --git a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/ConverterTeklaStructures.cs b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/ConverterTeklaStructures.cs index f45a5d508e..9b8df73b93 100644 --- a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/ConverterTeklaStructures.cs +++ b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/ConverterTeklaStructures.cs @@ -11,6 +11,7 @@ using Speckle.Core.Logging; using Tekla.Structures.Model; using Tekla.Structures; +using GE = Objects.Geometry; namespace Objects.Converter.TeklaStructures @@ -28,6 +29,8 @@ public partial class ConverterTeklaStructures : ISpeckleConverter public string Name => nameof(ConverterTeklaStructures); + public Dictionary Settings { get; private set; } = new Dictionary(); + public string Author => "Speckle"; public string WebsiteOrEmail => "https://speckle.systems"; @@ -59,6 +62,8 @@ public void SetContextDocument(object doc) public bool CanConvertToNative(Base @object) { + + switch (@object) { case BE.Beam b: @@ -84,6 +89,7 @@ public bool CanConvertToNative(Base @object) public bool CanConvertToSpeckle(object @object) { + //return @object switch (@object) { @@ -115,6 +121,29 @@ public bool CanConvertToSpeckle(object @object) public object ConvertToNative(Base @object) { + + Settings.TryGetValue("recieve-objects-mesh", out string recieveModelMesh); + if (bool.Parse(recieveModelMesh) == true) + { + try + { + List displayValues = new List { }; + var meshes = @object.GetType().GetProperty("displayValue").GetValue(@object) as List; + //dynamic property = propInfo; + //List meshes = (List)property; + MeshToNative(@object, meshes); + return true; + } + catch + { + + } + + + + } + + switch (@object) { case BE.Beam o: @@ -218,7 +247,7 @@ private string GetElemInfo(object o) public void SetConverterSettings(object settings) { - throw new NotImplementedException("This converter does not have any settings."); + Settings = settings as Dictionary; } } } diff --git a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/ConverterTeklaStructuresShared.projitems b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/ConverterTeklaStructuresShared.projitems index 158f5b9876..9624610c15 100644 --- a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/ConverterTeklaStructuresShared.projitems +++ b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/ConverterTeklaStructuresShared.projitems @@ -11,6 +11,7 @@ + diff --git a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertDirectShapeMesh.cs b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertDirectShapeMesh.cs new file mode 100644 index 0000000000..cd8872f66f --- /dev/null +++ b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertDirectShapeMesh.cs @@ -0,0 +1,173 @@ +using System; +using System.Collections.Generic; +using GE = Objects.Geometry; +using GES = Objects.Structural.Geometry; +using Objects.Structural.Analysis; +using Speckle.Core.Models; +using BE = Objects.BuiltElements; +using Objects.BuiltElements.TeklaStructures; +using System.Linq; +using Tekla.Structures.Model; +using Tekla.Structures.Solid; +using System.Collections; +using StructuralUtilities.PolygonMesher; +using Tekla.Structures.Model.UI; +using Tekla.Structures.Geometry3d; +using Tekla.Structures.Catalogs; + +namespace Objects.Converter.TeklaStructures +{ + public partial class ConverterTeklaStructures + { + public void MeshToNative(Base @object, List displayValues) + { + int incr = 0; + foreach (var mesh in displayValues) + { + FacetedBrep facetedBrep = CreateFacetedBrep(mesh); + + // Add shape to catalog + // Each shape in catalog needs to have a unique name + string objectName = GetShapeName(@object); + string shapeName = "Speckle_" + objectName + (incr > 0 ? "_" + incr.ToString() : ""); + var shapeItem = new ShapeItem + { + Name = shapeName, + ShapeFacetedBrep = facetedBrep, + UpAxis = ShapeUpAxis.Z_Axis + }; + // remove possibly pre-existing shape with same name and then insert a Speckle object shape + // with that name into the catalog + shapeItem.Delete(); + bool result = false; + try + { + result = shapeItem.Insert(); + // Fails if two shapes exist with different names but same geometry fingerprint + } + catch (Exception ex) { } + + if (!result) + { + // Find pre-existing shape in catalog with same fingerprint + var matchingShape = CheckFingerprint(shapeItem); + if (matchingShape != null) + { + shapeName = matchingShape.Name; + result = true; + } + } + + // Insert object in model + if (result) + { + var brep = new Brep(); + brep.StartPoint = new Tekla.Structures.Geometry3d.Point(0, 0, 0); + brep.EndPoint = new Tekla.Structures.Geometry3d.Point(1000, 0, 0); + brep.Profile.ProfileString = shapeName; + brep.Material.MaterialString = "TS_Undefined"; + brep.Position.Depth = Position.DepthEnum.MIDDLE; + brep.Position.Plane = Position.PlaneEnum.MIDDLE; + brep.Position.Rotation = Position.RotationEnum.TOP; + brep.Insert(); + } + + incr++; + } + + //var vertex = new[] + // { + // new Vector(0.0, 0.0, 0.0), // 0 + // new Vector(300.0, 0.0, 0.0), // 1 + // new Vector(300.0, 700.0, 0.0), // 2 + // new Vector(0.0, 700.0, 0.0), // 3 + // new Vector(300.0, 700.0, 0.0), // 4 + // new Vector(300.0, 700.0, 2000.0), // 5 + // new Vector(0.0, 700.0, 2000.0), // 6 + // new Vector(100.0, 100.0, 0.0), // 7 + // new Vector(200.0, 100.0, 0.0), // 8 + // new Vector(200.0, 200.0, 0.0), // 9 + // new Vector(100.0, 200.0, 0.0) // 10 + // }; + //var outerWires = new[] + //{ + //foreach + // }; + //var innerWires = new Dictionary + // { + + // }; + + //var brep = new FacetedBrep(vertex, outerWires, innerWires); + + //var shapeItem = new ShapeItem + //{ + // Name = "Test", + // ShapeFacetedBrep = brep, + // UpAxis = ShapeUpAxis.Z_Axis + //}; + //shapeItem.Insert(); + //Model.CommitChanges(); + } + + public FacetedBrep CreateFacetedBrep(GE.Mesh mesh) + { + var faces = mesh.faces; + List> faceList = new List> { }; + faceList = faces.Select((x, i) => new { Index = i, Value = x }) + .GroupBy(x => x.Index / 4) + .Select(x => x.Select(v => v.Value).ToList()) + .ToList(); + var vertices = mesh.vertices; + List> verticesList = new List> { }; + verticesList = vertices.Select((x, i) => new { Index = i, Value = x }) + .GroupBy(x => x.Index / 3) + .Select(x => x.Select(v => v.Value).ToList()) + .ToList(); + List vertexs = new List(); + List outerWires = new List(); + var innerLoop = new Dictionary { }; + foreach (var vertex in verticesList) + { + var teklaVectorVertex = new Vector(vertex[0], vertex[1], vertex[2]); + vertexs.Add(teklaVectorVertex); + } + foreach (var face in faceList) + { + // Tekla wants the face loops in reverse + var teklaFaceLoop = new[] { face[3], face[2], face[1] }; + outerWires.Add(teklaFaceLoop); + } + var brep = new FacetedBrep(vertexs.ToArray(), outerWires.ToArray(), innerLoop); + return brep; + } + public string GetShapeName(Base @object) + { + string name = ""; + + // Take application id + if (string.IsNullOrEmpty(name)) + name = @object.applicationId; + + // If still empty then do Speckle id but can cause failure since changes with every commit + if (string.IsNullOrEmpty(name)) + name = @object.id; + + return name; + } + public ShapeItem CheckFingerprint(ShapeItem si) + { + CatalogHandler catalogHandler = new CatalogHandler(); + ShapeItemEnumerator sie = catalogHandler.GetShapeItems(); + while(sie.MoveNext()) + { + ShapeItem siItem = sie.Current; + if (siItem.Fingerprint == Polymesh.Fingerprint(si.ShapeFacetedBrep)) + return siItem; + } + return null; + } + } + +} +