boundary_force_pane.js 14 KB

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