boundary_constraint_pane.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. ////////////////////////////////////////////////////////////////////////////
  2. // System Pre-define Functions
  3. // 95099372-ef3e-11ea-9c81-bf848405c62e
  4. //Callback of data preparation stage before UI is fully loaded.
  5. function OnInitializeData(reload, preview) {
  6. PUI(()=>{
  7. //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
  8. //The 'pui' variable is valid in all functions of this document.
  9. //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
  10. });
  11. // ui.stack_constraint.index = 1;
  12. // ui.stack_menu.index = 2;
  13. //control(true);
  14. //controls(true);
  15. //ui.stack_constraint.index = 2;
  16. //ui.stack_menu.index = 2;
  17. }
  18. //Callback after UI is fully loaded and displayed.
  19. function OnReady(reload, preview) {
  20. PUI(()=>{
  21. //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
  22. //The 'pui' variable is valid in all functions of this document.
  23. //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
  24. });
  25. }
  26. function OnCloseForm() {
  27. }
  28. function OnException(err) {
  29. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  30. }
  31. //////////////////////////////////////////////////////////////////////////
  32. // Callback Functions.
  33. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  34. function OnGetFaceName(){
  35. const str = unit.form.mainfrm.OnGetFaceName();
  36. // 匹配type对应内容的正则表达式,以type:开头,后面跟着非冒号的内容直到遇到空格或者字符串结束
  37. const typeRegex = /type:([^point]+)/;
  38. // 匹配center坐标对应内容的正则表达式
  39. const centerRegex = /point:([\d. ]+)/;
  40. const typeMatch = str.match(typeRegex);
  41. const typeInfo = typeMatch? typeMatch[1] : null;
  42. const centerMatch = str.match(centerRegex);
  43. const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
  44. ui.type.value = typeInfo;
  45. ui.xc.value = centerCoords[0];
  46. ui.yc.value = centerCoords[1];
  47. ui.zc.value = centerCoords[2];
  48. }
  49. function OnCPointAddEnd(){
  50. const str = unit.form.mainfrm.OnGetName();
  51. // 匹配center坐标对应内容的正则表达式
  52. const centerRegex = /center:([\d. ]+)/;
  53. const typeInfo = str.split(' ').slice(1, 4).join(' ');
  54. const centerMatch = str.match(centerRegex);
  55. const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
  56. ui.ctpyee.value = typeInfo;
  57. ui.cxe.value = centerCoords[0];
  58. ui.cye.value = centerCoords[1];
  59. ui.cze.value = centerCoords[2];
  60. }
  61. function OnCPointAddStart(){
  62. const str = unit.form.mainfrm.OnGetName();
  63. // 匹配center坐标对应内容的正则表达式
  64. const centerRegex = /center:([\d. ]+)/;
  65. const typeInfo = str.split(' ').slice(1, 4).join(' ');
  66. const centerMatch = str.match(centerRegex);
  67. const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
  68. ui.ctypes.value = typeInfo;
  69. ui.cxs.value = centerCoords[0];
  70. ui.cys.value = centerCoords[1];
  71. ui.czs.value = centerCoords[2];
  72. }
  73. function OnSPointAddEnd(){
  74. const str = unit.form.mainfrm.OnGetName();
  75. // 匹配center坐标对应内容的正则表达式
  76. const centerRegex = /center:([\d. ]+)/;
  77. const typeInfo = str.split(' ').slice(1, 4).join(' ');
  78. const centerMatch = str.match(centerRegex);
  79. const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
  80. ui.stypee.value = typeInfo;
  81. ui.sxe.value = centerCoords[0];
  82. ui.sye.value = centerCoords[1];
  83. ui.sze.value = centerCoords[2];
  84. }
  85. function OnSPointAddStart(){
  86. const str = unit.form.mainfrm.OnGetName();
  87. // 匹配center坐标对应内容的正则表达式
  88. const centerRegex = /center:([\d. ]+)/;
  89. const typeInfo = str.split(' ').slice(1, 4).join(' ');
  90. const centerMatch = str.match(centerRegex);
  91. const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
  92. ui.stypes.value = typeInfo;
  93. ui.sxs.value = centerCoords[0];
  94. ui.sys.value = centerCoords[1];
  95. ui.szs.value = centerCoords[2];
  96. }
  97. function OnGetName(){
  98. const str = unit.form.mainfrm.OnGetName();
  99. console.log(str);
  100. // 匹配center坐标对应内容的正则表达式
  101. const centerRegex = /center:([\d. ]+)/;
  102. const typeInfo = str.split(' ').slice(1, 4).join(' ');
  103. const centerMatch = str.match(centerRegex);
  104. const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
  105. ui.type.value = typeInfo;
  106. ui.xc.value = centerCoords[0];
  107. ui.yc.value = centerCoords[1];
  108. ui.zc.value = centerCoords[2];
  109. }
  110. //修改约束
  111. function OnModify(){
  112. if(ui.limit_constraint.index === 0 && ui.constraint_type.index === 0) {
  113. let name = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).unique;
  114. unit.form.mainfrm.OnModifyConstrains(ui.xc.value, ui.yc.value, ui.zc.value, name);
  115. let color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color;
  116. let Load = {
  117. "constraint":"固定支撑",
  118. "约束类型":ui.constraint_type.value,
  119. "type":ui.type.value,
  120. "xc":ui.xc.value,
  121. "yc":ui.yc.value,
  122. "zc":ui.zc.value,
  123. "固定支撑属性xd":ui.con_xn.value,
  124. "固定支撑属性xr":ui.con_xr.value,
  125. "固定支撑属性yd":ui.con_yn.value,
  126. "固定支撑属性yr":ui.con_yr.value,
  127. "固定支撑属性zd":ui.con_zn.value,
  128. "固定支撑属性zr":ui.con_zr.value,
  129. "cons_type":"constraints",
  130. "color":color,
  131. "unique":name
  132. };
  133. unit.form.tree.ModifyConstraint(Load);
  134. unit.form.mainfrm.OnCueline('修改成功', 'green');
  135. }
  136. if(ui.limit_constraint.index ===1 && ui.misConstraints.index === 0 ) {
  137. let name = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).unique;
  138. unit.form.mainfrm.OnModifyBeams(ui.pb_size.value, ui.pb_xDiration.value, ui.pb_yDiration.value, ui.pb_zDiration.value, ui.pb_xCoord.value, ui.pb_yCoord.value, ui.pb_zCoord.value, ui.R.value, ui.G.value, ui.B.value, ui.pb_node_size.value, name);
  139. let color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color;
  140. let Load = {
  141. "constraint":"梁",
  142. "非约束类型":ui.misConstraints.value,
  143. "梁约束位置xDirection":ui.pb_xDiration.value,
  144. "梁约束位置yDirection":ui.pb_yDiration.value,
  145. "梁约束位置zDirection":ui.pb_zDiration.value,
  146. "梁约束位置xCoord":ui.pb_xCoord.value,
  147. "梁约束位置yCoord":ui.pb_yCoord.value,
  148. "梁约束位置zCoord":ui.pb_zCoord.value,
  149. "梁约束参数半径":ui.rad.value,
  150. "梁约束参数长度":ui.pb_length.value,
  151. "梁约束参数个数":ui.pb_size.value,
  152. "弹性模量":ui.m.value,
  153. "泊松比":ui.poi.value,
  154. "梁节点大小半径":ui.pb_node_size.value,
  155. "R":ui.R.value,
  156. "G":ui.G.value,
  157. "B":ui.B.value,
  158. "cons_type":"beams",
  159. "color":color,
  160. "unique":name
  161. };
  162. unit.form.tree.ModifyConstraint(Load);
  163. unit.form.mainfrm.OnCueline('修改成功', 'green');
  164. }
  165. if(ui.limit_constraint.index ===1 && ui.misConstraints.index === 1 ) {
  166. let name = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).unique;
  167. unit.form.mainfrm.OnModifySpring(ui.sxs.value, ui.sys.value, ui.szs.value, ui.sxe.value, ui.sye.value, ui.sze.value, ui.sr.value, ui.sg.value, ui.sb.value, name);
  168. let color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color;
  169. let Load = {
  170. "constraint":"弹簧",
  171. "非约束类型":ui.misConstraints.value,
  172. "弹簧坐标x":ui.sxs.value,
  173. "弹簧坐标y":ui.sys.value,
  174. "弹簧坐标z":ui.szs.value,
  175. "stypes":ui.stypes.value,
  176. "弹簧终点x":ui.sxe.value,
  177. "弹簧终点y":ui.sye.value,
  178. "弹簧终点z":ui.sze.value,
  179. "stypee":ui.stypee.value,
  180. "stiffness_x":ui.sstifx.value,
  181. "stiffness_y":ui.sstify.value,
  182. "stiffness_z":ui.sstifz.value,
  183. "R":ui.sr.value,
  184. "G":ui.sg.value,
  185. "B":ui.sb.value,
  186. "cons_type":"spring",
  187. "color":color,
  188. "unique":name
  189. };
  190. unit.form.tree.ModifyConstraint(Load);
  191. unit.form.mainfrm.OnCueline('修改成功', 'green');
  192. }
  193. if(ui.limit_constraint.index ===1 && ui.misConstraints.index === 2 ) {
  194. let name = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).unique;
  195. unit.form.mainfrm.OnModifyConnects(ui.cxs.value, ui.cys.value, ui.czs.value, ui.cxe.value, ui.cye.value, ui.cze.value, ui.cr.value, ui.cg.value, ui.cb.value, name);
  196. let color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color;
  197. let Load = {
  198. "constraint":"连接",
  199. "非约束类型":ui.misConstraints.value,
  200. "弹簧坐标x":ui.cxs.value,
  201. "弹簧坐标y":ui.cys.value,
  202. "弹簧坐标z":ui.czs.value,
  203. "ctypes":ui.ctypes.value,
  204. "弹簧终点x":ui.cxe.value,
  205. "弹簧终点y":ui.cye.value,
  206. "弹簧终点z":ui.cze.value,
  207. "ctpyee":ui.ctpyee.value,
  208. "弹簧材料xn":ui.cxn.value,
  209. "弹簧材料yn":ui.cyn.value,
  210. "弹簧材料zn":ui.czn.value,
  211. "弹簧材料xr":ui.cxr.value,
  212. "弹簧材料yr":ui.cyr.value,
  213. "弹簧材料zr":ui.czr.value,
  214. "R":ui.cr.value,
  215. "G":ui.cg.value,
  216. "B":ui.cb.value,
  217. "cons_type":"connect",
  218. "color":color,
  219. "unique":name
  220. };
  221. unit.form.tree.ModifyConstraint(Load);
  222. unit.form.mainfrm.OnCueline('修改成功', 'green');
  223. }
  224. }
  225. function OnChangeBeam(){
  226. if(parseFloat(ui.pb_length.value) <= 0 || parseFloat(ui.rad.value) <= 0 || parseFloat(ui.m.value) <= 0 || parseFloat(ui.poi.value) <= 0 || parseFloat(ui.rad.value) <= 0){
  227. unit.form.mainfrm.OnChangePicture(3, 3);
  228. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: red;font-size:20px;">非常抱歉,您输入的数据不在参数范围内!</h4>');
  229. unit.form.mainfrm.OnCueline('您输入的数据不在参数范围内!', 'red');
  230. }else{
  231. unit.form.mainfrm.OnChangePicture(3, 2);
  232. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: Blue;font-size:20px;">恭喜您,您输入了正确的数据!</h4>');
  233. unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'blue');
  234. }
  235. }
  236. function OnFix(){
  237. let temp = unit.form.tree.GetCurUniqueName();
  238. let name = temp;
  239. let constrain_data = model.acax_app.model.constrain.Database();
  240. //console.log(workcondition_data);
  241. let i = 0;
  242. let j = 0;
  243. let constrain_arr = Object.keys(constrain_data.db);
  244. //console.log(constrain_data.db);
  245. name = name + "fix0";
  246. while(1){
  247. for( i = 0;i < constrain_arr.length;++i) {
  248. if(constrain_data.db[constrain_arr[i]].unique === name) {
  249. ++j;
  250. name = temp + "fix" + j;
  251. break;
  252. }
  253. }
  254. if(i === constrain_arr.length) {
  255. break;
  256. }
  257. }
  258. let name1 = unit.form.mainfrm.OnConstrains(ui.xc.value, ui.yc.value, ui.zc.value, name);
  259. name1 = name1.replace(temp, "");
  260. unit.form.mainfrm.OnChangePicture(3, 2);
  261. let color = unit.form.tree.getRandomHexColor();
  262. let Load = {
  263. "constraint":"固定支撑",
  264. "约束类型":ui.constraint_type.value,
  265. "type":ui.type.value,
  266. "xc":ui.xc.value,
  267. "yc":ui.yc.value,
  268. "zc":ui.zc.value,
  269. "固定支撑属性xd":ui.con_xn.value,
  270. "固定支撑属性xr":ui.con_xr.value,
  271. "固定支撑属性yd":ui.con_yn.value,
  272. "固定支撑属性yr":ui.con_yr.value,
  273. "固定支撑属性zd":ui.con_zn.value,
  274. "固定支撑属性zr":ui.con_zr.value,
  275. "cons_type":"constraints",
  276. "color":color,
  277. "unique":name
  278. };
  279. // console.log(name1);
  280. if(ui.type.value === '--') {
  281. unit.form.mainfrm.OnCueline('未添加中心坐标', 'green');
  282. }else{
  283. unit.form.tree.CreateBoundary(Load, name1);
  284. unit.form.mainfrm.OnCueline('您完成了固定支撑属性的添加,请用鼠标右键选中需要施加约束的物体并按快捷键T或者t进行添加!', 'green');
  285. }
  286. }
  287. function OnBeam2(){
  288. unit.form.mainfrm.OnSend('beamHightLight2 ' + ui.m_seg.value + ' ' + ui.m_len.value + ' ' + ui.m_radius.value + ' ' + ui.m_mat.value + ' ' + ui.m_poi.value + ' ' + ui.m_R.value + ' '+ ui.m_G.value + ' ' + ui.m_B.value + ' ' + ui.m_ras.value);
  289. model.clearStr();
  290. unit.form.mainfrm.OnChangePicture(3, 2);
  291. unit.form.mainfrm.OnCueline('您成功做好了不均匀梁的添加!', 'green');
  292. }
  293. function OnConnect(){
  294. let temp = unit.form.tree.GetCurUniqueName();
  295. let name = temp;
  296. let constrain_data = model.acax_app.model.constrain.Database();
  297. let i = 0;
  298. let j = 0;
  299. let constrain_arr = Object.keys(constrain_data.db);
  300. name = name + "con0";
  301. while(1){
  302. for( i = 0;i < constrain_arr.length;++i) {
  303. if(constrain_data.db[constrain_arr[i]].unique === name) {
  304. ++j;
  305. name = temp + "con" + j;
  306. break;
  307. }
  308. }
  309. if(i === constrain_arr.length) {
  310. break;
  311. }
  312. }
  313. let name1 = unit.form.mainfrm.OnConnects(ui.cxs.value, ui.cys.value, ui.czs.value, ui.cxe.value, ui.cye.value, ui.cze.value, ui.cr.value, ui.cg.value, ui.cb.value, name);
  314. name1 = name1.replace(temp, "");
  315. console.log(name1);
  316. unit.form.mainfrm.OnChangePicture(3, 2);
  317. let color = unit.form.tree.getRandomHexColor();
  318. let Load = {
  319. "constraint":"连接",
  320. "非约束类型":ui.misConstraints.value,
  321. "弹簧坐标x":ui.cxs.value,
  322. "弹簧坐标y":ui.cys.value,
  323. "弹簧坐标z":ui.czs.value,
  324. "ctypes":ui.ctypes.value,
  325. "弹簧终点x":ui.cxe.value,
  326. "弹簧终点y":ui.cye.value,
  327. "弹簧终点z":ui.cze.value,
  328. "ctpyee":ui.ctpyee.value,
  329. "弹簧材料xn":ui.cxn.value,
  330. "弹簧材料yn":ui.cyn.value,
  331. "弹簧材料zn":ui.czn.value,
  332. "弹簧材料xr":ui.cxr.value,
  333. "弹簧材料yr":ui.cyr.value,
  334. "弹簧材料zr":ui.czr.value,
  335. "R":ui.cr.value,
  336. "G":ui.cg.value,
  337. "B":ui.cb.value,
  338. "cons_type":"connect",
  339. "color":color,
  340. "unique":name
  341. };
  342. //console.log(name1);
  343. if(ui.ctypes.value === '--' || ui.ctpyee.value === '--') {
  344. unit.form.mainfrm.OnCueline('未添加弹簧坐标', 'red');
  345. }else{
  346. unit.form.tree.CreateBoundary(Load, name1);
  347. unit.form.mainfrm.OnCueline('您成功地做好了连接!', 'green');
  348. }
  349. }
  350. function onEndMessage(){
  351. controls(false);
  352. }
  353. function onStartMessage(){
  354. controls(true);
  355. }
  356. function controls(idx){
  357. ui.pb_start_message.enable = !idx;
  358. ui.pb_start_mes.enable = !idx;
  359. ui.pb_start_x.enable = idx;
  360. ui.pb_start_y.enable = idx;
  361. ui.pb_start_z.enable = idx;
  362. ui.pb_end_message.enable = idx;
  363. ui.pb_end_mes.enable = idx;
  364. ui.pb_end_x.enable = !idx;
  365. ui.pb_end_y.enable = !idx;
  366. ui.pb_end_z.enable = !idx;
  367. if(idx === true){
  368. model.setStartEnd(0);
  369. }
  370. if(idx === false){
  371. model.setStartEnd(1);
  372. }
  373. }
  374. function OnChangeValue(){
  375. ui.pb_pass.enable = false;
  376. }
  377. function OnReturn(){
  378. unit.form.mainfrm.menu(4);
  379. }
  380. function OnFile(){
  381. ui.pb_pass.enable = true;
  382. model.setCon(1);
  383. if(ui.stack_menu.index === 0){
  384. let id = parent.setTimeout(() => {
  385. unit.form.mainfrm.OnSend('0');
  386. }, 100);
  387. unit.form.mainfrm.OnSend('beamSave ' + model.getCurrentDirectory());
  388. }
  389. if(ui.stack_menu.index === 1){
  390. let id = parent.setTimeout(() => {
  391. unit.form.mainfrm.OnSend('0');
  392. }, 100);
  393. unit.form.mainfrm.OnSend('springSave ' + model.getCurrentDirectory());
  394. }
  395. }
  396. function OnSpring(){
  397. let temp = unit.form.tree.GetCurUniqueName();
  398. let name = temp;
  399. let constrain_data = model.acax_app.model.constrain.Database();
  400. //console.log(workcondition_data);
  401. let i = 0;
  402. let j = 0;
  403. let constrain_arr = Object.keys(constrain_data.db);
  404. //console.log(constrain_data.db);
  405. name = name + "spring0";
  406. while(1){
  407. for( i = 0;i < constrain_arr.length;++i) {
  408. if(constrain_data.db[constrain_arr[i]].unique === name) {
  409. ++j;
  410. name = temp + "spring" + j;
  411. break;
  412. }
  413. }
  414. if(i === constrain_arr.length) {
  415. break;
  416. }
  417. }
  418. let name1 = unit.form.mainfrm.OnSpring(ui.sxs.value, ui.sys.value, ui.szs.value, ui.sxe.value, ui.sye.value, ui.sze.value, ui.sr.value, ui.sg.value, ui.sb.value, name);
  419. name1 = name1.replace(temp, "");
  420. unit.form.mainfrm.OnChangePicture(3, 2);
  421. let color = unit.form.tree.getRandomHexColor();
  422. let Load = {
  423. "constraint":"弹簧",
  424. "非约束类型":ui.misConstraints.value,
  425. "弹簧坐标x":ui.sxs.value,
  426. "弹簧坐标y":ui.sys.value,
  427. "弹簧坐标z":ui.szs.value,
  428. "stypes":ui.stypes.value,
  429. "弹簧终点x":ui.sxe.value,
  430. "弹簧终点y":ui.sye.value,
  431. "弹簧终点z":ui.sze.value,
  432. "stypee":ui.stypee.value,
  433. "stiffness_x":ui.sstifx.value,
  434. "stiffness_y":ui.sstify.value,
  435. "stiffness_z":ui.sstifz.value,
  436. "R":ui.sr.value,
  437. "G":ui.sg.value,
  438. "B":ui.sb.value,
  439. "cons_type":"spring",
  440. "color":color,
  441. "unique":name
  442. };
  443. console.log(name1);
  444. if(ui.stypes.value === '--' || ui.stypee.value === '--') {
  445. unit.form.mainfrm.OnCueline('未添加弹簧坐标', 'green');
  446. }else{
  447. unit.form.tree.CreateBoundary(Load, name1);
  448. unit.form.mainfrm.OnCueline('您完成了弹簧约束的添加!', 'green');
  449. }
  450. }
  451. function OnBeam(){
  452. let temp = unit.form.tree.GetCurUniqueName();
  453. let name = temp;
  454. let constrain_data = model.acax_app.model.constrain.Database();
  455. //console.log(workcondition_data);
  456. let i = 0;
  457. let j = 0;
  458. let constrain_arr = Object.keys(constrain_data.db);
  459. //console.log(constrain_data.db);
  460. name = name + "beam0";
  461. while(1){
  462. for( i = 0;i < constrain_arr.length;++i) {
  463. if(constrain_data.db[constrain_arr[i]].unique.split(" ")[0] === name) {
  464. ++j;
  465. name = temp + "beam" + j;
  466. break;
  467. }
  468. }
  469. if(i === constrain_arr.length) {
  470. break;
  471. }
  472. }
  473. name = name + " B 0";
  474. const str =unit.form.mainfrm.OnBeams(ui.pb_size.value, ui.pb_xDiration.value, ui.pb_yDiration.value, ui.pb_zDiration.value, ui.pb_xCoord.value, ui.pb_yCoord.value, ui.pb_zCoord.value, ui.R.value, ui.G.value, ui.B.value, ui.pb_node_size.value, name);
  475. let name1 = str.split(' ')[0].split(':')[1];
  476. name1 = name1.replace(temp, "");
  477. const centerRegex = /centers:([\d. ]+)/;
  478. const centerMatch = str.match(centerRegex);
  479. const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
  480. let color = unit.form.tree.getRandomHexColor();
  481. unit.form.mainfrm.OnChangePicture(3, 2);
  482. let Load = {
  483. "constraint":"梁",
  484. "非约束类型":ui.misConstraints.value,
  485. "梁约束位置xDirection":ui.pb_xDiration.value,
  486. "梁约束位置yDirection":ui.pb_yDiration.value,
  487. "梁约束位置zDirection":ui.pb_zDiration.value,
  488. "梁约束位置xCoord":ui.pb_xCoord.value,
  489. "梁约束位置yCoord":ui.pb_yCoord.value,
  490. "梁约束位置zCoord":ui.pb_zCoord.value,
  491. "梁约束参数半径":ui.rad.value,
  492. "梁约束参数长度":ui.pb_length.value,
  493. "梁约束参数个数":ui.pb_size.value,
  494. "弹性模量":ui.m.value,
  495. "泊松比":ui.poi.value,
  496. "梁节点大小半径":ui.pb_node_size.value,
  497. "R":ui.R.value,
  498. "G":ui.G.value,
  499. "B":ui.B.value,
  500. "point":centerCoords,
  501. "cons_type":"beams",
  502. "color":color,
  503. "unique":name
  504. };
  505. console.log(name1);
  506. unit.form.tree.CreateBoundary(Load, name1);
  507. unit.form.mainfrm.OnCueline('您完成了梁约束的添加!', 'green');
  508. }
  509. function control(idx){
  510. ui.pb_start.enable = !idx;
  511. ui.pb_x.enable = idx;
  512. ui.pb_y.enable = idx;
  513. ui.pb_z.enable = idx;
  514. ui.pb_end.enable = idx;
  515. ui.pb_X.enable = !idx;
  516. ui.pb_Y.enable = !idx;
  517. ui.pb_Z.enable = !idx;
  518. if(idx === true){
  519. model.setStartEnd(0);
  520. }
  521. if(idx === false){
  522. model.setStartEnd(1);
  523. }
  524. }
  525. function OnEed(){
  526. control(false);
  527. }
  528. function OnStart(){
  529. control(true);
  530. }
  531. function OnChangeMenu(){
  532. ui.stack_menu.index = parseFloat(ui.misConstraints.index);
  533. console.log(ui.no_limit_constraint.index === 1);
  534. //console.log(ui.limit_constraint.index);
  535. if(ui.stack_menu.index === 3){
  536. model.setBeam(true);
  537. }else{
  538. model.setBeam(false);
  539. }
  540. }
  541. function OnChangeConstraint(){
  542. ui.stack_constraint.index = ui.limit_constraint.index;
  543. if(parseFloat(idx) === 1){
  544. unit.form.mainfrm.OnChangePicture(3, 1);
  545. unit.form.mainfrm.OnCueline('注意事项:弹簧单元的起点和终点需要自动添加,鼠标右键选中起始/终止点,点击按钮(在窗口左侧倒数第3个按钮)添加即可将坐标导入!', 'blue');
  546. }else if(parseFloat(idx) === 2){
  547. unit.form.mainfrm.OnChangePicture(3, 1);
  548. unit.form.mainfrm.OnCueline('注意事项:连接单元的起点和终点需要自动添加,鼠标右键选中起始/终止点,点击按钮(在窗口左侧倒数第3个按钮)添加即可将坐标导入!', 'blue');
  549. }else if(parseFloat(idx) === 3){
  550. unit.form.mainfrm.OnChangePicture(3, 1);
  551. unit.form.mainfrm.OnCueline('注意事项:非均匀梁的各个节点需要用鼠标右键拾取后点击H或h进行保存,梁上的各个点需要在一条直线上!', 'blue');
  552. }
  553. }
  554. function ChangeRadiobutton(idx) {
  555. ui.limit_constraint.index = parseFloat(idx);
  556. }
  557. //The message corresponding callback executed by the docker pane.
  558. // when calling [side_pane].fireEvent(type,para) in the main form.
  559. function OnParentDockerMessage(type, para) {
  560. }
  561. //////////////////////////////////////////////////////////////////////////
  562. // Utils Functions.
  563. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  564. CW_DeclareVariable("pb_x",
  565. val => {
  566. ui.pb_x.value = val;
  567. ui.pb_start_x.value = val;
  568. }, () => {});
  569. CW_DeclareVariable("pb_y",
  570. val => {
  571. ui.pb_y.value = val;
  572. ui.pb_start_y.value = val;
  573. }, () => {});
  574. CW_DeclareVariable("pb_z",
  575. val => {
  576. ui.pb_z.value = val;
  577. ui.pb_start_z.value = val;
  578. }, () => {});
  579. CW_DeclareVariable("pb_X",
  580. val => {
  581. ui.pb_X.value = val;
  582. ui.pb_end_x.value = val;
  583. }, () => {});
  584. CW_DeclareVariable("pb_Y",
  585. val => {
  586. ui.pb_Y.value = val;
  587. ui.pb_end_y.value = val;
  588. }, () => {});
  589. CW_DeclareVariable("pb_Z",
  590. val => {
  591. ui.pb_Z.value = val;
  592. ui.pb_end_z.value = val;
  593. }, () => {});
  594. CW_DeclareVariable("listbox",
  595. val => {
  596. ui.listbox.list = [
  597. val
  598. ];
  599. }, () => {});
  600. CW_DeclareVariable("start_mes",
  601. val => {
  602. ui.pb_type1.value = val;
  603. ui.pb_start_mes.value = val;
  604. }, () => {});
  605. CW_DeclareVariable("end_mes",
  606. val => {
  607. ui.pb_type2.value = val;
  608. ui.pb_end_mes.value = val;
  609. }, () => {});
  610. CW_DeclareVariable("change1",
  611. val => {
  612. ui.stack_constraint.index = val;
  613. }, () => {});
  614. CW_DeclareVariable("change2",
  615. val => {
  616. ui.stack_menu.index = val;
  617. ui.misConstraints.index = val;
  618. }, () => {});
  619. //固定支撑
  620. CW_DeclareVariable("setConstraint0",
  621. val => {
  622. ui.type.value = val.type;
  623. ui.xc.value=val.xc;
  624. ui.yc.value=val.yc;
  625. ui.zc.value=val.zc;
  626. ui.con_xn.value = val["固定支撑属性xd"];
  627. ui.con_xr.value = val["固定支撑属性xr"];
  628. ui.con_yn.value = val["固定支撑属性yd"];
  629. ui.con_yr.value = val["固定支撑属性yr"];
  630. ui.con_zn.value = val["固定支撑属性zd"];
  631. ui.con_zr.value = val["固定支撑属性zr"];
  632. }, () => {});
  633. //梁
  634. CW_DeclareVariable("setConstraint1",
  635. val => {
  636. ui.pb_xDiration.value = val["梁约束位置xDirection"];
  637. ui.pb_yDiration.value = val["梁约束位置yDirection"];
  638. ui.pb_zDiration.value = val["梁约束位置zDirection"];
  639. ui.pb_xCoord.value = val["梁约束位置xCoord"];
  640. ui.pb_yCoord.value = val["梁约束位置yCoord"];
  641. ui.pb_zCoord.value = val["梁约束位置zCoord"];
  642. ui.rad.value = val["梁约束参数半径"];
  643. ui.pb_length.value = val["梁约束参数长度"];
  644. ui.pb_size.value = val["梁约束参数个数"];
  645. ui.m.value = val["弹性模量"];
  646. ui.poi.value = val["泊松比"];
  647. ui.pb_node_size.value = val["梁节点大小半径"];
  648. ui.R.value = val.R;
  649. ui.G.value = val.G;
  650. ui.B.value = val.B;
  651. }, () => {});
  652. //弹簧
  653. CW_DeclareVariable("setConstraint2",
  654. val => {
  655. ui.sxs.value = val["弹簧坐标x"];
  656. ui.sys.value = val["弹簧坐标y"];
  657. ui.szs.value = val["弹簧坐标z"];
  658. ui.stypes.value = val.stypes;
  659. ui.sxe.value = val["弹簧终点x"];
  660. ui.sye.value = val["弹簧终点y"];
  661. ui.sze.value = val["弹簧终点z"];
  662. ui.stypee.value = val.stypee;
  663. ui.sstifx.value = val.stiffness_x;
  664. ui.sstify.value = val.stiffness_y;
  665. ui.sstifz.value = val.stiffness_z;
  666. ui.sr.value = val.R;
  667. ui.sg.value = val.G;
  668. ui.sb.value = val.B;
  669. }, () => {});
  670. //连接
  671. CW_DeclareVariable("setConstraint3",
  672. val => {
  673. ui.cxs.value = val["弹簧坐标x"];
  674. ui.cys.value= val["弹簧坐标y"];
  675. ui.czs.value= val["弹簧坐标z"];
  676. ui.ctypes.value= val.ctypes;
  677. ui.cxe.value= val["弹簧终点x"];
  678. ui.cye.value= val["弹簧终点y"];
  679. ui.cze.value= val["弹簧终点z"];
  680. ui.ctpyee.value= val.ctpyee;
  681. ui.cxn.value = val["弹簧材料xn"];
  682. ui.cyn.value= val["弹簧材料yn"];
  683. ui.czn.value= val["弹簧材料zn"];
  684. ui.cxr.value= val["弹簧材料xr"];
  685. ui.cyr.value= val["弹簧材料yr"];
  686. ui.czr.value= val["弹簧材料zr"];
  687. ui.cr.value = val.R;
  688. ui.cg.value = val.G;
  689. ui.cb.value = val.B;
  690. }, () => {});
  691. function onDragFile(filepath) {
  692. }
  693. function PUI(cb) {
  694. if(pui){cb();}
  695. }
  696. /*Usage of BLOCK_EVENT
  697. BLOCK_EVENT(()=>{
  698. ui.[name].[var] = ...;
  699. });
  700. */
  701. function BLOCK_EVENT(cb) {
  702. ui.block_event = true;
  703. cb();
  704. ui.block_event = false;
  705. }
  706. //////////////////////////////////////////////////////////////////////////
  707. // template codes for cw callback js.
  708. function CW_DeclareVariable(name, setter, getter) {
  709. if(typeof(__DeclareVariable) === 'function') {
  710. __DeclareVariable(name, setter, getter);
  711. }
  712. }
  713. function CW_DeclareOuterVariable(name) {
  714. if(typeof(__DeclareOuterVariable) === 'function') {
  715. __DeclareOuterVariable(name);
  716. }
  717. }