Skip to content

Commit

Permalink
Feat(tekla): plugin structure and bind UI (#282)
Browse files Browse the repository at this point in the history
* Fun 101

* Update package.lock for tekla project

* Align tekla with new DI

* More alignment

* Add launch setting

* Message for init

* Move project to connectors folder

* Show, activate, focus

* Post build action

* NOT_DEPENDENT for inputs

on slides said that it useful on imports and exports and faster around 20x

* Add doc for InputObjectDependency.NOT_DEPENDENT

* Disable conditions on post build action

* Make it work!

* Move packages to Directory.Packages.props

* Bump tekla package.json to sdk 3.1.0-dev.146

* Add tekla project to Local.sln too

* Update packages.lock
  • Loading branch information
oguzhankoral authored Sep 26, 2024
1 parent 9f402e8 commit b086d16
Show file tree
Hide file tree
Showing 14 changed files with 774 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Sdk;

namespace Speckle.Connector.Tekla2024.Bindings;

public class TeklaBasicConnectorBinding : IBasicConnectorBinding
{
private readonly ISpeckleApplication _speckleApplication;
private readonly DocumentModelStore _store;
public string Name => "baseBinding";
public IBrowserBridge Parent { get; }

public TeklaBasicConnectorBinding(
IBrowserBridge parent,
ISpeckleApplication speckleApplication,
DocumentModelStore store
)
{
_speckleApplication = speckleApplication;
_store = store;
Parent = parent;
}

public string GetSourceApplicationName() => _speckleApplication.Slug;

public string GetSourceApplicationVersion() => _speckleApplication.HostApplicationVersion;

public string GetConnectorVersion() => _speckleApplication.SpeckleVersion;

public DocumentInfo? GetDocumentInfo() => new DocumentInfo("Test", "Test", "Test");

public DocumentModelStore GetDocumentState() => _store;

public void AddModel(ModelCard model) => throw new NotImplementedException();

public void UpdateModel(ModelCard model) => throw new NotImplementedException();

public void RemoveModel(ModelCard model) => throw new NotImplementedException();

public void HighlightModel(string modelCardId) => throw new NotImplementedException();

public void HighlightObjects(List<string> objectIds) => throw new NotImplementedException();

public BasicConnectorBindingCommands Commands { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Connectors.DUI.Settings;

namespace Speckle.Connector.Tekla2024.Bindings;

public class TeklaSendBinding : ISendBinding
{
public string Name => "sendBinding";
public IBrowserBridge Parent { get; }

public TeklaSendBinding(IBrowserBridge parent)
{
Parent = parent;
}

public List<ISendFilter> GetSendFilters() => [];

public List<ICardSetting> GetSendSettings() => [];

public Task Send(string modelCardId) => throw new NotImplementedException();

public void CancelSend(string modelCardId) => throw new NotImplementedException();

public SendBindingUICommands Commands { get; }
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Speckle.Connectors.DUI.Models;
using Speckle.Newtonsoft.Json;

namespace Speckle.Connector.Tekla2024.HostApp;

public class TeklaDocumentModelStore : DocumentModelStore
{
public TeklaDocumentModelStore(
JsonSerializerSettings jsonSerializerSettings
// ITopLevelExceptionHandler topLevelExceptionHandler
)
: base(jsonSerializerSettings, true) { }

public override void WriteToFile() { }

public override void ReadFromFile() { }
}
18 changes: 18 additions & 0 deletions Connectors/Tekla/Speckle.Connector.Tekla2024/Plugin/TeklaPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Tekla.Structures.Plugins;

namespace Speckle.Connector.Tekla2024.Plugin;

[Plugin("Speckle.Connectors.Tekla")]
[PluginUserInterface("Speckle.Connector.Tekla2024.SpeckleTeklaPanelHost")]
[InputObjectDependency(InputObjectDependency.NOT_DEPENDENT)] // See DevDocs/InputObjectDependency.NOT_DEPENDENT.png
public class TeklaPlugin : PluginBase
{
#pragma warning disable IDE1006
public override bool Run(List<InputDefinition> Input)
{
return true;
}
#pragma warning restore IDE1006

public override List<InputDefinition> DefineInput() => new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Tekla2024": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\Tekla Structures\\2024.0\\bin\\TeklaStructures.exe"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.Extensions.DependencyInjection;
using Speckle.Connector.Tekla2024.Bindings;
using Speckle.Connector.Tekla2024.HostApp;
using Speckle.Connectors.Common;
using Speckle.Connectors.DUI;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.WebView;

namespace Speckle.Connector.Tekla2024;

public static class ServiceRegistration
{
public static void AddTekla(this IServiceCollection serviceCollection)
{
serviceCollection.AddConnectorUtils();
serviceCollection.AddDUI();
serviceCollection.AddDUIView();

serviceCollection.AddSingleton<IBinding, TestBinding>();
serviceCollection.AddSingleton<IBinding, ConfigBinding>();
serviceCollection.AddSingleton<IBinding, AccountBinding>();

serviceCollection.AddSingleton<DocumentModelStore, TeklaDocumentModelStore>();

serviceCollection.RegisterTopLevelExceptionHandler();

serviceCollection.AddSingleton<IBinding>(sp => sp.GetRequiredService<IBasicConnectorBinding>());
serviceCollection.AddSingleton<IBasicConnectorBinding, TeklaBasicConnectorBinding>();

serviceCollection.AddSingleton<IBinding, TeklaSendBinding>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<UseWpf>true</UseWpf>
<DefineConstants>$(DefineConstants);TEKLA2024</DefineConstants>
<PostBuildEvent>RD /S /Q "$(TargetDir)arm64\"
if EXIST "C:\Program Files\Tekla Structures\2024.0\" (
xcopy "$(TargetDir)*.*" "C:\ProgramData\Trimble\Tekla Structures\2024.0\Environments\common\extensions\Speckle3TeklaStructures" /Y /I /E
)
if EXIST "C:\TeklaStructures\2024.0\" (
xcopy "$(TargetDir)*.*" "C:\TeklaStructures\2024.0\Environments\common\extensions\Speckle3TeklaStructures" /Y /I /E
)
</PostBuildEvent>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Tekla.Structures.Dialog" IncludeAssets="compile; build" PrivateAssets="all" />
<PackageReference Include="Tekla.Structures.Model" IncludeAssets="compile; build" PrivateAssets="all" />
<PackageReference Include="Tekla.Structures.Plugins" IncludeAssets="compile; build" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\DUI3\Speckle.Connectors.DUI.WebView\Speckle.Connectors.DUI.WebView.csproj" />
<ProjectReference Include="..\..\..\DUI3\Speckle.Connectors.DUI\Speckle.Connectors.DUI.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="WindowsFormsIntegration" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using Microsoft.Extensions.DependencyInjection;
using Speckle.Connectors.Common;
using Speckle.Connectors.DUI;
using Speckle.Connectors.DUI.WebView;
using Speckle.Sdk.Host;
using Tekla.Structures.Dialog;
using Tekla.Structures.Model;
using Tekla.Structures.Model.Operations;

namespace Speckle.Connector.Tekla2024;

public class SpeckleTeklaPanelHost : PluginFormBase
{
private ElementHost Host { get; }
public Model Model { get; private set; }

public static new ServiceProvider? Container { get; private set; }

// TODO: private IDisposable? _disposableLogger;

public SpeckleTeklaPanelHost()
{
var services = new ServiceCollection();
services.Initialize(HostApplications.TeklaStructures, GetVersion());
services.AddTekla();

// TODO: Add Tekla converters

Container = services.BuildServiceProvider();
Container.UseDUI(); // TODO: this might not needed? ISyncToThread?

Model = new Model(); // don't know what is this..
if (!Model.GetConnectionStatus())
{
MessageBox.Show(
"Speckle connector connection failed. Please try again.",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
}
var webview = Container.GetRequiredService<DUI3ControlWebView>();
Host = new() { Child = webview, Dock = DockStyle.Fill };
Controls.Add(Host);
Operation.DisplayPrompt("Speckle connector initialized.");

Show();
Activate();
Focus();
}

private HostAppVersion GetVersion()
{
#if TEKLA2024
return HostAppVersion.v2024;
#else
throw new NotImplementedException();
#endif
}
}
15 changes: 15 additions & 0 deletions Connectors/Tekla/Speckle.Connector.Tekla2024/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetZip" publicKeyToken="6583c7c814667745" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.16.0.0" newVersion="1.16.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
Loading

0 comments on commit b086d16

Please sign in to comment.