-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathStepGraph.cs
68 lines (53 loc) · 1.87 KB
/
StepGraph.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
using System.Collections.Generic;
using System.Linq;
using Ara3D.Utils;
namespace Ara3D.StepParser
{
public class StepGraph
{
public StepDocument Document { get; }
public readonly Dictionary<uint, StepNode> Lookup = new();
public StepNode GetNode(uint id)
=> Lookup[id];
public IEnumerable<StepNode> Nodes
=> Lookup.Values;
public StepGraph(StepDocument doc)
{
Document = doc;
foreach (var e in doc.GetInstances())
{
var node = new StepNode(this, e);
Lookup.Add(node.Entity.Id, node);
}
foreach (var n in Nodes)
n.Init();
}
public static StepGraph Create(StepDocument doc)
=> new(doc);
public string ToValString(StepNode node, int depth)
=> ToValString(node.Entity.Entity, depth - 1);
public string ToValString(StepValue value, int depth)
{
if (value == null)
return "";
switch (value)
{
case StepList stepAggregate:
return $"({stepAggregate.Values.Select(v => ToValString(v, depth)).JoinStringsWithComma()})";
case StepEntity stepEntity:
return $"{stepEntity.EntityType}{ToValString(stepEntity.Attributes, depth)}";
case StepId stepId:
return depth <= 0
? "#"
: ToValString(GetNode(stepId.Id), depth - 1);
case StepNumber stepNumber:
case StepRedeclared stepRedeclared:
case StepString stepString:
case StepSymbol stepSymbol:
case StepUnassigned stepUnassigned:
default:
return value.ToString();
}
}
}
}