import React, {useContext, useState} from 'react'; import cx from 'classnames'; import ls from './SketchObjectExplorer.less' import {combine} from 'lstream'; import {useStream} from "ui/effects"; import {SketcherAppContext} from "./SketcherAppContext"; export function SketchObjectExplorer() { const [modification, setModification] = useState(0); const objects = useStream(ctx => ctx.viewer.streams.objects); const selection = useStream(ctx => ctx.viewer.streams.selection); const ctx = useContext(SketcherAppContext); if (!objects || !selection) { return null } const select = (obj, exclusive) => { let viewer = ctx.viewer; viewer.select([obj], exclusive); viewer.refresh(); }; const deselect = obj => { let viewer = ctx.viewer; viewer.deselect(obj); viewer.refresh(); }; const setRole = (obj, role) => { let viewer = ctx.viewer; if (obj.aux) { return; } obj.role = role; viewer.refresh(); }; const tweakSelection = (obj, shiftKey) => { if (obj.marked) { deselect(obj); } else { select(obj, !shiftKey); } }; const tweakRole = (obj) => { if (obj.role === 'construction') { setRole(obj, null); } else if (obj.role === null) { setRole(obj, 'construction'); } setModification(count => count + 1); }; const getObjectRole = (o) => { if (o.aux) { return B } else if (o.role === 'construction') { return tweakRole(o)} title="construction object not used for 3D operations" className={cx(ls.objectRole, ls.construction)}>C } else { return tweakRole(o)} title="sketch object participates in 3D operations" className={cx(ls.objectRole, ls.sketch)}>S } }; return Objects {objects.map(o => {getObjectRole(o)} tweakSelection(o, e.shiftKey)} className={cx(ls.objectTag, o.marked && ls.selected)}>{o.simpleClassName} {o.id} ... )} } function ObjectIcon({object}) { const Icon = object.icon; return ; } function getClassName() { return null; }