mainfrm_pane.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. ////////////////////////////////////////////////////////////////////////////
  2. // System Pre-define Functions
  3. // 95099372-ef3e-11ea-9c81-bf848405c62e
  4. var dock_widget = false;
  5. var dock_widget1 = false;
  6. var dock_widget2 = false;
  7. var dock_widget3 = false;
  8. var g_preview = false;
  9. var g_io = false;
  10. var g_wid = false;
  11. let myArray = [];
  12. var res = [];
  13. var judge = 0;
  14. var startEnd = 0;
  15. var vtkContext = null;
  16. var workData = null;
  17. var postManage = null;
  18. function OnDockerChange(){
  19. updateDockerButtonStatus();
  20. }
  21. function OnResize() {
  22. if (dock_widget && !ui.docker.isVisible(dock_widget)) {
  23. showLeftDocker(true);
  24. }
  25. }
  26. function OnInitDocker() {
  27. dock_widget1 = appendDockPane(unit.form.toolbar, "", 4, 1|2|4);
  28. dock_widget2 = appendDockPane(unit.form.tree, "模型树", 1, 1|2);
  29. }
  30. function updateDockerButtonStatus() {
  31. if (!dock_widget) {
  32. return;
  33. }
  34. //unit.form.cw_topmenu.onUpdateBtn(!ui.docker.isFloat(dock_widget), !ui.docker.isVisible(dock_widget));
  35. }
  36. function appendDockPane(sub_form, title, init_pos, allow_pos, features) {
  37. let dw = sub_form.CreateDock(title);
  38. if (features) {
  39. ui.docker.setFeatures(features);
  40. }
  41. ui.docker.setAllowAreas(dw, allow_pos);
  42. ui.docker.dock(dw, init_pos);
  43. return dw;
  44. }
  45. function showLeftDocker(flag) {
  46. ui.docker.show(dock_widget, flag);
  47. updateDockerButtonStatus();
  48. }
  49. function InitCanvasIOEngine() {
  50. ui.canvas.adaptor('nastran', function(fname_nas) {
  51. //console.log(fname_nas);
  52. console.time('Nastran Import');
  53. model.cueline('解析并加载Nastran文件 ...');
  54. model.updateGeometry(ui.geometry);
  55. ui.canvas.db = null;
  56. parent.mesh.shell.ClearCache();
  57. parent.mesh.shell.LoadNastranToCache(fname_nas);
  58. console.timeEnd('Nastran Import');
  59. model.cueline('创建图形缓冲区 ...');
  60. console.time('Nastran Buffer');
  61. var buf = parent.mesh.shell.RenderToGLCache();
  62. console.timeEnd('Nastran Buffer');
  63. model.cueline('生成图形数据库并渲染 ...');
  64. return buf;
  65. });
  66. ui.canvas.adaptor('step', function(fname_step) {
  67. console.log('Step');
  68. console.time('Step Import');
  69. model.cueline('解析并加载STEP文件 ...');
  70. model.updateGeometry(ui.geometry);
  71. ui.canvas.db = null;
  72. comx.occore.Clear();
  73. comx.occio.ImportStepEx(comx.occore.GetEntryEx(), fname_step);
  74. var modelTree = comx.occio.ImportStepEx(comx.occore.GetEntryEx(), fname_step);
  75. //ui.tree.tree = JSON.parse(modelTree);
  76. unit.form.tree.OnTree(JSON.parse(modelTree));
  77. var hashCodes = comx.occio.GetFaceHashCodes(comx.occore.GetEntryEx());
  78. //console.log(JSON.parse(hashCodes));
  79. model.setHash(JSON.parse(hashCodes));
  80. console.timeEnd('Step Import');
  81. model.cueline('创建图形缓冲区 ...');
  82. console.time('Step Buffer');
  83. var gl_buf = comx.occrender.RenderToBufferEx(comx.occore.GetEntryEx(), true, false);
  84. console.timeEnd('Step Buffer');
  85. model.cueline('生成图形数据库并渲染 ...');
  86. return gl_buf;
  87. });
  88. ui.canvas.adaptor('iges', function(fname_step) {
  89. console.time('Iges Import');
  90. model.cueline('解析并加载IGES文件 ...');
  91. model.updateGeometry(ui.geometry);
  92. ui.canvas.db = null;
  93. comx.occore.Clear();
  94. comx.occio.ImportIges(comx.occore.GetEntry(), fname_step);
  95. console.timeEnd('Iges Import');
  96. model.cueline('创建图形缓冲区 ...');
  97. console.time('Iges Buffer');
  98. var gl_buf = comx.occrender.RenderToBuffer(comx.occore.GetEntry());
  99. console.timeEnd('Iges Buffer');
  100. model.cueline('生成图形数据库并渲染 ...');
  101. return gl_buf;
  102. });
  103. }
  104. function SetCanvasProp() {
  105. ui.canvas.filter = [2025]; //面
  106. if (ui.canvas.view()) {
  107. //ui.canvas.view().setColor(0.75, 0.75, 0.75, 0.5);
  108. ui.canvas.view().setColor(1.0, 1.0, 0, 1.0);
  109. ui.canvas.view().setVisible(true);
  110. ui.canvas.view().setBlend(false);
  111. }
  112. ui.canvas.lamp = true;
  113. }
  114. //Callback of data preparation stage before UI is fully loaded.
  115. //隐藏显示
  116. function HideAndShow(type, name, flag) {
  117. comx.ply.hideShow(vtkContext.Interface(), workData, type, name, flag);
  118. }
  119. //显示3D模型
  120. function OnloadModel(path) {
  121. ui.canvas.step = path;
  122. }
  123. //清除canvas
  124. function ClearCanvas() {
  125. ui.canvas.db = null;
  126. }
  127. //设置材料参数界面
  128. function setMaterial(material) {
  129. ui.physics_mastk.setmaterial = material;
  130. }
  131. //设置约束
  132. function setConstraint(prop) {
  133. let constraint = {
  134. "固定支撑":function(){
  135. ui.cw_boundary_constraint_25.setConstraint0 = prop;
  136. },
  137. "梁":function(){
  138. ui.cw_boundary_constraint_25.setConstraint1 = prop;
  139. },
  140. "弹簧":function(){
  141. ui.cw_boundary_constraint_25.setConstraint2 = prop;
  142. },
  143. "连接":function(){
  144. ui.cw_boundary_constraint_25.setConstraint3 = prop;
  145. },
  146. "梁(非均匀)":function(){
  147. },
  148. "集中载荷压力":function(){
  149. ui.cw_boundary_force_24.setConstraint0 = prop;
  150. },
  151. "分布载荷压力":function(){
  152. ui.cw_boundary_force_24.setConstraint1 = prop;
  153. },
  154. "rb3":function(){
  155. ui.cw_boundary_brep_23.setConstraint = prop;
  156. }
  157. };
  158. constraint[prop.constraint]();
  159. }
  160. //显示重命名界面
  161. function RenameTreeNode(Idx) {
  162. if(Idx === 2) {
  163. unit.form.Rename.Show();
  164. }else if(Idx === 5){
  165. unit.form.RenameMaterial.Show();
  166. }
  167. }
  168. //点亮面
  169. function LightFace(id, rgb) {
  170. let r_id = findRIdById(model.acax_app.model.project.GetModel().pro_model, parseInt(id));
  171. ui.canvas.view([ui.canvas.generateKey(2025, parseInt(r_id))]).setColor(parseFloat(rgb.r)/255, parseFloat(rgb.g)/255, parseFloat(rgb.b)/255);
  172. }
  173. //加载涂色
  174. function SetColor(color) {
  175. let color_arr = Object.keys(color);
  176. for (let i = 0; i < color_arr.length; ++i) {
  177. try {
  178. console.log(i + " ");
  179. // 查找 r_id
  180. let r_id = findRIdById(
  181. model.acax_app.model.project.GetModel().pro_model,
  182. parseInt(color_arr[i])
  183. );
  184. if (!r_id) {
  185. throw new Error(`r_id not found for id: ${color_arr[i]}`);
  186. }
  187. // 转换颜色为 RGB
  188. let rgb = hexToRgb(color[color_arr[i]]);
  189. if (!rgb || rgb.r === undefined || rgb.g === undefined || rgb.b === undefined) {
  190. throw new Error(`Invalid color value: ${color[color_arr[i]]}`);
  191. }
  192. // 设置颜色
  193. ui.canvas
  194. .view([ui.canvas.generateKey(2025, parseInt(r_id))])
  195. .setColor(
  196. parseFloat(rgb.r) / 255,
  197. parseFloat(rgb.g) / 255,
  198. parseFloat(rgb.b) / 255
  199. );
  200. } catch (error) {
  201. console.error(
  202. `Failed to set color for id ${color_arr[i]}: `,
  203. error.message
  204. );
  205. }
  206. }
  207. }
  208. function hexToRgb(hex) {
  209. // 去掉前缀 #(如果有)
  210. hex = hex.replace(/^#/, '');
  211. // 如果是简写形式(#RGB),将其转换为完整形式(#RRGGBB)
  212. if (hex.length === 3) {
  213. hex = hex.split('').map(char => char + char).join('');
  214. }
  215. // 解析 RGB 颜色值
  216. const r = parseInt(hex.slice(0, 2), 16);
  217. const g = parseInt(hex.slice(2, 4), 16);
  218. const b = parseInt(hex.slice(4, 6), 16);
  219. return { r, g, b };
  220. }
  221. function OnInitializeData(reload, preview) {
  222. //model.ide_info(model.uuid().length);
  223. vtkContext = comx.vtk.CreateContext();
  224. ui.canvas.vtkContextInterface = vtkContext.Interface();
  225. workData = comx.ply.InitWorkArea();
  226. postManage = comx.ply.InitPostManage();
  227. ui.pc_geo.value = model.getPicturePath('蓝灰色.png');
  228. OnCueline('白色->未使用,蓝灰色->正在处理,绿色->未通过,蓝色->通过', 'blue');
  229. InitCanvasIOEngine();
  230. parent.setTimeout(() => {
  231. OnInitDocker();
  232. }, 0);
  233. ui.canvas.lamp = true;
  234. }
  235. //Callback after UI is fully loaded and displayed.
  236. function OnAnalysisShow(){
  237. //unit.form.form.Show();
  238. }
  239. function OnSolveShow(){
  240. }
  241. function OnReady(reload, preview) {
  242. }
  243. function OnCloseForm() {
  244. //console.log(11);
  245. //model.deleteFile(model.getCurrentDirectory() + 'data/faceID');
  246. //model.deleteFile(model.getCurrentDirectory() + 'data/face');
  247. //model.deleteFile(model.getCurrentDirectory() + 'data/peidian');
  248. //model.deleteFile(model.getCurrentDirectory() + 'data/restraint');
  249. //model.deleteFile(model.getCurrentDirectory() + 'data/force');
  250. //model.deleteFile(model.getCurrentDirectory() + 'data/beam');
  251. }
  252. function OnException(err) {
  253. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  254. }
  255. //////////////////////////////////////////////////////////////////////////
  256. // Callback Functions.
  257. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  258. function OnSetChangePost(attribute){
  259. comx.ply.setChangeData(vtkContext.Interface(), postManage, attribute);
  260. ui.canvas.update();
  261. }
  262. function OnPostBar(attribute, isBar){
  263. comx.ply.setPostBars(vtkContext.Interface(), postManage, attribute, isBar);
  264. ui.canvas.update();
  265. }
  266. function OnGenerateGuass(id){
  267. var res = comx.ply.generateBreps(vtkContext.Interface(), workData, id, model.getCurrentDirectory());
  268. ui.canvas.update();
  269. return res;
  270. }
  271. function OnGetName(){
  272. return comx.ply.getCurrentActorName(vtkContext.Interface(), workData);
  273. }
  274. function mousePick(type){
  275. if(type === "points"){
  276. comx.ply.mousePick(vtkContext.Interface(), workData, "points");
  277. }
  278. }
  279. function OnRenders(path, rate){
  280. comx.ply.renderer(vtkContext.Interface(), postManage, path, rate);
  281. ui.canvas.update();
  282. }
  283. function OnModifySpheres(x, y, z, radius, name){
  284. var res = comx.ply.modifySpheres(vtkContext.Interface(), workData, parseFloat(x), parseFloat(y), parseFloat(z), parseFloat(radius), name);
  285. ui.canvas.update();
  286. return res;
  287. }
  288. function OnSpheres(x, y, z, radius, name){
  289. var res = comx.ply.setSpheres(vtkContext.Interface(), workData, parseFloat(x), parseFloat(y), parseFloat(z), parseFloat(radius), name);
  290. ui.canvas.update();
  291. return res;
  292. }
  293. function OnModifyConnects(x, y, z, X, Y, Z, r, g, b, name){
  294. var res = comx.ply.modifyConnects(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  295. ui.canvas.update();
  296. return res;
  297. }
  298. function OnConnects(x, y, z, X, Y, Z, r, g, b, name){
  299. var res = comx.ply.setConnects(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  300. ui.canvas.update();
  301. return res;
  302. }
  303. function OnModifySpring(x, y, z, X, Y, Z, r, g, b, name){
  304. var res = comx.ply.modifySprings(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  305. ui.canvas.update();
  306. return res;
  307. }
  308. function OnSpring(x, y, z, X, Y, Z, r, g, b, name){
  309. var res = comx.ply.setSprings(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  310. ui.canvas.update();
  311. return res;
  312. }
  313. function OnPic(){
  314. comx.ply.pickup(vtkContext.Interface(), workData, "points", 0);
  315. ui.canvas.update();
  316. }
  317. function OnModifyBeams(seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name){
  318. var res = comx.ply.modifyBeams(vtkContext.Interface(), workData, seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name);
  319. ui.canvas.update();
  320. return res;
  321. }
  322. function OnBeams(seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name){
  323. var res = comx.ply.setBeams(vtkContext.Interface(), workData, seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name);
  324. ui.canvas.update();
  325. return res;
  326. }
  327. function OnModifyConstrains(x, y, z, name){
  328. var res = comx.ply.modifyConstraints(vtkContext.Interface(), workData, x, y, z, name);
  329. ui.canvas.update();
  330. return res;
  331. }
  332. function OnConstrains(x, y, z, name){
  333. var res = comx.ply.setConstraints(vtkContext.Interface(), workData, x, y, z, name);
  334. ui.canvas.update();
  335. return res;
  336. }
  337. function OnModifyArrows(x, y, z, xn, yn, zn, name){
  338. return comx.ply.modifyArrows(vtkContext.Interface(), workData, x, y, z, xn, yn, zn, name);
  339. ui.canvas.update();
  340. }
  341. function OnArrows(x, y, z, xn, yn, zn, name){
  342. return comx.ply.setArrows(vtkContext.Interface(), workData, x, y, z, xn, yn, zn, name);
  343. ui.canvas.update();
  344. }
  345. function OnModifyPoints(x, y, z, radius, name){
  346. comx.ply.modifyPoints(vtkContext.Interface(), workData, x, y, z, radius, name);
  347. ui.canvas.update();
  348. }
  349. function OnSetPoints(x, y, z, radius, name){
  350. comx.ply.setPoints(vtkContext.Interface(), workData, x, y, z, radius, name);
  351. ui.canvas.update();
  352. }
  353. function OnMat(){
  354. comx.ply.mousePick(vtkContext.Interface(), workData, "beams_point");
  355. }
  356. function setExecs(index){
  357. ui.cw_solve_setup.exec = index;
  358. }
  359. function OnWindowVisible(idx){
  360. ui.stack_menu.visible = idx;
  361. ui.stack_switch.visible = idx;
  362. }
  363. function OnChangePicture(id, value){
  364. if(id === 1){
  365. if(value === 1){
  366. ui.pc_geo.value = model.getPicturePath('蓝灰色.png');
  367. }else if(value === 2){
  368. ui.pc_geo.value = model.getPicturePath('绿色.png');
  369. }else if(value === 3){
  370. ui.pc_geo.value = model.getPicturePath('红色.png');
  371. }
  372. }else if(id === 2){
  373. if(value === 1){
  374. ui.pc_mat.value = model.getPicturePath('蓝灰色.png');
  375. }else if(value === 2){
  376. ui.pc_mat.value = model.getPicturePath('绿色.png');
  377. }else if(value === 3){
  378. ui.pc_mat.value = model.getPicturePath('红色.png');
  379. }
  380. }else if(id === 3){
  381. if(value === 1){
  382. ui.pc_bou.value = model.getPicturePath('蓝灰色.png');
  383. }else if(value === 2){
  384. ui.pc_bou.value = model.getPicturePath('绿色.png');
  385. }else if(value === 3){
  386. ui.pc_bou.value = model.getPicturePath('红色.png');
  387. }
  388. }else if(id === 4){
  389. if(value === 1){
  390. ui.pc_sol.value = model.getPicturePath('蓝灰色.png');
  391. }else if(value === 2){
  392. ui.pc_sol.value = model.getPicturePath('绿色.png');
  393. }else if(value === 3){
  394. ui.pc_sol.value = model.getPicturePath('红色.png');
  395. }
  396. }else if(id === 5){
  397. if(value === 1){
  398. ui.pc_res.value = model.getPicturePath('蓝灰色.png');
  399. }else if(value === 2){
  400. ui.pc_res.value = model.getPicturePath('绿色.png');
  401. }else if(value === 3){
  402. ui.pc_res.value = model.getPicturePath('红色.png');
  403. }
  404. }
  405. }
  406. function OnCueline(msg, color){
  407. let real_color = 'black';
  408. if(color){real_color = color;}
  409. if(!msg) {
  410. ui.cueline.value = "";
  411. return;
  412. }
  413. ui.cueline.value = `<span style=\"color:black\"><u><b>提示信息</b></u>:</span><span style="color:${real_color}">${msg}</span>`;// + msg;
  414. }
  415. function OnPoints(){
  416. //OnSend('pointsCoord');
  417. comx.ply.mousePick(vtkContext.Interface(), workData, "points");
  418. }
  419. function OnMaterial(){
  420. ui.stack_menu.index = 19;
  421. console.log(22);
  422. }
  423. function OnFalseOpacity(){
  424. var id = parent.setTimeout(() => {
  425. OnSend('0');
  426. }, 100);
  427. OnSend('Opacity 0');
  428. }
  429. function OnOpacity(){
  430. var id = parent.setTimeout(() => {
  431. OnSend('0');
  432. }, 100);
  433. OnSend('Opacity 1');
  434. }
  435. function OnFaceCanvas(){
  436. ui.canvas.filter = [2025]; //面
  437. if (ui.canvas.view()) {
  438. ui.canvas.view().setColor(0.5, 0.5, 0.5, 0.2);
  439. ui.canvas.view().setVisible(true);
  440. ui.canvas.view().setBlend(false);
  441. }
  442. }
  443. function OnLineCanvas(){
  444. ui.canvas.filter = [2025]; //面
  445. if (ui.canvas.view()) {
  446. //ui.canvas.view().setColor(1.0, 1.0, 0.0, 0.0);
  447. ui.canvas.view().setVisible(true);
  448. ui.canvas.view().setBlend(true);
  449. }
  450. }
  451. function OnHightFace(idx){
  452. ui.canvas.view([ui.canvas.generateKey(2025, parseInt(idx))]).setColor(1.0, 0.0, 0.0);
  453. }
  454. function OnSetProp(index){
  455. ui.prop.visible = true;
  456. ui.prop.value = parseFloat(index);
  457. if(parseFloat(index) === 100){
  458. ui.prop.visible = false;
  459. }
  460. }
  461. function OnGetBeam(idx){
  462. myArray.push(idx);
  463. ui.cw_boundary_spring.beam = myArray;
  464. }
  465. function OnDeleteBeam(idx){
  466. myArray.splice(idx, 1);
  467. ui.cw_boundary_spring.beam = myArray;
  468. }
  469. function OnModuleChange(idx){
  470. ui.stack_switch.index = parseInt(idx);
  471. }
  472. function OnTransform(idx) {
  473. //ui.pb_pan.valid = ui.pb_rotate.valid = ui.pb_zoom.valid = ui.pb_zoom_window.valid = false;
  474. if (idx === 1) {
  475. //ui.pb_pan.valid = true;
  476. ui.canvas.sensor = GL.Sensor.Pan;
  477. }
  478. if (idx === 2) {
  479. //ui.canvas.sensor = GL.Sensor.Rotate;
  480. ui.pb_rotate.valid = true;
  481. }
  482. if (idx === 3) {
  483. //ui.canvas.sensor = GL.Sensor.Scale;
  484. ui.pb_zoom.valid = true;
  485. }
  486. if (idx === 4) {
  487. //ui.canvas.sensor = GL.Sensor.RectScale;
  488. ui.pb_zoom_window.valid = true;
  489. }
  490. }
  491. function On3DPosition(idx) {
  492. //ui.pb_yox.valid = ui.pb_xoy.valid = ui.pb_zoy.valid = ui.pb_yoz.valid = ui.pb_zox.valid = ui.pb_xoz.valid = false;
  493. if (idx === 1) {
  494. //ui.pb_yox.valid = true;
  495. ui.canvas.sensor = GL.Sensor.YOX;
  496. }
  497. if (idx === 2) {
  498. //ui.pb_xoy.valid = true;
  499. ui.canvas.sensor = GL.Sensor.XOY;
  500. }
  501. if (idx === 3) {
  502. //ui.pb_zoy.valid = true;
  503. ui.canvas.sensor = GL.Sensor.ZOY;
  504. }
  505. if (idx === 4) {
  506. //ui.pb_yoz.valid = true;
  507. ui.canvas.sensor = GL.Sensor.YOZ;
  508. }
  509. if (idx === 5) {
  510. //ui.pb_xoz.valid = true;
  511. ui.canvas.sensor = GL.Sensor.XOZ;
  512. }
  513. if (idx === 6) {
  514. //ui.pb_zox.valid = true;
  515. ui.canvas.sensor = GL.Sensor.ZOX;
  516. }
  517. }
  518. //用树id取出真实id
  519. function findRIdById(jsonData, targetId) {
  520. let result = null; // 存储结果
  521. function traverse(node) {
  522. // 如果当前节点的 id 匹配目标值,记录其 r_id
  523. if (node.id === targetId) {
  524. result = node.r_id;
  525. return; // 提前结束递归
  526. }
  527. // 如果有子节点,则递归遍历子节点
  528. if (node.children && Array.isArray(node.children)) {
  529. for (let child of node.children) {
  530. traverse(child);
  531. if (result !== null) {return;} // 如果已找到,停止遍历
  532. }
  533. }
  534. }
  535. traverse(jsonData); // 开始遍历
  536. return result; // 返回结果或 null
  537. }
  538. //将真实id转换为对应树id
  539. function findNodeIdByRId(jsonData, targetRId) {
  540. let result = null; // 用于存储找到的节点的 id
  541. function traverse(node) {
  542. // 如果当前节点的 r_id 与目标值匹配,记录其 id
  543. if (node.r_id === targetRId) {
  544. result = node.id;
  545. return; // 提前结束当前递归
  546. }
  547. // 如果有子节点,则递归遍历子节点
  548. if (node.children && Array.isArray(node.children)) {
  549. for (let child of node.children) {
  550. traverse(child);
  551. if (result !== null) {return;} // 如果已经找到,停止遍历
  552. }
  553. }
  554. }
  555. traverse(jsonData); // 开始遍历
  556. return result; // 返回找到的 id 或 null
  557. }
  558. function OnPickUp() {
  559. if (!ui.canvas.hits) {
  560. return;
  561. }
  562. //放brep路径
  563. var rec = ui.canvas.hits[0];
  564. var key = rec.keyRecord;
  565. var keyObj = ui.canvas.parseKey(key);
  566. console.log("keyObj", keyObj);
  567. let id = findNodeIdByRId(model.acax_app.model.project.GetModel().pro_model, keyObj.sid);
  568. console.log("id", id);
  569. var path = model.getCurrentDirectory() + "data/brep/face" + id + ".brep";
  570. comx.occio.GetFaceBrep(comx.occore.GetEntryEx(), keyObj.sid, path);
  571. var facName = "type:F 0 " + id + " " + comx.occio.GetFacePoint(comx.occore.GetEntryEx(), keyObj.sid);
  572. OnSetFaceName(facName);
  573. let brep = {
  574. "brep":path.replace(/\\/g, "/")
  575. } ;
  576. unit.form.tree.SetBrepFile(brep);
  577. }
  578. function GetBrepPath() {
  579. return brep_path;
  580. }
  581. var faceName;
  582. function OnSetFaceName(input){
  583. faceName = input;
  584. }
  585. function OnGetFaceName(){
  586. return faceName;
  587. }
  588. function pick(idx) {
  589. console.log(idx);
  590. if (idx === 1) {
  591. ui.canvas.picker = {
  592. mode: GL.Picker.Mode.Single,
  593. autoHighlight: true,
  594. behavior: GL.Picker.Behavior.Point
  595. };
  596. }
  597. if (idx === 2) {
  598. ui.canvas.picker = {
  599. mode: GL.Picker.Mode.Multi,
  600. autoHighlight: true,
  601. behavior: GL.Picker.Behavior.None
  602. };
  603. }
  604. }
  605. function OnChangeWindows(Idx){
  606. if(Idx === 1){
  607. ui.pb_window.index = 0;
  608. }
  609. if(Idx === 2){
  610. ui.pb_window.index = 1;
  611. }
  612. }
  613. function OnOpenSTL(){
  614. var fname = ui.OpenFileDialog("Import File", unit.dir + 'data/', "Stl Files(*.stl *.STL)");
  615. ui.cw_boundary_STL.path = fname;
  616. }
  617. function OnSend(Idx) {
  618. //console.log(33);
  619. if (g_io) {
  620. g_io.send(Idx);
  621. }
  622. }
  623. function OnOpenFile(fname) {
  624. //console.log(1000);
  625. if (fname) {
  626. //console.log(fname);
  627. model.execs(model.getCurrentDirectory() + "/src/generateBrep/generateBrep.exe " + fname + " " + model.getCurrentDirectory(), cb => {
  628. console.log(cb);
  629. });
  630. var is_step = (fname.indexOf('.STEP') !== -1) ||
  631. (fname.indexOf('.step') !== -1) ||
  632. (fname.indexOf('.STP') !== -1) ||
  633. (fname.indexOf('.stp') !== -1);
  634. var is_nas = (fname.indexOf('.nas') !== -1) || (fname.indexOf('.NAS') !== -1);
  635. model.wait();
  636. ui.canvas.db = null;
  637. parent.setTimeout(() => {
  638. if (is_step) {
  639. console.time('Global Step Load');
  640. ui.canvas.step = fname;
  641. console.timeEnd('Global Step Load');
  642. } else if (is_nas) {
  643. console.time('Global Nastran Load');
  644. ui.canvas.nastran = fname;
  645. console.timeEnd('Global Nastran Load');
  646. SetCanvasProp();
  647. } else {
  648. console.time('Global Iges Load');
  649. ui.canvas.iges = fname;
  650. console.timeEnd('Global Iges Load');
  651. }
  652. SetCanvasProp();
  653. ui.canvas.lamp = true;
  654. model.stop();
  655. }, 100);
  656. }
  657. ui.cw_geometry_check.path = fname;
  658. }
  659. function OnChangeValue(idx){
  660. menu(idx);
  661. }
  662. function menu(Idx) {
  663. ui.stack_menu.index = parseInt(Idx);
  664. }
  665. function changeConstrain(index1, index2){
  666. if(index1 === 1){
  667. ui.cw_boundary_constraint_25.change1 = index2;
  668. }
  669. if(index1 === 2){
  670. ui.cw_boundary_constraint_25.change2 = index2;
  671. }
  672. if(index1 === 3){
  673. ui.cw_boundary_force_24.index = index2;
  674. }
  675. }
  676. //The message corresponding callback executed by the main form
  677. // when calling pui.fireEvent(type,para) in the Docker subform.
  678. function OnChildDockerMessage(type, para){
  679. }
  680. //////////////////////////////////////////////////////////////////////////
  681. // Utils Functions.
  682. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  683. function onDragFile(filepath) {
  684. }
  685. /*Usage of BLOCK_EVENT
  686. BLOCK_EVENT(()=>{
  687. ui.[name].[var] = ...;
  688. });
  689. */
  690. function BLOCK_EVENT(cb) {
  691. ui.block_event = true;
  692. cb();
  693. ui.block_event = false;
  694. }