tree_pane.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. ////////////////////////////////////////////////////////////////////////////
  2. // System Pre-define Functions
  3. // 95099372-ef3e-11ea-9c81-bf848405c62e
  4. //Callback of data preparation stage before UI is fully loaded.
  5. //dcip节点和模型树节点对应值
  6. var g_cur_id2index_cache = {};
  7. var g_cur_index2id_cache = {};
  8. function OnInitializeData(reload, preview) {
  9. PUI(()=>{
  10. //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
  11. //The 'pui' variable is valid in all functions of this document.
  12. //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
  13. });
  14. ui.tree_menu.index = 2;
  15. }
  16. //Callback after UI is fully loaded and displayed.
  17. function OnReady(reload, preview) {
  18. PUI(()=>{
  19. //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
  20. //The 'pui' variable is valid in all functions of this document.
  21. //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
  22. });
  23. }
  24. function OnCloseForm() {
  25. }
  26. function OnException(err) {
  27. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  28. }
  29. var options = true;
  30. let myArray = [];
  31. //////////////////////////////////////////////////////////////////////////
  32. // Callback Functions.
  33. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  34. //修改约束属性的名字
  35. function ModifyConstraintName(new_name) {
  36. let cur_name = model.acax_app.model.constrain.Current();
  37. let flag = model.acax_app.control.constrain.Rename(cur_name, new_name);
  38. let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  39. let cur_id;
  40. if(flag === true) {
  41. unit.form.mainfrm.OnCueline('修改成功', 'green');
  42. }else{
  43. unit.form.mainfrm.OnCueline('修改失败', 'red');
  44. }
  45. model.acax_app.view.RenderTree(() => {
  46. g_cur_id2index_cache = {};
  47. g_cur_index2id_cache = {};
  48. }, info=>{
  49. let id2index = g_cur_id2index_cache;
  50. let index2id = g_cur_index2id_cache;
  51. let index = info.index;
  52. let id = info.id;
  53. if(index) {
  54. id2index[id] = index;
  55. index2id[index] = id;
  56. }
  57. if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
  58. cur_id = info.id;
  59. }
  60. return {
  61. name : info.name,
  62. icon : info.icon,
  63. id : info.id,
  64. check_state : 0
  65. };
  66. },
  67. tree => {
  68. //从工程中获取保存的model数据
  69. if(model.acax_app.model.project.GetModel().pro_model){
  70. //获取当前工程的名字
  71. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  72. let pro_name = model.acax_app.path.Name(pro_Index);
  73. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  74. findAndAppendByName(tree, pro_name, cur_model);
  75. }
  76. //赋值给dcip的树结构
  77. ui.tree_Model.tree = tree;
  78. }
  79. );
  80. //渲染3d模型
  81. if(model.acax_app.model.project.GetModel().step === "unimported") {
  82. unit.form.mainfrm.ClearCanvas();
  83. }else{
  84. model.acax_app.view.Render3D(info=>{
  85. unit.form.mainfrm.OnloadModel(info.model3d.step);
  86. });
  87. }
  88. ui.tree_Model.position = cur_id;
  89. }
  90. //修改材料属性的名字
  91. function ModifyMaterialName(new_name) {
  92. let cur_name = model.acax_app.model.materialProp.Current();
  93. let flag = model.acax_app.control.materialProp.Rename(cur_name, new_name);
  94. let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  95. let cur_id;
  96. if(flag === true) {
  97. unit.form.mainfrm.OnCueline('修改成功', 'green');
  98. }else{
  99. unit.form.mainfrm.OnCueline('修改失败', 'red');
  100. }
  101. model.acax_app.view.RenderTree(() => {
  102. g_cur_id2index_cache = {};
  103. g_cur_index2id_cache = {};
  104. }, info=>{
  105. let id2index = g_cur_id2index_cache;
  106. let index2id = g_cur_index2id_cache;
  107. let index = info.index;
  108. let id = info.id;
  109. if(index) {
  110. id2index[id] = index;
  111. index2id[index] = id;
  112. }
  113. if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
  114. cur_id = info.id;
  115. }
  116. return {
  117. name : info.name,
  118. icon : info.icon,
  119. id : info.id,
  120. check_state : 0
  121. };
  122. },
  123. tree => {
  124. //从工程中获取保存的model数据
  125. if(model.acax_app.model.project.GetModel().pro_model){
  126. //获取当前工程的名字
  127. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  128. let pro_name = model.acax_app.path.Name(pro_Index);
  129. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  130. findAndAppendByName(tree, pro_name, cur_model);
  131. }
  132. //赋值给dcip的树结构
  133. ui.tree_Model.tree = tree;
  134. }
  135. );
  136. //渲染3d模型
  137. if(model.acax_app.model.project.GetModel().step === "unimported") {
  138. unit.form.mainfrm.ClearCanvas();
  139. }else{
  140. model.acax_app.view.Render3D(info=>{
  141. unit.form.mainfrm.OnloadModel(info.model3d.step);
  142. });
  143. }
  144. ui.tree_Model.position = cur_id;
  145. }
  146. //修改的工程名
  147. function ModifyProName(new_name) {
  148. let cur_name = model.acax_app.path.Name(model.acax_app.view.GetCurrentProjectIndex());
  149. model.acax_app.model.project.Rename(cur_name, new_name);
  150. let cur_index = model.acax_app.view.GetCurrentWorkAreaIndex();
  151. let cur_id;
  152. model.acax_app.view.RenderTree(() => {
  153. g_cur_id2index_cache = {};
  154. g_cur_index2id_cache = {};
  155. }, info=>{
  156. let id2index = g_cur_id2index_cache;
  157. let index2id = g_cur_index2id_cache;
  158. let index = info.index;
  159. let id = info.id;
  160. if(index) {
  161. id2index[id] = index;
  162. index2id[index] = id;
  163. }
  164. if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 0) === cur_index)) {
  165. cur_id = info.id;
  166. }
  167. return {
  168. name : info.name,
  169. icon : info.icon,
  170. id : info.id,
  171. check_state : 0
  172. };
  173. },
  174. tree => {
  175. //从工程中获取保存的model数据
  176. if(model.acax_app.model.project.GetModel().pro_model){
  177. //获取当前工程的名字
  178. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  179. let pro_name = model.acax_app.path.Name(pro_Index);
  180. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  181. findAndAppendByName(tree, pro_name, cur_model);
  182. }
  183. //赋值给dcip的树结构
  184. ui.tree_Model.tree = tree;
  185. }
  186. );
  187. //渲染3d模型
  188. if(model.acax_app.model.project.GetModel().step === "unimported") {
  189. unit.form.mainfrm.ClearCanvas();
  190. }else{
  191. model.acax_app.view.Render3D(info=>{
  192. unit.form.mainfrm.OnloadModel(info.model3d.step);
  193. });
  194. }
  195. ui.tree_Model.position = cur_id;
  196. }
  197. //处理字符串截掉后五位
  198. function removeLastFiveCharacters(str) {
  199. str = String(str);
  200. if (str.length <= 5) {
  201. return ''; // 如果字符串长度小于等于 5,则返回空字符串
  202. }
  203. return str.substring(0, str.length - 5); // 提取从 0 到倒数第 5 位的子字符串
  204. }
  205. //点击弹出菜单
  206. function OnContentClick(){
  207. //获取一级子节点
  208. let str = removeLastFiveCharacters(ui.tree_Model.content_menu);
  209. let model_id = g_cur_id2index_cache[str];
  210. //let cur_name = model.acax_app.path.Name(model_id);
  211. switch (model.acax_app.path.Type(model_id)){
  212. case 2:
  213. unit.form.Rename.Show();
  214. break;
  215. case 3:
  216. break;
  217. case 4:
  218. unit.form.RenameConstraint.Show();
  219. break;
  220. case 5:
  221. unit.form.RenameMaterial.Show();
  222. break;
  223. default:
  224. break;
  225. }
  226. }
  227. //右键单击树效果
  228. function OnRightClick(){
  229. //console.log(ui.tree_Model.position);
  230. let model_id = g_cur_id2index_cache[ui.tree_Model.position];
  231. switch (model.acax_app.path.Type(model_id)){
  232. case 2:
  233. ui.tree_Model.content_menu =[{
  234. "name":"重命名",
  235. "icon":"",
  236. "id":ui.tree_Model.position + "13579"
  237. }];
  238. break;
  239. case 3:
  240. break;
  241. case 4:
  242. ui.tree_Model.content_menu =[{
  243. "name":"重命名",
  244. "icon":"",
  245. "id":ui.tree_Model.position + "13579"
  246. }];
  247. break;
  248. case 5:
  249. ui.tree_Model.content_menu =[{
  250. "name":"重命名",
  251. "icon":"",
  252. "id":ui.tree_Model.position + "13579"
  253. }];
  254. break;
  255. default:
  256. break;
  257. }
  258. }
  259. //点击树
  260. function OnClickTree(){
  261. //获取模型树的对应节点
  262. console.log(ui.tree_Model.position);
  263. let model_id = g_cur_id2index_cache[ui.tree_Model.position];
  264. let cur_workarea = model.acax_app.view.GetCurrentWorkAreaIndex();
  265. let cur_proj = model.acax_app.view.GetCurrentProjectIndex();
  266. let cur_workcondition = model.acax_app.view.GetCurrentWorkConditionIndex();
  267. model.acax_app.view.RenderNode(model_id, info => {
  268. console.log(info);
  269. });
  270. switch (model.acax_app.path.Type(model_id)) {
  271. //切换工作区
  272. case 0:
  273. //不是当前工作区,切换工作区
  274. if(model_id !== cur_workarea){
  275. model.acax_app.view.RenderNode(model_id, info => {
  276. OpenWorkArea(info.prop);
  277. //切换到当前工作区
  278. ui.tree_Model.position = g_cur_index2id_cache[model_id];
  279. });
  280. }
  281. break;
  282. //选中材料库
  283. case 1:
  284. break;
  285. //切换工程
  286. case 2:
  287. //不是当前工程,切换工程
  288. if(model_id !== cur_proj){
  289. model.acax_app.view.RenderNode(model_id, info => {
  290. ChangePro(model.acax_app.path.Name(model_id));
  291. //切换到当前工程
  292. ui.tree_Model.position = g_cur_index2id_cache[model_id];
  293. });
  294. }
  295. break;
  296. //切换工况
  297. case 3:
  298. //不是当前工况,切换工况
  299. if(model_id !== cur_workcondition){
  300. model.acax_app.view.RenderNode(model_id, info => {
  301. console.log(model.acax_app.path.Name(model_id)) ;
  302. ChangeWorkCondition(model.acax_app.path.Name(model_id));
  303. //切换到当前工况
  304. ui.tree_Model.position = g_cur_index2id_cache[model_id];
  305. });
  306. }
  307. break;
  308. //选中约束
  309. case 4:
  310. model.acax_app.view.RenderNode(model_id, info => {
  311. //切换到当前约束
  312. model.acax_app.model.constrain.SwitchTo(model.acax_app.path.Name(model_id));
  313. //将约束属性设置到对应面板
  314. ChangeConstraint(Object.values(info.prop)[0], info.prop);
  315. //切换点击约束
  316. ui.tree_Model.position = g_cur_index2id_cache[model_id];
  317. });
  318. break;
  319. //选中材料属性
  320. case 5:
  321. model.acax_app.view.RenderNode(model_id, info => {
  322. //切换当前材料
  323. model.acax_app.model.materialProp.SwitchTo(model.acax_app.path.Name(model_id));
  324. unit.form.mainfrm.menu(3);
  325. unit.form.mainfrm.OnChangePicture(2, 1);
  326. unit.form.mainfrm.OnCueline('结构静力学材料设置', 'blue');
  327. //将材料属性设置到面板
  328. unit.form.mainfrm.setMaterial(info.prop);
  329. //切换到点击材料
  330. ui.tree_Model.position = g_cur_index2id_cache[model_id];
  331. });
  332. break;
  333. default:
  334. break;
  335. }
  336. }
  337. //切换约束面板
  338. function ChangeConstraint(constraint_name, prop) {
  339. let constraint = {
  340. "固定支撑":function(){
  341. unit.form.mainfrm.menu(18);
  342. unit.form.mainfrm.changeConstrain(1, 0);
  343. unit.form.mainfrm.setConstraint(prop);
  344. },
  345. "梁":function(){
  346. unit.form.mainfrm.menu(18);
  347. unit.form.mainfrm.changeConstrain(1, 1);
  348. unit.form.mainfrm.changeConstrain(2, 0);
  349. unit.form.mainfrm.setConstraint(prop);
  350. },
  351. "弹簧":function(){
  352. unit.form.mainfrm.menu(18);
  353. unit.form.mainfrm.changeConstrain(1, 1);
  354. unit.form.mainfrm.changeConstrain(2, 1);
  355. unit.form.mainfrm.setConstraint(prop);
  356. },
  357. "连接":function(){
  358. unit.form.mainfrm.menu(18);
  359. unit.form.mainfrm.changeConstrain(1, 1);
  360. unit.form.mainfrm.changeConstrain(2, 2);
  361. unit.form.mainfrm.setConstraint(prop);
  362. },
  363. "梁(非均匀)":function(){
  364. },
  365. "集中载荷压力":function(){
  366. unit.form.mainfrm.menu(17);
  367. unit.form.mainfrm.changeConstrain(3, 0);
  368. unit.form.mainfrm.setConstraint(prop);
  369. },
  370. "分布载荷压力":function(){
  371. unit.form.mainfrm.menu(17);
  372. unit.form.mainfrm.changeConstrain(3, 1);
  373. unit.form.mainfrm.setConstraint(prop);
  374. }
  375. };
  376. constraint[constraint_name]();
  377. }
  378. //测试函数
  379. function OnTest(){
  380. // console.log(model.acax_app.path.Name(g_cur_id2index_cache["131"]));
  381. //console.log(g_cur_id2index_cache);
  382. // console.log(g_cur_index2id_cache);
  383. }
  384. //切换工作区
  385. function OpenWorkArea(fname) {
  386. fname = fname.replace(/\/+/g, "\\");
  387. var work_path = model.acax_app.model.workArea.List();
  388. //渲染模型树
  389. for(var i = 0;i < work_path.length;++i) {
  390. work_path[i] = work_path[i].replace(/\/+/g, "\\");
  391. if(fname === work_path[i]){
  392. model.acax_app.control.workArea.SwitchTo(i);
  393. model.acax_app.view.RenderTree(() => {
  394. g_cur_id2index_cache = {};
  395. g_cur_index2id_cache = {};
  396. }, info=>{
  397. let id2index = g_cur_id2index_cache;
  398. let index2id = g_cur_index2id_cache;
  399. let index = info.index;
  400. let id = info.id;
  401. if(index) {
  402. id2index[id] = index;
  403. index2id[index] = id;
  404. }
  405. return {
  406. name : info.name,
  407. icon : info.icon,
  408. id : info.id,
  409. check_state : 0
  410. };
  411. },
  412. tree => {
  413. //从工程中获取保存的model数据
  414. if(model.acax_app.model.project.GetModel().pro_model){
  415. //获取当前工程的名字
  416. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  417. let pro_name = model.acax_app.path.Name(pro_Index);
  418. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  419. findAndAppendByName(tree, pro_name, cur_model);
  420. }
  421. //赋值给dcip的树结构
  422. ui.tree_Model.tree = tree;
  423. }
  424. );
  425. }
  426. }
  427. //渲染3d模型
  428. if(model.acax_app.model.project.GetModel().step === "unimported") {
  429. unit.form.mainfrm.ClearCanvas();
  430. }else{
  431. model.acax_app.view.Render3D(info=>{
  432. unit.form.mainfrm.OnloadModel(info.model3d.step);
  433. });
  434. }
  435. }
  436. //切换工程
  437. function ChangePro(pro_name) {
  438. model.acax_app.control.project.SwitchTo(pro_name);
  439. model.acax_app.view.RenderTree(() => {
  440. g_cur_id2index_cache = {};
  441. g_cur_index2id_cache = {};
  442. }, info=>{
  443. let id2index = g_cur_id2index_cache;
  444. let index2id = g_cur_index2id_cache;
  445. let index = info.index;
  446. let id = info.id;
  447. if(index) {
  448. id2index[id] = index;
  449. index2id[index] = id;
  450. }
  451. return {
  452. name : info.name,
  453. icon : info.icon,
  454. id : info.id,
  455. check_state : 0
  456. };
  457. },
  458. tree => {
  459. //从工程中获取保存的model数据
  460. if(model.acax_app.model.project.GetModel().pro_model){
  461. //获取当前工程的名字
  462. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  463. let pro_name = model.acax_app.path.Name(pro_Index);
  464. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  465. findAndAppendByName(tree, pro_name, cur_model);
  466. }
  467. //赋值给dcip的树结构
  468. ui.tree_Model.tree = tree;
  469. }
  470. );
  471. //渲染3d模型
  472. if(model.acax_app.model.project.GetModel().step === "unimported") {
  473. unit.form.mainfrm.ClearCanvas();
  474. }else{
  475. model.acax_app.view.Render3D(info=>{
  476. unit.form.mainfrm.OnloadModel(info.model3d.step);
  477. });
  478. }
  479. }
  480. //切换工况
  481. function ChangeWorkCondition(wor_name) {
  482. model.acax_app.control.workCondition.SwitchTo(wor_name);
  483. model.acax_app.view.RenderTree(() => {
  484. g_cur_id2index_cache = {};
  485. g_cur_index2id_cache = {};
  486. }, info=>{
  487. let id2index = g_cur_id2index_cache;
  488. let index2id = g_cur_index2id_cache;
  489. let index = info.index;
  490. let id = info.id;
  491. if(index) {
  492. id2index[id] = index;
  493. index2id[index] = id;
  494. }
  495. return {
  496. name : info.name,
  497. icon : info.icon,
  498. id : info.id,
  499. check_state : 0
  500. };
  501. },
  502. tree => {
  503. //从工程中获取保存的model数据
  504. if(model.acax_app.model.project.GetModel().pro_model){
  505. //获取当前工程的名字
  506. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  507. let pro_name = model.acax_app.path.Name(pro_Index);
  508. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  509. findAndAppendByName(tree, pro_name, cur_model);
  510. }
  511. //赋值给dcip的树结构
  512. ui.tree_Model.tree = tree;
  513. }
  514. );
  515. //渲染3d模型
  516. if(model.acax_app.model.project.GetModel().step === "unimported") {
  517. unit.form.mainfrm.ClearCanvas();
  518. }else{
  519. model.acax_app.view.Render3D(info=>{
  520. unit.form.mainfrm.OnloadModel(info.model3d.step);
  521. });
  522. }
  523. }
  524. //创建工作区
  525. function CreateWorkArea(name) {
  526. model.acax_app.control.workArea.Append(name);
  527. let cur_id;
  528. model.acax_app.view.RenderTree(() => {
  529. g_cur_id2index_cache = {};
  530. g_cur_index2id_cache = {};
  531. }, info=>{
  532. let id2index = g_cur_id2index_cache;
  533. let index2id = g_cur_index2id_cache;
  534. let index = info.index;
  535. let id = info.id;
  536. if(index) {
  537. id2index[id] = index;
  538. index2id[index] = id;
  539. }
  540. if("workArea" === info.name) {
  541. cur_id = info.id;
  542. }
  543. return {
  544. name : info.name,
  545. icon : info.icon,
  546. id : info.id,
  547. check_state : 0
  548. };
  549. },
  550. tree=>{
  551. ui.tree_Model.tree = tree;
  552. });
  553. //渲染3d模型
  554. if(model.acax_app.model.project.GetModel().step === "unimported") {
  555. unit.form.mainfrm.ClearCanvas();
  556. }else{
  557. model.acax_app.view.Render3D(info=>{
  558. unit.form.mainfrm.OnloadModel(info.model3d.step);
  559. });
  560. }
  561. ui.tree_Model.position = cur_id;
  562. }
  563. //创建工程
  564. function CreateProject(name) {
  565. model.acax_app.control.project.Create(name);
  566. let cur_name = model.acax_app.model.project.Current();
  567. let cur_index = model.acax_app.view.GetCurrentWorkAreaIndex();
  568. let cur_id;
  569. model.acax_app.view.RenderTree(() => {
  570. g_cur_id2index_cache = {};
  571. g_cur_index2id_cache = {};
  572. }, info=>{
  573. let id2index = g_cur_id2index_cache;
  574. let index2id = g_cur_index2id_cache;
  575. let index = info.index;
  576. let id = info.id;
  577. if(index) {
  578. id2index[id] = index;
  579. index2id[index] = id;
  580. }
  581. if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 0) === cur_index)) {
  582. cur_id = info.id;
  583. }
  584. return {
  585. name : info.name,
  586. icon : info.icon,
  587. id : info.id,
  588. check_state : 0
  589. };
  590. },
  591. tree=>{
  592. ui.tree_Model.tree = tree;
  593. });
  594. //渲染3d模型
  595. if(model.acax_app.model.project.GetModel().step === "unimported") {
  596. unit.form.mainfrm.ClearCanvas();
  597. }else{
  598. model.acax_app.view.Render3D(info=>{
  599. unit.form.mainfrm.OnloadModel(info.model3d.step);
  600. });
  601. }
  602. ui.tree_Model.position = cur_id;
  603. }
  604. //导入模型
  605. function OnOpenStepFile() {
  606. var model_file = myArray[parseFloat(ui.listbox.index)];
  607. model.acax_app.control.ImportStep(model_file, (model_file, model_plyfile)=>{
  608. model.acax_app.view.Render3D(info=>{
  609. unit.form.mainfrm.OnloadModel(info.model3d.step);
  610. });
  611. // unit.form.mainfrm.OnSend('openSTLFile ' + model.getCurrentDirectory() + ' ' + myArray[parseFloat(ui.listbox.index)]);
  612. //unit.form.mainfrm.OnCueline(`Loading ${myArray[parseFloat(ui.listbox.index)]} ...`, 'Blue');
  613. //model.setStepPath(model_file);
  614. //console.log(model_file);
  615. }
  616. );
  617. }
  618. //插入新子节点
  619. function findAndAppendByName(json, targetName, newChild) {
  620. if (json.name === targetName) {
  621. // 拼接新的 JSON 数据
  622. if (!json.children) {
  623. json.children = [];
  624. }
  625. json.children.unshift(newChild);
  626. return true; // 找到后返回 true
  627. }
  628. // 遍历子节点递归查找
  629. if (json.children) {
  630. for (const child of json.children) {
  631. if (findAndAppendByName(child, targetName, newChild)) {
  632. return true; // 如果找到目标节点,结束递归
  633. }
  634. }
  635. }
  636. return false; // 没找到返回 false
  637. }
  638. //将模型的id值加密与模型树一一对应
  639. function printIds(node) {
  640. if (node.id !== undefined) {
  641. id2index[id] = model.acax_app.path.Path;
  642. }
  643. if (Array.isArray(node.children)) {
  644. node.children.forEach(child => printIds(child));
  645. }
  646. }
  647. //给面节点改名字并添加check_state属性
  648. function updateJsonNodes(jsonData) {
  649. let count = 1; // 用于计数生成 Face1, Face2...
  650. function traverse(node) {
  651. // 为每个节点添加 check_state: 2 属性
  652. node.check_state = 2;
  653. node.icon = '';
  654. // 如果存在 children 属性,则递归处理
  655. if (node.children && Array.isArray(node.children)) {
  656. for (let child of node.children) {
  657. traverse(child); // 递归遍历子节点
  658. }
  659. } else if (node.name && node.name.startsWith("Face_")) {
  660. // 修改 name 值为 Face1, Face2...
  661. node.name = `Face${count}`;
  662. count++;
  663. }
  664. }
  665. traverse(jsonData);
  666. return jsonData;
  667. }
  668. //查找模型的第一个节点值获取id
  669. function getFirstId(obj) {
  670. // 检查是否有 children 并提取第一个节点的 id
  671. if (obj.children && obj.children.length > 0) {
  672. return obj.children[0].id;
  673. }
  674. return null; // 如果没有子节点,返回 null
  675. }
  676. //导入模型树节点
  677. function OnTree(Idx){
  678. updateJsonNodes(Idx);
  679. model.acax_app.view.RenderTree(() => {
  680. g_cur_id2index_cache = {};
  681. g_cur_index2id_cache = {};
  682. }, info=>{
  683. let id2index = g_cur_id2index_cache;
  684. let index2id = g_cur_index2id_cache;
  685. let index = info.index;
  686. let id = info.id;
  687. if(index) {
  688. id2index[id] = index;
  689. index2id[index] = id;
  690. }
  691. return {
  692. name : info.name,
  693. icon : info.icon,
  694. id : info.id,
  695. check_state : 0
  696. };
  697. },
  698. tree => {
  699. //插入模型树节点与工程节点进行拼接
  700. let pro_Index= model.acax_app.view.GetCurrentProjectIndex();
  701. let pro_name = model.acax_app.path.Name(pro_Index);
  702. findAndAppendByName(tree, pro_name, Idx);
  703. //将模型树节点与工程节点拼接后保存到model中
  704. let pro_model = model.acax_app.model.project.GetModel();
  705. pro_model.pro_model = Idx;
  706. model.acax_app.model.project.SetModel(pro_model);
  707. ui.tree_Model.tree = tree;
  708. }
  709. );
  710. ui.tree_Model.position = getFirstId(Idx);
  711. }
  712. //创建工况
  713. function CreateWorkCondition(name){
  714. let condition_index = model.acax_app.control.workCondition.Create(name);
  715. let cur_name = model.acax_app.model.workCondition.Current();
  716. let cur_index = model.acax_app.view.GetCurrentProjectIndex();
  717. let cur_id;
  718. console.log(model.acax_app.path.Parent(cur_index, 2) === model.acax_app.view.GetCurrentProjectIndex());
  719. model.acax_app.view.RenderTree(() => {
  720. g_cur_id2index_cache = {};
  721. g_cur_index2id_cache = {};
  722. }, info=>{
  723. let id2index = g_cur_id2index_cache;
  724. let index2id = g_cur_index2id_cache;
  725. let index = info.index;
  726. let id = info.id;
  727. if(index) {
  728. id2index[id] = index;
  729. index2id[index] = id;
  730. }
  731. if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 2) === cur_index)) {
  732. cur_id = info.id;
  733. }
  734. return {
  735. name : info.name,
  736. icon : info.icon,
  737. id : info.id,
  738. check_state : 0
  739. };
  740. },
  741. tree => {
  742. //获取当前工程的名字
  743. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  744. let pro_name = model.acax_app.path.Name(pro_Index);
  745. //模型存在在加载
  746. if(model.acax_app.model.project.GetModel().pro_model) {
  747. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  748. findAndAppendByName(tree, pro_name, cur_model);
  749. }
  750. //赋值给dcip的树结构
  751. ui.tree_Model.tree = tree;
  752. }
  753. );
  754. ui.tree_Model.position = cur_id;
  755. }
  756. //创建材料属性
  757. function CreateMaterial(mat) {
  758. model.acax_app.control.materialProp.Create(mat);
  759. let cur_name = model.acax_app.model.materialProp.Current();
  760. let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  761. let cur_id;
  762. model.acax_app.view.RenderTree(() => {
  763. g_cur_id2index_cache = {};
  764. g_cur_index2id_cache = {};
  765. }, info=>{
  766. let id2index = g_cur_id2index_cache;
  767. let index2id = g_cur_index2id_cache;
  768. let index = info.index;
  769. let id = info.id;
  770. if(index) {
  771. id2index[id] = index;
  772. index2id[index] = id;
  773. }
  774. if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
  775. cur_id = info.id;
  776. }
  777. return {
  778. name : info.name,
  779. icon : info.icon,
  780. id : info.id,
  781. check_state : 0
  782. };
  783. },
  784. tree => {
  785. //获取当前工程的名字
  786. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  787. let pro_name = model.acax_app.path.Name(pro_Index);
  788. if(model.acax_app.model.project.GetModel().pro_model) {
  789. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  790. findAndAppendByName(tree, pro_name, cur_model);
  791. }
  792. //赋值给dcip的树结构
  793. ui.tree_Model.tree = tree;
  794. }
  795. );
  796. ui.tree_Model.position = cur_id;
  797. }
  798. //修改材料面板属性属性
  799. function ModifyMaterial(material) {
  800. //获取当前材料的名字
  801. let material_name = model.acax_app.model.materialProp.Current();
  802. model.acax_app.control.materialProp.Set(material, material_name);
  803. unit.form.mainfrm.OnCueline('修改成功', 'green');
  804. }
  805. //创建载荷
  806. function CreateBoundary(Load, name) {
  807. let load = model.acax_app.control.constrain.Create(Load, name);
  808. let cur_name = model.acax_app.model.constrain.Current();
  809. let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
  810. let cur_id;
  811. model.acax_app.view.RenderTree(() => {
  812. g_cur_id2index_cache = {};
  813. g_cur_index2id_cache = {};
  814. }, info=>{
  815. let id2index = g_cur_id2index_cache;
  816. let index2id = g_cur_index2id_cache;
  817. let index = info.index;
  818. let id = info.id;
  819. if(index) {
  820. id2index[id] = index;
  821. index2id[index] = id;
  822. }
  823. if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
  824. cur_id = info.id;
  825. }
  826. return {
  827. name : info.name,
  828. icon : info.icon,
  829. id : info.id,
  830. check_state : 0
  831. };
  832. },
  833. tree => {
  834. //获取当前工程的名字
  835. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  836. let pro_name = model.acax_app.path.Name(pro_Index);
  837. if(model.acax_app.model.project.GetModel().pro_model) {
  838. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  839. findAndAppendByName(tree, pro_name, cur_model);
  840. }
  841. //赋值给dcip的树结构
  842. ui.tree_Model.tree = tree;
  843. }
  844. );
  845. ui.tree_Model.position = cur_id;
  846. }
  847. //修改载荷面板属性
  848. function ModifyConstraint(constrain) {
  849. let constrain_name = model.acax_app.model.constrain.Current();
  850. model.acax_app.control.constrain.Set(constrain, constrain_name);
  851. unit.form.mainfrm.OnCueline('修改成功', 'green');
  852. }
  853. function OnMessage(idx){
  854. ui.cueline.value += idx + '\n';
  855. ui.cueline.row = -1;
  856. }
  857. function OnChangeMenu(Idx){
  858. ui.tree_menu.index = parseInt(Idx);
  859. }
  860. function OnDeleteFile() {
  861. myArray.splice(parseFloat(ui.listbox.index), 1);
  862. ui.listbox.list = [
  863. myArray
  864. ];
  865. }
  866. function OnOpenFile(){
  867. var fname = ui.OpenFileDialog("Import File", unit.dir + 'data/', "Step Files(*.step *.stp);;Iges Files(*.iges *.igs);;Nastran Files(*.nas)");
  868. model.write(fname, model.getCurrentDirectory() + '/data/address.txt');
  869. myArray.push(fname);
  870. ui.listbox.list = [
  871. myArray
  872. ];
  873. }
  874. function OnChangeOptions(){
  875. options = !options;
  876. ui.stack_options.visible = options;
  877. }
  878. function OnTopMenu(idx) {
  879. ui.stack_import.visible = true;
  880. ui.stack_import.index = parseInt(idx) - 1;
  881. ui.pb_import01.valid = ui.pb_import02.valid = ui.pb_import03.valid = ui.pb_import04.valid = ui.pb_import05.valid = false;
  882. //model.ide_info(idx);
  883. if (parseInt(idx) === 1) {
  884. ui.pb_import01.valid = true;
  885. }
  886. if (parseInt(idx) === 2) {
  887. ui.pb_import02.valid = true;
  888. }
  889. if (parseInt(idx) === 3) {
  890. ui.pb_import03.valid = true;
  891. }
  892. if (parseInt(idx) === 4) {
  893. ui.pb_import04.valid = true;
  894. }
  895. if (parseInt(idx) === 5) {
  896. ui.pb_import05.valid = true;
  897. }
  898. }
  899. //The message corresponding callback executed by the docker pane.
  900. // when calling [side_pane].fireEvent(type,para) in the main form.
  901. function OnParentDockerMessage(type, para) {
  902. }
  903. //////////////////////////////////////////////////////////////////////////
  904. // Utils Functions.
  905. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  906. function onDragFile(filepath) {
  907. }
  908. function PUI(cb) {
  909. if(pui){cb();}
  910. }
  911. /*Usage of BLOCK_EVENT
  912. BLOCK_EVENT(()=>{
  913. ui.[name].[var] = ...;
  914. });
  915. */
  916. function BLOCK_EVENT(cb) {
  917. ui.block_event = true;
  918. cb();
  919. ui.block_event = false;
  920. }
  921. //////////////////////////////////////////////////////////////////////////
  922. // template codes for cw callback js.
  923. function CW_DeclareVariable(name, setter, getter) {
  924. if(typeof(__DeclareVariable) === 'function') {
  925. __DeclareVariable(name, setter, getter);
  926. }
  927. }
  928. function CW_DeclareOuterVariable(name) {
  929. if(typeof(__DeclareOuterVariable) === 'function') {
  930. __DeclareOuterVariable(name);
  931. }
  932. }