From 49bcaf75985d4660bf2c072941e1400402105504 Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Tue, 5 Sep 2023 09:25:55 +0200 Subject: [PATCH] feat(rvt): Adds Block to Family conversion (#2884) * fix(rvt): Make revit converter Doc non-static * feat(rvt): First run at Block->Family conversion * temp: Commit to not loose current state * fix(rvt): temp category assignment to family * feat(rvt): New mapping option for blocks to family * fix(rvt): Reformat block file * feat(rvt): Magical Transform.Decompose fix. Pending cleanup * fix(rvt): Use DirectShape in family document+ cleanup * feat(rvt): Add Block template for 2023 * feat(rvt): 2022 and 2024 block templates. Kudos to Pavol * feat(rvt): 2020 and 2021 Block template + extension correct for 23 and 24 * fix(rvt): Remove converter block suffix * feat(rvt): Block converter docs + reshuffle --- .vscode/settings.json | 4 +- .../UI/MappingBindingsRhino.cs | 3 + .../MappingTool/MappingsViewModel.cs | 1 + .../ViewModels/MappingTool/Schemas.cs | 53 +- .../DesktopUI2/Views/MappingsControl.xaml | 18 +- .../ConverterRevitShared/ConversionUtils.cs | 11 +- .../ConverterRevitShared/ConverterRevit.cs | 21 +- .../Partial Classes/ConvertBlock.cs | 539 ++++++++++++------ .../Partial Classes/ConvertFreeformElement.cs | 15 +- .../Templates/2020/Block - Imperial.rft | Bin 0 -> 356352 bytes .../Templates/2020/Block - Metric.rft | Bin 0 -> 356352 bytes .../Templates/2021/Block - Imperial.rft | Bin 0 -> 409600 bytes .../Templates/2021/Block - Metric.rft | Bin 0 -> 409600 bytes .../Templates/2022/Block - Imperial.rft | Bin 0 -> 413696 bytes .../Templates/2022/Block - Metric.rft | Bin 0 -> 413696 bytes .../Templates/2023/Block - Imperial.rft | Bin 0 -> 356352 bytes .../Templates/2023/Block - Metric.rft | Bin 0 -> 356352 bytes .../Templates/2024/Block - Imperial.rft | Bin 0 -> 446464 bytes .../Templates/2024/Block - Metric.rft | Bin 0 -> 446464 bytes .../ConverterRhinoGh.Mappings.cs | 7 + Objects/Objects/Other/MappedBlockWrapper.cs | 19 + Objects/Objects/Other/Transform.cs | 46 +- 22 files changed, 521 insertions(+), 216 deletions(-) create mode 100755 Objects/Converters/ConverterRevit/Templates/2020/Block - Imperial.rft create mode 100755 Objects/Converters/ConverterRevit/Templates/2020/Block - Metric.rft create mode 100755 Objects/Converters/ConverterRevit/Templates/2021/Block - Imperial.rft create mode 100755 Objects/Converters/ConverterRevit/Templates/2021/Block - Metric.rft create mode 100644 Objects/Converters/ConverterRevit/Templates/2022/Block - Imperial.rft create mode 100644 Objects/Converters/ConverterRevit/Templates/2022/Block - Metric.rft create mode 100644 Objects/Converters/ConverterRevit/Templates/2023/Block - Imperial.rft create mode 100644 Objects/Converters/ConverterRevit/Templates/2023/Block - Metric.rft create mode 100644 Objects/Converters/ConverterRevit/Templates/2024/Block - Imperial.rft create mode 100644 Objects/Converters/ConverterRevit/Templates/2024/Block - Metric.rft create mode 100644 Objects/Objects/Other/MappedBlockWrapper.cs diff --git a/.vscode/settings.json b/.vscode/settings.json index 444722ff71..f5bc003aa2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,10 +8,10 @@ }, "omnisharp.enableEditorConfigSupport": true, "omnisharp.enableRoslynAnalyzers": true, - "omnisharp.defaultLaunchSolution": "SDK.slnf", "[dotnet][xml]": { "editor.defaultFormatter": "ms-dotnettools.csharp", "editor.tabSize": 2 }, - "xml.format.spaceBeforeEmptyCloseTag": false + "xml.format.spaceBeforeEmptyCloseTag": false, + "dotnet.defaultSolution": "SDK.slnf" } diff --git a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/MappingBindingsRhino.cs b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/MappingBindingsRhino.cs index 7f032e2d07..fe2319801a 100644 --- a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/MappingBindingsRhino.cs +++ b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/MappingBindingsRhino.cs @@ -73,7 +73,10 @@ private List GetObjectSchemas(RhinoObject obj) result.Add(existingSchema); if (obj is InstanceObject) + { + result.Add(new BlockDefinitionViewModel()); result.Add(new RevitFamilyInstanceViewModel()); + } else switch (obj.Geometry) { diff --git a/DesktopUI2/DesktopUI2/ViewModels/MappingTool/MappingsViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/MappingTool/MappingsViewModel.cs index 60fc80505c..8434ff27bd 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/MappingTool/MappingsViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/MappingTool/MappingsViewModel.cs @@ -315,6 +315,7 @@ private void AddRevitInfoToSchema(List schemas) //no need to do extra stuff if ( schema is DirectShapeFreeformViewModel + || schema is BlockDefinitionViewModel || schema is RevitTopographyViewModel || schema is RevitDefaultWallViewModel || schema is RevitDefaultFloorViewModel diff --git a/DesktopUI2/DesktopUI2/ViewModels/MappingTool/Schemas.cs b/DesktopUI2/DesktopUI2/ViewModels/MappingTool/Schemas.cs index 92bfcdfbb4..99e52e0b2b 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/MappingTool/Schemas.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/MappingTool/Schemas.cs @@ -4,6 +4,7 @@ using System.Runtime.Serialization; using Objects.BuiltElements; using Objects.BuiltElements.Revit; +using Objects.Other; using Objects.BuiltElements.Revit.RevitRoof; using ReactiveUI; using Speckle.Core.Api; @@ -378,7 +379,6 @@ public DirectShapeFreeformViewModel() .Select(x => x.ToString()) .OrderBy(x => x) .ToList(); - ; } public override string Name => "DirectShape"; @@ -437,6 +437,57 @@ public override string GetSerializedSchema() } } +public class BlockDefinitionViewModel : Schema +{ + private List _categories; + + private string _selectedCategory = RevitCategory.GenericModel.ToString(); + + public BlockDefinitionViewModel() + { + Categories = Enum.GetValues(typeof(RevitCategory)) + .Cast() + .Select(x => x.ToString()) + .OrderBy(x => x) + .ToList(); + ; + } + + public override string Name => "New Revit Family"; + + public List Categories + { + get => _categories; + set => this.RaiseAndSetIfChanged(ref _categories, value); + } + + [DataMember] + public string SelectedCategory + { + get => _selectedCategory; + set + { + this.RaiseAndSetIfChanged(ref _selectedCategory, value); + this.RaisePropertyChanged(nameof(IsValid)); + } + } + public override string Summary => $"New Revit Family - {SelectedCategory}"; + + public override bool IsValid => !string.IsNullOrEmpty(SelectedCategory); + + public override string GetSerializedSchema() + { + var res = Enum.TryParse(SelectedCategory, out RevitCategory cat); + if (!res) + cat = RevitCategory.GenericModel; + + var ds = new MappedBlockWrapper(); //don't use the constructor + ds.category = cat.ToString(); + + return Operations.Serialize(ds); + } +} + public class RevitDefaultWallViewModel : Schema { public override string Name => "Default Wall"; diff --git a/DesktopUI2/DesktopUI2/Views/MappingsControl.xaml b/DesktopUI2/DesktopUI2/Views/MappingsControl.xaml index d160f47e97..6054bc9214 100644 --- a/DesktopUI2/DesktopUI2/Views/MappingsControl.xaml +++ b/DesktopUI2/DesktopUI2/Views/MappingsControl.xaml @@ -347,17 +347,25 @@ IsChecked="{Binding Freeform}" />--> - + + + + +