task(A4.5): migrate revcloud/hatch/measure tools to v2

This commit is contained in:
Agent Zero
2026-08-27 00:48:28 +02:00
parent af46f0028a
commit 464ddb91cc
5 changed files with 255 additions and 8 deletions
@@ -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],
};