boundary_force_pane.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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_force.index = 1;
  12. }
  13. //Callback after UI is fully loaded and displayed.
  14. function OnReady(reload, preview) {
  15. PUI(()=>{
  16. //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
  17. //The 'pui' variable is valid in all functions of this document.
  18. //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
  19. });
  20. }
  21. function OnCloseForm() {
  22. }
  23. function OnException(err) {
  24. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  25. }
  26. //////////////////////////////////////////////////////////////////////////
  27. // Callback Functions.
  28. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  29. function OnGetFaceName(){
  30. const str = unit.form.mainfrm.OnGetFaceName();
  31. console.log(str);
  32. // 匹配type对应内容的正则表达式,以type:开头,后面跟着非冒号的内容直到遇到空格或者字符串结束
  33. const typeRegex = /type:([^point]+)/;
  34. // 匹配center坐标对应内容的正则表达式
  35. //const centerRegex = /point:([\d. ]+)/;
  36. const typeMatch = str.match(typeRegex);
  37. const typeInfo = typeMatch? typeMatch[1] : null;
  38. //const centerMatch = str.match(centerRegex);
  39. //const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
  40. const match = str.match(/point:([-\d.]+)\s+([-\d.]+)\s+([-\d.]+)/);
  41. const centerCoords = match.slice(1, 4);
  42. ui.type1.value = typeInfo;
  43. ui.x1.value = centerCoords[0];
  44. ui.y1.value = centerCoords[1];
  45. ui.z1.value = centerCoords[2];
  46. }
  47. function OnGetName(){
  48. const str = unit.form.mainfrm.OnGetName();
  49. const centerRegex = /center:([\d. ]+)/;
  50. const typeInfo = str.split(' ').slice(1, 4).join(' ');
  51. const centerMatch = str.match(centerRegex);
  52. const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
  53. ui.type.value = typeInfo;
  54. ui.x.value = centerCoords[0];
  55. ui.y.value = centerCoords[1];
  56. ui.z.value = centerCoords[2];
  57. }
  58. function OnModify(idx){
  59. if(idx ===0){
  60. let name = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).unique;
  61. unit.form.mainfrm.OnModifyArrows(ui.x.value, ui.y.value, ui.z.value, ui.pb_xn.value, ui.pb_yn.value, ui.pb_zn.value, name);
  62. let color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color;
  63. let Load = {
  64. "constraint":"集中载荷压力",
  65. "位置标记" :ui.type.value,
  66. "位置坐标x":ui.x.value,
  67. "位置坐标y":ui.y.value,
  68. "位置坐标z":ui.z.value,
  69. "压力方向xn":ui.pb_xn.value,
  70. "压力方向yn":ui.pb_yn.value,
  71. "压力方向zn":ui.pb_zn.value,
  72. "压力大小xr":ui.pb_xr.value,
  73. "压力大小yr":ui.pb_yr.value,
  74. "压力大小zr":ui.pb_zr.value,
  75. "cons_type":"arrows",
  76. "color":color,
  77. "unique":name
  78. };
  79. unit.form.tree.ModifyConstraint(Load);
  80. unit.form.mainfrm.OnCueline('修改成功', 'green');
  81. }else if(idx === 1){
  82. let name = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).unique;
  83. unit.form.mainfrm.OnModifyArrows(ui.x1.value, ui.y1.value, ui.z1.value, ui.fa_x.value, ui.fa_y.value, ui.fa_z.value, name);
  84. let color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color;
  85. let Load = {
  86. "constraint":"分布载荷压力",
  87. "位置标记" :ui.type1.value,
  88. "位置坐标x":ui.x1.value,
  89. "位置坐标y":ui.y1.value,
  90. "位置坐标z":ui.z1.value,
  91. "压力方向fa_x":ui.fa_x.value,
  92. "压力方向fa_y":ui.fa_y.value,
  93. "压力方向fa_z":ui.fa_z.value,
  94. "压力大小fa_xr":ui.fa_xr.value,
  95. "压力大小fa_yr":ui.fa_yr.value,
  96. "压力大小fa_zr":ui.fa_zr.value,
  97. "cons_type":"arrows",
  98. "color":color,
  99. "unique":name
  100. };
  101. unit.form.tree.ModifyConstraint(Load);
  102. unit.form.mainfrm.OnCueline('修改成功', 'green');
  103. }
  104. }
  105. function OnValueChange2(){
  106. if(ui.fa_x.value === '' || ui.fa_y.value === '' || ui.fa_z.value === '' || ui.fa_xr.value === '' || ui.fa_yr.value === '' || ui.fa_zr.value === ''){
  107. unit.form.mainfrm.OnChangePicture(3, 3);
  108. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: red;font-size:20px;">非常抱歉,您输入的数据不在范围内</h4>');
  109. unit.form.mainfrm.OnCueline('您输入的数据不在范围内!!!', 'red');
  110. }else{
  111. unit.form.mainfrm.OnChangePicture(3, 1);
  112. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入了正确的数据</h4>');
  113. unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
  114. }
  115. }
  116. function OnChangeValue(){
  117. if(ui.pb_xn.value === '' || ui.pb_yn.value === '' || ui.pb_zn.value === '' || ui.pb_xr.value === '' || ui.pb_yr.value === '' || ui.pb_zr.value === ''){
  118. unit.form.mainfrm.OnChangePicture(3, 3);
  119. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: red;font-size:20px;">非常抱歉,您输入的数据不在范围内</h4>');
  120. unit.form.mainfrm.OnCueline('您输入的数据不在范围内!!!', 'red');
  121. }else{
  122. unit.form.mainfrm.OnChangePicture(3, 1);
  123. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入了正确的数据</h4>');
  124. unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
  125. }
  126. }
  127. function OnReturn(){
  128. unit.form.mainfrm.menu(4);
  129. }
  130. function OnFrameSelect(){
  131. let temp = unit.form.tree.GetCurUniqueName();
  132. let name = temp;
  133. let constrain_data = model.acax_app.model.constrain.Database();
  134. //console.log(workcondition_data);
  135. let i = 0;
  136. let j = 0;
  137. let constrain_arr = Object.keys(constrain_data.db);
  138. //console.log(constrain_data.db);
  139. name = name + "force0";
  140. while(1){
  141. for( i = 0;i < constrain_arr.length;++i) {
  142. if(constrain_data.db[constrain_arr[i]].unique === name) {
  143. ++j;
  144. name = temp + "force" + j;
  145. break;
  146. }
  147. }
  148. if(i === constrain_arr.length) {
  149. break;
  150. }
  151. }
  152. let color = unit.form.tree.getRandomHexColor();
  153. let name1 = unit.form.mainfrm.OnArrows(ui.x1.value, ui.y1.value, ui.z1.value, ui.fa_x.value, ui.fa_y.value, ui.fa_z.value, name);
  154. name1 = name1.replace(temp, "");
  155. let Load = {
  156. "constraint":"分布载荷压力",
  157. "位置标记" :ui.type1.value,
  158. "位置坐标x":ui.x1.value,
  159. "位置坐标y":ui.y1.value,
  160. "位置坐标z":ui.z1.value,
  161. "压力方向fa_x":ui.fa_x.value,
  162. "压力方向fa_y":ui.fa_y.value,
  163. "压力方向fa_z":ui.fa_z.value,
  164. "压力大小fa_xr":ui.fa_xr.value,
  165. "压力大小fa_yr":ui.fa_yr.value,
  166. "压力大小fa_zr":ui.fa_zr.value,
  167. "cons_type":"arrows",
  168. "color":color,
  169. "unique":name
  170. };
  171. console.log(name1);
  172. if(ui.type1.value === '--') {
  173. unit.form.mainfrm.OnCueline('您未添加压力位置', 'red');
  174. }else{
  175. unit.form.tree.CreateBoundary(Load, name1);
  176. unit.form.mainfrm.OnCueline('您已将压力数据进行保存,请按鼠标右键选中您要施加约束的物体,并按快捷键R或者r进行添加!', 'green');
  177. }
  178. }
  179. function OnArrowFrame(){
  180. }
  181. function OnArrow(){
  182. let temp = unit.form.tree.GetCurUniqueName();
  183. let name = temp;
  184. let constrain_data = model.acax_app.model.constrain.Database();
  185. //console.log(workcondition_data);
  186. let i = 0;
  187. let j = 0;
  188. let constrain_arr = Object.keys(constrain_data.db);
  189. //console.log(constrain_data.db);
  190. name = name + "force0";
  191. while(1){
  192. for( i = 0;i < constrain_arr.length;++i) {
  193. if(constrain_data.db[constrain_arr[i]].unique === name) {
  194. ++j;
  195. name = temp + "force" + j;
  196. break;
  197. }
  198. }
  199. if(i === constrain_arr.length) {
  200. break;
  201. }
  202. }
  203. let name1 = unit.form.mainfrm.OnArrows(ui.x.value, ui.y.value, ui.z.value, ui.pb_xn.value, ui.pb_yn.value, ui.pb_zn.value, name);
  204. name1 = name1.replace(temp, "");
  205. let color = unit.form.tree.getRandomHexColor();
  206. unit.form.mainfrm.OnChangePicture(3, 2);
  207. let Load = {
  208. "constraint":"集中载荷压力",
  209. "位置标记" :ui.type.value,
  210. "位置坐标x":ui.x.value,
  211. "位置坐标y":ui.y.value,
  212. "位置坐标z":ui.z.value,
  213. "压力方向xn":ui.pb_xn.value,
  214. "压力方向yn":ui.pb_yn.value,
  215. "压力方向zn":ui.pb_zn.value,
  216. "压力大小xr":ui.pb_xr.value,
  217. "压力大小yr":ui.pb_yr.value,
  218. "压力大小zr":ui.pb_zr.value,
  219. "cons_type":"arrows",
  220. "color":color,
  221. "unique":name
  222. };
  223. if(ui.type.value === '--') {
  224. unit.form.mainfrm.OnCueline('您未添加压力位置', 'red');
  225. }else{
  226. unit.form.tree.CreateBoundary(Load, name1);
  227. unit.form.mainfrm.OnCueline('您已将压力数据和框选范围进行保存,请按鼠标右键选中您要施加约束的物体,并按快捷键R或者r进行添加以及快捷键U或u者进行框选!', 'green');
  228. }
  229. }
  230. function OnChangeIndex(idx) {
  231. ui.force_arr.index = parseInt(idx);
  232. }
  233. function OnChangeForce(idx){
  234. ui.stack_force.index = parseInt(idx);
  235. }
  236. //The message corresponding callback executed by the docker pane.
  237. // when calling [side_pane].fireEvent(type,para) in the main form.
  238. function OnParentDockerMessage(type, para) {
  239. }
  240. //////////////////////////////////////////////////////////////////////////
  241. // Utils Functions.
  242. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  243. function onDragFile(filepath) {
  244. }
  245. function PUI(cb) {
  246. if(pui){cb();}
  247. }
  248. /*Usage of BLOCK_EVENT
  249. BLOCK_EVENT(()=>{
  250. ui.[name].[var] = ...;
  251. });
  252. */
  253. CW_DeclareVariable("idx",
  254. val => {
  255. ui.force_arr.index = val;
  256. }, () => {});
  257. CW_DeclareVariable("index",
  258. val => {
  259. ui.stack_force.index = val;
  260. }, () => {});
  261. //集中载荷
  262. CW_DeclareVariable("setConstraint0",
  263. val => {
  264. ui.type.value = val["位置标记"];
  265. ui.x.value=val["位置坐标x"];
  266. ui.y.value=val["位置坐标y"];
  267. ui.z.value=val["位置坐标z"];
  268. ui.pb_xn.value = val["压力方向xn"];
  269. ui.pb_yn.value = val["压力方向yn"];
  270. ui.pb_zn.value = val["压力方向zn"];
  271. ui.pb_xr.value = val["压力大小xr"];
  272. ui.pb_yr.value = val["压力大小yr"];
  273. ui.pb_zr.value = val["压力大小zr"];
  274. }, () => {});
  275. //分布载荷
  276. CW_DeclareVariable("setConstraint1",
  277. val => {
  278. ui.type1.value = val["位置标记"];
  279. ui.x1.value= val["位置坐标x"];
  280. ui.y1.value= val["位置坐标y"];
  281. ui.z1.value= val["位置坐标z"];
  282. ui.fa_x.value = val["压力方向fa_x"];
  283. ui.fa_y.value = val["压力方向fa_y"];
  284. ui.fa_z.value = val["压力方向fa_z"];
  285. ui.fa_xr.value = val["压力大小fa_xr"];
  286. ui.fa_yr.value = val["压力大小fa_yr"];
  287. ui.fa_zr.value = val["压力大小fa_zr"];
  288. }, () => {});
  289. function BLOCK_EVENT(cb) {
  290. ui.block_event = true;
  291. cb();
  292. ui.block_event = false;
  293. }
  294. //////////////////////////////////////////////////////////////////////////
  295. // template codes for cw callback js.
  296. function CW_DeclareVariable(name, setter, getter) {
  297. if(typeof(__DeclareVariable) === 'function') {
  298. __DeclareVariable(name, setter, getter);
  299. }
  300. }
  301. function CW_DeclareOuterVariable(name) {
  302. if(typeof(__DeclareOuterVariable) === 'function') {
  303. __DeclareOuterVariable(name);
  304. }
  305. }