checkpoint widget group/ungroup

This commit is contained in:
Stewart Allen 2021-03-01 00:22:07 -05:00
commit 3f5ccf5158
4 changed files with 72 additions and 13 deletions

View file

@ -162,6 +162,10 @@
})
};
AP.uniq = function() {
return this.slice().sort().filter((x, i, a) => !i || x != a[i-1]);
};
/** ******************************************************************
* String prototype helpers
******************************************************************* */

View file

@ -331,6 +331,12 @@
if (API.feature.on_key) {
if (API.feature.on_key({key:evt})) return;
}
if (evt.ctrlKey) {
switch (evt.key) {
case 'g': return API.group.merge();
case 'u': return API.group.split();
}
}
switch (evt.charCode) {
case cca('`'): API.show.slices(0); break;
case cca('0'): API.show.slices(API.var.layer_max); break;
@ -468,11 +474,9 @@
function duplicateSelection() {
API.selection.for_widgets(function(widget) {
let mesh = widget.mesh;
mesh.geometry = mesh.geometry.clone();
mesh.material = mesh.material.clone();
let bb = mesh.getBoundingBox();
let ow = widget;
let nw = API.widgets.new().loadGeometry(mesh.geometry);
let nw = API.widgets.new().loadGeometry(mesh.geometry.clone());
nw.meta.file = ow.meta.file;
nw.meta.vertices = ow.meta.vertices;
nw.move(bb.max.x - bb.min.x + 1, 0, 0);

View file

@ -80,7 +80,10 @@
scale: scaleSelection,
rotate: rotateSelection,
meshes: function() { return selectedMeshes.slice() },
widgets: function() { return selectedMeshes.slice().map(m => m.widget) },
widgets: function(orall) {
let sel = selectedMeshes.slice().map(m => m.widget);
return sel.length ? sel : orall ? WIDGETS.slice() : []
},
for_groups: forSelectedGroups,
for_meshes: forSelectedMeshes,
for_widgets: forSelectedWidgets,
@ -290,6 +293,10 @@
clear: KIRI.client.clear,
parse: loadCode
},
group: {
merge: groupMerge,
split: groupSplit,
},
hide: {
alert: function(rec) { alert2cancel(rec) },
import: function() { },
@ -831,13 +838,10 @@
}
function forSelectedGroups(f) {
let m = selectedMeshes;
if (m.length === 0 && WIDGETS.length === 1) m = [ WIDGETS[0].mesh ];
let v = [];
m.slice().forEach(function (mesh) {
if (v.indexOf(mesh.widget.group) < 0) f(mesh.widget);
v.push(mesh.widget.group);
});
let groups = API.selection.widgets(true).map(w => w.group).uniq();
for (let group of groups) {
f(group[0]);
}
}
function forSelectedWidgets(f,noauto) {
@ -1334,6 +1338,14 @@
* Selection Functions
******************************************************************* */
function groupMerge() {
Widget.Groups.merge(API.selection.widgets(true));
}
function groupSplit() {
Widget.Groups.split(API.selection.widgets(false));
}
function updateSelectedInfo() {
let bounds = new THREE.Box3(), track;
forSelectedMeshes(mesh => {
@ -1657,10 +1669,17 @@
return settings.bounds = bounds;
}
function platformSelect(widget, shift) {
function platformSelect(widget, shift, recurse = true) {
if (viewMode !== VIEWS.ARRANGE) {
return;
}
// apply deselect to entire group
if (recurse && widget && widget.group.length > 1) {
for (let w of widget.group) {
platformSelect(w, true, false);
}
return;
}
let mesh = widget.mesh,
sel = (selectedMeshes.indexOf(mesh) >= 0);
if (sel) {
@ -1735,12 +1754,19 @@
}
}
function platformDeselect(widget) {
function platformDeselect(widget, recurse = true) {
if (viewMode !== VIEWS.ARRANGE) {
// don't de-select and re-color widgets in,
// for example, sliced or preview modes
return;
}
// apply deselect to entire group
if (recurse && widget && widget.group.length > 1) {
for (let w of widget.group) {
platformDeselect(w, false);
}
return;
}
if (!widget) {
forAllWidgets(function(widget) {
platform.deselect(widget);

View file

@ -36,6 +36,31 @@
return groups.slice()
},
merge: (widgets) => {
let grps = widgets.map(w => w.group).uniq();
if (grps.length > 1) {
let root = grps.shift();
for (let grp of grps) {
for (let w of grp) {
w.group = root;
root.push(w);
}
groups.splice(groups.indexOf(grp),1);
}
}
},
split: (widgets) => {
for (let group of widgets.map(w => w.group).uniq()) {
groups.splice(groups.indexOf(group),1);
for (let widget of group) {
let nugroup = Group.forid(widget.id);
nugroup.push(widget);
widget.group = nugroup;
}
}
},
forid: function(id) {
for (let i=0; i<groups.length; i++) {
if (groups[i].id === id) return groups[i];