mainfrm_pane.js 28 KB

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