boundary_spring_pane.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. controlAuto(true);
  12. control(true);
  13. }
  14. //Callback after UI is fully loaded and displayed.
  15. function OnReady(reload, preview) {
  16. PUI(()=>{
  17. //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
  18. //The 'pui' variable is valid in all functions of this document.
  19. //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
  20. });
  21. }
  22. function OnCloseForm() {
  23. }
  24. function OnException(err) {
  25. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  26. }
  27. var myStressArray = [];
  28. //////////////////////////////////////////////////////////////////////////
  29. // Callback Functions.
  30. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  31. var beamPicker = false;
  32. function OnBeamPicker(){
  33. pickPeiDian = !pickPeiDian;
  34. if (pickPeiDian === true) {
  35. var id = parent.setTimeout(() => {
  36. unit.form.mainfrm.OnSend('arrowOpen');
  37. }, 100);
  38. var id = parent.setTimeout(() => {
  39. unit.form.mainfrm.OnSend('0');
  40. }, 200);
  41. unit.form.mainfrm.OnSend('peidianPicker 2 ' + model.getCurrentDirectory() + '/data/faceID/pei.txt' + ' ' + (parseInt(ui.pb_BeamID.value) - 1));
  42. ui.pb_BeamPick.valid = true;
  43. }
  44. if (pickPeiDian === false) {
  45. var id = parent.setTimeout(() => {
  46. unit.form.mainfrm.OnSend('0');
  47. }, 100);
  48. unit.form.mainfrm.OnSend('arrowClose');
  49. ui.pb_BeamPick.valid = false;
  50. }
  51. }
  52. var pickPeiDian = false;
  53. function OnPeidianPicker() {
  54. pickPeiDian = !pickPeiDian;
  55. if (pickPeiDian === true) {
  56. var id = parent.setTimeout(() => {
  57. unit.form.mainfrm.OnSend('arrowOpen');
  58. }, 100);
  59. var id = parent.setTimeout(() => {
  60. unit.form.mainfrm.OnSend('0');
  61. }, 200);
  62. unit.form.mainfrm.OnSend('peidianPicker 1 ' + model.getCurrentDirectory() + '/data/faceID/pei.txt' + ' 0');
  63. ui.pb_peidian.valid = true;
  64. }
  65. if (pickPeiDian === false) {
  66. var id = parent.setTimeout(() => {
  67. unit.form.mainfrm.OnSend('0');
  68. }, 100);
  69. unit.form.mainfrm.OnSend('arrowClose');
  70. ui.pb_peidian.valid = false;
  71. }
  72. }
  73. function OnHand(){
  74. controlAuto(false);
  75. }
  76. function controlAuto(idx){
  77. ui.pb_peidian.enable = idx;
  78. ui.pb_BeamID.enable = idx;
  79. ui.pb_BeamPick.enable = idx;
  80. //ui.pb_start.enable = idx;
  81. //ui.pb_end.enable = idx;
  82. ui.pb_startID.visible = idx;
  83. ui.pb_endID.visible = idx;
  84. ui.pb_Auto.enable = !idx;
  85. ui.pb_hand.enable = idx;
  86. if(idx === true){
  87. ui.pb_judge.value = 1;
  88. model.setJudge(1);
  89. }
  90. if(idx === false){
  91. ui.pb_judge.value = 0;
  92. model.setJudge(0);
  93. }
  94. }
  95. function OnAuto(){
  96. controlAuto(true);
  97. }
  98. function OnDeleteFixFace() {
  99. var str = myStressArray[parseFloat(ui.listbox.index)];
  100. var str1 = str.split(',');
  101. var id = parent.setTimeout(() => {
  102. unit.form.mainfrm.OnSend('0');
  103. }, 100);
  104. unit.form.mainfrm.OnSend('showSpring ' + (parseInt(str1[0]) - 1) + ' 0 1 0 0' );
  105. myStressArray.splice(parseFloat(ui.listbox.index), 1);
  106. ui.listbox.list = [
  107. myStressArray
  108. ];
  109. }
  110. function OnAddFixFace() {
  111. //unit.form.mainfrm.OnChangeWindows(2);
  112. ui.pb_ID.value = parseInt(ui.pb_ID.value) + 1;
  113. if( ui.pb_judge.value === '0'){
  114. var value = ui.pb_ID.value + ',*,' + parseFloat(ui.pb_x.value) + ',' + parseFloat(ui.pb_y.value) + ',' + parseFloat(ui.pb_z.value) + ',' + parseFloat(ui.pb_X.value) + ',' + parseFloat(ui.pb_Y.value)+ ',' + parseFloat(ui.pb_Z.value) + ',' + ui.pb_springStiffness.value;
  115. }
  116. if( ui.pb_judge.value === '1'){
  117. var value = ui.pb_ID.value + ',' + parseFloat(ui.pb_startID.value) + ',' + parseFloat(ui.pb_x.value) + ',' + parseFloat(ui.pb_y.value) + ',' + parseFloat(ui.pb_z.value) + ',' + parseFloat(ui.pb_endID.value) + ',' + parseFloat(ui.pb_X.value) + ',' + parseFloat(ui.pb_Y.value)+ ',' + parseFloat(ui.pb_Z.value) + ',' + ui.pb_springStiffness.value;
  118. }
  119. var id = parent.setTimeout(() => {
  120. unit.form.mainfrm.OnSend('0');
  121. }, 100);
  122. unit.form.mainfrm.OnSend('springLine ' + parseFloat(ui.pb_x.value) + ' ' + parseFloat(ui.pb_y.value) + ' ' + parseFloat(ui.pb_z.value) + ' ' + parseFloat(ui.pb_X.value) + ' ' + parseFloat(ui.pb_Y.value) + ' ' + parseFloat(ui.pb_Z.value));
  123. myStressArray.push(value);
  124. ui.listbox.list = [
  125. myStressArray
  126. ];
  127. }
  128. function control(idx){
  129. ui.pb_start.enable = !idx;
  130. ui.pb_startPoint.enable = idx;
  131. ui.pb_x.enable = idx;
  132. ui.pb_y.enable = idx;
  133. ui.pb_z.enable = idx;
  134. ui.pb_end.enable = idx;
  135. ui.pb_endPoint.enable = !idx;
  136. ui.pb_X.enable = !idx;
  137. ui.pb_Y.enable = !idx;
  138. ui.pb_Z.enable = !idx;
  139. if(idx === true){
  140. ui.pb_StartEnd.value = 0;
  141. model.setStartEnd(0);
  142. }
  143. if(idx === false){
  144. ui.pb_StartEnd.value = 1;
  145. model.setStartEnd(1);
  146. }
  147. }
  148. function OnEed(){
  149. control(false);
  150. }
  151. function OnStart(){
  152. control(true);
  153. }
  154. function OnLoad(){
  155. /*
  156. var id = parent.setTimeout(() => {
  157. unit.form.mainfrm.OnSend('0');
  158. }, 100);
  159. unit.form.mainfrm.OnSend('line ' + ui.pb_x.value + ' ' + ui.pb_y.value + ' ' + ui.pb_z.value + ' ' + ui.pb_X.value + ' ' + ui.pb_Y.value + ' ' + ui.pb_Z.value);*/
  160. var value = '';
  161. for (var i = 0; i < myStressArray.length; i++) {
  162. var str = myStressArray[i].split(',');
  163. value += '* ' + str[1] + ' ' + str[5] + '\n' +
  164. '# ' + str[9] + '\n';
  165. }
  166. model.write(value, model.getCurrentDirectory() + '/data/spring/spring.txt');
  167. }
  168. //The message corresponding callback executed by the docker pane.
  169. // when calling [side_pane].fireEvent(type,para) in the main form.
  170. function OnParentDockerMessage(type, para) {
  171. }
  172. //////////////////////////////////////////////////////////////////////////
  173. // Utils Functions.
  174. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  175. var arrayPoint = [];
  176. CW_DeclareVariable("message",
  177. val => {
  178. //console.log(val + '\n');
  179. console.log(val[0]);
  180. var arrayPoint = [];
  181. arrayPoint = val;
  182. if(ui.pb_judge.value === 0) {
  183. //var str = val.split(' ');
  184. if(ui.pb_StartEnd.value === 0){
  185. ui.pb_x.value = arrayPoint[0];
  186. ui.pb_y.value = arrayPoint[1];
  187. ui.pb_z.value = arrayPoint[2];
  188. }
  189. if(ui.pb_StartEnd.value === 1){
  190. ui.pb_X.value = arrayPoint[0];
  191. ui.pb_Y.value = arrayPoint[1];
  192. ui.pb_Z.value = arrayPoint[2];
  193. }
  194. }
  195. if(ui.pb_judge.value === 1) {
  196. var str = val.split(' ');
  197. if(ui.pb_StartEnd.value === 0){
  198. ui.pb_x.value = str[0];
  199. ui.pb_y.value = str[1];
  200. ui.pb_z.value = str[2];
  201. ui.pb_startID.value = str[3];
  202. }
  203. if(ui.pb_StartEnd.value === 1){
  204. ui.pb_X.value = str[0];
  205. ui.pb_Y.value = str[1];
  206. ui.pb_Z.value = str[2];
  207. ui.pb_endID.value = str[3];
  208. }
  209. }
  210. }, () => {});
  211. CW_DeclareVariable("pb_x",
  212. val => {
  213. ui.pb_x.value = val;
  214. }, () => {});
  215. CW_DeclareVariable("pb_y",
  216. val => {
  217. ui.pb_y.value = val;
  218. }, () => {});
  219. CW_DeclareVariable("pb_z",
  220. val => {
  221. ui.pb_z.value = val;
  222. }, () => {});
  223. CW_DeclareVariable("pb_startID",
  224. val => {
  225. ui.pb_startID.value = val;
  226. }, () => {});
  227. CW_DeclareVariable("pb_X",
  228. val => {
  229. ui.pb_X.value = val;
  230. }, () => {});
  231. CW_DeclareVariable("pb_Y",
  232. val => {
  233. ui.pb_Y.value = val;
  234. }, () => {});
  235. CW_DeclareVariable("pb_Z",
  236. val => {
  237. ui.pb_Z.value = val;
  238. }, () => {});
  239. CW_DeclareVariable("pb_endID",
  240. val => {
  241. ui.pb_endID.value = val;
  242. }, () => {});
  243. CW_DeclareVariable("beam",
  244. val => {
  245. ui.pb_BeamID.list = val;
  246. }, () => {});
  247. function onDragFile(filepath) {
  248. }
  249. function PUI(cb) {
  250. if(pui){cb();}
  251. }
  252. /*Usage of BLOCK_EVENT
  253. BLOCK_EVENT(()=>{
  254. ui.[name].[var] = ...;
  255. });
  256. */
  257. function BLOCK_EVENT(cb) {
  258. ui.block_event = true;
  259. cb();
  260. ui.block_event = false;
  261. }
  262. //////////////////////////////////////////////////////////////////////////
  263. // template codes for cw callback js.
  264. function CW_DeclareVariable(name, setter, getter) {
  265. if(typeof(__DeclareVariable) === 'function') {
  266. __DeclareVariable(name, setter, getter);
  267. }
  268. }
  269. function CW_DeclareOuterVariable(name) {
  270. if(typeof(__DeclareOuterVariable) === 'function') {
  271. __DeclareOuterVariable(name);
  272. }
  273. }