////////////////////////////////////////////////////////////////////////////
// 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.
});
//ui.stack_force.index = 1;
}
//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
function OnGetFaceName(){
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;
ui.type1.value = typeInfo;
ui.x1.value = centerCoords[0];
ui.y1.value = centerCoords[1];
ui.z1.value = centerCoords[2];
}
function OnGetName(){
const str = unit.form.mainfrm.OnGetName();
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.type.value = typeInfo;
ui.x.value = centerCoords[0];
ui.y.value = centerCoords[1];
ui.z.value = centerCoords[2];
}
function OnModify(idx){
if(idx ===0){
let name = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).unique;
//console.log(name);
unit.form.mainfrm.OnArrows(ui.x1.value, ui.y1.value, ui.z1.value, ui.fa_x.value, ui.fa_y.value, ui.fa_z.value, name);
let color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color;
let Load = {
"constraint":"集中载荷压力",
"位置标记" :ui.type.value,
"位置坐标x":ui.x.value,
"位置坐标y":ui.y.value,
"位置坐标z":ui.z.value,
"压力方向xn":ui.pb_xn.value,
"压力方向yn":ui.pb_yn.value,
"压力方向zn":ui.pb_zn.value,
"压力大小xr":ui.pb_xr.value,
"压力大小yr":ui.pb_yr.value,
"压力大小zr":ui.pb_zr.value,
"cons_type":"arrows",
"color":color,
"unique":name
};
unit.form.tree.ModifyConstraint(Load);
unit.form.mainfrm.OnCueline('修改成功', 'green');
}else if(idx === 1){
let name = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).unique;
console.log(name);
unit.form.mainfrm.OnArrows(ui.x1.value, ui.y1.value, ui.z1.value, ui.fa_x.value, ui.fa_y.value, ui.fa_z.value, name);
let color = model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()).color;
let Load = {
"constraint":"分布载荷压力",
"位置标记" :ui.type1.value,
"位置坐标x":ui.x1.value,
"位置坐标y":ui.y1.value,
"位置坐标z":ui.z1.value,
"压力方向fa_x":ui.fa_x.value,
"压力方向fa_y":ui.fa_y.value,
"压力方向fa_z":ui.fa_z.value,
"压力大小fa_xr":ui.fa_xr.value,
"压力大小fa_yr":ui.fa_yr.value,
"压力大小fa_zr":ui.fa_zr.value,
"cons_type":"arrows",
"color":color,
"unique":name
};
unit.form.tree.ModifyConstraint(Load);
unit.form.mainfrm.OnCueline('修改成功', 'green');
}
}
function OnValueChange2(){
if(ui.fa_x.value === '' || ui.fa_y.value === '' || ui.fa_z.value === '' || ui.fa_xr.value === '' || ui.fa_yr.value === '' || ui.fa_zr.value === '' || parseFloat(ui.fa_radius.value) <= 0){
unit.form.mainfrm.OnChangePicture(3, 3);
//unit.form.mainfrm.OnCueline('
非常抱歉,您输入的数据不在范围内
');
unit.form.mainfrm.OnCueline('您输入的数据不在范围内!!!', 'red');
}else{
unit.form.mainfrm.OnChangePicture(3, 1);
//unit.form.mainfrm.OnCueline('恭喜您,您输入了正确的数据
');
unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
}
}
function OnChangeValue(){
if(ui.pb_xn.value === '' || ui.pb_yn.value === '' || ui.pb_zn.value === '' || ui.pb_xr.value === '' || ui.pb_yr.value === '' || ui.pb_zr.value === ''){
unit.form.mainfrm.OnChangePicture(3, 3);
//unit.form.mainfrm.OnCueline('非常抱歉,您输入的数据不在范围内
');
unit.form.mainfrm.OnCueline('您输入的数据不在范围内!!!', 'red');
}else{
unit.form.mainfrm.OnChangePicture(3, 1);
//unit.form.mainfrm.OnCueline('恭喜您,您输入了正确的数据
');
unit.form.mainfrm.OnCueline('您输入了正确的数据!', 'green');
}
}
function OnReturn(){
unit.form.mainfrm.menu(4);
}
function OnFrameSelect(){
let temp = unit.form.tree.GetCurUniqueName();
let name = temp;
let constrain_data = model.acax_app.model.constrain.Database();
//console.log(workcondition_data);
let i = 0;
let j = 0;
let constrain_arr = Object.keys(constrain_data.db);
//console.log(constrain_data.db);
name = name + "force0";
while(1){
for( i = 0;i < constrain_arr.length;++i) {
if(constrain_data.db[constrain_arr[i]].unique === name) {
++j;
name = temp + "force" + j;
break;
}
}
if(i === constrain_arr.length) {
break;
}
}
let color = unit.form.tree.getRandomHexColor();
let name1 = unit.form.mainfrm.OnArrows(ui.x1.value, ui.y1.value, ui.z1.value, ui.fa_x.value, ui.fa_y.value, ui.fa_z.value, name);
name1 = name1.replace(temp, "");
let Load = {
"constraint":"分布载荷压力",
"位置标记" :ui.type1.value,
"位置坐标x":ui.x1.value,
"位置坐标y":ui.y1.value,
"位置坐标z":ui.z1.value,
"压力方向fa_x":ui.fa_x.value,
"压力方向fa_y":ui.fa_y.value,
"压力方向fa_z":ui.fa_z.value,
"压力大小fa_xr":ui.fa_xr.value,
"压力大小fa_yr":ui.fa_yr.value,
"压力大小fa_zr":ui.fa_zr.value,
"cons_type":"arrows",
"color":color,
"unique":name
};
console.log(name1);
if(ui.type1.value === '--') {
unit.form.mainfrm.OnCueline('您未添加压力位置', 'red');
}else{
unit.form.tree.CreateBoundary(Load, name1);
unit.form.mainfrm.OnCueline('您已将压力数据进行保存,请按鼠标右键选中您要施加约束的物体,并按快捷键R或者r进行添加!', 'green');
}
}
function OnArrowFrame(){
}
function OnArrow(){
let temp = unit.form.tree.GetCurUniqueName();
let name = temp;
let constrain_data = model.acax_app.model.constrain.Database();
//console.log(workcondition_data);
let i = 0;
let j = 0;
let constrain_arr = Object.keys(constrain_data.db);
//console.log(constrain_data.db);
name = name + "force0";
while(1){
for( i = 0;i < constrain_arr.length;++i) {
if(constrain_data.db[constrain_arr[i]].unique === name) {
++j;
name = temp + "force" + j;
break;
}
}
if(i === constrain_arr.length) {
break;
}
}
let name1 = unit.form.mainfrm.OnArrows(ui.x.value, ui.y.value, ui.z.value, ui.pb_xn.value, ui.pb_yn.value, ui.pb_zn.value, name);
name1 = name1.replace(temp, "");
let color = unit.form.tree.getRandomHexColor();
unit.form.mainfrm.OnChangePicture(3, 2);
let Load = {
"constraint":"集中载荷压力",
"位置标记" :ui.type.value,
"位置坐标x":ui.x.value,
"位置坐标y":ui.y.value,
"位置坐标z":ui.z.value,
"压力方向xn":ui.pb_xn.value,
"压力方向yn":ui.pb_yn.value,
"压力方向zn":ui.pb_zn.value,
"压力大小xr":ui.pb_xr.value,
"压力大小yr":ui.pb_yr.value,
"压力大小zr":ui.pb_zr.value,
"cons_type":"arrows",
"color":color,
"unique":name
};
if(ui.type.value === '--') {
unit.form.mainfrm.OnCueline('您未添加压力位置', 'red');
}else{
unit.form.tree.CreateBoundary(Load, name1);
unit.form.mainfrm.OnCueline('您已将压力数据和框选范围进行保存,请按鼠标右键选中您要施加约束的物体,并按快捷键R或者r进行添加以及快捷键U或u者进行框选!', 'green');
}
}
function OnChangeForce(idx){
ui.stack_force.index = parseInt(idx);
}
//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("index",
val => {
ui.stack_force.index = val;
}, () => {});
//集中载荷
CW_DeclareVariable("setConstraint0",
val => {
ui.type.value = val["位置标记"];
ui.x.value=val["位置坐标x"];
ui.y.value=val["位置坐标y"];
ui.z.value=val["位置坐标z"];
ui.pb_xn.value = val["压力方向xn"];
ui.pb_yn.value = val["压力方向yn"];
ui.pb_zn.value = val["压力方向zn"];
ui.pb_xr.value = val["压力大小xr"];
ui.pb_yr.value = val["压力大小yr"];
ui.pb_zr.value = val["压力大小zr"];
}, () => {});
//分布载荷
CW_DeclareVariable("setConstraint1",
val => {
ui.type1.value = val["位置标记"];
ui.x1.value= val["位置坐标x"];
ui.y1.value= val["位置坐标y"];
ui.z1.value= val["位置坐标z"];
ui.fa_x.value = val["压力方向fa_x"];
ui.fa_y.value = val["压力方向fa_y"];
ui.fa_z.value = val["压力方向fa_z"];
ui.fa_xr.value = val["压力大小fa_xr"];
ui.fa_yr.value = val["压力大小fa_yr"];
ui.fa_zr.value = val["压力大小fa_zr"];
}, () => {});
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);
}
}