mainfrm_pane.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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 upDateCanvas() {
  222. ui.canvas.update();
  223. }
  224. function OnInitializeData(reload, preview) {
  225. //model.ide_info(model.uuid().length);
  226. vtkContext = comx.vtk.CreateContext();
  227. ui.canvas.vtkContextInterface = vtkContext.Interface();
  228. workData = comx.ply.InitWorkArea();
  229. postManage = comx.ply.InitPostManage();
  230. ui.pc_geo.value = model.getPicturePath('蓝灰色.png');
  231. OnCueline('白色->未使用,蓝灰色->正在处理,绿色->未通过,蓝色->通过', 'blue');
  232. InitCanvasIOEngine();
  233. parent.setTimeout(() => {
  234. OnInitDocker();
  235. }, 0);
  236. ui.canvas.lamp = true;
  237. }
  238. //Callback after UI is fully loaded and displayed.
  239. function OnAnalysisShow(){
  240. //unit.form.form.Show();
  241. }
  242. function OnSolveShow(){
  243. }
  244. function OnReady(reload, preview) {
  245. }
  246. function OnCloseForm() {
  247. //console.log(11);
  248. //model.deleteFile(model.getCurrentDirectory() + 'data/faceID');
  249. //model.deleteFile(model.getCurrentDirectory() + 'data/face');
  250. //model.deleteFile(model.getCurrentDirectory() + 'data/peidian');
  251. //model.deleteFile(model.getCurrentDirectory() + 'data/restraint');
  252. //model.deleteFile(model.getCurrentDirectory() + 'data/force');
  253. //model.deleteFile(model.getCurrentDirectory() + 'data/beam');
  254. }
  255. function OnException(err) {
  256. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  257. }
  258. //////////////////////////////////////////////////////////////////////////
  259. // Callback Functions.
  260. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  261. function OnLight(isLight){
  262. if(isLight){
  263. ui.canvas.lamp = true;
  264. }else{
  265. ui.canvas.lamp = false;
  266. }
  267. }
  268. function OnCanvasContentMenu(){
  269. if(ui.canvas.content_menu === 1){
  270. OnTransform(1);
  271. }
  272. if(ui.canvas.content_menu === 2){
  273. OnTransform(2);
  274. }
  275. if(ui.canvas.content_menu === 3){
  276. On3DPosition(1);
  277. }
  278. if(ui.canvas.content_menu === 4){
  279. On3DPosition(2);
  280. }
  281. if(ui.canvas.content_menu === 5){
  282. On3DPosition(3);
  283. }
  284. if(ui.canvas.content_menu === 6){
  285. On3DPosition(4);
  286. }
  287. if(ui.canvas.content_menu === 7){
  288. On3DPosition(5);
  289. }
  290. if(ui.canvas.content_menu === 8){
  291. On3DPosition(6);
  292. }
  293. }
  294. function OnCanvasRightClick(){
  295. ui.canvas.content_menu = [
  296. {
  297. name: '旋转',
  298. icon: 'bar10',
  299. id: 1
  300. },
  301. {
  302. name: '平移',
  303. icon: 'bar11',
  304. id: 2
  305. },
  306. {
  307. name: '-'
  308. },
  309. {
  310. name: 'YOX',
  311. icon: 'bar19',
  312. id: 3
  313. },
  314. {
  315. name: 'XOY',
  316. icon: 'bar20',
  317. id: 4
  318. },
  319. {
  320. name: 'ZOX',
  321. icon: 'bar21',
  322. id: 5
  323. },
  324. {
  325. name: 'XOZ',
  326. icon: 'bar22',
  327. id: 6
  328. },
  329. {
  330. name: 'ZOY',
  331. icon: 'bar23',
  332. id: 7
  333. },
  334. {
  335. name: 'YOZ',
  336. icon: 'bar24',
  337. id: 8
  338. }
  339. ];
  340. }
  341. function OnClear(){
  342. ui.canvas.db = null;
  343. }
  344. /*
  345. function OnHide(){
  346. comx.ply.hideShow(vtkContext.Interface(), workData, "mark", "mark", true);
  347. }*/
  348. function OnForceChange(idx){
  349. ui.cw_boundary_force_24.idx = idx;
  350. }
  351. function OnConChange(idx){
  352. ui.cw_boundary_constraint_25.idx = idx;
  353. }
  354. function OnCut(x, y, z, xn, yn, zn){
  355. comx.ply.cutters(vtkContext.Interface(), postManage, x, y, z, xn, yn, zn);
  356. }
  357. function OnRGBMap4(r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4, r5, g5, b5){
  358. comx.ply.colorRGBS4(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2, r3, g3, b3, r4, g4, b4, r5, g5, b5);
  359. }
  360. function OnRGBMap3(r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4){
  361. comx.ply.colorRGBS3(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2, r3, g3, b3, r4, g4, b4);
  362. }
  363. function OnRGBMap2(r1, g1, b1, r2, g2, b2, r3, g3, b3){
  364. comx.ply.colorRGBS2(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2, r3, g3, b3);
  365. }
  366. function OnRGBMap1(r1, g1, b1, r2, g2, b2){
  367. comx.ply.colorRGBS1(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2);
  368. }
  369. function OnMotifyMarks(x, y, z, r, g, b, size, mark, name){
  370. comx.ply.modifyMarks(vtkContext.Interface(), workData, x, y, z, r, g, b, size, mark, name);
  371. }
  372. function OnSetMarks(x, y, z, r, g, b, size, mark, name){
  373. comx.ply.setMarks(vtkContext.Interface(), workData, x, y, z, r, g, b, size, mark, name);
  374. }
  375. function OnSetChangePost(attribute){
  376. comx.ply.setChangeData(vtkContext.Interface(), postManage, attribute);
  377. ui.canvas.update();
  378. }
  379. function OnPostBar(attribute, isBar){
  380. comx.ply.setPostBars(vtkContext.Interface(), postManage, attribute, isBar);
  381. ui.canvas.update();
  382. }
  383. function OnGenerateGuass(id){
  384. var res = comx.ply.generateBreps(vtkContext.Interface(), workData, id, model.getCurrentDirectory());
  385. ui.canvas.update();
  386. return res;
  387. }
  388. function OnGetName(){
  389. return comx.ply.getCurrentActorName(vtkContext.Interface(), workData);
  390. }
  391. function mousePick(type){
  392. if(type === "points"){
  393. comx.ply.mousePick(vtkContext.Interface(), workData, "points");
  394. }
  395. }
  396. function OnRenders(path, rate){
  397. comx.ply.renderer(vtkContext.Interface(), postManage, path, rate);
  398. ui.canvas.update();
  399. }
  400. function OnModifySpheres(x, y, z, radius, name){
  401. var res = comx.ply.modifySpheres(vtkContext.Interface(), workData, parseFloat(x), parseFloat(y), parseFloat(z), parseFloat(radius), name);
  402. ui.canvas.update();
  403. return res;
  404. }
  405. function OnSpheres(x, y, z, radius, name){
  406. var res = comx.ply.setSpheres(vtkContext.Interface(), workData, parseFloat(x), parseFloat(y), parseFloat(z), parseFloat(radius), name);
  407. ui.canvas.update();
  408. return res;
  409. }
  410. function OnModifyConnects(x, y, z, X, Y, Z, r, g, b, name){
  411. var res = comx.ply.modifyConnects(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  412. ui.canvas.update();
  413. return res;
  414. }
  415. function OnConnects(x, y, z, X, Y, Z, r, g, b, name){
  416. var res = comx.ply.setConnects(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  417. ui.canvas.update();
  418. return res;
  419. }
  420. function OnModifySpring(x, y, z, X, Y, Z, r, g, b, name){
  421. var res = comx.ply.modifySprings(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  422. ui.canvas.update();
  423. return res;
  424. }
  425. function OnSpring(x, y, z, X, Y, Z, r, g, b, name){
  426. var res = comx.ply.setSprings(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  427. ui.canvas.update();
  428. return res;
  429. }
  430. function OnPic(){
  431. comx.ply.pickup(vtkContext.Interface(), workData, "points", 0);
  432. ui.canvas.update();
  433. }
  434. function OnModifyBeams(seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name){
  435. var res = comx.ply.modifyBeams(vtkContext.Interface(), workData, seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name);
  436. ui.canvas.update();
  437. return res;
  438. }
  439. function OnBeams(seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name){
  440. var res = comx.ply.setBeams(vtkContext.Interface(), workData, seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name);
  441. ui.canvas.update();
  442. return res;
  443. }
  444. function OnModifyConstrains(x, y, z, name){
  445. var res = comx.ply.modifyConstraints(vtkContext.Interface(), workData, x, y, z, name);
  446. ui.canvas.update();
  447. return res;
  448. }
  449. function OnConstrains(x, y, z, name){
  450. var res = comx.ply.setConstraints(vtkContext.Interface(), workData, x, y, z, name);
  451. ui.canvas.update();
  452. return res;
  453. }
  454. function OnModifyArrows(x, y, z, xn, yn, zn, name){
  455. var res = comx.ply.modifyArrows(vtkContext.Interface(), workData, x, y, z, xn, yn, zn, name);
  456. ui.canvas.update();
  457. return res;
  458. }
  459. function OnArrows(x, y, z, xn, yn, zn, name){
  460. var res = comx.ply.setArrows(vtkContext.Interface(), workData, x, y, z, xn, yn, zn, name);
  461. ui.canvas.update();
  462. return res;
  463. }
  464. function OnModifyPoints(x, y, z, radius, name){
  465. comx.ply.modifyPoints(vtkContext.Interface(), workData, x, y, z, radius, name);
  466. ui.canvas.update();
  467. }
  468. function OnSetPoints(x, y, z, radius, name){
  469. comx.ply.setPoints(vtkContext.Interface(), workData, x, y, z, radius, name);
  470. ui.canvas.update();
  471. }
  472. function OnMat(){
  473. comx.ply.mousePick(vtkContext.Interface(), workData, "beams_point");
  474. }
  475. function setExecs(index){
  476. ui.cw_solve_setup.exec = index;
  477. }
  478. function OnWindowVisible(idx){
  479. ui.stack_menu.visible = idx;
  480. ui.stack_switch.visible = idx;
  481. }
  482. function OnChangePicture(id, value){
  483. if(id === 1){
  484. if(value === 1){
  485. ui.pc_geo.value = model.getPicturePath('蓝灰色.png');
  486. }else if(value === 2){
  487. ui.pc_geo.value = model.getPicturePath('绿色.png');
  488. }else if(value === 3){
  489. ui.pc_geo.value = model.getPicturePath('红色.png');
  490. }
  491. }else if(id === 2){
  492. if(value === 1){
  493. ui.pc_mat.value = model.getPicturePath('蓝灰色.png');
  494. }else if(value === 2){
  495. ui.pc_mat.value = model.getPicturePath('绿色.png');
  496. }else if(value === 3){
  497. ui.pc_mat.value = model.getPicturePath('红色.png');
  498. }
  499. }else if(id === 3){
  500. if(value === 1){
  501. ui.pc_bou.value = model.getPicturePath('蓝灰色.png');
  502. }else if(value === 2){
  503. ui.pc_bou.value = model.getPicturePath('绿色.png');
  504. }else if(value === 3){
  505. ui.pc_bou.value = model.getPicturePath('红色.png');
  506. }
  507. }else if(id === 4){
  508. if(value === 1){
  509. ui.pc_sol.value = model.getPicturePath('蓝灰色.png');
  510. }else if(value === 2){
  511. ui.pc_sol.value = model.getPicturePath('绿色.png');
  512. }else if(value === 3){
  513. ui.pc_sol.value = model.getPicturePath('红色.png');
  514. }
  515. }else if(id === 5){
  516. if(value === 1){
  517. ui.pc_res.value = model.getPicturePath('蓝灰色.png');
  518. }else if(value === 2){
  519. ui.pc_res.value = model.getPicturePath('绿色.png');
  520. }else if(value === 3){
  521. ui.pc_res.value = model.getPicturePath('红色.png');
  522. }
  523. }
  524. }
  525. function OnCueline(msg, color){
  526. let real_color = 'black';
  527. if(color){real_color = color;}
  528. if(!msg) {
  529. ui.cueline.value = "";
  530. return;
  531. }
  532. ui.cueline.value = `<span style=\"color:black\"><u><b>提示信息</b></u>:</span><span style="color:${real_color}">${msg}</span>`;// + msg;
  533. }
  534. function OnPoints(){
  535. //OnSend('pointsCoord');
  536. comx.ply.mousePick(vtkContext.Interface(), workData, "points");
  537. }
  538. function OnMaterial(){
  539. ui.stack_menu.index = 19;
  540. console.log(22);
  541. }
  542. function OnFalseOpacity(){
  543. comx.ply.openCloseOpacity(vtkContext.Interface(), postManage, false);
  544. }
  545. function OnOpacity(){
  546. comx.ply.openCloseOpacity(vtkContext.Interface(), postManage, true);
  547. }
  548. function OnFaceCanvas(){
  549. ui.canvas.filter = [2025]; //面
  550. if (ui.canvas.view()) {
  551. ui.canvas.view().setColor(0.5, 0.5, 0.5, 0.2);
  552. ui.canvas.view().setVisible(true);
  553. ui.canvas.view().setBlend(false);
  554. }
  555. }
  556. function OnLineCanvas(){
  557. ui.canvas.filter = [2025]; //面
  558. if (ui.canvas.view()) {
  559. //ui.canvas.view().setColor(1.0, 1.0, 0.0, 0.0);
  560. ui.canvas.view().setVisible(true);
  561. ui.canvas.view().setBlend(true);
  562. }
  563. }
  564. function OnHightFace(idx){
  565. ui.canvas.view([ui.canvas.generateKey(2025, parseInt(idx))]).setColor(1.0, 0.0, 0.0);
  566. }
  567. function OnSetProp(index){
  568. ui.prop.visible = true;
  569. ui.prop.value = parseFloat(index);
  570. if(parseFloat(index) === 100){
  571. ui.prop.visible = false;
  572. }
  573. }
  574. function OnGetBeam(idx){
  575. myArray.push(idx);
  576. ui.cw_boundary_spring.beam = myArray;
  577. }
  578. function OnDeleteBeam(idx){
  579. myArray.splice(idx, 1);
  580. ui.cw_boundary_spring.beam = myArray;
  581. }
  582. function OnModuleChange(idx){
  583. ui.stack_switch.index = parseInt(idx);
  584. }
  585. function OnTransform(idx) {
  586. //ui.pb_pan.valid = ui.pb_rotate.valid = ui.pb_zoom.valid = ui.pb_zoom_window.valid = false;
  587. if (idx === 1) {
  588. ui.canvas.sensor = GL.Sensor.Rotate;
  589. //ui.pb_pan.valid = true;
  590. //ui.canvas.sensor = GL.Sensor.Pan;
  591. }
  592. if (idx === 2) {
  593. ui.canvas.sensor = GL.Sensor.Pan;
  594. //ui.canvas.sensor = GL.Sensor.Rotate;
  595. //ui.pb_rotate.valid = true;
  596. }
  597. if (idx === 3) {
  598. //ui.canvas.sensor = GL.Sensor.Scale;
  599. ui.pb_zoom.valid = true;
  600. }
  601. if (idx === 4) {
  602. //ui.canvas.sensor = GL.Sensor.RectScale;
  603. ui.pb_zoom_window.valid = true;
  604. }
  605. }
  606. function On3DPosition(idx) {
  607. //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;
  608. if (idx === 1) {
  609. //ui.pb_yox.valid = true;
  610. ui.canvas.sensor = GL.Sensor.YOX;
  611. }
  612. if (idx === 2) {
  613. //ui.pb_xoy.valid = true;
  614. ui.canvas.sensor = GL.Sensor.XOY;
  615. }
  616. if (idx === 3) {
  617. //ui.pb_zoy.valid = true;
  618. ui.canvas.sensor = GL.Sensor.ZOY;
  619. }
  620. if (idx === 4) {
  621. //ui.pb_yoz.valid = true;
  622. ui.canvas.sensor = GL.Sensor.YOZ;
  623. }
  624. if (idx === 5) {
  625. //ui.pb_xoz.valid = true;
  626. ui.canvas.sensor = GL.Sensor.XOZ;
  627. }
  628. if (idx === 6) {
  629. //ui.pb_zox.valid = true;
  630. ui.canvas.sensor = GL.Sensor.ZOX;
  631. }
  632. }
  633. //用树id取出真实id
  634. function findRIdById(jsonData, targetId) {
  635. let result = null; // 存储结果
  636. function traverse(node) {
  637. // 如果当前节点的 id 匹配目标值,记录其 r_id
  638. if (node.id === targetId) {
  639. result = node.r_id;
  640. return; // 提前结束递归
  641. }
  642. // 如果有子节点,则递归遍历子节点
  643. if (node.children && Array.isArray(node.children)) {
  644. for (let child of node.children) {
  645. traverse(child);
  646. if (result !== null) {return;} // 如果已找到,停止遍历
  647. }
  648. }
  649. }
  650. traverse(jsonData); // 开始遍历
  651. return result; // 返回结果或 null
  652. }
  653. //将真实id转换为对应树id
  654. function findNodeIdByRId(jsonData, targetRId) {
  655. let result = null; // 用于存储找到的节点的 id
  656. function traverse(node) {
  657. // 如果当前节点的 r_id 与目标值匹配,记录其 id
  658. if (node.r_id === targetRId) {
  659. result = node.id;
  660. return; // 提前结束当前递归
  661. }
  662. // 如果有子节点,则递归遍历子节点
  663. if (node.children && Array.isArray(node.children)) {
  664. for (let child of node.children) {
  665. traverse(child);
  666. if (result !== null) {return;} // 如果已经找到,停止遍历
  667. }
  668. }
  669. }
  670. traverse(jsonData); // 开始遍历
  671. return result; // 返回找到的 id 或 null
  672. }
  673. function OnPickUp() {
  674. if (!ui.canvas.hits) {
  675. return;
  676. }
  677. //放brep路径
  678. var rec = ui.canvas.hits[0];
  679. var key = rec.keyRecord;
  680. var keyObj = ui.canvas.parseKey(key);
  681. console.log("keyObj", keyObj);
  682. let id = findNodeIdByRId(model.acax_app.model.project.GetModel().pro_model, keyObj.sid);
  683. console.log("id", id);
  684. var path = model.getCurrentDirectory() + "data/brep/face" + id + ".brep";
  685. comx.occio.GetFaceBrep(comx.occore.GetEntryEx(), keyObj.sid, path);
  686. var facName = "type:F 0 " + id + " " + comx.occio.GetFacePoint(comx.occore.GetEntryEx(), keyObj.sid);
  687. OnSetFaceName(facName);
  688. let brep = {
  689. "brep":path.replace(/\\/g, "/")
  690. } ;
  691. unit.form.tree.SetBrepFile(brep);
  692. }
  693. function GetBrepPath() {
  694. return brep_path;
  695. }
  696. var faceName;
  697. function OnSetFaceName(input){
  698. faceName = input;
  699. }
  700. function OnGetFaceName(){
  701. return faceName;
  702. }
  703. function pick(idx) {
  704. console.log(idx);
  705. if (idx === 1) {
  706. ui.canvas.picker = {
  707. mode: GL.Picker.Mode.Single,
  708. autoHighlight: true,
  709. behavior: GL.Picker.Behavior.Point
  710. };
  711. }
  712. if (idx === 2) {
  713. ui.canvas.picker = {
  714. mode: GL.Picker.Mode.Multi,
  715. autoHighlight: true,
  716. behavior: GL.Picker.Behavior.None
  717. };
  718. }
  719. }
  720. function OnChangeWindows(Idx){
  721. if(Idx === 1){
  722. ui.pb_window.index = 0;
  723. }
  724. if(Idx === 2){
  725. ui.pb_window.index = 1;
  726. }
  727. }
  728. function OnOpenSTL(){
  729. var fname = ui.OpenFileDialog("Import File", unit.dir + 'data/', "Stl Files(*.stl *.STL)");
  730. ui.cw_boundary_STL.path = fname;
  731. }
  732. function OnSend(Idx) {
  733. //console.log(33);
  734. if (g_io) {
  735. g_io.send(Idx);
  736. }
  737. }
  738. function OnOpenFile(fname) {
  739. //console.log(1000);
  740. if (fname) {
  741. //console.log(fname);
  742. model.execs(model.getCurrentDirectory() + "/src/generateBrep/generateBrep.exe " + fname + " " + model.getCurrentDirectory(), cb => {
  743. console.log(cb);
  744. });
  745. var is_step = (fname.indexOf('.STEP') !== -1) ||
  746. (fname.indexOf('.step') !== -1) ||
  747. (fname.indexOf('.STP') !== -1) ||
  748. (fname.indexOf('.stp') !== -1);
  749. var is_nas = (fname.indexOf('.nas') !== -1) || (fname.indexOf('.NAS') !== -1);
  750. model.wait();
  751. ui.canvas.db = null;
  752. parent.setTimeout(() => {
  753. if (is_step) {
  754. console.time('Global Step Load');
  755. ui.canvas.step = fname;
  756. console.timeEnd('Global Step Load');
  757. } else if (is_nas) {
  758. console.time('Global Nastran Load');
  759. ui.canvas.nastran = fname;
  760. console.timeEnd('Global Nastran Load');
  761. SetCanvasProp();
  762. } else {
  763. console.time('Global Iges Load');
  764. ui.canvas.iges = fname;
  765. console.timeEnd('Global Iges Load');
  766. }
  767. SetCanvasProp();
  768. ui.canvas.lamp = true;
  769. model.stop();
  770. }, 100);
  771. }
  772. ui.cw_geometry_check.path = fname;
  773. }
  774. function OnChangeValue(idx){
  775. menu(idx);
  776. }
  777. function menu(Idx) {
  778. ui.stack_menu.index = parseInt(Idx);
  779. }
  780. function OnChangeIndex(idx){
  781. ui.geo.index = idx;
  782. }
  783. function changeConstrain(index1, index2){
  784. if(index1 === 1){
  785. ui.cw_boundary_constraint_25.change1 = index2;
  786. }
  787. if(index1 === 2){
  788. ui.cw_boundary_constraint_25.change2 = index2;
  789. }
  790. if(index1 === 3){
  791. ui.cw_boundary_force_24.index = index2;
  792. }
  793. }
  794. //The message corresponding callback executed by the main form
  795. // when calling pui.fireEvent(type,para) in the Docker subform.
  796. function OnChildDockerMessage(type, para){
  797. }
  798. //////////////////////////////////////////////////////////////////////////
  799. // Utils Functions.
  800. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  801. function onDragFile(filepath) {
  802. }
  803. /*Usage of BLOCK_EVENT
  804. BLOCK_EVENT(()=>{
  805. ui.[name].[var] = ...;
  806. });
  807. */
  808. function BLOCK_EVENT(cb) {
  809. ui.block_event = true;
  810. cb();
  811. ui.block_event = false;
  812. }