UNPKG

vue2-tunnel-lining

Version:

A Vue2 component for tunnel lining design with MxCAD integration

218 lines (181 loc) 7.17 kB
// src/Cq/LinDrawLK.ts import { McObjectId, MxCpp, McDb, McGePoint3d, McDbPolyline, McDbLine, McDbText } from "mxcad"; // import { LinData } from './LinData'; import { LinDataHelper } from './LInDataHelper'; import { Setting } from '../../Setting/Setting'; import { MxFun } from "mxdraw"; import { CxwDraw } from "../../TunnelCADFns/CxwDraw"; import { Maths } from "../../TunnelCADFns/Maths"; import { CadSys } from "../../TunnelCADFns/CadSys"; export class Cad{ /** * 返回 id1 曲线上的交点 * @param id1 第一个图元对象 ID * @param id2 第二个图元对象 ID * @returns Promise<McGePoint3d[]> 交点数组 */ public static async intersect(id1: McObjectId, id2: McObjectId): Promise<McGePoint3d[]> { const result: McGePoint3d[] = []; try { // 使用 getObject() 获取实体对象 const ent1: any = await id1.getMcDbCurve(); const ent2: any = await id2.getMcDbCurve(); if (!ent1 || !ent2 || typeof ent1.intersectWith !== "function") { console.warn("一个或两个对象无效或不支持 intersectWith"); return result; } // 调用交点计算函数 const pts: McGePoint3d[] = await ent1.intersectWith(ent2); if (Array.isArray(pts)) { return pts; } } catch (error) { console.error("交点计算失败:", error); } return result; } /** * 画倒三角形 * @param ptPosition 倒三角的顶点(最底部) * @param height 三角形高度 * @returns 实体对象 ID */ public static async addTriangle(ptPosition: McGePoint3d, height: number): Promise<McObjectId | null> { try { const ptTopRight = new McGePoint3d(ptPosition.x + height / 2, ptPosition.y + height, 0); const ptTopLeft = new McGePoint3d(ptPosition.x - height / 2, ptPosition.y + height, 0); const ptList: McGePoint3d[] = [ ptPosition, ptTopRight, ptTopLeft, ptPosition ]; const triangleId = await CxwDraw.addPline5P(ptList, 0, 7, false, false); return triangleId; } catch (err) { console.error("❌ 添加倒三角失败:", err); return null; } } public static joinIdCol(baseIdCol: McObjectId[], addIdCol: McObjectId[]): McObjectId[] { console.log("合并ID集合: 原长度=" + baseIdCol.length + ", 新增长度=" + addIdCol.length); baseIdCol.push(...addIdCol); console.log("合并后长度:", baseIdCol.length); return baseIdCol; } public static async centerPoint(ptCenter: McGePoint3d): Promise<McObjectId[]> { const ids: McObjectId[] = []; const horizontal: McGePoint3d[] = [ new McGePoint3d(ptCenter.x - 0.25, ptCenter.y, 0), new McGePoint3d(ptCenter.x + 0.25, ptCenter.y, 0), ]; const vertical: McGePoint3d[] = [ new McGePoint3d(ptCenter.x, ptCenter.y - 0.25, 0), new McGePoint3d(ptCenter.x, ptCenter.y + 0.25, 0), ]; const id1 = await CxwDraw.addPline5P(horizontal, 0, 7, false, false); const id2 = await CxwDraw.addPline5P(vertical, 0, 7, false, false); if (id1) ids.push(id1); if (id2) ids.push(id2); return ids; } public static async Heading1( ptUpCenter: McGePoint3d, upText: string, downText: string ): Promise<McObjectId[]> { const idCol: McObjectId[] = []; try { const upLength = await CadSys.textLength(upText, 4.5); // 估算文字宽度 const downLength = await CadSys.textLength(downText, 3.5); const maxLength = Math.max(upLength, downLength) + 3; const upStartPoint = new McGePoint3d(ptUpCenter.x - maxLength / 2, ptUpCenter.y, 0); const upEndPoint = CxwDraw.polarPoint(upStartPoint, 0, maxLength); const downStartPoint = CxwDraw.polarPoint(upStartPoint, (3 * Math.PI) / 2, 1); const downEndPoint = CxwDraw.polarPoint(downStartPoint, 0, maxLength); // 上下线 idCol.push(await CxwDraw.addLine3P(upStartPoint, upEndPoint, 3)); idCol.push(await CxwDraw.addLine3P(downStartPoint, downEndPoint, 7)); if (upText !== "") { const upTextPoint = CxwDraw.polarPoint( CxwDraw.midPoint(upStartPoint, upEndPoint), Math.PI / 2, 4 ); idCol.push( await CxwDraw.addText( upTextPoint, upText, 4.5, 0, 0.7, 0, McDb.TextHorzMode.kTextCenter, McDb.TextHorzMode.kTextMid ) ); } if (downText !== "") { const downTextPoint = CxwDraw.polarPoint( CxwDraw.midPoint(upStartPoint, upEndPoint), (3 * Math.PI) / 2, 4 ); idCol.push( await CxwDraw.addText( downTextPoint, downText, 3.5, 0, 0.7, 0, McDb.TextHorzMode.kTextCenter, McDb.TextHorzMode.kTextMid ) ); } return idCol; } catch (err) { console.error("⚠️ Heading1 标注绘制失败:", err); return idCol; } } } /** * 定义表格区域的四个顶点 */ export class Point4d { topRow: number; // 上行数 leftColumn: number; // 左列数 bottomRow: number; // 下行数 rightColumn: number; // 右列数 constructor(topRow: number, leftColumn: number, bottomRow: number, rightColumn: number) { this.topRow = topRow; this.leftColumn = leftColumn; this.bottomRow = bottomRow; this.rightColumn = rightColumn; } } export interface IMergeCellInfo { row: number; col: number; rowspan: number; colspan: number; } /** * 合并表格中的单元格(兼容 setMergeCells 接口) * @param tb 表格对象,必须包含 setMergeCells() 方法 * @param point4dList 合并区域集合,每个由四个角(Point4d)表示 */ export function mergeTable( tb: { setMergeCells: (cells: IMergeCellInfo[]) => void }, point4dList: Point4d[] ): void { const mergeCells: IMergeCellInfo[] = point4dList.map(pt => ({ row: pt.topRow, col: pt.leftColumn, rowspan: pt.bottomRow - pt.topRow + 1, colspan: pt.rightColumn - pt.leftColumn + 1, })); tb.setMergeCells(mergeCells); }