mainfrm_pane.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  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 isEnablePost(isUse){
  117. ui.pb_open.enable = isUse;
  118. ui.pb_close.enable = isUse;
  119. ui.pb_colorMap.enable = isUse;
  120. }
  121. function OnTest1(){
  122. changeColor("rb3", "121rb3 0", 1, 0, 0);
  123. }
  124. function changeColor(type, name, r, g, b) {
  125. comx.ply.changeColor(vtkContext.Interface(), workData, type, name, r, g, b);
  126. }
  127. function HideAndShow(type, name, flag) {
  128. comx.ply.hideShow(vtkContext.Interface(), workData, type, name, flag);
  129. }
  130. function upDateCanvas() {
  131. ui.canvas.update();
  132. }
  133. //显示3D模型
  134. function OnloadModel(path) {
  135. ui.canvas.step = path;
  136. }
  137. //清除canvas
  138. function ClearCanvas() {
  139. ui.canvas.db = null;
  140. }
  141. //设置材料参数界面
  142. function setMaterial(material) {
  143. ui.physics_mastk.setmaterial = material;
  144. }
  145. //设置约束
  146. function setConstraint(prop) {
  147. let constraint = {
  148. "固定支撑":function(){
  149. ui.cw_boundary_constraint_25.setConstraint0 = prop;
  150. },
  151. "梁":function(){
  152. ui.cw_boundary_constraint_25.setConstraint1 = prop;
  153. },
  154. "弹簧":function(){
  155. ui.cw_boundary_constraint_25.setConstraint2 = prop;
  156. },
  157. "连接":function(){
  158. ui.cw_boundary_constraint_25.setConstraint3 = prop;
  159. },
  160. "梁(非均匀)":function(){
  161. },
  162. "集中载荷压力":function(){
  163. ui.cw_boundary_force_24.setConstraint0 = prop;
  164. },
  165. "分布载荷压力":function(){
  166. ui.cw_boundary_force_24.setConstraint1 = prop;
  167. },
  168. "rb3":function(){
  169. ui.cw_boundary_brep_23.setConstraint = prop;
  170. }
  171. };
  172. constraint[prop.constraint]();
  173. }
  174. //显示重命名界面
  175. function RenameTreeNode(Idx) {
  176. if(Idx === 2) {
  177. unit.form.Rename.Show();
  178. }else if(Idx === 5){
  179. unit.form.RenameMaterial.Show();
  180. }
  181. }
  182. //点亮面
  183. function LightFace(id, rgb) {
  184. let r_id = findRIdById(model.acax_app.model.project.GetModel().pro_model, parseInt(id));
  185. ui.canvas.view([ui.canvas.generateKey(2025, parseInt(r_id))]).setColor(parseFloat(rgb.r)/255, parseFloat(rgb.g)/255, parseFloat(rgb.b)/255);
  186. }
  187. //加载涂色
  188. function SetColor(color) {
  189. let color_arr = Object.keys(color);
  190. for (let i = 0; i < color_arr.length; ++i) {
  191. try {
  192. //console.log(i + " ");
  193. // 查找 r_id
  194. let r_id = findRIdById(
  195. model.acax_app.model.project.GetModel().pro_model,
  196. parseInt(color_arr[i])
  197. );
  198. if (!r_id) {
  199. throw new Error(`r_id not found for id: ${color_arr[i]}`);
  200. }
  201. // 转换颜色为 RGB
  202. let rgb = hexToRgb(color[color_arr[i]]);
  203. if (!rgb || rgb.r === undefined || rgb.g === undefined || rgb.b === undefined) {
  204. throw new Error(`Invalid color value: ${color[color_arr[i]]}`);
  205. }
  206. // 设置颜色
  207. ui.canvas
  208. .view([ui.canvas.generateKey(2025, parseInt(r_id))])
  209. .setColor(
  210. parseFloat(rgb.r) / 255,
  211. parseFloat(rgb.g) / 255,
  212. parseFloat(rgb.b) / 255
  213. );
  214. } catch (error) {
  215. console.error(
  216. `Failed to set color for id ${color_arr[i]}: `,
  217. error.message
  218. );
  219. }
  220. }
  221. }
  222. //设置面高亮并选中
  223. function PickFaceLight(id) {
  224. let idx = findRIdById(model.acax_app.model.project.GetModel().pro_model, id);
  225. //console.log(idx);
  226. if(idx){
  227. ui.canvas.view([ui.canvas.generateKey(2025, parseInt(idx))]).setColor(235/255, 152/255, 20/255);
  228. var path = model.getCurrentDirectory() + "data/brep/face" + id + ".brep";
  229. comx.occio.GetFaceBrep(comx.occore.GetEntryEx(), idx, path);
  230. var facName = "type:F 0 " + id + " " + comx.occio.GetFacePoint(comx.occore.GetEntryEx(), idx);
  231. OnSetFaceName(facName);
  232. let brep = {
  233. "brep":path.replace(/\\/g, "/")
  234. } ;
  235. unit.form.tree.SetBrepFile(brep);
  236. }
  237. }
  238. function hexToRgb(hex) {
  239. // 去掉前缀 #(如果有)
  240. hex = hex.replace(/^#/, '');
  241. // 如果是简写形式(#RGB),将其转换为完整形式(#RRGGBB)
  242. if (hex.length === 3) {
  243. hex = hex.split('').map(char => char + char).join('');
  244. }
  245. // 解析 RGB 颜色值
  246. const r = parseInt(hex.slice(0, 2), 16);
  247. const g = parseInt(hex.slice(2, 4), 16);
  248. const b = parseInt(hex.slice(4, 6), 16);
  249. return { r, g, b };
  250. }
  251. function OnInitializeData(reload, preview) {
  252. //model.ide_info(model.uuid().length);
  253. vtkContext = comx.vtk.CreateContext();
  254. ui.canvas.vtkContextInterface = vtkContext.Interface();
  255. workData = comx.ply.InitWorkArea();
  256. postManage = comx.ply.InitPostManage();
  257. ui.pc_geo.value = model.getPicturePath('蓝灰色.png');
  258. OnCueline('白色->未使用,蓝灰色->正在处理,绿色->未通过,蓝色->通过', 'blue');
  259. InitCanvasIOEngine();
  260. parent.setTimeout(() => {
  261. OnInitDocker();
  262. }, 0);
  263. ui.canvas.lamp = true;
  264. OnPoints();
  265. }
  266. //Callback after UI is fully loaded and displayed.
  267. function OnAnalysisShow(){
  268. //unit.form.form.Show();
  269. }
  270. function OnSolveShow(){
  271. }
  272. function OnReady(reload, preview) {
  273. }
  274. function OnCloseForm() {
  275. //console.log(11);
  276. //model.deleteFile(model.getCurrentDirectory() + 'data/faceID');
  277. //model.deleteFile(model.getCurrentDirectory() + 'data/face');
  278. //model.deleteFile(model.getCurrentDirectory() + 'data/peidian');
  279. //model.deleteFile(model.getCurrentDirectory() + 'data/restraint');
  280. //model.deleteFile(model.getCurrentDirectory() + 'data/force');
  281. //model.deleteFile(model.getCurrentDirectory() + 'data/beam');
  282. }
  283. function OnException(err) {
  284. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  285. }
  286. //////////////////////////////////////////////////////////////////////////
  287. // Callback Functions.
  288. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  289. function OnColorMap(){
  290. unit.form.colorMap.Show();
  291. }
  292. function OnLight(isLight){
  293. if(isLight){
  294. ui.canvas.lamp = true;
  295. ui.canvas.update();
  296. }else{
  297. ui.canvas.lamp = false;
  298. ui.canvas.update();
  299. }
  300. }
  301. function OnCanvasContentMenu(){
  302. if(ui.canvas.content_menu === 1){
  303. OnTransform(1);
  304. }
  305. if(ui.canvas.content_menu === 2){
  306. OnTransform(2);
  307. }
  308. if(ui.canvas.content_menu === 3){
  309. On3DPosition(1);
  310. }
  311. if(ui.canvas.content_menu === 4){
  312. On3DPosition(2);
  313. }
  314. if(ui.canvas.content_menu === 5){
  315. On3DPosition(3);
  316. }
  317. if(ui.canvas.content_menu === 6){
  318. On3DPosition(4);
  319. }
  320. if(ui.canvas.content_menu === 7){
  321. On3DPosition(5);
  322. }
  323. if(ui.canvas.content_menu === 8){
  324. On3DPosition(6);
  325. }
  326. }
  327. function OnCanvasRightClick(){
  328. ui.canvas.content_menu = [
  329. {
  330. name: '旋转',
  331. icon: 'bar10',
  332. id: 1
  333. },
  334. {
  335. name: '平移',
  336. icon: 'bar11',
  337. id: 2
  338. },
  339. {
  340. name: '-'
  341. },
  342. {
  343. name: 'YOX',
  344. icon: 'bar19',
  345. id: 3
  346. },
  347. {
  348. name: 'XOY',
  349. icon: 'bar20',
  350. id: 4
  351. },
  352. {
  353. name: 'ZOX',
  354. icon: 'bar21',
  355. id: 5
  356. },
  357. {
  358. name: 'XOZ',
  359. icon: 'bar22',
  360. id: 6
  361. },
  362. {
  363. name: 'ZOY',
  364. icon: 'bar23',
  365. id: 7
  366. },
  367. {
  368. name: 'YOZ',
  369. icon: 'bar24',
  370. id: 8
  371. }
  372. ];
  373. }
  374. function OnClear(){
  375. ui.canvas.db = null;
  376. }
  377. /*
  378. function OnHide(){
  379. comx.ply.hideShow(vtkContext.Interface(), workData, "mark", "mark", true);
  380. }*/
  381. function OnLoad(){
  382. return comx.ply.loadFiles(vtkContext.Interface(), postManage, model.getCurrentDirectory(), model.getCurrentDirectory() + '/data/modelAnsys/unitfcm5-0-1e-10-451');
  383. }
  384. function OnLoad1(){
  385. return comx.ply.loadFiles(vtkContext.Interface(), postManage, model.getCurrentDirectory(), model.getCurrentDirectory() + '/data/modelAnsys/danbianguding');
  386. }
  387. function OnLoad2(){
  388. return comx.ply.loadFiles(vtkContext.Interface(), postManage, model.getCurrentDirectory(), model.getCurrentDirectory() + '/data/modelAnsys/ziyouzhendong');
  389. }
  390. function OnRendererMoTi(idx, size){
  391. var res = comx.ply.rendererMoTi(vtkContext.Interface(), postManage, model.getCurrentDirectory(), idx, size);
  392. ui.canvas.update();
  393. return res;
  394. }
  395. function OnForceChange(idx){
  396. ui.cw_boundary_force_24.idx = idx;
  397. }
  398. function OnConChange(idx){
  399. ui.cw_boundary_constraint_25.idx = idx;
  400. }
  401. function OnCut(x, y, z, xn, yn, zn){
  402. comx.ply.cutters(vtkContext.Interface(), postManage, x, y, z, xn, yn, zn);
  403. }
  404. function OnRGBMap4(r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4, r5, g5, b5){
  405. comx.ply.colorRGBS4(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2, r3, g3, b3, r4, g4, b4, r5, g5, b5);
  406. }
  407. function OnRGBMap3(r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4){
  408. comx.ply.colorRGBS3(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2, r3, g3, b3, r4, g4, b4);
  409. }
  410. function OnRGBMap2(r1, g1, b1, r2, g2, b2, r3, g3, b3){
  411. comx.ply.colorRGBS2(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2, r3, g3, b3);
  412. }
  413. function OnRGBMap1(r1, g1, b1, r2, g2, b2){
  414. comx.ply.colorRGBS1(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2);
  415. }
  416. function OnMotifyMarks(x, y, z, r, g, b, size, mark, name){
  417. comx.ply.modifyMarks(vtkContext.Interface(), workData, x, y, z, r, g, b, size, mark, name);
  418. }
  419. function OnSetMarks(x, y, z, r, g, b, size, mark, name){
  420. comx.ply.setMarks(vtkContext.Interface(), workData, x, y, z, r, g, b, size, mark, name);
  421. }
  422. function OnSetChangePost(attribute){
  423. comx.ply.setChangeData(vtkContext.Interface(), postManage, attribute);
  424. ui.canvas.update();
  425. }
  426. function OnPostBar(attribute, isBar){
  427. comx.ply.setPostBars(vtkContext.Interface(), postManage, attribute, isBar);
  428. ui.canvas.update();
  429. }
  430. function OnGenerateGuass(id){
  431. var res = comx.ply.generateBreps(vtkContext.Interface(), workData, id, model.getCurrentDirectory());
  432. ui.canvas.update();
  433. return res;
  434. }
  435. function OnGetName(){
  436. return comx.ply.getCurrentActorName(vtkContext.Interface(), workData);
  437. }
  438. function mousePick(type){
  439. if(type === "points"){
  440. comx.ply.mousePick(vtkContext.Interface(), workData, "points");
  441. }
  442. }
  443. function OnRenders(path, rate){
  444. comx.ply.renderer(vtkContext.Interface(), postManage, path, rate);
  445. ui.canvas.update();
  446. }
  447. function OnModifySpheres(x, y, z, radius, name){
  448. var res = comx.ply.modifySpheres(vtkContext.Interface(), workData, parseFloat(x), parseFloat(y), parseFloat(z), parseFloat(radius), name);
  449. ui.canvas.update();
  450. return res;
  451. }
  452. function OnSpheres(x, y, z, radius, name){
  453. var res = comx.ply.setSpheres(vtkContext.Interface(), workData, parseFloat(x), parseFloat(y), parseFloat(z), parseFloat(radius), name);
  454. ui.canvas.update();
  455. return res;
  456. }
  457. function OnModifyConnects(x, y, z, X, Y, Z, r, g, b, name){
  458. var res = comx.ply.modifyConnects(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  459. ui.canvas.update();
  460. return res;
  461. }
  462. function OnConnects(x, y, z, X, Y, Z, r, g, b, name){
  463. var res = comx.ply.setConnects(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  464. ui.canvas.update();
  465. return res;
  466. }
  467. function OnModifySpring(x, y, z, X, Y, Z, r, g, b, name){
  468. var res = comx.ply.modifySprings(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  469. ui.canvas.update();
  470. return res;
  471. }
  472. function OnSpring(x, y, z, X, Y, Z, r, g, b, name){
  473. var res = comx.ply.setSprings(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name);
  474. ui.canvas.update();
  475. return res;
  476. }
  477. function OnPic(){
  478. comx.ply.pickup(vtkContext.Interface(), workData, "points", 0);
  479. ui.canvas.update();
  480. }
  481. function OnModifyBeams(seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name){
  482. var res = comx.ply.modifyBeams(vtkContext.Interface(), workData, seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name);
  483. ui.canvas.update();
  484. return res;
  485. }
  486. function OnBeams(seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name){
  487. var res = comx.ply.setBeams(vtkContext.Interface(), workData, seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name);
  488. ui.canvas.update();
  489. return res;
  490. }
  491. function OnModifyConstrains(x, y, z, name){
  492. var res = comx.ply.modifyConstraints(vtkContext.Interface(), workData, x, y, z, name);
  493. ui.canvas.update();
  494. return res;
  495. }
  496. function OnConstrains(x, y, z, name){
  497. var res = comx.ply.setConstraints(vtkContext.Interface(), workData, x, y, z, name);
  498. ui.canvas.update();
  499. return res;
  500. }
  501. function OnModifyArrows(x, y, z, xn, yn, zn, name){
  502. var res = comx.ply.modifyArrows(vtkContext.Interface(), workData, x, y, z, xn, yn, zn, name);
  503. ui.canvas.update();
  504. return res;
  505. }
  506. function OnArrows(x, y, z, xn, yn, zn, name){
  507. var res = comx.ply.setArrows(vtkContext.Interface(), workData, x, y, z, xn, yn, zn, name);
  508. ui.canvas.update();
  509. return res;
  510. }
  511. function OnModifyPoints(x, y, z, radius, name){
  512. comx.ply.modifyPoints(vtkContext.Interface(), workData, x, y, z, radius, name);
  513. ui.canvas.update();
  514. }
  515. function OnSetPoints(x, y, z, radius, name){
  516. comx.ply.setPoints(vtkContext.Interface(), workData, x, y, z, radius, name);
  517. ui.canvas.update();
  518. }
  519. function OnMat(){
  520. comx.ply.mousePick(vtkContext.Interface(), workData, "beams_point");
  521. ui.pb_Points.valid = false;
  522. ui.pb_beam.valid = true;
  523. }
  524. function setExecs(index){
  525. ui.cw_solve_setup.exec = index;
  526. }
  527. function OnWindowVisible(idx){
  528. ui.stack_menu.visible = idx;
  529. ui.stack_switch.visible = idx;
  530. }
  531. function OnChangePicture(id, value){
  532. if(id === 1){
  533. if(value === 1){
  534. ui.pc_geo.value = model.getPicturePath('蓝灰色.png');
  535. }else if(value === 2){
  536. ui.pc_geo.value = model.getPicturePath('绿色.png');
  537. }else if(value === 3){
  538. ui.pc_geo.value = model.getPicturePath('红色.png');
  539. }
  540. }else if(id === 2){
  541. if(value === 1){
  542. ui.pc_mat.value = model.getPicturePath('蓝灰色.png');
  543. }else if(value === 2){
  544. ui.pc_mat.value = model.getPicturePath('绿色.png');
  545. }else if(value === 3){
  546. ui.pc_mat.value = model.getPicturePath('红色.png');
  547. }
  548. }else if(id === 3){
  549. if(value === 1){
  550. ui.pc_bou.value = model.getPicturePath('蓝灰色.png');
  551. }else if(value === 2){
  552. ui.pc_bou.value = model.getPicturePath('绿色.png');
  553. }else if(value === 3){
  554. ui.pc_bou.value = model.getPicturePath('红色.png');
  555. }
  556. }else if(id === 4){
  557. if(value === 1){
  558. ui.pc_sol.value = model.getPicturePath('蓝灰色.png');
  559. }else if(value === 2){
  560. ui.pc_sol.value = model.getPicturePath('绿色.png');
  561. }else if(value === 3){
  562. ui.pc_sol.value = model.getPicturePath('红色.png');
  563. }
  564. }else if(id === 5){
  565. if(value === 1){
  566. ui.pc_res.value = model.getPicturePath('蓝灰色.png');
  567. }else if(value === 2){
  568. ui.pc_res.value = model.getPicturePath('绿色.png');
  569. }else if(value === 3){
  570. ui.pc_res.value = model.getPicturePath('红色.png');
  571. }
  572. }
  573. }
  574. function OnCueline(msg, color){
  575. let real_color = 'black';
  576. if(color){real_color = color;}
  577. if(!msg) {
  578. ui.cueline.value = "";
  579. return;
  580. }
  581. ui.cueline.value = `<span style=\"color:black\"><u><b>提示信息</b></u>:</span><span style="color:${real_color}">${msg}</span>`;// + msg;
  582. }
  583. function OnPoints(){
  584. //OnSend('pointsCoord');
  585. comx.ply.mousePick(vtkContext.Interface(), workData, "points");
  586. ui.pb_Points.valid = true;
  587. ui.pb_beam.valid = false;
  588. }
  589. function OnMaterial(){
  590. ui.stack_menu.index = 19;
  591. console.log(22);
  592. }
  593. function OnFalseOpacity(){
  594. comx.ply.openCloseOpacity(vtkContext.Interface(), postManage, false);
  595. }
  596. function OnOpacity(){
  597. comx.ply.openCloseOpacity(vtkContext.Interface(), postManage, true);
  598. }
  599. function OnFaceCanvas(){
  600. ui.canvas.filter = [2025]; //面
  601. if (ui.canvas.view()) {
  602. ui.canvas.view().setColor(0.5, 0.5, 0.5, 0.2);
  603. ui.canvas.view().setVisible(true);
  604. ui.canvas.view().setBlend(false);
  605. }
  606. }
  607. function OnLineCanvas(){
  608. ui.canvas.filter = [2025]; //面
  609. if (ui.canvas.view()) {
  610. //ui.canvas.view().setColor(1.0, 1.0, 0.0, 0.0);
  611. ui.canvas.view().setVisible(true);
  612. ui.canvas.view().setBlend(true);
  613. }
  614. }
  615. function OnHightFace(idx){
  616. ui.canvas.view([ui.canvas.generateKey(2025, parseInt(idx))]).setColor(1.0, 0.0, 0.0);
  617. }
  618. function OnSetProp(index){
  619. ui.prop.visible = true;
  620. ui.prop.value = parseFloat(index);
  621. if(parseFloat(index) === 100){
  622. ui.prop.visible = false;
  623. }
  624. }
  625. function OnGetBeam(idx){
  626. myArray.push(idx);
  627. ui.cw_boundary_spring.beam = myArray;
  628. }
  629. function OnDeleteBeam(idx){
  630. myArray.splice(idx, 1);
  631. ui.cw_boundary_spring.beam = myArray;
  632. }
  633. function OnModuleChange(idx){
  634. ui.stack_switch.index = parseInt(idx);
  635. }
  636. function OnTransform(idx) {
  637. //ui.pb_pan.valid = ui.pb_rotate.valid = ui.pb_zoom.valid = ui.pb_zoom_window.valid = false;
  638. if (idx === 1) {
  639. ui.canvas.sensor = GL.Sensor.Rotate;
  640. //ui.pb_pan.valid = true;
  641. //ui.canvas.sensor = GL.Sensor.Pan;
  642. }
  643. if (idx === 2) {
  644. ui.canvas.sensor = GL.Sensor.Pan;
  645. //ui.canvas.sensor = GL.Sensor.Rotate;
  646. //ui.pb_rotate.valid = true;
  647. }
  648. if (idx === 3) {
  649. //ui.canvas.sensor = GL.Sensor.Scale;
  650. ui.pb_zoom.valid = true;
  651. }
  652. if (idx === 4) {
  653. //ui.canvas.sensor = GL.Sensor.RectScale;
  654. ui.pb_zoom_window.valid = true;
  655. }
  656. }
  657. function On3DPosition(idx) {
  658. //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;
  659. if (idx === 1) {
  660. //ui.pb_yox.valid = true;
  661. ui.canvas.sensor = GL.Sensor.YOX;
  662. }
  663. if (idx === 2) {
  664. //ui.pb_xoy.valid = true;
  665. ui.canvas.sensor = GL.Sensor.XOY;
  666. }
  667. if (idx === 3) {
  668. //ui.pb_zoy.valid = true;
  669. ui.canvas.sensor = GL.Sensor.ZOY;
  670. }
  671. if (idx === 4) {
  672. //ui.pb_yoz.valid = true;
  673. ui.canvas.sensor = GL.Sensor.YOZ;
  674. }
  675. if (idx === 5) {
  676. //ui.pb_xoz.valid = true;
  677. ui.canvas.sensor = GL.Sensor.XOZ;
  678. }
  679. if (idx === 6) {
  680. //ui.pb_zox.valid = true;
  681. ui.canvas.sensor = GL.Sensor.ZOX;
  682. }
  683. }
  684. //用树id取出真实id
  685. function findRIdById(jsonData, targetId) {
  686. let result = null; // 存储结果
  687. function traverse(node) {
  688. // 如果当前节点的 id 匹配目标值,记录其 r_id
  689. if (node.id === targetId) {
  690. result = node.r_id;
  691. return; // 提前结束递归
  692. }
  693. // 如果有子节点,则递归遍历子节点
  694. if (node.children && Array.isArray(node.children)) {
  695. for (let child of node.children) {
  696. traverse(child);
  697. if (result !== null) {return;} // 如果已找到,停止遍历
  698. }
  699. }
  700. }
  701. traverse(jsonData); // 开始遍历
  702. return result; // 返回结果或 null
  703. }
  704. //将真实id转换为对应树id
  705. function findNodeIdByRId(jsonData, targetRId) {
  706. let result = null; // 用于存储找到的节点的 id
  707. function traverse(node) {
  708. // 如果当前节点的 r_id 与目标值匹配,记录其 id
  709. if (node.r_id === targetRId) {
  710. result = node.id;
  711. return; // 提前结束当前递归
  712. }
  713. // 如果有子节点,则递归遍历子节点
  714. if (node.children && Array.isArray(node.children)) {
  715. for (let child of node.children) {
  716. traverse(child);
  717. if (result !== null) {return;} // 如果已经找到,停止遍历
  718. }
  719. }
  720. }
  721. traverse(jsonData); // 开始遍历
  722. return result; // 返回找到的 id 或 null
  723. }
  724. function OnPickUp() {
  725. if (!ui.canvas.hits) {
  726. return;
  727. }
  728. //放brep路径
  729. var rec = ui.canvas.hits[0];
  730. var key = rec.keyRecord;
  731. var keyObj = ui.canvas.parseKey(key);
  732. console.log("keyObj", keyObj);
  733. let id = findNodeIdByRId(model.acax_app.model.project.GetModel().pro_model, keyObj.sid);
  734. console.log("id", id);
  735. var path = model.getCurrentDirectory() + "data/brep/face" + id + ".brep";
  736. comx.occio.GetFaceBrep(comx.occore.GetEntryEx(), keyObj.sid, path);
  737. var facName = "type:F 0 " + id + " " + comx.occio.GetFacePoint(comx.occore.GetEntryEx(), keyObj.sid);
  738. OnSetFaceName(facName);
  739. let brep = {
  740. "brep":path.replace(/\\/g, "/")
  741. } ;
  742. unit.form.tree.SetBrepFile(brep);
  743. }
  744. function GetBrepPath() {
  745. return brep_path;
  746. }
  747. var faceName;
  748. function OnSetFaceName(input){
  749. faceName = input;
  750. }
  751. function OnGetFaceName(){
  752. return faceName;
  753. }
  754. var isPick = false;
  755. var color_face = "";
  756. function GetFlag() {
  757. return !isPick;
  758. }
  759. function pick(idx) {
  760. isPick = !isPick;
  761. let cur_proj = model.acax_app.view.GetCurrentProjectIndex();
  762. color_face = unit.form.tree.GetColorFace();
  763. unit.form.tree.Light3DFace(cur_proj, 11);
  764. ui.pb_pick.valid = isPick;
  765. if(isPick){
  766. ui.canvas.picker = {
  767. mode: GL.Picker.Mode.Single,
  768. autoHighlight: true,
  769. behavior: GL.Picker.Behavior.Point
  770. };
  771. }else{
  772. ui.canvas.picker = {
  773. mode: GL.Picker.Mode.Multi,
  774. autoHighlight: true,
  775. behavior: GL.Picker.Behavior.None
  776. };
  777. }
  778. }
  779. function OnChangeWindows(Idx){
  780. if(Idx === 1){
  781. ui.pb_window.index = 0;
  782. }
  783. if(Idx === 2){
  784. ui.pb_window.index = 1;
  785. }
  786. }
  787. function OnOpenSTL(){
  788. var fname = ui.OpenFileDialog("Import File", unit.dir + 'data/', "Stl Files(*.stl *.STL)");
  789. ui.cw_boundary_STL.path = fname;
  790. }
  791. function OnSend(Idx) {
  792. //console.log(33);
  793. if (g_io) {
  794. g_io.send(Idx);
  795. }
  796. }
  797. function OnOpenFile(fname) {
  798. //console.log(1000);
  799. if (fname) {
  800. //console.log(fname);
  801. model.execs(model.getCurrentDirectory() + "/src/generateBrep/generateBrep.exe " + fname + " " + model.getCurrentDirectory(), cb => {
  802. console.log(cb);
  803. });
  804. var is_step = (fname.indexOf('.STEP') !== -1) ||
  805. (fname.indexOf('.step') !== -1) ||
  806. (fname.indexOf('.STP') !== -1) ||
  807. (fname.indexOf('.stp') !== -1);
  808. var is_nas = (fname.indexOf('.nas') !== -1) || (fname.indexOf('.NAS') !== -1);
  809. model.wait();
  810. ui.canvas.db = null;
  811. parent.setTimeout(() => {
  812. if (is_step) {
  813. console.time('Global Step Load');
  814. ui.canvas.step = fname;
  815. console.timeEnd('Global Step Load');
  816. } else if (is_nas) {
  817. console.time('Global Nastran Load');
  818. ui.canvas.nastran = fname;
  819. console.timeEnd('Global Nastran Load');
  820. SetCanvasProp();
  821. } else {
  822. console.time('Global Iges Load');
  823. ui.canvas.iges = fname;
  824. console.timeEnd('Global Iges Load');
  825. }
  826. SetCanvasProp();
  827. ui.canvas.lamp = true;
  828. model.stop();
  829. }, 100);
  830. }
  831. ui.cw_geometry_check.path = fname;
  832. }
  833. function OnChangeValue(idx){
  834. menu(idx);
  835. }
  836. function menu(Idx) {
  837. ui.stack_menu.index = parseInt(Idx);
  838. }
  839. function OnChangeIndex(idx){
  840. ui.geo.index = idx;
  841. }
  842. function changeConstrain(index1, index2){
  843. if(index1 === 1){
  844. ui.cw_boundary_constraint_25.change1 = index2;
  845. }
  846. if(index1 === 2){
  847. ui.cw_boundary_constraint_25.change2 = index2;
  848. }
  849. if(index1 === 3){
  850. ui.cw_boundary_force_24.index = index2;
  851. }
  852. }
  853. //The message corresponding callback executed by the main form
  854. // when calling pui.fireEvent(type,para) in the Docker subform.
  855. function OnChildDockerMessage(type, para){
  856. }
  857. //////////////////////////////////////////////////////////////////////////
  858. // Utils Functions.
  859. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  860. function onDragFile(filepath) {
  861. }
  862. /*Usage of BLOCK_EVENT
  863. BLOCK_EVENT(()=>{
  864. ui.[name].[var] = ...;
  865. });
  866. */
  867. function BLOCK_EVENT(cb) {
  868. ui.block_event = true;
  869. cb();
  870. ui.block_event = false;
  871. }