-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathStepNode.cs
59 lines (49 loc) · 1.41 KB
/
StepNode.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
using System.Collections.Generic;
using System.Linq;
using Ara3D.Utils;
namespace Ara3D.StepParser
{
public class StepNode
{
public readonly StepGraph Graph;
public readonly StepInstance Entity;
public StepNode(StepGraph g, StepInstance e)
{
Graph = g;
Entity = e;
}
public List<StepNode> Nodes { get; } = new();
private void AddNodes(StepValue value)
{
if (value is StepId id)
{
var n = Graph.GetNode(id.Id);
Nodes.Add(n);
}
else if (value is StepList agg)
{
foreach (var v in agg.Values)
AddNodes(v);
}
}
public void Init()
{
foreach (var a in Entity.AttributeValues)
AddNodes(a);
}
public override string ToString()
=> Entity.ToString();
public string ToGraph(HashSet<StepNode> prev = null)
{
prev ??= new HashSet<StepNode>();
if (prev.Contains(this))
return "_";
var nodeStr = Nodes.Select(n => n.ToGraph(prev)).JoinStringsWithComma();
return $"{EntityType}({nodeStr})";
}
public string EntityType
=> Entity.EntityType;
public string QuickHash()
=> $"{EntityType}:{Nodes.Count}";
}
}