-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathStepUtilities.cs
More file actions
109 lines (89 loc) · 3.02 KB
/
StepUtilities.cs
File metadata and controls
109 lines (89 loc) · 3.02 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace STEP_Parser
{
public class StepPrinter
{
public StepPrinter(StepFile stepFile)
{
this.stepFile = stepFile;
indentStringTerminator = "└──";
indentStringSpaces = new string(' ', indentStringTerminator.Length);
}
private StepFile stepFile;
private string indentStringTerminator;
private string indentStringSpaces;
private List<StringBuilder> treeStrings;
private StringBuilder currentLine;
public List<string> tree;
//build a string representation of the tree
public List<string> TreeToString()
{
treeStrings = new List<StringBuilder>();
var topLevelIDs = stepFile.GetTopLevelEntities();
foreach (int id in topLevelIDs)
{
PrintChildrenRecursive(id, 0);
}
for (int y = 1; y < treeStrings.Count; y++)
{
for (int x = 0; x < treeStrings[y].Length; x++)
{
FillLineRecursive(y, x);
}
}
tree = new List<string>();
for (int y = 0; y < treeStrings.Count; y++)
{
tree.Add(treeStrings[y].ToString());
}
return tree;
}
public void FillLineRecursive(int y, int x)
{
if (treeStrings[y][x] == '└' && treeStrings[y - 1][x] == ' ')
{
treeStrings[y - 1][x] = '│';
FillLineRecursive(y - 1, x);
}
else if (treeStrings[y][x] == '└' && treeStrings[y - 1][x] == '└')
{
treeStrings[y - 1][x] = '├';
FillLineRecursive(y - 1, x);
}
else if (treeStrings[y][x] == '│' && treeStrings[y - 1][x] == '└')
{
treeStrings[y - 1][x] = '├';
FillLineRecursive(y - 1, x);
}
else if (treeStrings[y][x] == '│' && treeStrings[y - 1][x] == ' ')
{
treeStrings[y - 1][x] = '│';
FillLineRecursive(y - 1, x);
}
}
public void PrintChildrenRecursive(int id, int depth)
{
if (id == -1) return;
List<int> children = stepFile.GetChildren(id);
currentLine = new StringBuilder();
for (int i = 0; i < depth - 1; i++)
{
currentLine.Append(indentStringSpaces);
}
if (depth > 0)
{
currentLine.Append(indentStringTerminator);
}
currentLine.Append(stepFile.Entitys[id].entityID.ToString() + " " + stepFile.Entitys[id].type);
treeStrings.Add(currentLine);
foreach (int cid in children)
{
PrintChildrenRecursive(cid, depth + 1);
}
}
}
}