boundary_force_pane.js 14 KB

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