boundary_brep_pane.js 8.4 KB

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