physics_material_pane.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. }
  12. //Callback after UI is fully loaded and displayed.
  13. function OnReady(reload, preview) {
  14. PUI(()=>{
  15. //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
  16. //The 'pui' variable is valid in all functions of this document.
  17. //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
  18. });
  19. }
  20. function OnCloseForm() {
  21. }
  22. function OnException(err) {
  23. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  24. }
  25. let myArray = [];
  26. //////////////////////////////////////////////////////////////////////////
  27. // Callback Functions.
  28. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  29. function OnModify(){
  30. // var name = ["泊松比", "密度(g/cm^3)", "屈服强度", "弹性模量(MPa)", "Id"];
  31. let mat = {
  32. "泊松比": ui.phy_poi.value,
  33. "密度(g/cm^3)":ui.phy_density.value,
  34. "屈服强度":ui.phy_yie.value,
  35. "弹性模量(MPa)":ui.phy_ela.value,
  36. "Id":ui.phy_id.value
  37. };
  38. unit.form.tree.ModifyMaterial(mat);
  39. }
  40. function OnId(){
  41. }
  42. function OnDen(){
  43. if(ui.phy_density.value <= 0){
  44. unit.form.mainfrm.OnChangePicture(2, 3);
  45. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: red;font-size:20px;">非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!</h4>');
  46. unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red');
  47. }
  48. if(ui.phy_density.value > 0){
  49. unit.form.mainfrm.OnChangePicture(2, 1);
  50. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入了正确的数据!</h4>');
  51. unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
  52. }
  53. }
  54. function OnEla(){
  55. if(ui.phy_ela.value <= 0){
  56. unit.form.mainfrm.OnChangePicture(2, 3);
  57. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: red;font-size:20px;">非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!</h4>');
  58. unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red');
  59. }
  60. if(ui.phy_ela.value > 0){
  61. unit.form.mainfrm.OnChangePicture(2, 1);
  62. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入了正确的数据!</h4>');
  63. unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
  64. }
  65. }
  66. function OnPoi(){
  67. if(ui.phy_poi.value <= 0){
  68. unit.form.mainfrm.OnChangePicture(2, 3);
  69. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: red;font-size:20px;">非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!</h4>');
  70. unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red');
  71. }
  72. if(ui.phy_poi.value > 0){
  73. unit.form.mainfrm.OnChangePicture(2, 1);
  74. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入了正确的数据!</h4>');
  75. unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
  76. }
  77. }
  78. function OnYie(){
  79. if(ui.phy_yie.value <= 0){
  80. unit.form.mainfrm.OnChangePicture(2, 3);
  81. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: red;font-size:20px;">非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!</h4>');
  82. unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red');
  83. }
  84. if(ui.phy_yie.value > 0){
  85. unit.form.mainfrm.OnChangePicture(2, 1);
  86. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入了正确的数据!</h4>');
  87. unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
  88. }
  89. }
  90. function OnReturnMenu(){
  91. unit.form.mainfrm.menu(2);
  92. }
  93. function OnMaterialFiles() {
  94. //ui.pb_ok.enable = true;
  95. if(myArray.length === 0){
  96. unit.form.mainfrm.OnChangePicture(2, 3);
  97. return;
  98. }
  99. var str = myArray[ui.listBox.index];
  100. var arr = str.split(",");
  101. //arr[0] = '0';
  102. //arr.splice(4, 1);
  103. var str1 = arr.join(' ');
  104. console.log(arr);
  105. model.write(str1, model.getCurrentDirectory() + '/data/material.txt');
  106. unit.form.mainfrm.OnSend('materials ' + str1);
  107. unit.form.mainfrm.OnChangePicture(2, 2);
  108. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,材料添加成功!</h4>');
  109. let mat = {
  110. "泊松比": ui.phy_poi.value,
  111. "密度(g/cm^3)":ui.phy_density.value,
  112. "屈服强度":ui.phy_yie.value,
  113. "弹性模量(MPa)":ui.phy_ela.value,
  114. "Id":ui.phy_id.value
  115. };
  116. unit.form.tree.CreateMaterial(mat);
  117. unit.form.mainfrm.OnCueline('恭喜您,材料添加成功!', 'green');
  118. //ui.cueline.value += '材料文件载入完毕\n';
  119. //ui.cueline.row = -1;
  120. }
  121. function OnDeleteValue() {
  122. myArray.splice(parseFloat(ui.listBox.index), 1);
  123. console.log(ui.listBox.index);
  124. ui.listBox.list = [
  125. myArray
  126. ];
  127. unit.form.mainfrm.OnCueline('非常抱歉,您记录的数据已得到了删除!', 'red');
  128. //ui.cueline.value += '已删除\n';
  129. //ui.cueline.row = -1;
  130. }
  131. function OnAddValue() {
  132. var value = ui.pb_Id.value + ',' + parseFloat(ui.phy_density.value) + ',' + parseFloat(ui.phy_ela.value) + ',' + parseFloat(ui.phy_poi.value) + ',' + parseFloat(ui.phy_yie.value) + ',' + parseFloat(ui.phy_id.value);
  133. myArray.push(value);
  134. ui.listBox.list = [
  135. myArray
  136. ];
  137. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入的数据已得到了记录!</h4>');
  138. unit.form.mainfrm.OnCueline('恭喜您,您输入的数据已得到了记录!', 'green');
  139. //ui.cueline.value += '已添加\n';
  140. //ui.cueline.row = -1;
  141. }
  142. //The message corresponding callback executed by the docker pane.
  143. // when calling [side_pane].fireEvent(type,para) in the main form.
  144. function OnParentDockerMessage(type, para) {
  145. }
  146. //////////////////////////////////////////////////////////////////////////
  147. // Utils Functions.
  148. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  149. function onDragFile(filepath) {
  150. }
  151. function PUI(cb) {
  152. if(pui){cb();}
  153. }
  154. /*Usage of BLOCK_EVENT
  155. BLOCK_EVENT(()=>{
  156. ui.[name].[var] = ...;
  157. });
  158. */
  159. function BLOCK_EVENT(cb) {
  160. ui.block_event = true;
  161. cb();
  162. ui.block_event = false;
  163. }
  164. CW_DeclareVariable("pb_ID",
  165. val => {
  166. ui.phy_id.value = val;
  167. }, () => {});
  168. CW_DeclareVariable("setmaterial",
  169. material => {
  170. ui.phy_poi.value = material["泊松比"];
  171. ui.phy_density.value = material["密度(g/cm^3)"];
  172. ui.phy_yie.value = material["屈服强度"];
  173. ui.phy_ela.value = material["弹性模量(MPa)"];
  174. ui.phy_id.value = material.Id;
  175. }, () => {});
  176. //////////////////////////////////////////////////////////////////////////
  177. // template codes for cw callback js.
  178. function CW_DeclareVariable(name, setter, getter) {
  179. if(typeof(__DeclareVariable) === 'function') {
  180. __DeclareVariable(name, setter, getter);
  181. }
  182. }
  183. function CW_DeclareOuterVariable(name) {
  184. if(typeof(__DeclareOuterVariable) === 'function') {
  185. __DeclareOuterVariable(name);
  186. }
  187. }