From fbe528ff2ccdadbbd176afbac93147c7d549ab53 Mon Sep 17 00:00:00 2001 From: Claire Kuang Date: Mon, 5 Sep 2022 15:52:10 +0100 Subject: [PATCH] fix(dui2/rhino): preview and report bugs (#1582) * preview bug fixes for rhino * updated all connector bindings * Update ConnectorBindingsTeklaStructure.Send.cs --- .../ConnectorArchicad/ConnectorBinding.cs | 5 +- .../UI/ConnectorBindingsAutocadCivil.cs | 3 +- .../UI/ConnectorBindingsCSI.Recieve.cs | 2 +- .../UI/ConnectorBindingsCSI.Send.cs | 1 + .../UI/Bindings2.cs | 23 +-- .../ConnectorBindingsRevit2.Receive.cs | 2 + .../ConnectorBindingsRevit2.Send.cs | 1 + .../UI/ConnectorBindingsRhino.cs | 156 +++++++++++++----- .../ConnectorBindingsTeklaStructure.Send.cs | 3 +- ...onnectorBindingsTeklaStructures.Receive.cs | 6 + ...nectorBindingsTeklaStructures.Selection.cs | 7 - DesktopUI2/DesktopUI2/ConnectorBindings.cs | 18 ++ DesktopUI2/DesktopUI2/DummyBindings.cs | 2 + .../DesktopUI2/ViewModels/StreamViewModel.cs | 15 +- .../ConverterRhinoGh.BuiltElements.cs | 7 +- 15 files changed, 187 insertions(+), 64 deletions(-) diff --git a/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs b/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs index 8b850cf5f1..4b070e95f6 100644 --- a/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs +++ b/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs @@ -98,10 +98,10 @@ public override List GetReceiveModes() return new List { ReceiveMode.Create }; } + public override bool CanPreviewReceive => false; public override Task PreviewReceive(StreamState state, ProgressViewModel progress) { return null; - // TODO! } public override async Task ReceiveStream(StreamState state, ProgressViewModel progress) @@ -120,9 +120,10 @@ public override void SelectClientObjects(List args, bool deselect = fals // TODO! } + public override bool CanPreviewSend => false; public override void PreviewSend(StreamState state, ProgressViewModel progress) { - // TODO! + return; } public override async Task SendStream(StreamState state, ProgressViewModel progress) { diff --git a/ConnectorAutocadCivil/ConnectorAutocadCivil/UI/ConnectorBindingsAutocadCivil.cs b/ConnectorAutocadCivil/ConnectorAutocadCivil/UI/ConnectorBindingsAutocadCivil.cs index 068dcfe7c7..c98012089f 100644 --- a/ConnectorAutocadCivil/ConnectorAutocadCivil/UI/ConnectorBindingsAutocadCivil.cs +++ b/ConnectorAutocadCivil/ConnectorAutocadCivil/UI/ConnectorBindingsAutocadCivil.cs @@ -187,10 +187,10 @@ public override async Task>> ImportFamilyC #endregion #region receiving + public override bool CanPreviewReceive => false; public override async Task PreviewReceive(StreamState state, ProgressViewModel progress) { return null; - // TODO! } public override async Task ReceiveStream(StreamState state, ProgressViewModel progress) { @@ -549,6 +549,7 @@ private bool GetOrMakeLayer(string layerName, Transaction tr, out string cleanNa #endregion #region sending + public override bool CanPreviewSend => false; public override async void PreviewSend(StreamState state, ProgressViewModel progress) { // TODO! diff --git a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs index a527c65999..15962ca377 100644 --- a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs +++ b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Recieve.cs @@ -16,10 +16,10 @@ namespace Speckle.ConnectorCSI.UI { public partial class ConnectorBindingsCSI : ConnectorBindings { + public override bool CanPreviewReceive => false; public override Task PreviewReceive(StreamState state, ProgressViewModel progress) { return null; - // TODO! } public override async Task ReceiveStream(StreamState state, ProgressViewModel progress) diff --git a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Send.cs b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Send.cs index 0b093b7b20..721dd2f2e1 100644 --- a/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Send.cs +++ b/ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Send.cs @@ -17,6 +17,7 @@ namespace Speckle.ConnectorCSI.UI { public partial class ConnectorBindingsCSI : ConnectorBindings { + public override bool CanPreviewSend => false; public override void PreviewSend(StreamState state, ProgressViewModel progress) { // TODO! diff --git a/ConnectorMicroStation/ConnectorMicroStationOpenShared/UI/Bindings2.cs b/ConnectorMicroStation/ConnectorMicroStationOpenShared/UI/Bindings2.cs index 202d7a5cc6..a7a4fb270a 100644 --- a/ConnectorMicroStation/ConnectorMicroStationOpenShared/UI/Bindings2.cs +++ b/ConnectorMicroStation/ConnectorMicroStationOpenShared/UI/Bindings2.cs @@ -198,6 +198,12 @@ public override async Task>> ImportFamilyC #endregion #region receiving + public override bool CanPreviewReceive => false; + public override Task PreviewReceive(StreamState state, ProgressViewModel progress) + { + return null; + } + public override async Task ReceiveStream(StreamState state, ProgressViewModel progress) { var kit = KitManager.GetDefaultKit(); @@ -444,6 +450,12 @@ private void DeleteObjects(List previouslyReceiveObjects, Lis #endregion #region sending + public override bool CanPreviewSend => false; + public override void PreviewSend(StreamState state, ProgressViewModel progress) + { + return; + } + public override async Task SendStream(StreamState state, ProgressViewModel progress) { var kit = KitManager.GetDefaultKit(); @@ -850,17 +862,6 @@ public override void ResetDocument() { // TODO! } - - public override void PreviewSend(StreamState state, ProgressViewModel progress) - { - // TODO! - } - - public override Task PreviewReceive(StreamState state, ProgressViewModel progress) - { - return null; - // TODO! - } #endregion } } \ No newline at end of file diff --git a/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Receive.cs b/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Receive.cs index d2123b5f50..ecc7813750 100644 --- a/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Receive.cs +++ b/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Receive.cs @@ -25,6 +25,8 @@ public partial class ConnectorBindingsRevit2 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; diff --git a/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Send.cs b/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Send.cs index 47b238cdb0..ad65bb1fbd 100644 --- a/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Send.cs +++ b/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit2/ConnectorBindingsRevit2.Send.cs @@ -18,6 +18,7 @@ public partial class ConnectorBindingsRevit2 { // used to store the Stream State settings when sending/receiving private List CurrentSettings { get; set; } + public override bool CanPreviewSend => true; public override void PreviewSend(StreamState state, ProgressViewModel progress) { diff --git a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.cs b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.cs index 04a79e697e..0a347f8224 100644 --- a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.cs +++ b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/ConnectorBindingsRhino.cs @@ -40,7 +40,6 @@ public partial class ConnectorBindingsRhino : ConnectorBindings private static string UserStrings = "userStrings"; private static string UserDictionary = "userDictionary"; - public ISpeckleConverter Converter { get; set; } = KitManager.GetDefaultKit().LoadConverter(Utils.RhinoAppName); public Dictionary StoredObjects = new Dictionary(); public List Preview { get; set; } = new List(); public PreviewConduit PreviewConduit { get; set; } @@ -142,10 +141,10 @@ private void LogUnsupportedObjects(List objs, ISpeckleConverter con public override List GetSelectedObjects() { var objs = new List(); - if (Doc == null) return objs; - - Converter.SetContextDocument(Doc); + var Converter = KitManager.GetDefaultKit().LoadConverter(Utils.RhinoAppName); + if (Converter == null || Doc == null) return objs; + var selected = Doc.Objects.GetSelectedObjects(true, false).ToList(); if (selected.Count == 0) return objs; var supportedObjs = selected.Where(o => Converter.CanConvertToSpeckle(o) == true)?.ToList(); @@ -226,8 +225,9 @@ public override void ResetDocument() { if (PreviewConduit != null) PreviewConduit.Enabled = false; + else + Doc.Objects.UnselectAll(true); - Doc.Objects.UnselectAll(true); // TODO: consider instead of unselecting, storing doc visibility state and restoring to this point Doc.Views.Redraw(); } @@ -240,13 +240,21 @@ public override async Task>> ImportFamilyC #endregion #region receiving + public override bool CanPreviewReceive => true; public override async Task PreviewReceive(StreamState state, ProgressViewModel progress) { // first check if commit is the same and preview objects have already been generated Commit commit = await GetCommitFromState(state, progress); + progress.Report = new ProgressReport(); if (commit.id != SelectedReceiveCommit) { + // check for converter + var converter = KitManager.GetDefaultKit().LoadConverter(Utils.RhinoAppName); + if (converter == null) + throw new Exception("Could not find any Kit!"); + converter.SetContextDocument(Doc); + var commitObject = await GetCommit(commit, state, progress); if (commitObject == null) { @@ -260,7 +268,7 @@ public override async Task PreviewReceive(StreamState state, Progre int count = 0; var commitLayerName = DesktopUI2.Formatting.CommitInfo(state.CachedStream.name, state.BranchName, commit.id); // get commit layer name - Preview = FlattenCommitObject(commitObject, commitLayerName, ref count); + Preview = FlattenCommitObject(commitObject, converter, commitLayerName, ref count); Doc.Notes += "%%%" + commitLayerName; // give converter a way to access commit layer info // Convert preview objects @@ -276,7 +284,7 @@ public override async Task PreviewReceive(StreamState state, Progre progress.Report.Log(previewObj); continue; } - previewObj.Converted = previewObj.Convertible ? ConvertObject(previewObj) : previewObj.Fallback.SelectMany(o => ConvertObject(o)).ToList(); + previewObj.Converted = previewObj.Convertible ? ConvertObject(previewObj, converter) : previewObj.Fallback.SelectMany(o => ConvertObject(o, converter)).ToList(); if (previewObj.Converted == null || previewObj.Converted.Count == 0) { @@ -290,12 +298,17 @@ public override async Task PreviewReceive(StreamState state, Progre } progress.Report.Log(previewObj); } - progress.Report.Merge(Converter.Report); + progress.Report.Merge(converter.Report); // undo notes edit var segments = Doc.Notes.Split(new string[] { "%%%" }, StringSplitOptions.None).ToList(); Doc.Notes = segments[0]; } + else // just generate the log + { + foreach(var previewObj in Preview) + progress.Report.Log(previewObj); + } // create display conduit PreviewConduit = new PreviewConduit(Preview); @@ -315,13 +328,15 @@ public override async Task PreviewReceive(StreamState state, Progre public override async Task ReceiveStream(StreamState state, ProgressViewModel progress) { - var kit = KitManager.GetDefaultKit(); - if (Converter == null) + // check for converter + var converter = KitManager.GetDefaultKit().LoadConverter(Utils.RhinoAppName); + if (converter == null) throw new Exception("Could not find any Kit!"); - Converter.SetContextDocument(Doc); + converter.SetContextDocument(Doc); Commit commit = await GetCommitFromState(state, progress); if (commit == null) return null; + if (SelectedReceiveCommit != commit.id) { Preview.Clear(); @@ -329,6 +344,7 @@ public override async Task ReceiveStream(StreamState state, Progres SelectedReceiveCommit = commit.id; } + progress.Report = new ProgressReport(); var conversionProgressDict = new ConcurrentDictionary(); conversionProgressDict["Conversion"] = 0; var undoRecord = Doc.BeginUndoRecord($"Speckle bake operation for {state.CachedStream.name}"); @@ -351,12 +367,12 @@ public override async Task ReceiveStream(StreamState state, Progres { // flatten the commit object to retrieve children objs int count = 0; - Preview = FlattenCommitObject(commitObject, commitLayerName, ref count); + Preview = FlattenCommitObject(commitObject, converter, commitLayerName, ref count); // convert foreach (var previewObj in Preview) { - previewObj.Converted = previewObj.Convertible ? ConvertObject(previewObj) : previewObj.Fallback.SelectMany(o => ConvertObject(o)).ToList(); + previewObj.Converted = previewObj.Convertible ? ConvertObject(previewObj, converter) : previewObj.Fallback.SelectMany(o => ConvertObject(o, converter)).ToList(); if (previewObj.Converted == null || previewObj.Converted.Count == 0) previewObj.Update(status: ApplicationObject.State.Failed, logItem: $"Couldn't convert object or any fallback values"); @@ -368,7 +384,7 @@ public override async Task ReceiveStream(StreamState state, Progres if (progress.CancellationTokenSource.Token.IsCancellationRequested) return; } - progress.Report.Merge(Converter.Report); + progress.Report.Merge(converter.Report); } if (progress.Report.OperationErrorsCount != 0) @@ -378,7 +394,7 @@ public override async Task ReceiveStream(StreamState state, Progres { // bake previewObj.CreatedIds.Clear(); // clear created ids before bake because these may be speckle ids from the preview - BakeObject(previewObj); + BakeObject(previewObj, converter); progress.Report.Log(previewObj); if (progress.CancellationTokenSource.Token.IsCancellationRequested) @@ -441,7 +457,7 @@ private async Task GetCommit(Commit commit, StreamState state, ProgressVie } // Recurses through the commit object and flattens it. Returns list of Preview objects - private List FlattenCommitObject(object obj, string layer, ref int count, bool foundConvertibleMember = false) + private List FlattenCommitObject(object obj, ISpeckleConverter converter, string layer, ref int count, bool foundConvertibleMember = false) { var objects = new List(); @@ -449,7 +465,7 @@ private List FlattenCommitObject(object obj, string layer, re { var speckleType = @base.speckle_type.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(); var appObj = new ApplicationObject(@base.id, speckleType) { applicationId = @base.applicationId, Container = layer }; - if (Converter.CanConvertToNative(@base)) + if (converter.CanConvertToNative(@base)) { appObj.Convertible = true; objects.Add(appObj); @@ -465,7 +481,7 @@ private List FlattenCommitObject(object obj, string layer, re bool hasFallback = false; if (@base.GetMembers().ContainsKey("displayValue")) { - var fallbackObjects = FlattenCommitObject(@base["displayValue"], layer, ref count, foundConvertibleMember); + var fallbackObjects = FlattenCommitObject(@base["displayValue"], converter, layer, ref count, foundConvertibleMember); if (fallbackObjects.Count > 0) { appObj.Fallback.AddRange(fallbackObjects); @@ -492,7 +508,7 @@ private List FlattenCommitObject(object obj, string layer, re string objLayerName = prop.StartsWith("@") ? prop.Remove(0, 1) : prop; string rhLayerName = objLayerName.StartsWith($"{layer}{Layer.PathSeparator}") ? objLayerName : $"{layer}{Layer.PathSeparator}{objLayerName}"; - var nestedObjects = FlattenCommitObject(@base[prop], rhLayerName, ref count, foundConvertibleMember); + var nestedObjects = FlattenCommitObject(@base[prop], converter, rhLayerName, ref count, foundConvertibleMember); var validNestedObjects = nestedObjects.Where(o => o.Convertible == true || o.Fallback.Count > 0)?.ToList(); if (validNestedObjects != null && validNestedObjects.Count > 0) { @@ -515,7 +531,7 @@ private List FlattenCommitObject(object obj, string layer, re { count = 0; foreach (var listObj in list) - objects.AddRange(FlattenCommitObject(listObj, layer, ref count)); + objects.AddRange(FlattenCommitObject(listObj, converter, layer, ref count)); return objects; } @@ -523,7 +539,7 @@ private List FlattenCommitObject(object obj, string layer, re { count = 0; foreach (DictionaryEntry kvp in dict) - objects.AddRange(FlattenCommitObject(kvp.Value, layer, ref count)); + objects.AddRange(FlattenCommitObject(kvp.Value, converter, layer, ref count)); return objects; } @@ -531,12 +547,12 @@ private List FlattenCommitObject(object obj, string layer, re } // conversion and bake - private List ConvertObject(ApplicationObject previewObj) + private List ConvertObject(ApplicationObject previewObj, ISpeckleConverter converter) { var obj = StoredObjects[previewObj.OriginalId]; var convertedList = new List(); - var converted = Converter.ConvertToNative(obj); + var converted = converter.ConvertToNative(obj); if (converted == null) return convertedList; @@ -553,10 +569,15 @@ void FlattenConvertedObject(object item) return convertedList; } - private void BakeObject(ApplicationObject previewObj) + private void BakeObject(ApplicationObject previewObj, ISpeckleConverter converter) { var obj = StoredObjects[previewObj.OriginalId]; int bakedCount = 0; + // check if this is a view or block - convert instead of bake if so (since these are "baked" during conversion) + if (!previewObj.Converted.Any() && (obj.speckle_type.Contains("Block") || obj.speckle_type.Contains("View"))) + { + previewObj.Converted = ConvertObject(previewObj, converter); + } foreach (var convertedItem in previewObj.Converted) { switch (convertedItem) @@ -578,7 +599,7 @@ private void BakeObject(ApplicationObject previewObj) // handle display style if (obj[@"displayStyle"] is Base display) - if (Converter.ConvertToNative(display) is ObjectAttributes displayAttribute) + if (converter.ConvertToNative(display) is ObjectAttributes displayAttribute) attributes = displayAttribute; else if (obj[@"renderMaterial"] is Base renderMaterial) attributes.ColorSource = ObjectColorSource.ColorFromMaterial; @@ -602,7 +623,7 @@ private void BakeObject(ApplicationObject previewObj) // handle render material if (obj[@"renderMaterial"] is Base render) { - var convertedMaterial = Converter.ConvertToNative(render); //Maybe wrap in try catch in case no conversion exists? + var convertedMaterial = converter.ConvertToNative(render); //Maybe wrap in try catch in case no conversion exists? if (convertedMaterial is RenderMaterial rm) { var rhinoObject = Doc.Objects.FindId(id); @@ -611,10 +632,14 @@ private void BakeObject(ApplicationObject previewObj) } } break; - case RhinoObject o: + case RhinoObject o: // this was prbly a block instance, baked during conversion previewObj.Update(status: ApplicationObject.State.Created, createdId: o.Id.ToString()); bakedCount++; break; + case string o: // this was prbly a view, baked during conversion + previewObj.Update(status: ApplicationObject.State.Created, createdId: o); + bakedCount++; + break; default: break; } @@ -642,18 +667,75 @@ private void SetUserInfo(Base obj, ObjectAttributes attributes) #endregion #region sending + public override bool CanPreviewSend => true; public override void PreviewSend(StreamState state, ProgressViewModel progress) { + progress.Report = new ProgressReport(); + var filterObjs = GetObjectsFromFilter(state.Filter); + // remove any invalid objs + var existingIds = new List(); + foreach (var id in filterObjs) + { + RhinoObject obj = null; + try + { + obj = Doc.Objects.FindId(new Guid(id)); // this is a rhinoobj + } + catch + { + var viewId = Doc.NamedViews.FindByName(id); + var viewObj = new ApplicationObject(id, "Named View"); + if (viewId != -1) + viewObj.Update(status: ApplicationObject.State.Created); + else + viewObj.Update(status: ApplicationObject.State.Failed, logItem: "Does not exist in document"); + progress.Report.Log(viewObj); + continue; + } + + if (obj == null) + { + progress.Report.Log(new ApplicationObject(id, "unknown") { Status = ApplicationObject.State.Failed, Log = new List() { "Could not find object in document" } }); + continue; + } + + // get converter + var appObj = new ApplicationObject(id, obj.ObjectType.ToString()) { Status = ApplicationObject.State.Unknown }; + var converter = KitManager.GetDefaultKit().LoadConverter(Utils.RhinoAppName); + if (converter != null) + { + converter.SetContextDocument(Doc); + if (converter.CanConvertToSpeckle(obj)) + appObj.Update(status: ApplicationObject.State.Created); + else + appObj.Update(status: ApplicationObject.State.Failed, logItem: "Object type conversion to Speckle not supported"); + } + else + appObj.Update(logItem: "Converter not found, conversion status could not be determined"); + existingIds.Add(id); + } + + if (existingIds.Count == 0) + { + progress.Report.LogOperationError(new Exception("No valid objects selected, nothing will be sent!")); + return; + } + // TODO: instead of selection, consider saving current visibility of objects in doc, hiding everything except selected, and restoring original states on cancel Doc.Objects.UnselectAll(false); - SelectClientObjects(filterObjs); + SelectClientObjects(existingIds); Doc.Views.Redraw(); } + public override async Task SendStream(StreamState state, ProgressViewModel progress) { - Converter.SetContextDocument(Doc); + // check for converter + var converter = KitManager.GetDefaultKit().LoadConverter(Utils.RhinoAppName); + if (converter == null) + throw new Exception("Could not find any Kit!"); + converter.SetContextDocument(Doc); var streamId = state.StreamId; var client = state.Client; @@ -669,6 +751,7 @@ public override async Task SendStream(StreamState state, ProgressViewMod return null; } + progress.Report = new ProgressReport(); var conversionProgressDict = new ConcurrentDictionary(); conversionProgressDict["Conversion"] = 0; @@ -698,15 +781,15 @@ public override async Task SendStream(StreamState state, ProgressViewMod if (obj != null) { - if (!Converter.CanConvertToSpeckle(obj)) + if (!converter.CanConvertToSpeckle(obj)) { reportObj.Update(status: ApplicationObject.State.Skipped, logItem: $"Sending this object type is not supported in Rhino"); progress.Report.Log(reportObj); continue; } - Converter.Report.Log(reportObj); // Log object so converter can access - converted = Converter.ConvertToSpeckle(obj); + converter.Report.Log(reportObj); // Log object so converter can access + converted = converter.ConvertToSpeckle(obj); if (converted == null) { reportObj.Update(status: ApplicationObject.State.Failed, logItem: $"Conversion returned null"); @@ -726,8 +809,8 @@ public override async Task SendStream(StreamState state, ProgressViewMod else if (viewIndex != -1) { ViewInfo view = Doc.NamedViews[viewIndex]; - Converter.Report.Log(reportObj); // Log object so converter can access - converted = Converter.ConvertToSpeckle(view); + converter.Report.Log(reportObj); // Log object so converter can access + converted = converter.ConvertToSpeckle(view); if (converted == null) { reportObj.Update(status: ApplicationObject.State.Failed, logItem: $"Conversion returned null"); @@ -765,7 +848,7 @@ public override async Task SendStream(StreamState state, ProgressViewMod objCount++; } - progress.Report.Merge(Converter.Report); + progress.Report.Merge(converter.Report); if (objCount == 0) { @@ -827,7 +910,7 @@ public override async Task SendStream(StreamState state, ProgressViewMod //return state; } - + private List GetObjectsFromFilter(ISelectionFilter filter) { var objs = new List(); @@ -864,7 +947,6 @@ private List GetObjectsFromFilter(ISelectionFilter filter) return objs; } - /// /// Copies a Base to an ArchivableDictionary /// diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Send.cs b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Send.cs index c024a6f863..932a56d71b 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Send.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructure.Send.cs @@ -25,9 +25,10 @@ public partial class ConnectorBindingsTeklaStructures : ConnectorBindings private List CurrentSettings { get; set; } + public override bool CanPreviewSend => false; public override void PreviewSend(StreamState state, ProgressViewModel progress) { - // TODO! + return; } public override async System.Threading.Tasks.Task SendStream(StreamState state, ProgressViewModel progress) diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Receive.cs b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Receive.cs index 4d5e703793..7b32de2124 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Receive.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Receive.cs @@ -20,6 +20,12 @@ public partial class ConnectorBindingsTeklaStructures : ConnectorBindings { #region receiving + public override bool CanPreviewReceive => false; + public override async Task PreviewReceive(StreamState state, ProgressViewModel progress) + { + return null; + } + public override async Task ReceiveStream(StreamState state, ProgressViewModel progress) { Exceptions.Clear(); diff --git a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Selection.cs b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Selection.cs index 7e37574b13..b808ce88fa 100644 --- a/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Selection.cs +++ b/ConnectorTeklaStructures/ConnectorTeklaStructuresShared/UI/ConnectorBindingsTeklaStructures.Selection.cs @@ -55,13 +55,6 @@ public override List GetSelectionFilters() }; } - public override async System.Threading.Tasks.Task PreviewReceive(StreamState state, ProgressViewModel progress) - { - await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(200)); - return new StreamState(); - // TODO! - } - public override void ResetDocument() { // TODO! diff --git a/DesktopUI2/DesktopUI2/ConnectorBindings.cs b/DesktopUI2/DesktopUI2/ConnectorBindings.cs index 9b4c3d9582..ee580454d5 100644 --- a/DesktopUI2/DesktopUI2/ConnectorBindings.cs +++ b/DesktopUI2/DesktopUI2/ConnectorBindings.cs @@ -44,6 +44,23 @@ public virtual bool CanTogglePreview() return false; } + #region abstract properties + + /// + /// Indicates if previewing send has been implemented + /// + /// + public abstract bool CanPreviewSend { get; } + + /// + /// Indicates if previewing receive has been implemented + /// + /// + public abstract bool CanPreviewReceive { get; } + + #endregion + + #region abstract methods /// @@ -126,6 +143,7 @@ public virtual bool CanTogglePreview() /// public abstract void PreviewSend(StreamState state, ProgressViewModel progress); + /// /// Receives stream data from the server /// diff --git a/DesktopUI2/DesktopUI2/DummyBindings.cs b/DesktopUI2/DesktopUI2/DummyBindings.cs index 823897c1df..f49dc6b4ed 100644 --- a/DesktopUI2/DesktopUI2/DummyBindings.cs +++ b/DesktopUI2/DesktopUI2/DummyBindings.cs @@ -266,6 +266,7 @@ public override void SelectClientObjects(List objs, bool deselect = fals // TODO! } + public override bool CanPreviewReceive => true; public override async Task PreviewReceive(StreamState state, ProgressViewModel progress) { var pd = new ConcurrentDictionary(); @@ -371,6 +372,7 @@ public override async Task ReceiveStream(StreamState state, Progres return state; } + public override bool CanPreviewSend => true; public override async void PreviewSend(StreamState state, ProgressViewModel progress) { // Let's fake some progress barsssss diff --git a/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs index eb92f1ed73..8d2ccfd558 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs @@ -47,6 +47,12 @@ public bool PreviewOn get => _previewOn; set { + if (value == false && value != _previewOn) + { + if (Progress.IsPreviewProgressing) + Progress.IsPreviewProgressing = false; + Bindings.ResetDocument(); + } this.RaiseAndSetIfChanged(ref _previewOn, value); } } @@ -159,6 +165,10 @@ public bool IsReceiver get => _isReceiver; set { + if (value != _isReceiver) + { + PreviewOn = false; + } this.RaiseAndSetIfChanged(ref _isReceiver, value); this.RaisePropertyChanged(nameof(BranchesViewModel)); } @@ -1131,7 +1141,10 @@ private bool CanReceiveCommand(object parameter) [DependsOn(nameof(IsReceiver))] private bool CanPreviewCommand(object parameter) { - return IsReady(); + bool previewImplemented = IsReceiver ? Bindings.CanPreviewReceive : Bindings.CanPreviewSend; + if (previewImplemented) + return IsReady(); + else return false; } private bool IsReady() diff --git a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs index 4157f987e4..35bc7d7116 100644 --- a/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs +++ b/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.BuiltElements.cs @@ -62,6 +62,7 @@ public View3D ViewToSpeckle(ViewInfo view) } public string ViewToNative(View3D view) { + var bakedViewName = string.Empty; Rhino.RhinoApp.InvokeOnUiThread((Action)delegate { RhinoView _view = Doc.Views.ActiveView; @@ -97,14 +98,14 @@ public string ViewToNative(View3D view) viewport.ChangeToParallelProjection(true); var commitInfo = GetCommitInfo(); - var viewName = $"{commitInfo } - {view.name}"; + bakedViewName = $"{commitInfo } - {view.name}"; - Doc.NamedViews.Add(viewName, viewport.Id); + Doc.NamedViews.Add(bakedViewName, viewport.Id); }); //ConversionErrors.Add(sdfasdfaf); - return "baked"; + return bakedViewName; } private void AttachViewParams(Base speckleView, ViewInfo view)