123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- ////////////////////////////////////////////////////////////////////////////
- // 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);
- }
- var faceId = [];
- //////////////////////////////////////////////////////////////////////////
- // Callback Functions.
- // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
- function OnModify(){
- let color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color;
- let Load = {
- "constraint":"rb3",
- "type":ui.type.value,
- "x":ui.x.value,
- "y":ui.y.value,
- "z":ui.z.value,
- "types":ui.types.value,
- "radius":ui.radius.value,
- "编号":name,
- "cons_type":"rb3",
- "color":color,
- "unique":model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).unique
- };
- unit.form.tree.ModifyConstraint(Load);
- }
- function OnGetName(){
- const str = unit.form.mainfrm.OnGetName();
-
- // 匹配center坐标对应内容的正则表达式
- const centerRegex = /center:([\d. ]+)/;
-
- const typeInfo = str.split(' ').slice(1, 4).join(' ');
- const centerMatch = str.match(centerRegex);
- const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
-
- ui.types.value = typeInfo;
- ui.x.value = parseFloat(centerCoords[0]).toFixed(0);
- ui.y.value = parseFloat(centerCoords[1]).toFixed(0);
- ui.z.value = parseFloat(centerCoords[2]).toFixed(0);
- }
- function OnAddFace(){
- const str = unit.form.mainfrm.OnGetFaceName();
- // 匹配type对应内容的正则表达式,以type:开头,后面跟着非冒号的内容直到遇到空格或者字符串结束
- const typeRegex = /type:([^point]+)/;
- // 匹配center坐标对应内容的正则表达式
- const centerRegex = /point:([\d. ]+)/;
- const typeMatch = str.match(typeRegex);
- const typeInfo = typeMatch? typeMatch[1] : null;
- const centerMatch = str.match(centerRegex);
- const centerCoords = centerMatch? centerMatch[1].split(' ').map(x => x.trim()) : null;
-
- console.log(centerCoords);
- ui.type.value = typeInfo;
- let parts = typeInfo.split(' ');
- let result = parts[2];
- console.log(unit.form.mainfrm.OnGenerateGuass(result));
- }
- function OnReturn(){
- unit.form.mainfrm.menu(4);
- }
- //Rb3
- function OnBrep(){
- let temp = unit.form.tree.GetCurUniqueName();
- let name = temp;
- let constrain_data = model.acax_app.model.constrain.Database();
- let i = 0;
- let j = 0;
- let constrain_arr = Object.keys(constrain_data.db);
- name = name + "rb3 0";
- while(1){
- for( i = 0;i < constrain_arr.length;++i) {
- if(constrain_data.db[constrain_arr[i]].unique === name) {
- ++j;
- name = temp + "rb3 " + j;
- break;
- }
- }
- if(i === constrain_arr.length) {
- break;
- }
- }
- let name1 = unit.form.mainfrm.OnSpheres(ui.x.value, ui.y.value, ui.z.value, ui.radius.value, name);
- console.log(name1);
- let match = name1.split(":")[1];
- name1 = name1.replace(temp, "").split(" Breps:")[0];
- let color = unit.form.tree.getRandomHexColor();
- let Load = {
- "constraint":"rb3",
- "type":ui.type.value,
- "x":ui.x.value,
- "y":ui.y.value,
- "z":ui.z.value,
- "types":ui.types.value,
- "radius":ui.radius.value,
- "编号":match,
- "cons_type":"rb3",
- "color":color,
- "unique":name
- };
- console.log(name1);
- if(ui.type.value === '--' || ui.types.value === '--') {
- unit.form.mainfrm.OnCueline('未添加连界面和节点信息', 'red');
- }else{
- unit.form.tree.CreateBoundary(Load, name1);
- unit.form.mainfrm.OnCueline('您完成了rb3添加!', 'green');
- }
-
- }
- function OnPickUp(){
- unit.form.mainfrm.OnSend('rendererFace ' + ui.listBox.value);
- unit.form.mainfrm.OnChangePicture(3, 1);
- //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: Blue;font-size:20px;">选取的面已在界面中选中,请不要忘记生成它的Brep文件!</h4>');
- unit.form.mainfrm.OnCueline('选取的面已在界面中选中,请不要忘记生成它的Brep文件!', 'blue');
- }
- function OnShow(){
- unit.form.mainfrm.OnSend('selectId');
- unit.form.mainfrm.OnChangePicture(3, 1);
- //unit.form.mainfrm.OnCueline('<h4 style="font-family:arial;color: Blue;font-size:20px;">拾取的各个面ID已在记录中,注意事项:选中功能不能有空值,否则界面会崩溃!</h4>');
- unit.form.mainfrm.OnCueline('拾取的各个面ID已在记录中,注意事项:选中功能不能有空值,否则界面会崩溃!', 'blue');
- }
- //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();}
- }
- CW_DeclareVariable("list",
- val => {
- ui.listBox.list = [
- val
- ];
- }, () => {});
- /*Usage of BLOCK_EVENT
- BLOCK_EVENT(()=>{
- ui.[name].[var] = ...;
- });
- */
- //rb3
- CW_DeclareVariable("setConstraint",
- val => {
- ui.type.value = val.type;
- ui.x.value = val.x;
- ui.y.value = val.y;
- ui.z.value = val.z;
- ui.types.value = val.types;
- ui.radius.value = val.radius;
- }, () => {});
- 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);
- }
- }
|