geometry_nurbs_pane.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. //////////////////////////////////////////////////////////////////////////
  26. // Callback Functions.
  27. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  28. var pick = false;
  29. function OnPickUp() {
  30. pick = !pick;
  31. if (pick === true) {
  32. unit.form.mainfrm.pick(1);
  33. ui.pb_pick.valid = true;
  34. }
  35. if (pick === false) {
  36. unit.form.mainfrm.pick(2);
  37. ui.pb_pick.valid = false;
  38. }
  39. }
  40. function TransStr(str, len, prec) {
  41. var val = parseFloat(str);
  42. val = val.toPrecision(prec);
  43. str = val.toString();
  44. if(str[0] !== '-') {
  45. str = ' ' + str;
  46. }
  47. var str_len = str.length;
  48. var space_num = len - str_len;
  49. for(var loop = 0; loop < space_num; ++loop) {
  50. str = str + ' ';
  51. }
  52. return str;
  53. }
  54. function FilterNurbsInfo() {
  55. var ret = '';
  56. var surface_res = /Surfaces[\t ]+([0-9]+)[\r\n]+([0-9\t \.eE+\-\r\n]+)/.exec(ui.sci.document);
  57. if(surface_res) {
  58. var surface_num = parseInt(surface_res[1]);
  59. var surface_res_arr = surface_res[2].split(/[\t \r\n]+/);
  60. var base_idx = 0;
  61. var surface_id = 1;
  62. while(true) {
  63. var surface_output = 'Surface\n';
  64. var surface_type = parseInt(surface_res_arr[base_idx]);
  65. if(surface_type !== 9) {
  66. return ('第' + surface_id + '个曲面类型不是9, 暂时不被支持');
  67. }
  68. var flag = parseInt(surface_res_arr[base_idx + 1]);
  69. var order_u = parseInt(surface_res_arr[base_idx + 5]);
  70. var order_v = parseInt(surface_res_arr[base_idx + 6]);
  71. surface_output += ('#so' + ' ' + order_u + ' ' + order_v + '\n');
  72. var ctrl_pt_num_u = parseInt(surface_res_arr[base_idx + 7]);
  73. var ctrl_pt_num_v = parseInt(surface_res_arr[base_idx + 8]);
  74. var surface_para_num_u = parseInt(surface_res_arr[base_idx + 9]);
  75. var surface_para_num_v = parseInt(surface_res_arr[base_idx + 10]);
  76. var uv_para_idx_base = base_idx + 10 + ctrl_pt_num_u * ctrl_pt_num_v * 4 + 1;
  77. if(flag === 0) {
  78. uv_para_idx_base = base_idx + 10 + ctrl_pt_num_u * ctrl_pt_num_v * 3 + 1;
  79. }
  80. var surface_para_u_loop = 0;
  81. var u_para_arr = [];
  82. while(surface_para_u_loop < surface_para_num_u) {
  83. for(var loop = 0; loop < parseInt(surface_res_arr[uv_para_idx_base + 1]); ++loop) {
  84. u_para_arr.push(TransStr(surface_res_arr[uv_para_idx_base], 24, 10));
  85. }
  86. surface_para_u_loop++;
  87. uv_para_idx_base += 2;
  88. }
  89. surface_output += ('#su' + ' ' + u_para_arr.length + '\n');
  90. surface_output += u_para_arr.join('\n');
  91. surface_output += '\n';
  92. var surface_para_v_loop = 0;
  93. var v_para_arr = [];
  94. while(surface_para_v_loop < surface_para_num_v) {
  95. for(var loop = 0; loop < parseInt(surface_res_arr[uv_para_idx_base + 1]); ++loop) {
  96. v_para_arr.push(TransStr(surface_res_arr[uv_para_idx_base], 24, 10));
  97. }
  98. surface_para_v_loop++;
  99. uv_para_idx_base += 2;
  100. }
  101. var ctrl_pt_base_idx = base_idx + 11;
  102. base_idx = uv_para_idx_base;
  103. surface_output += ('#sv' + ' ' + v_para_arr.length + '\n');
  104. surface_output += v_para_arr.join('\n');
  105. surface_output += '\n';
  106. surface_output += '#suvp ' + ctrl_pt_num_u + ' ' + ctrl_pt_num_v + '\n';
  107. for(var loop = 0; loop < ctrl_pt_num_u * ctrl_pt_num_v; ++loop) {
  108. if(flag === 1) {
  109. surface_output += (TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 4 + 0], 24, 13) + ' ' +
  110. TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 4 + 1], 24, 13) + ' ' +
  111. TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 4 + 2], 24, 13) + ' ' +
  112. TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 4 + 3], 24, 13) + '\n');
  113. } else {
  114. surface_output += (TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 3 + 0], 24, 13) + ' ' +
  115. TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 3 + 1], 24, 13) + ' ' +
  116. TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 3 + 2], 24, 13) + ' ' +
  117. '1\n');
  118. }
  119. }
  120. ret += (surface_output);
  121. ret += '\n';
  122. if(surface_id === surface_num) {
  123. break;
  124. }
  125. surface_id++;
  126. }
  127. }
  128. //var curve_res = /Curves[\t ]+([0-9]+)[\r\n]+([0-9]+[\t ]+.*[\r\n]+[\t ]*[0-9]+[0-9\.\t eE\+\-\r\n]+)/.exec(binding.cur_nurbs_info);
  129. //var curve_res = /Curves[\t ]+([0-9]+)[\r\n]+([0-9]+[\t ]+[\t 0-9\.\+\-Ee\r\n]+)/gm.exec(binding.cur_nurbs_info);
  130. var patt = new RegExp("Curves[\\t ]+([0-9]+)[\\r\\n]+([0-9]+[\\t ]+[\\t 0-9\\.\\Ee\\+\\-\\r\\n]+)", "g");
  131. var curve_res = false;
  132. do {
  133. curve_res = patt.exec(ui.sci.document);
  134. if(!curve_res) {
  135. break;
  136. }
  137. var curve_num = parseInt(curve_res[1]);
  138. var curve_res_arr = curve_res[2].split(/[\t \r\n]+/);
  139. //comx.ui.InformationBox(curve_res[0]);
  140. //comx.ui.InformationBox(curve_res[1]);
  141. //comx.ui.InformationBox(curve_res[2]);
  142. //alert(curve_res.length);
  143. base_idx = 0;
  144. var curve_id = 1;
  145. while(true) {
  146. var curve_output = 'Curve\n';
  147. var curve_type = parseInt(curve_res_arr[base_idx + 0]);
  148. var flag = parseInt(curve_res_arr[base_idx + 1]);
  149. if(curve_type !== 7) {
  150. return ('第' + curve_id + '条曲线类型不是7, 暂时不被支持');
  151. }
  152. var curve_order = parseInt(curve_res_arr[base_idx + 3]);
  153. curve_output += '#co ' + curve_order + '\n';
  154. var ctrl_pt_num = parseInt(curve_res_arr[base_idx + 4]);
  155. var para_num = parseInt(curve_res_arr[base_idx + 5]);
  156. var weight_arr = [];
  157. for(var loop = 0; loop < ctrl_pt_num; ++loop) {
  158. if(flag === 1) {
  159. weight_arr.push(TransStr(curve_res_arr[base_idx + 6 + loop], 24, 13));
  160. } else {
  161. weight_arr.push(TransStr("1", 24, 13));
  162. }
  163. }
  164. var ctrl_pt_coord = [];
  165. for(var loop = 0; loop < ctrl_pt_num * 3; ++loop) {
  166. if(flag === 1) {
  167. ctrl_pt_coord.push(TransStr(curve_res_arr[base_idx + 6 + ctrl_pt_num + loop], 24, 13));
  168. } else {
  169. ctrl_pt_coord.push(TransStr(curve_res_arr[base_idx + 6 + loop], 24, 13));
  170. }
  171. }
  172. var curve_base_idx = base_idx + 6 + ctrl_pt_num * 3;
  173. if(flag === 1) {
  174. curve_base_idx = base_idx + 6 + ctrl_pt_num * 4;
  175. }
  176. var para_loop = 0;
  177. var para_arr = [];
  178. while(para_loop < para_num) {
  179. for(var loop = 0; loop < parseInt(curve_res_arr[curve_base_idx + 1]); ++loop) {
  180. para_arr.push(TransStr(curve_res_arr[curve_base_idx], 24, 10));
  181. }
  182. para_loop++;
  183. curve_base_idx += 2;
  184. }
  185. curve_output += ('#ct ' + para_arr.length + '\n');
  186. curve_output += para_arr.join('\n');
  187. curve_output += '\n';
  188. curve_output += ('#cp ' + ctrl_pt_num + '\n');
  189. for(var loop = 0; loop < ctrl_pt_num; ++loop) {
  190. curve_output += ('' + ctrl_pt_coord[loop * 3 + 0] + ' ' +
  191. ctrl_pt_coord[loop * 3 + 1] + ' ' +
  192. ctrl_pt_coord[loop * 3 + 2] + ' ' +
  193. weight_arr[loop] + '\n');
  194. }
  195. base_idx = curve_base_idx;
  196. ret += (curve_output);
  197. ret += '\n';
  198. if(curve_id === curve_num) {
  199. break;
  200. }
  201. curve_id++;
  202. }
  203. }while(true);
  204. return ret;
  205. }
  206. function LoadBrepInfo() {
  207. //var brep_file = comx.sys.GetEnvironmentVariables('CASCADE') + '\\data\\_temp.brep';
  208. var brep_file = model.getDefaultDataDir() + '_temp.brep';
  209. comx.occio.SaveBrep(comx.occore.GetEntry(), brep_file);
  210. //cascade.io.SaveBrep(cascade.core.GetEntry(), brep_file);
  211. ui.ctrl.document = model.getBrepInfoContext();
  212. }
  213. //The message corresponding callback executed by the docker pane.
  214. // when calling [side_pane].fireEvent(type,para) in the main form.
  215. function OnParentDockerMessage(type, para) {
  216. }
  217. //////////////////////////////////////////////////////////////////////////
  218. // Utils Functions.
  219. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  220. function onDragFile(filepath) {
  221. }
  222. function PUI(cb) {
  223. if(pui){cb();}
  224. }
  225. /*Usage of BLOCK_EVENT
  226. BLOCK_EVENT(()=>{
  227. ui.[name].[var] = ...;
  228. });
  229. */
  230. CW_DeclareVariable("sci",
  231. val => {
  232. ui.sci.value += val + '\n';
  233. ui.sci.row = -1;
  234. }, () => {});
  235. CW_DeclareVariable("self",
  236. val => {
  237. ui.self.value += val + '\n';
  238. ui.self.row = -1;
  239. }, () => {});
  240. function BLOCK_EVENT(cb) {
  241. ui.block_event = true;
  242. cb();
  243. ui.block_event = false;
  244. }
  245. //////////////////////////////////////////////////////////////////////////
  246. // template codes for cw callback js.
  247. function CW_DeclareVariable(name, setter, getter) {
  248. if(typeof(__DeclareVariable) === 'function') {
  249. __DeclareVariable(name, setter, getter);
  250. }
  251. }
  252. function CW_DeclareOuterVariable(name) {
  253. if(typeof(__DeclareOuterVariable) === 'function') {
  254. __DeclareOuterVariable(name);
  255. }
  256. }