Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dogukan/etabs connector poc #406

Merged
merged 13 commits into from
Nov 28, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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.ETABS22.Bindings;

public class EtabsBasicConnectorBinding : IBasicConnectorBinding
{
private readonly ISpeckleApplication _speckleApplication;
private readonly DocumentModelStore _store;

public string Name => "baseBinding";
public IBrowserBridge Parent { get; }
public BasicConnectorBindingCommands Commands { get; }

public EtabsBasicConnectorBinding(
IBrowserBridge parent,
ISpeckleApplication speckleApplication,
DocumentModelStore store
)
{
Parent = parent;
_speckleApplication = speckleApplication;
_store = store;
Commands = new BasicConnectorBindingCommands(parent);
}

public string GetConnectorVersion() => _speckleApplication.SpeckleVersion;

public string GetSourceApplicationName() => _speckleApplication.Slug;

public string GetSourceApplicationVersion() => _speckleApplication.HostApplicationVersion;

public DocumentInfo? GetDocumentInfo() => new DocumentInfo("ETABS Model", "ETABS Model", "1");

public DocumentModelStore GetDocumentState() => _store;

public void AddModel(ModelCard model) => _store.Models.Add(model);

public void UpdateModel(ModelCard model) => _store.UpdateModel(model);

public void RemoveModel(ModelCard model) => _store.RemoveModel(model);

public Task HighlightModel(string modelCardId) => Task.CompletedTask;

public Task HighlightObjects(IReadOnlyList<string> objectIds) => Task.CompletedTask;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;

namespace Speckle.Connector.ETABS22.Bindings;

public class ETABSSelectionBinding : ISelectionBinding
{
public string Name => "selectionBinding";
public IBrowserBridge Parent { get; }

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

public SelectionInfo GetSelection()
{
// placeholder for actual implementation
return new SelectionInfo(new List<string>(), "No objects selected.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Microsoft.Extensions.Logging;
using Speckle.Connectors.Common.Cancellation;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Connectors.DUI.Settings;

namespace Speckle.Connector.ETABS22.Bindings;

public sealed class ETABSSendBinding : ISendBinding
{
public string Name => "sendBinding";
public SendBindingUICommands Commands { get; }
public IBrowserBridge Parent { get; }

private readonly DocumentModelStore _store;
private readonly IAppIdleManager _idleManager;
private readonly IServiceProvider _serviceProvider;
private readonly List<ISendFilter> _sendFilters;
private readonly CancellationManager _cancellationManager;
private readonly IOperationProgressManager _operationProgressManager;
private readonly ILogger<ETABSSendBinding> _logger;

public ETABSSendBinding(
DocumentModelStore store,
IAppIdleManager idleManager,
IBrowserBridge parent,
IEnumerable<ISendFilter> sendFilters,
IServiceProvider serviceProvider,
CancellationManager cancellationManager,
IOperationProgressManager operationProgressManager,
ILogger<ETABSSendBinding> logger
)
{
_store = store;
_idleManager = idleManager;
_serviceProvider = serviceProvider;
_sendFilters = sendFilters.ToList();
_cancellationManager = cancellationManager;
_operationProgressManager = operationProgressManager;
_logger = logger;
Parent = parent;
Commands = new SendBindingUICommands(parent);
}

public List<ISendFilter> GetSendFilters() => _sendFilters;

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

public async Task Send(string modelCardId)
{
// placeholder for actual send implementation
await Task.CompletedTask.ConfigureAwait(false);
}

public void CancelSend(string modelCardId)
{
_cancellationManager.CancelOperation(modelCardId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Speckle.Connectors.DUI.Models.Card.SendFilter;

namespace Speckle.Connector.ETABS22.Filters;

public class ETABSSelectionFilter : DirectSelectionSendFilter
{
public ETABSSelectionFilter()
{
IsDefault = true;
}

public override List<string> RefreshObjectIds() => SelectedObjectIds;
}
49 changes: 49 additions & 0 deletions Connectors/ETABS/Speckle.Connector.ETABS22/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Windows.Forms.Integration;
using CSiAPIv1;
using Microsoft.Extensions.DependencyInjection;
using Speckle.Connectors.Common;
using Speckle.Connectors.DUI.WebView;
using Speckle.Sdk.Host;

namespace Speckle.Connector.ETABS22;

public class Form1 : Form
{
private ElementHost Host { get; set; }
public static new ServiceProvider? Container { get; set; }
private cSapModel _sapModel;
private cPluginCallback _pluginCallback;

public Form1()
{
this.Text = "Speckle (Beta)";

var services = new ServiceCollection();
services.Initialize(HostApplications.ETABS, GetVersion());
services.AddETABS();

Container = services.BuildServiceProvider();

var webview = Container.GetRequiredService<DUI3ControlWebView>();
Host = new() { Child = webview, Dock = DockStyle.Fill };
Controls.Add(Host);
FormClosing += Form1Closing;
}

public void SetSapModel(ref cSapModel sapModel, ref cPluginCallback pluginCallback)
{
_sapModel = sapModel;
_pluginCallback = pluginCallback;
}

public void Form1Closing(object? sender, FormClosingEventArgs e)
{
Host.Dispose();
_pluginCallback.Finish(0);
}

private static HostAppVersion GetVersion()
{
return HostAppVersion.v2022;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Speckle.Connectors.DUI.Models;
using Speckle.Newtonsoft.Json;

namespace Speckle.Connector.ETABS22.HostApp;

public class ETABSDocumentModelStore : DocumentModelStore
{
public ETABSDocumentModelStore(JsonSerializerSettings jsonSerializerSettings)
: base(jsonSerializerSettings, true) { }

public override void WriteToFile() { }

public override void ReadFromFile() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Speckle.Connectors.DUI.Bridge;

namespace Speckle.Connector.ETABS22.HostApp;

public sealed class EtabsIdleManager : AppIdleManager
{
private readonly IIdleCallManager _idleCallManager;

public EtabsIdleManager(IIdleCallManager idleCallManager)
: base(idleCallManager)
{
_idleCallManager = idleCallManager;
}

protected override void AddEvent()
{
// ETABS specific idle handling can be added here if needed
_idleCallManager.AppOnIdle(() => { });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"ETABS 22": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\Computers and Structures\\ETABS 22\\ETABS.exe"
}
}
}
44 changes: 44 additions & 0 deletions Connectors/ETABS/Speckle.Connector.ETABS22/ServiceRegistration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.Extensions.DependencyInjection;
using Speckle.Connector.ETABS22.Bindings;
using Speckle.Connector.ETABS22.Filters;
using Speckle.Connector.ETABS22.HostApp;
using Speckle.Connectors.Common;
using Speckle.Connectors.DUI;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Connectors.DUI.WebView;

namespace Speckle.Connector.ETABS22;

public static class ServiceRegistration
{
public static IServiceCollection AddETABS(this IServiceCollection services)
{
services.AddSingleton<IBrowserBridge, BrowserBridge>();

services.AddConnectorUtils();
services.AddDUI();
services.AddDUIView();

services.AddSingleton<DocumentModelStore, ETABSDocumentModelStore>();

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

services.AddSingleton<IBinding>(sp => sp.GetRequiredService<IBasicConnectorBinding>());
services.AddSingleton<IBasicConnectorBinding, EtabsBasicConnectorBinding>();
services.AddSingleton<IAppIdleManager, EtabsIdleManager>();

services.AddSingleton<IBinding, ETABSSelectionBinding>();
services.AddSingleton<IBinding, ETABSSendBinding>();

services.AddScoped<ISendFilter, ETABSSelectionFilter>();

services.RegisterTopLevelExceptionHandler();

return services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>AnyCPU;x64</Platforms>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>

<ItemGroup>
<Reference Include="CSiAPIv1">
<HintPath>..\..\..\..\..\..\..\..\Program Files\Computers and Structures\ETABS 22\CSiAPIv1.dll</HintPath>
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</Reference>
</ItemGroup>

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

<ItemGroup>
<Compile Update="Form1.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>
63 changes: 63 additions & 0 deletions Connectors/ETABS/Speckle.Connector.ETABS22/cPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using CSiAPIv1;

namespace Speckle.Connector.ETABS22;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "<Pending>")]
public class cPlugin : cPluginContract, IDisposable
{
private static string s_modality = "Non-Modal";
private Form1? _panel;
private bool _disposed;

public void Main(ref cSapModel sapModel, ref cPluginCallback pluginCallback)
{
_panel = new Form1();
_panel.SetSapModel(ref sapModel, ref pluginCallback);

_panel.FormClosed += (s, e) => Dispose();

if (string.Equals(s_modality, "Non-Modal", StringComparison.OrdinalIgnoreCase))
{
_panel.Show();
}
else
{
_panel.ShowDialog();
}
}

public int Info(ref string text)
{
text = "Hey Speckler! This is our next-gen ETABS Connector.";
return 0;
}

protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
// Dispose managed resources
if (_panel != null)
{
_panel.Dispose();
_panel = null;
}
}

_disposed = true;
}
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

~cPlugin()
{
Dispose(false);
}
}
Loading
Loading