physics_material_pane.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. model.write(str1, model.getCurrentDirectory() + '/data/material.txt');
  105. unit.form.mainfrm.OnSend('materials ' + str1);
  106. unit.form.mainfrm.OnChangePicture(2, 2);
  107. let color = unit.form.tree.getRandomHexColor();
  108. let mat = {
  109. "泊松比": ui.phy_poi.value,
  110. "密度(g/cm^3)":ui.phy_density.value,
  111. "屈服强度":ui.phy_yie.value,
  112. "弹性模量(MPa)":ui.phy_ela.value,
  113. "color":color,
  114. "Id":ui.phy_id.value
  115. };
  116. if(!model.global_ctrl[0] || !model.global_ctrl[1] || !model.global_ctrl[2] || !model.global_ctrl[3]) {
  117. unit.form.mainfrm.OnCueline('未满足创建条件', 'red');
  118. return;
  119. }
  120. unit.form.tree.CreateMaterial(mat);
  121. unit.form.mainfrm.OnCueline('恭喜您,材料添加成功!', 'green');
  122. }
  123. function OnDeleteValue() {
  124. myArray.splice(parseFloat(ui.listBox.index), 1);
  125. console.log(ui.listBox.index);
  126. ui.listBox.list = [
  127. myArray
  128. ];
  129. unit.form.mainfrm.OnCueline('非常抱歉,您记录的数据已得到了删除!', 'red');
  130. //ui.cueline.value += '已删除\n';
  131. //ui.cueline.row = -1;
  132. }
  133. function OnAddValue() {
  134. 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);
  135. myArray.push(value);
  136. ui.listBox.list = [
  137. myArray
  138. ];
  139. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: green;font-size:20px;">恭喜您,您输入的数据已得到了记录!</h4>');
  140. unit.form.mainfrm.OnCueline('恭喜您,您输入的数据已得到了记录!', 'green');
  141. //ui.cueline.value += '已添加\n';
  142. //ui.cueline.row = -1;
  143. }
  144. //The message corresponding callback executed by the docker pane.
  145. // when calling [side_pane].fireEvent(type,para) in the main form.
  146. function OnParentDockerMessage(type, para) {
  147. }
  148. //////////////////////////////////////////////////////////////////////////
  149. // Utils Functions.
  150. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  151. function onDragFile(filepath) {
  152. }
  153. function PUI(cb) {
  154. if(pui){cb();}
  155. }
  156. /*Usage of BLOCK_EVENT
  157. BLOCK_EVENT(()=>{
  158. ui.[name].[var] = ...;
  159. });
  160. */
  161. function BLOCK_EVENT(cb) {
  162. ui.block_event = true;
  163. cb();
  164. ui.block_event = false;
  165. }
  166. CW_DeclareVariable("pb_ID",
  167. val => {
  168. ui.phy_id.value = val;
  169. }, () => {});
  170. CW_DeclareVariable("setmaterial",
  171. material => {
  172. ui.phy_poi.value = material["泊松比"];
  173. ui.phy_density.value = material["密度(g/cm^3)"];
  174. ui.phy_yie.value = material["屈服强度"];
  175. ui.phy_ela.value = material["弹性模量(MPa)"];
  176. ui.phy_id.value = material.Id;
  177. }, () => {});
  178. //////////////////////////////////////////////////////////////////////////
  179. // template codes for cw callback js.
  180. function CW_DeclareVariable(name, setter, getter) {
  181. if(typeof(__DeclareVariable) === 'function') {
  182. __DeclareVariable(name, setter, getter);
  183. }
  184. }
  185. function CW_DeclareOuterVariable(name) {
  186. if(typeof(__DeclareOuterVariable) === 'function') {
  187. __DeclareOuterVariable(name);
  188. }
  189. }