boundary_brep_pane.js 7.7 KB

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