-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Settings.cs
313 lines (297 loc) · 10.6 KB
/
Settings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
using Grasshopper.Kernel;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace Sunglasses
{
public static class Settings
{
public static string Key_DrawNames => "Sunglasses.DrawNames";
public static string Key_Font => "Sunglasses.Font";
public static string Key_DisplayNicknames => "Sunglasses.DisplayNicknames";
public static string Key_DisplayCustomNicknames => "Sunglasses.DisplayCustomNicknames";
public static string Key_DisplayRichedCapsules => "Sunglasses.DisplayRichedAttributes";
public static string Key_FilterComponents => "Sunglasses.FilterComponents";
public static string Key_FilterParameters => "Sunglasses.FilterParameters";
public static string Key_FilterSpecial => "Sunglasses.FilterSpecial";
public static string Key_FilterGraphic => "Sunglasses.FilterGraphic";
public static string Key_FilterCustom => "Sunglasses.FilterCustom";
public static string Key_HideOnLowZoom => "Sunglasses.HideOnLowZoom ";
public static string Key_GroupsOnLowZoom => "Sunglasses.GroupsOnLowZoom ";
#region Fonts
private static Font _font;
private static Font _fontCapsuleInfoName;
private static Font _fontCapsuleDescription;
private static Font _fontCapsuleInstanceDescription;
private static Font _fontCapsuleParameterName;
private static Font _fontCapsuleParameterData;
public static Font Font
{
get
{
if (_font == null)
{
_font = GH_FontServer.StringToFont(Grasshopper.Instances.Settings.GetValue(Key_Font, GH_FontServer.FontToString(GH_FontServer.StandardItalic)));
}
return _font;
}
set
{
if (value == null)
return;
_font = value;
Grasshopper.Instances.Settings.SetValue(Key_Font, GH_FontServer.FontToString(value));
}
}
internal static Font FontCapsuleInfoName
{
get
{
if (_fontCapsuleInfoName == null)
_fontCapsuleInfoName = new Font(Font.FontFamily, Drawing.ScaleSize(2f), FontStyle.Bold);
return _fontCapsuleInfoName;
}
}
internal static Font FontCapsuleDescription
{
get
{
if (_fontCapsuleDescription == null)
_fontCapsuleDescription = new Font(Font.FontFamily, Drawing.ScaleSize(1.2f), FontStyle.Italic);
return _fontCapsuleDescription;
}
}
internal static Font FontCapsuleInstanceDescription
{
get
{
if (_fontCapsuleInstanceDescription == null)
_fontCapsuleInstanceDescription = new Font(Font.FontFamily, Drawing.ScaleSize(0.85f), FontStyle.Italic);
return _fontCapsuleInstanceDescription;
}
}
internal static Font FontCapsuleParameterName
{
get
{
if (_fontCapsuleParameterName == null)
_fontCapsuleParameterName = new Font(Font.FontFamily, Drawing.ScaleSize(2f), FontStyle.Regular);
return _fontCapsuleParameterName;
}
}
internal static Font FontCapsuleParameterData
{
get
{
if (_fontCapsuleParameterData == null)
_fontCapsuleParameterData = new Font(Font.FontFamily, Drawing.ScaleSize(0.75f), FontStyle.Italic);
return _fontCapsuleParameterData;
}
}
#endregion
private static bool? m_DisplayNames;
private static bool? m_DisplayNicknames;
private static bool? m_DisplayCustomNicknames;
private static bool? m_DisplayRichedCapsules;
private static bool? m_HideOnLowZoom;
private static bool? m_GroupsOnLowZoom;
private static bool? m_FilterComponents;
private static bool? m_FilterParameters;
private static bool? m_FilterSpecial;
private static bool? m_FilterGraphic;
private static string m_FilterCustom;
private static HashSet<string> _customFilters;
public static bool DisplayNames
{
get
{
return m_DisplayNames ??
(m_DisplayNames =
Grasshopper.Instances.Settings.GetValue(Key_DrawNames, true)).Value;
}
set
{
m_DisplayNames = value;
Grasshopper.Instances.Settings.SetValue(Key_DrawNames, value);
}
}
public static bool DisplayNicknames
{
get
{
return m_DisplayNicknames ??
(m_DisplayNicknames =
Grasshopper.Instances.Settings.GetValue(Key_DisplayNicknames, false)).Value;
}
set
{
m_DisplayNicknames = value;
Grasshopper.Instances.Settings.SetValue(Key_DisplayNicknames, value);
}
}
public static bool DisplayCustomNicknames
{
get
{
return m_DisplayCustomNicknames ??
(m_DisplayCustomNicknames =
Grasshopper.Instances.Settings.GetValue(Key_DisplayCustomNicknames, false)).Value;
}
set
{
m_DisplayCustomNicknames = value;
Grasshopper.Instances.Settings.SetValue(Key_DisplayCustomNicknames, value);
}
}
public static bool DisplayRichedCapsules
{
get
{
return m_DisplayRichedCapsules ??
(m_DisplayRichedCapsules =
Grasshopper.Instances.Settings.GetValue(Key_DisplayRichedCapsules, true)).Value;
}
set
{
m_DisplayRichedCapsules = value;
Grasshopper.Instances.Settings.SetValue(Key_DisplayRichedCapsules, value);
}
}
public static bool HideOnLowZoom
{
get
{
return m_HideOnLowZoom ??
(m_HideOnLowZoom =
Grasshopper.Instances.Settings.GetValue(Key_HideOnLowZoom, true)).Value;
}
set
{
m_HideOnLowZoom = value;
Grasshopper.Instances.Settings.SetValue(Key_HideOnLowZoom, value);
}
}
public static bool GroupsOnLowZoom
{
get
{
return m_GroupsOnLowZoom ??
(m_GroupsOnLowZoom =
Grasshopper.Instances.Settings.GetValue(Key_GroupsOnLowZoom, false)).Value;
}
set
{
m_GroupsOnLowZoom = value;
Grasshopper.Instances.Settings.SetValue(Key_GroupsOnLowZoom, value);
}
}
public static bool FilterComponents
{
get
{
return m_FilterComponents ??
(m_FilterComponents =
Grasshopper.Instances.Settings.GetValue(Key_FilterComponents, true)).Value;
}
set
{
m_FilterComponents = value;
Grasshopper.Instances.Settings.SetValue(Key_FilterComponents, value);
}
}
public static bool FilterParameters
{
get
{
return m_FilterParameters ??
(m_FilterParameters =
Grasshopper.Instances.Settings.GetValue(Key_FilterParameters, true)).Value;
}
set
{
m_FilterParameters = value;
Grasshopper.Instances.Settings.SetValue(Key_FilterParameters, value);
}
}
public static bool FilterSpecial
{
get
{
return m_FilterSpecial ??
(m_FilterSpecial =
Grasshopper.Instances.Settings.GetValue(Key_FilterSpecial, true)).Value;
}
set
{
m_FilterSpecial = value;
Grasshopper.Instances.Settings.SetValue(Key_FilterSpecial, value);
}
}
public static bool FilterGraphic
{
get
{
return m_FilterGraphic ??
(m_FilterGraphic =
Grasshopper.Instances.Settings.GetValue(Key_FilterGraphic, false)).Value;
}
set
{
m_FilterGraphic = value;
Grasshopper.Instances.Settings.SetValue(Key_FilterGraphic, value);
}
}
public static string FilterCustom
{
get
{
return m_FilterCustom ??
(m_FilterCustom =
Grasshopper.Instances.Settings.GetValue(Key_FilterCustom, string.Empty));
}
set
{
m_FilterCustom = value;
Grasshopper.Instances.Settings.SetValue(Key_FilterCustom, value);
UpdateFilterHashset();
}
}
public static bool IsFilterCustomEnabled => !string.IsNullOrEmpty(FilterCustom);
public static bool ShouldExcludeObject(IGH_DocumentObject obj)
{
if (_customFilters == null)
UpdateFilterHashset();
return _customFilters.Contains(obj.Name) || _customFilters.Contains(obj.NickName);
}
private static void UpdateFilterHashset()
{
var enumerable = FilterCustom.Split(',').Select(t => t.Trim());
if (_customFilters == null)
{
_customFilters = new HashSet<string>(enumerable);
}
else
{
_customFilters.Clear();
_customFilters.UnionWith(enumerable);
}
}
public static void ResetFonts()
{
_font = null;
_fontCapsuleInfoName = null;
_fontCapsuleDescription = null;
_fontCapsuleInstanceDescription = null;
_fontCapsuleParameterName = null;
_fontCapsuleParameterData = null;
}
public static void Dispose()
{
_font?.Dispose();
_fontCapsuleInfoName?.Dispose();
_fontCapsuleDescription?.Dispose();
_fontCapsuleInstanceDescription?.Dispose();
_fontCapsuleParameterName?.Dispose();
}
}
}