Skip to content

Commit

Permalink
bjorn/cnx-828-shared-projects-for-connector (#419)
Browse files Browse the repository at this point in the history
* ETABS21

- Shared project for converters
- ETABS21 support

* 21 and 22 Support

- cPlugin.cs and Form1.cs in Shared defined as interfaces. Version specific implementations (basically just the namespaces) created in proj specific files
- Plugins load and selection works in both ETABS versions

* Form1 -> SpeckleForm

* cPlugin base class

- Better to have a cPlugin base class which ETABS21 and 22 inherit. Reduced code duplication
- Better project namespace structure

* s_modality
  • Loading branch information
bjoernsteinhagen authored Nov 28, 2024
1 parent 13f48d9 commit 0be8897
Show file tree
Hide file tree
Showing 16 changed files with 512 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public SelectionInfo GetSelection()
var typeName = objectTypeMap.TryGetValue(typeKey, out var name) ? name : $"Unknown ({typeKey})";

encodedIds.Add(EncodeObjectIdentifier(typeKey, objectName[i]));
typeCounts[typeName] = typeCounts.GetValueOrDefault(typeName) + 1;
typeCounts[typeName] = (typeCounts.TryGetValue(typeName, out var count) ? count : 0) + 1; // NOTE: Cross-framework compatibility
}

var summary =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
// NOTE: Plugin entry point must match the assembly name, otherwise hits you with a "Not found" error when loading plugin
// TODO: Move ETABS implementation to csproj as part of CNX-835 and/or CNX-828
namespace Speckle.Connectors.ETABS22;
namespace Speckle.Connectors.CSiShared;

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

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

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

if (string.Equals(s_modality, "Non-Modal", StringComparison.OrdinalIgnoreCase))
Expand All @@ -26,7 +23,9 @@ public void Main(ref cSapModel sapModel, ref cPluginCallback pluginCallback)
}
}

public int Info(ref string text)
protected abstract SpeckleFormBase CreateForm();

public virtual int Info(ref string text)
{
text = "Hey Speckler! This is our next-gen ETABS Connector.";
return 0;
Expand All @@ -38,14 +37,9 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
// Dispose managed resources
if (_panel != null)
{
_panel.Dispose();
_panel = null;
}
_panel?.Dispose();
_panel = null;
}

_disposed = true;
}
}
Expand All @@ -56,7 +50,7 @@ public void Dispose()
GC.SuppressFinalize(this);
}

~cPlugin()
~CSiSharedPluginBase()
{
Dispose(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
using System.Windows.Forms.Integration;
using Microsoft.Extensions.DependencyInjection;
using Speckle.Connectors.Common;
using Speckle.Connectors.CSiShared;
using Speckle.Connectors.CSiShared.HostApp;
using Speckle.Connectors.DUI.WebView;
using Speckle.Sdk.Host;

// NOTE: Plugin entry point must match the assembly name, otherwise hits you with a "Not found" error when loading plugin
// TODO: Move ETABS implementation to csproj as part of CNX-835 and/or CNX-828
namespace Speckle.Connectors.ETABS22;
namespace Speckle.Connectors.CSiShared;

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

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

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

Container = services.BuildServiceProvider();

Expand All @@ -38,20 +35,20 @@ public void SetSapModel(ref cSapModel sapModel, ref cPluginCallback pluginCallba
_sapModel = sapModel;
_pluginCallback = pluginCallback;

// NOTE: Update the form to initialize the CSiSharedApplicationService when we receive "sapModel"
// Ensures service ready to use by other components
var csiService = Container.GetRequiredService<ICSiApplicationService>();
csiService.Initialize(sapModel, pluginCallback);
}

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

private static HostAppVersion GetVersion()
protected abstract HostAppVersion GetVersion();

public new void ShowDialog()
{
return HostAppVersion.v2022;
base.ShowDialog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ namespace Speckle.Connectors.CSiShared;

public static class ServiceRegistration
{
// TODO: AddCSi and AddETABS for shared and specific implementations respectively. To do with CNX-828
public static IServiceCollection AddETABS(this IServiceCollection services)
public static IServiceCollection AddCSi(this IServiceCollection services)
{
services.AddSingleton<IBrowserBridge, BrowserBridge>();
services.AddSingleton<ICSiApplicationService, CSiApplicationService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CSiSharedBasicConnectorBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CSiSharedSelectionBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CSiSharedSendBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)cPlugin.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Filters\CSiSharedSelectionFilter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Form1.cs">
<Compile Include="$(MSBuildThisFileDirectory)Plugin\CSiSharedPluginBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Plugin\SpeckleFormBase.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)GlobalUsing.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />

<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Form1.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>

<Import Project="Speckle.Connectors.CSiShared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
12 changes: 12 additions & 0 deletions Connectors/CSi/Speckle.Connectors.ETABS21/Plugin/SpeckleForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Speckle.Connectors.CSiShared;
using Speckle.Sdk.Host;

// NOTE: Plugin entry point must match the assembly name, otherwise ETABS hits you with a "Not found" error when loading plugin
// Disabling error below to prioritize DUI3 project structure. Name of cPlugin class cannot be changed
#pragma warning disable IDE0130
namespace Speckle.Connectors.ETABS21;

public class SpeckleForm : SpeckleFormBase
{
protected override HostAppVersion GetVersion() => HostAppVersion.v2021;
}
12 changes: 12 additions & 0 deletions Connectors/CSi/Speckle.Connectors.ETABS21/Plugin/cPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Speckle.Connectors.CSiShared;

// NOTE: Plugin entry point must match the assembly name, otherwise ETABS hits you with a "Not found" error when loading plugin
// Disabling error below to prioritize DUI3 project structure. Name of cPlugin class cannot be changed
#pragma warning disable IDE0130
namespace Speckle.Connectors.ETABS21;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "<Pending>")]
public class cPlugin : CSiSharedPluginBase
{
protected override SpeckleFormBase CreateForm() => new SpeckleForm();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"ETABS 21": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\Computers and Structures\\ETABS 21\\ETABS.exe"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>AnyCPU</Platforms>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<ETABSVersion>21</ETABSVersion>
<DefineConstants>$(DefineConstants);ETABS21</DefineConstants>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>

<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>
<PackageReference Include="Speckle.CSI.API" PrivateAssets="all" IncludeAssets="compile; build" VersionOverride="1.30.0"/>
</ItemGroup>

<ItemGroup>
<Compile Update="Plugin\SpeckleForm.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>

<Import Project="..\Speckle.Connectors.CSiShared\Speckle.Connectors.CSiShared.projitems" Label="Shared" />

</Project>
Loading

0 comments on commit 0be8897

Please sign in to comment.