Skip to content

Commit

Permalink
(fix Tekla Structures) PluginCallback Small fixes (#1395)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Alan Rynne <[email protected]>
  • Loading branch information
3 people authored Jul 19, 2022
1 parent 1edc546 commit f5a2d62
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 153 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -127,5 +120,10 @@ public static void CreateOrFocusSpeckle(bool showWindow = true)
{
}
}

private void MainForm_Load(object sender, EventArgs e)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 111 additions & 1 deletion ConnectorTeklaStructures/ConnectorTeklaStructures2021/MainForm.cs
Original file line number Diff line number Diff line change
@@ -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<DesktopUI2.App>()
.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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="structuresExtender.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
Original file line number Diff line number Diff line change
@@ -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<DesktopUI2.App>()
.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<InputDefinition> DefineInput()
{
return new List<InputDefinition>();
Expand All @@ -88,42 +25,12 @@ public override List<InputDefinition> 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<InputDefinition> input)
{
try
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(OnAssemblyResolve);
CreateOrFocusSpeckle();

}
catch (Exception e)
{

}
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public partial class ConnectorBindingsTeklaStructures : ConnectorBindings
public ConnectorBindingsTeklaStructures(Model model)
{
Model = model;

}



public override List<ReceiveMode> GetReceiveModes()
{
return new List<ReceiveMode> { ReceiveMode.Create };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class ConverterRevit

public List<ApplicationPlaceholderObject> BeamToNative(Beam speckleBeam, StructuralType structuralType = StructuralType.Beam)
{

if (speckleBeam.baseLine == null)
{
throw new Speckle.Core.Logging.SpeckleException("Only line based Beams are currently supported.");
Expand Down
Loading

0 comments on commit f5a2d62

Please sign in to comment.