dsh-qizhoucnc-cam 1.3.4 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/client.js +116 -33
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -252,7 +252,7 @@ window.__ModuleLoader__.load({
252
252
  // scene 来自 /dsh-cam/model:{ bounds:{min,max}, faces:[{id,vertices,triangles,center,area}], edges:[{id,points}] }
253
253
  // selected: { kind:'face'|'edge', id } | null;点击面/边时回传 onSelect。
254
254
  // pivot: [x,y,z] 旋转轴心;默认取模型包围盒中心。旋转/缩放都围绕该点。
255
- function ModelViewer3D({ scene, selected, onSelect, onAnnotate, pivot, features }) {
255
+ function ModelViewer3D({ scene, selected, onSelect, onAnnotate, pivot, features, locate }) {
256
256
  const [view, setView] = React.useState(null);
257
257
  const drag = React.useRef(null);
258
258
  const suppressClick = React.useRef(false);
@@ -328,6 +328,46 @@ window.__ModuleLoader__.load({
328
328
  const EDGE_COLOR = '#64748b';
329
329
  const EDGE_SELECTED = '#ff9a3d';
330
330
  const FEAT_FILL = 'rgba(255,154,61,0.72)'; // 已标注特征:橙色高亮
331
+ const LOCATE_FILL = 'rgba(34,197,94,0.85)'; // 点击标签定位:亮绿高亮
332
+ const LOCATE_STROKE = '#16a34a';
333
+
334
+ // 点击左侧标注列表某条 → 定位到模型对应面/边并高亮
335
+ const locateKey = locate ? (locate.kind + ':' + locate.id) : null;
336
+
337
+ // 必须在 face/edge 渲染循环之前声明(const 存在 TDZ,循环里已引用它)。
338
+ // 单击面/边 = 选择;双击 = 标注。拖拽后抑制 click,避免误触发。
339
+ const clickGuard = (fn) => (e) => {
340
+ e.stopPropagation();
341
+ if (suppressClick.current) { suppressClick.current = false; return; }
342
+ fn();
343
+ };
344
+
345
+ // 光照着色:按面法向做朗伯明暗(Lambert),让每个面有明暗层次,立体感强、
346
+ // 与浅色/深色背景都能区分开,避免纯色与背景融合。
347
+ const LIGHT = (() => { const l = [0.42, 0.36, 0.83]; const m = Math.hypot(l[0], l[1], l[2]); return [l[0] / m, l[1] / m, l[2] / m]; })();
348
+ const rotateDir = (p, yaw, pitch) => {
349
+ const [x, y, z] = p;
350
+ const cy = Math.cos(yaw), sy = Math.sin(yaw);
351
+ const x1 = x * cy - y * sy, y1 = x * sy + y * cy;
352
+ const cp = Math.cos(pitch), sp = Math.sin(pitch);
353
+ return [x1, y1 * cp + z * sp, -y1 * sp + z * cp];
354
+ };
355
+ const faceNormal = (f) => {
356
+ for (const tri of f.triangles) {
357
+ const a = f.vertices[tri[0]], b = f.vertices[tri[1]], c = f.vertices[tri[2]];
358
+ const nx = (b[1] - a[1]) * (c[2] - a[2]) - (b[2] - a[2]) * (c[1] - a[1]);
359
+ const ny = (b[2] - a[2]) * (c[0] - a[0]) - (b[0] - a[0]) * (c[2] - a[2]);
360
+ const nz = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
361
+ const len = Math.hypot(nx, ny, nz);
362
+ if (len > 1e-9) return [nx / len, ny / len, nz / len];
363
+ }
364
+ return [0, 0, 1];
365
+ };
366
+ const shadeOf = (n) => {
367
+ const rn = rotateDir(n, view.yaw, view.pitch);
368
+ const nd = rn[0] * LIGHT[0] + rn[1] * LIGHT[1] + rn[2] * LIGHT[2];
369
+ return 0.34 + 0.66 * Math.max(0, nd);
370
+ };
331
371
 
332
372
  // faces → ONE <path> per face (merge all its triangles into a single path).
333
373
  // 每个三角形若独立成 <polygon>,复杂 STEP 会有上万 DOM 节点导致崩溃;
@@ -336,25 +376,29 @@ window.__ModuleLoader__.load({
336
376
  for (const f of scene.faces) {
337
377
  const isSel = selected && selected.kind === 'face' && selected.id === f.id;
338
378
  const isFeat = featMap['face:' + f.id];
379
+ const isLoc = locateKey === 'face:' + f.id;
380
+ const shade = shadeOf(faceNormal(f));
381
+ const r = Math.round(96 * shade), g = Math.round(116 * shade), b = Math.round(140 * shade);
382
+ const baseFill = 'rgb(' + r + ',' + g + ',' + b + ')';
383
+ const hoverFill = 'rgb(' + Math.min(255, r + 42) + ',' + Math.min(255, g + 42) + ',' + Math.min(255, b + 42) + ')';
384
+ const fillColor = isLoc ? LOCATE_FILL : (isFeat ? FEAT_FILL : (isSel ? FACE_SELECTED : baseFill));
339
385
  let d = '';
340
- let p0 = null;
341
386
  for (const tri of f.triangles) {
342
387
  const a = f.vertices[tri[0]], b = f.vertices[tri[1]], c = f.vertices[tri[2]];
343
388
  const [ax, ay] = toScreen(a), [bx, by] = toScreen(b), [cx2, cy2] = toScreen(c);
344
389
  d += 'M' + ax.toFixed(1) + ' ' + ay.toFixed(1)
345
390
  + 'L' + bx.toFixed(1) + ' ' + by.toFixed(1)
346
391
  + 'L' + cx2.toFixed(1) + ' ' + cy2.toFixed(1) + 'Z';
347
- if (p0 === null) p0 = [ax, ay];
348
392
  }
349
393
  faceEls.push(h('path', {
350
394
  key: 'f' + f.id,
351
395
  d,
352
- fill: isFeat ? FEAT_FILL : (isSel ? FACE_SELECTED : FACE_FILL),
353
- stroke: isFeat ? '#f97316' : (isSel ? '#f97316' : FACE_STROKE),
354
- strokeWidth: isFeat ? 0.8 : 0.4, strokeLinejoin: 'round',
396
+ fill: fillColor,
397
+ stroke: isLoc ? LOCATE_STROKE : (isFeat ? '#f97316' : (isSel ? '#f97316' : FACE_STROKE)),
398
+ strokeWidth: isLoc ? 2.4 : (isFeat ? 0.8 : 0.4), strokeLinejoin: 'round',
355
399
  style: { cursor: 'pointer' },
356
- onMouseEnter: (e) => { if (!isSel && !isFeat) e.currentTarget.setAttribute('fill', FACE_HOVER); },
357
- onMouseLeave: (e) => { if (!isSel && !isFeat) e.currentTarget.setAttribute('fill', FACE_FILL); },
400
+ onMouseEnter: (e) => { if (!isSel && !isFeat && !isLoc) e.currentTarget.setAttribute('fill', hoverFill); },
401
+ onMouseLeave: (e) => { if (!isSel && !isFeat && !isLoc) e.currentTarget.setAttribute('fill', baseFill); },
358
402
  onClick: clickGuard(() => onSelect({ kind: 'face', id: f.id, center: f.center, area: f.area })),
359
403
  onDoubleClick: clickGuard(() => onAnnotate({ kind: 'face', id: f.id, center: f.center, area: f.area })),
360
404
  }));
@@ -364,14 +408,15 @@ window.__ModuleLoader__.load({
364
408
  for (const e of scene.edges) {
365
409
  const isSel = selected && selected.kind === 'edge' && selected.id === e.id;
366
410
  const isFeat = featMap['edge:' + e.id];
411
+ const isLoc = locateKey === 'edge:' + e.id;
367
412
  let pts = '';
368
413
  e.points.forEach((p, j) => { const [sx, sy] = toScreen(p); pts += (j === 0 ? '' : ' ') + sx.toFixed(1) + ',' + sy.toFixed(1); });
369
414
  edgeEls.push(h('polyline', {
370
415
  key: 'e' + e.id,
371
416
  points: pts,
372
417
  fill: 'none',
373
- stroke: isFeat ? '#f97316' : (isSel ? EDGE_SELECTED : EDGE_COLOR),
374
- strokeWidth: isFeat ? 3.2 : (isSel ? 3 : 1.4),
418
+ stroke: isLoc ? LOCATE_STROKE : (isFeat ? '#f97316' : (isSel ? EDGE_SELECTED : EDGE_COLOR)),
419
+ strokeWidth: isLoc ? 4.4 : (isFeat ? 3.2 : (isSel ? 3 : 1.4)),
375
420
  strokeLinejoin: 'round', strokeLinecap: 'round',
376
421
  style: { cursor: 'pointer' },
377
422
  onClick: clickGuard(() => onSelect({ kind: 'edge', id: e.id, points: e.points })),
@@ -408,11 +453,6 @@ window.__ModuleLoader__.load({
408
453
  window.addEventListener('pointercancel', up);
409
454
  };
410
455
  const onWheel = (e) => { e.preventDefault(); setView((v) => ({ ...v, zoom: Math.max(0.05, Math.min(20, v.zoom * (e.deltaY < 0 ? 1.12 : 0.9))) })); };
411
- const clickGuard = (fn) => (e) => {
412
- e.stopPropagation();
413
- if (suppressClick.current) { suppressClick.current = false; return; }
414
- fn();
415
- };
416
456
 
417
457
  const applyView = (v) => setView((cur) => fitView(v.yaw, v.pitch));
418
458
  const viewBtn = (v, active) => h('button', {
@@ -706,7 +746,7 @@ window.__ModuleLoader__.load({
706
746
  };
707
747
  const btn = { display: 'inline-flex', alignItems: 'center', gap: 4, padding: '3px 10px', fontSize: 12, cursor: 'pointer', borderRadius: 6, border: '1px solid var(--dsw-alias-border-l1, #e5e7eb)', background: 'var(--dsw-alias-interactive-bg, transparent)', color: 'var(--dsw-alias-label-primary, #111)' };
708
748
  const btnPrimary = { display: 'inline-flex', alignItems: 'center', gap: 4, padding: '3px 12px', fontSize: 12, cursor: 'pointer', fontWeight: 600, borderRadius: 6, border: '1px solid transparent', background: 'var(--dsw-alias-state-business-primary, #2563eb)', color: '#fff' };
709
- const input = { flex: 1, minWidth: 0, padding: '5px 8px', fontSize: 12, border: '1px solid var(--dsw-alias-border-l1, #e5e7eb)', borderRadius: 6, background: 'var(--dsw-alias-surface, #fff)', color: 'var(--dsw-alias-label-primary, #111)' };
749
+ const input = { flex: 1, minWidth: 0, padding: '6px 10px', fontSize: 13, border: '1px solid #d1d5db', borderRadius: 6, background: '#ffffff', color: '#111827' };
710
750
 
711
751
  function ToolpathPanel({ useSessions }) {
712
752
  const [open, setOpen] = React.useState(true);
@@ -734,8 +774,12 @@ window.__ModuleLoader__.load({
734
774
  const [modelFeatures, setModelFeatures] = React.useState([]);
735
775
  const [featureName, setFeatureName] = React.useState('');
736
776
  const [featureNote, setFeatureNote] = React.useState('');
777
+ // 二次修改:正在编辑的标注 id(null=新建);双击标注项进入重命名态
778
+ const [editingFeatureId, setEditingFeatureId] = React.useState(null);
737
779
  // 模型视窗的旋转轴心(默认为 null → 用模型包围盒中心);用户可设自定义轴心
738
780
  const [modelPivot, setModelPivot] = React.useState(null);
781
+ // 点击左侧标注列表项 → 定位到模型对应面/边并高亮({ kind, id })
782
+ const [locateTarget, setLocateTarget] = React.useState(null);
739
783
  // 打赏二维码弹窗
740
784
  const [showReward, setShowReward] = React.useState(false);
741
785
  const panelRef = React.useRef(null);
@@ -916,23 +960,48 @@ window.__ModuleLoader__.load({
916
960
  const name = featureName.trim();
917
961
  if (!name) { setErr('请为这个加工位置填写名称'); return; }
918
962
  setBusy(true); setErr(null);
919
- post('/dsh-cam/feature', {
963
+ const body = {
920
964
  model: modelFile,
921
965
  name,
922
966
  kind: modelSelected.kind,
923
967
  refId: modelSelected.id,
924
968
  note: featureNote.trim(),
925
- })
969
+ };
970
+ // 二次修改:若正在编辑某条已有标注,走 update;否则新增
971
+ if (editingFeatureId) body.op = 'update', body.id = editingFeatureId;
972
+ post('/dsh-cam/feature', body)
926
973
  .then((d) => {
927
974
  if (d.ok && Array.isArray(d.features)) {
928
975
  setModelFeatures(d.features);
929
976
  setFeatureName('');
930
977
  setFeatureNote('');
978
+ setEditingFeatureId(null);
979
+ setAnnotating(false);
980
+ setModelSelected(null);
931
981
  } else setErr(d.error || '标注写入失败');
932
982
  })
933
983
  .catch((e) => setErr(String(e)))
934
984
  .finally(() => setBusy(false));
935
- }, [post, modelFile, modelSelected, featureName, featureNote]);
985
+ }, [post, modelFile, modelSelected, featureName, featureNote, editingFeatureId]);
986
+
987
+ // 从已有标注列表开始「二次修改」(重命名 / 改备注 / 重选目标)
988
+ const startEditFeature = React.useCallback((f) => {
989
+ setModelSelected({ kind: f.kind, id: f.refId });
990
+ setFeatureName(f.name || '');
991
+ setFeatureNote(f.note || '');
992
+ setEditingFeatureId(f.id);
993
+ setAnnotating(true);
994
+ }, []);
995
+
996
+ // 删除一条已有标注
997
+ const removeFeature = React.useCallback((f) => {
998
+ if (!modelFile) return;
999
+ setBusy(true); setErr(null);
1000
+ post('/dsh-cam/feature', { model: modelFile, op: 'delete', id: f.id })
1001
+ .then((d) => { if (d.ok && Array.isArray(d.features)) setModelFeatures(d.features); else setErr(d.error || '删除失败'); })
1002
+ .catch((e) => setErr(String(e)))
1003
+ .finally(() => setBusy(false));
1004
+ }, [post, modelFile]);
936
1005
 
937
1006
  const ncCount = files.nc.length;
938
1007
 
@@ -1157,19 +1226,33 @@ window.__ModuleLoader__.load({
1157
1226
  ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 4, flex: 1, overflowY: 'auto' } },
1158
1227
  modelFeatures.map((f) => h('div', {
1159
1228
  key: f.id,
1160
- style: { display: 'flex', alignItems: 'center', gap: 6, padding: '5px 7px', fontSize: 12, borderRadius: 6, background: 'rgba(255,154,61,0.14)', border: '1px solid rgba(249,115,22,0.35)' },
1229
+ title: '单击定位到模型 · 双击重命名 · 点击 ✕ 删除',
1230
+ style: { display: 'flex', alignItems: 'center', gap: 6, padding: '5px 7px', fontSize: 12, borderRadius: 6, background: 'rgba(255,154,61,0.14)', border: '1px solid rgba(249,115,22,0.35)', cursor: 'pointer' },
1231
+ onClick: () => setLocateTarget({ kind: f.kind, id: f.refId }),
1232
+ onDoubleClick: () => startEditFeature(f),
1161
1233
  },
1162
1234
  h('span', { style: { fontSize: 12, color: '#f97316' } }, f.kind === 'face' ? '▨' : '╱'),
1163
1235
  h('div', { style: { display: 'flex', flexDirection: 'column', minWidth: 0, flex: 1 } },
1164
1236
  h('span', { style: { fontWeight: 600, color: 'var(--dsw-alias-label-primary, #111)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, f.name),
1165
- h('span', { style: { fontSize: 10, color: 'var(--dsw-alias-label-secondary, #6b7280)' } }, (f.kind === 'face' ? '面' : '边') + ' #' + f.refId + (f.note ? ' · ' + f.note : ''))))))
1237
+ h('span', { style: { fontSize: 10, color: 'var(--dsw-alias-label-secondary, #6b7280)' } }, (f.kind === 'face' ? '面' : '边') + ' #' + f.refId + (f.note ? ' · ' + f.note : ''))),
1238
+ h('button', {
1239
+ onClick: () => removeFeature(f),
1240
+ title: '删除此标注',
1241
+ style: { display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 16, height: 16, fontSize: 11, lineHeight: 1, cursor: 'pointer', borderRadius: '50%', border: 'none', background: 'transparent', color: '#f97316', padding: 0 },
1242
+ }, '✕'))))
1166
1243
  : h('div', { style: { fontSize: 11, color: 'var(--dsw-alias-label-tertiary, #9ca3af)', textAlign: 'center', padding: '12px 0' } }, '暂无标注\n双击面/边线添加')),
1167
1244
  // 右侧:模型视窗 + 轴心 + 标注输入
1168
1245
  h('div', { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column' } },
1169
1246
  h(ModelViewer3D, {
1170
- scene: modelScene, selected: modelSelected, pivot: modelPivot, features: modelFeatures,
1247
+ scene: modelScene, selected: modelSelected, pivot: modelPivot, features: modelFeatures, locate: locateTarget,
1171
1248
  onSelect: (sel) => { setModelSelected(sel); setAnnotating(false); },
1172
- onAnnotate: (sel) => { setModelSelected(sel); setAnnotating(true); },
1249
+ onAnnotate: (sel) => {
1250
+ setModelSelected(sel);
1251
+ setFeatureName('');
1252
+ setFeatureNote('');
1253
+ setEditingFeatureId(null);
1254
+ setAnnotating(true);
1255
+ },
1173
1256
  }),
1174
1257
  h('div', { style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 6 } },
1175
1258
  h('span', { style: { fontSize: 11, color: 'var(--dsw-alias-label-secondary, #6b7280)' } }, '旋转轴心'),
@@ -1196,13 +1279,13 @@ window.__ModuleLoader__.load({
1196
1279
  modelSelected && annotating
1197
1280
  ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, padding: 8, marginTop: 6, borderRadius: 8, background: 'var(--dsw-alias-bg-layer-2, #f3f4f6)', border: '1px solid var(--dsw-alias-border-l1, #e5e7eb)' } },
1198
1281
  h('div', { style: { fontSize: 11, fontWeight: 600, color: 'var(--dsw-alias-label-primary, #111)' } },
1199
- (modelSelected.kind === 'face' ? '标注加工面' : '标注加工边线') + ' · 已选 #' + modelSelected.id),
1282
+ (editingFeatureId ? '修改加工位置' : (modelSelected.kind === 'face' ? '标注加工面' : '标注加工边线')) + ' · 已选 #' + modelSelected.id),
1200
1283
  h('div', { style: { display: 'flex', gap: 6 } },
1201
1284
  h('input', { style: input, value: featureName, placeholder: '加工位置名称(必填)', onChange: (e) => setFeatureName(e.target.value), onKeyDown: (e) => { if (e.key === 'Enter') addFeature(); } }),
1202
1285
  h('input', { style: input, value: featureNote, placeholder: '备注(可选,如钻孔/铣面)', onChange: (e) => setFeatureNote(e.target.value), onKeyDown: (e) => { if (e.key === 'Enter') addFeature(); } })),
1203
1286
  h('div', { style: { display: 'flex', gap: 6, alignItems: 'center' } },
1204
- h('button', { style: btnPrimary, onClick: addFeature, disabled: busy }, '写入识别文件'),
1205
- h('button', { style: btn, onClick: () => { setModelSelected(null); setAnnotating(false); } }, '取消')))
1287
+ h('button', { style: btnPrimary, onClick: addFeature, disabled: busy }, editingFeatureId ? '保存修改' : '写入识别文件'),
1288
+ h('button', { style: btn, onClick: () => { setModelSelected(null); setAnnotating(false); setEditingFeatureId(null); } }, '取消')))
1206
1289
  : null))
1207
1290
  : h(Viewer3D, { data })),
1208
1291
  // 打赏 footer(左下角)
@@ -1249,21 +1332,21 @@ window.__ModuleLoader__.load({
1249
1332
  },
1250
1333
  onClick: (e) => e.stopPropagation(),
1251
1334
  },
1252
- h('div', { style: { fontSize: 15, fontWeight: 700, color: 'var(--dsw-alias-label-primary, #111)' } }, '制作不易,打赏随心'),
1335
+ h('div', { style: { fontSize: 17, fontWeight: 700, color: '#1f2937', letterSpacing: '0.5px' } }, '制作不易,打赏随心'),
1253
1336
  h('div', {
1254
1337
  style: {
1255
- textAlign: 'center', fontSize: 13.5, lineHeight: '24px', color: '#92400e',
1338
+ textAlign: 'center', fontSize: 14, lineHeight: '26px', color: '#92400e',
1256
1339
  background: 'linear-gradient(135deg, #fef3c7, #fde68a)', borderRadius: 10,
1257
- padding: '10px 14px', fontWeight: 600, letterSpacing: '0.5px',
1340
+ padding: '12px 16px', fontWeight: 600, letterSpacing: '1px',
1258
1341
  boxShadow: 'inset 0 0 0 1px rgba(217,119,6,0.25)',
1259
1342
  },
1260
1343
  },
1261
1344
  '莫愁前路无知己,天下谁人不识君。', h('br', null), '起舟扬帆难不畏,越是当下最好时。'),
1262
- h('img', { src: '/dsh-cam/qrcode', alt: '微信收款二维码', style: { width: 224, height: 'auto', borderRadius: 8, display: 'block' } }),
1263
- h('div', { style: { fontSize: 13, fontWeight: 700, color: '#d97706' } }, '微信扫码 · 支持鼓励一下'),
1264
- h('div', { style: { textAlign: 'center', fontSize: 12, lineHeight: '18px', color: 'var(--dsw-alias-label-secondary, #6b7280)', padding: '0 6px' } },
1345
+ h('img', { src: '/dsh-cam/qrcode', alt: '微信收款二维码', style: { width: 112, height: 'auto', borderRadius: 8, display: 'block' } }),
1346
+ h('div', { style: { fontSize: 15, fontWeight: 700, color: '#d97706', letterSpacing: '0.5px' } }, '微信扫码 · 支持鼓励一下'),
1347
+ h('div', { style: { textAlign: 'center', fontSize: 13, lineHeight: '20px', color: '#4b5563', padding: '0 8px' } },
1265
1348
  '如果觉得对你有帮助,打赏一下,让我知道帮助到了又一个同道中人。'),
1266
- h('button', { onClick: () => setShowReward(false), style: { ...btn, fontSize: 12 } }, '关闭')))
1349
+ h('button', { onClick: () => setShowReward(false), style: { ...btn, fontSize: 13, padding: '4px 16px' } }, '关闭')))
1267
1350
  : null,
1268
1351
  )));
1269
1352
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-qizhoucnc-cam",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "CNC program (NC/CNC/G-code) toolpath recognition, 3D toolpath + 3D STEP model viewport (face/edge machining-position annotation), and a large editing view with quote-to-composer, for DeepSeek Harness (DSH). Made by Chengdu Qizhou Machinery Technology Co., Ltd., for research and study only.",
5
5
  "type": "module",
6
6
  "license": "MIT",