-
Notifications
You must be signed in to change notification settings - Fork 676
/
Copy pathadvanced-cam.js
204 lines (180 loc) · 6.53 KB
/
advanced-cam.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
var toolpathsInScene = [];
function initTree() {
// $('#filetree').on('keyup change','input', function() {
// var inputVal = $(this).val();
// var newval = parseFloat(inputVal, 3)
// var id = $(this).attr('id');
// var objectseq = $(this).attr('objectseq');
// if (!id) {
// return;
// }
// // console.log('Value for ' +id+ ' changed to ' +newval+ ' for object ' +objectseq );
// if ( id.indexOf('xoffset') == 0 ) {
// objectsInScene[objectseq].position.x = objectsInScene[objectseq].userData.offsetX + newval;
// // console.log('Moving ' +objectsInScene[objectseq].name+ ' to X: '+newval);
// attachBB(objectsInScene[objectseq]);
// } else if ( id.indexOf('yoffset') == 0 ) {
// objectsInScene[objectseq].position.y = objectsInScene[objectseq].userData.offsetY + newval;
// // console.log('Moving ' +objectsInScene[objectseq].name+ ' to Y: '+newval);
// attachBB(objectsInScene[objectseq]);
// } else if ( id.indexOf('svgresol') == 0 ) {
// var svgscale = (25.4 / newval );
// scaleSVGObject(objectsInScene[objectseq], svgscale);
// // objectsInScene[objectseq].scale.x = svgscale;
// // objectsInScene[objectseq].scale.y = svgscale;
// // objectsInScene[objectseq].scale.z = svgscale;
// // putFileObjectAtZero(objectsInScene[objectseq]);
// attachBB(objectsInScene[objectseq]);
// }
// });
// // Fill it up as empty
fillTree()
}
function addJob(id) {
storeUndo(true);
$("#savetpgcode").addClass("disabled");
$("#exportGcodeMenu").addClass("disabled");
// animation to move "doc" to Toolpath - helps user visualise what happened
$("#flyingdoc").css('top', '50%');
$("#flyingdoc").css('left', '50%');
$("#flyingdoc").fadeIn(200);
var offset = $('#toolpathtree').offset()
setTimeout(function() {
$("#flyingdoc").fadeOut(300);
}, 200);
$("#flyingdoc").animate({
left: offset.left + 'px',
top: offset.top + 'px'
}, 600);
var toolpath;
if (id > -1) { // Use Existing Toolpath
// console.log("Using existing toolpath: " + id)
toolpath = toolpathsInScene[id];
} else {
// console.log("Creating new toolpath")
toolpath = new THREE.Group();
}
for (i = 0; i < objectsInScene.length; i++) {
var obj = objectsInScene[i];
obj.traverse(function(child) {
if (child.userData.selected) {
var copy = child.clone()
console.log("copy:", copy)
if (copy.geometry.vertices.length < 3) {
copy.userData.closed = false
} else if (copy.geometry.vertices.length > 2) {
var d = distanceFormula(copy.geometry.vertices[0].x, copy.geometry.vertices[copy.geometry.vertices.length - 1].x, copy.geometry.vertices[0].y, copy.geometry.vertices[copy.geometry.vertices.length - 1].y)
console.log(d)
if (d < 0.1) {
copy.userData.closed = true
} else {
copy.userData.closed = false
}
}
copy.position.copy(obj.position);
toolpath.add(copy);
}
});
};
if (id == -1) { // New Toolpath
if (toolpath.children.length > 0) {
toolpath.name = "Toolpath-" + (toolpathsInScene.length)
toolpath.userData.visible = true;
toolpathsInScene.push(toolpath)
}
setTimeout(function() {
fillTree();
setupJob(toolpathsInScene.length - 1);
}, 800); // launch modal
} else { // Existing toolpath
// toolpath.children = sortToolpathByGeometryStartpoint(toolpath.children);
setTimeout(function() {
fillTree();
toolpathPreview(id);
}, 800); // launch modal
}
}
// -----------------------------------------------------------------------------------------------
function remJob(id) {
storeUndo(true);
$("#savetpgcode").addClass("disabled");
$("#exportGcodeMenu").addClass("disabled");
// animation to remove "doc" from Toolpath - helps user visualize what happened
var offset = $('#toolpathtree').offset()
$("#flyingdoc").css('top', offset.top);
$("#flyingdoc").css('left', offset.left);
$("#flyingdoc").fadeIn(200);
setTimeout(function() {
$("#flyingdoc").fadeOut(300);
}, 200);
$("#flyingdoc").animate({
left: '50%',
top: '50%'
}, 600);
var toolpath;
if (id > -1) { // Use Existing Toolpath
toolpath = toolpathsInScene[id];
}
selectedGeom = objectsInScene.map(a => a.children.map(b => b).filter(c => c.userData.selected)).reduce(a => a);
selectedGeom.forEach(
function(e) {
toolpath_IDS = toolpath.children.map(a => a.geometry.uuid)
toolpath.children.splice(toolpath_IDS.indexOf(e.geometry.uuid), 1);
});
if (toolpath.children.length == 0) {
var message = `Toolpath Container is empty. Would you like to remove it.`
Metro.dialog.create({
width: 500,
title: "Empty Toolpath.",
content: "<div>Toolpath container is empty. Would you like to remove it?</div>",
actions: [{
caption: "<i class=\"far fa-fw fa-save\"></i>Remove",
cls: "js-dialog-close success",
onclick: function() {
toolpathsInScene.splice(id, 1);
fillTree();
}
},
{
caption: "<i class=\"far fa-fw fa-file\"></i>Keep",
cls: "js-dialog-close success",
onclick: function() {}
}
]
});
} else {
var message = `Toolpath container updated.`
Metro.toast.create(message, null, 4000, 'bg-green');
}
setTimeout(function() {
fillTree();
toolpathPreview(id);
}, 800); // launch modal
}
function setSelectionFromToolPath(id) {
storeUndo(true);
$("#savetpgcode").addClass("disabled");
$("#exportGcodeMenu").addClass("disabled");
// animation to remove "doc" from Toolpath - helps user visualize what happened
var offset = $('#toolpathtree').offset()
$("#flyingdoc").css('top', offset.top);
$("#flyingdoc").css('left', offset.left);
$("#flyingdoc").fadeIn(200);
setTimeout(function() {
$("#flyingdoc").fadeOut(300);
}, 200);
$("#flyingdoc").animate({
left: '50%',
top: '50%'
}, 600);
var toolpath;
if (id > -1) { // Use Existing Toolpath
toolpath = toolpathsInScene[id];
}
GeoInToolPath = toolpath.children.map(a => a.geometry.uuid);
ItemsToSelect = objectsInScene.map(a => a.children.map(b => GeoInToolPath.indexOf(b.geometry.uuid))).reduce(a => a);
objectsInScene.map(a => a.children.map(b => b.userData.selected = (GeoInToolPath.indexOf(b.geometry.uuid) >= 0) ? true : false));
setTimeout(function() {
fillTree();
}, 500); // launch modal
}