boundary_brep_pane.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. var faceId = [];
  26. //////////////////////////////////////////////////////////////////////////
  27. // Callback Functions.
  28. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  29. function OnModify(){
  30. let name = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).unique;
  31. unit.form.mainfrm.OnModifySpheres(ui.x.value, ui.y.value, ui.z.value, ui.radius.value, name);
  32. let color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color;
  33. let Load = {
  34. "constraint":"rb3",
  35. "type":ui.type.value,
  36. "x":ui.x.value,
  37. "y":ui.y.value,
  38. "z":ui.z.value,
  39. "types":ui.types.value,
  40. "radius":ui.radius.value,
  41. "编号":name,
  42. "cons_type":"rb3",
  43. "color":color,
  44. "unique":name
  45. };
  46. unit.form.tree.ModifyConstraint(Load);
  47. unit.form.mainfrm.OnCueline('修改成功', 'green');
  48. }
  49. function OnGetName(){
  50. const str = unit.form.mainfrm.OnGetName();
  51. // 匹配center坐标对应内容的正则表达式
  52. const centerRegex = /center:([\d. ]+)/;
  53. const typeInfo = str.split(' ').slice(1, 4).join(' ');
  54. const centerMatch = str.match(centerRegex);
  55. const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
  56. ui.types.value = typeInfo;
  57. ui.x.value = parseFloat(centerCoords[0]).toFixed(0);
  58. ui.y.value = parseFloat(centerCoords[1]).toFixed(0);
  59. ui.z.value = parseFloat(centerCoords[2]).toFixed(0);
  60. }
  61. function OnAddFace(){
  62. const str = unit.form.mainfrm.OnGetFaceName();
  63. // 匹配type对应内容的正则表达式,以type:开头,后面跟着非冒号的内容直到遇到空格或者字符串结束
  64. const typeRegex = /type:([^point]+)/;
  65. // 匹配center坐标对应内容的正则表达式
  66. const centerRegex = /point:([\d. ]+)/;
  67. const typeMatch = str.match(typeRegex);
  68. const typeInfo = typeMatch? typeMatch[1] : null;
  69. const centerMatch = str.match(centerRegex);
  70. const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
  71. console.log(centerCoords);
  72. ui.type.value = typeInfo;
  73. let parts = typeInfo.split(' ');
  74. let result = parts[2];
  75. console.log(unit.form.mainfrm.OnGenerateGuass(result));
  76. }
  77. function OnReturn(){
  78. unit.form.mainfrm.menu(4);
  79. }
  80. //Rb3
  81. function OnBrep(){
  82. let temp = unit.form.tree.GetCurUniqueName();
  83. let name = temp;
  84. let constrain_data = model.acax_app.model.constrain.Database();
  85. let i = 0;
  86. let j = 0;
  87. let constrain_arr = Object.keys(constrain_data.db);
  88. name = name + "rb3 0";
  89. while(1){
  90. for( i = 0;i < constrain_arr.length;++i) {
  91. if(constrain_data.db[constrain_arr[i]].unique === name) {
  92. ++j;
  93. name = temp + "rb3 " + j;
  94. break;
  95. }
  96. }
  97. if(i === constrain_arr.length) {
  98. break;
  99. }
  100. }
  101. let name1 = unit.form.mainfrm.OnSpheres(ui.x.value, ui.y.value, ui.z.value, ui.radius.value, name);
  102. console.log(name1);
  103. let match = name1.split(":")[1];
  104. name1 = name1.replace(temp, "").split(" Breps:")[0];
  105. let color = unit.form.tree.getRandomHexColor();
  106. let Load = {
  107. "constraint":"rb3",
  108. "type":ui.type.value,
  109. "x":ui.x.value,
  110. "y":ui.y.value,
  111. "z":ui.z.value,
  112. "types":ui.types.value,
  113. "radius":ui.radius.value,
  114. "编号":match,
  115. "cons_type":"rb3",
  116. "color":color,
  117. "unique":name
  118. };
  119. console.log(name1);
  120. if(ui.type.value === '--' || ui.types.value === '--') {
  121. unit.form.mainfrm.OnCueline('未添加连界面和节点信息', 'red');
  122. }else{
  123. unit.form.tree.CreateBoundary(Load, name1);
  124. unit.form.mainfrm.OnCueline('您完成了rb3添加!', 'green');
  125. }
  126. }
  127. function OnPickUp(){
  128. unit.form.mainfrm.OnSend('rendererFace ' + ui.listBox.value);
  129. unit.form.mainfrm.OnChangePicture(3, 1);
  130. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: Blue;font-size:20px;">选取的面已在界面中选中,请不要忘记生成它的Brep文件!</h4>');
  131. unit.form.mainfrm.OnCueline('选取的面已在界面中选中,请不要忘记生成它的Brep文件!', 'blue');
  132. }
  133. function OnShow(){
  134. unit.form.mainfrm.OnSend('selectId');
  135. unit.form.mainfrm.OnChangePicture(3, 1);
  136. //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: Blue;font-size:20px;">拾取的各个面ID已在记录中,注意事项:选中功能不能有空值,否则界面会崩溃!</h4>');
  137. unit.form.mainfrm.OnCueline('拾取的各个面ID已在记录中,注意事项:选中功能不能有空值,否则界面会崩溃!', 'blue');
  138. }
  139. //The message corresponding callback executed by the docker pane.
  140. // when calling [side_pane].fireEvent(type,para) in the main form.
  141. function OnParentDockerMessage(type, para) {
  142. }
  143. //////////////////////////////////////////////////////////////////////////
  144. // Utils Functions.
  145. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  146. function onDragFile(filepath) {
  147. }
  148. function PUI(cb) {
  149. if(pui){cb();}
  150. }
  151. CW_DeclareVariable("list",
  152. val => {
  153. ui.listBox.list = [
  154. val
  155. ];
  156. }, () => {});
  157. /*Usage of BLOCK_EVENT
  158. BLOCK_EVENT(()=>{
  159. ui.[name].[var] = ...;
  160. });
  161. */
  162. //rb3
  163. CW_DeclareVariable("setConstraint",
  164. val => {
  165. ui.type.value = val.type;
  166. ui.x.value = val.x;
  167. ui.y.value = val.y;
  168. ui.z.value = val.z;
  169. ui.types.value = val.types;
  170. ui.radius.value = val.radius;
  171. }, () => {});
  172. function BLOCK_EVENT(cb) {
  173. ui.block_event = true;
  174. cb();
  175. ui.block_event = false;
  176. }
  177. //////////////////////////////////////////////////////////////////////////
  178. // template codes for cw callback js.
  179. function CW_DeclareVariable(name, setter, getter) {
  180. if(typeof(__DeclareVariable) === 'function') {
  181. __DeclareVariable(name, setter, getter);
  182. }
  183. }
  184. function CW_DeclareOuterVariable(name) {
  185. if(typeof(__DeclareOuterVariable) === 'function') {
  186. __DeclareOuterVariable(name);
  187. }
  188. }