Skip to content

Commit 09a6b40

Browse files
committed
optimize visualization dialogs for CurveLoop
1 parent e4e7501 commit 09a6b40

File tree

6 files changed

+119
-86
lines changed

6 files changed

+119
-86
lines changed

source/RevitLookup.UI.Playground/Client/ViewModels/Pages/DialogsViewModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Bogus;
1+
using Bogus;
22
using CommunityToolkit.Mvvm.ComponentModel;
33
using CommunityToolkit.Mvvm.Input;
44
using JetBrains.Annotations;
@@ -111,6 +111,13 @@ private async Task ShowPolylineVisualizationDialogAsync()
111111
await dialog.ShowDialogAsync("polyline");
112112
}
113113

114+
[RelayCommand]
115+
private async Task ShowCurveLoopVisualizationDialogAsync()
116+
{
117+
var dialog = serviceProvider.GetRequiredService<CurveLoopVisualizationDialog>();
118+
await dialog.ShowDialogAsync("curveLoop");
119+
}
120+
114121
[RelayCommand]
115122
private async Task ShowSolidVisualizationDialogAsync()
116123
{

source/RevitLookup.UI.Playground/Client/Views/Pages/DialogsPage.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Page
1+
<Page
22
x:Class="RevitLookup.UI.Playground.Client.Views.Pages.DialogsPage"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -77,6 +77,11 @@
7777
Icon="{ui:SymbolIcon Wallpaper24}"
7878
Content="Polyline visualization dialog"
7979
Command="{Binding ViewModel.ShowPolylineVisualizationDialogCommand}" />
80+
<ui:CardAction
81+
Margin="0 4 0 0"
82+
Icon="{ui:SymbolIcon Wallpaper24}"
83+
Content="CurveLoop visualization dialog"
84+
Command="{Binding ViewModel.ShowCurveLoopVisualizationDialogCommand}" />
8085
<ui:CardAction
8186
Margin="0 4 0 0"
8287
Icon="{ui:SymbolIcon Wallpaper24}"
@@ -108,5 +113,4 @@
108113
Content="Create INI entry dialog"
109114
Command="{Binding ViewModel.ShowCreateIniEntryDialogCommand}" />
110115
</StackPanel>
111-
112116
</Page>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Windows.Media;
2+
using Bogus;
3+
using CommunityToolkit.Mvvm.ComponentModel;
4+
using JetBrains.Annotations;
5+
using RevitLookup.Abstractions.ViewModels.Visualization;
6+
7+
namespace RevitLookup.UI.Playground.Mockups.ViewModels.Visualization;
8+
9+
[UsedImplicitly]
10+
public sealed partial class MockCurveLoopVisualizationViewModel : ObservableObject, ICurveLoopVisualizationViewModel
11+
{
12+
[ObservableProperty] private double _diameter;
13+
[ObservableProperty] private double _transparency;
14+
15+
[ObservableProperty] private Color _surfaceColor;
16+
[ObservableProperty] private Color _curveColor;
17+
[ObservableProperty] private Color _directionColor;
18+
19+
[ObservableProperty] private bool _showSurface;
20+
[ObservableProperty] private bool _showCurve;
21+
[ObservableProperty] private bool _showDirection;
22+
23+
public MockCurveLoopVisualizationViewModel()
24+
{
25+
var faker = new Faker();
26+
27+
MinThickness = 0;
28+
Transparency = faker.Random.Double(0, 100);
29+
Diameter = faker.Random.Double(0, 6);
30+
SurfaceColor = Color.FromRgb(faker.Random.Byte(), faker.Random.Byte(), faker.Random.Byte());
31+
CurveColor = Color.FromRgb(faker.Random.Byte(), faker.Random.Byte(), faker.Random.Byte());
32+
DirectionColor = Color.FromRgb(faker.Random.Byte(), faker.Random.Byte(), faker.Random.Byte());
33+
34+
ShowSurface = faker.Random.Bool();
35+
ShowCurve = faker.Random.Bool();
36+
ShowDirection = faker.Random.Bool();
37+
}
38+
39+
public double MinThickness { get; }
40+
41+
public void RegisterServer(object curveOrEdge)
42+
{
43+
}
44+
45+
public void UnregisterServer()
46+
{
47+
}
48+
}

source/RevitLookup/Core/Decomposition/Descriptors/CurveLoopDescriptor.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Copyright 2003-2024 by Autodesk, Inc.
2-
//
2+
//
33
// Permission to use, copy, modify, and distribute this software in
44
// object code form for any purpose and without fee is hereby granted,
55
// provided that the above copyright notice appears in all copies and
66
// that both that copyright notice and the limited warranty and
77
// restricted rights notice below appear in all supporting
88
// documentation.
9-
//
9+
//
1010
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
1111
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
1212
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
1313
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
1414
// UNINTERRUPTED OR ERROR FREE.
15-
//
15+
//
1616
// Use, duplication, or disclosure by the U.S. Government is subject to
1717
// restrictions set forth in FAR 52.227-19 (Commercial Computer
1818
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
@@ -36,11 +36,11 @@ namespace RevitLookup.Core.Decomposition.Descriptors;
3636

3737
public sealed class CurveLoopDescriptor : Descriptor, IDescriptorResolver, IContextMenuConnector
3838
{
39-
private readonly CurveLoop _curveloop;
39+
private readonly CurveLoop _curveLoop;
4040

4141
public CurveLoopDescriptor(CurveLoop curveloop)
4242
{
43-
_curveloop = curveloop;
43+
_curveLoop = curveloop;
4444
Name = $"{curveloop.GetExactLength().ToString(CultureInfo.InvariantCulture)} ft";
4545
}
4646

@@ -58,22 +58,22 @@ IVariant ResolveNumberOfCurves()
5858
{
5959
var variants = Variants.Values<int>(1);
6060

61-
variants.Add(_curveloop.NumberOfCurves(), "number of curves in the curve loop");
61+
variants.Add(_curveLoop.NumberOfCurves(), "number of curves in the curve loop");
6262

6363
return variants.Consume();
6464
}
6565

6666
IVariant ResolveIsOpen()
6767
{
6868
return Variants.Values<bool>(1)
69-
.Add(_curveloop.IsOpen(), "whether the curve loop is open or closed")
69+
.Add(_curveLoop.IsOpen(), "whether the curve loop is open or closed")
7070
.Consume();
7171
}
7272

7373
IVariant ResolveGetPlane()
7474
{
7575
return Variants.Values<Plane>(1)
76-
.Add(_curveloop.GetPlane(), "Plane")
76+
.Add(_curveLoop.GetPlane(), "Plane")
7777
.Consume();
7878
}
7979
}
@@ -90,8 +90,8 @@ public void RegisterMenu(ContextMenu contextMenu, IServiceProvider serviceProvid
9090
.SetShortcut(Key.F7);
9191
#endif
9292
contextMenu.AddMenuItem("VisualizeMenuItem")
93-
.SetAvailability(true && _curveloop.GetExactLength() > 1e-6)
94-
.SetCommand(_curveloop, VisualizeCurve)
93+
.SetAvailability(true && _curveLoop.GetExactLength() > 1e-6)
94+
.SetCommand(_curveLoop, VisualizeCurve)
9595
.SetShortcut(Key.F8);
9696

9797
async Task VisualizeCurve(CurveLoop curveloop)

source/RevitLookup/Core/Decomposition/DescriptorsMap.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Copyright 2003-2024 by Autodesk, Inc.
2-
//
2+
//
33
// Permission to use, copy, modify, and distribute this software in
44
// object code form for any purpose and without fee is hereby granted,
55
// provided that the above copyright notice appears in all copies and
66
// that both that copyright notice and the limited warranty and
77
// restricted rights notice below appear in all supporting
88
// documentation.
9-
//
9+
//
1010
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
1111
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
1212
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
1313
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
1414
// UNINTERRUPTED OR ERROR FREE.
15-
//
15+
//
1616
// Use, duplication, or disclosure by the U.S. Government is subject to
1717
// restrictions set forth in FAR 52.227-19 (Commercial Computer
1818
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
@@ -55,11 +55,10 @@ public static Descriptor FindDescriptor(object? obj, Type? type)
5555
{
5656
return obj switch
5757
{
58-
CurveLoop value when type is null || type == typeof(CurveLoop) => new CurveLoopDescriptor(value),
59-
6058
//System
6159
string value when type is null || type == typeof(string) => new StringDescriptor(value),
6260
bool value when type is null || type == typeof(bool) => new BooleanDescriptor(value),
61+
CurveLoop value when type is null || type == typeof(CurveLoop) => new CurveLoopDescriptor(value),//before regular IEnumerable
6362
IEnumerable value => new EnumerableDescriptor(value),
6463
Exception value when type is null || type == typeof(Exception) => new ExceptionDescriptor(value),
6564

source/RevitLookup/ViewModels/Visualization/CurveLoopVisualizationViewModel.cs

Lines changed: 43 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -16,84 +16,59 @@
1616
namespace RevitLookup.ViewModels.Visualization
1717
{
1818
[UsedImplicitly]
19-
public sealed partial class CurveLoopVisualizationViewModel : ObservableObject, ICurveLoopVisualizationViewModel
19+
public sealed partial class CurveLoopVisualizationViewModel(
20+
ISettingsService settingsService,
21+
INotificationService notificationService,
22+
ILogger<CurveLoopVisualizationViewModel> logger)
23+
: ObservableObject, ICurveLoopVisualizationViewModel
2024
{
2125
private readonly CurveLoopVisualizationServer _server = new();
22-
private readonly ISettingsService _settingsService;
23-
private readonly INotificationService _notificationService;
24-
private readonly ILogger<CurveLoopVisualizationViewModel> _logger;
2526

26-
public CurveLoopVisualizationViewModel(
27-
ISettingsService settingsService,
28-
INotificationService notificationService,
29-
ILogger<CurveLoopVisualizationViewModel> logger)
30-
{
31-
_settingsService = settingsService;
32-
_notificationService = notificationService;
33-
_logger = logger;
34-
35-
Diameter = _settingsService.VisualizationSettings.CurveLoopSettings.Diameter;
36-
Transparency = _settingsService.VisualizationSettings.CurveLoopSettings.Transparency;
37-
SurfaceColor = _settingsService.VisualizationSettings.CurveLoopSettings.SurfaceColor;
38-
CurveColor = _settingsService.VisualizationSettings.CurveLoopSettings.CurveColor;
39-
DirectionColor = _settingsService.VisualizationSettings.CurveLoopSettings.DirectionColor;
40-
ShowSurface = _settingsService.VisualizationSettings.CurveLoopSettings.ShowSurface;
41-
ShowCurve = _settingsService.VisualizationSettings.CurveLoopSettings.ShowCurve;
42-
ShowDirection = _settingsService.VisualizationSettings.CurveLoopSettings.ShowDirection;
43-
}
44-
45-
public double MinThickness => _settingsService.VisualizationSettings.CurveLoopSettings.MinThickness;
46-
47-
[ObservableProperty]
48-
private double _diameter;
49-
50-
[ObservableProperty]
51-
private double _transparency;
27+
[ObservableProperty] private double _diameter = settingsService.VisualizationSettings.CurveLoopSettings.Diameter;
28+
[ObservableProperty] private double _transparency = settingsService.VisualizationSettings.CurveLoopSettings.Transparency;
5229

53-
[ObservableProperty]
54-
private Color _surfaceColor;
30+
[ObservableProperty] private Color _surfaceColor = settingsService.VisualizationSettings.CurveLoopSettings.SurfaceColor;
31+
[ObservableProperty] private Color _curveColor = settingsService.VisualizationSettings.CurveLoopSettings.CurveColor;
32+
[ObservableProperty] private Color _directionColor = settingsService.VisualizationSettings.CurveLoopSettings.DirectionColor;
5533

56-
[ObservableProperty]
57-
private Color _curveColor;
34+
[ObservableProperty] private bool _showSurface = settingsService.VisualizationSettings.CurveLoopSettings.ShowSurface;
35+
[ObservableProperty] private bool _showCurve = settingsService.VisualizationSettings.CurveLoopSettings.ShowCurve;
36+
[ObservableProperty] private bool _showDirection = settingsService.VisualizationSettings.CurveLoopSettings.ShowDirection;
5837

59-
[ObservableProperty]
60-
private Color _directionColor;
61-
62-
[ObservableProperty]
63-
private bool _showSurface;
64-
65-
[ObservableProperty]
66-
private bool _showCurve;
67-
68-
[ObservableProperty]
69-
private bool _showDirection;
38+
public double MinThickness => settingsService.VisualizationSettings.CurveLoopSettings.MinThickness;
7039

7140
public void RegisterServer(object curveLoop)
7241
{
7342
if (curveLoop is CurveLoop loop)
7443
{
7544
Initialize();
7645
_server.RenderFailed += HandleRenderFailure;
77-
var allVertices = new List<XYZ>();
78-
foreach (var curve in loop)
79-
{
80-
var collectionPts = curve.Tessellate().ToList();
81-
foreach (var vertex in collectionPts)
82-
{
83-
if (allVertices.Any(pt => pt.IsAlmostEqualTo(vertex))) continue;
84-
85-
allVertices.Add(vertex);
86-
}
87-
}
88-
89-
if (!loop.IsOpen()) allVertices.Add(allVertices[0]);
46+
var allVertices = CollectVertices(loop);
9047

9148
_server.Register(allVertices);
9249
return;
9350
}
9451
throw new ArgumentException("Unexpected CurveLoop type", nameof(curveLoop));
9552
}
9653

54+
private static List<XYZ> CollectVertices(CurveLoop loop)
55+
{
56+
var allVertices = new List<XYZ>();
57+
foreach (var curve in loop)
58+
{
59+
var collectionPts = curve.Tessellate().ToList();
60+
foreach (var vertex in collectionPts)
61+
{
62+
if (allVertices.Any(pt => pt.IsAlmostEqualTo(vertex))) continue;
63+
64+
allVertices.Add(vertex);
65+
}
66+
}
67+
68+
if (!loop.IsOpen()) allVertices.Add(allVertices[0]);
69+
return allVertices;
70+
}
71+
9772
private void Initialize()
9873
{
9974
UpdateShowSurface(ShowSurface);
@@ -116,55 +91,55 @@ public void UnregisterServer()
11691

11792
private void HandleRenderFailure(object? sender, RenderFailedEventArgs args)
11893
{
119-
_logger.LogError(args.ExceptionObject, "Render error");
120-
_notificationService.ShowError("Render error", args.ExceptionObject);
94+
logger.LogError(args.ExceptionObject, "Render error");
95+
notificationService.ShowError("Render error", args.ExceptionObject);
12196
}
12297

12398
partial void OnSurfaceColorChanged(Color value)
12499
{
125-
_settingsService.VisualizationSettings.CurveLoopSettings.SurfaceColor = value;
100+
settingsService.VisualizationSettings.CurveLoopSettings.SurfaceColor = value;
126101
UpdateSurfaceColor(value);
127102
}
128103

129104
partial void OnCurveColorChanged(Color value)
130105
{
131-
_settingsService.VisualizationSettings.CurveLoopSettings.CurveColor = value;
106+
settingsService.VisualizationSettings.CurveLoopSettings.CurveColor = value;
132107
UpdateCurveColor(value);
133108
}
134109

135110
partial void OnDirectionColorChanged(Color value)
136111
{
137-
_settingsService.VisualizationSettings.CurveLoopSettings.DirectionColor = value;
112+
settingsService.VisualizationSettings.CurveLoopSettings.DirectionColor = value;
138113
UpdateDirectionColor(value);
139114
}
140115

141116
partial void OnDiameterChanged(double value)
142117
{
143-
_settingsService.VisualizationSettings.CurveLoopSettings.Diameter = value;
118+
settingsService.VisualizationSettings.CurveLoopSettings.Diameter = value;
144119
UpdateDiameter(value);
145120
}
146121

147122
partial void OnTransparencyChanged(double value)
148123
{
149-
_settingsService.VisualizationSettings.CurveLoopSettings.Transparency = value;
124+
settingsService.VisualizationSettings.CurveLoopSettings.Transparency = value;
150125
UpdateTransparency(value);
151126
}
152127

153128
partial void OnShowSurfaceChanged(bool value)
154129
{
155-
_settingsService.VisualizationSettings.CurveLoopSettings.ShowSurface = value;
130+
settingsService.VisualizationSettings.CurveLoopSettings.ShowSurface = value;
156131
UpdateShowSurface(value);
157132
}
158133

159134
partial void OnShowCurveChanged(bool value)
160135
{
161-
_settingsService.VisualizationSettings.CurveLoopSettings.ShowCurve = value;
136+
settingsService.VisualizationSettings.CurveLoopSettings.ShowCurve = value;
162137
UpdateShowCurve(value);
163138
}
164139

165140
partial void OnShowDirectionChanged(bool value)
166141
{
167-
_settingsService.VisualizationSettings.CurveLoopSettings.ShowDirection = value;
142+
settingsService.VisualizationSettings.CurveLoopSettings.ShowDirection = value;
168143
UpdateShowDirection(value);
169144
}
170145

0 commit comments

Comments
 (0)