mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 08:25:19 +01:00
28 lines
No EOL
879 B
JavaScript
28 lines
No EOL
879 B
JavaScript
import {state} from 'lstream';
|
|
import {DATUM, EDGE, FACE, SHELL, SKETCH_OBJECT} from '../../model/entities';
|
|
|
|
const SELECTABLE_ENTITIES = [FACE, EDGE, SKETCH_OBJECT, DATUM, SHELL];
|
|
|
|
|
|
export function defineDefaultSelectionState(ctx) {
|
|
ctx.streams.selection = {
|
|
};
|
|
SELECTABLE_ENTITIES.forEach(entity => {
|
|
ctx.streams.selection[entity] = state([]);
|
|
});
|
|
|
|
SELECTABLE_ENTITIES.forEach(entity => {
|
|
let entitySelectApi = {
|
|
objects: [],
|
|
single: undefined
|
|
};
|
|
ctx.services.selection[entity] = entitySelectApi;
|
|
let selectionState = streams.selection[entity];
|
|
selectionState.attach(selection => {
|
|
entitySelectApi.objects = selection.map(id => services.cadRegistry.findEntity(entity, id));
|
|
entitySelectApi.single = entitySelectApi.objects[0];
|
|
});
|
|
entitySelectApi.select = selection => selectionState.value = selection;
|
|
});
|
|
|
|
} |