rework and improve tool bar pop menus
This commit is contained in:
parent
9a02408e7b
commit
3a97903017
9 changed files with 179 additions and 129 deletions
|
|
@ -488,10 +488,6 @@ gapp.register("kiri.init", [], (root, exports) => {
|
|||
case cca('m'): // mirror object
|
||||
mirrorSelection();
|
||||
break;
|
||||
case cca('R'): // toggle slice render mode
|
||||
renderMode++;
|
||||
api.function.slice();
|
||||
break;
|
||||
case cca('a'):
|
||||
if (api.view.get() === VIEWS.ARRANGE) {
|
||||
// auto arrange items on platform
|
||||
|
|
@ -2231,9 +2227,9 @@ gapp.register("kiri.init", [], (root, exports) => {
|
|||
let dv = parseFloat(e.target.value || 1),
|
||||
pv = parseFloat(e.target.was || 1),
|
||||
ra = dv / pv,
|
||||
xv = parseFloat(ui.sizeX.was),
|
||||
yv = parseFloat(ui.sizeY.was),
|
||||
zv = parseFloat(ui.sizeZ.was),
|
||||
xv = parseFloat(ui.sizeX.was ?? ui.scaleX.value) || 1,
|
||||
yv = parseFloat(ui.sizeY.was ?? ui.scaleY.value) || 1,
|
||||
zv = parseFloat(ui.sizeZ.was ?? ui.scaleZ.value) || 1,
|
||||
ta = e.target,
|
||||
xc = ui.lockX.checked,
|
||||
yc = ui.lockY.checked,
|
||||
|
|
@ -2259,9 +2255,9 @@ gapp.register("kiri.init", [], (root, exports) => {
|
|||
let dv = parseFloat(e.target.value || 1),
|
||||
pv = parseFloat(e.target.was || 1),
|
||||
ra = dv / pv,
|
||||
xv = parseFloat(ui.scaleX.was),
|
||||
yv = parseFloat(ui.scaleY.was),
|
||||
zv = parseFloat(ui.scaleZ.was),
|
||||
xv = parseFloat(ui.scaleX.was ?? ui.scaleX.value) || 1,
|
||||
yv = parseFloat(ui.scaleY.was ?? ui.scaleY.value) || 1,
|
||||
zv = parseFloat(ui.scaleZ.was ?? ui.scaleY.value) || 1,
|
||||
ta = e.target,
|
||||
xc = ui.lockX.checked,
|
||||
yc = ui.lockY.checked,
|
||||
|
|
@ -2273,6 +2269,7 @@ gapp.register("kiri.init", [], (root, exports) => {
|
|||
xr = ((tl && xc) || (!tl && xt) ? ra : 1),
|
||||
yr = ((tl && yc) || (!tl && yt) ? ra : 1),
|
||||
zr = ((tl && zc) || (!tl && zt) ? ra : 1);
|
||||
|
||||
api.selection.scale(xr,yr,zr);
|
||||
ui.scaleX.was = ui.scaleX.value = xv * xr;
|
||||
ui.scaleY.was = ui.scaleY.value = yv * yr;
|
||||
|
|
@ -2280,13 +2277,9 @@ gapp.register("kiri.init", [], (root, exports) => {
|
|||
}
|
||||
|
||||
function selectionRotate(e) {
|
||||
let deg = parseFloat(e.target.value) * DEG2RAD;
|
||||
e.target.value = 0;
|
||||
switch (e.target.id.split('').pop()) {
|
||||
case 'x': return api.selection.rotate(deg,0,0);
|
||||
case 'y': return api.selection.rotate(0,deg,0);
|
||||
case 'z': return api.selection.rotate(0,0,deg);
|
||||
}
|
||||
let val = parseFloat(e.target.value) || 0;
|
||||
// let deg = val * DEG2RAD;
|
||||
e.target.value = val;
|
||||
}
|
||||
|
||||
space.event.onEnterKey([
|
||||
|
|
@ -2393,30 +2386,6 @@ gapp.register("kiri.init", [], (root, exports) => {
|
|||
}
|
||||
};
|
||||
|
||||
// space.mouse.up((event, int) => {
|
||||
// // context menu
|
||||
// if (event.button === 2) {
|
||||
// let et = event.target;
|
||||
// if (et.tagName != 'CANVAS' && et.id != 'context-menu') {
|
||||
// return;
|
||||
// }
|
||||
// let full = api.view.is_arrange();
|
||||
// for (let key of ["layflat","mirror","duplicate"]) {
|
||||
// $(`context-${key}`).disabled = !full;
|
||||
// }
|
||||
// let style = ui.context.style;
|
||||
// style.display = 'flex';
|
||||
// style.left = `${event.clientX-3}px`;
|
||||
// style.top = `${event.clientY-3}px`;
|
||||
// ui.context.onmouseleave = () => {
|
||||
// style.display = '';
|
||||
// };
|
||||
// event.preventDefault();
|
||||
// event.stopPropagation();
|
||||
// contextInt = int;
|
||||
// }
|
||||
// });
|
||||
|
||||
space.mouse.downSelect((int, event) => {
|
||||
if (api.feature.on_mouse_down) {
|
||||
if (int) {
|
||||
|
|
@ -2701,19 +2670,22 @@ gapp.register("kiri.init", [], (root, exports) => {
|
|||
api.selection.update_info();
|
||||
};
|
||||
// rotation buttons
|
||||
let d = (Math.PI / 180) * 5;
|
||||
$('rot_x_lt').onclick = () => { api.selection.rotate(-d,0,0) };
|
||||
$('rot_x_gt').onclick = () => { api.selection.rotate( d,0,0) };
|
||||
$('rot_y_lt').onclick = () => { api.selection.rotate(0,-d,0) };
|
||||
$('rot_y_gt').onclick = () => { api.selection.rotate(0, d,0) };
|
||||
$('rot_z_lt').onclick = () => { api.selection.rotate(0,0, d) };
|
||||
$('rot_z_gt').onclick = () => { api.selection.rotate(0,0,-d) };
|
||||
let d = (Math.PI / 180);
|
||||
$('rot_x_lt').onclick = () => { api.selection.rotate(-d * $('rot_x').value,0,0) };
|
||||
$('rot_x_gt').onclick = () => { api.selection.rotate( d * $('rot_x').value,0,0) };
|
||||
$('rot_y_lt').onclick = () => { api.selection.rotate(0,-d * $('rot_y').value,0) };
|
||||
$('rot_y_gt').onclick = () => { api.selection.rotate(0, d * $('rot_y').value,0) };
|
||||
$('rot_z_lt').onclick = () => { api.selection.rotate(0,0, d * $('rot_z').value) };
|
||||
$('rot_z_gt').onclick = () => { api.selection.rotate(0,0,-d * $('rot_z').value) };
|
||||
// rendering options
|
||||
$('render-ghost').onclick = () => { api.view.wireframe(false, 0, api.view.is_arrange() ? 0.4 : 0.25); };
|
||||
$('render-wire').onclick = () => { api.view.wireframe(true, 0, api.space.is_dark() ? 0.25 : 0.5); };
|
||||
$('render-solid').onclick = () => { api.view.wireframe(false, 0, 1); };
|
||||
// mesh buttons
|
||||
$('mesh-swap').onclick = () => { api.widgets.replace() };
|
||||
$('mesh-enable').onclick = () => { api.selection.enable() };
|
||||
$('mesh-disable').onclick = () => { api.selection.disable() };
|
||||
$('mesh-rename').onclick = () => { api.widgets.rename() };
|
||||
$('mesh-export-stl').onclick = () => { objectsExport('stl') };
|
||||
$('mesh-export-obj').onclick = () => { objectsExport('obj') };
|
||||
$('context-duplicate').onclick = duplicateSelection;
|
||||
|
|
|
|||
|
|
@ -560,7 +560,7 @@ gapp.register("kiri.main", [], (root, exports) => {
|
|||
ann.url = widget.meta.url;
|
||||
});
|
||||
SDB.setItem('ws-widgets', o2js(newWidgets));
|
||||
oldWidgets.forEach(function(wid) {
|
||||
oldWidgets.forEach(wid => {
|
||||
Widget.deleteFromState(wid);
|
||||
});
|
||||
// eliminate dangling saved widgets
|
||||
|
|
|
|||
|
|
@ -226,25 +226,29 @@ function platformUpdateBounds() {
|
|||
|
||||
function platformSelectedCount() {
|
||||
return api.view.is_arrange() ? api.selection.count() : 0;
|
||||
// return viewMode === VIEWS.ARRANGE ? selectedMeshes.length : 0;
|
||||
}
|
||||
|
||||
function platformUpdateSelected() {
|
||||
const settings = current();
|
||||
|
||||
const { device } = settings;
|
||||
const { extruders } = device;
|
||||
const { selection, ui } = api;
|
||||
|
||||
const selreal = selection.widgets();
|
||||
const selwid = selection.widgets(true);
|
||||
const selreal = selection.widgets(false).length;
|
||||
const selcount = selwid.length;
|
||||
|
||||
$('mesh-enable').disabled = selreal != 1;
|
||||
$('mesh-disable').disabled = selreal != 1;
|
||||
$('mesh-rename').disabled = selcount != 1;
|
||||
$('mesh-swap').disabled = selcount != 1;
|
||||
|
||||
if (selcount) {
|
||||
let enaC = selwid.filter(w => w.meta.disabled !== true).length;
|
||||
let disC = selwid.filter(w => w.meta.disabled === true).length;
|
||||
if (api.feature.meta && selcount === 1) {
|
||||
let sel = selwid[0];
|
||||
let name = sel.meta.file || sel.meta.url;
|
||||
if (api.feature.meta && selcount) {
|
||||
let name = selwid[0].meta.file || selwid[0].meta.url;
|
||||
if (name) {
|
||||
name = name
|
||||
.toLowerCase()
|
||||
|
|
@ -255,20 +259,19 @@ function platformUpdateSelected() {
|
|||
if (sp >= 0) {
|
||||
name = name.substring(sp + 1);
|
||||
}
|
||||
ui.mesh.name.innerText = name;
|
||||
}
|
||||
ui.mesh.points.innerText = util.comma(sel.meta.vertices);
|
||||
ui.mesh.faces.innerText = util.comma(sel.meta.vertices / 3);
|
||||
let vert = selwid.map(w => w.meta.vertices).reduce((a,b) => a+b);
|
||||
ui.mesh.points.innerText = util.comma(vert);
|
||||
ui.mesh.faces.innerText = util.comma(vert / 3);
|
||||
} else {
|
||||
ui.mesh.name.innerText = `[${selcount}]`;
|
||||
ui.mesh.points.innerText = '-';
|
||||
ui.mesh.faces.innerText = '-';
|
||||
}
|
||||
} else {
|
||||
ui.mesh.name.innerText = '[0]';
|
||||
ui.mesh.points.innerText = '-';
|
||||
ui.mesh.faces.innerText = '-';
|
||||
}
|
||||
ui.mesh.name.innerText = selection.widgets(false).length;
|
||||
|
||||
if (extruders) {
|
||||
for (let i = 0; i < extruders.length; i++) {
|
||||
|
|
@ -867,6 +870,7 @@ function fitDeviceToWidgets() {
|
|||
const platform = api.platform = {
|
||||
fit: fitDeviceToWidgets,
|
||||
add: platformAdd,
|
||||
changed: platformChanged,
|
||||
delete: platformDelete,
|
||||
layout: platformLayout,
|
||||
group: platformGroup,
|
||||
|
|
|
|||
|
|
@ -24,12 +24,18 @@ function for_groups(fn) {
|
|||
function for_widgets(fn, noauto) {
|
||||
let m = selectedMeshes;
|
||||
let w = api.widgets.all();
|
||||
if (m.length === 0 && w.length === 1) {
|
||||
m = noauto ? [] : [ w[0].mesh ];
|
||||
if (m.length === 0 && w.length) {
|
||||
m = noauto ? [] : w.map(w => w.mesh);
|
||||
}
|
||||
m.slice().forEach(mesh => { fn(mesh.widget) });
|
||||
}
|
||||
|
||||
function for_status(fn) {
|
||||
api.widgets.all().forEach(w => {
|
||||
fn(w, selectedMeshes.contains(w.mesh));
|
||||
});
|
||||
}
|
||||
|
||||
function for_meshes(fn) {
|
||||
selectedMeshes.slice().forEach(mesh => { fn(mesh) });
|
||||
}
|
||||
|
|
@ -276,6 +282,7 @@ const selection = api.selection = {
|
|||
duplicate,
|
||||
for_groups,
|
||||
for_meshes,
|
||||
for_status,
|
||||
for_widgets,
|
||||
update_bounds,
|
||||
update_info,
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ function startIt() {
|
|||
console.log(`${opName} cannot pre-empt hover`);
|
||||
return;
|
||||
}
|
||||
$('lay-flat').classList.add('selected');
|
||||
api.feature.hover = true;
|
||||
enabled = true;
|
||||
alert = api.show.alert(`[ESC] to end ${opName}`, 600000);
|
||||
|
|
@ -74,7 +73,6 @@ function startIt() {
|
|||
function endIt() {
|
||||
if (enabled) {
|
||||
api.hide.alert(alert);
|
||||
$('lay-flat').classList.remove('selected');
|
||||
api.feature.hover = false;
|
||||
enabled = false;
|
||||
alert = undefined;
|
||||
|
|
|
|||
|
|
@ -127,7 +127,6 @@ class Widget {
|
|||
return;
|
||||
}
|
||||
const widget = this;
|
||||
// console.log({ saveState: widget.id });
|
||||
index().put('ws-save-'+this.id, {
|
||||
geo: widget.getGeoVertices({ unroll: false }).slice(),
|
||||
track: widget.track,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,20 @@ function annotate(id) {
|
|||
return (w.anno = w.anno || {});
|
||||
}
|
||||
|
||||
function rename() {
|
||||
let widgets = api.selection.widgets(true);
|
||||
if (widgets.length !== 1) {
|
||||
return;
|
||||
}
|
||||
let widget = widgets[0];
|
||||
const newname = prompt("new widget name", widget.meta.file);
|
||||
if (newname) {
|
||||
widget.meta.file = newname;
|
||||
api.platform.changed();
|
||||
api.space.save(true);
|
||||
}
|
||||
}
|
||||
|
||||
function replace(vertices) {
|
||||
let widgets = api.selection.widgets(true);
|
||||
if (!widgets.length) {
|
||||
|
|
@ -82,6 +96,7 @@ const widgets = api.widgets = {
|
|||
new: newWidget,
|
||||
map,
|
||||
meshes,
|
||||
rename,
|
||||
replace,
|
||||
opacity,
|
||||
annotate,
|
||||
|
|
|
|||
Loading…
Reference in a new issue