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)`);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-08-27 00:48:28 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* 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)',
|
2026-08-27 00:48:28 +02:00
|
|
|
|
version: '1.1.0',
|
2026-08-26 21:30:54 +02:00
|
|
|
|
author: 'web-cad team',
|
2026-08-27 00:48:28 +02:00
|
|
|
|
description: 'Auswahl und Bearbeitung (V2: Selektion, Schraffur).',
|
2026-08-26 21:30:54 +02:00
|
|
|
|
category: 'tools',
|
|
|
|
|
|
enabledByDefault: true,
|
|
|
|
|
|
},
|
2026-08-27 00:48:28 +02:00
|
|
|
|
tools: [selectTool, hatchTool],
|
2026-08-26 21:30:54 +02:00
|
|
|
|
};
|