//////////////////////////////////////////////////////////////////////////// // 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); } let myArray = []; ////////////////////////////////////////////////////////////////////////// // Callback Functions. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7 function OnModify(){ // var name = ["泊松比", "密度(g/cm^3)", "屈服强度", "弹性模量(MPa)", "Id"]; let color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color; let mat = { "泊松比": ui.phy_poi.value, "密度(g/cm^3)":ui.phy_density.value, "屈服强度":ui.phy_yie.value, "弹性模量(MPa)":ui.phy_ela.value, "color":color, "Id":ui.phy_id.value }; unit.form.tree.ModifyMaterial(mat); } function OnId(){ } function OnDen(){ if(ui.phy_density.value <= 0){ unit.form.mainfrm.OnChangePicture(2, 3); //unit.form.mainfrm.OnCueline('

非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!

'); unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red'); } if(ui.phy_density.value > 0){ unit.form.mainfrm.OnChangePicture(2, 1); //unit.form.mainfrm.OnCueline('

恭喜您,您输入了正确的数据!

'); unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green'); } } function OnEla(){ if(ui.phy_ela.value <= 0){ unit.form.mainfrm.OnChangePicture(2, 3); //unit.form.mainfrm.OnCueline('

非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!

'); unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red'); } if(ui.phy_ela.value > 0){ unit.form.mainfrm.OnChangePicture(2, 1); //unit.form.mainfrm.OnCueline('

恭喜您,您输入了正确的数据!

'); unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green'); } } function OnPoi(){ if(ui.phy_poi.value <= 0){ unit.form.mainfrm.OnChangePicture(2, 3); //unit.form.mainfrm.OnCueline('

非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!

'); unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red'); } if(ui.phy_poi.value > 0){ unit.form.mainfrm.OnChangePicture(2, 1); //unit.form.mainfrm.OnCueline('

恭喜您,您输入了正确的数据!

'); unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green'); } } function OnYie(){ if(ui.phy_yie.value <= 0){ unit.form.mainfrm.OnChangePicture(2, 3); //unit.form.mainfrm.OnCueline('

非常抱歉,您设置的材料参数不符合常理,请您重新输入!!!

'); unit.form.mainfrm.OnCueline('您设置的材料参数不符合常理,请您重新输入!!!', 'red'); } if(ui.phy_yie.value > 0){ unit.form.mainfrm.OnChangePicture(2, 1); //unit.form.mainfrm.OnCueline('

恭喜您,您输入了正确的数据!

'); unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green'); } } function OnReturnMenu(){ unit.form.mainfrm.menu(2); } function OnMaterialFiles() { //ui.pb_ok.enable = true; if(myArray.length === 0){ unit.form.mainfrm.OnChangePicture(2, 3); return; } var str = myArray[ui.listBox.index]; var arr = str.split(","); var str1 = arr.join(' '); model.write(str1, model.getCurrentDirectory() + '/data/material.txt'); unit.form.mainfrm.OnSend('materials ' + str1); unit.form.mainfrm.OnChangePicture(2, 2); let color = unit.form.tree.getRandomHexColor(); let mat = { "泊松比": ui.phy_poi.value, "密度(g/cm^3)":ui.phy_density.value, "屈服强度":ui.phy_yie.value, "弹性模量(MPa)":ui.phy_ela.value, "color":color, "Id":ui.phy_id.value }; if(!model.global_ctrl[0] || !model.global_ctrl[1] || !model.global_ctrl[2] || !model.global_ctrl[3]) { unit.form.mainfrm.OnCueline('未满足创建条件', 'red'); return; } unit.form.tree.CreateMaterial(mat); unit.form.mainfrm.OnCueline('恭喜您,材料添加成功!', 'green'); } function OnDeleteValue() { myArray.splice(parseFloat(ui.listBox.index), 1); console.log(ui.listBox.index); ui.listBox.list = [ myArray ]; unit.form.mainfrm.OnCueline('非常抱歉,您记录的数据已得到了删除!', 'red'); //ui.cueline.value += '已删除\n'; //ui.cueline.row = -1; } function OnAddValue() { var value = ui.pb_Id.value + ',' + parseFloat(ui.phy_density.value) + ',' + parseFloat(ui.phy_ela.value) + ',' + parseFloat(ui.phy_poi.value) + ',' + parseFloat(ui.phy_yie.value) + ',' + parseFloat(ui.phy_id.value); myArray.push(value); ui.listBox.list = [ myArray ]; //unit.form.mainfrm.OnCueline('

恭喜您,您输入的数据已得到了记录!

'); unit.form.mainfrm.OnCueline('恭喜您,您输入的数据已得到了记录!', 'green'); //ui.cueline.value += '已添加\n'; //ui.cueline.row = -1; } //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] = ...; }); */ function BLOCK_EVENT(cb) { ui.block_event = true; cb(); ui.block_event = false; } CW_DeclareVariable("pb_ID", val => { ui.phy_id.value = val; }, () => {}); CW_DeclareVariable("setmaterial", material => { ui.phy_poi.value = material["泊松比"]; ui.phy_density.value = material["密度(g/cm^3)"]; ui.phy_yie.value = material["屈服强度"]; ui.phy_ela.value = material["弹性模量(MPa)"]; ui.phy_id.value = material.Id; }, () => {}); ////////////////////////////////////////////////////////////////////////// // 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); } }