task(A4.5): migrate revcloud/hatch/measure tools to v2
This commit is contained in:
@@ -26,6 +26,8 @@ let arcCenter: Pt | null = null;
|
||||
let arcStartPt: Pt | null = null;
|
||||
/** Laufende Polyline/Polygon-Punkte; Commit per ENTER. */
|
||||
let polyPoints: Pt[] = [];
|
||||
/** Laufende RevCloud-Punkte (A4.5); Commit per ENTER. */
|
||||
let cloudPoints: Pt[] = [];
|
||||
|
||||
function optsOf(ctx: FullToolContext): { stroke: string; layerId: string } {
|
||||
return {
|
||||
@@ -354,16 +356,73 @@ function buildPoly(type: 'polyline' | 'polygon', pts: Pt[], ctx: FullToolContext
|
||||
} as unknown as CADElement;
|
||||
}
|
||||
|
||||
/** V2-Plugin: Kern-Zeichenwerkzeuge (Pilot: line; A4.2: rect; A4.3: circle/arc/poly). */
|
||||
/**
|
||||
* revcloud-Werkzeug (A4.5): Mehrklick-Revisionswolke wie Poly-Muster;
|
||||
* ENTER committet ab 3 Punkten. Legacy-Konvention: arcHeight 8.
|
||||
*/
|
||||
export const revcloudTool: ToolExtensionV2 = {
|
||||
manifest: {
|
||||
id: 'revcloud', label: 'RevCloud', icon: '\u2611', ribbonTab: 'format', tags: ['pro'],
|
||||
description: 'Revisionswolke: Punkte klicken, ENTER beendet',
|
||||
},
|
||||
optionsSchema: [{ key: 'strokeColor', label: 'Farbe', type: 'color' }],
|
||||
handlers: {
|
||||
down(e, ctx) {
|
||||
cloudPoints.push(e.world);
|
||||
ctx.setStatus(`RevCloud: ${cloudPoints.length} Punkte \u2013 ENTER beendet`);
|
||||
},
|
||||
move(e, ctx) {
|
||||
if (cloudPoints.length === 0) return;
|
||||
ctx.setPreview?.(buildRevCloud([...cloudPoints, e.world], ctx));
|
||||
},
|
||||
up() { /* commit via ENTER */ },
|
||||
key(e, ctx) {
|
||||
if (e.key !== 'Enter') return false;
|
||||
if (cloudPoints.length < 3) {
|
||||
ctx.setStatus('RevCloud: mindestens 3 Punkte n\u00f6tig');
|
||||
return true;
|
||||
}
|
||||
const c = ctx as FullToolContext;
|
||||
if (!c.doc) { cloudPoints = []; return true; }
|
||||
const el = buildRevCloud(cloudPoints, c);
|
||||
c.doc.transact(() => c.doc!.addElement(el));
|
||||
cloudPoints = [];
|
||||
ctx.setPreview?.(null);
|
||||
ctx.setStatus(`RevCloud erstellt (${el.id})`);
|
||||
return true;
|
||||
},
|
||||
cancel(ctx) {
|
||||
cloudPoints = [];
|
||||
ctx.setPreview?.(null);
|
||||
ctx.setStatus('RevCloud abgebrochen');
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
function buildRevCloud(pts: Pt[], ctx: FullToolContext): CADElement {
|
||||
const o = optsOf(ctx);
|
||||
const xs = pts.map((p) => p.x);
|
||||
const ys = pts.map((p) => p.y);
|
||||
return {
|
||||
id: uid('revcloud'), type: 'revcloud', layerId: o.layerId,
|
||||
x: (Math.min(...xs) + Math.max(...xs)) / 2,
|
||||
y: (Math.min(...ys) + Math.max(...ys)) / 2,
|
||||
width: Math.max(...xs) - Math.min(...xs),
|
||||
height: Math.max(...ys) - Math.min(...ys),
|
||||
properties: { points: pts.map((p) => ({ x: p.x, y: p.y })), arcHeight: 8, fill: 'none', stroke: '#e0e0e0', strokeWidth: 1.5 },
|
||||
} as unknown as CADElement;
|
||||
}
|
||||
|
||||
/** V2-Plugin: Kern-Zeichenwerkzeuge (A4.x schrittweise migriert). */
|
||||
export const coreDrawingPlugin: PluginV2 = {
|
||||
manifest: {
|
||||
id: 'core-drawing',
|
||||
name: 'Zeichnen (Kern)',
|
||||
version: '1.2.0',
|
||||
version: '1.3.0',
|
||||
author: 'web-cad team',
|
||||
description: 'Grundlegende Zeichenwerkzeuge (V2: Linie, Rechteck, Kreis, Bogen, Polylinie, Polygon).',
|
||||
description: 'Zeichenwerkzeuge V2: Linie, Rechteck, Kreis, Bogen, Polylinie, Polygon, RevCloud.',
|
||||
category: 'tools',
|
||||
enabledByDefault: true,
|
||||
},
|
||||
tools: [lineTool, rectTool, circleTool, arcTool, polylineTool, polygonTool],
|
||||
tools: [lineTool, rectTool, circleTool, arcTool, polylineTool, polygonTool, revcloudTool],
|
||||
};
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* core-measure – Built-in V2-Plugin (Task A4.5).
|
||||
*
|
||||
* measure: 2 Klicks → Distanz+Winkel-Anzeige im Status. KEIN Element-Commit
|
||||
* (Legacy-Verhalten getreu — Messung ist Information, keine Zeichnung).
|
||||
* Distanzformatierung via bestehendem formatDistance(unit, scaleFactor).
|
||||
*/
|
||||
import type { PluginV2, ToolExtensionV2, FullToolContext } from '../../types';
|
||||
import { formatDistance } from '../../../utils/format';
|
||||
|
||||
type MeasurePhase = 0 | 1; // 0=wartet auf Start, 1=wartet auf Ende
|
||||
let measureStart: import('../../../tools/modification/geometry').Pt | null = null;
|
||||
|
||||
export const measureTool: ToolExtensionV2 = {
|
||||
manifest: {
|
||||
id: 'measure',
|
||||
label: 'Messen',
|
||||
icon: '\u2194',
|
||||
ribbonTab: 'view',
|
||||
tags: ['basic'],
|
||||
description: 'Distanz und Winkel zwischen zwei Punkten messen',
|
||||
},
|
||||
optionsSchema: [],
|
||||
handlers: {
|
||||
down(e, ctx) {
|
||||
const c = ctx as FullToolContext;
|
||||
if (!measureStart) {
|
||||
measureStart = e.world;
|
||||
ctx.setStatus('Messung: Endpunkt klicken');
|
||||
return;
|
||||
}
|
||||
// Zweiter Klick → anzeigen (Legacy-Ausgabeformat)
|
||||
const rawDist = Math.hypot(e.world.x - measureStart.x, e.world.y - measureStart.y);
|
||||
const angle = (Math.atan2(e.world.y - measureStart.y, e.world.x - measureStart.x) * 180) / Math.PI;
|
||||
const unit = (c.options.unit as string | undefined) ?? 'mm';
|
||||
const scale = (c.options.scaleFactor as number | undefined) ?? 1;
|
||||
const distStr = formatDistance(rawDist, unit as never, scale);
|
||||
ctx.setStatus(`distance: ${distStr} angle: ${angle.toFixed(1)}\u00b0`);
|
||||
measureStart = null;
|
||||
},
|
||||
cancel(ctx) {
|
||||
measureStart = null;
|
||||
ctx.setStatus('Messung abgebrochen');
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/** V2-Plugin: Messwerkzeuge. */
|
||||
export const coreMeasurePlugin: PluginV2 = {
|
||||
manifest: {
|
||||
id: 'core-measure',
|
||||
name: 'Messen (Kern)',
|
||||
version: '1.0.0',
|
||||
author: 'web-cad team',
|
||||
description: 'Abstandswinkel-Messung ohne Element-Erzeugung.',
|
||||
category: 'tools',
|
||||
enabledByDefault: true,
|
||||
},
|
||||
tools: [measureTool],
|
||||
};
|
||||
@@ -48,16 +48,53 @@ export const selectTool: ToolExtensionV2 = {
|
||||
},
|
||||
};
|
||||
|
||||
/** V2-Plugin: Kern-Bearbeitungswerkzeuge (Pilot: nur select). */
|
||||
/**
|
||||
* 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). */
|
||||
export const coreModifyPlugin: PluginV2 = {
|
||||
manifest: {
|
||||
id: 'core-modify',
|
||||
name: 'Bearbeiten (Kern)',
|
||||
version: '1.0.0',
|
||||
version: '1.1.0',
|
||||
author: 'web-cad team',
|
||||
description: 'Auswahl und Bearbeitung (V2-Pilot: Selektion).',
|
||||
description: 'Auswahl und Bearbeitung (V2: Selektion, Schraffur).',
|
||||
category: 'tools',
|
||||
enabledByDefault: true,
|
||||
},
|
||||
tools: [selectTool],
|
||||
tools: [selectTool, hatchTool],
|
||||
};
|
||||
|
||||
@@ -30,12 +30,14 @@ export { eventToolsPlugin } from './builtin/eventTools';
|
||||
export { coreDrawingPlugin } from './builtin/core-drawing';
|
||||
export { coreModifyPlugin } from './builtin/core-modify';
|
||||
export { coreAnnotatePlugin } from './builtin/core-annotate';
|
||||
export { coreMeasurePlugin } from './builtin/core-measure';
|
||||
|
||||
import { pluginRegistry } from './PluginRegistry';
|
||||
import { eventToolsPlugin } from './builtin/eventTools';
|
||||
import { coreDrawingPlugin } from './builtin/core-drawing';
|
||||
import { coreModifyPlugin } from './builtin/core-modify';
|
||||
import { coreAnnotatePlugin } from './builtin/core-annotate';
|
||||
import { coreMeasurePlugin } from './builtin/core-measure';
|
||||
|
||||
/** Register all built-in plugins */
|
||||
export function registerBuiltinPlugins() {
|
||||
@@ -44,4 +46,5 @@ export function registerBuiltinPlugins() {
|
||||
pluginRegistry.registerV2(coreDrawingPlugin);
|
||||
pluginRegistry.registerV2(coreModifyPlugin);
|
||||
pluginRegistry.registerV2(coreAnnotatePlugin);
|
||||
pluginRegistry.registerV2(coreMeasurePlugin);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user