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],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user