tree_pane.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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. //导入工作区
  9. function OnInitializeData(reload, preview) {
  10. PUI(()=>{
  11. //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
  12. //The 'pui' variable is valid in all functions of this document.
  13. //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
  14. });
  15. ui.tree_menu.index = 2;
  16. }
  17. //Callback after UI is fully loaded and displayed.
  18. function OnReady(reload, preview) {
  19. PUI(()=>{
  20. //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
  21. //The 'pui' variable is valid in all functions of this document.
  22. //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
  23. });
  24. }
  25. function OnCloseForm() {
  26. }
  27. function OnException(err) {
  28. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  29. }
  30. var options = true;
  31. let myArray = [];
  32. //////////////////////////////////////////////////////////////////////////
  33. // Callback Functions.
  34. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  35. //点击树
  36. function OnClickTree(){
  37. //获取模型树的对应节点
  38. let model_id = g_cur_id2index_cache[ui.tree_Model.position];
  39. model.acax_app.view.RenderNode(model_id, info => {
  40. console.log(info);
  41. });
  42. switch (model.acax_app.path.Type(model_id)) {
  43. //切换工作区
  44. case 0:
  45. //不是当前工作区,切换工作区
  46. if(model_id !== cur_workarea){
  47. model.acax_app.view.RenderNode(model_id, info => {
  48. OpenWorkArea(info.prop);
  49. });
  50. }
  51. break;
  52. //选中材料库
  53. case 1:
  54. break;
  55. //切换工程
  56. case 2:
  57. //不是当前工程,切换工程
  58. if(model_id !== cur_proj){
  59. model.acax_app.view.RenderNode(model_id, info => {
  60. unit.form.physics_material.FindMateial(info.prop);
  61. });
  62. }
  63. break;
  64. //切换工况
  65. case 3:
  66. break;
  67. //选中约束
  68. case 4:
  69. break;
  70. //选中材料属性
  71. case 5:
  72. model.acax_app.view.RenderNode(model_id, info => {
  73. unit.form.mainfrm.menu(3);
  74. unit.form.mainfrm.OnChangePicture(2, 1);
  75. unit.form.mainfrm.OnCueline('结构静力学材料设置', 'blue');
  76. console.log(info.prop);
  77. unit.form.mainfrm.setMaterial(info.prop);
  78. });
  79. break;
  80. default:
  81. break;
  82. }
  83. }
  84. //测试函数
  85. function OnTest(){
  86. console.log(g_cur_id2index_cache);
  87. console.log(g_cur_index2id_cache);
  88. }
  89. //切换工作区
  90. function OpenWorkArea(fname) {
  91. fname = fname.replace(/\/+/g, "\\");
  92. var work_path = model.acax_app.model.workArea.List();
  93. //渲染模型树
  94. for(var i = 0;i < work_path.length;++i) {
  95. work_path[i] = work_path[i].replace(/\/+/g, "\\");
  96. if(fname === work_path[i]){
  97. model.acax_app.control.workArea.SwitchTo(i);
  98. model.acax_app.view.RenderTree(() => {
  99. g_cur_id2index_cache = {};
  100. g_cur_index2id_cache = {};
  101. }, info=>{
  102. let id2index = g_cur_id2index_cache;
  103. let index2id = g_cur_index2id_cache;
  104. let index = info.index;
  105. let id = info.id;
  106. if(index) {
  107. id2index[id] = index;
  108. index2id[index] = id;
  109. }
  110. console.log(info);
  111. return {
  112. name : info.name,
  113. icon : info.icon,
  114. id : info.id,
  115. check_state : info.index
  116. };
  117. },
  118. tree => {
  119. //从工程中获取保存的model数据
  120. if(model.acax_app.model.project.GetModel().pro_model){
  121. //获取当前工程的名字
  122. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  123. let pro_name = model.acax_app.path.Name(pro_Index);
  124. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  125. findAndAppendByName(tree, pro_name, cur_model);
  126. }
  127. //赋值给dcip的树结构
  128. ui.tree_Model.tree = tree;
  129. }
  130. );
  131. }
  132. }
  133. //渲染3d模型
  134. if(model.acax_app.model.project.GetModel().step === "unimported") {
  135. unit.form.mainfrm.ClearCanvas();
  136. }else{
  137. model.acax_app.view.Render3D(info=>{
  138. unit.form.mainfrm.OnloadModel(info.model3d.step);
  139. });
  140. }
  141. }
  142. //切换工程
  143. function ChangePro(pro_name) {
  144. model.acax_app.control.project.SwitchTo(pro_name);
  145. model.acax_app.view.RenderTree(() => {
  146. g_cur_id2index_cache = {};
  147. g_cur_index2id_cache = {};
  148. }, info=>{
  149. let id2index = g_cur_id2index_cache;
  150. let index2id = g_cur_index2id_cache;
  151. let index = info.index;
  152. let id = info.id;
  153. if(index) {
  154. id2index[id] = index;
  155. index2id[index] = id;
  156. }
  157. console.log(info);
  158. return {
  159. name : info.name,
  160. icon : info.icon,
  161. id : info.id,
  162. check_state : info.index
  163. };
  164. },
  165. tree => {
  166. //从工程中获取保存的model数据
  167. if(model.acax_app.model.project.GetModel().pro_model){
  168. //获取当前工程的名字
  169. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  170. let pro_name = model.acax_app.path.Name(pro_Index);
  171. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  172. findAndAppendByName(tree, pro_name, cur_model);
  173. }
  174. //赋值给dcip的树结构
  175. ui.tree_Model.tree = tree;
  176. }
  177. );
  178. //渲染3d模型
  179. if(model.acax_app.model.project.GetModel().step === "unimported") {
  180. unit.form.mainfrm.ClearCanvas();
  181. }else{
  182. model.acax_app.view.Render3D(info=>{
  183. unit.form.mainfrm.OnloadModel(info.model3d.step);
  184. });
  185. }
  186. }
  187. //创建工作区
  188. function CreateWorkArea(name) {
  189. model.acax_app.control.workArea.Append(name);
  190. model.acax_app.view.RenderTree(() => {
  191. g_cur_id2index_cache = {};
  192. g_cur_index2id_cache = {};
  193. }, info=>{
  194. let id2index = g_cur_id2index_cache;
  195. let index2id = g_cur_index2id_cache;
  196. let index = info.index;
  197. let id = info.id;
  198. if(index) {
  199. id2index[id] = index;
  200. index2id[index] = id;
  201. }
  202. return {
  203. name : info.name,
  204. icon : info.icon,
  205. id : info.id,
  206. check_state : 3
  207. };
  208. },
  209. tree=>{
  210. ui.tree_Model.tree = tree;
  211. });
  212. //渲染3d模型
  213. if(model.acax_app.model.project.GetModel().step === "unimported") {
  214. unit.form.mainfrm.ClearCanvas();
  215. }else{
  216. model.acax_app.view.Render3D(info=>{
  217. unit.form.mainfrm.OnloadModel(info.model3d.step);
  218. });
  219. }
  220. }
  221. //创建工程
  222. function CreateProject(name) {
  223. model.acax_app.control.project.Create(name);
  224. model.acax_app.view.RenderTree(() => {
  225. g_cur_id2index_cache = {};
  226. g_cur_index2id_cache = {};
  227. }, info=>{
  228. let id2index = g_cur_id2index_cache;
  229. let index2id = g_cur_index2id_cache;
  230. let index = info.index;
  231. let id = info.id;
  232. return {
  233. name : info.name,
  234. icon : info.icon,
  235. id : info.id,
  236. check_state : 2
  237. };
  238. },
  239. tree=>{
  240. // console.log(model.acax_app.utils.FormatJSON(tree)+'\n');
  241. ui.tree_Model.tree = tree;
  242. });
  243. //渲染3d模型
  244. if(model.acax_app.model.project.GetModel().step === "unimported") {
  245. unit.form.mainfrm.ClearCanvas();
  246. }else{
  247. model.acax_app.view.Render3D(info=>{
  248. unit.form.mainfrm.OnloadModel(info.model3d.step);
  249. });
  250. }
  251. }
  252. //导入模型
  253. function OnOpenStepFile() {
  254. var model_file = myArray[parseFloat(ui.listbox.index)];
  255. model.acax_app.control.ImportStep(model_file, (model_file, model_plyfile)=>{
  256. model.acax_app.view.Render3D(info=>{
  257. unit.form.mainfrm.OnloadModel(info.model3d.step);
  258. });
  259. // unit.form.mainfrm.OnSend('openSTLFile ' + model.getCurrentDirectory() + ' ' + myArray[parseFloat(ui.listbox.index)]);
  260. //unit.form.mainfrm.OnCueline(`Loading ${myArray[parseFloat(ui.listbox.index)]} ...`, 'Blue');
  261. //model.setStepPath(model_file);
  262. //console.log(model_file);
  263. }
  264. );
  265. }
  266. //插入新子节点
  267. function findAndAppendByName(json, targetName, newChild) {
  268. if (json.name === targetName) {
  269. // 拼接新的 JSON 数据
  270. if (!json.children) {
  271. json.children = [];
  272. }
  273. json.children.unshift(newChild);
  274. return true; // 找到后返回 true
  275. }
  276. // 遍历子节点递归查找
  277. if (json.children) {
  278. for (const child of json.children) {
  279. if (findAndAppendByName(child, targetName, newChild)) {
  280. return true; // 如果找到目标节点,结束递归
  281. }
  282. }
  283. }
  284. return false; // 没找到返回 false
  285. }
  286. //将模型的id值加密与模型树一一对应
  287. function printIds(node) {
  288. if (node.id !== undefined) {
  289. id2index[id] = model.acax_app.path.Path;
  290. }
  291. if (Array.isArray(node.children)) {
  292. node.children.forEach(child => printIds(child));
  293. }
  294. }
  295. //导入模型树节点
  296. function OnTree(Idx){
  297. model.acax_app.view.RenderTree(() => {
  298. g_cur_id2index_cache = {};
  299. g_cur_index2id_cache = {};
  300. }, info=>{
  301. let id2index = g_cur_id2index_cache;
  302. let index2id = g_cur_index2id_cache;
  303. let index = info.index;
  304. let id = info.id;
  305. if(index) {
  306. id2index[id] = index;
  307. index2id[index] = id;
  308. }
  309. return {
  310. name : info.name,
  311. icon : info.icon,
  312. id : info.id,
  313. check_state : info.index
  314. };
  315. },
  316. tree => {
  317. //插入模型树节点与工程节点进行拼接
  318. let pro_Index= model.acax_app.view.GetCurrentProjectIndex();
  319. let pro_name = model.acax_app.path.Name(pro_Index);
  320. findAndAppendByName(tree, pro_name, Idx);
  321. //将模型树节点与工程节点拼接后保存到model中
  322. let pro_model = model.acax_app.model.project.GetModel();
  323. pro_model.pro_model = Idx;
  324. model.acax_app.model.project.SetModel(pro_model);
  325. ui.tree_Model.tree = tree;
  326. }
  327. );
  328. }
  329. //创建工况
  330. function CreateWorkCondition(name){
  331. let condition_index = model.acax_app.control.workCondition.Create(name);
  332. model.acax_app.view.RenderTree(() => {
  333. g_cur_id2index_cache = {};
  334. g_cur_index2id_cache = {};
  335. }, info=>{
  336. console.log(info);
  337. let id2index = g_cur_id2index_cache;
  338. let index2id = g_cur_index2id_cache;
  339. let index = info.index;
  340. let id = info.id;
  341. if(index) {
  342. id2index[id] = index;
  343. index2id[index] = id;
  344. }
  345. return {
  346. name : info.name,
  347. icon : info.icon,
  348. id : info.id,
  349. check_state : 2
  350. };
  351. },
  352. tree => {
  353. //获取当前工程的名字
  354. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  355. let pro_name = model.acax_app.path.Name(pro_Index);
  356. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  357. findAndAppendByName(tree, pro_name, cur_model);
  358. //赋值给dcip的树结构
  359. ui.tree_Model.tree = tree;
  360. }
  361. );
  362. }
  363. //创建材料属性
  364. function CreateMaterial(mat) {
  365. let material = model.acax_app.control.materialProp.Create(mat);
  366. model.acax_app.view.RenderTree(() => {
  367. g_cur_id2index_cache = {};
  368. g_cur_index2id_cache = {};
  369. }, info=>{
  370. console.log(info);
  371. let id2index = g_cur_id2index_cache;
  372. let index2id = g_cur_index2id_cache;
  373. let index = info.index;
  374. let id = info.id;
  375. if(index) {
  376. id2index[id] = index;
  377. index2id[index] = id;
  378. }
  379. return {
  380. name : info.name,
  381. icon : info.icon,
  382. id : info.id,
  383. check_state : 2
  384. };
  385. },
  386. tree => {
  387. //获取当前工程的名字
  388. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  389. let pro_name = model.acax_app.path.Name(pro_Index);
  390. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  391. findAndAppendByName(tree, pro_name, cur_model);
  392. //赋值给dcip的树结构
  393. ui.tree_Model.tree = tree;
  394. }
  395. );
  396. }
  397. //创建载荷
  398. function CreateBoundary(Load) {
  399. let load = model.acax_app.control.constrain.Create(Load);
  400. model.acax_app.view.RenderTree(() => {
  401. g_cur_id2index_cache = {};
  402. g_cur_index2id_cache = {};
  403. }, info=>{
  404. console.log(info);
  405. let id2index = g_cur_id2index_cache;
  406. let index2id = g_cur_index2id_cache;
  407. let index = info.index;
  408. let id = info.id;
  409. if(index) {
  410. id2index[id] = index;
  411. index2id[index] = id;
  412. }
  413. return {
  414. name : info.name,
  415. icon : info.icon,
  416. id : info.id,
  417. check_state : 2
  418. };
  419. },
  420. tree => {
  421. //获取当前工程的名字
  422. let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
  423. let pro_name = model.acax_app.path.Name(pro_Index);
  424. let cur_model = model.acax_app.model.project.GetModel().pro_model;
  425. findAndAppendByName(tree, pro_name, cur_model);
  426. //赋值给dcip的树结构
  427. ui.tree_Model.tree = tree;
  428. }
  429. );
  430. }
  431. function OnMessage(idx){
  432. ui.cueline.value += idx + '\n';
  433. ui.cueline.row = -1;
  434. }
  435. function OnChangeMenu(Idx){
  436. ui.tree_menu.index = parseInt(Idx);
  437. }
  438. function OnDeleteFile() {
  439. myArray.splice(parseFloat(ui.listbox.index), 1);
  440. ui.listbox.list = [
  441. myArray
  442. ];
  443. }
  444. function OnOpenFile(){
  445. var fname = ui.OpenFileDialog("Import File", unit.dir + 'data/', "Step Files(*.step *.stp);;Iges Files(*.iges *.igs);;Nastran Files(*.nas)");
  446. model.write(fname, model.getCurrentDirectory() + '/data/address.txt');
  447. myArray.push(fname);
  448. ui.listbox.list = [
  449. myArray
  450. ];
  451. }
  452. function OnChangeOptions(){
  453. options = !options;
  454. ui.stack_options.visible = options;
  455. }
  456. function OnTopMenu(idx) {
  457. ui.stack_import.visible = true;
  458. ui.stack_import.index = parseInt(idx) - 1;
  459. ui.pb_import01.valid = ui.pb_import02.valid = ui.pb_import03.valid = ui.pb_import04.valid = ui.pb_import05.valid = false;
  460. //model.ide_info(idx);
  461. if (parseInt(idx) === 1) {
  462. ui.pb_import01.valid = true;
  463. }
  464. if (parseInt(idx) === 2) {
  465. ui.pb_import02.valid = true;
  466. }
  467. if (parseInt(idx) === 3) {
  468. ui.pb_import03.valid = true;
  469. }
  470. if (parseInt(idx) === 4) {
  471. ui.pb_import04.valid = true;
  472. }
  473. if (parseInt(idx) === 5) {
  474. ui.pb_import05.valid = true;
  475. }
  476. }
  477. //The message corresponding callback executed by the docker pane.
  478. // when calling [side_pane].fireEvent(type,para) in the main form.
  479. function OnParentDockerMessage(type, para) {
  480. }
  481. //////////////////////////////////////////////////////////////////////////
  482. // Utils Functions.
  483. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  484. function onDragFile(filepath) {
  485. }
  486. function PUI(cb) {
  487. if(pui){cb();}
  488. }
  489. /*Usage of BLOCK_EVENT
  490. BLOCK_EVENT(()=>{
  491. ui.[name].[var] = ...;
  492. });
  493. */
  494. function BLOCK_EVENT(cb) {
  495. ui.block_event = true;
  496. cb();
  497. ui.block_event = false;
  498. }
  499. //////////////////////////////////////////////////////////////////////////
  500. // template codes for cw callback js.
  501. function CW_DeclareVariable(name, setter, getter) {
  502. if(typeof(__DeclareVariable) === 'function') {
  503. __DeclareVariable(name, setter, getter);
  504. }
  505. }
  506. function CW_DeclareOuterVariable(name) {
  507. if(typeof(__DeclareOuterVariable) === 'function') {
  508. __DeclareOuterVariable(name);
  509. }
  510. }