From 11557554964a58e4fb97c39105968ba40abb605a Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Tue, 19 Sep 2023 18:00:45 +0200 Subject: [PATCH 01/49] chore(CSI): Run CSharpier on all CSI related projects (#2947) * chore(csi): Run csharpier on CSI converter projects * chore(csi): Run csharpier in CSI connector projects --- .../StreamStateManager/StreamStateManager.cs | 43 +++- .../ConnectorBindingsCSI.ClientOperations.cs | 3 +- .../UI/ConnectorBindingsCSI.Recieve.cs | 66 +++-- .../UI/ConnectorBindingsCSI.Selection.cs | 77 +++--- .../UI/ConnectorBindingsCSI.Send.cs | 83 +++++-- .../UI/ConnectorBindingsCSI.Settings.cs | 31 ++- .../Util/ConnectorCSIUtils.cs | 168 ++++++++++--- ConnectorCSI/ConnectorCSIShared/cPlugin.cs | 17 +- ConnectorCSI/DriverCSharp/PluginCallback.cs | 10 +- ConnectorCSI/DriverCSharp/Program.cs | 22 +- .../ConverterCSIShared/ConverterCSIUtils.cs | 40 ++- .../Extensions/PolycurveExtensions.cs | 3 +- .../Partial Classes/Analysis/ConvertModel.cs | 12 +- .../Analysis/ConvertModelInfo.cs | 17 +- .../Analysis/ConvertModelSettings.cs | 9 +- .../Analysis/ConvertModelUnits.cs | 3 +- .../Partial Classes/Geometry/ConvertArea.cs | 97 ++++++-- .../Partial Classes/Geometry/ConvertBraces.cs | 2 +- .../Geometry/ConvertBuiltElement.cs | 5 +- .../Partial Classes/Geometry/ConvertColumn.cs | 2 +- .../Partial Classes/Geometry/ConvertFloor.cs | 2 +- .../Partial Classes/Geometry/ConvertFrame.cs | 108 ++++++--- .../Geometry/ConvertGridLines.cs | 22 +- .../Partial Classes/Geometry/ConvertLine.cs | 4 +- .../Partial Classes/Geometry/ConvertLinks.cs | 14 +- .../Partial Classes/Geometry/ConvertPier.cs | 5 +- .../Partial Classes/Geometry/ConvertPoint.cs | 52 ++-- .../Geometry/ConvertSpandrel.cs | 46 +++- .../Geometry/ConvertStories.cs | 39 ++- .../Partial Classes/Geometry/ConvertTendon.cs | 5 +- .../Loading/ConvertLoadPattern.cs | 17 +- .../Loading/Loading1DElements.cs | 104 ++++++-- .../Loading/Loading2DElements.cs | 39 ++- .../Partial Classes/Loading/LoadingNode.cs | 26 +- .../Materials/ConvertMaterials.cs | 197 ++++++++++----- .../Properties/Convert1DProperty.cs | 95 +++++--- .../Properties/Convert2DProperty.cs | 9 +- .../Properties/Convert2DPropertyFloor.cs | 197 ++++++++++----- .../Properties/Convert2DPropertyWall.cs | 12 +- .../Properties/ConvertDiaphragm.cs | 8 +- .../Properties/ConvertLinkProperty.cs | 12 +- .../Properties/ConvertSectionProfile.cs | 130 ++++++++-- .../Properties/ConvertSpring.cs | 110 ++++++++- .../Properties/ConvertTendonProperty.cs | 9 +- .../Results/ConvertResultGlobal.cs | 43 +++- .../Results/ConvertResultNodes.cs | 71 +++++- .../Results/ConvertResultSet1D.cs | 105 ++++++-- .../Results/ConvertResultSet2D.cs | 227 ++++++++++++++---- .../Partial Classes/Results/ConvertResults.cs | 9 +- 49 files changed, 1800 insertions(+), 627 deletions(-) diff --git a/ConnectorCSI/ConnectorCSIShared/StreamStateManager/StreamStateManager.cs b/ConnectorCSI/ConnectorCSIShared/StreamStateManager/StreamStateManager.cs index 084f242289..be01ee1006 100644 --- a/ConnectorCSI/ConnectorCSIShared/StreamStateManager/StreamStateManager.cs +++ b/ConnectorCSI/ConnectorCSIShared/StreamStateManager/StreamStateManager.cs @@ -12,6 +12,7 @@ namespace ConnectorCSI.Storage public static class StreamStateManager { private static string _speckleFilePath; + public static List ReadState(cSapModel model) { var strings = ReadSpeckleFile(model); @@ -37,9 +38,14 @@ public static List ReadState(cSapModel model) /// public static void WriteStreamStateList(cSapModel model, List streamStates) { - if (_speckleFilePath == null) + if (_speckleFilePath == null) GetOrCreateSpeckleFilePath(model); - FileStream fileStream = new FileStream(_speckleFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); + FileStream fileStream = new FileStream( + _speckleFilePath, + FileMode.Open, + FileAccess.ReadWrite, + FileShare.ReadWrite + ); using (var streamWriter = new StreamWriter(fileStream)) { @@ -50,8 +56,14 @@ public static void WriteStreamStateList(cSapModel model, List strea public static void ClearStreamStateList(cSapModel model) { - if (_speckleFilePath == null) GetOrCreateSpeckleFilePath(model); - FileStream fileStream = new FileStream(_speckleFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); + if (_speckleFilePath == null) + GetOrCreateSpeckleFilePath(model); + FileStream fileStream = new FileStream( + _speckleFilePath, + FileMode.Open, + FileAccess.ReadWrite, + FileShare.ReadWrite + ); try { fileStream.SetLength(0); @@ -106,7 +118,8 @@ private static string ReadSpeckleFile(cSapModel model) if (_speckleFilePath == null) GetOrCreateSpeckleFilePath(model); - if (_speckleFilePath == null) return ""; + if (_speckleFilePath == null) + return ""; FileStream fileStream = new FileStream(_speckleFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); try { @@ -115,7 +128,10 @@ private static string ReadSpeckleFile(cSapModel model) return streamReader.ReadToEnd(); } } - catch { return ""; } + catch + { + return ""; + } } /// @@ -136,9 +152,12 @@ public static void SaveBackupFile(cSapModel model) string speckleFolderPath = Path.Combine(CSIModelFolder, "speckle"); var backups = new List<(DateTime, string)>(); - foreach (var fileName in Directory.GetFiles(speckleFolderPath)) - { - if (fileName.Contains($"{CSIFileName}_speckleBackup") && fileName.Split('.').Last().ToLower() == fileExtension.ToLower()) + foreach (var fileName in Directory.GetFiles(speckleFolderPath)) + { + if ( + fileName.Contains($"{CSIFileName}_speckleBackup") + && fileName.Split('.').Last().ToLower() == fileExtension.ToLower() + ) { backups.Add((File.GetLastWriteTime(fileName), fileName)); } @@ -146,7 +165,9 @@ public static void SaveBackupFile(cSapModel model) if (backups.Count < 3) { - model.File.Save(Path.Combine(speckleFolderPath, $"{CSIFileName}_speckleBackup{backups.Count + 1}.{fileExtension}")); + model.File.Save( + Path.Combine(speckleFolderPath, $"{CSIFileName}_speckleBackup{backups.Count + 1}.{fileExtension}") + ); } else { @@ -159,4 +180,4 @@ public static void SaveBackupFile(cSapModel model) model.File.Save(CSIModelfilePath); } } -} \ No newline at end of file +} diff --git a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.ClientOperations.cs b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.ClientOperations.cs index 828660b364..a217c234b8 100644 --- a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.ClientOperations.cs +++ b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.ClientOperations.cs @@ -12,7 +12,6 @@ namespace Speckle.ConnectorCSI.UI { public partial class ConnectorBindingsCSI : ConnectorBindings - { #region Local stream I/O with local file public override List GetCustomStreamMenuItems() @@ -33,4 +32,4 @@ public override List GetStreamsInFile() #endregion } -} \ No newline at end of file +} diff --git a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs index e8259387b5..29d7ed731d 100644 --- a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs +++ b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs @@ -22,6 +22,7 @@ public partial class ConnectorBindingsCSI : ConnectorBindings public List Preview { get; set; } = new List(); public Dictionary StoredObjects = new Dictionary(); public override bool CanPreviewReceive => false; + public override Task PreviewReceive(StreamState state, ProgressViewModel progress) { return null; @@ -46,17 +47,16 @@ public override async Task ReceiveStream(StreamState state, Progres converter.SetContextDocument(Model); Exceptions.Clear(); var previouslyReceivedObjects = state.ReceivedObjects; - + progress.CancellationToken.ThrowIfCancellationRequested(); - - Exceptions.Clear(); + Exceptions.Clear(); Commit commit = await ConnectorHelpers.GetCommitFromState(state, progress.CancellationToken); state.LastCommit = commit; Base commitObject = await ConnectorHelpers.ReceiveCommit(commit, state, progress); await ConnectorHelpers.TryCommitReceived(state, commit, GetHostAppVersion(Model), progress.CancellationToken); - + Preview.Clear(); StoredObjects.Clear(); @@ -75,7 +75,7 @@ public override async Task ReceiveStream(StreamState state, Progres progress.Report.Log(previewObj); converter.ReceiveMode = state.ReceiveMode; - // needs to be set for editing to work + // needs to be set for editing to work converter.SetPreviousContextObjects(previouslyReceivedObjects); progress.CancellationToken.ThrowIfCancellationRequested(); @@ -83,7 +83,7 @@ public override async Task ReceiveStream(StreamState state, Progres StreamStateManager.SaveBackupFile(Model); var newPlaceholderObjects = ConvertReceivedObjects(converter, progress); - + DeleteObjects(previouslyReceivedObjects, newPlaceholderObjects, progress); // The following block of code is a hack to properly refresh the view @@ -144,7 +144,7 @@ private List ConvertReceivedObjects(ISpeckleConverter convert } /// - /// Recurses through the commit object and flattens it. + /// Recurses through the commit object and flattens it. /// /// /// @@ -155,7 +155,11 @@ private List FlattenCommitObject(object obj, ISpeckleConverte if (obj is Base @base) { - var appObj = new ApplicationObject(@base.id, ConnectorCSIUtils.SimplifySpeckleType(@base.speckle_type)) { applicationId = @base.applicationId, Status = ApplicationObject.State.Unknown }; + var appObj = new ApplicationObject(@base.id, ConnectorCSIUtils.SimplifySpeckleType(@base.speckle_type)) + { + applicationId = @base.applicationId, + Status = ApplicationObject.State.Unknown + }; if (converter.CanConvertToNative(@base)) { @@ -188,13 +192,15 @@ private List FlattenCommitObject(object obj, ISpeckleConverte objects.AddRange(FlattenCommitObject(kvp.Value, converter)); return objects; } - else { if (obj != null && !obj.GetType().IsPrimitive && !(obj is string)) { var appObj = new ApplicationObject(obj.GetHashCode().ToString(), obj.GetType().ToString()); - appObj.Update(status: ApplicationObject.State.Skipped, logItem: $"Receiving this object type is not supported in CSI"); + appObj.Update( + status: ApplicationObject.State.Skipped, + logItem: $"Receiving this object type is not supported in CSI" + ); objects.Add(appObj); } } @@ -213,7 +219,14 @@ private void RefreshDatabaseTable(string floorTableKey) int numInfoMsgs = 0; int numErrorMsgs = 0; string importLog = ""; - Model.DatabaseTables.GetTableForEditingArray(floorTableKey, "ThisParamIsNotActiveYet", ref tableVersion, ref fieldsKeysIncluded, ref numberRecords, ref tableData); + Model.DatabaseTables.GetTableForEditingArray( + floorTableKey, + "ThisParamIsNotActiveYet", + ref tableVersion, + ref fieldsKeysIncluded, + ref numberRecords, + ref tableData + ); double version = 0; string versionString = null; @@ -225,12 +238,29 @@ private void RefreshDatabaseTable(string floorTableKey) if (programVersion.CompareTo("20.0.0") < 0 && fieldsKeysIncluded[0] == "UniqueName") fieldsKeysIncluded[0] = "Unique Name"; - Model.DatabaseTables.SetTableForEditingArray(floorTableKey, ref tableVersion, ref fieldsKeysIncluded, numberRecords, ref tableData); - Model.DatabaseTables.ApplyEditedTables(false, ref numFatalErrors, ref numErrorMsgs, ref numWarnMsgs, ref numInfoMsgs, ref importLog); + Model.DatabaseTables.SetTableForEditingArray( + floorTableKey, + ref tableVersion, + ref fieldsKeysIncluded, + numberRecords, + ref tableData + ); + Model.DatabaseTables.ApplyEditedTables( + false, + ref numFatalErrors, + ref numErrorMsgs, + ref numWarnMsgs, + ref numInfoMsgs, + ref importLog + ); } // delete previously sent objects that are no longer in this stream - private void DeleteObjects(List previouslyReceiveObjects, List newPlaceholderObjects, ProgressViewModel progress) + private void DeleteObjects( + List previouslyReceiveObjects, + List newPlaceholderObjects, + ProgressViewModel progress + ) { foreach (var obj in previouslyReceiveObjects) { @@ -239,7 +269,13 @@ private void DeleteObjects(List previouslyReceiveObjects, Lis for (int i = 0; i < obj.Converted.Count; i++) { - if (!(obj.Converted[i] is string s && s.Split(new[] { ConnectorCSIUtils.delimiter }, StringSplitOptions.None) is string[] typeAndName && typeAndName.Length == 2)) + if ( + !( + obj.Converted[i] is string s + && s.Split(new[] { ConnectorCSIUtils.delimiter }, StringSplitOptions.None) is string[] typeAndName + && typeAndName.Length == 2 + ) + ) continue; switch (typeAndName[0]) diff --git a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Selection.cs b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Selection.cs index 961c5231b8..8f673691e6 100644 --- a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Selection.cs +++ b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Selection.cs @@ -13,7 +13,8 @@ public override List GetSelectedObjects() { var names = new List(); var typeNameTupleList = ConnectorCSIUtils.SelectedObjects(Model); - if (typeNameTupleList == null) return new List() { }; + if (typeNameTupleList == null) + return new List() { }; foreach (var item in typeNameTupleList) { (string typeName, string name) = item; @@ -29,43 +30,48 @@ public override List GetSelectedObjects() public override List GetSelectionFilters() { var filters = new List(); - filters.Add(new AllSelectionFilter - { - Slug = "all", - Name = "Everything", - Icon = "CubeScan", - Description = "Selects all document objects." - }); + filters.Add( + new AllSelectionFilter + { + Slug = "all", + Name = "Everything", + Icon = "CubeScan", + Description = "Selects all document objects." + } + ); filters.Add(new ManualSelectionFilter()); if (Model != null) { ConnectorCSIUtils.GetObjectIDsTypesAndNames(Model); - var objectTypes = ConnectorCSIUtils.ObjectIDsTypesAndNames - .Select(pair => pair.Value.Item1).Distinct().ToList(); - + var objectTypes = ConnectorCSIUtils.ObjectIDsTypesAndNames.Select(pair => pair.Value.Item1).Distinct().ToList(); + if (objectTypes.Any()) - filters.Add(new ListSelectionFilter - { - Slug = "type", - Name = "Categories", - Icon = "Category", - Values = objectTypes, - Description = "Adds all objects belonging to the selected types." - }); + filters.Add( + new ListSelectionFilter + { + Slug = "type", + Name = "Categories", + Icon = "Category", + Values = objectTypes, + Description = "Adds all objects belonging to the selected types." + } + ); string[] groupNames = new string[0]; int numNames = 0; Model.GroupDef.GetNameList(ref numNames, ref groupNames); if (groupNames.Any()) - filters.Add(new ListSelectionFilter - { - Slug = "group", - Name = "Group", - Icon = "SelectGroup", - Values = groupNames.ToList(), - Description = "Add all objects belonging to CSI Group." - }); + filters.Add( + new ListSelectionFilter + { + Slug = "group", + Name = "Group", + Icon = "SelectGroup", + Values = groupNames.ToList(), + Description = "Add all objects belonging to CSI Group." + } + ); } return filters; @@ -89,8 +95,7 @@ private List GetSelectionFilterObjects(ISelectionFilter filter) return GetSelectedObjects(); case "all": - selection.AddRange(ConnectorCSIUtils.ObjectIDsTypesAndNames - .Select(pair => pair.Key).ToList()); + selection.AddRange(ConnectorCSIUtils.ObjectIDsTypesAndNames.Select(pair => pair.Key).ToList()); return selection; case "type": @@ -98,10 +103,12 @@ private List GetSelectionFilterObjects(ISelectionFilter filter) foreach (var type in typeFilter.Selection) { - selection.AddRange(ConnectorCSIUtils.ObjectIDsTypesAndNames + selection.AddRange( + ConnectorCSIUtils.ObjectIDsTypesAndNames .Where(pair => pair.Value.Item1 == type) .Select(pair => pair.Key) - .ToList()); + .ToList() + ); } return selection; @@ -110,14 +117,14 @@ private List GetSelectionFilterObjects(ISelectionFilter filter) Model.SelectObj.ClearSelection(); var groupFilter = filter as ListSelectionFilter; foreach (var group in groupFilter.Selection) - { Model.SelectObj.Group(group); } + { + Model.SelectObj.Group(group); + } return GetSelectedObjects(); - } return selection; - } } -} \ No newline at end of file +} diff --git a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Send.cs b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Send.cs index 470693c354..0af921f729 100644 --- a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Send.cs +++ b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Send.cs @@ -18,6 +18,7 @@ namespace Speckle.ConnectorCSI.UI public partial class ConnectorBindingsCSI : ConnectorBindings { public override bool CanPreviewSend => false; + public override void PreviewSend(StreamState state, ProgressViewModel progress) { // TODO! @@ -51,7 +52,9 @@ public override async Task SendStream(StreamState state, ProgressViewMod if (totalObjectCount == 0) { - throw new InvalidOperationException( "Zero objects selected; send stopped. Please select some objects, or check that your filter can actually select something."); + throw new InvalidOperationException( + "Zero objects selected; send stopped. Please select some objects, or check that your filter can actually select something." + ); } var conversionProgressDict = new ConcurrentDictionary(); @@ -66,7 +69,12 @@ public override async Task SendStream(StreamState state, ProgressViewMod return await SendCommitObj(state, progress, commitObj, conversionProgressDict); } - public void BuildSendCommitObj(ISpeckleConverter converter, List selectedObjIds, ref ProgressViewModel progress, ref ConcurrentDictionary conversionProgressDict) + public void BuildSendCommitObj( + ISpeckleConverter converter, + List selectedObjIds, + ref ProgressViewModel progress, + ref ConcurrentDictionary conversionProgressDict + ) { foreach (var applicationId in selectedObjIds) { @@ -75,10 +83,10 @@ public void BuildSendCommitObj(ISpeckleConverter converter, List selecte Base converted = null; string containerName = string.Empty; - var selectedObjectType = ConnectorCSIUtils.ObjectIDsTypesAndNames - .Where(pair => pair.Key == applicationId) - .Select(pair => pair.Value.Item1).FirstOrDefault(); + .Where(pair => pair.Key == applicationId) + .Select(pair => pair.Value.Item1) + .FirstOrDefault(); var reportObj = new ApplicationObject(applicationId, selectedObjectType) { applicationId = applicationId }; @@ -89,8 +97,9 @@ public void BuildSendCommitObj(ISpeckleConverter converter, List selecte } var typeAndName = ConnectorCSIUtils.ObjectIDsTypesAndNames - .Where(pair => pair.Key == applicationId) - .Select(pair => pair.Value).FirstOrDefault(); + .Where(pair => pair.Key == applicationId) + .Select(pair => pair.Value) + .FirstOrDefault(); try { @@ -110,7 +119,10 @@ public void BuildSendCommitObj(ISpeckleConverter converter, List selecte continue; } - reportObj.Update(status: ApplicationObject.State.Created, logItem: $"Sent as {ConnectorCSIUtils.SimplifySpeckleType(converted.speckle_type)}"); + reportObj.Update( + status: ApplicationObject.State.Created, + logItem: $"Sent as {ConnectorCSIUtils.SimplifySpeckleType(converted.speckle_type)}" + ); progress.Report.Log(reportObj); conversionProgressDict["Conversion"]++; @@ -118,7 +130,11 @@ public void BuildSendCommitObj(ISpeckleConverter converter, List selecte } } - public Base GetCommitObj(ISpeckleConverter converter, ProgressViewModel progress, ConcurrentDictionary conversionProgressDict) + public Base GetCommitObj( + ISpeckleConverter converter, + ProgressViewModel progress, + ConcurrentDictionary conversionProgressDict + ) { var commitObj = new Base(); var reportObj = new ApplicationObject("model", "ModelInfo"); @@ -163,7 +179,13 @@ public Base GetCommitObj(ISpeckleConverter converter, ProgressViewModel progress return commitObj; } - public async Task SendCommitObj(StreamState state, ProgressViewModel progress, Base commitObj, ConcurrentDictionary conversionProgressDict, string branchName = null) + public async Task SendCommitObj( + StreamState state, + ProgressViewModel progress, + Base commitObj, + ConcurrentDictionary conversionProgressDict, + string branchName = null + ) { var streamId = state.StreamId; var client = state.Client; @@ -172,25 +194,29 @@ public async Task SendCommitObj(StreamState state, ProgressViewModel pro progress.Max = conversionProgressDict["Conversion"]; var objectId = await Operations.Send( - @object: commitObj, - cancellationToken: progress.CancellationToken, - transports: transports, - onProgressAction: dict => - { - progress.Update(dict); - }, - onErrorAction: ConnectorHelpers.DefaultSendErrorHandler, - disposeTransports: true - ); - - + @object: commitObj, + cancellationToken: progress.CancellationToken, + transports: transports, + onProgressAction: dict => + { + progress.Update(dict); + }, + onErrorAction: ConnectorHelpers.DefaultSendErrorHandler, + disposeTransports: true + ); + if (branchName != null) { var branchesSplit = state.BranchName.Split('/'); branchesSplit[branchesSplit.Count() - 1] = branchName; branchName = string.Join("", branchesSplit); - var branchInput = new BranchCreateInput() { streamId = streamId, name = branchName, description = "This branch holds the comprehensive reports generated by Speckle"}; + var branchInput = new BranchCreateInput() + { + streamId = streamId, + name = branchName, + description = "This branch holds the comprehensive reports generated by Speckle" + }; var branch = await client.BranchGet(streamId, branchName); if (branch == null) await client.BranchCreate(branchInput); @@ -203,14 +229,19 @@ public async Task SendCommitObj(StreamState state, ProgressViewModel pro streamId = streamId, objectId = objectId, branchName = branchName, - message = state.CommitMessage != null ? state.CommitMessage : $"Pushed {conversionProgressDict["Conversion"]} elements from CSI.", + message = + state.CommitMessage != null + ? state.CommitMessage + : $"Pushed {conversionProgressDict["Conversion"]} elements from CSI.", sourceApplication = GetHostAppVersion(Model) }; - if (state.PreviousCommitId != null) { actualCommit.parents = new List() { state.PreviousCommitId }; } + if (state.PreviousCommitId != null) + { + actualCommit.parents = new List() { state.PreviousCommitId }; + } return await ConnectorHelpers.CreateCommit(client, actualCommit, progress.CancellationToken); - } } } diff --git a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Settings.cs b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Settings.cs index 1e7550e7e6..8ee5058881 100644 --- a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Settings.cs +++ b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Settings.cs @@ -12,13 +12,38 @@ public partial class ConnectorBindingsCSI : ConnectorBindings readonly string SendNodeResults = "sendNodeResults"; readonly string Send1DResults = "send1DResults"; readonly string Send2DResults = "send2DResults"; + public override List GetSettings() { return new List { - new CheckBoxSetting {Slug = SendNodeResults, Name = "Send Node Analysis Results", Icon ="Link", IsChecked= false, Description = "Include node analysis results with object data when sending to Speckle. This will make the sending process take more time."}, - new CheckBoxSetting {Slug = Send1DResults, Name = "Send 1D Analysis Results", Icon ="Link", IsChecked= false, Description = "Include 1D analysis results with object data when sending to Speckle. This will make the sending process take more time."}, - new CheckBoxSetting {Slug = Send2DResults, Name = "Send 2D Analysis Results", Icon ="Link", IsChecked= false, Description = "Include 2D analysis results with object data when sending to Speckle. This will make the sending process take MUCH more time."}, + new CheckBoxSetting + { + Slug = SendNodeResults, + Name = "Send Node Analysis Results", + Icon = "Link", + IsChecked = false, + Description = + "Include node analysis results with object data when sending to Speckle. This will make the sending process take more time." + }, + new CheckBoxSetting + { + Slug = Send1DResults, + Name = "Send 1D Analysis Results", + Icon = "Link", + IsChecked = false, + Description = + "Include 1D analysis results with object data when sending to Speckle. This will make the sending process take more time." + }, + new CheckBoxSetting + { + Slug = Send2DResults, + Name = "Send 2D Analysis Results", + Icon = "Link", + IsChecked = false, + Description = + "Include 2D analysis results with object data when sending to Speckle. This will make the sending process take MUCH more time." + }, }; } } diff --git a/ConnectorCSI/ConnectorCSIShared/Util/ConnectorCSIUtils.cs b/ConnectorCSI/ConnectorCSIShared/Util/ConnectorCSIUtils.cs index e622e9c2f5..3c2d89d682 100644 --- a/ConnectorCSI/ConnectorCSIShared/Util/ConnectorCSIUtils.cs +++ b/ConnectorCSI/ConnectorCSIShared/Util/ConnectorCSIUtils.cs @@ -126,6 +126,7 @@ public static List GetAllNamesOfObjectType(cSapModel model, string objec return null; } } + #region Get List Names public static List GetAllPointNames(cSapModel model) { @@ -136,9 +137,12 @@ public static List GetAllPointNames(cSapModel model) model.PointObj.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } - + catch + { + return null; + } } + public static List GetAllFrameNames(cSapModel model) { int num = 0; @@ -148,7 +152,10 @@ public static List GetAllFrameNames(cSapModel model) model.FrameObj.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } public static List GetColumnNames(cSapModel model) @@ -239,8 +246,12 @@ public static List GetAllTendonNames(cSapModel model) model.TendonObj.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllAreaNames(cSapModel model) { int num = 0; @@ -250,7 +261,10 @@ public static List GetAllAreaNames(cSapModel model) model.AreaObj.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } public static List GetAllWallNames(cSapModel model) @@ -274,6 +288,7 @@ public static List GetAllWallNames(cSapModel model) return WallName; } + public static List GetAllFloorNames(cSapModel model) { var FloorNames = GetAllAreaNames(model); @@ -295,6 +310,7 @@ public static List GetAllFloorNames(cSapModel model) return FloorName; } + public static List GetAllLinkNames(cSapModel model) { int num = 0; @@ -304,8 +320,12 @@ public static List GetAllLinkNames(cSapModel model) model.LinkObj.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllPropMaterialNames(cSapModel model) { int num = 0; @@ -315,8 +335,12 @@ public static List GetAllPropMaterialNames(cSapModel model) model.PropMaterial.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllPropRebarNames(cSapModel model) { int num = 0; @@ -326,8 +350,12 @@ public static List GetAllPropRebarNames(cSapModel model) model.PropRebar.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllPropFrameNames(cSapModel model) { int num = 0; @@ -337,8 +365,12 @@ public static List GetAllPropFrameNames(cSapModel model) model.PropFrame.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllLoadCaseNames(cSapModel model) { int num = 0; @@ -348,8 +380,12 @@ public static List GetAllLoadCaseNames(cSapModel model) model.LoadCases.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllGroupNames(cSapModel model) { int num = 0; @@ -359,8 +395,12 @@ public static List GetAllGroupNames(cSapModel model) model.GroupDef.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllGridNames(cSapModel model) { int num = 0; @@ -370,8 +410,12 @@ public static List GetAllGridNames(cSapModel model) model.GridSys.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllComboNames(cSapModel model) { int num = 0; @@ -381,8 +425,12 @@ public static List GetAllComboNames(cSapModel model) model.RespCombo.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllConstraintNames(cSapModel model) { int num = 0; @@ -392,8 +440,12 @@ public static List GetAllConstraintNames(cSapModel model) model.ConstraintDef.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllLoadPatternNames(cSapModel model) { int num = 0; @@ -403,8 +455,12 @@ public static List GetAllLoadPatternNames(cSapModel model) model.LoadPatterns.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllSteelDesignNames(cSapModel model) { var name = ""; @@ -413,8 +469,12 @@ public static List GetAllSteelDesignNames(cSapModel model) model.DesignSteel.GetCode(ref name); return new List() { name }; } - catch { return null; } + catch + { + return null; + } } + public static List GetAllConcreteDesignNames(cSapModel model) { var name = ""; @@ -423,8 +483,12 @@ public static List GetAllConcreteDesignNames(cSapModel model) model.DesignConcrete.GetCode(ref name); return new List() { name }; } - catch { return null; } + catch + { + return null; + } } + public static List GetAllStoryNames(cSapModel model) { int num = 0; @@ -434,8 +498,12 @@ public static List GetAllStoryNames(cSapModel model) model.Story.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllDiaphragmNames(cSapModel model) { int num = 0; @@ -445,8 +513,12 @@ public static List GetAllDiaphragmNames(cSapModel model) model.Diaphragm.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllLineNames(cSapModel model) { int num = 0; @@ -456,8 +528,12 @@ public static List GetAllLineNames(cSapModel model) model.LineElm.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllPierLabelNames(cSapModel model) { int num = 0; @@ -467,8 +543,12 @@ public static List GetAllPierLabelNames(cSapModel model) model.PierLabel.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllPropAreaSpringNames(cSapModel model) { int num = 0; @@ -478,8 +558,12 @@ public static List GetAllPropAreaSpringNames(cSapModel model) model.PropAreaSpring.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllPropLineSpringNames(cSapModel model) { int num = 0; @@ -489,8 +573,12 @@ public static List GetAllPropLineSpringNames(cSapModel model) model.PropLineSpring.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllPropPointSpringNames(cSapModel model) { int num = 0; @@ -500,8 +588,12 @@ public static List GetAllPropPointSpringNames(cSapModel model) model.PropPointSpring.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllSpandrelLabelNames(cSapModel model) { int num = 0; @@ -512,8 +604,12 @@ public static List GetAllSpandrelLabelNames(cSapModel model) model.SpandrelLabel.GetNameList(ref num, ref names, ref isMultiStory); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllTowerNames(cSapModel model) { int num = 0; @@ -523,8 +619,12 @@ public static List GetAllTowerNames(cSapModel model) model.Tower.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllPropTendonNames(cSapModel model) { int num = 0; @@ -534,8 +634,12 @@ public static List GetAllPropTendonNames(cSapModel model) model.PropTendon.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllPropLinkNames(cSapModel model) { int num = 0; @@ -545,7 +649,10 @@ public static List GetAllPropLinkNames(cSapModel model) model.PropLink.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } #endregion @@ -620,6 +727,7 @@ public enum CSIAPIUsableTypes Tendon, LoadPattern, Model, + //Diaphragm, BeamLoading, ColumnLoading, @@ -630,7 +738,6 @@ public enum CSIAPIUsableTypes WallLoading, NodeLoading, - //ColumnResults, //BeamResults, //BraceResults, @@ -649,5 +756,4 @@ public enum CSIViewSelectableTypes Area = 4 } } - -} \ No newline at end of file +} diff --git a/ConnectorCSI/ConnectorCSIShared/cPlugin.cs b/ConnectorCSI/ConnectorCSIShared/cPlugin.cs index 0f9c021889..2ecba071b3 100644 --- a/ConnectorCSI/ConnectorCSIShared/cPlugin.cs +++ b/ConnectorCSI/ConnectorCSIShared/cPlugin.cs @@ -30,13 +30,14 @@ public class cPlugin public static ConnectorBindingsCSI Bindings { get; set; } - public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() - .UsePlatformDetect() - .With(new SkiaOptions { MaxGpuResourceSizeBytes = 8096000 }) - .With(new Win32PlatformOptions { AllowEglInitialization = true, EnableMultitouch = false }) - .LogToTrace() - .UseReactiveUI(); - + public static AppBuilder BuildAvaloniaApp() => + AppBuilder + .Configure() + .UsePlatformDetect() + .With(new SkiaOptions { MaxGpuResourceSizeBytes = 8096000 }) + .With(new Win32PlatformOptions { AllowEglInitialization = true, EnableMultitouch = false }) + .LogToTrace() + .UseReactiveUI(); public static void CreateOrFocusSpeckle() { @@ -125,6 +126,4 @@ public void Main(ref cSapModel SapModel, ref cPluginCallback ISapPlugin) return; } } - - } diff --git a/ConnectorCSI/DriverCSharp/PluginCallback.cs b/ConnectorCSI/DriverCSharp/PluginCallback.cs index 69f9ea23b4..671df0a684 100644 --- a/ConnectorCSI/DriverCSharp/PluginCallback.cs +++ b/ConnectorCSI/DriverCSharp/PluginCallback.cs @@ -9,18 +9,12 @@ class PluginCallback : cPluginCallback public int ErrorFlag { - get - { - return m_ErrorFlag; - } + get { return m_ErrorFlag; } } public bool Finished { - get - { - return m_IsFinished; - } + get { return m_IsFinished; } } public void Finish(int iVal) diff --git a/ConnectorCSI/DriverCSharp/Program.cs b/ConnectorCSI/DriverCSharp/Program.cs index ac9144b5c2..2ddae118e7 100644 --- a/ConnectorCSI/DriverCSharp/Program.cs +++ b/ConnectorCSI/DriverCSharp/Program.cs @@ -41,7 +41,7 @@ static int Main(string[] args) return ret; } - // attach to a running program instance + // attach to a running program instance try { // get the active SapObject @@ -72,20 +72,16 @@ static int Main(string[] args) progID = ProgID_SAP2000; mySapObject = myHelper.GetObject(progID); } - catch (Exception ex) - { - } + catch (Exception ex) { } if (mySapObject == null) { try - { + { progID = ProgID_ETABS; mySapObject = myHelper.GetObject(progID); } - catch (Exception ex) - { - } + catch (Exception ex) { } } if (mySapObject == null) { @@ -94,9 +90,7 @@ static int Main(string[] args) progID = ProgID_CSiBridge; mySapObject = myHelper.GetObject(progID); } - catch (Exception ex) - { - } + catch (Exception ex) { } } } } @@ -119,8 +113,10 @@ static int Main(string[] args) // DO NOT return from SpeckleConnectorETABS.cPlugin.Main() until all work is done. p.Main(ref mySapModel, ref cb); - if(cb.Finished == true) - { Environment.Exit(0); } + if (cb.Finished == true) + { + Environment.Exit(0); + } return cb.ErrorFlag; } diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSIUtils.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSIUtils.cs index 8c371b5178..428515a85e 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSIUtils.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSIUtils.cs @@ -19,9 +19,10 @@ public partial class ConverterCSI readonly string Send2DResults = "send2DResults"; private string _modelUnits; + public string ModelUnits() { - if (_modelUnits != null) + if (_modelUnits != null) return _modelUnits; var units = Model.GetPresentUnits(); @@ -33,11 +34,13 @@ public string ModelUnits() } return null; } + public double ScaleToNative(double value, string units) { var f = Speckle.Core.Kits.Units.GetConversionFactor(units, ModelUnits()); return value * f; } + public static List GetAllFrameNames(cSapModel model) { int num = 0; @@ -47,7 +50,10 @@ public static List GetAllFrameNames(cSapModel model) model.FrameObj.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } public static List GetColumnNames(cSapModel model) @@ -115,6 +121,7 @@ public static List GetBraceNames(cSapModel model) return braceNames; } + public static List GetAllAreaNames(cSapModel model) { int num = 0; @@ -124,8 +131,12 @@ public static List GetAllAreaNames(cSapModel model) model.AreaObj.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } + catch + { + return null; + } } + public static List GetAllWallNames(cSapModel model) { var WallNames = GetAllAreaNames(model); @@ -147,6 +158,7 @@ public static List GetAllWallNames(cSapModel model) return WallName; } + public static List GetAllFloorNames(cSapModel model) { var FloorNames = GetAllAreaNames(model); @@ -235,12 +247,14 @@ public string GetOriginalApplicationId(string csiAppId) if (string.IsNullOrEmpty(csiAppId)) return csiAppId; - var originalAppId = PreviousContextObjects.Where(o => o.CreatedIds.Contains(csiAppId)).FirstOrDefault()?.applicationId; + var originalAppId = PreviousContextObjects + .Where(o => o.CreatedIds.Contains(csiAppId)) + .FirstOrDefault() + ?.applicationId; return originalAppId ?? csiAppId; } - public ShellType ConvertShellType(eShellType eShellType) { ShellType shellType = new ShellType(); @@ -262,8 +276,6 @@ public ShellType ConvertShellType(eShellType eShellType) default: shellType = ShellType.Null; break; - - } return shellType; @@ -278,7 +290,7 @@ public bool[] RestraintToNative(Restraint restraint) int i = 0; foreach (char c in code) { - restraints[i] = c.Equals('F') ? true : false; // other assume default of released + restraints[i] = c.Equals('F') ? true : false; // other assume default of released i++; } @@ -304,13 +316,15 @@ public Restraint RestraintToSpeckle(bool[] releases) { for (int i = 0; i < releases.Length; i++) { - if (releases[i]) code[i] = "F"; + if (releases[i]) + code[i] = "F"; } } var restraint = new Restraint(string.Join("", code)); return restraint; } + public static List GetAllPointNames(cSapModel model) { int num = 0; @@ -320,8 +334,10 @@ public static List GetAllPointNames(cSapModel model) model.PointObj.GetNameList(ref num, ref names); return names.ToList(); } - catch { return null; } - + catch + { + return null; + } } public enum CSIConverterSupported @@ -351,6 +367,7 @@ public enum CSIAPIUsableTypes Spandrel, Pier, Grids, + //Diaphragm, BeamLoading, ColumnLoading, @@ -360,6 +377,7 @@ public enum CSIAPIUsableTypes AreaLoading, WallLoading, NodeLoading, + //ColumnResults, //BeamResults, //BraceResults, diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Extensions/PolycurveExtensions.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Extensions/PolycurveExtensions.cs index 186265054b..bfc72e9cbd 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Extensions/PolycurveExtensions.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Extensions/PolycurveExtensions.cs @@ -13,7 +13,8 @@ public static IEnumerable ToPoints(this Polycurve polycurve) { foreach (var point in seg.ToPoints()) { - if (Math.Abs(point.x - prevPoint.x) < .01 + if ( + Math.Abs(point.x - prevPoint.x) < .01 && Math.Abs(point.y - prevPoint.y) < .01 && Math.Abs(point.z - prevPoint.z) < .01 ) diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModel.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModel.cs index 9efae38e6c..d6f9516da7 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModel.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModel.cs @@ -22,9 +22,9 @@ public partial class ConverterCSI { public object ModelToNative(Model model, ref ApplicationObject appObj) { - return null; } + Base ModelElementsCountToSpeckle() { var ElementsCount = new Base(); @@ -33,6 +33,7 @@ Base ModelElementsCountToSpeckle() ElementsCount.applicationId = count.ToString(); return ElementsCount; } + public Model ModelToSpeckle() { var model = new Model(); @@ -47,7 +48,7 @@ public Model ModelToSpeckle() string[] properties1D = { }; //var stories = StoriesToSpeckle(); - ////Should stories belong here ? not sure + ////Should stories belong here ? not sure //model.elements.Add(stories); @@ -129,7 +130,6 @@ public Model ModelToSpeckle() } } - string[] materials = { }; Model.PropMaterial.GetNameList(ref number, ref materials); foreach (string material in materials) @@ -138,11 +138,7 @@ public Model ModelToSpeckle() model.materials.Add(speckleMaterial); } - - - - return model; } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelInfo.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelInfo.cs index 8799bf3b23..7a94c83b4a 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelInfo.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelInfo.cs @@ -15,22 +15,28 @@ public void ModelInfoToNative(ModelInfo modelInfo) Model.SetProjectInfo("Model Description", modelInfo.description); Model.SetProjectInfo("Project Number", modelInfo.projectNumber); Model.SetProjectInfo("Project Name", modelInfo.projectName); - if (modelInfo.settings != null) { modelSettingsToNative(modelInfo.settings); } + if (modelInfo.settings != null) + { + modelSettingsToNative(modelInfo.settings); + } return; - } + public ModelInfo ModelInfoToSpeckle() { var modelInfo = new ModelInfo(); modelInfo.name = Model.GetModelFilename(false); - string programName, programVersion, programLevel; + string programName, + programVersion, + programLevel; programVersion = programName = programLevel = null; Model.GetProgramInfo(ref programName, ref programVersion, ref programLevel); modelInfo.application = programName; modelInfo.settings = modelSettingsToSpeckle(); int numberItems = 0; - string[] items, data; + string[] items, + data; items = data = null; Model.GetProjectInfo(ref numberItems, ref items, ref data); if (numberItems != 0) @@ -57,7 +63,6 @@ public ModelInfo ModelInfoToSpeckle() } } return modelInfo; - } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelSettings.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelSettings.cs index 728512a084..77295af625 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelSettings.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelSettings.cs @@ -11,8 +11,12 @@ public void modelSettingsToNative(ModelSettings modelSettings) { Model.DesignConcrete.SetCode(modelSettings.concreteCode); Model.DesignSteel.SetCode(modelSettings.steelCode); - if (modelSettings.modelUnits != null) { UnitsToNative(modelSettings.modelUnits); } + if (modelSettings.modelUnits != null) + { + UnitsToNative(modelSettings.modelUnits); + } } + public ModelSettings modelSettingsToSpeckle() { var speckleModelSettings = new ModelSettings(); @@ -25,6 +29,5 @@ public ModelSettings modelSettingsToSpeckle() speckleModelSettings.steelCode = steelCode; return speckleModelSettings; } - } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelUnits.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelUnits.cs index 5a59006e47..1a08ce6a05 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelUnits.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Analysis/ConvertModelUnits.cs @@ -71,6 +71,7 @@ public void UnitsToNative(ModelUnits units) Model.SetPresentUnits_2(force, length, temp); return; } + public ModelUnits UnitsToSpeckle() { var modelUnits = new ModelUnits(); @@ -89,4 +90,4 @@ public ModelUnits UnitsToSpeckle() return modelUnits; } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertArea.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertArea.cs index 445f73fc42..33b551a96c 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertArea.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertArea.cs @@ -27,6 +27,7 @@ public object updateExistingArea(Element2D area) } return area.name; } + public void UpdateArea(Element2D area, string name, ref ApplicationObject appObj) { var points = new string[0]; @@ -46,7 +47,7 @@ public void UpdateArea(Element2D area, string name, ref ApplicationObject appObj pointsUpdated.Add(pointName); continue; } - + pointsUpdated.Add(UpdatePoint(points[i], area.topology[i])); if (!connectivityChanged && pointsUpdated[i] != points[i]) connectivityChanged = true; @@ -66,7 +67,14 @@ public void UpdateArea(Element2D area, string name, ref ApplicationObject appObj string[] fieldsKeysIncluded = null; string[] tableData = null; string floorTableKey = "Floor Object Connectivity"; - Model.DatabaseTables.GetTableForEditingArray(floorTableKey, "ThisParamIsNotActiveYet", ref tableVersion, ref fieldsKeysIncluded, ref numberRecords, ref tableData); + Model.DatabaseTables.GetTableForEditingArray( + floorTableKey, + "ThisParamIsNotActiveYet", + ref tableVersion, + ref fieldsKeysIncluded, + ref numberRecords, + ref tableData + ); // if the floor object now has more points than it previously had // and it has more points that any other floor object, then updating would involve adding a new column to this array @@ -104,12 +112,25 @@ public void UpdateArea(Element2D area, string name, ref ApplicationObject appObj if (ProgramVersion.CompareTo("20.0.0") < 0 && fieldsKeysIncluded[0] == "UniqueName") fieldsKeysIncluded[0] = "Unique Name"; - Model.DatabaseTables.SetTableForEditingArray(floorTableKey, ref tableVersion, ref fieldsKeysIncluded, numberRecords, ref tableData); + Model.DatabaseTables.SetTableForEditingArray( + floorTableKey, + ref tableVersion, + ref fieldsKeysIncluded, + numberRecords, + ref tableData + ); int numFatalErrors = 0; int numWarnMsgs = 0; int numInfoMsgs = 0; - success = Model.DatabaseTables.ApplyEditedTables(true, ref numFatalErrors, ref numErrorMsgs, ref numWarnMsgs, ref numInfoMsgs, ref importLog); + success = Model.DatabaseTables.ApplyEditedTables( + true, + ref numFatalErrors, + ref numErrorMsgs, + ref numWarnMsgs, + ref numInfoMsgs, + ref importLog + ); if (success == 0) { @@ -133,13 +154,27 @@ public void UpdateArea(Element2D area, string name, ref ApplicationObject appObj { string guid = null; Model.AreaObj.GetGUID(name, ref guid); - appObj.Update(status: ApplicationObject.State.Updated, createdId: guid, convertedItem: $"Area{delimiter}{name}"); + appObj.Update( + status: ApplicationObject.State.Updated, + createdId: guid, + convertedItem: $"Area{delimiter}{name}" + ); if (numErrorMsgs != 0) - appObj.Update(log: new List() { $"Area may not have updated successfully. Number of error messages for operation is {numErrorMsgs}", importLog }); + appObj.Update( + log: new List() + { + $"Area may not have updated successfully. Number of error messages for operation is {numErrorMsgs}", + importLog + } + ); } else - appObj.Update(status: ApplicationObject.State.Failed, log: new List() { "Failed to apply edited database tables", importLog }); + appObj.Update( + status: ApplicationObject.State.Failed, + log: new List() { "Failed to apply edited database tables", importLog } + ); } + public void AreaToNative(Element2D area, ref ApplicationObject appObj) { if (ElementExistsWithApplicationId(area.applicationId, out string areaName)) @@ -150,14 +185,19 @@ public void AreaToNative(Element2D area, ref ApplicationObject appObj) if (GetAllAreaNames(Model).Contains(area.name)) { - appObj.Update(status: ApplicationObject.State.Failed, logItem: $"There is already a frame object named {area.name} in the model"); + appObj.Update( + status: ApplicationObject.State.Failed, + logItem: $"There is already a frame object named {area.name} in the model" + ); return; } var propName = CreateOrGetProp(area.property, out bool isExactMatch); if (!isExactMatch) { - appObj.Update(logItem: $"Area section for object could not be created and was replaced with section named \"{propName}\""); + appObj.Update( + logItem: $"Area section for object could not be created and was replaced with section named \"{propName}\"" + ); } var name = CreateAreaFromPoints(area.topology.Select(t => t.basePoint), propName, out var success); @@ -191,7 +231,11 @@ public void AreaToNative(Element2D area, ref ApplicationObject appObj) Model.AreaObj.GetGUID(name, ref guid); if (success == 0) - appObj.Update(status: ApplicationObject.State.Created, createdId: guid, convertedItem: $"Area{delimiter}{name}"); + appObj.Update( + status: ApplicationObject.State.Created, + createdId: guid, + convertedItem: $"Area{delimiter}{name}" + ); else appObj.Update(status: ApplicationObject.State.Failed); } @@ -212,14 +256,15 @@ private string CreateAreaFromPoints(IEnumerable points, string propName, numPoints++; } - if (Math.Abs(X.Last() - X.First()) < .01 + if ( + Math.Abs(X.Last() - X.First()) < .01 && Math.Abs(Y.Last() - Y.First()) < .01 && Math.Abs(Z.Last() - Z.First()) < .01 ) { - X.RemoveAt(X.Count- 1); - Y.RemoveAt(Y.Count- 1); - Z.RemoveAt(Z.Count- 1); + X.RemoveAt(X.Count - 1); + Y.RemoveAt(Y.Count - 1); + Z.RemoveAt(Z.Count - 1); numPoints--; } var x = X.ToArray(); @@ -287,14 +332,18 @@ public void SetAreaProperties(string name, Element2D area) Model.AreaObj.SetLocalAxes(csiArea.name, csiArea.orientationAngle); Model.AreaObj.SetPier(csiArea.name, csiArea.PierAssignment); Model.AreaObj.SetSpandrel(csiArea.name, csiArea.SpandrelAssignment); - if (csiArea.CSIAreaSpring != null) { Model.AreaObj.SetSpringAssignment(csiArea.name, csiArea.CSIAreaSpring.name); } + if (csiArea.CSIAreaSpring != null) + { + Model.AreaObj.SetSpringAssignment(csiArea.name, csiArea.CSIAreaSpring.name); + } - if (csiArea.DiaphragmAssignment != null) - { - Model.AreaObj.SetDiaphragm(csiArea.name, csiArea.DiaphragmAssignment); + if (csiArea.DiaphragmAssignment != null) + { + Model.AreaObj.SetDiaphragm(csiArea.name, csiArea.DiaphragmAssignment); } } } + public Element2D AreaToSpeckle(string name) { string units = ModelUnits(); @@ -325,7 +374,6 @@ public Element2D AreaToSpeckle(string name) speckleStructArea.property = Property2DToSpeckle(name, propName); } - List coordinates = new List { }; foreach (Node node in nodes) { @@ -346,7 +394,10 @@ public Element2D AreaToSpeckle(string name) var faces = polygonMesher.Faces(); var vertices = polygonMesher.Coordinates; //speckleStructArea.displayMesh = new Geometry.Mesh(vertices, faces.ToArray(), null, null, ModelUnits(), null); - speckleStructArea.displayValue = new List { new Geometry.Mesh(vertices.ToList(), faces, units: ModelUnits()) }; + speckleStructArea.displayValue = new List + { + new Geometry.Mesh(vertices.ToList(), faces, units: ModelUnits()) + }; } //Model.AreaObj.GetModifiers(area, ref value); @@ -360,7 +411,10 @@ public Element2D AreaToSpeckle(string name) string springArea = null; Model.AreaObj.GetSpringAssignment(name, ref springArea); - if (springArea != null) { speckleStructArea.CSIAreaSpring = AreaSpringToSpeckle(springArea); } + if (springArea != null) + { + speckleStructArea.CSIAreaSpring = AreaSpringToSpeckle(springArea); + } string pierAssignment = null; Model.AreaObj.GetPier(name, ref pierAssignment); @@ -398,6 +452,5 @@ public Element2D AreaToSpeckle(string name) return speckleStructArea; } - } } diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertBraces.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertBraces.cs index 80fa18579e..297a20ad9a 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertBraces.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertBraces.cs @@ -14,4 +14,4 @@ public Element1D BraceToSpeckle(string name) return FrameToSpeckle(name); } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertBuiltElement.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertBuiltElement.cs index 85751f3ea4..83935702ef 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertBuiltElement.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertBuiltElement.cs @@ -14,7 +14,10 @@ public void CurveBasedElementToNative(Base @base, ICurve curve, ref ApplicationO { if (!(curve is Line baseLine)) { - appObj.Update(status: ApplicationObject.State.Failed, logItem: "Only line based frames are currently supported"); + appObj.Update( + status: ApplicationObject.State.Failed, + logItem: "Only line based frames are currently supported" + ); return; } diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertColumn.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertColumn.cs index f658b4901c..0207249692 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertColumn.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertColumn.cs @@ -14,4 +14,4 @@ public Element1D ColumnToSpeckle(string name) return FrameToSpeckle(name); } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertFloor.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertFloor.cs index d857ea3d7b..a81e23aef4 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertFloor.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertFloor.cs @@ -16,4 +16,4 @@ public Element2D FloorToSpeckle(string name) return AreaToSpeckle(name); } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertFrame.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertFrame.cs index 611b1d0d54..99f9e4e2d7 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertFrame.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertFrame.cs @@ -19,7 +19,10 @@ public void UpdateFrame(Element1D element1D, string name, ref ApplicationObject if (end1node == null || end2node == null) { - appObj.Update(status: ApplicationObject.State.Failed, logItem: $"Frame {element1D.name} does not have valid endpoints"); + appObj.Update( + status: ApplicationObject.State.Failed, + logItem: $"Frame {element1D.name} does not have valid endpoints" + ); return; } @@ -61,7 +64,11 @@ public void UpdateFrameLocation(string name, Point p1, Point p2, ApplicationObje { string guid = null; Model.FrameObj.GetGUID(name, ref guid); - appObj.Update(status: ApplicationObject.State.Updated, createdId: guid, convertedItem: $"Frame{delimiter}{name}"); + appObj.Update( + status: ApplicationObject.State.Updated, + createdId: guid, + convertedItem: $"Frame{delimiter}{name}" + ); } else appObj.Update(status: ApplicationObject.State.Failed, logItem: "Failed to change frame connectivity"); @@ -107,7 +114,15 @@ public void FrameToNative(Element1D element1D, ref ApplicationObject appObj) SetFrameElementProperties(element1D, newFrame); } - public int CreateFrame(Point p0, Point p1, out string newFrame, out string guid, ref ApplicationObject appObj, string type = "Default", string nameOverride = null) + public int CreateFrame( + Point p0, + Point p1, + out string newFrame, + out string guid, + ref ApplicationObject appObj, + string type = "Default", + string nameOverride = null + ) { newFrame = string.Empty; guid = string.Empty; @@ -132,7 +147,11 @@ public int CreateFrame(Point p0, Point p1, out string newFrame, out string guid, } if (success == 0) - appObj.Update(status: ApplicationObject.State.Created, createdId: guid, convertedItem: $"Frame{delimiter}{newFrame}"); + appObj.Update( + status: ApplicationObject.State.Created, + createdId: guid, + convertedItem: $"Frame{delimiter}{newFrame}" + ); else appObj.Update(status: ApplicationObject.State.Failed); @@ -146,7 +165,8 @@ public CSIElement1D FrameToSpeckle(string name) var speckleStructFrame = new CSIElement1D(); speckleStructFrame.name = name; - string pointI, pointJ; + string pointI, + pointJ; pointI = pointJ = null; _ = Model.FrameObj.GetPoints(name, ref pointI, ref pointJ); var pointINode = PointToSpeckle(pointI); @@ -168,36 +188,38 @@ public CSIElement1D FrameToSpeckle(string name) switch (frameDesignOrientation) { case eFrameDesignOrientation.Column: - { - speckleStructFrame.type = ElementType1D.Column; - break; - } + { + speckleStructFrame.type = ElementType1D.Column; + break; + } case eFrameDesignOrientation.Beam: - { - speckleStructFrame.type = ElementType1D.Beam; - break; - } + { + speckleStructFrame.type = ElementType1D.Beam; + break; + } case eFrameDesignOrientation.Brace: - { - speckleStructFrame.type = ElementType1D.Brace; - break; - } + { + speckleStructFrame.type = ElementType1D.Brace; + break; + } case eFrameDesignOrientation.Null: - { - //speckleStructFrame.memberType = MemberType.Generic1D; - speckleStructFrame.type = ElementType1D.Null; - break; - } + { + //speckleStructFrame.memberType = MemberType.Generic1D; + speckleStructFrame.type = ElementType1D.Null; + break; + } case eFrameDesignOrientation.Other: - { - speckleStructFrame.type = ElementType1D.Other; - break; - } + { + speckleStructFrame.type = ElementType1D.Other; + break; + } } - bool[] iRelease, jRelease; + bool[] iRelease, + jRelease; iRelease = jRelease = null; - double[] startV, endV; + double[] startV, + endV; startV = endV = null; Model.FrameObj.GetReleases(name, ref iRelease, ref jRelease, ref startV, ref endV); @@ -206,14 +228,13 @@ public CSIElement1D FrameToSpeckle(string name) SpeckleModel.restraints.Add(speckleStructFrame.end1Releases); SpeckleModel.restraints.Add(speckleStructFrame.end2Releases); - double localAxis = 0; bool advanced = false; Model.FrameObj.GetLocalAxes(name, ref localAxis, ref advanced); speckleStructFrame.orientationAngle = localAxis; - - string property, SAuto; + string property, + SAuto; property = SAuto = null; Model.FrameObj.GetSection(name, ref property, ref SAuto); speckleStructFrame.property = Property1DToSpeckle(property); @@ -281,7 +302,10 @@ public CSIElement1D FrameToSpeckle(string name) } double[] modifiers = new double[] { }; int s = Model.FrameObj.GetModifiers(name, ref modifiers); - if (s == 0) { speckleStructFrame.Modifiers = modifiers; } + if (s == 0) + { + speckleStructFrame.Modifiers = modifiers; + } var GUID = ""; Model.FrameObj.GetGUID(name, ref GUID); @@ -293,7 +317,6 @@ public CSIElement1D FrameToSpeckle(string name) SpeckleModel.elements.Add(speckleStructFrame); } - return speckleStructFrame; } @@ -301,7 +324,8 @@ public void SetFrameElementProperties(Element1D element1D, string newFrame) { bool[] end1Release = null; bool[] end2Release = null; - double[] startV, endV; + double[] startV, + endV; startV = null; endV = null; if (element1D.end1Releases != null && element1D.end2Releases != null) @@ -327,11 +351,19 @@ public void SetFrameElementProperties(Element1D element1D, string newFrame) Model.FrameObj.SetReleases(newFrame, ref end1Release, ref end2Release, ref startV, ref endV); if (element1D is CSIElement1D) { - var CSIelement1D = (CSIElement1D)element1D; - if (CSIelement1D.SpandrelAssignment != null) { Model.FrameObj.SetSpandrel(CSIelement1D.name, CSIelement1D.SpandrelAssignment); } - if (CSIelement1D.PierAssignment != null) { Model.FrameObj.SetPier(CSIelement1D.name, CSIelement1D.PierAssignment); } - if (CSIelement1D.CSILinearSpring != null) { Model.FrameObj.SetSpringAssignment(CSIelement1D.name, CSIelement1D.CSILinearSpring.name); } + if (CSIelement1D.SpandrelAssignment != null) + { + Model.FrameObj.SetSpandrel(CSIelement1D.name, CSIelement1D.SpandrelAssignment); + } + if (CSIelement1D.PierAssignment != null) + { + Model.FrameObj.SetPier(CSIelement1D.name, CSIelement1D.PierAssignment); + } + if (CSIelement1D.CSILinearSpring != null) + { + Model.FrameObj.SetSpringAssignment(CSIelement1D.name, CSIelement1D.CSILinearSpring.name); + } if (CSIelement1D.Modifiers != null) { var modifiers = CSIelement1D.Modifiers; diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertGridLines.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertGridLines.cs index b4507255ee..d1d022975f 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertGridLines.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertGridLines.cs @@ -18,6 +18,7 @@ public void gridLinesToNative(CSIGridLines gridlines) { throw new NotSupportedException(); } + public CSIGridLines gridLinesToSpeckle(string name) { double Xo = 0; @@ -35,7 +36,23 @@ public CSIGridLines gridLinesToSpeckle(string name) string[] BubbleLocX = null; string[] BubbleLocY = null; - Model.GridSys.GetGridSys_2(name, ref Xo, ref Yo, ref RZ, ref GridSysType, ref NumXLines, ref NumYLines, ref GridLineIDX, ref GridLineIDY, ref OrdinateX, ref OrdinateY, ref VisibleX, ref VisibleY, ref BubbleLocX, ref BubbleLocY); + Model.GridSys.GetGridSys_2( + name, + ref Xo, + ref Yo, + ref RZ, + ref GridSysType, + ref NumXLines, + ref NumYLines, + ref GridLineIDX, + ref GridLineIDY, + ref OrdinateX, + ref OrdinateY, + ref VisibleX, + ref VisibleY, + ref BubbleLocX, + ref BubbleLocY + ); var gridlines = new List { }; CSIGridLines speckleGridLines = new CSIGridLines(); @@ -65,9 +82,8 @@ public CSIGridLines gridLinesToSpeckle(string name) speckleGridLines.Rz = RZ; } - SpeckleModel.elements.Add(speckleGridLines); return speckleGridLines; } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertLine.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertLine.cs index 80565a0a2b..1d0a622709 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertLine.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertLine.cs @@ -12,7 +12,6 @@ public partial class ConverterCSI { public void LineToNative(Line line, ref ApplicationObject appObj) { - string newFrame = ""; Point end1node = line.start; Point end2node = line.end; @@ -31,6 +30,5 @@ ref newFrame else appObj.Update(status: ApplicationObject.State.Failed); } - } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertLinks.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertLinks.cs index 014b042aa4..c4c887f642 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertLinks.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertLinks.cs @@ -15,7 +15,6 @@ public partial class ConverterCSI { public void LinkToNative(CSIElement1D link, ref ApplicationObject appObj) { - PointToNative((CSINode)link.end1Node, ref appObj); PointToNative((CSINode)link.end2Node, ref appObj); string linkName = null; @@ -24,7 +23,12 @@ public void LinkToNative(CSIElement1D link, ref ApplicationObject appObj) Model.PropLink.GetNameList(ref numberProps, ref listProp); if (listProp.Contains(link.property.name)) { - var success = Model.LinkObj.AddByPoint(link.end1Node.name, link.end2Node.name, ref linkName, PropName: link.property.name); + var success = Model.LinkObj.AddByPoint( + link.end1Node.name, + link.end2Node.name, + ref linkName, + PropName: link.property.name + ); if (success == 0) appObj.Update(status: ApplicationObject.State.Created, createdId: linkName); else @@ -45,7 +49,8 @@ public CSIElement1D LinkToSpeckle(string name) speckleStructLink.type = ElementType1D.Link; speckleStructLink.name = name; - string pointI, pointJ; + string pointI, + pointJ; pointI = pointJ = null; _ = Model.LinkObj.GetPoints(name, ref pointI, ref pointJ); var pointINode = PointToSpeckle(pointI); @@ -83,8 +88,7 @@ public CSIElement1D LinkToSpeckle(string name) SpeckleModel.elements.Add(speckleStructLink); } - return speckleStructLink; } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertPier.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertPier.cs index 0e6f7c3096..d02b42a4f9 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertPier.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertPier.cs @@ -18,6 +18,7 @@ public void PierToNative(CSIPier CSIPier) { Model.PierLabel.SetPier(CSIPier.name); } + public CSIPier PierToSpeckle(string name) { int numberStories = 0; @@ -37,7 +38,7 @@ public CSIPier PierToSpeckle(string name) double[] centerofGravityTopY = null; double[] centerofGravityTopZ = null; - // **** ISSUE WITH THIS METHOD HANGING IF PIER LABEL NOT ASSIGNED IN MODEL **** // + // **** ISSUE WITH THIS METHOD HANGING IF PIER LABEL NOT ASSIGNED IN MODEL **** // //var s = Model.PierLabel.GetSectionProperties(name, ref numberStories, ref storyName, ref axisAngle, ref numAreaObjs, ref numLineObjs, ref widthBot, ref thicknessBot, ref widthTop, ref thicknessTop, ref matProp //, ref centerofGravityBotX, ref centerofGravityBotY, ref centerofGravityBotZ, ref centerofGravityTopX, ref centerofGravityTopY, ref centerofGravityTopZ); @@ -48,4 +49,4 @@ public CSIPier PierToSpeckle(string name) return speckleCSIPier; } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertPoint.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertPoint.cs index b750f57789..8dc2258ce1 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertPoint.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertPoint.cs @@ -31,7 +31,7 @@ public void UpdatePointProperties(Node speckleStructNode, ref string name) { if (speckleStructNode == null) return; - + if (speckleStructNode.restraint != null) { var restraint = RestraintToNative(speckleStructNode.restraint); @@ -47,7 +47,7 @@ public void UpdatePointProperties(Node speckleStructNode, ref string name) if (!(speckleStructNode is CSINode csiNode)) return; - if (csiNode.CSISpringProperty != null) + if (csiNode.CSISpringProperty != null) Model.PointObj.SetSpringAssignment(csiNode.name, csiNode.CSISpringProperty.name); if (csiNode.DiaphragmAssignment != null) @@ -55,22 +55,38 @@ public void UpdatePointProperties(Node speckleStructNode, ref string name) switch (csiNode.DiaphragmOption) { case DiaphragmOption.Disconnect: - Model.PointObj.SetDiaphragm(csiNode.name, eDiaphragmOption.Disconnect, DiaphragmName: csiNode.DiaphragmAssignment); + Model.PointObj.SetDiaphragm( + csiNode.name, + eDiaphragmOption.Disconnect, + DiaphragmName: csiNode.DiaphragmAssignment + ); break; case DiaphragmOption.DefinedDiaphragm: - Model.PointObj.SetDiaphragm(csiNode.name, eDiaphragmOption.DefinedDiaphragm, DiaphragmName: csiNode.DiaphragmAssignment); + Model.PointObj.SetDiaphragm( + csiNode.name, + eDiaphragmOption.DefinedDiaphragm, + DiaphragmName: csiNode.DiaphragmAssignment + ); break; case DiaphragmOption.FromShellObject: - Model.PointObj.SetDiaphragm(csiNode.name, eDiaphragmOption.FromShellObject, DiaphragmName: csiNode.DiaphragmAssignment); + Model.PointObj.SetDiaphragm( + csiNode.name, + eDiaphragmOption.FromShellObject, + DiaphragmName: csiNode.DiaphragmAssignment + ); break; } } } + public void PointToNative(Node speckleStructNode, ref ApplicationObject appObj) { if (GetAllPointNames(Model).Contains(speckleStructNode.name)) { - appObj.Update(status: ApplicationObject.State.Skipped, logItem: $"node with name {speckleStructNode.name} already exists"); + appObj.Update( + status: ApplicationObject.State.Skipped, + logItem: $"node with name {speckleStructNode.name} already exists" + ); return; } var point = speckleStructNode.basePoint; @@ -79,7 +95,7 @@ public void PointToNative(Node speckleStructNode, ref ApplicationObject appObj) appObj.Update(status: ApplicationObject.State.Skipped, logItem: $"Node does not have a valid location"); return; } - + var success = CreatePoint(point, out string name); UpdatePointProperties(speckleStructNode, ref name); @@ -88,21 +104,25 @@ public void PointToNative(Node speckleStructNode, ref ApplicationObject appObj) else appObj.Update(status: ApplicationObject.State.Failed); } + public int CreatePoint(Point point, out string name) { name = null; var success = Model.PointObj.AddCartesian( - ScaleToNative(point.x, point.units), - ScaleToNative(point.y, point.units), - ScaleToNative(point.z, point.units), - ref name + ScaleToNative(point.x, point.units), + ScaleToNative(point.y, point.units), + ScaleToNative(point.z, point.units), + ref name ); return success; } + public CSINode PointToSpeckle(string name) { var speckleStructNode = new CSINode(); - double x, y, z; + double x, + y, + z; x = y = z = 0; int v = Model.PointObj.GetCoordCartesian(name, ref x, ref y, ref z); speckleStructNode.basePoint = new Point(); @@ -122,7 +142,10 @@ public CSINode PointToSpeckle(string name) string SpringProp = null; Model.PointObj.GetSpringAssignment(name, ref SpringProp); - if (SpringProp != null) { speckleStructNode.CSISpringProperty = SpringPropertyToSpeckle(SpringProp); } + if (SpringProp != null) + { + speckleStructNode.CSISpringProperty = SpringPropertyToSpeckle(SpringProp); + } string diaphragmAssignment = null; eDiaphragmOption eDiaphragmOption = eDiaphragmOption.Disconnect; @@ -157,6 +180,5 @@ public CSINode PointToSpeckle(string name) return speckleStructNode; } - } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertSpandrel.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertSpandrel.cs index 6e1ca4e617..7a3bb18e64 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertSpandrel.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertSpandrel.cs @@ -18,6 +18,7 @@ public void SpandrelToNative(CSISpandrel spandrel) { Model.SpandrelLabel.SetSpandrel(spandrel.name, spandrel.multistory); } + public CSISpandrel SpandrelToSpeckle(string name) { int numberStories = 0; @@ -37,15 +38,50 @@ public CSISpandrel SpandrelToSpeckle(string name) double[] centerofGravityRightY = null; double[] centerofGravityRightZ = null; - Model.SpandrelLabel.GetSectionProperties(name, ref numberStories, ref storyName, ref numAreaObjs, ref numLineObjs, ref length, ref depthLeft, - ref thickLeft, ref depthRight, ref thickRight, ref matProp, ref centerofGravityLeftX, ref centerofGravityLeftY, ref centerofGravityLeftZ, ref centerofGravityRightX, ref centerofGravityRightY, ref centerofGravityRightZ); + Model.SpandrelLabel.GetSectionProperties( + name, + ref numberStories, + ref storyName, + ref numAreaObjs, + ref numLineObjs, + ref length, + ref depthLeft, + ref thickLeft, + ref depthRight, + ref thickRight, + ref matProp, + ref centerofGravityLeftX, + ref centerofGravityLeftY, + ref centerofGravityLeftZ, + ref centerofGravityRightX, + ref centerofGravityRightY, + ref centerofGravityRightZ + ); bool multistory = false; Model.SpandrelLabel.GetSpandrel(name, ref multistory); - - var speckleCSISpandrel = new CSISpandrel(name, multistory, numberStories, storyName, numAreaObjs, numLineObjs, length, depthLeft, thickLeft, depthRight, thickRight, matProp, centerofGravityLeftX, centerofGravityLeftY, centerofGravityLeftZ, centerofGravityRightX, centerofGravityRightY, centerofGravityRightZ); + var speckleCSISpandrel = new CSISpandrel( + name, + multistory, + numberStories, + storyName, + numAreaObjs, + numLineObjs, + length, + depthLeft, + thickLeft, + depthRight, + thickRight, + matProp, + centerofGravityLeftX, + centerofGravityLeftY, + centerofGravityLeftZ, + centerofGravityRightX, + centerofGravityRightY, + centerofGravityRightZ + ); SpeckleModel.elements.Add(speckleCSISpandrel); return speckleCSISpandrel; } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertStories.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertStories.cs index 73bec27a12..218ab710d5 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertStories.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertStories.cs @@ -33,15 +33,25 @@ public void StoriesToNative(CSIStories stories, ref ApplicationObject appObj) spliceAbove[i] = stories.CSIStory[i].SpliceAbove; spliceHeight[i] = stories.CSIStory[i].SpliceHeight; colors[i] = stories.CSIStory[i].Color; - } - var success = Model.Story.SetStories_2(stories.BaseElevation, stories.NumberStories, ref storyNames, ref storyHeights, ref isMasterStory, ref similarToStory, ref spliceAbove, ref spliceHeight, ref colors); + var success = Model.Story.SetStories_2( + stories.BaseElevation, + stories.NumberStories, + ref storyNames, + ref storyHeights, + ref isMasterStory, + ref similarToStory, + ref spliceAbove, + ref spliceHeight, + ref colors + ); if (success == 0) appObj.Update(status: ApplicationObject.State.Created, createdIds: storyNames.ToList()); else appObj.Update(status: ApplicationObject.State.Failed); } + public CSIStories StoriesToSpeckle() { double baseElevation = 0; @@ -55,7 +65,18 @@ public CSIStories StoriesToSpeckle() double[] spliceHeight = null; int numberOfStories = 0; - var s = Model.Story.GetStories_2(ref baseElevation, ref numberOfStories, ref names, ref storyElevations, ref storyHeights, ref isMasterStory, ref SimilarToStory, ref spliceAbove, ref spliceHeight, ref colors); + var s = Model.Story.GetStories_2( + ref baseElevation, + ref numberOfStories, + ref names, + ref storyElevations, + ref storyHeights, + ref isMasterStory, + ref SimilarToStory, + ref spliceAbove, + ref spliceHeight, + ref colors + ); var speckleStories = new CSIStories(); speckleStories.BaseElevation = baseElevation; @@ -63,7 +84,15 @@ public CSIStories StoriesToSpeckle() speckleStories.CSIStory = new List { }; for (int index = 0; index < numberOfStories; index++) { - var speckleStory = new CSIStorey(names[index], storyElevations[index], storyHeights[index], isMasterStory[index], SimilarToStory[index], spliceAbove[index], spliceHeight[index]); + var speckleStory = new CSIStorey( + names[index], + storyElevations[index], + storyHeights[index], + isMasterStory[index], + SimilarToStory[index], + spliceAbove[index], + spliceHeight[index] + ); speckleStories.CSIStory.Add(speckleStory); } @@ -72,4 +101,4 @@ public CSIStories StoriesToSpeckle() return speckleStories; } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertTendon.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertTendon.cs index 6ab091acc5..4c9b2092d0 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertTendon.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertTendon.cs @@ -15,9 +15,9 @@ public partial class ConverterCSI { public void CSITendonToSpeckle(CSITendon tendon) { - throw new NotSupportedException(); } + public CSITendon CSITendonToSpeckle(string name) { var speckleCSITendon = new CSITendon(); @@ -43,7 +43,6 @@ public CSITendon CSITendonToSpeckle(string name) speckleCSITendon.CSITendonProperty = TendonPropToSpeckle(tendonProp); SpeckleModel.elements.Add(speckleCSITendon); return speckleCSITendon; - } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/ConvertLoadPattern.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/ConvertLoadPattern.cs index 89f66d50b0..02d5560b42 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/ConvertLoadPattern.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/ConvertLoadPattern.cs @@ -14,6 +14,7 @@ public void LoadPatternToNative(LoadGravity gravityLoad) var LoadType = GetAndConvertToCSIPatternType(gravityLoad.loadCase.loadType); Model.LoadPatterns.Add(gravityLoad.name, LoadType, selfweight); } + public LoadCase LoadPatternToSpeckle(string loadPatternName) { var speckleLoadCase = new LoadCase(); @@ -25,7 +26,7 @@ public LoadCase LoadPatternToSpeckle(string loadPatternName) var selfweight = GetSelfWeightMultiplier(loadPatternName); - //Encoding loadPatterns selfweight multiplier within + //Encoding loadPatterns selfweight multiplier within if (selfweight != 0) { var gravityVector = new Geometry.Vector(0, 0, -selfweight); @@ -45,8 +46,10 @@ public LoadCase LoadPatternToSpeckle(string loadPatternName) SpeckleModel.loads.Add(gravityLoad); } if (SpeckleModel.loads.Contains(speckleLoadCase)) { } - else { SpeckleModel.loads.Add(speckleLoadCase); } - + else + { + SpeckleModel.loads.Add(speckleLoadCase); + } return speckleLoadCase; } @@ -68,7 +71,10 @@ public LoadCase LoadPatternCaseToSpeckle(string loadPatternName) speckleLoadCase.applicationId = loadPatternName; if (!SpeckleModel.loads.Contains(speckleLoadCase)) { } - else { SpeckleModel.loads.Add(speckleLoadCase); } + else + { + SpeckleModel.loads.Add(speckleLoadCase); + } return speckleLoadCase; } @@ -96,6 +102,7 @@ public eLoadPatternType GetAndConvertToCSIPatternType(LoadType loadType) return eLoadPatternType.Other; } } + public LoadType GetAndConvertCSILoadType(string name) { eLoadPatternType patternType = new eLoadPatternType(); @@ -142,4 +149,4 @@ public double GetSelfWeightMultiplier(string name) return selfWeightMultiplier; } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/Loading1DElements.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/Loading1DElements.cs index e5aea9b9f7..3ad9fa6b2e 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/Loading1DElements.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/Loading1DElements.cs @@ -14,6 +14,7 @@ public partial class ConverterCSI Dictionary LoadStoringBeam = new Dictionary(); Dictionary> FrameStoring = new Dictionary>(); int counterFrame = 0; + void LoadFrameToNative(LoadBeam loadBeam, ref ApplicationObject appObj) { int direction = 11; @@ -119,9 +120,25 @@ void LoadFrameToNative(LoadBeam loadBeam, ref ApplicationObject appObj) string name = element.name ?? element.id; if (loadBeam.loadType == BeamLoadType.Point) - Model.FrameObj.SetLoadDistributed(name, loadBeam.loadCase.name, myType, direction, loadBeam.positions[0], loadBeam.positions[1], loadBeam.values[0], loadBeam.values[1]); - else - Model.FrameObj.SetLoadPoint(name, loadBeam.loadCase.name, myType, direction, loadBeam.positions[0], loadBeam.values[0]); + Model.FrameObj.SetLoadDistributed( + name, + loadBeam.loadCase.name, + myType, + direction, + loadBeam.positions[0], + loadBeam.positions[1], + loadBeam.values[0], + loadBeam.values[1] + ); + else + Model.FrameObj.SetLoadPoint( + name, + loadBeam.loadCase.name, + myType, + direction, + loadBeam.positions[0], + loadBeam.values[0] + ); if (success == 0) appObj.Update(status: ApplicationObject.State.Created, createdId: name); @@ -129,10 +146,9 @@ void LoadFrameToNative(LoadBeam loadBeam, ref ApplicationObject appObj) appObj.Update(status: ApplicationObject.State.Failed); } } - + Base LoadFrameToSpeckle(string name, int frameNumber) { - int numberItems = 0; string[] frameName = null; string[] loadPat = null; @@ -148,18 +164,44 @@ Base LoadFrameToSpeckle(string name, int frameNumber) //var element1DList = new List(); - int s = Model.FrameObj.GetLoadDistributed(name, ref numberItems, ref frameName, ref loadPat, ref MyType, ref csys, ref dir, ref RD1, ref RD2, ref dist1, ref dist2, ref val1, ref val2); + int s = Model.FrameObj.GetLoadDistributed( + name, + ref numberItems, + ref frameName, + ref loadPat, + ref MyType, + ref csys, + ref dir, + ref RD1, + ref RD2, + ref dist1, + ref dist2, + ref val1, + ref val2 + ); if (s == 0) { foreach (int index in Enumerable.Range(0, numberItems)) { var speckleLoadFrame = new LoadBeam(); var element = FrameToSpeckle(frameName[index]); - var loadID = String.Concat(loadPat[index], val1[index], val2[index], dist1[index], dist2[index], dir[index], MyType[index]); + var loadID = String.Concat( + loadPat[index], + val1[index], + val2[index], + dist1[index], + dist2[index], + dir[index], + MyType[index] + ); speckleLoadFrame.applicationId = loadID; FrameStoring.TryGetValue(loadID, out var element1DList); - if (element1DList == null) { element1DList = new List { }; } - if (!element1DList.Select(el => el.applicationId).Contains(element.applicationId)) element1DList.Add(element); + if (element1DList == null) + { + element1DList = new List { }; + } + if (!element1DList.Select(el => el.applicationId).Contains(element.applicationId)) + element1DList.Add(element); FrameStoring[loadID] = element1DList; switch (dir[index]) @@ -213,10 +255,16 @@ Base LoadFrameToSpeckle(string name, int frameNumber) speckleLoadFrame.loadAxisType = Structural.LoadAxisType.Global; break; } - if (speckleLoadFrame.values == null) { speckleLoadFrame.values = new List { }; } + if (speckleLoadFrame.values == null) + { + speckleLoadFrame.values = new List { }; + } speckleLoadFrame.values.Add(val1[index]); speckleLoadFrame.values.Add(val2[index]); - if (speckleLoadFrame.positions == null) { speckleLoadFrame.positions = new List { }; } + if (speckleLoadFrame.positions == null) + { + speckleLoadFrame.positions = new List { }; + } speckleLoadFrame.positions.Add(dist1[index]); speckleLoadFrame.positions.Add(dist2[index]); speckleLoadFrame.loadType = BeamLoadType.Uniform; @@ -241,7 +289,18 @@ Base LoadFrameToSpeckle(string name, int frameNumber) double[] dist = null; double[] relDist = null; double[] val = null; - s = Model.FrameObj.GetLoadPoint(name, ref numberItems, ref frameName, ref loadPat, ref MyType, ref csys, ref dir, ref relDist, ref dist, ref val); + s = Model.FrameObj.GetLoadPoint( + name, + ref numberItems, + ref frameName, + ref loadPat, + ref MyType, + ref csys, + ref dir, + ref relDist, + ref dist, + ref val + ); if (s == 0) { foreach (int index in Enumerable.Range(0, numberItems)) @@ -251,8 +310,12 @@ Base LoadFrameToSpeckle(string name, int frameNumber) var loadID = String.Concat(loadPat[index], val, dist[index], dir[index], MyType[index]); speckleLoadFrame.applicationId = loadID; FrameStoring.TryGetValue(loadID, out var element1DList); - if (element1DList == null) { element1DList = new List { }; } - if (!element1DList.Select(el => el.applicationId).Contains(element.applicationId)) element1DList.Add(element); + if (element1DList == null) + { + element1DList = new List { }; + } + if (!element1DList.Select(el => el.applicationId).Contains(element.applicationId)) + element1DList.Add(element); FrameStoring[loadID] = element1DList; switch (dir[index]) @@ -305,10 +368,16 @@ Base LoadFrameToSpeckle(string name, int frameNumber) speckleLoadFrame.loadAxisType = Structural.LoadAxisType.Global; break; } - if (speckleLoadFrame.values == null) { speckleLoadFrame.values = new List { }; } + if (speckleLoadFrame.values == null) + { + speckleLoadFrame.values = new List { }; + } speckleLoadFrame.values.Add(val[index]); - if (speckleLoadFrame.positions == null) { speckleLoadFrame.positions = new List { }; } + if (speckleLoadFrame.positions == null) + { + speckleLoadFrame.positions = new List { }; + } speckleLoadFrame.positions.Add(dist[index]); speckleLoadFrame.loadType = BeamLoadType.Point; speckleLoadFrame.loadCase = LoadPatternCaseToSpeckle(loadPat[index]); @@ -331,6 +400,5 @@ Base LoadFrameToSpeckle(string name, int frameNumber) var speckleObject = new Base(); return speckleObject; } - } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/Loading2DElements.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/Loading2DElements.cs index 065aa8ec8b..21ede9d195 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/Loading2DElements.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/Loading2DElements.cs @@ -16,14 +16,15 @@ public partial class ConverterCSI Dictionary> AreaStoring = new Dictionary>(); int counterAreaLoadUniform = 0; int counterAreaLoadWind = 0; + void LoadFaceToNative(LoadFace loadFace, ref ApplicationObject appObj) { foreach (Element2D element in loadFace.elements) { string elementName = null; - if (element.name != null) + if (element.name != null) elementName = element.name; - else + else elementName = element.id; if (loadFace.loadType != FaceLoadType.Constant) // TODO: support other load types @@ -74,7 +75,15 @@ Base LoadFaceToSpeckle(string name, int areaNumber) string[] csys = null; int[] dir = null; double[] value = null; - int s = Model.AreaObj.GetLoadUniform(name, ref numberItems, ref areaName, ref loadPat, ref csys, ref dir, ref value); + int s = Model.AreaObj.GetLoadUniform( + name, + ref numberItems, + ref areaName, + ref loadPat, + ref csys, + ref dir, + ref value + ); if (s == 0) { foreach (int index in Enumerable.Range(0, numberItems)) @@ -84,7 +93,10 @@ Base LoadFaceToSpeckle(string name, int areaNumber) var loadID = string.Concat(loadPat[index], csys[index], dir[index], value[index]); speckleLoadFace.applicationId = loadID; AreaStoring.TryGetValue(loadID, out var element2Dlist); - if (element2Dlist == null) { element2Dlist = new List { }; } + if (element2Dlist == null) + { + element2Dlist = new List { }; + } element2Dlist.Add(element); AreaStoring[loadID] = element2Dlist; @@ -138,7 +150,10 @@ Base LoadFaceToSpeckle(string name, int areaNumber) speckleLoadFace.loadAxisType = Structural.LoadAxisType.Global; break; } - if (speckleLoadFace.values == null) { speckleLoadFace.values = new List { }; } + if (speckleLoadFace.values == null) + { + speckleLoadFace.values = new List { }; + } speckleLoadFace.values.Add(value[index]); speckleLoadFace.loadCase = LoadPatternCaseToSpeckle(loadPat[index]); LoadStoringArea[loadID] = speckleLoadFace; @@ -156,7 +171,6 @@ Base LoadFaceToSpeckle(string name, int areaNumber) } counterAreaLoadUniform = 0; } - } int[] myType = null; @@ -171,10 +185,16 @@ Base LoadFaceToSpeckle(string name, int areaNumber) var loadID = string.Concat(loadPat[index], myType[index], cp[index]); speckleLoadFace.applicationId = loadID; AreaStoring.TryGetValue(loadID, out var element2Dlist); - if (element2Dlist == null) { element2Dlist = new List { }; } + if (element2Dlist == null) + { + element2Dlist = new List { }; + } element2Dlist.Add(element); AreaStoring[loadID] = element2Dlist; - if (speckleLoadFace.values == null) { speckleLoadFace.values = new List { }; } + if (speckleLoadFace.values == null) + { + speckleLoadFace.values = new List { }; + } speckleLoadFace.Cp = cp[index]; switch (myType[index]) { @@ -204,6 +224,5 @@ Base LoadFaceToSpeckle(string name, int areaNumber) var speckleBase = new Base(); return speckleBase; } - } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/LoadingNode.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/LoadingNode.cs index 50bdd3f881..003fe7f601 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/LoadingNode.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Loading/LoadingNode.cs @@ -15,6 +15,7 @@ public partial class ConverterCSI Dictionary LoadStoringNode = new Dictionary(); Dictionary> NodeStoring = new Dictionary>(); int counterPoint = 0; + //need to figure out how to recombine forces into val6 //void LoadNodeToNative(LoadNode loadNode) //{ @@ -37,7 +38,20 @@ Base LoadNodeToSpeckle(string name, int pointNumber) string[] loadPat = null; int numberItems = 0; - int s = Model.PointObj.GetLoadForce(name, ref numberItems, ref pointName, ref loadPat, ref lcStep, ref csys, ref F1, ref F2, ref F3, ref M1, ref M2, ref M3); + int s = Model.PointObj.GetLoadForce( + name, + ref numberItems, + ref pointName, + ref loadPat, + ref lcStep, + ref csys, + ref F1, + ref F2, + ref F3, + ref M1, + ref M2, + ref M3 + ); if (s == 0) { foreach (int index in Enumerable.Range(0, numberItems)) @@ -85,7 +99,6 @@ Base LoadNodeToSpeckle(string name, int pointNumber) generateIDAndElements(loadID, loadPat[index], pointName[index], M3[index], speckleLoadNode); } //speckleLoadFace.loadCase = LoadPatternCaseToSpeckle(loadPat[index]); - } counterPoint += 1; @@ -97,7 +110,6 @@ Base LoadNodeToSpeckle(string name, int pointNumber) LoadStoringNode.TryGetValue(entry, out var loadStoringNode); loadStoringNode.nodes = listNode; SpeckleModel.loads.Add(loadStoringNode); - } } } @@ -112,11 +124,13 @@ void generateIDAndElements(string loadID, string loadPat, string nodeName, doubl Node speckleNode = PointToSpeckle(nodeName); speckleLoadNode.loadCase = LoadPatternCaseToSpeckle(loadPat); NodeStoring.TryGetValue(loadID, out var nodeList); - if (nodeList == null) { nodeList = new List { }; } + if (nodeList == null) + { + nodeList = new List { }; + } nodeList.Add(speckleNode); NodeStoring[loadID] = nodeList; LoadStoringNode[loadID] = speckleLoadNode; - } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Materials/ConvertMaterials.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Materials/ConvertMaterials.cs index fae4dc0161..f8fdcb38c8 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Materials/ConvertMaterials.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Materials/ConvertMaterials.cs @@ -52,7 +52,13 @@ public string MaterialToNative(Objects.Structural.Materials.StructuralMaterial m if (material.designCode != null) { - Model.PropMaterial.AddMaterial(ref materialName, eMaterialType, material.designCode, material.codeYear, material.grade); + Model.PropMaterial.AddMaterial( + ref materialName, + eMaterialType, + material.designCode, + material.codeYear, + material.grade + ); Model.PropMaterial.ChangeName(materialName, material.name); } else @@ -62,7 +68,8 @@ public string MaterialToNative(Objects.Structural.Materials.StructuralMaterial m { SetConcreteMaterial(csiConcrete, material.name); } - else if (material is Structural.CSI.Materials.CSISteel csiSteel){ + else if (material is Structural.CSI.Materials.CSISteel csiSteel) + { SetSteelMaterial(csiSteel, material.name); } } @@ -75,7 +82,8 @@ public Structural.Materials.StructuralMaterial MaterialToSpeckle(string name) speckleStructMaterial.name = name; eMatType matType = new eMatType(); int color = 0; - string notes, GUID; + string notes, + GUID; notes = GUID = null; Model.PropMaterial.GetMaterial(name, ref matType, ref color, ref notes, ref GUID); @@ -97,7 +105,7 @@ public Structural.Materials.StructuralMaterial MaterialToSpeckle(string name) speckleStructMaterial.materialType = Structural.MaterialType.Aluminium; break; case eMatType.Rebar: - + return GetRebarMaterial(name); break; case eMatType.ColdFormed: @@ -110,20 +118,27 @@ public Structural.Materials.StructuralMaterial MaterialToSpeckle(string name) speckleStructMaterial.materialType = Structural.MaterialType.Masonry; break; } - + return speckleStructMaterial; } #region Helper functions public Structural.CSI.Materials.CSISteel GetSteelMaterial(string materialName) { - double fy, fu, eFy, eFu, strainAtHardening, strainAtMaxStress, strainAtRupture, finalSlope; + double fy, + fu, + eFy, + eFu, + strainAtHardening, + strainAtMaxStress, + strainAtRupture, + finalSlope; fy = fu = eFy = eFu = strainAtHardening = strainAtMaxStress = strainAtRupture = finalSlope = 0; - int sStype, sSHysType; + int sStype, + sSHysType; sStype = sSHysType = 0; var speckleMaterial = new Structural.CSI.Materials.CSISteel(); - // Material is isotropic or elastic - No support for other types currently if (sSHysType == 7 || sSHysType == 1) @@ -131,12 +146,24 @@ public Structural.CSI.Materials.CSISteel GetSteelMaterial(string materialName) speckleMaterial = (Structural.CSI.Materials.CSISteel)GetIsotropicMaterial(materialName); } - Model.PropMaterial.GetOSteel_1(materialName, ref fy, ref fu, ref eFy, ref eFu, ref sStype, ref sSHysType, ref strainAtHardening, ref strainAtMaxStress, ref strainAtRupture, ref finalSlope); - + Model.PropMaterial.GetOSteel_1( + materialName, + ref fy, + ref fu, + ref eFy, + ref eFu, + ref sStype, + ref sSHysType, + ref strainAtHardening, + ref strainAtMaxStress, + ref strainAtRupture, + ref finalSlope + ); + speckleMaterial.strength = fy; speckleMaterial.ultimateStrength = fu; speckleMaterial.maxStrain = strainAtRupture; - speckleMaterial.strainHardeningModulus = finalSlope ; + speckleMaterial.strainHardeningModulus = finalSlope; speckleMaterial.strainAtHardening = strainAtHardening; speckleMaterial.strainAtMaxStress = strainAtMaxStress; speckleMaterial.SSHysType = sSHysType; @@ -147,34 +174,46 @@ public Structural.CSI.Materials.CSISteel GetSteelMaterial(string materialName) return speckleMaterial; } - public void SetSteelMaterial(Structural.CSI.Materials.CSISteel structuralMaterial, string etabsMaterialName){ + + public void SetSteelMaterial(Structural.CSI.Materials.CSISteel structuralMaterial, string etabsMaterialName) + { //Support only isotropic Steel Material setting //Lossy transformation since Speckle classes are missing material properties - Model.PropMaterial.SetOSteel_1(etabsMaterialName, - structuralMaterial.strength, - structuralMaterial.yieldStrength, - structuralMaterial.EFy, - structuralMaterial.EFu, - structuralMaterial.SSType, - structuralMaterial.SSHysType, - structuralMaterial.strainAtHardening, - structuralMaterial.strainAtMaxStress, - structuralMaterial.maxStrain, - structuralMaterial.strainHardeningModulus); - - Model.PropMaterial.SetMPIsotropic(etabsMaterialName, - structuralMaterial.elasticModulus, - structuralMaterial.poissonsRatio, - structuralMaterial.thermalExpansivity, - structuralMaterial.shearModulus); - - } + Model.PropMaterial.SetOSteel_1( + etabsMaterialName, + structuralMaterial.strength, + structuralMaterial.yieldStrength, + structuralMaterial.EFy, + structuralMaterial.EFu, + structuralMaterial.SSType, + structuralMaterial.SSHysType, + structuralMaterial.strainAtHardening, + structuralMaterial.strainAtMaxStress, + structuralMaterial.maxStrain, + structuralMaterial.strainHardeningModulus + ); + + Model.PropMaterial.SetMPIsotropic( + etabsMaterialName, + structuralMaterial.elasticModulus, + structuralMaterial.poissonsRatio, + structuralMaterial.thermalExpansivity, + structuralMaterial.shearModulus + ); + } public Structural.CSI.Materials.CSIConcrete GetConcreteMaterial(string materialName) { - double fc, fcsFactor, strainAtFc, strainUltimate, finalSlope, frictionAngle, dilatationalAngle; + double fc, + fcsFactor, + strainAtFc, + strainUltimate, + finalSlope, + frictionAngle, + dilatationalAngle; fc = fcsFactor = strainAtFc = strainUltimate = finalSlope = frictionAngle = dilatationalAngle = 0; - int sStype, sSHysType; + int sStype, + sSHysType; sStype = sSHysType = 0; bool isLightweight = false; @@ -185,10 +224,20 @@ public Structural.CSI.Materials.CSIConcrete GetConcreteMaterial(string materialN speckleMaterial = (Structural.CSI.Materials.CSIConcrete)GetIsotropicMaterial(materialName); } - Model.PropMaterial.GetOConcrete_1(materialName, ref fc, ref isLightweight, ref fcsFactor, ref sStype, ref sSHysType, ref strainAtFc, ref strainUltimate, ref finalSlope, ref frictionAngle, ref dilatationalAngle); + Model.PropMaterial.GetOConcrete_1( + materialName, + ref fc, + ref isLightweight, + ref fcsFactor, + ref sStype, + ref sSHysType, + ref strainAtFc, + ref strainUltimate, + ref finalSlope, + ref frictionAngle, + ref dilatationalAngle + ); - - speckleMaterial.strength = fc; speckleMaterial.materialSafetyFactor = fcsFactor; speckleMaterial.maxCompressiveStrain = strainUltimate; @@ -204,35 +253,46 @@ public Structural.CSI.Materials.CSIConcrete GetConcreteMaterial(string materialN return speckleMaterial; } - public void SetConcreteMaterial(Structural.CSI.Materials.CSIConcrete structuralMaterial, string etabsMaterialName){ - Model.PropMaterial.SetOConcrete_1(etabsMaterialName, - structuralMaterial.strength, - structuralMaterial.lightweight, - structuralMaterial.materialSafetyFactor, - structuralMaterial.SSType, - structuralMaterial.SSHysType, - structuralMaterial.maxTensileStrain, - structuralMaterial.maxCompressiveStrain, - structuralMaterial.finalSlope, - structuralMaterial.frictionAngle, - structuralMaterial.dialationalAngle); - - - Model.PropMaterial.SetMPIsotropic(etabsMaterialName, - structuralMaterial.elasticModulus, - structuralMaterial.poissonsRatio, - structuralMaterial.thermalExpansivity, - structuralMaterial.shearModulus); + public void SetConcreteMaterial(Structural.CSI.Materials.CSIConcrete structuralMaterial, string etabsMaterialName) + { + Model.PropMaterial.SetOConcrete_1( + etabsMaterialName, + structuralMaterial.strength, + structuralMaterial.lightweight, + structuralMaterial.materialSafetyFactor, + structuralMaterial.SSType, + structuralMaterial.SSHysType, + structuralMaterial.maxTensileStrain, + structuralMaterial.maxCompressiveStrain, + structuralMaterial.finalSlope, + structuralMaterial.frictionAngle, + structuralMaterial.dialationalAngle + ); + + Model.PropMaterial.SetMPIsotropic( + etabsMaterialName, + structuralMaterial.elasticModulus, + structuralMaterial.poissonsRatio, + structuralMaterial.thermalExpansivity, + structuralMaterial.shearModulus + ); } - public Structural.CSI.Materials.CSIRebar GetRebarMaterial(string materialName ){ - double fy, fu, eFy, eFu, strainAtHardening, strainUltimate, finalSlope; + public Structural.CSI.Materials.CSIRebar GetRebarMaterial(string materialName) + { + double fy, + fu, + eFy, + eFu, + strainAtHardening, + strainUltimate, + finalSlope; fy = fu = eFy = eFu = strainAtHardening = strainUltimate = finalSlope = 0; - int sStype, sSHysType; + int sStype, + sSHysType; sStype = sSHysType = 0; bool useCaltransSSDefaults = false; - Structural.CSI.Materials.CSIRebar rebarMaterial = new Structural.CSI.Materials.CSIRebar(); // Rebar can only be set to uniaxial //GetUniaxialMaterial(materialName); @@ -241,17 +301,24 @@ public Structural.CSI.Materials.CSIRebar GetRebarMaterial(string materialName ){ //speckleMaterial.strength = fy; return rebarMaterial; - } - public void SetRebarMaterial(StructuralMaterial structuralMaterial, string etabsMaterialName){ + public void SetRebarMaterial(StructuralMaterial structuralMaterial, string etabsMaterialName) + { Model.PropMaterial.SetORebar_1(etabsMaterialName, structuralMaterial.strength, 0, 0, 0, 0, 0, 0, 0, 0, false); - Model.PropMaterial.SetMPUniaxial(etabsMaterialName, structuralMaterial.elasticModulus, structuralMaterial.thermalExpansivity); + Model.PropMaterial.SetMPUniaxial( + etabsMaterialName, + structuralMaterial.elasticModulus, + structuralMaterial.thermalExpansivity + ); } public object GetIsotropicMaterial(string materialName) { - double e, u, a, g; + double e, + u, + a, + g; e = u = a = g = 0; Model.PropMaterial.GetMPIsotropic(materialName, ref e, ref u, ref a, ref g); @@ -262,8 +329,8 @@ public object GetIsotropicMaterial(string materialName) speckleMaterial.shearModulus = g; return speckleMaterial; } - - public void GetUniaxialMaterial(string materialName,ref Structural.Materials.StructuralMaterial speckleMaterial) + + public void GetUniaxialMaterial(string materialName, ref Structural.Materials.StructuralMaterial speckleMaterial) { double e = 0; double a = 0; diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert1DProperty.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert1DProperty.cs index 0d4ce49754..fc21ab6b06 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert1DProperty.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert1DProperty.cs @@ -21,6 +21,7 @@ public bool Property1DExists(string name) } return false; } + public string Property1DToNative(Property1D property1D, ref ApplicationObject appObj) { if (property1D == null) @@ -38,9 +39,11 @@ public string Property1DToNative(Property1D property1D, ref ApplicationObject ap var catalogue = new Catalogue(); int? success = null; - if (property1D.profile is Catalogue sectionProfile + if ( + property1D.profile is Catalogue sectionProfile && !string.IsNullOrEmpty(sectionProfile.catalogueName) - && !string.IsNullOrEmpty(sectionProfile.sectionName)) + && !string.IsNullOrEmpty(sectionProfile.sectionName) + ) { switch (sectionProfile.catalogueName) { @@ -49,7 +52,12 @@ public string Property1DToNative(Property1D property1D, ref ApplicationObject ap break; } - success = Model.PropFrame.ImportProp(property1D.name, materialName, sectionProfile.catalogueName + ".xml", sectionProfile.sectionName.ToUpper()); + success = Model.PropFrame.ImportProp( + property1D.name, + materialName, + sectionProfile.catalogueName + ".xml", + sectionProfile.sectionName.ToUpper() + ); if (success == 0) appObj.Update(status: ApplicationObject.State.Created, createdId: $"{property1D.name}"); @@ -63,45 +71,46 @@ public string Property1DToNative(Property1D property1D, ref ApplicationObject ap { case Angle o: success = Model.PropFrame.SetAngle( - property1D.name, + property1D.name, materialName, - ScaleToNative(o.depth, o.units), - ScaleToNative(o.width, o.units), - ScaleToNative(o.flangeThickness, o.units), - ScaleToNative(o.webThickness, o.units)); + ScaleToNative(o.depth, o.units), + ScaleToNative(o.width, o.units), + ScaleToNative(o.flangeThickness, o.units), + ScaleToNative(o.webThickness, o.units) + ); break; case Channel o: success = Model.PropFrame.SetChannel( - property1D.name, - materialName, - ScaleToNative(o.depth, o.units), - ScaleToNative(o.width, o.units), - ScaleToNative(o.flangeThickness, o.units), - ScaleToNative(o.webThickness, o.units)); + property1D.name, + materialName, + ScaleToNative(o.depth, o.units), + ScaleToNative(o.width, o.units), + ScaleToNative(o.flangeThickness, o.units), + ScaleToNative(o.webThickness, o.units) + ); break; case Circular o: if (o.wallThickness > 0) success = Model.PropFrame.SetPipe( - property1D.name, - materialName, - ScaleToNative(o.radius * 2, o.units), - ScaleToNative(o.wallThickness, o.units)); + property1D.name, + materialName, + ScaleToNative(o.radius * 2, o.units), + ScaleToNative(o.wallThickness, o.units) + ); else - success = Model.PropFrame.SetCircle( - property1D.name, - materialName, - ScaleToNative(o.radius * 2, o.units)); + success = Model.PropFrame.SetCircle(property1D.name, materialName, ScaleToNative(o.radius * 2, o.units)); break; case ISection o: success = Model.PropFrame.SetISection( - property1D.name, + property1D.name, materialName, ScaleToNative(o.depth, o.units), ScaleToNative(o.width, o.units), ScaleToNative(o.flangeThickness, o.units), ScaleToNative(o.webThickness, o.units), ScaleToNative(o.width, o.units), - ScaleToNative(o.flangeThickness, o.units)); + ScaleToNative(o.flangeThickness, o.units) + ); break; case Rectangular o: if (o.flangeThickness > 0 && o.webThickness > 0) @@ -111,34 +120,41 @@ public string Property1DToNative(Property1D property1D, ref ApplicationObject ap ScaleToNative(o.depth, o.units), ScaleToNative(o.width, o.units), ScaleToNative(o.flangeThickness, o.units), - ScaleToNative(o.webThickness, o.units)); + ScaleToNative(o.webThickness, o.units) + ); else success = Model.PropFrame.SetRectangle( - property1D.name, + property1D.name, materialName, - ScaleToNative(o.depth, o.units), - ScaleToNative(o.width, o.units)); + ScaleToNative(o.depth, o.units), + ScaleToNative(o.width, o.units) + ); break; case Tee o: success = Model.PropFrame.SetConcreteTee( - property1D.name, - materialName, - ScaleToNative(o.depth, o.units), - ScaleToNative(o.width, o.units), - ScaleToNative(o.flangeThickness, o.units), - ScaleToNative(o.webThickness, o.units), - ScaleToNative(o.webThickness, o.units), - false); + property1D.name, + materialName, + ScaleToNative(o.depth, o.units), + ScaleToNative(o.width, o.units), + ScaleToNative(o.flangeThickness, o.units), + ScaleToNative(o.webThickness, o.units), + ScaleToNative(o.webThickness, o.units), + false + ); break; } if (success == 0) appObj.Update(status: ApplicationObject.State.Created, createdId: property1D.name); else - appObj.Update(status: ApplicationObject.State.Failed, logItem: $"Unable to create section with profile named {property1D.name}"); + appObj.Update( + status: ApplicationObject.State.Failed, + logItem: $"Unable to create section with profile named {property1D.name}" + ); return property1D.name; } + public Property1D Property1DToSpeckle(string name) { var speckleStructProperty1D = new Property1D(); @@ -148,11 +164,10 @@ public Property1D Property1DToSpeckle(string name) speckleStructProperty1D.material = MaterialToSpeckle(materialProp); speckleStructProperty1D.profile = SectionToSpeckle(name); - speckleStructProperty1D.applicationId = $"{speckleStructProperty1D.material.applicationId}:{speckleStructProperty1D.profile.applicationId}"; + speckleStructProperty1D.applicationId = + $"{speckleStructProperty1D.material.applicationId}:{speckleStructProperty1D.profile.applicationId}"; return speckleStructProperty1D; } - - } } diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DProperty.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DProperty.cs index 129a7aa41c..642ef56ea8 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DProperty.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DProperty.cs @@ -12,7 +12,6 @@ namespace Objects.Converter.CSI { public partial class ConverterCSI { - void setProperties(CSIProperty2D property2D, string matProp, double thickeness, string name) { property2D.name = name; @@ -20,15 +19,16 @@ void setProperties(CSIProperty2D property2D, string matProp, double thickeness, property2D.material = MaterialToSpeckle(matProp); return; } + private string Property2DToNative(CSIProperty2D property2D) { if (property2D.type2D == CSIPropertyType2D.Wall) { return WallPropertyToNative(property2D); } - else - { - return FloorPropertyToNative(property2D); + else + { + return FloorPropertyToNative(property2D); } } @@ -60,6 +60,5 @@ CSIProperty2D Property2DToSpeckle(string area, string property) return null; } - } } diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyFloor.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyFloor.cs index adc75ee0e4..afb840dfc8 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyFloor.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyFloor.cs @@ -21,35 +21,41 @@ public string FloorPropertyToNative(CSIProperty2D property2D) { case Structural.CSI.Analysis.DeckType.Filled: var deckFilled = (CSIProperty2D.DeckFilled)property2D; - success = Model.PropArea.SetDeckFilled(deckFilled.name, - deckFilled.SlabDepth, - deckFilled.RibDepth, - deckFilled.RibWidthTop, - deckFilled.RibWidthBot, - deckFilled.RibSpacing, - deckFilled.ShearThickness, - deckFilled.UnitWeight, - deckFilled.ShearStudDia, - deckFilled.ShearStudHt, - deckFilled.ShearStudFu); + success = Model.PropArea.SetDeckFilled( + deckFilled.name, + deckFilled.SlabDepth, + deckFilled.RibDepth, + deckFilled.RibWidthTop, + deckFilled.RibWidthBot, + deckFilled.RibSpacing, + deckFilled.ShearThickness, + deckFilled.UnitWeight, + deckFilled.ShearStudDia, + deckFilled.ShearStudHt, + deckFilled.ShearStudFu + ); break; case Structural.CSI.Analysis.DeckType.Unfilled: var deckUnfilled = (CSIProperty2D.DeckUnFilled)property2D; - success = Model.PropArea.SetDeckUnfilled(deckUnfilled.name, - deckUnfilled.RibDepth, - deckUnfilled.RibWidthTop, - deckUnfilled.RibWidthBot, - deckUnfilled.RibSpacing, - deckUnfilled.ShearThickness, - deckUnfilled.UnitWeight); + success = Model.PropArea.SetDeckUnfilled( + deckUnfilled.name, + deckUnfilled.RibDepth, + deckUnfilled.RibWidthTop, + deckUnfilled.RibWidthBot, + deckUnfilled.RibSpacing, + deckUnfilled.ShearThickness, + deckUnfilled.UnitWeight + ); break; case Structural.CSI.Analysis.DeckType.SolidSlab: var deckSlab = (CSIProperty2D.DeckSlab)property2D; - success = Model.PropArea.SetDeckSolidSlab(deckSlab.name, - deckSlab.SlabDepth, - deckSlab.ShearStudDia, - deckSlab.ShearStudHt, - deckSlab.ShearStudFu); + success = Model.PropArea.SetDeckSolidSlab( + deckSlab.name, + deckSlab.SlabDepth, + deckSlab.ShearStudDia, + deckSlab.ShearStudHt, + deckSlab.ShearStudFu + ); break; } } @@ -60,37 +66,59 @@ public string FloorPropertyToNative(CSIProperty2D property2D) case Structural.CSI.Analysis.SlabType.Slab: var SolidSlab = property2D; var shell = shellType(SolidSlab); - success = Model.PropArea.SetSlab(SolidSlab.name, eSlabType.Slab, shell, SolidSlab.material.name, SolidSlab.thickness); + success = Model.PropArea.SetSlab( + SolidSlab.name, + eSlabType.Slab, + shell, + SolidSlab.material.name, + SolidSlab.thickness + ); break; case Structural.CSI.Analysis.SlabType.Ribbed: var slabRibbed = (CSIProperty2D.RibbedSlab)property2D; shell = shellType(slabRibbed); - Model.PropArea.SetSlab(slabRibbed.name, eSlabType.Ribbed, shell, slabRibbed.material.name, slabRibbed.thickness); - success = Model.PropArea.SetSlabRibbed(slabRibbed.name, - slabRibbed.OverAllDepth, - slabRibbed.thickness, - slabRibbed.StemWidthTop, - slabRibbed.StemWidthTop, - slabRibbed.RibSpacing, - slabRibbed.RibsParallelTo); + Model.PropArea.SetSlab( + slabRibbed.name, + eSlabType.Ribbed, + shell, + slabRibbed.material.name, + slabRibbed.thickness + ); + success = Model.PropArea.SetSlabRibbed( + slabRibbed.name, + slabRibbed.OverAllDepth, + slabRibbed.thickness, + slabRibbed.StemWidthTop, + slabRibbed.StemWidthTop, + slabRibbed.RibSpacing, + slabRibbed.RibsParallelTo + ); break; case Structural.CSI.Analysis.SlabType.Waffle: var slabWaffled = (CSIProperty2D.WaffleSlab)property2D; shell = shellType(slabWaffled); - Model.PropArea.SetSlab(slabWaffled.name, eSlabType.Waffle, shell, slabWaffled.material.name, slabWaffled.thickness); + Model.PropArea.SetSlab( + slabWaffled.name, + eSlabType.Waffle, + shell, + slabWaffled.material.name, + slabWaffled.thickness + ); success = Model.PropArea.SetSlabWaffle( - slabWaffled.name, - slabWaffled.OverAllDepth, - slabWaffled.thickness, - slabWaffled.StemWidthTop, - slabWaffled.StemWidthBot, - slabWaffled.RibSpacingDir1, - slabWaffled.RibSpacingDir2); + slabWaffled.name, + slabWaffled.OverAllDepth, + slabWaffled.thickness, + slabWaffled.StemWidthTop, + slabWaffled.StemWidthBot, + slabWaffled.RibSpacingDir1, + slabWaffled.RibSpacingDir2 + ); break; } } - if (success == 0) return property2D.name; + if (success == 0) + return property2D.name; throw new Exception($"Unable to create floor property from CSIProperty2D with Id {property2D.id}"); } @@ -114,6 +142,7 @@ public eShellType shellType(CSIProperty2D property) } return shellType; } + public void SetDeck(CSIProperty2D deck) { var deckType = eDeckType.Filled; @@ -132,6 +161,7 @@ public void SetDeck(CSIProperty2D deck) var shell = shellType(deck); Model.PropArea.SetDeck(deck.name, deckType, shell, deck.material.name, deck.thickness); } + public CSIProperty2D FloorPropertyToSpeckle(string property) { eDeckType deckType = eDeckType.Filled; @@ -143,10 +173,18 @@ public CSIProperty2D FloorPropertyToSpeckle(string property) string notes = ""; string GUID = ""; - int d = Model.PropArea.GetDeck(property, ref deckType, ref shellType, ref matProp, ref thickness, ref color, ref notes, ref GUID); + int d = Model.PropArea.GetDeck( + property, + ref deckType, + ref shellType, + ref matProp, + ref thickness, + ref color, + ref notes, + ref GUID + ); if (d == 0) { - var speckleProperties2D = new CSIProperty2D(); double slabDepth = 0; double shearStudDia = 0; @@ -162,17 +200,19 @@ public CSIProperty2D FloorPropertyToSpeckle(string property) if (deckType == eDeckType.Filled) { var speckleProperty2D = new CSIProperty2D.DeckFilled(); - Model.PropArea.GetDeckFilled(property, - ref slabDepth, - ref ribDepth, - ref ribWidthTop, - ref ribWidthBot, - ref ribSpacing, - ref shearThickness, - ref unitWeight, - ref shearStudDia, - ref shearStudHt, - ref shearStudFu); + Model.PropArea.GetDeckFilled( + property, + ref slabDepth, + ref ribDepth, + ref ribWidthTop, + ref ribWidthBot, + ref ribSpacing, + ref shearThickness, + ref unitWeight, + ref shearStudDia, + ref shearStudHt, + ref shearStudFu + ); speckleProperty2D.SlabDepth = slabDepth; speckleProperty2D.ShearStudDia = shearStudDia; speckleProperty2D.ShearStudFu = shearStudFu; @@ -193,13 +233,15 @@ public CSIProperty2D FloorPropertyToSpeckle(string property) else if (deckType == eDeckType.Unfilled) { var speckleProperty2D = new CSIProperty2D.DeckUnFilled(); - Model.PropArea.GetDeckUnfilled(property, - ref ribDepth, - ref ribWidthTop, - ref ribWidthBot, - ref ribSpacing, - ref shearThickness, - ref unitWeight); + Model.PropArea.GetDeckUnfilled( + property, + ref ribDepth, + ref ribWidthTop, + ref ribWidthBot, + ref ribSpacing, + ref shearThickness, + ref unitWeight + ); speckleProperty2D.RibDepth = ribDepth; speckleProperty2D.RibWidthTop = ribWidthTop; speckleProperty2D.RibWidthBot = ribWidthBot; @@ -212,7 +254,6 @@ public CSIProperty2D FloorPropertyToSpeckle(string property) speckleProperty2D.shellType = speckleShellType; speckleProperty2D.applicationId = GUID; return speckleProperty2D; - } else if (deckType == eDeckType.SolidSlab) { @@ -230,7 +271,16 @@ public CSIProperty2D FloorPropertyToSpeckle(string property) return speckleProperty2D; } } - int s = Model.PropArea.GetSlab(property, ref slabType, ref shellType, ref matProp, ref thickness, ref color, ref notes, ref GUID); + int s = Model.PropArea.GetSlab( + property, + ref slabType, + ref shellType, + ref matProp, + ref thickness, + ref color, + ref notes, + ref GUID + ); if (s == 0) { var specklePropery2DSlab = new CSIProperty2D(); @@ -248,7 +298,15 @@ public CSIProperty2D FloorPropertyToSpeckle(string property) if (slabType == eSlabType.Waffle) { var speckleProperty2D = new CSIProperty2D.WaffleSlab(); - Model.PropArea.GetSlabWaffle(property, ref overallDepth, ref slabThickness, ref stemWidthTop, ref stemWidthBot, ref ribSpacingDir1, ref ribSpacingDir2); + Model.PropArea.GetSlabWaffle( + property, + ref overallDepth, + ref slabThickness, + ref stemWidthTop, + ref stemWidthBot, + ref ribSpacingDir1, + ref ribSpacingDir2 + ); speckleProperty2D.OverAllDepth = overallDepth; speckleProperty2D.StemWidthBot = stemWidthBot; speckleProperty2D.StemWidthTop = stemWidthTop; @@ -264,7 +322,15 @@ public CSIProperty2D FloorPropertyToSpeckle(string property) else if (slabType == eSlabType.Ribbed) { var speckleProperty2D = new CSIProperty2D.RibbedSlab(); - Model.PropArea.GetSlabRibbed(property, ref overallDepth, ref slabThickness, ref stemWidthTop, ref stemWidthBot, ref ribSpacing, ref ribParrallelTo); + Model.PropArea.GetSlabRibbed( + property, + ref overallDepth, + ref slabThickness, + ref stemWidthTop, + ref stemWidthBot, + ref ribSpacing, + ref ribParrallelTo + ); speckleProperty2D.OverAllDepth = overallDepth; speckleProperty2D.StemWidthBot = stemWidthBot; speckleProperty2D.StemWidthTop = stemWidthTop; @@ -276,7 +342,6 @@ public CSIProperty2D FloorPropertyToSpeckle(string property) speckleProperty2D.shellType = speckleShellType; speckleProperty2D.applicationId = GUID; return speckleProperty2D; - } else { diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyWall.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyWall.cs index 28bc0234a2..0d361decfc 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyWall.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyWall.cs @@ -11,6 +11,7 @@ public string WallPropertyToNative(CSIProperty2D Wall) { throw new Exception("Wall properties are not currently supported on receive"); } + public CSIProperty2D WallPropertyToSpeckle(string property) { eWallPropType wallPropType = eWallPropType.Specified; @@ -22,7 +23,16 @@ public CSIProperty2D WallPropertyToSpeckle(string property) string GUID = ""; var specklePropery2DWall = new CSIProperty2D(); specklePropery2DWall.type = Structural.PropertyType2D.Wall; - Model.PropArea.GetWall(property, ref wallPropType, ref shellType, ref matProp, ref thickness, ref color, ref notes, ref GUID); + Model.PropArea.GetWall( + property, + ref wallPropType, + ref shellType, + ref matProp, + ref thickness, + ref color, + ref notes, + ref GUID + ); var speckleShellType = ConvertShellType(shellType); specklePropery2DWall.shellType = speckleShellType; setProperties(specklePropery2DWall, matProp, thickness, property); diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertDiaphragm.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertDiaphragm.cs index fe88a5d182..9f444f96e2 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertDiaphragm.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertDiaphragm.cs @@ -21,8 +21,12 @@ private void DiaphragmToNative(CSIDiaphragm CSIDiaphragm, ref ApplicationObject if (success == 0) appObj.Update(status: ApplicationObject.State.Created, createdId: CSIDiaphragm.name); else - appObj.Update(status: ApplicationObject.State.Failed, logItem: $"Unable to create diaphragm with id {CSIDiaphragm.id}"); + appObj.Update( + status: ApplicationObject.State.Failed, + logItem: $"Unable to create diaphragm with id {CSIDiaphragm.id}" + ); } + CSIDiaphragm diaphragmToSpeckle(string name) { bool semiRigid = false; @@ -30,4 +34,4 @@ CSIDiaphragm diaphragmToSpeckle(string name) return new CSIDiaphragm(name, semiRigid); } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertLinkProperty.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertLinkProperty.cs index 9e671292f8..ce6d8f2d4a 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertLinkProperty.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertLinkProperty.cs @@ -23,13 +23,21 @@ public void LinkPropertyToNative(CSILinkProperty linkProperty, ref ApplicationOb // TODO: test if this works, because I don't think it will... var success1 = Model.PropLink.SetPDelta(linkProperty.name, ref value); - var success2 = Model.PropLink.SetWeightAndMass(linkProperty.name, linkProperty.weight, linkProperty.mass, linkProperty.rotationalInertia1, linkProperty.rotationalInertia2, linkProperty.rotationalInertia3); + var success2 = Model.PropLink.SetWeightAndMass( + linkProperty.name, + linkProperty.weight, + linkProperty.mass, + linkProperty.rotationalInertia1, + linkProperty.rotationalInertia2, + linkProperty.rotationalInertia3 + ); if (success1 == 0 && success2 == 0) appObj.Update(status: ApplicationObject.State.Created, createdId: $"{linkProperty.name}"); else appObj.Update(status: ApplicationObject.State.Failed); } + public CSILinkProperty LinkPropertyToSpeckle(string name) { double W = 0; @@ -44,4 +52,4 @@ public CSILinkProperty LinkPropertyToSpeckle(string name) return speckleLinkProp; } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertSectionProfile.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertSectionProfile.cs index d3c44e7b2f..15cef83339 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertSectionProfile.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertSectionProfile.cs @@ -16,7 +16,13 @@ public SectionProfile SectionToSpeckle(string property) string matProp = ""; string sectionPropertyName = ""; - int s = Model.PropFrame.GetNameInPropFile(property, ref sectionPropertyName, ref catalogue, ref matProp, ref propType); + int s = Model.PropFrame.GetNameInPropFile( + property, + ref sectionPropertyName, + ref catalogue, + ref matProp, + ref propType + ); GetSectionProfile(property, matProp, propType, ref speckleSectionProfile); @@ -108,7 +114,12 @@ public SectionProfile SectionToSpeckle(string property) #endregion } - public void GetSectionProfile(string property, string matProp, eFramePropType propType, ref SectionProfile speckleSectionProfile) + public void GetSectionProfile( + string property, + string matProp, + eFramePropType propType, + ref SectionProfile speckleSectionProfile + ) { double T3 = 0; double T2 = 0; @@ -127,15 +138,50 @@ public void GetSectionProfile(string property, string matProp, eFramePropType pr switch (propType) { case eFramePropType.I: - Model.PropFrame.GetISection(property, ref FileName, ref matProp, ref T3, ref T2, ref Tf, ref Tw, ref T2b, ref Tfb, ref color, ref notes, ref GUID); + Model.PropFrame.GetISection( + property, + ref FileName, + ref matProp, + ref T3, + ref T2, + ref Tf, + ref Tw, + ref T2b, + ref Tfb, + ref color, + ref notes, + ref GUID + ); speckleSectionProfile = new ISection(property, T3, T2, Tw, Tf); break; case eFramePropType.Rectangular: - Model.PropFrame.GetRectangle(property, ref FileName, ref matProp, ref T3, ref T2, ref color, ref notes, ref GUID); + Model.PropFrame.GetRectangle( + property, + ref FileName, + ref matProp, + ref T3, + ref T2, + ref color, + ref notes, + ref GUID + ); speckleSectionProfile = new Rectangular(property, T3, T2); break; case eFramePropType.ConcreteTee: - Model.PropFrame.GetConcreteTee(property, ref FileName, ref matProp, ref T3, ref T2, ref Tf, ref TwF, ref Twt, ref mirrorAbout3, ref color, ref notes, ref GUID); + Model.PropFrame.GetConcreteTee( + property, + ref FileName, + ref matProp, + ref T3, + ref T2, + ref Tf, + ref TwF, + ref Twt, + ref mirrorAbout3, + ref color, + ref notes, + ref GUID + ); speckleSectionProfile = new Tee(property, T3, T2, TwF, Tf); break; case eFramePropType.Circle: @@ -143,15 +189,48 @@ public void GetSectionProfile(string property, string matProp, eFramePropType pr speckleSectionProfile = new Circular(property, T3 / 2); break; case eFramePropType.Angle: - Model.PropFrame.GetAngle(property, ref FileName, ref matProp, ref T3, ref T2, ref Tf, ref Tw, ref color, ref notes, ref GUID); + Model.PropFrame.GetAngle( + property, + ref FileName, + ref matProp, + ref T3, + ref T2, + ref Tf, + ref Tw, + ref color, + ref notes, + ref GUID + ); speckleSectionProfile = new Angle(property, T3, T2, Tw, Tf); break; case eFramePropType.Channel: - Model.PropFrame.GetChannel(property, ref FileName, ref matProp, ref T3, ref T2, ref Tf, ref Tw, ref color, ref notes, ref GUID); + Model.PropFrame.GetChannel( + property, + ref FileName, + ref matProp, + ref T3, + ref T2, + ref Tf, + ref Tw, + ref color, + ref notes, + ref GUID + ); speckleSectionProfile = new Channel(property, T3, T2, Tw, Tf); break; case eFramePropType.Box: - Model.PropFrame.GetTube(property, ref FileName, ref matProp, ref T3, ref T2, ref Tf, ref Tw, ref color, ref notes, ref GUID); + Model.PropFrame.GetTube( + property, + ref FileName, + ref matProp, + ref T3, + ref T2, + ref Tf, + ref Tw, + ref color, + ref notes, + ref GUID + ); speckleSectionProfile = new Rectangular(property, T3, T2, Tw, Tf); break; case eFramePropType.Pipe: @@ -194,19 +273,34 @@ public void GetSectionProperties(string property, ref SectionProfile sectionProf // sectionProfile.J = Torsion; // sectionProfile.applicationId = GUID; // } - - var k = Model.PropFrame.GetSectProps(property, ref Area, ref As2, ref As3, ref Torsion, ref I22, ref I33, ref S22, ref S33, ref Z22, ref Z33, ref R22, ref R33); - if(k==0){ + + var k = Model.PropFrame.GetSectProps( + property, + ref Area, + ref As2, + ref As3, + ref Torsion, + ref I22, + ref I33, + ref S22, + ref S33, + ref Z22, + ref Z33, + ref R22, + ref R33 + ); + if (k == 0) + { sectionProfile.name = property; - sectionProfile.area = Area; - sectionProfile.Ky = (Area == 0 || As3 == 0) ? 0 : As3 / Area; - sectionProfile.Kz = (Area == 0 || As2 == 0) ? 0 : As2 / Area; - sectionProfile.Iyy = I33; - sectionProfile.Izz = I22; - sectionProfile.J = Torsion; + sectionProfile.area = Area; + sectionProfile.Ky = (Area == 0 || As3 == 0) ? 0 : As3 / Area; + sectionProfile.Kz = (Area == 0 || As2 == 0) ? 0 : As2 / Area; + sectionProfile.Iyy = I33; + sectionProfile.Izz = I22; + sectionProfile.J = Torsion; } //to be discussed whether radius of gyration and section mod/plastic mod is needed ~ i personally think so } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertSpring.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertSpring.cs index 638948cac4..b14837964c 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertSpring.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertSpring.cs @@ -24,7 +24,13 @@ public void SpringPropertyToNative(CSISpringProperty springProperty, ref Applica { case SpringOption.Link: var springOption = 1; - success = Model.PropPointSpring.SetPointSpringProp(springProperty.name, springOption, ref k, springProperty.CYs, iGUID: springProperty.applicationId); + success = Model.PropPointSpring.SetPointSpringProp( + springProperty.name, + springOption, + ref k, + springProperty.CYs, + iGUID: springProperty.applicationId + ); break; case SpringOption.SoilProfileFooting: springOption = 2; @@ -36,6 +42,7 @@ public void SpringPropertyToNative(CSISpringProperty springProperty, ref Applica else appObj.Update(status: ApplicationObject.State.Failed); } + public void LinearSpringPropertyToNative(CSILinearSpring linearSpringProperty, ref ApplicationObject appObj) { var linearOption1 = 0; @@ -64,13 +71,23 @@ public void LinearSpringPropertyToNative(CSILinearSpring linearSpringProperty, r linearOption2 = 2; break; } - var success = Model.PropLineSpring.SetLineSpringProp(linearSpringProperty.name, linearSpringProperty.stiffnessX, linearSpringProperty.stiffnessY, linearSpringProperty.stiffnessZ, linearSpringProperty.stiffnessXX, linearOption1, linearOption2, iGUID: linearSpringProperty.applicationId); + var success = Model.PropLineSpring.SetLineSpringProp( + linearSpringProperty.name, + linearSpringProperty.stiffnessX, + linearSpringProperty.stiffnessY, + linearSpringProperty.stiffnessZ, + linearSpringProperty.stiffnessXX, + linearOption1, + linearOption2, + iGUID: linearSpringProperty.applicationId + ); if (success == 0) appObj.Update(status: ApplicationObject.State.Created, createdId: linearSpringProperty.name); else appObj.Update(status: ApplicationObject.State.Failed); } + public void AreaSpringPropertyToNative(CSIAreaSpring areaSpring, ref ApplicationObject appObj) { var linearOption1 = 0; @@ -86,13 +103,21 @@ public void AreaSpringPropertyToNative(CSIAreaSpring areaSpring, ref Application linearOption1 = 2; break; } - var success = Model.PropAreaSpring.SetAreaSpringProp(areaSpring.name, areaSpring.stiffnessX, areaSpring.stiffnessY, areaSpring.stiffnessZ, linearOption1, iGUID: areaSpring.applicationId); + var success = Model.PropAreaSpring.SetAreaSpringProp( + areaSpring.name, + areaSpring.stiffnessX, + areaSpring.stiffnessY, + areaSpring.stiffnessZ, + linearOption1, + iGUID: areaSpring.applicationId + ); if (success == 0) appObj.Update(status: ApplicationObject.State.Created, createdId: areaSpring.name); else appObj.Update(status: ApplicationObject.State.Failed); } + public CSISpringProperty SpringPropertyToSpeckle(string name) { double[] stiffness = null; @@ -104,11 +129,31 @@ public CSISpringProperty SpringPropertyToSpeckle(string name) int color = 0; string notes = null; string GUID = null; - Model.PropPointSpring.GetPointSpringProp(name, ref springOption, ref stiffness, ref Cys, ref soilProfile, ref footing, ref period, ref color, ref notes, ref GUID); + Model.PropPointSpring.GetPointSpringProp( + name, + ref springOption, + ref stiffness, + ref Cys, + ref soilProfile, + ref footing, + ref period, + ref color, + ref notes, + ref GUID + ); switch (springOption) { case 1: - CSISpringProperty speckleSpringProperty = new CSISpringProperty(name, Cys, stiffness[0], stiffness[1], stiffness[2], stiffness[3], stiffness[4], stiffness[5]); + CSISpringProperty speckleSpringProperty = new CSISpringProperty( + name, + Cys, + stiffness[0], + stiffness[1], + stiffness[2], + stiffness[3], + stiffness[4], + stiffness[5] + ); speckleSpringProperty.applicationId = GUID; return speckleSpringProperty; case 2: @@ -120,6 +165,7 @@ public CSISpringProperty SpringPropertyToSpeckle(string name) return speckleSpringProperty; } } + public CSILinearSpring LinearSpringToSpeckle(string name) { double stiffnessX = 0; @@ -134,7 +180,18 @@ public CSILinearSpring LinearSpringToSpeckle(string name) NonLinearOptions nonLinearOptions1 = NonLinearOptions.Linear; NonLinearOptions nonLinearOptions2 = NonLinearOptions.Linear; - var s = Model.PropLineSpring.GetLineSpringProp(name, ref stiffnessX, ref stiffnessY, ref stiffnessZ, ref stiffnessXX, ref nonLinearOpt1, ref nonLinearOpt2, ref color, ref notes, ref GUID); + var s = Model.PropLineSpring.GetLineSpringProp( + name, + ref stiffnessX, + ref stiffnessY, + ref stiffnessZ, + ref stiffnessXX, + ref nonLinearOpt1, + ref nonLinearOpt2, + ref color, + ref notes, + ref GUID + ); switch (nonLinearOpt1) { case 0: @@ -162,15 +219,23 @@ public CSILinearSpring LinearSpringToSpeckle(string name) if (s == 0) { - CSILinearSpring speckleLinearSpring = new CSILinearSpring(name, stiffnessX, stiffnessY, stiffnessZ, stiffnessXX, nonLinearOptions1, nonLinearOptions2, GUID); + CSILinearSpring speckleLinearSpring = new CSILinearSpring( + name, + stiffnessX, + stiffnessY, + stiffnessZ, + stiffnessXX, + nonLinearOptions1, + nonLinearOptions2, + GUID + ); return speckleLinearSpring; } return null; - } + public CSIAreaSpring AreaSpringToSpeckle(string name) { - double stiffnessX = 0; double stiffnessY = 0; double stiffnessZ = 0; @@ -186,7 +251,20 @@ public CSIAreaSpring AreaSpringToSpeckle(string name) string GUID = null; NonLinearOptions nonLinearOptions1 = NonLinearOptions.Linear; - var s = Model.PropAreaSpring.GetAreaSpringProp(name, ref stiffnessX, ref stiffnessY, ref stiffnessZ, ref nonLinearOpt1, ref springOption, ref soilProfile, ref endLengthRatio, ref period, ref color, ref notes, ref GUID); + var s = Model.PropAreaSpring.GetAreaSpringProp( + name, + ref stiffnessX, + ref stiffnessY, + ref stiffnessZ, + ref nonLinearOpt1, + ref springOption, + ref soilProfile, + ref endLengthRatio, + ref period, + ref color, + ref notes, + ref GUID + ); switch (nonLinearOpt1) { case 0: @@ -202,11 +280,17 @@ public CSIAreaSpring AreaSpringToSpeckle(string name) if (s == 0) { - CSIAreaSpring speckleAreaSpring = new CSIAreaSpring(name, stiffnessX, stiffnessY, stiffnessZ, nonLinearOptions1, GUID); + CSIAreaSpring speckleAreaSpring = new CSIAreaSpring( + name, + stiffnessX, + stiffnessY, + stiffnessZ, + nonLinearOptions1, + GUID + ); return speckleAreaSpring; } return null; - } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertTendonProperty.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertTendonProperty.cs index b0b4f3812a..70fa93d6a2 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertTendonProperty.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/ConvertTendonProperty.cs @@ -27,10 +27,11 @@ public CSITendonProperty TendonPropToSpeckle(string name) { specklePropertyTendon.modelingOption = ModelingOption.Loads; } - else { specklePropertyTendon.modelingOption = ModelingOption.Elements; } + else + { + specklePropertyTendon.modelingOption = ModelingOption.Elements; + } return specklePropertyTendon; - } - } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultGlobal.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultGlobal.cs index 83d60adf9a..a7b86a4556 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultGlobal.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultGlobal.cs @@ -23,7 +23,16 @@ public ResultGlobal ResultGlobal() double[] frequency = null; double[] circFreq = null; double[] eigenValue = null; - var s = Model.Results.ModalPeriod(ref numberResult, ref loadcase, ref stepType, ref stepNum, ref period, ref frequency, ref circFreq, ref eigenValue); + var s = Model.Results.ModalPeriod( + ref numberResult, + ref loadcase, + ref stepType, + ref stepNum, + ref period, + ref frequency, + ref circFreq, + ref eigenValue + ); double[] UX = null; double[] UY = null; @@ -34,7 +43,21 @@ public ResultGlobal ResultGlobal() double[] ModalMass = null; double[] ModalStiff = null; - var i = Model.Results.ModalParticipationFactors(ref numberResult, ref loadcase, ref stepType, ref stepNum, ref period, ref UX, ref UY, ref UZ, ref RX, ref RY, ref RZ, ref ModalMass, ref ModalStiff); + var i = Model.Results.ModalParticipationFactors( + ref numberResult, + ref loadcase, + ref stepType, + ref stepNum, + ref period, + ref UX, + ref UY, + ref UZ, + ref RX, + ref RY, + ref RZ, + ref ModalMass, + ref ModalStiff + ); if (s == 0 && i == 0) { @@ -45,19 +68,21 @@ public ResultGlobal ResultGlobal() speckleResultGlobal.reactionXX = (float)RX[0]; speckleResultGlobal.reactionYY = (float)RY[0]; speckleResultGlobal.reactionZZ = (float)RZ[0]; - speckleResultGlobal.effMassX = speckleResultGlobal.effMassXX = speckleResultGlobal.effMassY = speckleResultGlobal.effMassYY = speckleResultGlobal.effMassZ = speckleResultGlobal.effMassZZ = (float)ModalMass[0]; + speckleResultGlobal.effMassX = + speckleResultGlobal.effMassXX = + speckleResultGlobal.effMassY = + speckleResultGlobal.effMassYY = + speckleResultGlobal.effMassZ = + speckleResultGlobal.effMassZZ = + (float)ModalMass[0]; speckleResultGlobal.mode = (float)stepNum[0]; speckleResultGlobal.frequency = (float)frequency[0]; } } - catch - { - - } - + catch { } return speckleResultGlobal; } } -} \ No newline at end of file +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultNodes.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultNodes.cs index 7f7a94ec0a..d4fe2201a1 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultNodes.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultNodes.cs @@ -67,8 +67,38 @@ public void ResultNodeToSpeckle(string pointName, ResultSetNode resultSetNode) int numberGroundResults = 0; string[] loadCasesGround = null; - Model.Results.JointReact(pointName, eItemTypeElm.Element, ref numberResults, ref obj, ref elm, ref loadCases, ref stepType, ref stepNum, ref F1, ref F2, ref F3, ref M1, ref M2, ref M3); - Model.Results.JointDispl(pointName, eItemTypeElm.Element, ref numberResults, ref obj, ref elm, ref loadCases, ref stepType, ref stepNum, ref U1, ref U2, ref U3, ref R1, ref R2, ref R3); + Model.Results.JointReact( + pointName, + eItemTypeElm.Element, + ref numberResults, + ref obj, + ref elm, + ref loadCases, + ref stepType, + ref stepNum, + ref F1, + ref F2, + ref F3, + ref M1, + ref M2, + ref M3 + ); + Model.Results.JointDispl( + pointName, + eItemTypeElm.Element, + ref numberResults, + ref obj, + ref elm, + ref loadCases, + ref stepType, + ref stepNum, + ref U1, + ref U2, + ref U3, + ref R1, + ref R2, + ref R3 + ); foreach (int index in Enumerable.Range(0, numberResults)) { @@ -90,12 +120,40 @@ public void ResultNodeToSpeckle(string pointName, ResultSetNode resultSetNode) speckleResultNode.resultCase = LoadPatternCaseToSpeckle(loadCases[index]); resultSetNode.resultsNode.Add(speckleResultNode); - } - - var s = Model.Results.JointVelAbs(pointName, eItemTypeElm.Element, ref numberGroundResults, ref obj, ref elm, ref loadCasesGround, ref stepType, ref stepNum, ref U1Vel, ref U2Vel, ref U3Vel, ref R1Vel, ref R2Vel, ref R3Vel); - var z = Model.Results.JointAccAbs(pointName, eItemTypeElm.Element, ref numberGroundResults, ref obj, ref elm, ref loadCasesGround, ref stepType, ref stepNum, ref U1Acc, ref U2Acc, ref U3Acc, ref R1Acc, ref R2Acc, ref R3Acc); + var s = Model.Results.JointVelAbs( + pointName, + eItemTypeElm.Element, + ref numberGroundResults, + ref obj, + ref elm, + ref loadCasesGround, + ref stepType, + ref stepNum, + ref U1Vel, + ref U2Vel, + ref U3Vel, + ref R1Vel, + ref R2Vel, + ref R3Vel + ); + var z = Model.Results.JointAccAbs( + pointName, + eItemTypeElm.Element, + ref numberGroundResults, + ref obj, + ref elm, + ref loadCasesGround, + ref stepType, + ref stepNum, + ref U1Acc, + ref U2Acc, + ref U3Acc, + ref R1Acc, + ref R2Acc, + ref R3Acc + ); if (s == 0 && z == 0) { foreach (int index in Enumerable.Range(0, numberGroundResults)) @@ -118,7 +176,6 @@ public void ResultNodeToSpeckle(string pointName, ResultSetNode resultSetNode) speckleResultNode.resultCase = LoadPatternCaseToSpeckle(loadCases[index]); resultSetNode.resultsNode.Add(speckleResultNode); - } } diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultSet1D.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultSet1D.cs index a148a9bf33..f101d34a06 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultSet1D.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultSet1D.cs @@ -11,7 +11,11 @@ namespace Objects.Converter.CSI { public partial class ConverterCSI { - public ResultSet1D AllResultSet1dToSpeckle(List frameNames, List pierNames, List spandrelNames) + public ResultSet1D AllResultSet1dToSpeckle( + List frameNames, + List pierNames, + List spandrelNames + ) { ResultSet1D frameResults = new ResultSet1D(); ResultSet1D pierResults = new ResultSet1D(); @@ -53,7 +57,9 @@ public ResultSet1D FrameResultSet1dToSpeckle(string elementName) { List results = new List(); - var element = SpeckleModel.elements.Where(o => (string)o["name"] == elementName && o is Element1D).FirstOrDefault() as Element1D; + var element = + SpeckleModel.elements.Where(o => (string)o["name"] == elementName && o is Element1D).FirstOrDefault() + as Element1D; // if the element is null, then it was not part of the user's selection, so don't send its results if (element == null) @@ -63,12 +69,40 @@ public ResultSet1D FrameResultSet1dToSpeckle(string elementName) // Reference variables for CSI API int numberOfResults = 0; - string[] obj, elm, loadCase, stepType; + string[] obj, + elm, + loadCase, + stepType; obj = elm = loadCase = stepType = new string[1]; - double[] objSta, elmSta, stepNum, p, v2, v3, t, m2, m3; + double[] objSta, + elmSta, + stepNum, + p, + v2, + v3, + t, + m2, + m3; objSta = elmSta = stepNum = p = v2 = v3 = t = m2 = m3 = new double[1]; - Model.Results.FrameForce(elementName, eItemTypeElm.ObjectElm, ref numberOfResults, ref obj, ref objSta, ref elm, ref elmSta, ref loadCase, ref stepType, ref stepNum, ref p, ref v2, ref v3, ref t, ref m2, ref m3); + Model.Results.FrameForce( + elementName, + eItemTypeElm.ObjectElm, + ref numberOfResults, + ref obj, + ref objSta, + ref elm, + ref elmSta, + ref loadCase, + ref stepType, + ref stepNum, + ref p, + ref v2, + ref v3, + ref t, + ref m2, + ref m3 + ); // Value used to normalized output station of forces between 0 and 1 var lengthOf1dElement = objSta.Max(); @@ -107,9 +141,6 @@ public ResultSet1D FrameResultSet1dToSpeckle(string elementName) } return new ResultSet1D() { results1D = results }; - - - } public ResultSet1D PierResultSet1dToSpeckle(string elementName) @@ -120,12 +151,32 @@ public ResultSet1D PierResultSet1dToSpeckle(string elementName) // Reference variables for CSI API int numberOfResults = 0; - string[] storyName, pierName, loadCase, location; + string[] storyName, + pierName, + loadCase, + location; storyName = pierName = loadCase = location = new string[1]; - double[] p, v2, v3, t, m2, m3; + double[] p, + v2, + v3, + t, + m2, + m3; p = v2 = v3 = t = m2 = m3 = new double[1]; - Model.Results.PierForce(ref numberOfResults, ref storyName, ref pierName, ref loadCase, ref location, ref p, ref v2, ref v3, ref t, ref m2, ref m3); + Model.Results.PierForce( + ref numberOfResults, + ref storyName, + ref pierName, + ref loadCase, + ref location, + ref p, + ref v2, + ref v3, + ref t, + ref m2, + ref m3 + ); for (int i = 0; i < numberOfResults; i++) { @@ -165,9 +216,6 @@ public ResultSet1D PierResultSet1dToSpeckle(string elementName) } return new ResultSet1D() { results1D = results }; - - - } public ResultSet1D SpandrelResultSet1dToSpeckle(string elementName) @@ -178,12 +226,32 @@ public ResultSet1D SpandrelResultSet1dToSpeckle(string elementName) // Reference variables for CSI API int numberOfResults = 0; - string[] storyName, spandrelName, loadCase, location; + string[] storyName, + spandrelName, + loadCase, + location; storyName = spandrelName = loadCase = location = new string[1]; - double[] p, v2, v3, t, m2, m3; + double[] p, + v2, + v3, + t, + m2, + m3; p = v2 = v3 = t = m2 = m3 = new double[1]; - Model.Results.SpandrelForce(ref numberOfResults, ref storyName, ref spandrelName, ref loadCase, ref location, ref p, ref v2, ref v3, ref t, ref m2, ref m3); + Model.Results.SpandrelForce( + ref numberOfResults, + ref storyName, + ref spandrelName, + ref loadCase, + ref location, + ref p, + ref v2, + ref v3, + ref t, + ref m2, + ref m3 + ); for (int i = 0; i < numberOfResults; i++) { @@ -223,9 +291,6 @@ public ResultSet1D SpandrelResultSet1dToSpeckle(string elementName) } return new ResultSet1D() { results1D = results }; - - - } public void SetLoadCombinationsForResults() diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultSet2D.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultSet2D.cs index 85fdb4c433..7551707d2a 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultSet2D.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResultSet2D.cs @@ -15,68 +15,207 @@ public ResultSet2D AreaResultSet2dToSpeckle(List areaNames) foreach (var areaName in areaNames) { - var element = SpeckleModel.elements.Where(o => (string)o["name"] == areaName && o is Element2D).FirstOrDefault() as Element2D; + var element = + SpeckleModel.elements.Where(o => (string)o["name"] == areaName && o is Element2D).FirstOrDefault() + as Element2D; // if the element is null, then it was not part of the user's selection, so don't send its results if (element == null) continue; #region Return force results int numberOfForceResults = 0; - string[] obj, elm, pointElm, loadCase, stepType; - double[] stepNum, f11, f22, f12, fMax, fMin, fAngle, fVonMises, m11, m22, m12, mMax, mMin, mAngle, v13, v23, vMax, vAngle; + string[] obj, + elm, + pointElm, + loadCase, + stepType; + double[] stepNum, + f11, + f22, + f12, + fMax, + fMin, + fAngle, + fVonMises, + m11, + m22, + m12, + mMax, + mMin, + mAngle, + v13, + v23, + vMax, + vAngle; obj = elm = pointElm = loadCase = stepType = new string[] { }; - stepNum = f11 = f22 = f12 = fMax = fMin = fAngle = fVonMises = m11 = m22 = m12 = mMax = mMin = mAngle = v13 = v23 = vMax = vAngle = new double[] { }; + stepNum = + f11 = + f22 = + f12 = + fMax = + fMin = + fAngle = + fVonMises = + m11 = + m22 = + m12 = + mMax = + mMin = + mAngle = + v13 = + v23 = + vMax = + vAngle = + new double[] { }; - Model.Results.AreaForceShell(areaName, CSiAPIv1.eItemTypeElm.ObjectElm, ref numberOfForceResults, ref obj, ref elm, ref pointElm, ref loadCase, ref stepType, ref stepNum, ref f11, ref f22, ref f12, ref fMax, ref fMin, ref fAngle, ref fVonMises, ref m11, ref m22, ref m12, ref mMax, ref mMin, ref mAngle, ref v13, ref v23, ref vMax, ref vAngle); + Model.Results.AreaForceShell( + areaName, + CSiAPIv1.eItemTypeElm.ObjectElm, + ref numberOfForceResults, + ref obj, + ref elm, + ref pointElm, + ref loadCase, + ref stepType, + ref stepNum, + ref f11, + ref f22, + ref f12, + ref fMax, + ref fMin, + ref fAngle, + ref fVonMises, + ref m11, + ref m22, + ref m12, + ref mMax, + ref mMin, + ref mAngle, + ref v13, + ref v23, + ref vMax, + ref vAngle + ); #endregion #region Return stress results int numberOfStressResults = 0; - string[] stressObj, stressElm, stressPointElm, stressLoadCase, stressStepType; - double[] stressStepNum, S11Top, S22Top, S12Top, SMaxTop, SMinTop, SAngleTop, sVonMisesTop, S11Bot, S22Bot, S12Bot, SMaxBot, SMinBot, SAngleBot, sVonMisesBot, S13Avg, S23Avg, SMaxAvg, SAngleAvg; + string[] stressObj, + stressElm, + stressPointElm, + stressLoadCase, + stressStepType; + double[] stressStepNum, + S11Top, + S22Top, + S12Top, + SMaxTop, + SMinTop, + SAngleTop, + sVonMisesTop, + S11Bot, + S22Bot, + S12Bot, + SMaxBot, + SMinBot, + SAngleBot, + sVonMisesBot, + S13Avg, + S23Avg, + SMaxAvg, + SAngleAvg; stressObj = stressElm = stressPointElm = stressLoadCase = stressStepType = new string[] { }; - stressStepNum = S11Top = S22Top = S12Top = SMaxTop = SMinTop = SAngleTop = sVonMisesTop = S11Bot = S22Bot = S12Bot = SMaxBot = SMinBot = SAngleBot = sVonMisesBot = S13Avg = S23Avg = SMaxAvg = SAngleAvg = new double[] { }; + stressStepNum = + S11Top = + S22Top = + S12Top = + SMaxTop = + SMinTop = + SAngleTop = + sVonMisesTop = + S11Bot = + S22Bot = + S12Bot = + SMaxBot = + SMinBot = + SAngleBot = + sVonMisesBot = + S13Avg = + S23Avg = + SMaxAvg = + SAngleAvg = + new double[] { }; - Model.Results.AreaStressShell(areaName, CSiAPIv1.eItemTypeElm.ObjectElm, ref numberOfStressResults, ref stressObj, ref stressElm, ref stressPointElm, ref stressLoadCase, ref stressStepType, ref stressStepNum, ref S11Top, ref S22Top, ref S12Top, ref SMaxTop, ref SMinTop, ref SAngleTop, ref sVonMisesTop, ref S11Bot, ref S22Bot, ref S12Bot, ref SMaxBot, ref SMinBot, ref SAngleBot, ref sVonMisesBot, ref S13Avg, ref S23Avg, ref SMaxAvg, ref SAngleAvg); + Model.Results.AreaStressShell( + areaName, + CSiAPIv1.eItemTypeElm.ObjectElm, + ref numberOfStressResults, + ref stressObj, + ref stressElm, + ref stressPointElm, + ref stressLoadCase, + ref stressStepType, + ref stressStepNum, + ref S11Top, + ref S22Top, + ref S12Top, + ref SMaxTop, + ref SMinTop, + ref SAngleTop, + ref sVonMisesTop, + ref S11Bot, + ref S22Bot, + ref S12Bot, + ref SMaxBot, + ref SMinBot, + ref SAngleBot, + ref sVonMisesBot, + ref S13Avg, + ref S23Avg, + ref SMaxAvg, + ref SAngleAvg + ); #endregion for (int i = 0; i < numberOfForceResults; i++) { - results.Add(new Result2D - { - element = element, //AreaToSpeckle(areaName), - permutation = loadCase[i], - position = new List(), - dispX = 0, // pulling this data would require large amount of data parsing, implementation TBD - dispY = 0, // pulling this data would require large amount of data parsing, implementation TBD - dispZ = 0, // pulling this data would require large amount of data parsing, implementation TBD - forceXX = (float)f11[i], - forceYY = (float)f22[i], - forceXY = (float)f12[i], - momentXX = (float)m11[i], - momentYY = (float)m22[i], - momentXY = (float)m12[i], - shearX = (float)v13[i], - shearY = (float)v23[i], - stressTopXX = (float)S11Top[i], - stressTopYY = (float)S22Top[i], - stressTopZZ = 0, // shell elements are 2D elements - stressTopXY = (float)S12Top[i], - stressTopYZ = (float)S23Avg[i], // CSI reports avg out-of-plane shear - stressTopZX = (float)S12Top[i], - stressMidXX = 0, // CSI does not report - stressMidYY = 0, // CSI does not report - stressMidZZ = 0, // CSI does not report - stressMidXY = 0, // CSI does not report - stressMidYZ = 0, // CSI does not report - stressMidZX = 0, // CSI does not report - stressBotXX = (float)S11Bot[i], - stressBotYY = (float)S22Bot[i], - stressBotZZ = 0, // shell elements are 2D elements - stressBotXY = (float)S12Bot[i], - stressBotYZ = (float)S23Avg[i], // CSI reports avg out-of-plane shear - stressBotZX = (float)S12Bot[i], - }); + results.Add( + new Result2D + { + element = element, //AreaToSpeckle(areaName), + permutation = loadCase[i], + position = new List(), + dispX = 0, // pulling this data would require large amount of data parsing, implementation TBD + dispY = 0, // pulling this data would require large amount of data parsing, implementation TBD + dispZ = 0, // pulling this data would require large amount of data parsing, implementation TBD + forceXX = (float)f11[i], + forceYY = (float)f22[i], + forceXY = (float)f12[i], + momentXX = (float)m11[i], + momentYY = (float)m22[i], + momentXY = (float)m12[i], + shearX = (float)v13[i], + shearY = (float)v23[i], + stressTopXX = (float)S11Top[i], + stressTopYY = (float)S22Top[i], + stressTopZZ = 0, // shell elements are 2D elements + stressTopXY = (float)S12Top[i], + stressTopYZ = (float)S23Avg[i], // CSI reports avg out-of-plane shear + stressTopZX = (float)S12Top[i], + stressMidXX = 0, // CSI does not report + stressMidYY = 0, // CSI does not report + stressMidZZ = 0, // CSI does not report + stressMidXY = 0, // CSI does not report + stressMidYZ = 0, // CSI does not report + stressMidZX = 0, // CSI does not report + stressBotXX = (float)S11Bot[i], + stressBotYY = (float)S22Bot[i], + stressBotZZ = 0, // shell elements are 2D elements + stressBotXY = (float)S12Bot[i], + stressBotYZ = (float)S23Avg[i], // CSI reports avg out-of-plane shear + stressBotZX = (float)S12Bot[i], + } + ); } } diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResults.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResults.cs index 9a6fd798bb..bb4e9ba648 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResults.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Results/ConvertResults.cs @@ -26,7 +26,8 @@ public Base ResultsToSpeckle() if (!sendNodeResults && !send1DResults && !send2DResults) { var resultsAll = new Base(); - resultsAll["Data"] = "Did not send any analytical results to Speckle. To send results, change the settings in the \"Advanced Settings\" tab"; + resultsAll["Data"] = + "Did not send any analytical results to Speckle. To send results, change the settings in the \"Advanced Settings\" tab"; return resultsAll; } @@ -58,7 +59,6 @@ public Base ResultsToSpeckle() Model.SpandrelLabel.GetNameList(ref numberOfSpandrelNames, ref spandrelNames, ref isMultiStory); List convertedSpandrelNames = spandrelNames.ToList(); - #endregion #region Retrieve area names @@ -73,7 +73,9 @@ public Base ResultsToSpeckle() #endregion var resultsNode = sendNodeResults ? AllResultSetNodesToSpeckle() : null; - var results1D = send1DResults ? AllResultSet1dToSpeckle(convertedFrameNames, convertedPierNames, convertedSpandrelNames) : null; + var results1D = send1DResults + ? AllResultSet1dToSpeckle(convertedFrameNames, convertedPierNames, convertedSpandrelNames) + : null; var results2D = send2DResults ? AreaResultSet2dToSpeckle(convertedAreaNames) : null; var results = new ResultSetAll(results1D, results2D, new ResultSet3D(), new ResultGlobal(), resultsNode); @@ -81,5 +83,4 @@ public Base ResultsToSpeckle() return results; } } - } From aa9587cea443e0439b075440858fda4448c1dc34 Mon Sep 17 00:00:00 2001 From: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com> Date: Thu, 21 Sep 2023 11:52:57 +0100 Subject: [PATCH 02/49] chore(core): Make client functions consistent with cancellation token position (#2925) * chore(core): Deprecated client functions that take cancellation token last * Changed usages to non-deprecated overload --- .../ConnectorDynamoFunctions/Functions.cs | 126 ++++---- .../Deprecated/Operations.ReceiveComponent.cs | 4 +- .../Operations.ReceiveComponentSync.cs | 2 +- .../Deprecated/Operations.SendComponent.cs | 2 +- .../Operations.SendComponentSync.cs | 2 +- .../Operations.VariableInputSendComponent.cs | 2 +- .../Ops/Operations.SyncReceiveComponent.cs | 2 +- .../Ops/Operations.SyncSendComponent.cs | 2 +- ...perations.VariableInputReceiveComponent.cs | 10 +- .../Operations.VariableInputSendComponent.cs | 2 +- .../Streams/StreamCreateComponentV2.cs | 2 +- .../Streams/StreamListComponentV2.cs | 2 +- .../Client.ActivityOperations.cs | 29 +- .../Client.BranchOperations.cs | 73 +---- .../Client.CommentOperations.cs | 38 +-- .../Client.CommitOperations.cs | 82 ++---- .../Client.ObjectOperations.cs | 36 +-- .../Client.ObsoleteOperations.cs | 270 ++++++++++++++++++ .../Client.ServerOperations.cs | 1 - .../Client.StreamOperations.cs | 207 +++----------- .../Client.UserOperations.cs | 43 +-- Core/Core/Api/GraphQL/Client.cs | 2 +- Core/Core/Api/GraphQL/Models.cs | 6 +- DesktopUI2/DesktopUI2/ConnectorHelpers.cs | 26 +- .../DesktopUI2/ViewModels/HomeViewModel.cs | 6 +- .../ViewModels/StreamSelectorViewModel.cs | 4 +- 26 files changed, 471 insertions(+), 510 deletions(-) create mode 100644 Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ObsoleteOperations.cs diff --git a/ConnectorDynamo/ConnectorDynamoFunctions/Functions.cs b/ConnectorDynamo/ConnectorDynamoFunctions/Functions.cs index d735ccc9d3..e8070350b2 100644 --- a/ConnectorDynamo/ConnectorDynamoFunctions/Functions.cs +++ b/ConnectorDynamo/ConnectorDynamoFunctions/Functions.cs @@ -23,17 +23,21 @@ namespace Speckle.ConnectorDynamo.Functions [IsVisibleInDynamoLibrary(false)] public static class Functions { - - /// /// Sends data to a Speckle Server by creating a commit on the master branch of a Stream /// /// Data to send /// Transports to send the data to /// Log - public static List Send(Base data, List transports, CancellationToken cancellationToken, - Dictionary branchNames = null, string message = "", - Action> onProgressAction = null, Action onErrorAction = null) + public static List Send( + Base data, + List transports, + CancellationToken cancellationToken, + Dictionary branchNames = null, + string message = "", + Action> onProgressAction = null, + Action onErrorAction = null + ) { var commitWrappers = new List(); var responses = new List(); @@ -54,9 +58,9 @@ public static List Send(Base data, List transports, Cancella message = $"Sent {totalCount} object{plural} from Dynamo"; } - - var objectId = Operations.Send(data, cancellationToken, new List(transports), true, - onProgressAction, onErrorAction).Result; + var objectId = Operations + .Send(data, cancellationToken, new List(transports), true, onProgressAction, onErrorAction) + .Result; if (cancellationToken.IsCancellationRequested) return null; @@ -73,23 +77,30 @@ public static List Send(Base data, List transports, Cancella var client = new Client(serverTransport.Account); try { - var res = client.CommitCreate(cancellationToken, - new CommitCreateInput - { - streamId = serverTransport.StreamId, - branchName = branchName, - objectId = objectId, - message = message, - sourceApplication = Utils.GetAppName(), - parents = new List { serverTransport.StreamId } - }).Result; + var res = client + .CommitCreate( + new CommitCreateInput + { + streamId = serverTransport.StreamId, + branchName = branchName, + objectId = objectId, + message = message, + sourceApplication = Utils.GetAppName(), + parents = new List { serverTransport.StreamId } + }, + cancellationToken + ) + .Result; responses.Add(res); - var wrapper = - new StreamWrapper(serverTransport.StreamId, serverTransport.Account.userInfo.id, serverTransport.BaseUri) - { - CommitId = res - }; + var wrapper = new StreamWrapper( + serverTransport.StreamId, + serverTransport.Account.userInfo.id, + serverTransport.BaseUri + ) + { + CommitId = res + }; commitWrappers.Add(wrapper.ToString()); Analytics.TrackEvent(client.Account, Analytics.Events.Send); } @@ -98,7 +109,6 @@ public static List Send(Base data, List transports, Cancella Utils.HandleApiExeption(ex); return null; } - } return commitWrappers; @@ -119,9 +129,13 @@ public static object SendData(string output) /// Stream to receive from /// [MultiReturn(new[] { "data", "commit" })] - public static Dictionary Receive(StreamWrapper stream, CancellationToken cancellationToken, - Action> onProgressAction = null, Action onErrorAction = null, - Action onTotalChildrenCountKnown = null) + public static Dictionary Receive( + StreamWrapper stream, + CancellationToken cancellationToken, + Action> onProgressAction = null, + Action onErrorAction = null, + Action onTotalChildrenCountKnown = null + ) { var account = stream.GetAccount().Result; // @@ -135,7 +149,7 @@ public static Dictionary Receive(StreamWrapper stream, Cancellat try { - var branch = client.BranchGet(cancellationToken, stream.StreamId, stream.BranchName, 1).Result; + var branch = client.BranchGet(stream.StreamId, stream.BranchName, 1, cancellationToken).Result; if (!branch.commits.items.Any()) { throw new SpeckleException("No commits found."); @@ -152,7 +166,7 @@ public static Dictionary Receive(StreamWrapper stream, Cancellat { try { - commit = client.CommitGet(cancellationToken, stream.StreamId, stream.CommitId).Result; + commit = client.CommitGet(stream.StreamId, stream.CommitId!, cancellationToken).Result; } catch (Exception ex) { @@ -175,15 +189,17 @@ public static Dictionary Receive(StreamWrapper stream, Cancellat var transport = new ServerTransport(account, stream.StreamId); - var @base = Operations.Receive( - commit.referencedObject, - cancellationToken, - remoteTransport: transport, - onProgressAction: onProgressAction, - onErrorAction: ((s, exception) => throw exception), - onTotalChildrenCountKnown: onTotalChildrenCountKnown, - disposeTransports: true - ).Result; + var @base = Operations + .Receive( + commit.referencedObject, + cancellationToken, + remoteTransport: transport, + onProgressAction: onProgressAction, + onErrorAction: ((s, exception) => throw exception), + onTotalChildrenCountKnown: onTotalChildrenCountKnown, + disposeTransports: true + ) + .Result; if (@base == null) { @@ -191,13 +207,17 @@ public static Dictionary Receive(StreamWrapper stream, Cancellat } try { - client.CommitReceived(new CommitReceivedInput - { - streamId = stream.StreamId, - commitId = commit?.id, - message = commit?.message, - sourceApplication = HostApplications.Dynamo.GetVersion(HostAppVersion.vRevit) - }).Wait(); + client + .CommitReceived( + new CommitReceivedInput + { + streamId = stream.StreamId, + commitId = commit?.id, + message = commit?.message, + sourceApplication = HostApplications.Dynamo.GetVersion(HostAppVersion.vRevit) + } + ) + .Wait(); } catch { @@ -212,12 +232,16 @@ public static Dictionary Receive(StreamWrapper stream, Cancellat var data = converter.ConvertRecursivelyToNative(@base); - Analytics.TrackEvent(client.Account, Analytics.Events.Receive, new Dictionary() - { - { "sourceHostApp", HostApplications.GetHostAppFromString(commit.sourceApplication)?.Slug }, - { "sourceHostAppVersion", commit.sourceApplication }, - { "isMultiplayer", commit.authorId != client.Account.userInfo.id } - }); + Analytics.TrackEvent( + client.Account, + Analytics.Events.Receive, + new Dictionary() + { + { "sourceHostApp", HostApplications.GetHostAppFromString(commit.sourceApplication)?.Slug }, + { "sourceHostAppVersion", commit.sourceApplication }, + { "isMultiplayer", commit.authorId != client.Account.userInfo.id } + } + ); return new Dictionary { { "data", data }, { "commit", commit } }; } diff --git a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.ReceiveComponent.cs b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.ReceiveComponent.cs index 9f03876eaf..25e24c2a4b 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.ReceiveComponent.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.ReceiveComponent.cs @@ -91,7 +91,7 @@ public override void DocumentContextChanged(GH_Document document, GH_DocumentCon // Get last commit from the branch var b = ApiClient - .BranchGet(BaseWorker.CancellationToken, StreamWrapper.StreamId, StreamWrapper.BranchName ?? "main", 1) + .BranchGet(StreamWrapper.StreamId, StreamWrapper.BranchName ?? "main", 1, BaseWorker.CancellationToken) .Result; // Compare commit id's. If they don't match, notify user or fetch data if in auto mode @@ -619,7 +619,7 @@ CancellationToken CancellationToken case StreamWrapperType.Commit: try { - myCommit = await client.CommitGet(CancellationToken, InputWrapper.StreamId, InputWrapper.CommitId); + myCommit = await client.CommitGet(InputWrapper.StreamId, InputWrapper.CommitId, CancellationToken); return myCommit; } catch (Exception e) diff --git a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.ReceiveComponentSync.cs b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.ReceiveComponentSync.cs index 5db3a7d3de..75d81f888f 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.ReceiveComponentSync.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.ReceiveComponentSync.cs @@ -84,7 +84,7 @@ public override void DocumentContextChanged(GH_Document document, GH_DocumentCon // Get last commit from the branch var b = ApiClient - .BranchGet(source.Token, StreamWrapper.StreamId, StreamWrapper.BranchName ?? "main", 1) + .BranchGet(StreamWrapper.StreamId, StreamWrapper.BranchName ?? "main", 1, source.Token) .Result; // Compare commit id's. If they don't match, notify user or fetch data if in auto mode diff --git a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.SendComponent.cs b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.SendComponent.cs index fd608e7513..82bd9d0f51 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.SendComponent.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.SendComponent.cs @@ -542,7 +542,7 @@ public override void DoWork(Action ReportProgress, Action Done) if (prevCommit != null) commitCreateInput.parents = new List { prevCommit.CommitId }; - var commitId = await client.CommitCreate(CancellationToken, commitCreateInput); + var commitId = await client.CommitCreate(commitCreateInput, CancellationToken); var wrapper = new StreamWrapper( $"{client.Account.serverInfo.url}/streams/{((ServerTransport)transport).StreamId}/commits/{commitId}?u={client.Account.userInfo.id}" diff --git a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.SendComponentSync.cs b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.SendComponentSync.cs index 4183c3a72a..0a847c1fcf 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.SendComponentSync.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.SendComponentSync.cs @@ -425,7 +425,7 @@ public override void SolveInstanceWithLogContext(IGH_DataAccess DA) if (prevCommit != null) commitCreateInput.parents = new List { prevCommit.CommitId }; - var commitId = await client.CommitCreate(source.Token, commitCreateInput); + var commitId = await client.CommitCreate(commitCreateInput, source.Token); var wrapper = new StreamWrapper( $"{client.Account.serverInfo.url}/streams/{((ServerTransport)transport).StreamId}/commits/{commitId}?u={client.Account.userInfo.id}" diff --git a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.VariableInputSendComponent.cs b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.VariableInputSendComponent.cs index ab2d0bc5a3..8dd8cc025e 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.VariableInputSendComponent.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Deprecated/Operations.VariableInputSendComponent.cs @@ -616,7 +616,7 @@ public override void DoWork(Action ReportProgress, Action Done) if (prevCommit != null) commitCreateInput.parents = new List { prevCommit.CommitId }; - var commitId = await client.CommitCreate(CancellationToken, commitCreateInput); + var commitId = await client.CommitCreate(commitCreateInput, CancellationToken); var wrapper = new StreamWrapper( $"{client.Account.serverInfo.url}/streams/{((ServerTransport)transport).StreamId}/commits/{commitId}?u={client.Account.userInfo.id}" diff --git a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.SyncReceiveComponent.cs b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.SyncReceiveComponent.cs index 4c3ab5dd19..67fecfcb80 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.SyncReceiveComponent.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.SyncReceiveComponent.cs @@ -58,7 +58,7 @@ public override void DocumentContextChanged(GH_Document document, GH_DocumentCon // Get last commit from the branch var b = ApiClient - .BranchGet(CancelToken, StreamWrapper.StreamId, StreamWrapper.BranchName ?? "main", 1) + .BranchGet(StreamWrapper.StreamId, StreamWrapper.BranchName ?? "main", 1, CancelToken) .Result; // Compare commit id's. If they don't match, notify user or fetch data if in auto mode diff --git a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.SyncSendComponent.cs b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.SyncSendComponent.cs index 46a49f005e..f69b181ee4 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.SyncSendComponent.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.SyncSendComponent.cs @@ -290,7 +290,7 @@ public override void SolveInstanceWithLogContext(IGH_DataAccess DA) if (prevCommit != null) commitCreateInput.parents = new List { prevCommit.CommitId }; - var commitId = await client.CommitCreate(CancelToken, commitCreateInput); + var commitId = await client.CommitCreate(commitCreateInput, CancelToken); var wrapper = new StreamWrapper( $"{client.Account.serverInfo.url}/streams/{((ServerTransport)transport).StreamId}/commits/{commitId}?u={client.Account.userInfo.id}" diff --git a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.VariableInputReceiveComponent.cs b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.VariableInputReceiveComponent.cs index de83307c22..df532bda5a 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.VariableInputReceiveComponent.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.VariableInputReceiveComponent.cs @@ -128,7 +128,7 @@ public override void DocumentContextChanged(GH_Document document, GH_DocumentCon // Get last commit from the branch var b = ApiClient - .BranchGet(BaseWorker.CancellationToken, StreamWrapper.StreamId, StreamWrapper.BranchName ?? "main", 1) + .BranchGet(StreamWrapper.StreamId, StreamWrapper.BranchName ?? "main", 1, BaseWorker.CancellationToken) .Result; // Compare commit id's. If they don't match, notify user or fetch data if in auto mode @@ -740,7 +740,7 @@ CancellationToken CancellationToken case StreamWrapperType.Commit: try { - myCommit = await client.CommitGet(CancellationToken, InputWrapper.StreamId, InputWrapper.CommitId); + myCommit = await client.CommitGet(InputWrapper.StreamId, InputWrapper.CommitId, CancellationToken); if (myCommit == null) OnFail( GH_RuntimeMessageLevel.Warning, @@ -758,7 +758,7 @@ CancellationToken CancellationToken return myCommit; case StreamWrapperType.Stream: case StreamWrapperType.Undefined: - var mb = await client.BranchGet(CancellationToken, InputWrapper.StreamId, "main", 1); + var mb = await client.BranchGet(InputWrapper.StreamId, "main", 1, CancellationToken); if (mb.commits.totalCount == 0) // TODO: Warn that we're not pulling from the main branch OnFail( @@ -768,7 +768,7 @@ CancellationToken CancellationToken else return mb.commits.items[0]; - var cms = await client.StreamGetCommits(CancellationToken, InputWrapper.StreamId, 1); + var cms = await client.StreamGetCommits(InputWrapper.StreamId, 1, CancellationToken); if (cms.Count == 0) { OnFail(GH_RuntimeMessageLevel.Warning, "This stream has no commits."); @@ -777,7 +777,7 @@ CancellationToken CancellationToken return cms[0]; case StreamWrapperType.Branch: - var br = await client.BranchGet(CancellationToken, InputWrapper.StreamId, InputWrapper.BranchName, 1); + var br = await client.BranchGet(InputWrapper.StreamId, InputWrapper.BranchName, 1, CancellationToken); if (br == null) { OnFail( diff --git a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.VariableInputSendComponent.cs b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.VariableInputSendComponent.cs index 3d9383fab3..95c09ce605 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.VariableInputSendComponent.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopperShared/Ops/Operations.VariableInputSendComponent.cs @@ -652,7 +652,7 @@ public override void DoWork(Action ReportProgress, Action Done) if (prevCommit != null) commitCreateInput.parents = new List { prevCommit.CommitId }; - var commitId = await client.CommitCreate(CancellationToken, commitCreateInput); + var commitId = await client.CommitCreate(commitCreateInput, CancellationToken); var wrapper = new StreamWrapper( $"{client.Account.serverInfo.url}/streams/{((ServerTransport)transport).StreamId}/commits/{commitId}?u={client.Account.userInfo.id}" diff --git a/ConnectorGrasshopper/ConnectorGrasshopperShared/Streams/StreamCreateComponentV2.cs b/ConnectorGrasshopper/ConnectorGrasshopperShared/Streams/StreamCreateComponentV2.cs index 2c4a3dfba4..53b442b223 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopperShared/Streams/StreamCreateComponentV2.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopperShared/Streams/StreamCreateComponentV2.cs @@ -108,7 +108,7 @@ public Task CreateStream(Account account) var client = new Client(account); - var streamId = client.StreamCreate(CancelToken, new StreamCreateInput { isPublic = false }).Result; + var streamId = client.StreamCreate(new StreamCreateInput { isPublic = false }, CancelToken).Result; var sw = new StreamWrapper(streamId, account.userInfo.id, account.serverInfo.url); sw.SetAccount(account); diff --git a/ConnectorGrasshopper/ConnectorGrasshopperShared/Streams/StreamListComponentV2.cs b/ConnectorGrasshopper/ConnectorGrasshopperShared/Streams/StreamListComponentV2.cs index 4be4639e5c..fa7ab5dcea 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopperShared/Streams/StreamListComponentV2.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopperShared/Streams/StreamListComponentV2.cs @@ -90,7 +90,7 @@ private Task> ListStreams(Account account, int limit) { var client = new Client(account); var res = client - .StreamsGet(CancelToken, limit) + .StreamsGet(limit, CancelToken) .Result.Select(stream => new StreamWrapper(stream.id, account.userInfo.id, account.serverInfo.url)) .ToList(); return Task.FromResult(res); diff --git a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ActivityOperations.cs b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ActivityOperations.cs index 30e6e7ead3..17feb41ec4 100644 --- a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ActivityOperations.cs +++ b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ActivityOperations.cs @@ -13,45 +13,22 @@ public partial class Client /// /// Gets the activity of a stream /// - /// Id of the stream to get the activity from + /// Id of the stream to get the activity from /// Only show activity after this DateTime /// Only show activity before this DateTime /// Time to filter the activity with /// Time to filter the activity with /// Max number of activity items to get - /// - public Task> StreamGetActivity( - string streamId, - DateTime? after = null, - DateTime? before = null, - DateTime? cursor = null, - string actionType = "", - int limit = 10 - ) - { - return StreamGetActivity(CancellationToken.None, streamId, after, before, cursor, actionType, limit); - } - - /// - /// Gets the activity of a stream - /// /// - /// Id of the stream to get the activity from - /// Only show activity after this DateTime - /// Only show activity before this DateTime - /// Time to filter the activity with - /// Time to filter the activity with - /// Max number of commits to get /// - /// public async Task> StreamGetActivity( - CancellationToken cancellationToken, string id, DateTime? after = null, DateTime? before = null, DateTime? cursor = null, string actionType = "", - int limit = 25 + int limit = 25, + CancellationToken cancellationToken = default ) { var request = new GraphQLRequest diff --git a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.BranchOperations.cs b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.BranchOperations.cs index 386cccdfcd..ef8c83a4c2 100644 --- a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.BranchOperations.cs +++ b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.BranchOperations.cs @@ -1,6 +1,5 @@ #nullable enable -using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -16,26 +15,13 @@ public partial class Client /// Id of the stream to get the branches from /// Max number of branches to retrieve /// Max number of commits to retrieve - /// - public Task> StreamGetBranches(string streamId, int branchesLimit = 10, int commitsLimit = 10) - { - return StreamGetBranches(CancellationToken.None, streamId, branchesLimit, commitsLimit); - } - - /// - /// Get branches from a given stream - /// /// - /// Id of the stream to get the branches from - /// Max number of branches to retrieve - /// Max number of commits to retrieve /// - /// public async Task> StreamGetBranches( - CancellationToken cancellationToken, string streamId, int branchesLimit = 10, - int commitsLimit = 10 + int commitsLimit = 10, + CancellationToken cancellationToken = default ) { var request = new GraphQLRequest @@ -77,18 +63,9 @@ public async Task> StreamGetBranches( /// Creates a branch on a stream. /// /// - /// The stream's id. - public Task BranchCreate(BranchCreateInput branchInput) - { - return BranchCreate(CancellationToken.None, branchInput); - } - - /// - /// Creates a branch on a stream. - /// - /// + /// /// The branch id. - public async Task BranchCreate(CancellationToken cancellationToken, BranchCreateInput branchInput) + public async Task BranchCreate(BranchCreateInput branchInput, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -105,24 +82,13 @@ public async Task BranchCreate(CancellationToken cancellationToken, Bran /// /// Id of the stream to get the branch from /// Name of the branch to get - /// - public Task BranchGet(string streamId, string branchName, int commitsLimit = 10) - { - return BranchGet(CancellationToken.None, streamId, branchName, commitsLimit); - } - - /// - /// Gets a given branch from a stream. - /// /// - /// Id of the stream to get the branch from - /// Name of the branch to get - /// + /// The requested branch public async Task BranchGet( - CancellationToken cancellationToken, string streamId, string branchName, - int commitsLimit = 10 + int commitsLimit = 10, + CancellationToken cancellationToken = default ) { var request = new GraphQLRequest @@ -165,17 +131,7 @@ public async Task BranchGet( /// /// /// The stream's id. - public Task BranchUpdate(BranchUpdateInput branchInput) - { - return BranchUpdate(CancellationToken.None, branchInput); - } - - /// - /// Updates a branch. - /// - /// - /// The stream's id. - public async Task BranchUpdate(CancellationToken cancellationToken, BranchUpdateInput branchInput) + public async Task BranchUpdate(BranchUpdateInput branchInput, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -191,18 +147,9 @@ public async Task BranchUpdate(CancellationToken cancellationToken, Branch /// Deletes a stream. /// /// + /// /// - public Task BranchDelete(BranchDeleteInput branchInput) - { - return BranchDelete(CancellationToken.None, branchInput); - } - - /// - /// Deletes a stream. - /// - /// - /// - public async Task BranchDelete(CancellationToken cancellationToken, BranchDeleteInput branchInput) + public async Task BranchDelete(BranchDeleteInput branchInput, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { diff --git a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.CommentOperations.cs b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.CommentOperations.cs index ab0769847b..b43baa36b4 100644 --- a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.CommentOperations.cs +++ b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.CommentOperations.cs @@ -3,7 +3,6 @@ using System.Threading; using System.Threading.Tasks; using GraphQL; -using Speckle.Core.Logging; namespace Speckle.Core.Api; @@ -15,26 +14,13 @@ public partial class Client /// Id of the stream to get the comments from /// The number of comments to get /// Time to filter the comments with - /// - public Task StreamGetComments(string streamId, int limit = 25, string? cursor = null) - { - return StreamGetComments(CancellationToken.None, streamId, limit, cursor); - } - - /// - /// Gets the comments on a Stream - /// /// - /// Id of the stream to get the comments from - /// The number of comments to get - /// Time to filter the comments with /// - /// public async Task StreamGetComments( - CancellationToken cancellationToken, string streamId, int limit = 25, - string? cursor = null + string? cursor = null, + CancellationToken cancellationToken = default ) { var request = new GraphQLRequest @@ -88,25 +74,17 @@ public async Task StreamGetComments( } /// - /// Gets the screenshot of a Comment + /// Gets the screenshot of a Comment /// /// Id of the comment /// Id of the stream to get the comment from - /// - public Task StreamGetCommentScreenshot(string id, string streamId) - { - return StreamGetCommentScreenshot(CancellationToken.None, id, streamId); - } - - /// - /// Gets the screenshot of a Comment - /// /// - /// Id of the comment - /// Id of the stream to get the comment from /// - /// - public async Task StreamGetCommentScreenshot(CancellationToken cancellationToken, string id, string streamId) + public async Task StreamGetCommentScreenshot( + string id, + string streamId, + CancellationToken cancellationToken = default + ) { var request = new GraphQLRequest { diff --git a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.CommitOperations.cs b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.CommitOperations.cs index 04d49356c9..b32b6a795b 100644 --- a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.CommitOperations.cs +++ b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.CommitOperations.cs @@ -1,6 +1,5 @@ #nullable enable -using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -15,20 +14,9 @@ public partial class Client /// /// Id of the stream to get the commit from /// Id of the commit to get - /// - public Task CommitGet(string streamId, string commitId) - { - return CommitGet(CancellationToken.None, streamId, commitId); - } - - /// - /// Gets a given commit from a stream. - /// /// - /// Id of the stream to get the commit from - /// Id of the commit to get /// - public async Task CommitGet(CancellationToken cancellationToken, string streamId, string commitId) + public async Task CommitGet(string streamId, string commitId, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -60,21 +48,13 @@ public async Task CommitGet(CancellationToken cancellationToken, string /// /// Id of the stream to get the commits from /// Max number of commits to get - /// - public Task> StreamGetCommits(string streamId, int limit = 10) - { - return StreamGetCommits(CancellationToken.None, streamId, limit); - } - - /// - /// Gets the latest commits from a stream - /// /// - /// Id of the stream to get the commits from - /// Max number of commits to get - /// - /// - public async Task> StreamGetCommits(CancellationToken cancellationToken, string streamId, int limit = 10) + /// The requested commits + public async Task> StreamGetCommits( + string streamId, + int limit = 10, + CancellationToken cancellationToken = default + ) { var request = new GraphQLRequest { @@ -110,14 +90,7 @@ public async Task> StreamGetCommits(CancellationToken cancellationT /// /// /// The commit id. - public Task CommitCreate(CommitCreateInput commitInput) - { - return CommitCreate(CancellationToken.None, commitInput); - } - - /// - /// - public async Task CommitCreate(CancellationToken cancellationToken, CommitCreateInput commitInput) + public async Task CommitCreate(CommitCreateInput commitInput, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -133,18 +106,9 @@ public async Task CommitCreate(CancellationToken cancellationToken, Comm /// Updates a commit. /// /// + /// /// The stream's id. - public Task CommitUpdate(CommitUpdateInput commitInput) - { - return CommitUpdate(CancellationToken.None, commitInput); - } - - /// - /// Updates a commit. - /// - /// - /// The stream's id. - public async Task CommitUpdate(CancellationToken cancellationToken, CommitUpdateInput commitInput) + public async Task CommitUpdate(CommitUpdateInput commitInput, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -160,18 +124,9 @@ public async Task CommitUpdate(CancellationToken cancellationToken, Commit /// Deletes a commit. /// /// + /// /// - public Task CommitDelete(CommitDeleteInput commitInput) - { - return CommitDelete(CancellationToken.None, commitInput); - } - - /// - /// Deletes a commit. - /// - /// - /// - public async Task CommitDelete(CancellationToken cancellationToken, CommitDeleteInput commitInput) + public async Task CommitDelete(CommitDeleteInput commitInput, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -188,15 +143,12 @@ public async Task CommitDelete(CancellationToken cancellationToken, Commit /// /// Used for read receipts /// - /// - public Task CommitReceived(CommitReceivedInput commitReceivedInput) - { - return CommitReceived(CancellationToken.None, commitReceivedInput); - } - - /// /// - public async Task CommitReceived(CancellationToken cancellationToken, CommitReceivedInput commitReceivedInput) + /// + public async Task CommitReceived( + CommitReceivedInput commitReceivedInput, + CancellationToken cancellationToken = default + ) { var request = new GraphQLRequest { diff --git a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ObjectOperations.cs b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ObjectOperations.cs index 406cf194a8..9ea3c3ed56 100644 --- a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ObjectOperations.cs +++ b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ObjectOperations.cs @@ -9,24 +9,17 @@ namespace Speckle.Core.Api; public partial class Client { /// - /// Gets a given object from a stream. + /// Gets data about the requested Speckle object from a stream. /// /// Id of the stream to get the object from /// Id of the object to get - /// - public Task ObjectGet(string streamId, string objectId) - { - return ObjectGet(CancellationToken.None, streamId, objectId); - } - - /// - /// Gets a given object from a stream. - /// /// - /// Id of the stream to get the object from - /// Id of the object to get /// - public async Task ObjectGet(CancellationToken cancellationToken, string streamId, string objectId) + public async Task ObjectGet( + string streamId, + string objectId, + CancellationToken cancellationToken = default + ) { var request = new GraphQLRequest { @@ -53,20 +46,13 @@ public async Task ObjectGet(CancellationToken cancellationToken, /// /// /// - /// - public Task ObjectCountGet(string streamId, string objectId) - { - return ObjectCountGet(CancellationToken.None, streamId, objectId); - } - - /// - /// Gets a given object from a stream. - /// /// - /// - /// /// - public async Task ObjectCountGet(CancellationToken cancellationToken, string streamId, string objectId) + public async Task ObjectCountGet( + string streamId, + string objectId, + CancellationToken cancellationToken = default + ) { var request = new GraphQLRequest { diff --git a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ObsoleteOperations.cs b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ObsoleteOperations.cs new file mode 100644 index 0000000000..d2688296dd --- /dev/null +++ b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ObsoleteOperations.cs @@ -0,0 +1,270 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Threading; +using System.Threading.Tasks; +using GraphQL; +using Speckle.Core.Logging; + +namespace Speckle.Core.Api; + +[SuppressMessage("Design", "CA1068:CancellationToken parameters must come last")] +public partial class Client +{ + #region Depreated Invites + + /// + /// Checks if Speckle Server version is at least v2.6.4 meaning stream invites are supported. + /// + /// + /// true if invites are supported + /// if Speckle Server version is less than v2.6.4 + [Obsolete("We're not supporting 2.6.4 version any more", true)] + public async Task _CheckStreamInvitesSupported(CancellationToken cancellationToken = default) + { + var version = ServerVersion ?? await GetServerVersion(cancellationToken).ConfigureAwait(false); + if (version < new System.Version("2.6.4")) + throw new SpeckleException("Stream invites are only supported as of Speckle Server v2.6.4."); + return true; + } + #endregion + + #region Stream Grant Permission + + /// + /// Grants permissions to a user on a given stream. + /// + /// + /// + [Obsolete("Please use the `StreamUpdatePermission` method", true)] + public Task StreamGrantPermission(StreamPermissionInput permissionInput) + { + return StreamGrantPermission(CancellationToken.None, permissionInput); + } + + /// + /// Grants permissions to a user on a given stream. + /// + /// + /// + /// + [Obsolete("Please use the `StreamUpdatePermission` method", true)] + public async Task StreamGrantPermission( + CancellationToken cancellationToken, + StreamPermissionInput permissionInput + ) + { + var request = new GraphQLRequest + { + Query = + @" + mutation streamGrantPermission($permissionParams: StreamGrantPermissionInput!) { + streamGrantPermission(permissionParams:$permissionParams) + }", + Variables = new { permissionParams = permissionInput } + }; + + var res = await ExecuteGraphQLRequest>(request, cancellationToken).ConfigureAwait(false); + return (bool)res["streamGrantPermission"]; + } + + #endregion + + #region Cancellation token as last param + + [Obsolete("Use overload with cancellation token parameter last")] + public Task> StreamGetActivity( + CancellationToken cancellationToken, + string id, + DateTime? after = null, + DateTime? before = null, + DateTime? cursor = null, + string actionType = "", + int limit = 25 + ) + { + return StreamGetActivity(id, after, before, cursor, actionType, limit, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task> StreamGetBranches( + CancellationToken cancellationToken, + string streamId, + int branchesLimit = 10, + int commitsLimit = 10 + ) + { + return StreamGetBranches(streamId, branchesLimit, commitsLimit, CancellationToken.None); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task BranchCreate(CancellationToken cancellationToken, BranchCreateInput branchInput) + { + return BranchCreate(branchInput, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task BranchGet( + CancellationToken cancellationToken, + string streamId, + string branchName, + int commitsLimit = 10 + ) + { + return BranchGet(streamId, branchName, commitsLimit, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task BranchUpdate(CancellationToken cancellationToken, BranchUpdateInput branchInput) + { + return BranchUpdate(branchInput, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task BranchDelete(CancellationToken cancellationToken, BranchDeleteInput branchInput) + { + return BranchDelete(branchInput, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task StreamGetComments( + CancellationToken cancellationToken, + string streamId, + int limit = 25, + string? cursor = null + ) + { + return StreamGetComments(streamId, limit, cursor, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task StreamGetCommentScreenshot(CancellationToken cancellationToken, string id, string streamId) + { + return StreamGetCommentScreenshot(id, streamId, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task CommitGet(CancellationToken cancellationToken, string streamId, string commitId) + { + return CommitGet(streamId, commitId, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task> StreamGetCommits(CancellationToken cancellationToken, string streamId, int limit = 10) + { + return StreamGetCommits(streamId, limit, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task CommitCreate(CancellationToken cancellationToken, CommitCreateInput commitInput) + { + return CommitCreate(commitInput, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task CommitUpdate(CancellationToken cancellationToken, CommitUpdateInput commitInput) + { + return CommitUpdate(commitInput, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task CommitDelete(CancellationToken cancellationToken, CommitDeleteInput commitInput) + { + return CommitDelete(commitInput, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task CommitReceived(CancellationToken cancellationToken, CommitReceivedInput commitReceivedInput) + { + return CommitReceived(commitReceivedInput, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task ObjectGet(CancellationToken cancellationToken, string streamId, string objectId) + { + return ObjectGet(streamId, objectId, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task ObjectCountGet(CancellationToken cancellationToken, string streamId, string objectId) + { + return ObjectCountGet(streamId, objectId, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task StreamGet(CancellationToken cancellationToken, string id, int branchesLimit = 10) + { + return StreamGet(id, branchesLimit, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task> StreamsGet(CancellationToken cancellationToken, int limit = 10) + { + return StreamsGet(limit, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task> FavoriteStreamsGet(CancellationToken cancellationToken, int limit = 10) + { + return FavoriteStreamsGet(limit, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task> StreamSearch(CancellationToken cancellationToken, string query, int limit = 10) + { + return StreamSearch(query, limit, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task StreamCreate(CancellationToken cancellationToken, StreamCreateInput streamInput) + { + return StreamCreate(streamInput, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task StreamUpdate(CancellationToken cancellationToken, StreamUpdateInput streamInput) + { + return StreamUpdate(streamInput, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task StreamDelete(CancellationToken cancellationToken, string id) + { + return StreamDelete(id, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task StreamRevokePermission( + CancellationToken cancellationToken, + StreamRevokePermissionInput permissionInput + ) + { + return StreamRevokePermission(permissionInput, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task StreamGetPendingCollaborators(CancellationToken cancellationToken, string id) + { + return StreamGetPendingCollaborators(id, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task StreamInviteCreate(CancellationToken cancellationToken, StreamInviteCreateInput inviteCreateInput) + { + return StreamInviteCreate(inviteCreateInput, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task OtherUserGet(CancellationToken cancellationToken, string id) + { + return OtherUserGet(id, cancellationToken); + } + + [Obsolete("Use overload with cancellation token parameter last")] + public Task> UserSearch(CancellationToken cancellationToken, string query, int limit = 10) + { + return UserSearch(query, limit, cancellationToken); + } + #endregion +} diff --git a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ServerOperations.cs b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ServerOperations.cs index 63b9291251..f45726b676 100644 --- a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ServerOperations.cs +++ b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.ServerOperations.cs @@ -16,7 +16,6 @@ public partial class Client /// [Optional] defaults to an empty cancellation token /// object excluding any strings (eg "2.7.2-alpha.6995" becomes "2.7.2.6995") /// - /// public async Task GetServerVersion(CancellationToken cancellationToken = default) { var request = new GraphQLRequest diff --git a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.StreamOperations.cs b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.StreamOperations.cs index 2c2b40f6e6..41ab2759e7 100644 --- a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.StreamOperations.cs +++ b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.StreamOperations.cs @@ -9,11 +9,11 @@ namespace Speckle.Core.Api; public partial class Client { - /// - /// Cheks if a stream exists by id. + /// Checks if a stream exists by id. /// /// Id of the stream to get + /// /// public async Task IsStreamAccessible(string id, CancellationToken cancellationToken = default) { @@ -41,30 +41,17 @@ public async Task IsStreamAccessible(string id, CancellationToken cancella { return false; } - } - /// /// Gets a stream by id including basic branch info (id, name, description, and total commit count). - /// For detailed commit and branch info, use StreamGetCommits and StreamGetBranches respectively. - /// - /// Id of the stream to get - /// Max number of branches to retrieve - /// - public Task StreamGet(string id, int branchesLimit = 10) - { - return StreamGet(CancellationToken.None, id, branchesLimit); - } - - /// - /// Gets a stream by id including basic branch info (id, name, description, and total commit count). - /// For detailed commit and branch info, use StreamGetCommits and StreamGetBranches respectively. + /// For detailed commit and branch info, use and respectively. /// /// Id of the stream to get /// Max number of branches to retrieve + /// /// - public async Task StreamGet(CancellationToken cancellationToken, string id, int branchesLimit = 10) + public async Task StreamGet(string id, int branchesLimit = 10, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -110,18 +97,9 @@ public async Task StreamGet(CancellationToken cancellationToken, string /// Gets all streams for the current user /// /// Max number of streams to return + /// /// - public Task> StreamsGet(int limit = 10) - { - return StreamsGet(CancellationToken.None, limit); - } - - /// - /// Gets all streams for the current user - /// - /// Max number of streams to return - /// - public async Task> StreamsGet(CancellationToken cancellationToken, int limit = 10) + public async Task> StreamsGet(int limit = 10, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -172,17 +150,13 @@ public async Task> StreamsGet(CancellationToken cancellationToken, return res.activeUser.streams.items; } - public Task> FavoriteStreamsGet(int limit = 10) - { - return FavoriteStreamsGet(CancellationToken.None, limit); - } - /// /// Gets all favorite streams for the current user /// /// Max number of streams to return + /// /// - public async Task> FavoriteStreamsGet(CancellationToken cancellationToken, int limit = 10) + public async Task> FavoriteStreamsGet(int limit = 10, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -234,19 +208,13 @@ public async Task> FavoriteStreamsGet(CancellationToken cancellatio /// /// String query to search for /// Max number of streams to return + /// /// - public Task> StreamSearch(string query, int limit = 10) - { - return StreamSearch(CancellationToken.None, query, limit); - } - - /// - /// Searches the user's streams by name, description, and ID - /// - /// String query to search for - /// Max number of streams to return - /// - public async Task> StreamSearch(CancellationToken cancellationToken, string query, int limit = 10) + public async Task> StreamSearch( + string query, + int limit = 10, + CancellationToken cancellationToken = default + ) { var request = new GraphQLRequest { @@ -276,7 +244,7 @@ public async Task> StreamSearch(CancellationToken cancellationToken Variables = new { query, limit } }; - var res = await GQLClient.SendMutationAsync(request, cancellationToken).ConfigureAwait(false); + var res = await GQLClient.SendMutationAsync(request, cancellationToken).ConfigureAwait(false); //WARN: Why do we do this? return (await ExecuteGraphQLRequest(request, cancellationToken).ConfigureAwait(false)).streams.items; } @@ -284,18 +252,9 @@ public async Task> StreamSearch(CancellationToken cancellationToken /// Creates a stream. /// /// + /// /// The stream's id. - public Task StreamCreate(StreamCreateInput streamInput) - { - return StreamCreate(CancellationToken.None, streamInput); - } - - /// - /// Creates a stream. - /// - /// - /// The stream's id. - public async Task StreamCreate(CancellationToken cancellationToken, StreamCreateInput streamInput) + public async Task StreamCreate(StreamCreateInput streamInput, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -310,19 +269,9 @@ public async Task StreamCreate(CancellationToken cancellationToken, Stre /// Updates a stream. /// /// Note: the id field needs to be a valid stream id. - /// The stream's id. - public Task StreamUpdate(StreamUpdateInput streamInput) - { - return StreamUpdate(CancellationToken.None, streamInput); - } - - /// - /// Updates a stream. - /// /// - /// Note: the id field needs to be a valid stream id. /// The stream's id. - public async Task StreamUpdate(CancellationToken cancellationToken, StreamUpdateInput streamInput) + public async Task StreamUpdate(StreamUpdateInput streamInput, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -339,19 +288,9 @@ public async Task StreamUpdate(CancellationToken cancellationToken, Stream /// Deletes a stream. /// /// Id of the stream to be deleted - /// - public Task StreamDelete(string id) - { - return StreamDelete(CancellationToken.None, id); - } - - /// - /// Deletes a stream. - /// /// - /// Id of the stream to be deleted /// - public async Task StreamDelete(CancellationToken cancellationToken, string id) + public async Task StreamDelete(string id, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -362,62 +301,15 @@ public async Task StreamDelete(CancellationToken cancellationToken, string return (bool)res["streamDelete"]; } - /// - /// Grants permissions to a user on a given stream. - /// - /// - /// - [Obsolete("Please use the `StreamUpdatePermission` method", true)] - public Task StreamGrantPermission(StreamPermissionInput permissionInput) - { - return StreamGrantPermission(CancellationToken.None, permissionInput); - } - - /// - /// Grants permissions to a user on a given stream. - /// - /// - /// - /// - [Obsolete("Please use the `StreamUpdatePermission` method", true)] - public async Task StreamGrantPermission( - CancellationToken cancellationToken, - StreamPermissionInput permissionInput - ) - { - var request = new GraphQLRequest - { - Query = - @" - mutation streamGrantPermission($permissionParams: StreamGrantPermissionInput!) { - streamGrantPermission(permissionParams:$permissionParams) - }", - Variables = new { permissionParams = permissionInput } - }; - - var res = await ExecuteGraphQLRequest>(request, cancellationToken).ConfigureAwait(false); - return (bool)res["streamGrantPermission"]; - } - /// /// Revokes permissions of a user on a given stream. /// /// - /// - public Task StreamRevokePermission(StreamRevokePermissionInput permissionInput) - { - return StreamRevokePermission(CancellationToken.None, permissionInput); - } - - /// - /// Revokes permissions of a user on a given stream. - /// /// - /// /// public async Task StreamRevokePermission( - CancellationToken cancellationToken, - StreamRevokePermissionInput permissionInput + StreamRevokePermissionInput permissionInput, + CancellationToken cancellationToken = default ) { var request = new GraphQLRequest @@ -463,21 +355,13 @@ mutation streamUpdatePermission($permissionParams: StreamUpdatePermissionInput!) /// Gets the pending collaborators of a stream by id. /// Requires the user to be an owner of the stream. /// - /// Id of the stream to get - /// - public Task StreamGetPendingCollaborators(string id) - { - return StreamGetPendingCollaborators(CancellationToken.None, id); - } - - /// - /// Gets the pending collaborators of a stream by id. - /// Requires the user to be an owner of the stream. - /// - /// Id of the stream to get - /// Max number of branches to retrieve + /// + /// /// - public async Task StreamGetPendingCollaborators(CancellationToken cancellationToken, string id) + public async Task StreamGetPendingCollaborators( + string streamId, + CancellationToken cancellationToken = default + ) { var request = new GraphQLRequest { @@ -496,31 +380,21 @@ public async Task StreamGetPendingCollaborators(CancellationToken cancel } } }", - Variables = new { id } + Variables = new { streamId } }; - var res = await GQLClient.SendMutationAsync(request, cancellationToken).ConfigureAwait(false); + var res = await GQLClient.SendMutationAsync(request, cancellationToken).ConfigureAwait(false); //WARN: Why do we do this? return (await ExecuteGraphQLRequest(request, cancellationToken).ConfigureAwait(false)).stream; } /// /// Sends an email invite to join a stream and assigns them a collaborator role. /// - /// - /// - public Task StreamInviteCreate(StreamInviteCreateInput streamCreateInput) - { - return StreamInviteCreate(CancellationToken.None, streamCreateInput); - } - - /// - /// Sends an email invite to join a stream and assigns them a collaborator role. - /// - /// /// + /// /// public async Task StreamInviteCreate( - CancellationToken cancellationToken, - StreamInviteCreateInput inviteCreateInput + StreamInviteCreateInput inviteCreateInput, + CancellationToken cancellationToken = default ) { if ((inviteCreateInput.email == null) & (inviteCreateInput.userId == null)) @@ -566,21 +440,6 @@ mutation streamInviteCancel( $streamId: String!, $inviteId: String! ) { return (bool)res["streamInviteCancel"]; } - /// - /// Checks if Speckle Server version is at least v2.6.4 meaning stream invites are supported. - /// - /// - /// true if invites are supported - /// if Speckle Server version is less than v2.6.4 - [Obsolete("We're not supporting 2.6.4 version any more", true)] - public async Task _CheckStreamInvitesSupported(CancellationToken cancellationToken = default) - { - var version = ServerVersion ?? await GetServerVersion(cancellationToken).ConfigureAwait(false); - if (version < new System.Version("2.6.4")) - throw new SpeckleException("Stream invites are only supported as of Speckle Server v2.6.4."); - return true; - } - /// /// Accept or decline a stream invite. /// diff --git a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.UserOperations.cs b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.UserOperations.cs index c6e29d7a7f..939f9aee2c 100644 --- a/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.UserOperations.cs +++ b/Core/Core/Api/GraphQL/Client.GraphqlCleintOperations/Client.UserOperations.cs @@ -3,28 +3,17 @@ using System.Threading; using System.Threading.Tasks; using GraphQL; -using Speckle.Core.Logging; namespace Speckle.Core.Api; public partial class Client { - /// - /// Gets the currently active user profile. - /// - /// - public Task ActiveUserGet() - { - return ActiveUserGet(CancellationToken.None); - } - /// /// Gets the currently active user profile. /// /// /// - /// - public async Task ActiveUserGet(CancellationToken cancellationToken) + public async Task ActiveUserGet(CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -50,20 +39,9 @@ public async Task ActiveUserGet(CancellationToken cancellationToken) /// Get another user's profile by its user id. /// /// Id of the user you are looking for - /// - public Task OtherUserGet(string id) - { - return OtherUserGet(CancellationToken.None, id); - } - - /// - /// Get another user's profile by its user id. - /// /// - /// Id of the user you are looking for /// - /// - public async Task OtherUserGet(CancellationToken cancellationToken, string id) + public async Task OtherUserGet(string id, CancellationToken cancellationToken = default) { var request = new GraphQLRequest { @@ -90,18 +68,11 @@ public async Task ActiveUserGet(CancellationToken cancellationToken) /// String to search for. Must be at least 3 characters /// Max number of users to return /// - public Task> UserSearch(string query, int limit = 10) - { - return UserSearch(CancellationToken.None, query, limit); - } - - /// - /// Searches for a user on the server. - /// - /// String to search for. Must be at least 3 characters - /// Max number of users to return - /// - public async Task> UserSearch(CancellationToken cancellationToken, string query, int limit = 10) + public async Task> UserSearch( + string query, + int limit = 10, + CancellationToken cancellationToken = default + ) { var request = new GraphQLRequest { diff --git a/Core/Core/Api/GraphQL/Client.cs b/Core/Core/Api/GraphQL/Client.cs index 26f6da51f9..dc39a034a3 100644 --- a/Core/Core/Api/GraphQL/Client.cs +++ b/Core/Core/Api/GraphQL/Client.cs @@ -75,7 +75,7 @@ public Client(Account account) public string ApiToken => Account.token; - public System.Version ServerVersion { get; set; } + public System.Version? ServerVersion { get; set; } [JsonIgnore] public Account Account { get; set; } diff --git a/Core/Core/Api/GraphQL/Models.cs b/Core/Core/Api/GraphQL/Models.cs index 68886c9915..a00e9e400d 100644 --- a/Core/Core/Api/GraphQL/Models.cs +++ b/Core/Core/Api/GraphQL/Models.cs @@ -122,17 +122,17 @@ public class Stream public Branches branches { get; set; } /// - /// Set only in the case that you've requested this through . + /// Set only in the case that you've requested this through . /// public Branch branch { get; set; } /// - /// Set only in the case that you've requested this through . + /// Set only in the case that you've requested this through . /// public Commit commit { get; set; } /// - /// Set only in the case that you've requested this through + /// Set only in the case that you've requested this through /// public Commits commits { get; set; } diff --git a/DesktopUI2/DesktopUI2/ConnectorHelpers.cs b/DesktopUI2/DesktopUI2/ConnectorHelpers.cs index 6b83ab1390..ca05a405e3 100644 --- a/DesktopUI2/DesktopUI2/ConnectorHelpers.cs +++ b/DesktopUI2/DesktopUI2/ConnectorHelpers.cs @@ -74,8 +74,6 @@ public static async Task ReceiveCommit(Commit commit, StreamState state, P return commitObject; } - - /// Progress cancellation token /// Current Stream card state (does not mutate) /// Requested Commit @@ -91,13 +89,13 @@ public static async Task GetCommitFromState(StreamState state, Cancellat if (state.CommitId == LatestCommitString) //if "latest", always make sure we get the latest commit { var res = await state.Client - .BranchGet(cancellationToken, state.StreamId, state.BranchName, 1) + .BranchGet(state.StreamId, state.BranchName, 1, cancellationToken) .ConfigureAwait(false); commit = res.commits.items.First(); } else { - var res = await state.Client.CommitGet(cancellationToken, state.StreamId, state.CommitId).ConfigureAwait(false); + var res = await state.Client.CommitGet(state.StreamId, state.CommitId, cancellationToken).ConfigureAwait(false); commit = res; } } @@ -118,7 +116,7 @@ public static async Task GetCommitFromState(StreamState state, Cancellat } /// - /// Try catch wrapper around with logging + /// Try catch wrapper around with logging /// public static async Task TryCommitReceived( Client client, @@ -128,7 +126,7 @@ public static async Task TryCommitReceived( { try { - await client.CommitReceived(cancellationToken, commitReceivedInput).ConfigureAwait(false); + await client.CommitReceived(commitReceivedInput, cancellationToken).ConfigureAwait(false); } catch (SpeckleException ex) { @@ -159,9 +157,9 @@ public static async Task TryCommitReceived( //TODO: should this just be how `CommitCreate` id implemented? /// - /// Wrapper around with Error handling. + /// Wrapper around with Error handling. /// - /// + /// /// /// All other exceptions public static async Task CreateCommit( @@ -172,7 +170,7 @@ public static async Task CreateCommit( { try { - var commitId = await client.CommitCreate(cancellationToken, commitInput).ConfigureAwait(false); + var commitId = await client.CommitCreate(commitInput, cancellationToken).ConfigureAwait(false); return commitId; } catch (OperationCanceledException) @@ -199,9 +197,9 @@ public static void DefaultSendErrorHandler(string error, Exception ex) //Treat all operation errors as fatal throw new SpeckleException($"Failed to send objects to server - {error}", ex); } - + #region deprecated members - + [Obsolete("Use overload that has cancellation token last", true)] public static async Task TryCommitReceived( CancellationToken cancellationToken, @@ -211,13 +209,13 @@ CommitReceivedInput commitReceivedInput { await TryCommitReceived(client, commitReceivedInput, cancellationToken).ConfigureAwait(false); } - + [Obsolete("Use overload that has cancellation token last", true)] public static async Task GetCommitFromState(CancellationToken cancellationToken, StreamState state) { return await GetCommitFromState(state, cancellationToken).ConfigureAwait(false); } - + [Obsolete("Use overload that has cancellation token last", true)] public static async Task TryCommitReceived( CancellationToken cancellationToken, @@ -228,7 +226,7 @@ string sourceApplication { await TryCommitReceived(state, commit, sourceApplication, cancellationToken).ConfigureAwait(false); } - + [Obsolete("Use overload that has cancellation token last", true)] public static async Task CreateCommit( CancellationToken cancellationToken, diff --git a/DesktopUI2/DesktopUI2/ViewModels/HomeViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/HomeViewModel.cs index 2bf03bcf66..4c6569fb23 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/HomeViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/HomeViewModel.cs @@ -181,10 +181,10 @@ private async Task GetStreams() { if (SelectedFilter == Filter.favorite) result = await account.Client - .FavoriteStreamsGet(StreamGetCancelTokenSource.Token, 25) + .FavoriteStreamsGet(25, StreamGetCancelTokenSource.Token) .ConfigureAwait(true); else - result = await account.Client.StreamsGet(StreamGetCancelTokenSource.Token, 25).ConfigureAwait(true); + result = await account.Client.StreamsGet(25, StreamGetCancelTokenSource.Token).ConfigureAwait(true); } //SEARCH else @@ -193,7 +193,7 @@ private async Task GetStreams() if (SelectedFilter == Filter.favorite) SelectedFilter = Filter.all; result = await account.Client - .StreamSearch(StreamGetCancelTokenSource.Token, SearchQuery, 25) + .StreamSearch(SearchQuery, 25, StreamGetCancelTokenSource.Token) .ConfigureAwait(true); } diff --git a/DesktopUI2/DesktopUI2/ViewModels/StreamSelectorViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/StreamSelectorViewModel.cs index 02857de481..f683a5b33d 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/StreamSelectorViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/StreamSelectorViewModel.cs @@ -58,11 +58,11 @@ private async Task GetStreams() //NO SEARCH if (string.IsNullOrEmpty(SearchQuery)) - result = await account.Client.StreamsGet(StreamGetCancelTokenSource.Token, 25).ConfigureAwait(true); + result = await account.Client.StreamsGet(25, StreamGetCancelTokenSource.Token).ConfigureAwait(true); //SEARCH else result = await account.Client - .StreamSearch(StreamGetCancelTokenSource.Token, SearchQuery, 25) + .StreamSearch(SearchQuery, 25, StreamGetCancelTokenSource.Token) .ConfigureAwait(true); if (StreamGetCancelTokenSource.IsCancellationRequested) From a8a3ebb57bf5080a95fbf0e8720dacb0d36d326b Mon Sep 17 00:00:00 2001 From: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com> Date: Thu, 21 Sep 2023 11:53:10 +0100 Subject: [PATCH 03/49] chore(core): Removed override ErrorsAsWarnings category (#2949) --- Core/Core/Core.csproj | 1 - Core/Core/Helpers/Crypt.cs | 2 ++ Core/Core/Helpers/Http.cs | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/Core/Core.csproj b/Core/Core/Core.csproj index 7ee14fe173..fc1dac829f 100644 --- a/Core/Core/Core.csproj +++ b/Core/Core/Core.csproj @@ -12,7 +12,6 @@ $(PackageTags) core true true - 8603, 8601, 8602, CS8625 diff --git a/Core/Core/Helpers/Crypt.cs b/Core/Core/Helpers/Crypt.cs index ad331307b1..0511911282 100644 --- a/Core/Core/Helpers/Crypt.cs +++ b/Core/Core/Helpers/Crypt.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using System.Security.Cryptography; using System.Text; @@ -5,6 +6,7 @@ namespace Speckle.Core.Helpers; public static class Crypt { + [SuppressMessage("Security", "CA5351:Do Not Use Broken Cryptographic Algorithms")] public static string Hash(string input) { using (MD5 md5 = MD5.Create()) diff --git a/Core/Core/Helpers/Http.cs b/Core/Core/Helpers/Http.cs index 58eaf08ba0..cac509efc2 100644 --- a/Core/Core/Helpers/Http.cs +++ b/Core/Core/Helpers/Http.cs @@ -181,7 +181,9 @@ public static HttpClient GetHttpProxyClient(SpeckleHttpClientHandler? handler = IWebProxy proxy = WebRequest.GetSystemWebProxy(); proxy.Credentials = CredentialCache.DefaultCredentials; - var client = new HttpClient(handler ?? new SpeckleHttpClientHandler()); + handler ??= new SpeckleHttpClientHandler(); + handler.CheckCertificateRevocationList = true; + var client = new HttpClient(handler); client.Timeout = timeout ?? TimeSpan.FromSeconds(100); return client; } From 3e88bc34c227b41ff5122b3429acef7388ac2624 Mon Sep 17 00:00:00 2001 From: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com> Date: Mon, 25 Sep 2023 11:01:42 +0100 Subject: [PATCH 04/49] Implemented Traversal Refactor for CSI connectors (#2961) * First pass at implementing traversal * chore(csi): Removed old traversal --- .../UI/ConnectorBindingsCSI.Recieve.cs | 95 ++++++++++--------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs index 29d7ed731d..b235407155 100644 --- a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs +++ b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs @@ -14,6 +14,7 @@ using System.Linq; using System.Resources; using System.Threading.Tasks; +using Speckle.Core.Models.GraphTraversal; namespace Speckle.ConnectorCSI.UI { @@ -144,68 +145,68 @@ private List ConvertReceivedObjects(ISpeckleConverter convert } /// - /// Recurses through the commit object and flattens it. + /// Traverses the object graph, returning objects to be converted. /// - /// - /// - /// - private List FlattenCommitObject(object obj, ISpeckleConverter converter) + /// The root object to traverse + /// The converter instance, used to define what objects are convertable + /// A flattened list of objects to be converted ToNative + private List FlattenCommitObject(Base obj, ISpeckleConverter converter) { - var objects = new List(); - - if (obj is Base @base) + void StoreObject(Base b) { - var appObj = new ApplicationObject(@base.id, ConnectorCSIUtils.SimplifySpeckleType(@base.speckle_type)) - { - applicationId = @base.applicationId, - Status = ApplicationObject.State.Unknown - }; + if (!StoredObjects.ContainsKey(b.id)) + StoredObjects.Add(b.id, b); + } - if (converter.CanConvertToNative(@base)) + ApplicationObject CreateApplicationObject(Base current) + { + ApplicationObject NewAppObj() { - if (StoredObjects.ContainsKey(@base.id)) - return objects; + var speckleType = current.speckle_type + .Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries) + .LastOrDefault(); - appObj.Convertible = true; - objects.Add(appObj); - StoredObjects.Add(@base.id, @base); - return objects; + return new ApplicationObject(current.id, speckleType) { applicationId = current.applicationId, }; } - else + + //Handle convertable objects + if (converter.CanConvertToNative(current)) { - foreach (var prop in @base.GetMembers().Keys) - objects.AddRange(FlattenCommitObject(@base[prop], converter)); - return objects; + var appObj = NewAppObj(); + appObj.Convertible = true; + StoreObject(current); + return appObj; } - } - if (obj is IList list && list != null) - { - foreach (var listObj in list) - objects.AddRange(FlattenCommitObject(listObj, converter)); - return objects; - } + //Handle objects convertable using displayValues + var fallbackMember = DefaultTraversal.displayValuePropAliases + .Where(o => current[o] != null) + .Select(o => current[o]) + .FirstOrDefault(); - if (obj is IDictionary dict) - { - foreach (DictionaryEntry kvp in dict) - objects.AddRange(FlattenCommitObject(kvp.Value, converter)); - return objects; - } - else - { - if (obj != null && !obj.GetType().IsPrimitive && !(obj is string)) + if (fallbackMember != null) { - var appObj = new ApplicationObject(obj.GetHashCode().ToString(), obj.GetType().ToString()); - appObj.Update( - status: ApplicationObject.State.Skipped, - logItem: $"Receiving this object type is not supported in CSI" - ); - objects.Add(appObj); + var appObj = NewAppObj(); + var fallbackObjects = GraphTraversal.TraverseMember(fallbackMember).Select(CreateApplicationObject); + appObj.Fallback.AddRange(fallbackObjects); + + StoreObject(current); + return appObj; } + + return null; } - return objects; + var traverseFunction = DefaultTraversal.CreateTraverseFunc(converter); + + var objectsToConvert = traverseFunction + .Traverse(obj) + .Select(tc => CreateApplicationObject(tc.current)) + .Where(appObject => appObject != null) + .Reverse() //just for the sake of matching the previous behaviour as close as possible + .ToList(); + + return objectsToConvert; } private void RefreshDatabaseTable(string floorTableKey) From 87bf8da85ffe4dcb08846d247961f5815d347b24 Mon Sep 17 00:00:00 2001 From: BovineOx <73857041+BovineOx@users.noreply.github.com> Date: Mon, 25 Sep 2023 11:08:13 +0100 Subject: [PATCH 05/49] feat(revit): Support for TopoSolid (#2951) * Toposolid WIP Early, not quite functional, Toposolid support - WIP and will need refactor if we are to provide Toposolid and RevitToposolid * Tidy up Toposolid implementation Some renaming | removed unused code for Toposolids | changed method of obtaining curves and presenting back to Toposolid.Create * Removed some additional debug logging Had some spurious SepckleLog.Logger additions I have removed * PR Fixes Wrapped CanConvertToNative() in preprocessor directive | removed debug line * Removing dead function This function was refactored out and my PR put it back - is unused * Tweaks to RevitToposolid Constructor Ronseal commit :) * Minor tweaks to improve GrassHopper experience as per title * BIM to Revit on the schema attribute --------- Co-authored-by: Ian Hawley --- .../ConverterRevitShared/ConverterRevit.cs | 26 +++- .../ConverterRevitShared.projitems | 1 + .../Partial Classes/ConvertGeometry.cs | 1 + .../Partial Classes/ConvertToposolid.cs | 124 ++++++++++++++++++ .../Partial Classes/ConvertView.cs | 1 + .../BuiltElements/Revit/RevitToposolid.cs | 43 ++++++ 6 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertToposolid.cs create mode 100644 Objects/Objects/BuiltElements/Revit/RevitToposolid.cs diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevit.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevit.cs index 7695b98422..905a9fea0f 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevit.cs +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevit.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Architecture; @@ -13,6 +14,7 @@ using RevitSharedResources.Interfaces; using RevitSharedResources.Models; using Speckle.Core.Kits; +using Speckle.Core.Logging; using Speckle.Core.Models; using Speckle.Core.Models.Extensions; using BE = Objects.BuiltElements; @@ -330,7 +332,15 @@ public Base ConvertToSpeckle(object @object) break; case DB.CombinableElement o: returnObject = CombinableElementToSpeckle(o); + break; + +// toposolid from Revit 2024 +#if (REVIT2024) + case DB.Toposolid o: + returnObject = ToposolidToSpeckle(o, out notes); break; +#endif + #if REVIT2020 || REVIT2021 || REVIT2022 case DB.Structure.AnalyticalModelStick o: returnObject = AnalyticalStickToSpeckle(o); @@ -576,7 +586,6 @@ public object ConvertToNativeObject(Base @object) case BE.Floor o: return FloorToNative(o); - case BE.Level o: return LevelToNative(o); @@ -674,6 +683,11 @@ public object ConvertToNativeObject(Base @object) // gis case PolygonElement o: return PolygonElementToNative(o); + +#if (REVIT2024) + case RevitToposolid o: + return ToposolidToNative(o); +#endif //hacky but the current comments camera is not a Base object //used only from DUI and not for normal geometry conversion @@ -746,6 +760,11 @@ public bool CanConvertToSpeckle(object @object) DB.ReferencePoint _ => true, DB.FabricationPart _ => true, DB.CombinableElement _ => true, + +#if (REVIT2024) + DB.Toposolid _ => true, +#endif + #if REVIT2020 || REVIT2021 || REVIT2022 DB.Structure.AnalyticalModelStick _ => true, DB.Structure.AnalyticalModelSurface _ => true, @@ -806,6 +825,11 @@ public bool CanConvertToNative(Base @object) BERC.RoomBoundaryLine _ => true, BERC.SpaceSeparationLine _ => true, BE.Roof _ => true, + +#if (REVIT2024) + RevitToposolid _ => true, +#endif + BE.Topography _ => true, BER.RevitCurtainWallPanel _ => true, BER.RevitFaceWall _ => true, diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevitShared.projitems b/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevitShared.projitems index 0530da4469..1b8cb0ba24 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevitShared.projitems +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/ConverterRevitShared.projitems @@ -54,6 +54,7 @@ + diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertGeometry.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertGeometry.cs index 26c2655361..663f8d4661 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertGeometry.cs +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertGeometry.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.DoubleNumerics; diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertToposolid.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertToposolid.cs new file mode 100644 index 0000000000..6188258e06 --- /dev/null +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertToposolid.cs @@ -0,0 +1,124 @@ +#if (REVIT2024) + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Autodesk.Revit.DB; +using Objects.BuiltElements.Revit; +using Speckle.Core.Models; +using DB = Autodesk.Revit.DB; + +using OG = Objects.Geometry; +using OO = Objects.Other; + +namespace Objects.Converter.Revit +{ + public partial class ConverterRevit + { + public ApplicationObject ToposolidToNative(RevitToposolid fromSpeckle) + { + string name = null; + ApplicationObject appObj = null; + + var docObj = GetExistingElementByApplicationId(fromSpeckle.applicationId); + appObj = new ApplicationObject(fromSpeckle.id, fromSpeckle.speckle_type) + { + applicationId = fromSpeckle.applicationId + }; + + // skip if element already exists in doc & receive mode is set to ignore + if (IsIgnore(docObj, appObj)) + return appObj; + + // get the curves and the points + var curveLoops = new List(); + foreach (var curveArray in fromSpeckle.profiles) + { + curveLoops.Add(CurveArrayToCurveLoop(CurveToNative(curveArray.segments))); + } + + var points = fromSpeckle.points.Select(x => PointToNative(x)).ToList(); + + // NOTE: if the level is null this will not create + // there maybe something more elegant we can do to automatically drop to direct shape + DB.Level level = ConvertLevelToRevit(fromSpeckle.level, out ApplicationObject.State state); + + var topoSolidType = GetElementType(fromSpeckle, appObj, out bool _); + + Toposolid revitToposolid = null; + if (points.Count > 0) + { + revitToposolid = Toposolid.Create(Doc, curveLoops, points, topoSolidType.Id, level?.Id); + } + else + { + revitToposolid = Toposolid.Create(Doc, curveLoops, topoSolidType.Id, level?.Id); + } + + SetInstanceParameters(revitToposolid, fromSpeckle); + + appObj.Update(status: ApplicationObject.State.Created, createdId: revitToposolid.UniqueId, convertedItem: revitToposolid); + + return appObj; + } + + private List GetSketchProfiles(Sketch sketch) + { + var profiles = new List(); + foreach (CurveArray curves in sketch.Profile) + { + var curveLoop = CurveArrayToCurveLoop(curves); + profiles.Add(new OG.Polycurve + { + segments = curveLoop.Select(x => CurveToSpeckle(x, sketch.Document)).ToList() + }); + } + + return profiles; + } + + private RevitToposolid ToposolidToSpeckle(Toposolid topoSolid, out List notes) + { + var toSpeckle = new RevitToposolid(); + notes = new List(); + + // we will store the list of interior points in order to recreate the Toposolid + var slabShapeEditor = topoSolid.GetSlabShapeEditor(); + var vertices = slabShapeEditor.SlabShapeVertices; + toSpeckle.points = vertices.Cast() + .Select(x => PointToSpeckle(x.Position, Doc)) + .ToList(); + + var sketch = Doc.GetElement(topoSolid.SketchId) as Sketch; + toSpeckle.profiles = GetSketchProfiles(sketch); + + var type = topoSolid.Document.GetElement(topoSolid.GetTypeId()) as ElementType; + + toSpeckle.level = ConvertAndCacheLevel(topoSolid, BuiltInParameter.LEVEL_PARAM); + toSpeckle.family = type?.FamilyName; + toSpeckle.type = type?.Name; + + GetAllRevitParamsAndIds( + toSpeckle, + topoSolid, + new List + { + "LEVEL_PARAM", + } + ); + + toSpeckle.displayValue = GetElementDisplayValue( + topoSolid, + new Options() { DetailLevel = ViewDetailLevel.Fine }); + + GetHostedElements(toSpeckle, topoSolid, out List hostedNotes); + if (hostedNotes.Any()) + notes.AddRange(hostedNotes); + + return toSpeckle; + } + } +} + +#endif diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertView.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertView.cs index 9aaa72aa69..1a74af2d7d 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertView.cs +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertView.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text.RegularExpressions; using Autodesk.Revit.DB; +using Speckle.Core.Logging; using Speckle.Core.Kits; using Speckle.Core.Models; using DB = Autodesk.Revit.DB; diff --git a/Objects/Objects/BuiltElements/Revit/RevitToposolid.cs b/Objects/Objects/BuiltElements/Revit/RevitToposolid.cs new file mode 100644 index 0000000000..749332141b --- /dev/null +++ b/Objects/Objects/BuiltElements/Revit/RevitToposolid.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using Objects.Geometry; +using Objects.Utils; +using Speckle.Core.Kits; +using Speckle.Core.Models; + +namespace Objects.BuiltElements.Revit +{ + public class RevitToposolid : Base, IDisplayValue> + { + public RevitToposolid() { } + + [SchemaInfo("RevitToposolid", "Creates a Revit Toposolid", "Revit", "Architecture")] + public RevitToposolid( + Level level, + List profiles, + List topPlanePoints = null, + [SchemaParamInfo("Any nested elements that this floor might have")] + List elements = null, + List parameters = null + ) + { + this.profiles = profiles; + this.level = level; + this.points = topPlanePoints; + this.elements = elements; + this.parameters = parameters.ToBase(); + } + + public List profiles { get; set; } = new(); + + public List points { get; set; } = new(); + + [DetachProperty] public List elements { get; set; } + + [DetachProperty] public List displayValue { get; set; } + + public string family { get; set; } + public string type { get; set; } + public Level level { get; set; } + public Base parameters { get; set; } + } +} From de5d858277b4139fb3a8c11f0b5c68d7438d25b9 Mon Sep 17 00:00:00 2001 From: connorivy <43247197+connorivy@users.noreply.github.com> Date: Fri, 29 Sep 2023 09:52:54 -0500 Subject: [PATCH 06/49] Feat(ETABS) : receive gridlines (#2969) * wip gridline receiving * creates grids if grid system is existing * code cleanup * appears to be working * small logic improvements * move create grid to separate method * adjust tolerances * added documentation * rename file * don't override existing grid system properties --------- Co-authored-by: Connor Ivy --- .../ConverterCSIShared/ConverterCSI.cs | 5 + .../ConverterCSIShared.projitems | 3 + .../Models/DatabaseTableWrapper.cs | 61 +++++ .../Models/ETABSGridLineDefinitionTable.cs | 245 ++++++++++++++++++ .../Geometry/ConvertGridLines.cs | 16 +- .../Services/ToNativeScalingService.cs | 35 +++ Objects/Objects/Other/Transform.cs | 9 + 7 files changed, 365 insertions(+), 9 deletions(-) create mode 100644 Objects/Converters/ConverterCSI/ConverterCSIShared/Models/DatabaseTableWrapper.cs create mode 100644 Objects/Converters/ConverterCSI/ConverterCSIShared/Models/ETABSGridLineDefinitionTable.cs create mode 100644 Objects/Converters/ConverterCSI/ConverterCSIShared/Services/ToNativeScalingService.cs diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSI.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSI.cs index f9053b043c..52bb2ac2ee 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSI.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSI.cs @@ -1,4 +1,5 @@ using CSiAPIv1; +using Objects.BuiltElements; using Objects.Structural.Analysis; using Objects.Structural.CSI.Analysis; using Objects.Structural.CSI.Geometry; @@ -112,6 +113,7 @@ public bool CanConvertToNative(Base @object) case Load _: //case Geometry.Line line: case Node _: + case GridLine _: //case Model o: //case Property property: @@ -211,6 +213,9 @@ public object ConvertToNative(Base @object) case BuiltElements.Column o: CurveBasedElementToNative(o, o.baseLine, ref appObj); break; + case GridLine o: + GridLineToNative(o); + break; #endregion default: appObj.Update( diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSIShared.projitems b/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSIShared.projitems index 2c47d7b4cf..f0f03983ad 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSIShared.projitems +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSIShared.projitems @@ -16,6 +16,8 @@ + + @@ -55,5 +57,6 @@ + \ No newline at end of file diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Models/DatabaseTableWrapper.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Models/DatabaseTableWrapper.cs new file mode 100644 index 0000000000..b95f3a624c --- /dev/null +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Models/DatabaseTableWrapper.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using ConverterCSIShared.Services; +using CSiAPIv1; + +namespace ConverterCSIShared.Models +{ + internal abstract class DatabaseTableWrapper + { + public abstract string TableKey { get; } + protected readonly cSapModel cSapModel; + protected readonly ToNativeScalingService toNativeScalingService; + private int tableVersion; + protected string[] fieldKeysIncluded; + protected int numRecords; + private readonly List tableData; + + protected DatabaseTableWrapper(cSapModel cSapModel, ToNativeScalingService toNativeScalingService) + { + this.cSapModel = cSapModel; + this.toNativeScalingService = toNativeScalingService; + this.tableData = new List(GetTableData()); + } + private string[] GetTableData() + { + var tableData = Array.Empty(); + cSapModel.DatabaseTables.GetTableForEditingArray( + TableKey, + "this param does nothing", + ref tableVersion, + ref fieldKeysIncluded, + ref numRecords, + ref tableData + ); + return tableData; + } + + protected void AddRow(params string[] arguments) + { + if (arguments.Length != fieldKeysIncluded.Length) + { + throw new ArgumentException($"Method {nameof(AddRow)} was passed an array of length {arguments.Length}, but was expecting an array of length {fieldKeysIncluded.Length}"); + } + tableData.AddRange(arguments); + numRecords++; + } + + public void ApplyEditedTables() + { + var tableDataArray = tableData.ToArray(); + cSapModel.DatabaseTables.SetTableForEditingArray(TableKey, ref tableVersion, ref fieldKeysIncluded, numRecords, ref tableDataArray); + + int numFatalErrors = 0; + int numWarnMsgs = 0; + int numInfoMsgs = 0; + int numErrorMsgs = 0; + string importLog = ""; + cSapModel.DatabaseTables.ApplyEditedTables(false, ref numFatalErrors, ref numErrorMsgs, ref numWarnMsgs, ref numInfoMsgs, ref importLog); + } + } +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Models/ETABSGridLineDefinitionTable.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Models/ETABSGridLineDefinitionTable.cs new file mode 100644 index 0000000000..36ee8566e9 --- /dev/null +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Models/ETABSGridLineDefinitionTable.cs @@ -0,0 +1,245 @@ +#nullable enable +using System; +using ConverterCSIShared.Services; +using CSiAPIv1; +using Objects.BuiltElements; +using Objects.Geometry; +using Objects.Other; +using Speckle.Core.Logging; + +namespace ConverterCSIShared.Models +{ + /// + /// Encapsulates the logic dealing with creating and manipulating gridlines via the interactive database in ETABS + /// + internal class ETABSGridLineDefinitionTable : DatabaseTableWrapper + { + private const double gridTolerance = .001; // .05 degrees as radians + public override string TableKey => "Grid Definitions - Grid Lines"; + public static string?[] DefaultRow => new string?[] { + null, // Name : Grid System name + null, // LineType + null, // Id : Grid name + null, // Ordinate : Offset in the positive direction + null, // Angle : clockwise offset in degrees for polar (cylindrical) coordinates + null, // X1 + null, // Y1 + null, // X2 + null, // Y2 + "Start", // BubbleLoc + "Yes", // Visible + }; + public ETABSGridLineDefinitionTable(cSapModel cSapModel, ToNativeScalingService toNativeScalingService) + : base(cSapModel, toNativeScalingService) { } + + public const string XGridLineType = "X (Cartesian)"; + public const string YGridLineType = "Y (Cartesian)"; + public const string RGridLineType = "R (Cylindrical)"; + public const string TGridLineType = "T (Cylindrical)"; + + /// + /// Add a gridline that is represented by a straight line to the ETABS document + /// + /// + /// + /// + /// + /// + /// + public void AddCartesian( + string gridSystemName, + string gridLineType, + string gridName, + double location, + string visible = "Yes" + ) + { + if (gridLineType != XGridLineType && gridLineType != YGridLineType) + { + throw new ArgumentException($"Argument gridLineType must be either {XGridLineType} or {YGridLineType}"); + } + var newRow = new string?[fieldKeysIncluded.Length]; + for (var index = 0; index < fieldKeysIncluded.Length; index++) + { + newRow[index] = fieldKeysIncluded[index] switch + { + "Name" => gridSystemName, + "LineType" => gridLineType, + "ID" => gridName, + "Ordinate" => location.ToString(), + "Visible" => visible, + _ => DefaultRow[index], + }; + } + + AddRow(newRow); + } + + /// + /// Add a gridline that is represented by a straight line to the ETABS document + /// + /// + /// + /// + public void AddCartesian(GridLine gridLine) + { + if (gridLine.baseLine is not Line line) + { + throw new ArgumentException("Non line based gridlines are not supported"); + } + + var gridRotation = GetAngleOffsetFromGlobalCoordinateSystem(line); + + var gridSystem = GetExistingGridSystem(gridRotation) ?? CreateGridSystem(gridRotation); + var transform = GetTransformFromGridSystem(gridSystem); + _ = line.TransformTo(transform.Inverse(), out Line transformedLine); + + var newUx = Math.Abs(transformedLine.start.x - transformedLine.end.x); + var newUy = Math.Abs(transformedLine.start.y - transformedLine.end.y); + + string lineType; + double gridLineOffset; + if (newUx < gridTolerance) + { + lineType = XGridLineType; + gridLineOffset = toNativeScalingService + .ScaleLength(transformedLine.start.x, transformedLine.units ?? transformedLine.start.units); + } + else if (newUy < gridTolerance) + { + lineType = YGridLineType; + gridLineOffset = toNativeScalingService + .ScaleLength(transformedLine.start.y, transformedLine.units ?? transformedLine.start.units); + } + else + { + throw new SpeckleException($"Error in transforming line from global coordinates to grid system with rotation {gridSystem.Rotation} and x,y offsets {gridSystem.XOrigin}, {gridSystem.YOrigin}"); + } + + AddCartesian(gridSystem.Name, lineType, gridLine.label, gridLineOffset); + } + + /// + /// Returns the rotation counter-clockwise from from the global x axis in radians + /// + /// + /// + private static double GetAngleOffsetFromGlobalCoordinateSystem(Line line) + { + var ux = line.start.x - line.end.x; + var uy = line.start.y - line.end.y; + + if (Math.Abs(ux) < gridTolerance) + { + return Math.PI / 2; + } + return Math.Atan(uy / ux); + } + + /// + /// Find a GridSystem in the CSi model whose local x axis is either parallel or perpendicular to the provided + /// grid angle. + /// + /// Rotation counter-clockwise from the global x axis in radians + /// + private GridSystemRepresentation? GetExistingGridSystem(double gridRotation) + { + var numGridSys = 0; + var gridSysNames = Array.Empty(); + this.cSapModel.GridSys.GetNameList(ref numGridSys, ref gridSysNames); + + var xOrigin = 0.0; + var yOrigin = 0.0; + var rotationDeg = 0.0; + foreach (var gridSysName in gridSysNames) + { + var success = cSapModel.GridSys.GetGridSys(gridSysName, ref xOrigin, ref yOrigin, ref rotationDeg); + if (success != 0) + { + // something went wrong. This is not necessarily unexpected or bad + continue; + } + + var rotationRad = rotationDeg * Math.PI / 180; + var combinedRotationsNormalized = Math.Abs((rotationRad - gridRotation) / (Math.PI / 2)); + var combinedRotationsRemainder = combinedRotationsNormalized - Math.Floor(combinedRotationsNormalized); + + if (combinedRotationsRemainder < gridTolerance || combinedRotationsRemainder > 1 - gridTolerance) + { + return new GridSystemRepresentation(gridSysName, xOrigin, yOrigin, rotationRad); + } + } + // could not find compatible existing grid system + return null; + } + + private GridSystemRepresentation CreateGridSystem(double gridRotation) + { + var systemName = GetUniqueGridSystemName(); + _ = cSapModel.GridSys.SetGridSys(systemName, 0, 0, gridRotation * 180 / Math.PI); + + // when a grid system is created, it doesn't show up unless it has at least one grid in each direction + AddCartesian(systemName, XGridLineType, "Default0", 0, "No"); + AddCartesian(systemName, YGridLineType, "Default1", 0, "No"); + return new GridSystemRepresentation(systemName, 0, 0, gridRotation); + } + + /// + /// Returns a unique name to be used for a new speckle-created grid system. + /// + /// + private string GetUniqueGridSystemName() + { + var numGridSys = 0; + var gridSysNames = Array.Empty(); + this.cSapModel.GridSys.GetNameList(ref numGridSys, ref gridSysNames); + + var numberOfGridSystems = 0; + var gridSystemNamePrefix = "SpeckleGridSystem"; + foreach (var gridSysName in gridSysNames) + { + // test if this grid system is one that we already created. If it is, then we need to adjust our + // numberOfGridSystems so that if we do end up creating a new one, it doesn't override an existing one. + if (!gridSysName.StartsWith(gridSystemNamePrefix)) + { + continue; + } + + if (int.TryParse(gridSysName.Replace(gridSystemNamePrefix, ""), out int gridSysNum)) + { + numberOfGridSystems = Math.Max(numberOfGridSystems, gridSysNum + 1); + } + } + return $"{gridSystemNamePrefix}{numberOfGridSystems}"; ; + } + + private static Transform GetTransformFromGridSystem(GridSystemRepresentation sys) + { + return new Transform( + new double[] + { + Math.Cos(sys.Rotation), -Math.Sin(sys.Rotation), 0, sys.XOrigin, + Math.Sin(sys.Rotation), Math.Cos(sys.Rotation), 0, sys.YOrigin, + 0, 0, 1, 0, + 0, 0, 0, 1 + } + ); + } + } + + public class GridSystemRepresentation + { + public GridSystemRepresentation(string name, double xOrigin, double yOrigin, double rotation) + { + Name = name; + XOrigin = xOrigin; + YOrigin = yOrigin; + Rotation = rotation; + } + + public string Name { get; } + public double XOrigin { get; set; } + public double YOrigin { get; set; } + public double Rotation { get; set; } + } +} diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertGridLines.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertGridLines.cs index d1d022975f..b11fd91f98 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertGridLines.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Geometry/ConvertGridLines.cs @@ -1,22 +1,20 @@ -using System; +using System; using System.Collections.Generic; using Objects.Geometry; -using Objects.Structural.Geometry; -using Objects.Structural.Analysis; -using Speckle.Core.Models; using Objects.Structural.CSI.Geometry; -using Objects.Structural.CSI.Properties; using Objects.BuiltElements; -using System.Linq; -using CSiAPIv1; +using ConverterCSIShared.Models; namespace Objects.Converter.CSI { public partial class ConverterCSI { - public void gridLinesToNative(CSIGridLines gridlines) + private ETABSGridLineDefinitionTable gridLineDefinitionTable; + private ETABSGridLineDefinitionTable GridLineDefinitionTable => gridLineDefinitionTable ??= new(Model, new(Model)); + public void GridLineToNative(GridLine gridline) { - throw new NotSupportedException(); + GridLineDefinitionTable.AddCartesian(gridline); + GridLineDefinitionTable.ApplyEditedTables(); } public CSIGridLines gridLinesToSpeckle(string name) diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Services/ToNativeScalingService.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Services/ToNativeScalingService.cs new file mode 100644 index 0000000000..21951aeaa6 --- /dev/null +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Services/ToNativeScalingService.cs @@ -0,0 +1,35 @@ +#nullable enable +using System; +using CSiAPIv1; +using Speckle.Core.Kits; + +namespace ConverterCSIShared.Services +{ + public class ToNativeScalingService + { + public ToNativeScalingService(cSapModel cSapModel) + { + var unitsArray = cSapModel.GetPresentUnits().ToString().Split('_'); + + ForceUnits = unitsArray[0]; + LengthUnits = unitsArray[1]; + TempuratureUnits = unitsArray[2]; + } + + public string LengthUnits { get; private set; } + public string ForceUnits { get; private set; } + public string TempuratureUnits { get; private set; } + + /// + /// Scales a value from a length unit of a specified power to the native length unit to the same power + /// + /// + /// + /// + /// + public double ScaleLength(double value, string speckleUnits, int power = 1) + { + return value * Math.Pow(Units.GetConversionFactor(speckleUnits, LengthUnits), power); + } + } +} diff --git a/Objects/Objects/Other/Transform.cs b/Objects/Objects/Other/Transform.cs index 3ca5938e07..2a1b130365 100644 --- a/Objects/Objects/Other/Transform.cs +++ b/Objects/Objects/Other/Transform.cs @@ -214,6 +214,15 @@ public double[] ConvertToUnits(string newUnits) }; } + public Transform Inverse() + { + if (Matrix4x4.Invert(matrix, out var transformed)) + { + return new Transform(transformed); + } + throw new SpeckleException("Could not create inverse transform"); + } + /// /// Returns the matrix that results from multiplying two matrices together. /// From 66630457c826b50e98ab6b48cbde72c05e75b9a5 Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Mon, 2 Oct 2023 11:45:25 +0200 Subject: [PATCH 07/49] fix(rvt): Fixes curve extraction method for Ceilings and Floors (#2973) * fix(rvt): Fix floor curve extraction * fix(rvt): Fix curve extraction in Ceilings --- .../Partial Classes/ConvertCeiling.cs | 6 ++++- .../Partial Classes/ConvertFloor.cs | 26 +++++++++++++++++-- .../Partial Classes/ConvertToposolid.cs | 15 ----------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertCeiling.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertCeiling.cs index 32fbbde875..458c8ce302 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertCeiling.cs +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertCeiling.cs @@ -15,8 +15,12 @@ public partial class ConverterRevit private RevitCeiling CeilingToSpeckle(DB.Ceiling revitCeiling, out List notes) { notes = new List(); +#if REVIT2020 || REVIT2021 var profiles = GetProfiles(revitCeiling); - +#else + var sketch = Doc.GetElement(revitCeiling.SketchId) as Sketch; + var profiles = GetSketchProfiles(sketch).Cast().ToList(); +#endif var speckleCeiling = new RevitCeiling(); speckleCeiling.type = revitCeiling.Document.GetElement(revitCeiling.GetTypeId()).Name; speckleCeiling.outline = profiles[0]; diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertFloor.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertFloor.cs index 56d4bd46a0..c760063574 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertFloor.cs +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertFloor.cs @@ -73,6 +73,7 @@ public ApplicationObject FloorToNative(BuiltElements.Floor speckleFloor) Doc.Delete(docObj.Id); DB.Floor revitFloor = null; + #if (REVIT2020 || REVIT2021) if (floorType == null) { @@ -138,9 +139,13 @@ public ApplicationObject FloorToNative(BuiltElements.Floor speckleFloor) private RevitFloor FloorToSpeckle(DB.Floor revitFloor, out List notes) { notes = new List(); - var profiles = GetProfiles(revitFloor); - var speckleFloor = new RevitFloor(); + #if REVIT2020 || REVIT2021 + var profiles = GetProfiles(revitFloor); + #else + var sketch = Doc.GetElement(revitFloor.SketchId) as Sketch; + var profiles = GetSketchProfiles(sketch).Cast().ToList(); + #endif var type = revitFloor.Document.GetElement(revitFloor.GetTypeId()) as ElementType; speckleFloor.family = type?.FamilyName; speckleFloor.type = type?.Name; @@ -441,5 +446,22 @@ private ICurve GetFlattenedCurve(ICurve curve, double z) } throw new NotSupportedException($"Trying to flatten unsupported curve type, {curve.GetType()}"); } + + + public List GetSketchProfiles(Sketch sketch) + { + var profiles = new List(); + foreach (CurveArray curves in sketch.Profile) + { + var curveLoop = CurveArrayToCurveLoop(curves); + profiles.Add(new OG.Polycurve + { + segments = curveLoop.Select(x => CurveToSpeckle(x, sketch.Document)).ToList() + }); + } + + return profiles; + } + } } diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertToposolid.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertToposolid.cs index 6188258e06..f4fc692887 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertToposolid.cs +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertToposolid.cs @@ -62,22 +62,7 @@ public ApplicationObject ToposolidToNative(RevitToposolid fromSpeckle) return appObj; } - - private List GetSketchProfiles(Sketch sketch) - { - var profiles = new List(); - foreach (CurveArray curves in sketch.Profile) - { - var curveLoop = CurveArrayToCurveLoop(curves); - profiles.Add(new OG.Polycurve - { - segments = curveLoop.Select(x => CurveToSpeckle(x, sketch.Document)).ToList() - }); - } - return profiles; - } - private RevitToposolid ToposolidToSpeckle(Toposolid topoSolid, out List notes) { var toSpeckle = new RevitToposolid(); From 35ac50720b9afb1acf799620c19c68974d02fb7a Mon Sep 17 00:00:00 2001 From: Claire Kuang Date: Mon, 2 Oct 2023 11:02:56 +0100 Subject: [PATCH 08/49] fix(rhino): default to using speckle id when creating render materials with no name (#2974) Update ConverterRhinoGh.Other.cs --- .../ConverterRhinoGhShared/ConverterRhinoGh.Other.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.Other.cs b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.Other.cs index 5db065c0d3..eb3df495a5 100644 --- a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.Other.cs +++ b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.Other.cs @@ -133,8 +133,8 @@ public DisplayStyle DisplayStyleToSpeckle(RH.ObjectAttributes attributes, RH.Lay public RenderMaterial RenderMaterialToNative(Other.RenderMaterial speckleMaterial) { var commitInfo = GetCommitInfo(); - var speckleName = - ReceiveMode == ReceiveMode.Create ? $"{commitInfo} - {speckleMaterial.name}" : $"{speckleMaterial.name}"; + var name = speckleMaterial.name ?? speckleMaterial.id; + var speckleName = ReceiveMode == ReceiveMode.Create ? $"{commitInfo} - {name}" : $"{name}"; // check if the doc already has a material with speckle material name, or a previously created speckle material //NOTE: Looking up renderMaterials this way is slow, maybe we can create a dictionary? From 6ea3541fa75f2fd63efd8b058236ecbe221b8a4c Mon Sep 17 00:00:00 2001 From: Claire Kuang Date: Mon, 2 Oct 2023 11:35:52 +0100 Subject: [PATCH 09/49] feat(autocad/rhino): adds gridline to native conversion (#2963) * adds gridline conversions to autocad and rhino * adds dashed line style and textdots to gridline * Update ConverterRhinoGh.BuiltElements.cs --------- Co-authored-by: Alan Rynne --- .../UI/ConnectorBindingsRhino.Previews.cs | 1 + .../UI/ConnectorBindingsRhino.Receive.cs | 2 +- .../ConverterAutocadCivil.cs | 9 +++- .../ConverterRhinoGh.BuiltElements.cs | 50 +++++++++++++++++++ .../ConverterRhinoGh.cs | 6 ++- 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Previews.cs b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Previews.cs index fda4f2f307..c574d8ad1e 100644 --- a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Previews.cs +++ b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Previews.cs @@ -89,6 +89,7 @@ private static bool IsPreviewIgnore(Base @object) return @object.speckle_type.Contains("Instance") || @object.speckle_type.Contains("View") || @object.speckle_type.Contains("Level") + || @object.speckle_type.Contains("GridLine") || @object.speckle_type.Contains("Collection"); } diff --git a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Receive.cs b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Receive.cs index bf808fad9a..4a490669dd 100644 --- a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Receive.cs +++ b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.Receive.cs @@ -596,7 +596,7 @@ private void SetUserInfo(Base obj, ObjectAttributes attributes, ApplicationObjec if (obj[UserDictionary] is Base userDictionary) ParseDictionaryToArchivable(attributes.UserDictionary, userDictionary); - var name = obj["name"] as string; + var name = obj["name"] as string ?? obj["label"] as string; // gridlines have a "label" prop instead of name? if (name != null) attributes.Name = name; } diff --git a/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.cs b/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.cs index 5c2613702a..df6f5c5f21 100644 --- a/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.cs +++ b/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.cs @@ -1,5 +1,6 @@ using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; +using Objects.BuiltElements; using Objects.Other; using Objects.Structural.Properties.Profiles; using Speckle.Core.Kits; @@ -395,6 +396,10 @@ public object ConvertToNative(Base @object) acadObj = CurveToNativeDB(o.baseCurve); break; + case GridLine o: + acadObj = CurveToNativeDB(o.baseLine); + break; + default: if (reportObj != null) { @@ -491,7 +496,7 @@ public bool CanConvertToSpeckle(object @object) #if ADVANCESTEEL return CanConvertASToSpeckle(o); #else - return false; + return false; #endif } } @@ -524,7 +529,6 @@ public bool CanConvertToNative(Base @object) case Polyline _: case Polycurve _: case Curve _: - //case Brep _: case Mesh _: case Dimension _: @@ -535,6 +539,7 @@ public bool CanConvertToNative(Base @object) case Alignment _: case ModelCurve _: + case GridLine _: return true; default: diff --git a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs index 785db3d1fc..d75605e793 100644 --- a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs +++ b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs @@ -5,6 +5,7 @@ using System.Linq; using Objects.BuiltElements; using Objects.Geometry; +using Objects.Other; using Rhino; using Rhino.Display; using Rhino.DocObjects; @@ -206,6 +207,55 @@ public ApplicationObject LevelToNative(Level level) return appObj; } + // gridline + public ApplicationObject GridlineToNative(GridLine gridline) + { + var appObj = new ApplicationObject(gridline.id, gridline.speckle_type) { applicationId = gridline.applicationId }; + + // create the curve + var curve = CurveToNative(gridline.baseLine); + if (curve == null) + { + appObj.Update(status: ApplicationObject.State.Failed, logItem: "Could not convert curve"); + return appObj; + } + // get linetype + ObjectAttributes atts = null; + if (gridline["@displayStyle"] as DisplayStyle == null) + { + var linetypeIndex = Doc.Linetypes.Find("Dashed"); + if (linetypeIndex >= 0) + atts = new ObjectAttributes() + { + LinetypeIndex = linetypeIndex, + LinetypeSource = ObjectLinetypeSource.LinetypeFromObject + }; + } + + // bake the curve + Guid id = atts != null ? Doc.Objects.Add(curve, atts) : Doc.Objects.Add(curve); + if (id == Guid.Empty) + { + appObj.Update(status: ApplicationObject.State.Failed, logItem: "Could not add curve to doc"); + return appObj; + } + var _gridLine = Doc.Objects.FindId(id); + appObj.Update(convertedItem: _gridLine, createdId: id.ToString()); + + // create and bake two textdots at the endpoints of the curve + if (!string.IsNullOrEmpty(gridline.label)) + { + var labelStartId = Doc.Objects.AddTextDot(gridline.label, curve.PointAtStart); + if (labelStartId != Guid.Empty) + appObj.Update(convertedItem: Doc.Objects.FindId(labelStartId), createdId: labelStartId.ToString()); + var labelEndId = Doc.Objects.AddTextDot(gridline.label, curve.PointAtEnd); + if (labelEndId != Guid.Empty) + appObj.Update(convertedItem: Doc.Objects.FindId(labelEndId), createdId: labelEndId.ToString()); + } + + return appObj; + } + #region CIVIL // alignment diff --git a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs index 97539977cd..29c4e314bf 100644 --- a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs +++ b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.cs @@ -457,6 +457,10 @@ public object ConvertToNative(Base @object) rhinoObj = SurfaceToNative(o); break; + case GridLine o: + rhinoObj = GridlineToNative(o); + break; + case Alignment o: rhinoObj = AlignmentToNative(o); break; @@ -674,13 +678,13 @@ public bool CanConvertToNative(Base @object) case DirectShape _: case View3D _: case Instance _: + case GridLine _: case Alignment _: case Level _: case Text _: case Dimension _: case Collection c when !c.collectionType.ToLower().Contains("model"): return true; - #endif default: From 1be1d546bccf2abb56fd3d99756457e5d4a80703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20L=2E=20Kiss?= <50739844+jozseflkiss@users.noreply.github.com> Date: Tue, 17 Oct 2023 17:31:28 +0200 Subject: [PATCH 10/49] feat(Archicad, Revit): Room height (#2977) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Room height * check --------- Co-authored-by: József L. Kiss <> Co-authored-by: Alan Rynne --- .../ConverterRevitShared/Partial Classes/ConvertRoom.cs | 3 +++ Objects/Objects/BuiltElements/Room.cs | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertRoom.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertRoom.cs index d2e3e4d43b..aa461c27aa 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertRoom.cs +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/ConvertRoom.cs @@ -39,6 +39,9 @@ public ApplicationObject RoomToNative(Room speckleRoom) revitRoom.Name = speckleRoom.name; revitRoom.Number = speckleRoom.number; + if (speckleRoom.height > 0.0) + TrySetParam(revitRoom, BuiltInParameter.ROOM_UPPER_OFFSET, ScaleToNative(speckleRoom.height, speckleRoom.units)); + SetInstanceParameters(revitRoom, speckleRoom); var state = isUpdate ? ApplicationObject.State.Updated : ApplicationObject.State.Created; diff --git a/Objects/Objects/BuiltElements/Room.cs b/Objects/Objects/BuiltElements/Room.cs index 4924761480..224b266e1c 100644 --- a/Objects/Objects/BuiltElements/Room.cs +++ b/Objects/Objects/BuiltElements/Room.cs @@ -49,6 +49,7 @@ public Room( public string number { get; set; } virtual public Level level { get; set; } public Point basePoint { get; set; } + public double height { get; set; } public List voids { get; set; } = new(); public ICurve outline { get; set; } @@ -83,8 +84,6 @@ public override Level level set => archicadLevel = value as ArchicadLevel ?? null; } - public double height { get; set; } - public ElementShape shape { get; set; } } } From 814d327bf020dcb93e6c840bf679ea9ac6f85d8f Mon Sep 17 00:00:00 2001 From: Matteo Cominetti Date: Tue, 17 Oct 2023 16:36:00 +0100 Subject: [PATCH 11/49] feat: check if server is using fe2 (#2989) --- Core/Core/Api/GraphQL/Models.cs | 4 ++++ Core/Core/Credentials/AccountManager.cs | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Core/Core/Api/GraphQL/Models.cs b/Core/Core/Api/GraphQL/Models.cs index a00e9e400d..5bdba7cd73 100644 --- a/Core/Core/Api/GraphQL/Models.cs +++ b/Core/Core/Api/GraphQL/Models.cs @@ -383,6 +383,10 @@ public class ServerInfo public string version { get; set; } public string adminContact { get; set; } public string description { get; set; } + //NOTE: this field is not returned from the GQL API + //it is manually populated by checking against the response headers + //TODO: deprecate after the transition from fe1 to fe2 + public bool frontend2 { get; set; } } public class StreamData diff --git a/Core/Core/Credentials/AccountManager.cs b/Core/Core/Credentials/AccountManager.cs index 76c706360c..da5869cf4b 100644 --- a/Core/Core/Credentials/AccountManager.cs +++ b/Core/Core/Credentials/AccountManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -275,6 +276,7 @@ public static async Task UpdateAccounts() account.userInfo = userServerInfo.activeUser; account.serverInfo = userServerInfo.serverInfo; account.serverInfo.url = url; + account.serverInfo.frontend2 = await IsFrontend2Server(url).ConfigureAwait(false); } catch (Exception) { @@ -587,6 +589,29 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) } } + private static async Task IsFrontend2Server(string server) + { + try + { + using var client = Http.GetHttpProxyClient(); + var response = await client.GetAsync(server).ConfigureAwait(false); + + if (response.Headers.TryGetValues("x-speckle-frontend-2", out IEnumerable values)) + { + if (values.Any() && bool.Parse(values.FirstOrDefault())) + { + return true; + } + } + + return false; + } + catch (Exception e) + { + return false; + } + } + private static string GenerateChallenge() { using (RandomNumberGenerator rng = new RNGCryptoServiceProvider()) From 1b1bae5e53c961f3ae0361397fb7dabf230c2047 Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Tue, 17 Oct 2023 17:46:00 +0200 Subject: [PATCH 12/49] feat(core): Adds SpeckleLogConfig input to Setup.Initialize (#2994) --- Core/Core/Logging/Setup.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Core/Core/Logging/Setup.cs b/Core/Core/Logging/Setup.cs index 01edc37053..61294e2056 100644 --- a/Core/Core/Logging/Setup.cs +++ b/Core/Core/Logging/Setup.cs @@ -40,7 +40,11 @@ static Setup() /// internal static string VersionedHostApplication { get; private set; } = HostApplications.Other.Slug; - public static void Init(string versionedHostApplication, string hostApplication) + public static void Init( + string versionedHostApplication, + string hostApplication, + SpeckleLogConfiguration logConfiguration = null + ) { if (_initialized) { @@ -63,7 +67,7 @@ public static void Init(string versionedHostApplication, string hostApplication) //start mutex so that Manager can detect if this process is running mutex = new Mutex(false, "SpeckleConnector-" + hostApplication); - SpeckleLog.Initialize(hostApplication, versionedHostApplication); + SpeckleLog.Initialize(hostApplication, versionedHostApplication, logConfiguration); foreach (var account in AccountManager.GetAccounts()) Analytics.AddConnectorToProfile(account.GetHashedEmail(), hostApplication); From 4cc928d1141b106f067b8d8c80d2957ec9348209 Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Tue, 17 Oct 2023 20:55:32 +0200 Subject: [PATCH 13/49] fix(CSI): Fixes missing materials on receive (#2988) * fix(csi): Ensure material creation in Property2D conversion to native * feat(csi): Add structural material top-level conversion support --- .../ConverterCSIShared/ConverterCSI.cs | 7 +++++ .../Properties/Convert2DPropertyFloor.cs | 26 ++++--------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSI.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSI.cs index 52bb2ac2ee..8d4aa14154 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSI.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/ConverterCSI.cs @@ -13,6 +13,8 @@ using System; using System.Collections.Generic; using System.Linq; +using Objects.Other; +using Objects.Structural.Materials; using OSG = Objects.Structural.Geometry; namespace Objects.Converter.CSI @@ -123,6 +125,7 @@ public bool CanConvertToNative(Base @object) case BuiltElements.Beam _: case BuiltElements.Brace _: case BuiltElements.Column _: + case StructuralMaterial _: return true; } ; @@ -203,6 +206,10 @@ public object ConvertToNative(Base @object) case Property1D o: Property1DToNative(o, ref appObj); break; + case StructuralMaterial o: + // Material conversion does not return an app object + MaterialToNative(o); + break; #region BuiltElements case BuiltElements.Beam o: CurveBasedElementToNative(o, o.baseLine, ref appObj); diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyFloor.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyFloor.cs index afb840dfc8..72aba30fbc 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyFloor.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Partial Classes/Properties/Convert2DPropertyFloor.cs @@ -14,6 +14,8 @@ public partial class ConverterCSI public string FloorPropertyToNative(CSIProperty2D property2D) { int? success = null; + var materialName = MaterialToNative(property2D.material); + if (property2D.deckType != Structural.CSI.Analysis.DeckType.Null) { SetDeck(property2D); @@ -66,24 +68,12 @@ public string FloorPropertyToNative(CSIProperty2D property2D) case Structural.CSI.Analysis.SlabType.Slab: var SolidSlab = property2D; var shell = shellType(SolidSlab); - success = Model.PropArea.SetSlab( - SolidSlab.name, - eSlabType.Slab, - shell, - SolidSlab.material.name, - SolidSlab.thickness - ); + success = Model.PropArea.SetSlab(SolidSlab.name, eSlabType.Slab, shell, materialName, SolidSlab.thickness); break; case Structural.CSI.Analysis.SlabType.Ribbed: var slabRibbed = (CSIProperty2D.RibbedSlab)property2D; shell = shellType(slabRibbed); - Model.PropArea.SetSlab( - slabRibbed.name, - eSlabType.Ribbed, - shell, - slabRibbed.material.name, - slabRibbed.thickness - ); + Model.PropArea.SetSlab(slabRibbed.name, eSlabType.Ribbed, shell, materialName, slabRibbed.thickness); success = Model.PropArea.SetSlabRibbed( slabRibbed.name, slabRibbed.OverAllDepth, @@ -97,13 +87,7 @@ public string FloorPropertyToNative(CSIProperty2D property2D) case Structural.CSI.Analysis.SlabType.Waffle: var slabWaffled = (CSIProperty2D.WaffleSlab)property2D; shell = shellType(slabWaffled); - Model.PropArea.SetSlab( - slabWaffled.name, - eSlabType.Waffle, - shell, - slabWaffled.material.name, - slabWaffled.thickness - ); + Model.PropArea.SetSlab(slabWaffled.name, eSlabType.Waffle, shell, materialName, slabWaffled.thickness); success = Model.PropArea.SetSlabWaffle( slabWaffled.name, slabWaffled.OverAllDepth, From 9773ea042f41846a542d9233674eaa976b4966fd Mon Sep 17 00:00:00 2001 From: Matteo Cominetti Date: Mon, 23 Oct 2023 09:03:22 +0100 Subject: [PATCH 14/49] feat(dui): better fe2 compatibility (#2991) * wip: moves fe2 button toggle * feat: check if server is using fe2 * feat(dui): autodetect fe2 streams, more string replacements * fix(dui): handle fe2 model ids coming from the stream wrapper class --- .../DesktopUI2/ViewModels/CommentViewModel.cs | 3 +- .../DesktopUI2/ViewModels/DialogViewModel.cs | 21 +++++++++ .../DesktopUI2/ViewModels/HomeViewModel.cs | 5 +-- .../DesktopUI2/ViewModels/StreamViewModel.cs | 39 +++++++++++------ .../Controls/StreamEditControls/Comments.xaml | 3 +- .../DesktopUI2/Views/Pages/HomeView.xaml | 43 ++++++++++++++++--- .../Windows/Dialogs/AddAccountDialog.xaml.cs | 2 + .../Windows/Dialogs/AddFromUrlDialog.xaml | 10 +++-- .../Windows/Dialogs/AddFromUrlDialog.xaml.cs | 2 + .../Windows/Dialogs/NewStreamDialog.xaml | 12 ++++-- .../Windows/Dialogs/NewStreamDialog.xaml.cs | 1 + 11 files changed, 109 insertions(+), 32 deletions(-) create mode 100644 DesktopUI2/DesktopUI2/ViewModels/DialogViewModel.cs diff --git a/DesktopUI2/DesktopUI2/ViewModels/CommentViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/CommentViewModel.cs index ff05cfc36c..d391c8a24c 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/CommentViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/CommentViewModel.cs @@ -122,8 +122,7 @@ public void OpenComment() var url = $"{_client.Account.serverInfo.url}/streams/{StreamId}/{r0.resourceType}s/{r0.resourceId}?cId={Comment.id}{overlay}"; - var config = ConfigManager.Load(); - if (config.UseFe2) + if (_client.Account.serverInfo.frontend2) url = $"{_client.Account.serverInfo.url}/projects/{StreamId}/"; Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); diff --git a/DesktopUI2/DesktopUI2/ViewModels/DialogViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/DialogViewModel.cs new file mode 100644 index 0000000000..308c04a518 --- /dev/null +++ b/DesktopUI2/DesktopUI2/ViewModels/DialogViewModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; +using DesktopUI2.Models; +using ReactiveUI; + +namespace DesktopUI2.ViewModels +{ + public class DialogViewModel : ReactiveObject + { + //UI Binding + public bool UseFe2 + { + get + { + var config = ConfigManager.Load(); + return config.UseFe2; + } + } + } +} diff --git a/DesktopUI2/DesktopUI2/ViewModels/HomeViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/HomeViewModel.cs index 4c6569fb23..35058323db 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/HomeViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/HomeViewModel.cs @@ -492,8 +492,6 @@ private void GenerateMenuItems() new MenuItemViewModel(ToggleDarkThemeCommand, "Toggle dark/light theme", MaterialIconKind.SunMoonStars) ); - menu.Items.Add(new MenuItemViewModel(ToggleFe2Command, "Toggle NEW Frontend support", MaterialIconKind.NewBox)); - #if DEBUG menu.Items.Add(new MenuItemViewModel(TestCommand, "Test stuff", MaterialIconKind.Bomb)); #endif @@ -579,7 +577,7 @@ public void ViewOnlineCommand(object parameter) var streamAcc = parameter as StreamAccountWrapper; var url = $"{streamAcc.Account.serverInfo.url.TrimEnd('/')}/streams/{streamAcc.Stream.id}"; - if (UseFe2) + if (streamAcc.Account.serverInfo.frontend2) url = $"{streamAcc.Account.serverInfo.url.TrimEnd('/')}/projects/{streamAcc.Stream.id}"; Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); @@ -940,6 +938,7 @@ public List FilteredStreams public bool HasSavedStreams => SavedStreams != null && SavedStreams.Any(); public bool HasStreams => FilteredStreams != null && FilteredStreams.Any(); + //UI Binding public bool UseFe2 { get diff --git a/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs index 66e2a30c1e..1336a190fa 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs @@ -94,8 +94,7 @@ private string Url { get { - var config = ConfigManager.Load(); - if (config.UseFe2) + if (Client.Account.serverInfo.frontend2) { //sender if (!IsReceiver) @@ -251,11 +250,25 @@ internal async void GetBranchesAndRestoreState() Branches = await Client.StreamGetBranches(Stream.id, 100, 0).ConfigureAwait(true); - var index = Branches.FindIndex(x => x.name == StreamState.BranchName); + //TODO: Core's API calls and the StreamWrapper class need to be updated to properly support FE2 links + //this is a temporary workaround + var index = -1; + if (UseFe2) + { + index = Branches.FindIndex(x => x.id == StreamState.BranchName); + } + else + { + index = Branches.FindIndex(x => x.name == StreamState.BranchName); + } if (index != -1) + { SelectedBranch = BranchesViewModel[index]; + } else + { SelectedBranch = BranchesViewModel[0]; + } //restore selected filter if (StreamState.Filter != null) @@ -592,6 +605,15 @@ public string LastUsed } } + //UI Binding + public bool UseFe2 + { + get + { + return Client.Account.serverInfo.frontend2; + } + } + public DateTime? LastUsedTime { get => StreamState.LastUsed; @@ -602,14 +624,6 @@ public DateTime? LastUsedTime } } - public bool UseFe2 - { - get - { - var config = ConfigManager.Load(); - return config.UseFe2; - } - } private bool _isRemovingStream; @@ -1305,8 +1319,7 @@ public async void SendCommand() OnClick = () => { var url = $"{StreamState.ServerUrl}/streams/{StreamState.StreamId}/commits/{commitId}"; - var config = ConfigManager.Load(); - if (config.UseFe2) + if (Client.Account.serverInfo.frontend2) url = $"{StreamState.ServerUrl}/projects/{StreamState.StreamId}/models/{SelectedBranch.Branch.id}"; OpenUrl(url); }, diff --git a/DesktopUI2/DesktopUI2/Views/Controls/StreamEditControls/Comments.xaml b/DesktopUI2/DesktopUI2/Views/Controls/StreamEditControls/Comments.xaml index fd1eb3f533..791dd95c21 100644 --- a/DesktopUI2/DesktopUI2/Views/Controls/StreamEditControls/Comments.xaml +++ b/DesktopUI2/DesktopUI2/Views/Controls/StreamEditControls/Comments.xaml @@ -18,6 +18,7 @@ + @@ -26,7 +27,7 @@ IsVisible="{Binding !Comments.Count}" Orientation="Vertical" Spacing="20"> - +