123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- ////////////////////////////////////////////////////////////////////////////
- // System Pre-define Functions
- // 95099372-ef3e-11ea-9c81-bf848405c62e
- //Callback of data preparation stage before UI is fully loaded.
- function OnInitializeData(reload, preview) {
-
- PUI(()=>{
- //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
- //The 'pui' variable is valid in all functions of this document.
- //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
-
- });
- }
- //Callback after UI is fully loaded and displayed.
- function OnReady(reload, preview) {
-
- PUI(()=>{
- //you can access the 'ui' namespace in the parent form using the variable 'pui' here.
- //The 'pui' variable is valid in all functions of this document.
- //For robustness, you'd better use 'PUI(cb);' to access 'pui' variable.
-
- });
- }
- function OnCloseForm() {
- }
- function OnException(err) {
- //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
- }
- //////////////////////////////////////////////////////////////////////////
- // Callback Functions.
- // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
- var pick = false;
- function OnPickUp() {
- pick = !pick;
- if (pick === true) {
- unit.form.mainfrm.pick(1);
- ui.pb_pick.valid = true;
- }
- if (pick === false) {
- unit.form.mainfrm.pick(2);
- ui.pb_pick.valid = false;
- }
- }
- function TransStr(str, len, prec) {
- var val = parseFloat(str);
- val = val.toPrecision(prec);
- str = val.toString();
- if(str[0] !== '-') {
- str = ' ' + str;
- }
- var str_len = str.length;
- var space_num = len - str_len;
- for(var loop = 0; loop < space_num; ++loop) {
- str = str + ' ';
- }
- return str;
- }
- function FilterNurbsInfo() {
- var ret = '';
- var surface_res = /Surfaces[\t ]+([0-9]+)[\r\n]+([0-9\t \.eE+\-\r\n]+)/.exec(ui.sci.document);
- if(surface_res) {
- var surface_num = parseInt(surface_res[1]);
- var surface_res_arr = surface_res[2].split(/[\t \r\n]+/);
- var base_idx = 0;
- var surface_id = 1;
- while(true) {
- var surface_output = 'Surface\n';
- var surface_type = parseInt(surface_res_arr[base_idx]);
- if(surface_type !== 9) {
- return ('第' + surface_id + '个曲面类型不是9, 暂时不被支持');
- }
- var flag = parseInt(surface_res_arr[base_idx + 1]);
- var order_u = parseInt(surface_res_arr[base_idx + 5]);
- var order_v = parseInt(surface_res_arr[base_idx + 6]);
- surface_output += ('#so' + ' ' + order_u + ' ' + order_v + '\n');
- var ctrl_pt_num_u = parseInt(surface_res_arr[base_idx + 7]);
- var ctrl_pt_num_v = parseInt(surface_res_arr[base_idx + 8]);
- var surface_para_num_u = parseInt(surface_res_arr[base_idx + 9]);
- var surface_para_num_v = parseInt(surface_res_arr[base_idx + 10]);
- var uv_para_idx_base = base_idx + 10 + ctrl_pt_num_u * ctrl_pt_num_v * 4 + 1;
- if(flag === 0) {
- uv_para_idx_base = base_idx + 10 + ctrl_pt_num_u * ctrl_pt_num_v * 3 + 1;
- }
- var surface_para_u_loop = 0;
- var u_para_arr = [];
- while(surface_para_u_loop < surface_para_num_u) {
- for(var loop = 0; loop < parseInt(surface_res_arr[uv_para_idx_base + 1]); ++loop) {
- u_para_arr.push(TransStr(surface_res_arr[uv_para_idx_base], 24, 10));
- }
- surface_para_u_loop++;
- uv_para_idx_base += 2;
- }
- surface_output += ('#su' + ' ' + u_para_arr.length + '\n');
- surface_output += u_para_arr.join('\n');
- surface_output += '\n';
- var surface_para_v_loop = 0;
- var v_para_arr = [];
- while(surface_para_v_loop < surface_para_num_v) {
- for(var loop = 0; loop < parseInt(surface_res_arr[uv_para_idx_base + 1]); ++loop) {
- v_para_arr.push(TransStr(surface_res_arr[uv_para_idx_base], 24, 10));
- }
- surface_para_v_loop++;
- uv_para_idx_base += 2;
- }
- var ctrl_pt_base_idx = base_idx + 11;
- base_idx = uv_para_idx_base;
- surface_output += ('#sv' + ' ' + v_para_arr.length + '\n');
- surface_output += v_para_arr.join('\n');
- surface_output += '\n';
- surface_output += '#suvp ' + ctrl_pt_num_u + ' ' + ctrl_pt_num_v + '\n';
- for(var loop = 0; loop < ctrl_pt_num_u * ctrl_pt_num_v; ++loop) {
- if(flag === 1) {
- surface_output += (TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 4 + 0], 24, 13) + ' ' +
- TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 4 + 1], 24, 13) + ' ' +
- TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 4 + 2], 24, 13) + ' ' +
- TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 4 + 3], 24, 13) + '\n');
- } else {
- surface_output += (TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 3 + 0], 24, 13) + ' ' +
- TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 3 + 1], 24, 13) + ' ' +
- TransStr(surface_res_arr[ctrl_pt_base_idx + loop * 3 + 2], 24, 13) + ' ' +
- '1\n');
- }
- }
- ret += (surface_output);
- ret += '\n';
- if(surface_id === surface_num) {
- break;
- }
- surface_id++;
- }
- }
- //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);
- //var curve_res = /Curves[\t ]+([0-9]+)[\r\n]+([0-9]+[\t ]+[\t 0-9\.\+\-Ee\r\n]+)/gm.exec(binding.cur_nurbs_info);
- var patt = new RegExp("Curves[\\t ]+([0-9]+)[\\r\\n]+([0-9]+[\\t ]+[\\t 0-9\\.\\Ee\\+\\-\\r\\n]+)", "g");
- var curve_res = false;
- do {
- curve_res = patt.exec(ui.sci.document);
- if(!curve_res) {
- break;
- }
- var curve_num = parseInt(curve_res[1]);
- var curve_res_arr = curve_res[2].split(/[\t \r\n]+/);
- //comx.ui.InformationBox(curve_res[0]);
- //comx.ui.InformationBox(curve_res[1]);
- //comx.ui.InformationBox(curve_res[2]);
- //alert(curve_res.length);
- base_idx = 0;
- var curve_id = 1;
- while(true) {
- var curve_output = 'Curve\n';
- var curve_type = parseInt(curve_res_arr[base_idx + 0]);
- var flag = parseInt(curve_res_arr[base_idx + 1]);
- if(curve_type !== 7) {
- return ('第' + curve_id + '条曲线类型不是7, 暂时不被支持');
- }
- var curve_order = parseInt(curve_res_arr[base_idx + 3]);
- curve_output += '#co ' + curve_order + '\n';
- var ctrl_pt_num = parseInt(curve_res_arr[base_idx + 4]);
- var para_num = parseInt(curve_res_arr[base_idx + 5]);
- var weight_arr = [];
- for(var loop = 0; loop < ctrl_pt_num; ++loop) {
- if(flag === 1) {
- weight_arr.push(TransStr(curve_res_arr[base_idx + 6 + loop], 24, 13));
- } else {
- weight_arr.push(TransStr("1", 24, 13));
- }
- }
- var ctrl_pt_coord = [];
- for(var loop = 0; loop < ctrl_pt_num * 3; ++loop) {
- if(flag === 1) {
- ctrl_pt_coord.push(TransStr(curve_res_arr[base_idx + 6 + ctrl_pt_num + loop], 24, 13));
- } else {
- ctrl_pt_coord.push(TransStr(curve_res_arr[base_idx + 6 + loop], 24, 13));
- }
- }
- var curve_base_idx = base_idx + 6 + ctrl_pt_num * 3;
- if(flag === 1) {
- curve_base_idx = base_idx + 6 + ctrl_pt_num * 4;
- }
- var para_loop = 0;
- var para_arr = [];
- while(para_loop < para_num) {
- for(var loop = 0; loop < parseInt(curve_res_arr[curve_base_idx + 1]); ++loop) {
- para_arr.push(TransStr(curve_res_arr[curve_base_idx], 24, 10));
- }
- para_loop++;
- curve_base_idx += 2;
- }
- curve_output += ('#ct ' + para_arr.length + '\n');
- curve_output += para_arr.join('\n');
- curve_output += '\n';
- curve_output += ('#cp ' + ctrl_pt_num + '\n');
- for(var loop = 0; loop < ctrl_pt_num; ++loop) {
- curve_output += ('' + ctrl_pt_coord[loop * 3 + 0] + ' ' +
- ctrl_pt_coord[loop * 3 + 1] + ' ' +
- ctrl_pt_coord[loop * 3 + 2] + ' ' +
- weight_arr[loop] + '\n');
- }
- base_idx = curve_base_idx;
- ret += (curve_output);
- ret += '\n';
- if(curve_id === curve_num) {
- break;
- }
- curve_id++;
- }
- }while(true);
- return ret;
- }
- function LoadBrepInfo() {
- //var brep_file = comx.sys.GetEnvironmentVariables('CASCADE') + '\\data\\_temp.brep';
- var brep_file = model.getDefaultDataDir() + '_temp.brep';
- comx.occio.SaveBrep(comx.occore.GetEntry(), brep_file);
- //cascade.io.SaveBrep(cascade.core.GetEntry(), brep_file);
- ui.ctrl.document = model.getBrepInfoContext();
- }
- //The message corresponding callback executed by the docker pane.
- // when calling [side_pane].fireEvent(type,para) in the main form.
- function OnParentDockerMessage(type, para) {
- }
- //////////////////////////////////////////////////////////////////////////
- // Utils Functions.
- // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
- function onDragFile(filepath) {
- }
- function PUI(cb) {
- if(pui){cb();}
- }
- /*Usage of BLOCK_EVENT
- BLOCK_EVENT(()=>{
- ui.[name].[var] = ...;
- });
- */
- CW_DeclareVariable("sci",
- val => {
- ui.sci.value += val + '\n';
- ui.sci.row = -1;
- }, () => {});
-
- CW_DeclareVariable("self",
- val => {
- ui.self.value += val + '\n';
- ui.self.row = -1;
- }, () => {});
- function BLOCK_EVENT(cb) {
- ui.block_event = true;
-
- cb();
-
- ui.block_event = false;
- }
- //////////////////////////////////////////////////////////////////////////
- // template codes for cw callback js.
- function CW_DeclareVariable(name, setter, getter) {
- if(typeof(__DeclareVariable) === 'function') {
- __DeclareVariable(name, setter, getter);
- }
- }
- function CW_DeclareOuterVariable(name) {
- if(typeof(__DeclareOuterVariable) === 'function') {
- __DeclareOuterVariable(name);
- }
- }
|