-
Notifications
You must be signed in to change notification settings - Fork 7
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
bjorn/cnx-835-add-converter-projects-and-top-level-converter #429
Merged
bjoernsteinhagen
merged 22 commits into
dev
from
bjorn/cnx-835-add-converter-projects-and-top-level-converter
Dec 3, 2024
Merged
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5ad5d3f
Initial commit
bjoernsteinhagen 1d76983
CSiObjectToSpeckleConverter
bjoernsteinhagen 80178ce
ICSiWrapper with factory
bjoernsteinhagen aac56b8
raw conversion placeholders
bjoernsteinhagen 03f90f2
service registration
bjoernsteinhagen 9f23c50
root to speckle
bjoernsteinhagen 336b5c5
type registration and resolution
bjoernsteinhagen 0091272
Setting up object level converters
bjoernsteinhagen b5fb154
some basic conversions
bjoernsteinhagen 173451f
units framework
bjoernsteinhagen 4800996
raw conversion placeholders
bjoernsteinhagen 71b3298
CollectionManager
bjoernsteinhagen fce77fc
Comments
bjoernsteinhagen d11c0d6
back to BASE-ics
bjoernsteinhagen 84d5a64
local
bjoernsteinhagen 03dca19
csharpier
bjoernsteinhagen af1d872
newline
bjoernsteinhagen 93fce9e
Merge branch 'dev' into bjorn/cnx-835-add-converter-projects-and-top-…
bjoernsteinhagen f862e13
AddObjectCollectionToRoot
bjoernsteinhagen 76d9f65
Merge remote-tracking branch 'origin/bjorn/cnx-835-add-converter-proj…
bjoernsteinhagen 79de2e1
Merge branch 'dev' into bjorn/cnx-835-add-converter-projects-and-top-…
clairekuang 7f1da73
cleaning locks
bjoernsteinhagen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Connectors/CSi/Speckle.Connectors.CSiShared/HostApp/CSiApplicationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace Speckle.Connectors.CSiShared.HostApp; | ||
|
||
/// <summary> | ||
/// Create a centralized access point for ETABS and SAP APIs across the entire program. | ||
/// </summary> | ||
/// <remarks> | ||
/// All API methods are based on the objectType and objectName, not the GUID. | ||
/// CSi is already giving us the "sapModel" reference through the plugin interface. No need to attach to running instance. | ||
/// Since objectType is a single int (1, 2 ... 7) we know first index will always be the objectType. | ||
/// Prevent having to pass the "sapModel" around between classes and this ensures consistent access. | ||
/// Name "sapModel" is misleading since it doesn't only apply to SAP2000, but this is the convention in the API, so we keep it. | ||
/// </remarks> | ||
public interface ICSiApplicationService | ||
{ | ||
cSapModel SapModel { get; } | ||
void Initialize(cSapModel sapModel, cPluginCallback pluginCallback); | ||
} | ||
|
||
public class CSiApplicationService : ICSiApplicationService | ||
{ | ||
public cSapModel SapModel { get; private set; } | ||
private cPluginCallback _pluginCallback; | ||
|
||
public CSiApplicationService() | ||
{ | ||
SapModel = null!; | ||
} | ||
|
||
public void Initialize(cSapModel sapModel, cPluginCallback pluginCallback) | ||
{ | ||
SapModel = sapModel; | ||
_pluginCallback = pluginCallback; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
Connectors/CSi/Speckle.Connectors.CSiShared/HostApp/CSiDocumentModelStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System.IO; | ||
using Microsoft.Extensions.Logging; | ||
using Speckle.Connectors.DUI.Models; | ||
using Speckle.Connectors.DUI.Utils; | ||
using Speckle.Sdk; | ||
using Speckle.Sdk.Helpers; | ||
using Speckle.Sdk.Logging; | ||
|
||
namespace Speckle.Connectors.CSiShared.HostApp; | ||
|
||
public class CSiDocumentModelStore : DocumentModelStore | ||
{ | ||
private readonly ISpeckleApplication _speckleApplication; | ||
private readonly ILogger<CSiDocumentModelStore> _logger; | ||
private readonly ICSiApplicationService _csiApplicationService; | ||
private string HostAppUserDataPath { get; set; } | ||
private string DocumentStateFile { get; set; } | ||
private string ModelPathHash { get; set; } | ||
|
||
public CSiDocumentModelStore( | ||
IJsonSerializer jsonSerializerSettings, | ||
ISpeckleApplication speckleApplication, | ||
ILogger<CSiDocumentModelStore> logger, | ||
ICSiApplicationService csiApplicationService | ||
) | ||
: base(jsonSerializerSettings) | ||
{ | ||
_speckleApplication = speckleApplication; | ||
_logger = logger; | ||
_csiApplicationService = csiApplicationService; | ||
SetPaths(); | ||
LoadState(); | ||
} | ||
|
||
private void SetPaths() | ||
{ | ||
ModelPathHash = Crypt.Md5(_csiApplicationService.SapModel.GetModelFilepath(), length: 32); | ||
HostAppUserDataPath = Path.Combine( | ||
SpecklePathProvider.UserSpeckleFolderPath, | ||
"ConnectorsFileData", | ||
_speckleApplication.Slug | ||
); | ||
DocumentStateFile = Path.Combine(HostAppUserDataPath, $"{ModelPathHash}.json"); | ||
} | ||
|
||
protected override void HostAppSaveState(string modelCardState) | ||
{ | ||
try | ||
{ | ||
if (!Directory.Exists(HostAppUserDataPath)) | ||
{ | ||
Directory.CreateDirectory(HostAppUserDataPath); | ||
} | ||
File.WriteAllText(DocumentStateFile, modelCardState); | ||
} | ||
catch (Exception ex) when (!ex.IsFatal()) | ||
{ | ||
_logger.LogError(ex.Message); | ||
} | ||
} | ||
|
||
protected override void LoadState() | ||
{ | ||
if (!Directory.Exists(HostAppUserDataPath)) | ||
{ | ||
ClearAndSave(); | ||
return; | ||
} | ||
|
||
if (!File.Exists(DocumentStateFile)) | ||
{ | ||
ClearAndSave(); | ||
return; | ||
} | ||
|
||
string serializedState = File.ReadAllText(DocumentStateFile); | ||
LoadFromString(serializedState); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Connectors/CSi/Speckle.Connectors.CSiShared/HostApp/CSiSendCollectionManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.CSiShared; | ||
using Speckle.Sdk.Models.Collections; | ||
|
||
namespace Speckle.Connectors.CSiShared.HostApp; | ||
|
||
/// <summary> | ||
/// We can use the CSiWrappers to create our collection structure. | ||
/// </summary> | ||
/// <remarks> | ||
/// This class manages the collections. If the key (from the path) already exists, this collection is returned. | ||
/// If it doesn't exist, a new collection is created and added to the rootObject. | ||
/// </remarks> | ||
public class CSiSendCollectionManager | ||
{ | ||
private readonly IConverterSettingsStore<CSiConversionSettings> _converterSettings; | ||
private readonly Dictionary<string, Collection> _collectionCache = new(); | ||
|
||
public CSiSendCollectionManager(IConverterSettingsStore<CSiConversionSettings> converterSettings) | ||
{ | ||
_converterSettings = converterSettings; | ||
} | ||
|
||
// TODO: Frames could be further classified under Columns, Braces and Beams. Same for Shells which could be classified into walls, floors | ||
public Collection GetAndCreateObjectHostCollection(ICSiWrapper csiObject, Collection rootObject) | ||
{ | ||
var path = csiObject.GetType().Name.Replace("Wrapper", ""); // CSiJointWrapper → CSiJoint, CSiFrameWrapper → CSiFrame etc. | ||
|
||
if (_collectionCache.TryGetValue(path, out Collection? value)) | ||
{ | ||
return value; | ||
} | ||
|
||
Collection childCollection = new(path); | ||
rootObject.elements.Add(childCollection); | ||
_collectionCache[path] = childCollection; | ||
|
||
rootObject = childCollection; | ||
|
||
return rootObject; | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
Connectors/CSi/Speckle.Connectors.CSiShared/HostApp/CSiSharedApplicationService.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be renamed to
AddObjectCollectionToRoot
, which would be more descriptive.Why is the root collection being set to the newly created collection? probably can just return the created one directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under commit "AddObjectCollectionToRoot":
AddObjectCollectionToRoot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment probably applies to Revit too Revit - SendCollectionManager.cs