-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSelectionSetCache.cs
More file actions
73 lines (66 loc) · 2.4 KB
/
Copy pathSelectionSetCache.cs
File metadata and controls
73 lines (66 loc) · 2.4 KB
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
using System.Collections.Generic;
using Autodesk.Navisworks.Api;
namespace AutisAnalytics.NavisworksAtributos
{
internal sealed class SetCacheEntry
{
public string Nome { get; }
public string NomeGravacao { get; }
public string Tipo { get; }
public SavedItem Item { get; }
public ModelItemCollection Itens { get; }
public HashSet<ModelItem> ItensSet { get; }
public SetCacheEntry(string nome, string nomeGravacao, string tipo, SavedItem item, ModelItemCollection itens)
{
Nome = nome;
NomeGravacao = nomeGravacao;
Tipo = tipo;
Item = item;
Itens = itens ?? new ModelItemCollection();
ItensSet = new HashSet<ModelItem>();
foreach (ModelItem mi in Itens)
ItensSet.Add(mi);
}
}
internal static class SelectionSetCache
{
public static List<SetCacheEntry> Collect(Document doc)
{
var resultado = new List<SetCacheEntry>();
if (doc?.SelectionSets?.RootItem is GroupItem group)
Coletar(group, "", resultado);
return resultado;
}
private static void Coletar(GroupItem group, string prefixo, List<SetCacheEntry> resultado)
{
foreach (var child in group.Children)
{
if (child is SelectionSet ss)
{
var itens = ObterItensDoSet(ss);
if (itens.Count == 0) continue;
var tipo = ss.HasExplicitModelItems ? "Selection" : (ss.HasSearch ? "Search" : "Other");
resultado.Add(new SetCacheEntry(
prefixo + ss.DisplayName,
ss.DisplayName,
tipo,
ss,
itens));
}
else if (child is GroupItem grp)
{
Coletar(grp, prefixo + grp.DisplayName + " > ", resultado);
}
}
}
private static ModelItemCollection ObterItensDoSet(SelectionSet ss)
{
var coll = new ModelItemCollection();
if (ss.HasExplicitModelItems)
coll.AddRange(ss.ExplicitModelItems);
else if (ss.HasSearch)
coll.AddRange(ss.Search.FindAll(false));
return coll;
}
}
}