boundary_constraint_pane.js 34 KB

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