16
16
namespace RevitLookup . ViewModels . Visualization
17
17
{
18
18
[ 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
20
24
{
21
25
private readonly CurveLoopVisualizationServer _server = new ( ) ;
22
- private readonly ISettingsService _settingsService ;
23
- private readonly INotificationService _notificationService ;
24
- private readonly ILogger < CurveLoopVisualizationViewModel > _logger ;
25
26
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 ;
52
29
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 ;
55
33
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 ;
58
37
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 ;
70
39
71
40
public void RegisterServer ( object curveLoop )
72
41
{
73
42
if ( curveLoop is CurveLoop loop )
74
43
{
75
44
Initialize ( ) ;
76
45
_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 ) ;
90
47
91
48
_server . Register ( allVertices ) ;
92
49
return ;
93
50
}
94
51
throw new ArgumentException ( "Unexpected CurveLoop type" , nameof ( curveLoop ) ) ;
95
52
}
96
53
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
+
97
72
private void Initialize ( )
98
73
{
99
74
UpdateShowSurface ( ShowSurface ) ;
@@ -116,55 +91,55 @@ public void UnregisterServer()
116
91
117
92
private void HandleRenderFailure ( object ? sender , RenderFailedEventArgs args )
118
93
{
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 ) ;
121
96
}
122
97
123
98
partial void OnSurfaceColorChanged ( Color value )
124
99
{
125
- _settingsService . VisualizationSettings . CurveLoopSettings . SurfaceColor = value ;
100
+ settingsService . VisualizationSettings . CurveLoopSettings . SurfaceColor = value ;
126
101
UpdateSurfaceColor ( value ) ;
127
102
}
128
103
129
104
partial void OnCurveColorChanged ( Color value )
130
105
{
131
- _settingsService . VisualizationSettings . CurveLoopSettings . CurveColor = value ;
106
+ settingsService . VisualizationSettings . CurveLoopSettings . CurveColor = value ;
132
107
UpdateCurveColor ( value ) ;
133
108
}
134
109
135
110
partial void OnDirectionColorChanged ( Color value )
136
111
{
137
- _settingsService . VisualizationSettings . CurveLoopSettings . DirectionColor = value ;
112
+ settingsService . VisualizationSettings . CurveLoopSettings . DirectionColor = value ;
138
113
UpdateDirectionColor ( value ) ;
139
114
}
140
115
141
116
partial void OnDiameterChanged ( double value )
142
117
{
143
- _settingsService . VisualizationSettings . CurveLoopSettings . Diameter = value ;
118
+ settingsService . VisualizationSettings . CurveLoopSettings . Diameter = value ;
144
119
UpdateDiameter ( value ) ;
145
120
}
146
121
147
122
partial void OnTransparencyChanged ( double value )
148
123
{
149
- _settingsService . VisualizationSettings . CurveLoopSettings . Transparency = value ;
124
+ settingsService . VisualizationSettings . CurveLoopSettings . Transparency = value ;
150
125
UpdateTransparency ( value ) ;
151
126
}
152
127
153
128
partial void OnShowSurfaceChanged ( bool value )
154
129
{
155
- _settingsService . VisualizationSettings . CurveLoopSettings . ShowSurface = value ;
130
+ settingsService . VisualizationSettings . CurveLoopSettings . ShowSurface = value ;
156
131
UpdateShowSurface ( value ) ;
157
132
}
158
133
159
134
partial void OnShowCurveChanged ( bool value )
160
135
{
161
- _settingsService . VisualizationSettings . CurveLoopSettings . ShowCurve = value ;
136
+ settingsService . VisualizationSettings . CurveLoopSettings . ShowCurve = value ;
162
137
UpdateShowCurve ( value ) ;
163
138
}
164
139
165
140
partial void OnShowDirectionChanged ( bool value )
166
141
{
167
- _settingsService . VisualizationSettings . CurveLoopSettings . ShowDirection = value ;
142
+ settingsService . VisualizationSettings . CurveLoopSettings . ShowDirection = value ;
168
143
UpdateShowDirection ( value ) ;
169
144
}
170
145
0 commit comments