brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
lightcadUse when embedding lightweight 2D CAD features in web applications — basic drawing, layer management, snapping, DXF import. LightCAD: lightweight Web 2D CAD framework for browser-based drafting.
Independent GitHub snapshot · Automated classification · Original documentation governs
name: lightcad description: "Use when embedding lightweight 2D CAD features in web applications — basic drawing, layer management, snapping, DXF import. LightCAD: lightweight Web 2D CAD framework for browser-based drafting." tags:
项目地址: 原仓库
github.com/light-CAD/lightcad已404,请以 znlgis.github.io 为准官网/演示: https://lightcad.cn/
许可证: MIT / Apache-2.0(视仓库声明)
LightCAD 主要特性:
该项目处于活跃迭代阶段,下文以通用 Web CAD 二次开发为视角,如细节差异请以仓库 README 与 znlgis 教程为准。
直接打开 https://lightcad.cn/ 体验。
<iframe src="https://lightcad.cn/" style="width:100%;height:100vh;border:0"></iframe>
<div id="cad" style="width:100%;height:100vh"></div>
<script type="module">
// ⚠ npm 仓库目前查无 @lightcad/sdk 包(404),请以 znlgis 文档 / 源码构建为准
import { LightCAD } from '@lightcad/sdk';
const app = new LightCAD({
container: '#cad',
locale: 'zh-CN'
});
await app.init();
// 直接执行命令
app.exec('line 0,0 100,100');
</script>
| 命令 | 功能 | 示例 |
|---|---|---|
line / l | 直线 | line 0,0 100,0 |
circle / c | 圆 | c 50,50 r 20 |
pline / pl | 多段线 | pl 0,0 10,0 10,10 |
arc / a | 圆弧(3点 / 起-中-终) | a 0,0 10,10 20,0 |
rect / re | 矩形 | re 0,0 100,50 |
text | 文字 | text 0,0 "Hello" |
dimlinear | 线性标注 | |
move/mv | 平移 | |
copy/cp | 复制 | |
mirror/mi | 镜像 | |
trim/tr | 修剪 | |
extend/ex | 延伸 | |
fillet/f | 圆角 | f 10 后选两条线 |
chamfer/cha | 倒角 |
// 添加实体
const id = app.add('LINE', { p1: [0,0], p2: [100,100] });
app.add('CIRCLE', { center: [50,50], radius: 20, layer: 'WALL' });
// 修改
app.update(id, { color: '#ff0000', lineWeight: 0.3 });
// 查询
const entities = app.query({ type: 'LINE', layer: 'WALL' });
// 删除
app.remove(id);
// 图层
app.layers.add('WALL', { color: '#0000ff', lineType: 'CONTINUOUS' });
app.layers.setCurrent('WALL');
app.layers.set('WALL', { visible: false });
const blkId = app.blocks.create('CHAIR', {
base: [0, 0],
entities: [
{ type: 'CIRCLE', center: [0,0], radius: 5 },
{ type: 'LINE', p1: [-5,0], p2: [5,0] }
]
});
app.add('INSERT', { block: 'CHAIR', position: [10,10], rotation: 0, scale: 1 });
// 导入
const dxfText = await fetch('/files/plan.dxf').then(r => r.text());
app.io.importDXF(dxfText);
// 导出
const dxf = app.io.exportDXF();
saveAs(new Blob([dxf]), 'out.dxf');
// 导出 SVG / PNG
const svg = app.io.exportSVG();
const png = await app.io.exportPNG({ width: 1920, height: 1080 });
app.on('selectionChanged', sel => console.log(sel.length, '已选'));
app.on('commandStarted', name => console.log('命令', name));
app.on('entityModified', e => console.log(e.id));
app.on('mouseClick', e => console.log(e.world));
app.commands.register({
name: 'mycross',
handler: async (ctx) => {
const p = await ctx.input.getPoint('选择中心点');
ctx.app.add('LINE', { p1: [p.x-5, p.y], p2: [p.x+5, p.y] });
ctx.app.add('LINE', { p1: [p.x, p.y-5], p2: [p.x, p.y+5] });
}
});
// 命令行:mycross
app.view.zoomExtents();
app.view.zoomTo([0,0,100,100]);
app.view.pan(10, 0);
app.view.rotate(15);
app.batch(() => { ... }) 包装,仅刷新一次| 问题 | 解决 |
|---|---|
| DWG 不支持 | 先用 ODA File Converter / LibreDWG 转 DXF |
| 中文乱码 | DXF 文件编码为 UTF-8;字体配置 Noto Sans CJK SC |
| 标注比例小 | 设置 dimstyle.scale |
| 与业务集成 | 监听 app.on('entityModified', ...) 同步到后端 |
LightCAD 类实例化)。SDK 模式按「app.init() → app.exec(command) 或 app.add(entity) → app.io.exportDXF()」的流程操作。批量添加实体用 app.batch(() => {...}) 包装。Noto Sans CJK SC 字体;③ 大文件 DXF 导入建议用 Web Worker 解析;④ 标注比例通过 dimstyle.scale 设置。new LightCAD({ container: '#cad', locale: 'zh-CN' }) → app.init() → app.exec('line 0,0 100,100')。自定义命令:app.commands.register({ name, handler: async (ctx) => { const p = await ctx.input.getPoint('...'); ... } })。@lightcad/sdk 包,勿直接 pnpm install)<div>,实例化 LightCAD 并初始化entityModified/selectionChanged 事件同步数据到后端app.io.importDXF()/app.io.exportDXF()app.exec() 发送 AutoCAD 风格命令app.exec('line 0,0 100,100') 绘制直线app.exec('circle 50,50 r 20') 绘制圆app.exec('rect 0,0 100,50') 绘制矩形app.io.exportDXF() 导出为 DXF 文件该 SKILL 基于 Web CAD 通用模式整理,具体 API 命名以最新版本仓库为准。