physics_material_pane.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color;
  32. let mat = {
  33. "泊松比": ui.phy_poi.value,
  34. "密度(g/cm^3)":ui.phy_density.value,
  35. "屈服强度":ui.phy_yie.value,
  36. "弹性模量(MPa)":ui.phy_ela.value,
  37. "color":color,
  38. "Id":ui.phy_id.value
  39. };
  40. unit.form.tree.ModifyMaterial(mat);
  41. }
  42. function OnId(){
  43. }
  44. function OnDen(){
  45. if(ui.phy_density.value <= 0){
  46. unit.form.mainfrm.OnChangePicture(2, 3);
  47. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: red;font-size:20px;">非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!</h4>');
  48. unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red');
  49. }
  50. if(ui.phy_density.value > 0){
  51. unit.form.mainfrm.OnChangePicture(2, 1);
  52. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入了正确的数据!</h4>');
  53. unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
  54. }
  55. }
  56. function OnEla(){
  57. if(ui.phy_ela.value <= 0){
  58. unit.form.mainfrm.OnChangePicture(2, 3);
  59. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: red;font-size:20px;">非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!</h4>');
  60. unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red');
  61. }
  62. if(ui.phy_ela.value > 0){
  63. unit.form.mainfrm.OnChangePicture(2, 1);
  64. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入了正确的数据!</h4>');
  65. unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
  66. }
  67. }
  68. function OnPoi(){
  69. if(ui.phy_poi.value <= 0){
  70. unit.form.mainfrm.OnChangePicture(2, 3);
  71. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: red;font-size:20px;">非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!</h4>');
  72. unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red');
  73. }
  74. if(ui.phy_poi.value > 0){
  75. unit.form.mainfrm.OnChangePicture(2, 1);
  76. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入了正确的数据!</h4>');
  77. unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
  78. }
  79. }
  80. function OnYie(){
  81. if(ui.phy_yie.value <= 0){
  82. unit.form.mainfrm.OnChangePicture(2, 3);
  83. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: red;font-size:20px;">非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!</h4>');
  84. unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red');
  85. }
  86. if(ui.phy_yie.value > 0){
  87. unit.form.mainfrm.OnChangePicture(2, 1);
  88. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入了正确的数据!</h4>');
  89. unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
  90. }
  91. }
  92. function OnReturnMenu(){
  93. unit.form.mainfrm.menu(2);
  94. }
  95. function OnMaterialFiles() {
  96. //ui.pb_ok.enable = true;
  97. if(myArray.length === 0){
  98. unit.form.mainfrm.OnChangePicture(2, 3);
  99. return;
  100. }
  101. var str = myArray[ui.listBox.index];
  102. var arr = str.split(",");
  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. let color = unit.form.tree.getRandomHexColor();
  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. "color":color,
  115. "Id":ui.phy_id.value
  116. };
  117. unit.form.tree.CreateMaterial(mat);
  118. unit.form.mainfrm.OnCueline('恭喜您,材料添加成功!', 'green');
  119. }
  120. function OnDeleteValue() {
  121. myArray.splice(parseFloat(ui.listBox.index), 1);
  122. console.log(ui.listBox.index);
  123. ui.listBox.list = [
  124. myArray
  125. ];
  126. unit.form.mainfrm.OnCueline('非常抱歉,您记录的数据已得到了删除!', 'red');
  127. //ui.cueline.value += '已删除\n';
  128. //ui.cueline.row = -1;
  129. }
  130. function OnAddValue() {
  131. 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);
  132. myArray.push(value);
  133. ui.listBox.list = [
  134. myArray
  135. ];
  136. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入的数据已得到了记录!</h4>');
  137. unit.form.mainfrm.OnCueline('恭喜您,您输入的数据已得到了记录!', 'green');
  138. //ui.cueline.value += '已添加\n';
  139. //ui.cueline.row = -1;
  140. }
  141. //The message corresponding callback executed by the docker pane.
  142. // when calling [side_pane].fireEvent(type,para) in the main form.
  143. function OnParentDockerMessage(type, para) {
  144. }
  145. //////////////////////////////////////////////////////////////////////////
  146. // Utils Functions.
  147. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  148. function onDragFile(filepath) {
  149. }
  150. function PUI(cb) {
  151. if(pui){cb();}
  152. }
  153. /*Usage of BLOCK_EVENT
  154. BLOCK_EVENT(()=>{
  155. ui.[name].[var] = ...;
  156. });
  157. */
  158. function BLOCK_EVENT(cb) {
  159. ui.block_event = true;
  160. cb();
  161. ui.block_event = false;
  162. }
  163. CW_DeclareVariable("pb_ID",
  164. val => {
  165. ui.phy_id.value = val;
  166. }, () => {});
  167. CW_DeclareVariable("setmaterial",
  168. material => {
  169. ui.phy_poi.value = material["泊松比"];
  170. ui.phy_density.value = material["密度(g/cm^3)"];
  171. ui.phy_yie.value = material["屈服强度"];
  172. ui.phy_ela.value = material["弹性模量(MPa)"];
  173. ui.phy_id.value = material.Id;
  174. }, () => {});
  175. //////////////////////////////////////////////////////////////////////////
  176. // template codes for cw callback js.
  177. function CW_DeclareVariable(name, setter, getter) {
  178. if(typeof(__DeclareVariable) === 'function') {
  179. __DeclareVariable(name, setter, getter);
  180. }
  181. }
  182. function CW_DeclareOuterVariable(name) {
  183. if(typeof(__DeclareOuterVariable) === 'function') {
  184. __DeclareOuterVariable(name);
  185. }
  186. }