vue2-tunnel-lining
Version:
A Vue2 component for tunnel lining design with MxCAD integration
139 lines (109 loc) • 7.56 kB
text/typescript
// src/Cq/LinDrawFps.ts
import { McObjectId, McGePoint3d, McDbPolyline } from "mxcad";
import { CxwDraw } from "../../TunnelCADFns/CxwDraw";
import { Maths } from "../../TunnelCADFns/Maths";
import { LinData } from "./LinData";
import { Setting } from '../../Setting/Setting';
export class LinDrawFps {
public static async DrawSgf(set, testMode: boolean = true) {
console.log("🚀 使用内部硬编码的 'mockSet' 对象进行测试");
if (testMode) {
const mockSet = {
ChenQi: {
LT: { DicIdCol: null, Color_Jg: 1, B_双侧施工缝宽度: 0 },
Cqdm: { Spsgf: true }
}
};
set = mockSet;
}
try {
console.log("🚧 开始绘制施工缝 DrawSgf,testMode:", testMode);
const lts =1;
if (!set.ChenQi.LT.DicIdCol || typeof set.ChenQi.LT.DicIdCol.get !== 'function') {
console.log("[Step 2] 初始化 DicIdCol");
set.ChenQi.LT.DicIdCol = new Map<string, McObjectId[]>();
}
const hasFirst = set.ChenQi.LT.DicIdCol.has("FirstId");
const hasSecond = set.ChenQi.LT.DicIdCol.has("SecondId");
console.log("[Step 3] 检查基准线: hasFirst =", hasFirst, "hasSecond =", hasSecond);
if ((!hasFirst || !hasSecond) && testMode) {
console.log("[Step 4] 准备 mock 两条基准线...");
const pt1 = new McGePoint3d(0, 0, 0);
const pt2 = new McGePoint3d(100, 0, 0);
const pt3 = new McGePoint3d(0, 10, 0);
const pt4 = new McGePoint3d(100, 10, 0);
console.log(" Mock Points:", pt1.toString(),pt2.toString(),pt3.toString(),pt4.toString())
// --- 拆分 Promise.all 进行精确定位 ---
console.log(" [4.1] 正在调用 CxwDraw.addLine 创建 line1...");
const line1 = await CxwDraw.addLine(pt1, pt2, 1, "Continuous", 0.25);
console.log(" [4.2] line1 创建成功, ID:", line1 ? line1.toString() : undefined);
console.log(" [4.3] 正在调用 CxwDraw.addLine 创建 line2...");
const line2 = await CxwDraw.addLine(pt3, pt4, 1, "Continuous", 0.25);
console.log(" [4.4] line2 创建成功, ID:", line2 ? line2.toString() : undefined);
// --- 拆分结束 ---
if (line1 && line2) {
set.ChenQi.LT.DicIdCol.set("FirstId", [line1]);
set.ChenQi.LT.DicIdCol.set("SecondId", [line2]);
console.log("[Step 5] 使用 mock line 初始化完成!");
} else {
console.warn("⚠️ 生成 mock 线失败,CxwDraw.addLine 返回为空");
return;
}
}
// const plFirstId = set.ChenQi.LT.DicIdCol.get("FirstId")?.[0];
// const plSecondId = set.ChenQi.LT.DicIdCol.get("SecondId")?.[0];
const chenQi = set && set.ChenQi;
const lt = chenQi && chenQi.LT;
const dicIdCol = lt && lt.DicIdCol;
const firstIdArray = dicIdCol && dicIdCol.get("FirstId");
const plFirstId = firstIdArray && firstIdArray[0];
const secondArray = dicIdCol && dicIdCol.get("SecondId");
const plSecondId = secondArray && secondArray[0];
if (!plFirstId || !plSecondId) {
console.error("❌ 未找到 FirstId 或 SecondId,这在硬编码模式下不应该发生!");
return;
}
console.log("✅ 读取实体 ID 成功");
console.log(" [*] 正在获取实体 entFir...");
const entFir = await plFirstId.getMcDbEntity() as McDbPolyline;
console.log(" [*] entFir 获取成功.");
console.log(" [*] 正在获取实体 entSec...");
const entSec = await plSecondId.getMcDbEntity() as McDbPolyline;
console.log(" [*] entSec 获取成功.");
const y1_intersect = testMode ? 0 : LinData.H_ngToSgf;
console.log(`🔢 计算第一条线交点使用的 Y 高度: ${y1_intersect}`);
console.log(" [*] 正在计算 pt施工缝左1...");
const pt施工缝左1 = await Maths.IntsOfLineToCurvePoint3d(new McGePoint3d(0, y1_intersect, 0), new McGePoint3d(100, y1_intersect, 0), plFirstId, "MinX");
console.log(" [*] pt施工缝左1 计算成功.");
console.log(" [*] 正在计算 pt施工缝右1...");
const pt施工缝右1 = await Maths.IntsOfLineToCurvePoint3d(new McGePoint3d(0, y1_intersect, 0), new McGePoint3d(100, y1_intersect, 0), plFirstId, "MaxX");
console.log(" [*] pt施工缝右1 计算成功.");
const pt施工缝左2 = await Maths.IntsOfLineToCurvePoint3d(new McGePoint3d(0, LinData.H_ngToSgf, 0), new McGePoint3d(1, LinData.H_ngToSgf, 0), plSecondId, "MinX");
const pt施工缝右2 = await Maths.IntsOfLineToCurvePoint3d(new McGePoint3d(0, LinData.H_ngToSgf, 0), new McGePoint3d(1, LinData.H_ngToSgf, 0), plSecondId, "MaxX");
// console.log("📍 pt施工缝左1 =", pt施工缝左1?.toString?.());
// console.log("📍 pt施工缝右1 =", pt施工缝右1?.toString?.());
// console.log("📍 pt施工缝左2 =", pt施工缝左2?.toString?.());
// console.log("📍 pt施工缝右2 =", pt施工缝右2?.toString?.());
console.log("📍 pt施工缝左1 =", pt施工缝左1 ? pt施工缝左1.toString() : "undefined");
console.log("📍 pt施工缝右1 =", pt施工缝右1 ? pt施工缝右1.toString() : "undefined");
console.log("📍 pt施工缝左2 =", pt施工缝左2 ? pt施工缝左2.toString() : "undefined");
console.log("📍 pt施工缝右2 =", pt施工缝右2 ? pt施工缝右2.toString() : "undefined");
// const sgfLineId = await CxwDraw.addLine(pt施工缝左1, pt施工缝右1, 1, "Continuous", (0.3 / lts));
// const sgfLineId2 = await CxwDraw.addLine(pt施工缝左2, pt施工缝右2, 1, "Continuous", (0.3 / lts));
const sgfLineId = await CxwDraw.addLine(pt施工缝左1, pt施工缝左2, 1, "Continuous", (0.3 / lts));
const sgfLineId2 = await CxwDraw.addLine(pt施工缝右1, pt施工缝右2, 1, "Continuous", (0.3 / lts));
// console.log("✅ 成功画出施工缝1线段,ID:", sgfLineId?.toString?.());
// console.log("✅ 成功画出施工缝2线段,ID:", sgfLineId2?.toString?.());
console.log("✅ 成功画出施工缝1线段,ID:", sgfLineId && sgfLineId.toString ? sgfLineId.toString() : 'undefined');
console.log("✅ 成功画出施工缝2线段,ID:", sgfLineId2 && sgfLineId2.toString ? sgfLineId2.toString() : 'undefined');
console.log("✅ 所有计算和绘制已完成!");
} catch (err) {
console.error("❌❌❌ 捕获到致命错误! ❌❌❌");
console.error("错误代码: 1107 - 绘制施工缝失败", err);
if (err instanceof Error) {
console.error("Stack Trace:", err.stack);
}
throw err;
}
}
}