-
Notifications
You must be signed in to change notification settings - Fork 676
/
Copy pathadvanced-cam-tree.js
155 lines (121 loc) · 6.8 KB
/
advanced-cam-tree.js
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
// Handles the Toolpaths / Operations tree
function toggleToolpathVisibility(i, bool) {
toolpathsInScene[i].userData.visible = bool
fillTree();
makeGcode();
}
// move toolpath order up/down
var moveOp = function(index, delta) {
storeUndo(true)
var array = toolpathsInScene;
// var index = array.indexOf(element);
var newIndex = index + delta;
if (newIndex < 0 || newIndex == array.length) return; //Already at the top or bottom.
var indexes = [index, newIndex].sort(); //Sort the indixes
array.splice(indexes[0], 2, array[indexes[1]], array[indexes[0]]); //Replace from lowest index, two elements, reverting the order
};
function fillTree() {
// $('#filetreeheader').empty();
$('#filetree').empty();
// $('#toolpathtreeheader').empty();
$('#toolpathtree').empty();
$('#toolpathsmenu').empty();
// Default Menu
var menuitem = `<li><a href="#" onclick="addJob(-1);"><span class="fa fa-fw fa-plus"></span>Create a new operation...</a></li>`;
$('#toolpathsmenu').append(menuitem);
clearSceneFlag = true;
filldoctree();
if (toolpathsInScene.length > 0) {
$('#generatetpgcode').prop('disabled', false);
$("#generatetpgcode").addClass('success');
var table = `<table class="jobsetuptable" style="width: 100%" id="toolpathstable">`
$('#toolpathtree').append(table)
for (i = 0; i < toolpathsInScene.length; i++) {
if (toolpathsInScene[i].type != "Mesh") {
var operation;
if (toolpathsInScene[i].userData.camOperation) {
operation = toolpathsInScene[i].userData.camOperation
} else {
operation = "not configured <i class='fas fa-times fa-fw fg-red'></i>"
}
var toolp = `<tr class="jobsetupfile" id="toolpathrow` + i + `">
<td>
<table>
<tr>
<td>
<h6 style="margin: 0px 0px;"><small>Toolpath: <b><span contenteditable="true" data-id="` + i + `">` + toolpathsInScene[i].name + `</span></b> [` + operation + `]`
if (!toolpathsInScene[i].userData.visible) {
toolp += " (hidden) "
}
toolp += `</small></h6>
</td>
</tr>
<tr>
<td>
<div class="toolbar mb-0">
`
toolp += `<button style="width: 60px;" class="tool-button primary" data-tooltip="tooltip" data-placement="bottom" title="Configure toolpath" onclick="setupJob(` + i + `);"><i class="fas fa-sliders-h"></i> Edit</button>`
toolp += `</div><div class="toolbar ml-1 mb-0">`
if (i > 0) {
toolp += `<button class="tool-button success" data-tooltip="tooltip" data-placement="bottom" title="Move up" onclick="moveOp(` + i + `, -1); fillTree();"><i class="fa fa-arrow-up fa-fw" aria-hidden="true"></i></button>`
} else {
toolp += `<button class="tool-button success disabled" data-tooltip="tooltip" data-placement="bottom" title="Move up" onclick="moveOp(` + i + `, -1); fillTree();"><i class="fa fa-arrow-up fa-fw" aria-hidden="true"></i></button>`
}
if (i < toolpathsInScene.length - 1) {
toolp += `<button class="tool-button success" data-tooltip="tooltip" data-placement="bottom" title="Move down" onclick="moveOp(` + i + `, 1); fillTree();"><i class="fa fa-arrow-down fa-fw" aria-hidden="true"></i></button>`
} else {
toolp += `<button class="tool-button success disabled" data-tooltip="tooltip" data-placement="bottom" title="Move down" onclick="moveOp(` + i + `, 1); fillTree();"><i class="fa fa-arrow-down fa-fw" aria-hidden="true"></i></button>`
}
toolp += `</div><div class="toolbar ml-1 mb-0">`
toolp += `<button class="tool-button secondary" data-tooltip="tooltip" data-placement="bottom" title="Reselect toolpaths" onclick="setSelectionFromToolPath(` + i + `)"><i class="far fa-object-group fa-fw"></i></button>`
toolp += `</div><div class="toolbar ml-1 mb-0">`
if (toolpathsInScene[i].userData.visible) {
toolp += `<button class="tool-button warning" data-tooltip="tooltip" data-placement="bottom" title="Hide toolpath and exclude from G-Code generation" onclick="toggleToolpathVisibility(` + i + `, false);"><i class="fa fa-fw fa-eye-slash" aria-hidden="true"></i></button>`
} else {
toolp += `<button class="tool-button alert" data-tooltip="tooltip" data-placement="bottom" title="Show toolpath and include in G-Code generation" onclick="toggleToolpathVisibility(` + i + `, true);"><i class="fa fa-fw fa-eye" aria-hidden="true"></i></button>`
}
toolp += `<button class="tool-button alert" data-tooltip="tooltip" data-placement="bottom" title="Delete toolpath" onclick="storeUndo(); toolpathsInScene.splice('` + i + `', 1); fillTree();"><i class="fa fa-times fa-fw" aria-hidden="true"></i></button>`
toolp += `</div>`
toolp += `
<span class="tally alert" style="display: none; margin-top: 6px;" id="toolpathSpinner` + i + `"><i class="fas fa-spinner fa-pulse"></i><small> calculating...</small></span>
</ul>
</td>
</tr>
</table>
</td>
</tr>
`
}
$('#toolpathstable').append(toolp);
// append toolpath to menu
var string = `Add selection to: ` + toolpathsInScene[i].name + `: ` + operation
if (string.length > 48) {
string = string.substring(0, 48) + "..."
}
var menuitem = `<li><a href="#" onclick="addJob(` + i + `)">` + string + `</a></li>`;
$('#toolpathsmenu').append(menuitem);
// append removal toolpath to menu
var string = `Delete selection from: ` + toolpathsInScene[i].name + `: ` + operation
if (string.length > 48) {
string = string.substring(0, 48) + "..."
}
var menuitem = `<li><a href="#" onclick="remJob(` + i + `)">` + string + `</a></li>`;
$('#toolpathsmenu').append(menuitem);
}
} else {
var instructions = `<p class="text-secondary text-center mt-3">Please select some Vectors by clicking them in the viewer or using the Documents tree above. Hold down Ctrl to select multiples, Ctrl+A for Select-All, etc. <br>Add them to a toolpath using the <kbd class="bg-openbuilds"> <i class="fa fa-plus" aria-hidden="true"></i> Create Toolpath</kbd> button</p>`
$('#toolpathtree').append(instructions);
$('#generatetpgcode').prop('disabled', true);
$("#generatetpgcode").removeClass('success');
} // End of if (toolpathsInScene.length > 0)
var tableend = `
</table>
`
$('#toolpathstable').append(tableend)
// Register event to Edit Toolpath Name inplace
$('#toolpathstable .entity-job').on('input', function() {
var $this = $(this);
var data = $this.data();
toolpathsInScene[data.id].name = $this.text();
});
}