T24: Use shared types from cad.types.ts in importService
This commit is contained in:
@@ -1,55 +1,10 @@
|
|||||||
import type { YjsDocument } from '../crdt/YjsDocument';
|
import type { YjsDocument } from '../crdt/YjsDocument';
|
||||||
|
import type {
|
||||||
// ── Types ────────────────────────────────────────────────────────────────────
|
CADLayer,
|
||||||
|
CADProperties,
|
||||||
interface CADLayer {
|
CADElement,
|
||||||
id: string;
|
ImportData,
|
||||||
name: string;
|
} from '../types/cad.types';
|
||||||
visible: boolean;
|
|
||||||
locked: boolean;
|
|
||||||
color?: string;
|
|
||||||
lineType?: string;
|
|
||||||
transparency?: number;
|
|
||||||
sortOrder?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CADProperties {
|
|
||||||
fill?: string;
|
|
||||||
stroke?: string;
|
|
||||||
strokeWidth?: number;
|
|
||||||
rotation?: number;
|
|
||||||
lineType?: 'solid' | 'dashed' | 'dotted';
|
|
||||||
radius?: number;
|
|
||||||
x1?: number;
|
|
||||||
y1?: number;
|
|
||||||
x2?: number;
|
|
||||||
y2?: number;
|
|
||||||
points?: Array<{ x: number; y: number }>;
|
|
||||||
text?: string;
|
|
||||||
fontSize?: number;
|
|
||||||
startAngle?: number;
|
|
||||||
endAngle?: number;
|
|
||||||
[key: string]: unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CADElement {
|
|
||||||
id: string;
|
|
||||||
type: string;
|
|
||||||
layerId: string;
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
properties: CADProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ImportData {
|
|
||||||
version: string;
|
|
||||||
exportedAt: number;
|
|
||||||
projectMeta: Record<string, unknown>;
|
|
||||||
layers: CADLayer[];
|
|
||||||
elements: CADElement[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ImportResult {
|
export interface ImportResult {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
@@ -59,7 +14,7 @@ export interface ImportResult {
|
|||||||
warnings: string[];
|
warnings: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── JSON Import ──────────────────────────────────────────────────────────────
|
// ── JSON Import ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import a JSON string (from exportJSON) into a YjsDocument.
|
* Import a JSON string (from exportJSON) into a YjsDocument.
|
||||||
@@ -173,7 +128,7 @@ export async function importJSONFile(file: File, yjsDoc: YjsDocument): Promise<I
|
|||||||
return importJSON(text, yjsDoc);
|
return importJSON(text, yjsDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── DXF Import (basic) ───────────────────────────────────────────────────────
|
// ── DXF Import (basic) ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
interface DxfEntity {
|
interface DxfEntity {
|
||||||
type: string;
|
type: string;
|
||||||
@@ -491,7 +446,7 @@ export async function importDXFFile(file: File, yjsDoc: YjsDocument): Promise<Im
|
|||||||
return importDXF(text, yjsDoc);
|
return importDXF(text, yjsDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Helpers ──────────────────────────────────────────────────────────────────
|
// ── Helpers ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function aciToHex(aci: number): string {
|
function aciToHex(aci: number): string {
|
||||||
const aciMap: Record<number, string> = {
|
const aciMap: Record<number, string> = {
|
||||||
@@ -506,7 +461,7 @@ function aciToHex(aci: number): string {
|
|||||||
return aciMap[aci] || '#000000';
|
return aciMap[aci] || '#000000';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Unified Import ───────────────────────────────────────────────────────────
|
// ── Unified Import ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export type ImportFormat = 'json' | 'dxf';
|
export type ImportFormat = 'json' | 'dxf';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user