Files
web-cad/frontend/src/plugins/builtin/core-modify/index.ts
T

101 lines
3.2 KiB
TypeScript
Raw Normal View History

2026-08-26 21:30:54 +02:00
/**
* core-modify Built-in V2-Plugin (Task A3 Pilot).
*
* Werkzeuge: select (Pilotportierung aus Legacy handleSelectDown).
* Pilot-Scope: Klick-Auswahl inkl. Group-Bewusstheit via SelectionBridge;
* Marquee/Box-Auswahl Migration folgt in A4 (Legacy bleibt parallel aktiv).
*/
import type { PluginV2, ToolExtensionV2 } from '../../types';
/**
* select-Werkzeug: Klick wählt Element direkt (Shift=additiv, Ctrl=subtraktiv).
*/
export const selectTool: ToolExtensionV2 = {
manifest: {
id: 'select',
label: 'Auswahl',
icon: '\u2196',
ribbonTab: 'canvas',
tags: ['basic'],
description: 'Elemente anklicken zum Auswählen',
},
optionsSchema: [],
handlers: {
down(e, ctx) {
const bridge = (ctx as import('../../types').FullToolContext).selection;
if (!bridge) return;
const additive = e.shift;
const subtractive = e.ctrl;
const hit = bridge.hitTest(e.world.x, e.world.y, 5);
if (!hit) {
// Leerer Klick: Selektion leeren (außer additiv)
if (!additive && !subtractive) bridge.setIds([]);
return;
}
let ids = new Set(bridge.getIds());
if (subtractive) {
ids.delete(hit.id);
} else {
ids.add(hit.id);
if (!additive) ids = new Set([hit.id]); // ohne Shift: nur das getroffene
}
bridge.setIds(Array.from(ids));
ctx.setStatus(`Selektion: ${ids.size} Element(e)`);
},
},
};
/**
* hatch-Werkzeug (A4.5): Klick auf geschlossenes Element (rect/circle/polygon)
* aktiviert Schraffur — Portierung aus Legacy handleHatchDown, aber jetzt via
* doc.updateElement (eigene Undo-Transaktion statt Callback-Direktaufruf).
*/
export const hatchTool: ToolExtensionV2 = {
manifest: {
id: 'hatch', label: 'Schraffur', icon: '\u2593', ribbonTab: 'format', tags: ['pro'],
description: 'Geschlossenes Element anklicken zum Schraffieren',
},
optionsSchema: [
{ key: 'hatchPattern', label: 'Muster', type: 'select', options: [
{ value: 'lines', label: 'Linien' },
{ value: 'cross', label: 'Kreuz' },
] },
{ key: 'hatchSpacing', label: 'Abstand', type: 'number', min: 2, max: 40 },
],
handlers: {
down(e, ctx) {
const c = ctx as import('../../types').FullToolContext;
const bridge = c.selection;
if (!bridge || !c.doc) return;
const hit = bridge.hitTest(e.world.x, e.world.y, 5);
if (!hit || !['rect', 'circle', 'polygon'].includes(hit.type)) {
ctx.setStatus('Schraffur: nur rect/circle/polygon');
return;
}
const pattern = (c.options.hatchPattern as string | undefined) ?? 'lines';
const spacing = (c.options.hatchSpacing as number | undefined) ?? 8;
c.doc.updateElement(hit.id, {
properties: { hatch: true, hatchPattern: pattern, hatchSpacing: spacing },
});
ctx.setStatus(`Schraffur auf ${hit.id} (${pattern})`);
},
},
};
/** V2-Plugin: Kern-Bearbeitungswerkzeuge (Pilot: select; A4.5: hatch). */
2026-08-26 21:30:54 +02:00
export const coreModifyPlugin: PluginV2 = {
manifest: {
id: 'core-modify',
name: 'Bearbeiten (Kern)',
version: '1.1.0',
2026-08-26 21:30:54 +02:00
author: 'web-cad team',
description: 'Auswahl und Bearbeitung (V2: Selektion, Schraffur).',
2026-08-26 21:30:54 +02:00
category: 'tools',
enabledByDefault: true,
},
tools: [selectTool, hatchTool],
2026-08-26 21:30:54 +02:00
};