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

61 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 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],
};