From f5a2d62183c491fbe57cdc9a4d1e1d480ab61c3c Mon Sep 17 00:00:00 2001 From: Reynold Chan Date: Tue, 19 Jul 2022 09:33:57 -0400 Subject: [PATCH] (fix Tekla Structures) PluginCallback Small fixes (#1395) * Tekla Beam to Revit * Change to non dependent plugin * Fix several issues Fix winforms window closing, serialisation of saved streams, and exception on Tekla close. * Small fixes. Match 2020 plugin changes to 2021 * (fix) Fixing Tekla Structures 2020 and 2021 plugin callback - winforms * fix for merge Co-authored-by: Erron Estrado <92844367+eestrado@users.noreply.github.com> Co-authored-by: Alan Rynne --- .../MainForm.Designer.cs | 30 ++--- .../ConnectorTeklaStructures2020/MainForm.cs | 12 +- .../MainPlugin.cs | 19 --- .../MainForm.Designer.cs | 3 + .../ConnectorTeklaStructures2021/MainForm.cs | 112 +++++++++++++++++- .../MainForm.resx | 3 + .../MainPlugin.cs | 95 +-------------- .../UI/ConnectorBindingsTeklaStructures.cs | 3 +- .../Partial Classes/ConvertBeam.cs | 2 +- .../Partial Classes/ConvertBeam.cs | 8 +- .../Partial Classes/ConvertContourPlate.cs | 1 - .../Partial Classes/ConvertPolyBeam.cs | 4 +- .../Partial Classes/ConvertSpiralBeam.cs | 4 +- Objects/Objects/BuiltElements/Beam.cs | 9 +- .../TeklaStructures/TeklaContourPlate.cs | 9 +- 15 files changed, 161 insertions(+), 153 deletions(-) diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainForm.Designer.cs b/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainForm.Designer.cs index 25140095ff..158320398d 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainForm.Designer.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainForm.Designer.cs @@ -29,20 +29,22 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.SuspendLayout(); - // - // MainForm - // - this.structuresExtender.SetAttributeName(this, null); - this.structuresExtender.SetAttributeTypeName(this, null); - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.structuresExtender.SetBindPropertyName(this, null); - this.ClientSize = new System.Drawing.Size(480, 197); - this.Name = "MainForm"; - this.Text = "MainForm"; - this.WindowState = System.Windows.Forms.FormWindowState.Minimized; - this.ResumeLayout(false); + this.SuspendLayout(); + // + // MainForm + // + this.structuresExtender.SetAttributeName(this, null); + this.structuresExtender.SetAttributeTypeName(this, null); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.structuresExtender.SetBindPropertyName(this, null); + this.ClientSize = new System.Drawing.Size(360, 160); + this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Name = "MainForm"; + this.Text = "MainForm"; + this.WindowState = System.Windows.Forms.FormWindowState.Minimized; + this.Load += new System.EventHandler(this.MainForm_Load); + this.ResumeLayout(false); } diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainForm.cs b/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainForm.cs index 470ae48e50..33a1461db7 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainForm.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainForm.cs @@ -1,11 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.IO; using Avalonia; @@ -127,5 +120,10 @@ public static void CreateOrFocusSpeckle(bool showWindow = true) { } } + + private void MainForm_Load(object sender, EventArgs e) + { + } + } } diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainPlugin.cs b/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainPlugin.cs index 356a9ab68e..c1f68af879 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainPlugin.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructures2020/MainPlugin.cs @@ -1,26 +1,7 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TSDatatype = Tekla.Structures.Datatype; -using Tekla.Structures.Model; using Tekla.Structures.Plugins; -using Tekla.Structures; -using Tekla.Structures.Geometry3d; -using Tekla.Structures.Model.UI; -using System.Reflection; -using Avalonia; -using Avalonia.Controls; -using Avalonia.ReactiveUI; - -using DesktopUI2.ViewModels; -using DesktopUI2.Views; -using System.Threading.Tasks; -using System.IO; -using Assembly = System.Reflection.Assembly; -using Speckle.ConnectorTeklaStructures.UI; namespace Speckle.ConnectorTeklaStructures { diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.Designer.cs b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.Designer.cs index 3265dffbe7..b5cd5537e6 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.Designer.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.Designer.cs @@ -33,8 +33,11 @@ private void InitializeComponent() // // MainForm // + this.structuresExtender.SetAttributeName(this, null); + this.structuresExtender.SetAttributeTypeName(this, null); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.structuresExtender.SetBindPropertyName(this, null); this.ClientSize = new System.Drawing.Size(800, 450); this.Name = "MainForm"; this.Text = "MainForm"; diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.cs b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.cs index 442385ced4..ec77fdc844 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.cs @@ -1,14 +1,124 @@ using System; +using System.IO; +using Avalonia; +using Avalonia.Controls; +using Avalonia.ReactiveUI; + +using Tekla.Structures.Model; using Tekla.Structures.Dialog; +using DesktopUI2.ViewModels; +using DesktopUI2.Views; +using Assembly = System.Reflection.Assembly; +using Speckle.ConnectorTeklaStructures.UI; +using System.Threading; + namespace Speckle.ConnectorTeklaStructures { public partial class MainForm : PluginFormBase { + // Enable inserting of objects in a model + private readonly Model model; + private static CancellationTokenSource Lifetime = null; + private static Avalonia.Application AvaloniaApp { get; set; } public MainForm() { - InitializeComponent(); + // Link to model. + model = new Model(); + Bindings = new ConnectorBindingsTeklaStructures(model); + + try + { + base.Load += (s, e) => Close(); + AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(OnAssemblyResolve); + CreateOrFocusSpeckle(); + + } + catch (Exception ex) + { + + } + } + + public Model Model + { + get { return model; } + } + public static Window MainWindow { get; private set; } + public static ConnectorBindingsTeklaStructures Bindings { get; set; } + + static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args) + { + Assembly a = null; + var name = args.Name.Split(',')[0]; + string path = Path.GetDirectoryName(typeof(MainPlugin).Assembly.Location); + + string assemblyFile = Path.Combine(path, name + ".dll"); + + if (File.Exists(assemblyFile)) + a = Assembly.LoadFrom(assemblyFile); + + return a; + } + public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() + .UsePlatformDetect() + .With(new SkiaOptions { MaxGpuResourceSizeBytes = 8096000 }) + .With(new Win32PlatformOptions { AllowEglInitialization = true, EnableMultitouch = false }) + .LogToTrace() + .UseReactiveUI(); + + private static void AppMain(Application app, string[] args) + { + //var viewModel = new MainWindowViewModel(Bindings); + //MainWindow = new DesktopUI2.Views.MainWindow + //{ + // DataContext = viewModel + //}; + //app.Run(MainWindow); + //System.Threading.Tasks.Task.Run(() => app.Run(MainWindow)); + AvaloniaApp = app; + } + //public static void CreateOrFocusSpeckle() + //{ + // if (MainWindow == null) + // { + // BuildAvaloniaApp().Start(AppMain, null); + // } + // MainWindow.Show(); + // MainWindow.Activate(); + //} + public static void CreateOrFocusSpeckle(bool showWindow = true) + { + if (MainWindow == null) + { + BuildAvaloniaApp().Start(AppMain, null); + var viewModel = new MainViewModel(Bindings); + MainWindow = new DesktopUI2.Views.MainWindow + { + DataContext = viewModel + }; + } + + try + { + if (showWindow) + { + MainWindow.Show(); + MainWindow.Activate(); + + //required to gracefully quit avalonia and the skia processes + //https://github.com/AvaloniaUI/Avalonia/wiki/Application-lifetimes + if (Lifetime == null) + { + Lifetime = new CancellationTokenSource(); + System.Threading.Tasks.Task.Run(() => AvaloniaApp.Run(Lifetime.Token)); + } + } + } + catch (Exception ex) + { + } } private void MainForm_Load(object sender, EventArgs e) diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.resx b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.resx index 1af7de150c..6cb8008dca 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.resx +++ b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainPlugin.cs b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainPlugin.cs index 348b194988..c1f68af879 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainPlugin.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainPlugin.cs @@ -1,82 +1,19 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TSDatatype = Tekla.Structures.Datatype; -using Tekla.Structures.Model; using Tekla.Structures.Plugins; -using Tekla.Structures; -using Tekla.Structures.Geometry3d; -using Tekla.Structures.Model.UI; -using System.Reflection; -using Avalonia; -using Avalonia.Controls; -using Avalonia.ReactiveUI; - -using DesktopUI2.ViewModels; -using DesktopUI2.Views; -using System.Threading.Tasks; -using System.IO; -using Assembly = System.Reflection.Assembly; -using Speckle.ConnectorTeklaStructures.UI; namespace Speckle.ConnectorTeklaStructures { - - - public class StructuresData { } [Plugin("Speckle.ConnectorTeklaStructures")] [PluginUserInterface("Speckle.ConnectorTeklaStructures.MainForm")] - + [InputObjectDependency(InputObjectDependency.NOT_DEPENDENT)] public class MainPlugin : PluginBase { - public static Window MainWindow { get; private set; } - - public static ConnectorBindingsTeklaStructures Bindings { get; set; } - public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() -.UsePlatformDetect() -.With(new SkiaOptions { MaxGpuResourceSizeBytes = 8096000 }) -.With(new Win32PlatformOptions { AllowEglInitialization = true, EnableMultitouch = false }) -.LogToTrace() -.UseReactiveUI(); - - private static void AppMain(Application app, string[] args) - { - var viewModel = new MainViewModel(Bindings); - MainWindow = new MainWindow - { - DataContext = viewModel - }; - - app.Run(MainWindow); - //System.Threading.Tasks.Task.Run(() => app.Run(MainWindow)); - } - public static void CreateOrFocusSpeckle() - { - if (MainWindow == null) - { - BuildAvaloniaApp().Start(AppMain, null); - } - - - MainWindow.Show(); - MainWindow.Activate(); - } - - // Enable inserting of objects in a model - private readonly Model model; - - - public Model Model - { - get { return model; } - } public override List DefineInput() { return new List(); @@ -88,42 +25,12 @@ public override List DefineInput() public MainPlugin(StructuresData data) { - // Link to model. - model = new Model(); - Bindings = new ConnectorBindingsTeklaStructures(model); - // Link to input values. - _data = data; } - static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args) - { - Assembly a = null; - var name = args.Name.Split(',')[0]; - string path = Path.GetDirectoryName(typeof(MainPlugin).Assembly.Location); - - string assemblyFile = Path.Combine(path, name + ".dll"); - - if (File.Exists(assemblyFile)) - a = Assembly.LoadFrom(assemblyFile); - - return a; - } - // Specify the user input needed for the plugin. - // This method is called upon execution of the plug-in and it´s the main method of the plug-in public override bool Run(List input) { - try - { - AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(OnAssemblyResolve); - CreateOrFocusSpeckle(); - - } - catch (Exception e) - { - - } return true; } } diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.cs b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.cs index efa5e78e78..b439751e5c 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.cs @@ -21,10 +21,9 @@ public partial class ConnectorBindingsTeklaStructures : ConnectorBindings public ConnectorBindingsTeklaStructures(Model model) { Model = model; + } - - public override List GetReceiveModes() { return new List { ReceiveMode.Create }; diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertBeam.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertBeam.cs index 7860c0a930..46b0e4f256 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertBeam.cs +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertBeam.cs @@ -16,7 +16,7 @@ public partial class ConverterRevit public List BeamToNative(Beam speckleBeam, StructuralType structuralType = StructuralType.Beam) { - + if (speckleBeam.baseLine == null) { throw new Speckle.Core.Logging.SpeckleException("Only line based Beams are currently supported."); diff --git a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertBeam.cs b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertBeam.cs index bb51d8a4c9..97005cf518 100644 --- a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertBeam.cs +++ b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertBeam.cs @@ -128,9 +128,9 @@ public TeklaBeam BeamToSpeckle(Tekla.Structures.Model.Beam beam) speckleBeam.TeklaBeamType = TeklaBeamType.Beam; var vol = new double(); var area = new double(); - beam.GetReportProperty("ASSEMBLY.MAINPART.VOLUME", ref vol); + beam.GetReportProperty("VOLUME", ref vol); speckleBeam.volume = vol; - beam.GetReportProperty("ASSEMBLY.MAINPART.AREA", ref area); + beam.GetReportProperty("AREA", ref area); speckleBeam.area = area; var rebars = beam.GetReinforcements(); @@ -178,9 +178,9 @@ public TeklaBeam AntiBeamToSpeckle(Tekla.Structures.Model.Beam beam) speckleBeam.applicationId = beam.Identifier.GUID.ToString(); var vol = new double(); var area = new double(); - beam.GetReportProperty("ASSEMBLY.MAINPART.VOLUME", ref vol); + beam.GetReportProperty("VOLUME", ref vol); speckleBeam.volume = vol; - beam.GetReportProperty("ASSEMBLY.MAINPART.AREA", ref area); + beam.GetReportProperty("AREA", ref area); speckleBeam.area = area; speckleBeam["units"] = units; diff --git a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertContourPlate.cs b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertContourPlate.cs index 463b79dbb7..bd5a1c1d16 100644 --- a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertContourPlate.cs +++ b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertContourPlate.cs @@ -41,7 +41,6 @@ public void ContourPlateToNative(BE.Area area) public TeklaContourPlate ContourPlateToSpeckle(Tekla.Structures.Model.ContourPlate plate) { var specklePlate = new TeklaContourPlate(); - var units = GetUnitsFromModel(); specklePlate.name = plate.Name; specklePlate.profile = GetContourPlateProfile(plate.Profile.ProfileString); specklePlate.material = GetMaterial(plate.Material.MaterialString); diff --git a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertPolyBeam.cs b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertPolyBeam.cs index 5845666c03..e906cd623d 100644 --- a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertPolyBeam.cs +++ b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertPolyBeam.cs @@ -46,9 +46,9 @@ public TeklaBeam PolyBeamToSpeckle(PolyBeam PolyBeam) speckleBeam.displayMesh = GetMeshFromSolid(solid); var vol = new double(); var area = new double(); - PolyBeam.GetReportProperty("ASSEMBLY.MAINPART.VOLUME", ref vol); + PolyBeam.GetReportProperty("VOLUME", ref vol); speckleBeam.volume = vol; - PolyBeam.GetReportProperty("ASSEMBLY.MAINPART.AREA", ref area); + PolyBeam.GetReportProperty("AREA", ref area); speckleBeam.area = area; return speckleBeam; diff --git a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertSpiralBeam.cs b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertSpiralBeam.cs index 44a446d0a0..b39edda45f 100644 --- a/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertSpiralBeam.cs +++ b/Objects/Converters/ConverterTeklaStructures/ConverterTeklaStructuresShared/Partial Classes/ConvertSpiralBeam.cs @@ -59,9 +59,9 @@ public SpiralBeam SpiralBeamToSpeckle(Tekla.Structures.Model.SpiralBeam SpiralBe var vol = new double(); var area = new double(); - SpiralBeam.GetReportProperty("ASSEMBLY.MAINPART.VOLUME", ref vol); + SpiralBeam.GetReportProperty("VOLUME", ref vol); speckleBeam.volume = vol; - SpiralBeam.GetReportProperty("ASSEMBLY.MAINPART.AREA", ref area); + SpiralBeam.GetReportProperty("AREA", ref area); speckleBeam.area = area; return speckleBeam; diff --git a/Objects/Objects/BuiltElements/Beam.cs b/Objects/Objects/BuiltElements/Beam.cs index cc81e9fa91..5d0c5bde3a 100644 --- a/Objects/Objects/BuiltElements/Beam.cs +++ b/Objects/Objects/BuiltElements/Beam.cs @@ -73,10 +73,13 @@ public class TeklaBeam : Beam, IHasVolume, IHasArea public SectionProfile profile { get; set; } [DetachProperty] public Material material { get; set; } - public string finish { get; set; } - public string classNumber { get; set; } + [DetachProperty] + public string finish { get; set; } + [DetachProperty] + public string classNumber { get; set; } public Vector alignmentVector { get; set; } // This can be set to get proper rotation if coming from an application that doesn't have positioning - public TeklaPosition position { get; set; } + [DetachProperty] + public TeklaPosition position { get; set; } public Base userProperties { get; set; } [DetachProperty] diff --git a/Objects/Objects/BuiltElements/TeklaStructures/TeklaContourPlate.cs b/Objects/Objects/BuiltElements/TeklaStructures/TeklaContourPlate.cs index a52b163792..8fb7141b71 100644 --- a/Objects/Objects/BuiltElements/TeklaStructures/TeklaContourPlate.cs +++ b/Objects/Objects/BuiltElements/TeklaStructures/TeklaContourPlate.cs @@ -14,9 +14,12 @@ public class TeklaContourPlate : Area public SectionProfile profile { get; set; } [DetachProperty] public Material material { get; set; } - public string finish { get; set; } - public string classNumber { get; set; } - public TeklaPosition position { get; set; } + [DetachProperty] + public string finish { get; set; } + [DetachProperty] + public string classNumber { get; set; } + [DetachProperty] + public TeklaPosition position { get; set; } [DetachProperty] public Mesh displayMesh { get; set; }