61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
/**
|
||
* 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],
|
||
};
|