//////////////////////////////////////////////////////////////////////////// // System Pre-define Functions // 95099372-ef3e-11ea-9c81-bf848405c62e //Callback of data preparation stage before UI is fully loaded. //dcip节点和模型树节点对应值 var g_cur_id2index_cache = {}; var g_cur_index2id_cache = {}; //记录已加载工况 var workcondition = []; 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.tree_menu.index = 2; ui.tree_Model.title = ['Part Assemblies/Parts', 'Color', 'UID']; } //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 options = true; let myArray = []; ////////////////////////////////////////////////////////////////////////// // Callback Functions. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7 //测试函数 function OnTest(){ //GenerateFile(); // console.log(model.acax_app.path.Name(g_cur_id2index_cache["131"])); //console.log(g_cur_id2index_cache); // console.log(g_cur_index2id_cache); //console.log(model.acax_app.model.materialProp.Current()); //SetUserColor(); let str = unit.form.mainfrm.findRIdById(model.acax_app.model.project.GetModel().pro_model, 100005); console.log(str); console.log(comx.occio.GetFacePoint(comx.occore.GetEntryEx(), str)); } //判断工作流程 function CheckCtrlProcess() { for(let i = 0 ;i < 6;++i) { model.global_ctrl[i] = false; } //工作区 if(model.acax_app.model.workArea.Current() !== false) { model.global_ctrl[0] = true; }else{ return; } //工程 if(model.acax_app.model.project.Current() !== "") { model.global_ctrl[1] = true; }else{ return; } //获取模型存在否 if( model.acax_app.model.project.GetModel().step !== "unimported") { model.global_ctrl[2] = true; }else{ return; } //工况 if(model.acax_app.model.workCondition.Current() !== "") { model.global_ctrl[3] = true; }else{ return; } //BBP let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex(); let model_prop = model.acax_app.view.GetProperty(cut_workcondition_index); if(model_prop === undefined ) { model.global_ctrl[4] = false; }else if(model_prop.BPP){ model.global_ctrl[4] = true; } //材料 if(model.acax_app.model.materialProp.Current()) { model.global_ctrl[5] = true; } } //生成随机颜色 function getRandomHexColor() { // 随机生成一个 0 到 16777215 之间的整数,并转换为十六进制字符串 let color = Math.floor(Math.random() * 16777216).toString(16); // 确保颜色代码始终为 6 位 return "#" + color.padStart(6, "0"); } //生成求解文件 function GenerateFile() { model.execs(model.getCurrentDirectory() + "/src/generateBrep/generateBrep.exe " + model.acax_app.model.project.GetModel().step.replace(/\\/g, "/") + " " + model.getCurrentDirectory(), cb => { console.log(cb); }); model.acax_app.control.Export(info=>{ //console.log(JSON.stringify(info, null, 2)); let cut_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex(); var File = ['结构静力学前处理文件', '\n$ address', info.model3d.step.replace(/\\/g, "/")]; //添加材料 File.push("\n$ materials"); let str = info.mat_prop_list[0]["密度(g/cm^3)"] + " " + info.mat_prop_list[0]["弹性模量(MPa)"] + " " + info.mat_prop_list[0]["泊松比"] + " " +info.mat_prop_list[0]["屈服强度"]; File.push(str); //添加BPP File.push("\n$ BPP"); File.push(model.acax_app.view.GetProperty(cut_workcondition_index).BPP.BPP); //brepFiles File.push("\n$ brepFiles"); //需要brepFiles文件 let brep_data = model.acax_app.view.GetProperty(cut_workcondition_index).brep; let brep_arr = Object.keys(brep_data); for(let i = 0;i < brep_arr.length;++i) { File.push(brep_data[brep_arr[i]].brep); } //forceFace未实现 File.push("\n$ forceFace id xn yn zn xr yr zr"); for(let i = 0;i < info.cons_list.length;++i ) { if(info.cons_list[i].constraint === "分布载荷压力" && info.cons_list[i]["位置标记"][0] === 'F' ) { let str0 = info.cons_list[i]["位置标记"].split(" "); let str1 = str0[2] + " "+ info.cons_list[i]["压力方向fa_x"] + " " + info.cons_list[i]["压力方向fa_y"] + " " + info.cons_list[i]["压力方向fa_z"] + " "+info.cons_list[i]["压力大小fa_xr"] + " " + info.cons_list[i]["压力大小fa_yr"] +" " + info.cons_list[i]["压力大小fa_zr"]; File.push(str1); } } //fixFace未实现 File.push("\n$ fixFace id xn yn zn xr yr zr"); for(let i = 0;i < info.cons_list.length;++i ) { if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'F' ) { let str0 = info.cons_list[i].type.split(" "); let str1 = str0[2] + " "+ info.cons_list[i]["固定支撑属性xd"] + " " + info.cons_list[i]["固定支撑属性yd"] + " " + info.cons_list[i]["固定支撑属性zd"] + " "+info.cons_list[i]["固定支撑属性xr"] + " " + info.cons_list[i]["固定支撑属性yr"] +" " + info.cons_list[i]["固定支撑属性zr"]; File.push(str1); } } //添加梁和梁节点 for(let i = 0;i < info.cons_list.length;++i ) { if(info.cons_list[i].constraint === "梁") { File.push("\n$ mat poi radius len seg Beam"); let str1 = info.cons_list[i]["弹性模量"] + " " + info.cons_list[i]["泊松比"] + " " + info.cons_list[i]["梁约束参数半径"] + " " +info.cons_list[i]["梁约束参数长度"] + " " + info.cons_list[i]["梁约束参数个数"]; File.push(str1); let len = info.cons_list[i]["梁约束参数个数"]; File.push("\n$ x y z Beam"); for(let j = 0 ; j <= len ;++j){ let str = info.cons_list[i].point[j*3] + " " +info.cons_list[i].point[j*3 +1] + " " +info.cons_list[i].point[j*3 + 2]; File.push(str); } } } //添加固定支撑 File.push("\n$ con ids id xd yd zd xr yr zr Beam"); for(let i = 0;i < info.cons_list.length;++i ) { if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'B') { let str0 = info.cons_list[i].type.split(" "); let str1 = str0[1] + " " + str0[2] + " "+ info.cons_list[i]["固定支撑属性xd"] + " " + info.cons_list[i]["固定支撑属性yd"] + " " + info.cons_list[i]["固定支撑属性zd"] + " "+info.cons_list[i]["固定支撑属性xr"] + " " + info.cons_list[i]["固定支撑属性yr"] +" " + info.cons_list[i]["固定支撑属性zr"]; File.push(str1); } } //添加arrow File.push("\n$ arrow ids id xn yn zn xr yr zr Beam"); for(let i = 0;i < info.cons_list.length;++i ) { if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'B') { let str0 = info.cons_list[i].type.split(" "); let str1 = str0[1] + " " + str0[2] + " "+ info.cons_list[i]["固定支撑属性xd"] + " " + info.cons_list[i]["固定支撑属性yd"] + " " + info.cons_list[i]["固定支撑属性zd"] + " "+info.cons_list[i]["固定支撑属性xr"] + " " + info.cons_list[i]["固定支撑属性yr"] +" " + info.cons_list[i]["固定支撑属性zr"]; File.push(str1); } } //添加弹簧 File.push("\n$ x y z X Y Z stiffness_x stiffness_y stiffness_z type1 type2 Spring"); for(let i = 0;i < info.cons_list.length;++i ) { if(info.cons_list[i].constraint === "弹簧" && (info.cons_list[i].stypes[0] === 'P' ||info.cons_list[i].stypes[0] === 'B') && (info.cons_list[i].stypee[0] === 'P' ||info.cons_list[i].stypee[0] === 'B')) { let str1 = info.cons_list[i]["弹簧坐标x"] + " " + info.cons_list[i]["弹簧坐标y"] + " " + info.cons_list[i]["弹簧坐标z"] + " "+info.cons_list[i]["弹簧终点x"] + " " + info.cons_list[i]["弹簧终点y"] +" " + info.cons_list[i]["弹簧终点z"] + " " + info.cons_list[i].stiffness_x +" " + info.cons_list[i].stiffness_y+ " " + info.cons_list[i].stiffness_z + " " + info.cons_list[i].stypes[0] + " " + info.cons_list[i].stypee[0]; File.push(str1); } } //添加连接 File.push("\n$ type id1 id x1 y1 z1 type id1 id x2 y2 z2 xn yn zn xr yr zr Connect"); for(let i = 0;i < info.cons_list.length;++i ) { if(info.cons_list[i].constraint === "连接" && (info.cons_list[i].ctypes[0] === 'P' ||info.cons_list[i].ctypes[0] === 'B') && (info.cons_list[i].ctpyee[0] === 'P' ||info.cons_list[i].ctpyee[0] === 'B')) { let str1 = info.cons_list[i].ctypes + " " + info.cons_list[i]["弹簧坐标x"] + " " + info.cons_list[i]["弹簧坐标y"] + " " + info.cons_list[i]["弹簧坐标z"] + " " + info.cons_list[i].ctpyee + " " + info.cons_list[i]["弹簧终点x"] + " " + info.cons_list[i]["弹簧终点y"] +" " + info.cons_list[i]["弹簧终点z"] + " " + info.cons_list[i]["弹簧材料xn"] +" " + info.cons_list[i]["弹簧材料yn"]+ " " + info.cons_list[i]["弹簧材料zn"] + " " + info.cons_list[i]["弹簧材料xr"] + " " + info.cons_list[i]["弹簧材料yr"]+ " "+ info.cons_list[i]["弹簧材料zr"]; File.push(str1); } } //添加rb3 for(let i = 0;i < info.cons_list.length;++i ) { if(info.cons_list[i].constraint === "rb3") { File.push("\n$ id RB3"); let str1 = info.cons_list[i]["编号"]; str1 = str1.split(" "); //console.log(str1); for(let j = 0;j < str1.length;++j) { if(str1[j] !== '') { File.push(str1[j]); } } File.push("\n$ type id ids x y z RB3"); let str = info.cons_list[i].types + " " +info.cons_list[i].x + " " + info.cons_list[i].y + " " + info.cons_list[i].z; File.push(str); } } //集中载荷rb3 File.push("\n$ arrow type id ids xn yn zn xr yr zr RB3"); for(let i = 0;i < info.cons_list.length;++i ) { if(info.cons_list[i].constraint === "集中载荷压力" && info.cons_list[i]["位置标记"][0] === 'P' ) { let str1 = info.cons_list[i]["位置标记"] + " " + info.cons_list[i]["压力方向xn"] + " " + info.cons_list[i]["压力方向yn"] + " "+info.cons_list[i]["压力方向zn"] + " " + info.cons_list[i]["压力大小xr"] +" " + info.cons_list[i]["压力大小yr"]+ " " + info.cons_list[i]["压力大小zr"]; File.push(str1); } } //固定支撑rb3 File.push("\n$ fix type id ids xn yn zn xr yr zr RB3"); for(let i = 0;i < info.cons_list.length;++i ) { if(info.cons_list[i].constraint === "固定支撑" && info.cons_list[i].type[0] === 'P') { let str1 = info.cons_list[i].type + " "+ info.cons_list[i]["固定支撑属性xd"] + " " + info.cons_list[i]["固定支撑属性yd"] + " " + info.cons_list[i]["固定支撑属性zd"] + " "+info.cons_list[i]["固定支撑属性xr"] + " " + info.cons_list[i]["固定支撑属性yr"] +" " + info.cons_list[i]["固定支撑属性zr"]; File.push(str1); } } model.writeFile(File); }); } function OnTest1(){ console.log(model.acax_app.model.project.GetModel()); //console.log(model.acax_app.model.constrain.Database()); //GenerateFile() ; //console.log(model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current())); } //创建约束显示 function CreateContrainShow() { //console.log(model.acax_app.model.workArea.Current() !== false); //console.log(model.acax_app.model.project.Current() !== ""); //console.log(model.acax_app.model.workCondition.Current() !== ""); if(model.acax_app.model.workArea.Current() !== false && model.acax_app.model.project.Current() !== "" &&model.acax_app.model.workCondition.Current() !== ""){ //获取工况数据库 //console.log(workcondition); var new_arr_key ; var constrain_data; if(model.acax_app.model.workCondition.Current() === "") { new_arr_key = []; }else{ constrain_data = model.acax_app.model.workCondition.Get(model.acax_app.model.workCondition.Current()); if(Object.keys(constrain_data.constrain.db).length !== 0) { new_arr_key = Object.keys(constrain_data.constrain.db); }else{ new_arr_key = []; } } //查看当前工程工况是否已加载 const path1 = model.acax_app.model.workArea.Current(); const workarea_name1 =path1.substring(path1.lastIndexOf('/') + 1); var cur_name = workarea_name1 + model.acax_app.model.project.Current() + model.acax_app.model.workCondition.Current(); var flag = 1; console.log(workcondition.includes(cur_name)); if(workcondition.includes(cur_name)) { for(let i = 0;i < new_arr_key.length;++i) { let type = constrain_data.constrain.db[new_arr_key[i]].cons_type; unit.form.mainfrm.HideAndShow(type, constrain_data.constrain.db[new_arr_key[i]].unique, false); if(type === "rb3" && flag) { unit.form.mainfrm.HideAndShow("pick", "rb3", false); flag = 0; } } ShowPoints(); ShowMarks(); }else{ for(let i = 0;i < new_arr_key.length;++i) { if(constrain_data.constrain.db[new_arr_key[i]].constraint === "集中载荷压力") { unit.form.mainfrm.OnArrows(constrain_data.constrain.db[new_arr_key[i]]["位置坐标x"], constrain_data.constrain.db[new_arr_key[i]]["位置坐标y"], constrain_data.constrain.db[new_arr_key[i]]["位置坐标z"], constrain_data.constrain.db[new_arr_key[i]]["压力方向xn"], constrain_data.constrain.db[new_arr_key[i]]["压力方向yn"], constrain_data.constrain.db[new_arr_key[i]]["压力方向zn"], constrain_data.constrain.db[new_arr_key[i]].unique); } if(constrain_data.constrain.db[new_arr_key[i]].constraint === "固定支撑") { unit.form.mainfrm.OnConstrains(constrain_data.constrain.db[new_arr_key[i]].xc, constrain_data.constrain.db[new_arr_key[i]].yc, constrain_data.constrain.db[new_arr_key[i]].zc, constrain_data.constrain.db[new_arr_key[i]].unique); } if(constrain_data.constrain.db[new_arr_key[i]].constraint === "梁") { unit.form.mainfrm.OnBeams(constrain_data.constrain.db[new_arr_key[i]]["梁约束参数个数"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置xDirection"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置yDirection"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置zDirection"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置xCoord"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置yCoord"], constrain_data.constrain.db[new_arr_key[i]]["梁约束位置zCoord"], constrain_data.constrain.db[new_arr_key[i]].R, constrain_data.constrain.db[new_arr_key[i]].G, constrain_data.constrain.db[new_arr_key[i]].B, constrain_data.constrain.db[new_arr_key[i]]["梁节点大小半径"], constrain_data.constrain.db[new_arr_key[i]].unique); } if(constrain_data.constrain.db[new_arr_key[i]].constraint === "连接") { unit.form.mainfrm.OnConnects(constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标x"], constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标y"], constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标z"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点x"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点y"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点z"], constrain_data.constrain.db[new_arr_key[i]].R, constrain_data.constrain.db[new_arr_key[i]].G, constrain_data.constrain.db[new_arr_key[i]].B, constrain_data.constrain.db[new_arr_key[i]].unique); } if(constrain_data.constrain.db[new_arr_key[i]].constraint === "弹簧") { unit.form.mainfrm.OnSpring(constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标x"], constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标y"], constrain_data.constrain.db[new_arr_key[i]]["弹簧坐标z"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点x"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点y"], constrain_data.constrain.db[new_arr_key[i]]["弹簧终点z"], constrain_data.constrain.db[new_arr_key[i]].R, constrain_data.constrain.db[new_arr_key[i]].G, constrain_data.constrain.db[new_arr_key[i]].B, constrain_data.constrain.db[new_arr_key[i]].unique); } if(constrain_data.constrain.db[new_arr_key[i]].constraint === "分布载荷压力") { unit.form.mainfrm.OnArrows(constrain_data.constrain.db[new_arr_key[i]]["位置坐标x"], constrain_data.constrain.db[new_arr_key[i]]["位置坐标y"], constrain_data.constrain.db[new_arr_key[i]]["位置坐标z"], constrain_data.constrain.db[new_arr_key[i]]["压力方向fa_x"], constrain_data.constrain.db[new_arr_key[i]]["压力方向fa_y"], constrain_data.constrain.db[new_arr_key[i]]["压力方向fa_z"], constrain_data.constrain.db[new_arr_key[i]].unique); } if(constrain_data.constrain.db[new_arr_key[i]].constraint === "rb3") { unit.form.mainfrm.OnGenerateGuass(constrain_data.constrain.db[new_arr_key[i]]["编号"]); unit.form.mainfrm.OnSpheres(constrain_data.constrain.db[new_arr_key[i]].x, constrain_data.constrain.db[new_arr_key[i]].y, constrain_data.constrain.db[new_arr_key[i]].z, constrain_data.constrain.db[new_arr_key[i]].radius, constrain_data.constrain.db[new_arr_key[i]].unique); } } //加载点 OnLoadPoints(); OnLoadMarks(); workcondition.push(cur_name); } } } //已创建但被隐藏,显示点 function ShowPoints() { console.log("1111"); let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex(); let point_model = model.acax_app.view.GetProperty(work_condition).point; let point_arr = Object.keys(point_model); for(let i = 0;i < point_arr.length;++i) { unit.form.mainfrm.HideAndShow("points", point_model[point_arr[i]].name, false); } } //已创建但被隐藏,显示Mark function ShowMarks() { let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex(); let mark_model = model.acax_app.view.GetProperty(work_condition).mark; let mark_arr = Object.keys(mark_model); for(let i = 0;i < mark_arr.length;++i) { unit.form.mainfrm.HideAndShow("mark", mark_model[mark_arr[i]].name, false); } } //加载点 function OnLoadPoints() { let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex(); if(model.acax_app.view.GetProperty(work_condition) !== undefined && model.acax_app.view.GetProperty(work_condition).point !== undefined ) { let point_model = model.acax_app.view.GetProperty(work_condition).point; let point_arr = Object.keys(point_model); for(let i = 0;i < point_arr.length;++i) { unit.form.mainfrm.OnSetPoints(point_model[point_arr[i]].x, point_model[point_arr[i]].y, point_model[point_arr[i]].z, point_model[point_arr[i]].radius, point_model[point_arr[i]].name); } } } //加载Mark function OnLoadMarks() { let work_condition = model.acax_app.view.GetCurrentWorkConditionIndex(); if(model.acax_app.view.GetProperty(work_condition) !== undefined && model.acax_app.view.GetProperty(work_condition).mark !== undefined ) { let mark_model = model.acax_app.view.GetProperty(work_condition).mark; let mark_arr = Object.keys(mark_model); for(let i = 0;i < mark_arr.length;++i) { unit.form.mainfrm.OnSetMarks(mark_model[mark_arr[i]].x, mark_model[mark_arr[i]].y, mark_model[mark_arr[i]].z, mark_model[mark_arr[i]].R, mark_model[mark_arr[i]].G, mark_model[mark_arr[i]].B, mark_model[mark_arr[i]]["字体大小"], mark_model[mark_arr[i]]["标记命名"], mark_model[mark_arr[i]].name); } } } //隐藏旧的工况 function HideWorkcondition() { if(model.acax_app.model.workArea.Current() !== false && model.acax_app.model.project.Current() !== "" &&model.acax_app.model.workCondition.Current() !== ""){ let old_workcondition_index = model.acax_app.view.GetCurrentWorkConditionIndex(); var point_model; var point_arr; if( model.acax_app.view.GetProperty(old_workcondition_index) === undefined || model.acax_app.view.GetProperty(old_workcondition_index).point === undefined) { point_model = {}; }else{ point_model = model.acax_app.view.GetProperty(old_workcondition_index).point; } point_arr = Object.keys(point_model); var mark_model; var mark_arr; if( model.acax_app.view.GetProperty(old_workcondition_index) === undefined || model.acax_app.view.GetProperty(old_workcondition_index).mark === undefined) { mark_model = {}; }else{ mark_model = model.acax_app.view.GetProperty(old_workcondition_index).mark; } mark_arr = Object.keys(mark_model); let constrain_data = model.acax_app.model.workCondition.Get(model.acax_app.model.workCondition.Current()); var old_arr_key ; if(Object.keys(constrain_data.constrain.db).length !== 0) { old_arr_key = Object.keys(constrain_data.constrain.db); }else{ old_arr_key = []; } //查看当前工程工况是否已加载 const path1 = model.acax_app.model.workArea.Current(); const workarea_name1 =path1.substring(path1.lastIndexOf('/') + 1); var cur_name = workarea_name1 + model.acax_app.model.project.Current() + model.acax_app.model.workCondition.Current(); var flag = 1; if(workcondition.includes(cur_name)) { for(let i = 0;i { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; let color = ""; //设置id let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } if(index) { id2index[id] = index; index2id[index] = id; } if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) { cur_id = info.id; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree => { //从工程中获取保存的model数据 if(model.acax_app.model.project.GetModel().pro_model){ //获取当前工程的名字 let pro_Index = model.acax_app.view.GetCurrentProjectIndex(); let pro_name = model.acax_app.path.Name(pro_Index); let cur_model = model.acax_app.model.project.GetModel().pro_model; findAndAppendByName(tree, pro_name, cur_model); } //赋值给dcip的树结构 tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; } ); //渲染3d模型 if(model.acax_app.model.project.GetModel().step === "unimported") { unit.form.mainfrm.ClearCanvas(); }else{ model.acax_app.view.Render3D(info=>{ unit.form.mainfrm.OnloadModel(info.model3d.step); }); } ui.tree_Model.column = [1, tree_color]; ui.tree_Model.position = cur_id; } //修改材料属性的名字 function ModifyMaterialName(new_name) { let tree_color = []; let cur_name = model.acax_app.model.materialProp.Current(); let flag = model.acax_app.control.materialProp.Rename(cur_name, new_name); let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex(); let cur_id; if(flag === true) { unit.form.mainfrm.OnCueline('修改成功', 'green'); }else{ unit.form.mainfrm.OnCueline('修改失败', 'red'); } model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; let color = ""; //设置id let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } if(index) { id2index[id] = index; index2id[index] = id; } if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) { cur_id = info.id; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree => { //从工程中获取保存的model数据 if(model.acax_app.model.project.GetModel().pro_model){ //获取当前工程的名字 let pro_Index = model.acax_app.view.GetCurrentProjectIndex(); let pro_name = model.acax_app.path.Name(pro_Index); let cur_model = model.acax_app.model.project.GetModel().pro_model; findAndAppendByName(tree, pro_name, cur_model); } //赋值给dcip的树结构 tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; } ); //渲染3d模型 if(model.acax_app.model.project.GetModel().step === "unimported") { unit.form.mainfrm.ClearCanvas(); }else{ model.acax_app.view.Render3D(info=>{ unit.form.mainfrm.OnloadModel(info.model3d.step); }); } ui.tree_Model.column = [1, tree_color]; ui.tree_Model.position = cur_id; } //修改的工程名 function ModifyProName(new_name) { let tree_color = []; let cur_name = model.acax_app.path.Name(model.acax_app.view.GetCurrentProjectIndex()); model.acax_app.model.project.Rename(cur_name, new_name); let cur_index = model.acax_app.view.GetCurrentWorkAreaIndex(); let cur_id; model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; let color = ""; //设置id let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } if(index) { id2index[id] = index; index2id[index] = id; } if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 0) === cur_index)) { cur_id = info.id; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree => { //从工程中获取保存的model数据 if(model.acax_app.model.project.GetModel().pro_model){ //获取当前工程的名字 let pro_Index = model.acax_app.view.GetCurrentProjectIndex(); let pro_name = model.acax_app.path.Name(pro_Index); let cur_model = model.acax_app.model.project.GetModel().pro_model; findAndAppendByName(tree, pro_name, cur_model); } //赋值给dcip的树结构 tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; } ); //渲染3d模型 if(model.acax_app.model.project.GetModel().step === "unimported") { unit.form.mainfrm.ClearCanvas(); }else{ model.acax_app.view.Render3D(info=>{ unit.form.mainfrm.OnloadModel(info.model3d.step); }); } ui.tree_Model.column = [1, tree_color]; ui.tree_Model.position = cur_id; } //处理字符串截掉后五位 function removeLastFiveCharacters(str) { str = String(str); if (str.length <= 5) { return ''; // 如果字符串长度小于等于 5,则返回空字符串 } return str.substring(0, str.length - 5); // 提取从 0 到倒数第 5 位的子字符串 } //点击弹出菜单 function OnContentClick(){ //获取一级子节点 let str = removeLastFiveCharacters(ui.tree_Model.content_menu); let model_id = g_cur_id2index_cache[str]; //let cur_name = model.acax_app.path.Name(model_id); switch (model.acax_app.path.Type(model_id)){ case 2: //unit.form.Rename.Show(); break; case 3: break; case 4: unit.form.RenameConstraint.Show(); break; case 5: unit.form.RenameMaterial.Show(); break; default: break; } } //右键单击树效果 function OnRightClick(){ let model_id = g_cur_id2index_cache[ui.tree_Model.position]; switch (model.acax_app.path.Type(model_id)){ case 2: /*ui.tree_Model.content_menu =[{ "name":"重命名", "icon":"", "id":ui.tree_Model.position + "13579" }];*/ break; case 3: break; case 4: ui.tree_Model.content_menu =[{ "name":"重命名", "icon":"", "id":ui.tree_Model.position + "13579" }]; break; case 5: ui.tree_Model.content_menu =[{ "name":"重命名", "icon":"", "id":ui.tree_Model.position + "13579" }]; break; default: break; } } //点击树 function OnClickTree(id, column, text){ //获取模型树的对应节点 let model_id = g_cur_id2index_cache[ui.tree_Model.position]; let cur_workarea = model.acax_app.view.GetCurrentWorkAreaIndex(); let cur_proj = model.acax_app.view.GetCurrentProjectIndex(); let cur_workcondition = model.acax_app.view.GetCurrentWorkConditionIndex(); model.acax_app.view.RenderNode(model_id, info => { console.log(info); }); switch (model.acax_app.path.Type(model_id)) { //切换工作区 case 0: //不是当前工作区,切换工作区 if(model_id !== cur_workarea){ model.acax_app.view.RenderNode(model_id, info => { //隐藏工作区工况 HideWorkcondition(); OpenWorkArea(info.prop); //切换到当前工作区 ui.tree_Model.position = g_cur_index2id_cache[model_id]; }); } break; //选中材料库 case 1: break; //切换工程 case 2: //不是当前工程,切换工程 if(model_id !== cur_proj){ //隐藏掉旧的工况 HideWorkcondition(); model.acax_app.view.RenderNode(model_id, info => { //切换工程 ChangePro(model.acax_app.path.Name(model_id)); //切换到当前工程 ui.tree_Model.position = g_cur_index2id_cache[model_id]; //在canvas显示新的约束 CreateContrainShow(); }); } break; //切换工况 case 3: //不是当前工况,切换工况 if(model_id !== cur_workcondition){ model.acax_app.view.RenderNode(model_id, info => { //隐藏工况 HideWorkcondition(); //切换工况,旧的隐藏 let old_data = ChangeWorkCondition(model.acax_app.path.Name(model_id)); ui.tree_Model.position = g_cur_index2id_cache[model_id]; //显示工况 CreateContrainShow(); }); } break; //选中约束 case 4: model.acax_app.view.RenderNode(model_id, info => { //切换到当前约束 model.acax_app.model.constrain.SwitchTo(model.acax_app.path.Name(model_id)); //将约束属性设置到对应面板 ChangeConstraint(Object.values(info.prop)[0], info.prop); //切换点击约束 ui.tree_Model.position = g_cur_index2id_cache[model_id]; //渲染到3D模型 if(ui.tree_Model.node.check_state === 2) { unit.form.mainfrm.HideAndShow(info.prop.cons_type, info.prop.unique, false); console.log("show"); }else if(ui.tree_Model.node.check_state === 0) { unit.form.mainfrm.HideAndShow(info.prop.cons_type, info.prop.unique, true); console.log("hide"); } }); break; //选中材料属性 case 5: model.acax_app.view.RenderNode(model_id, info => { //切换当前材料 model.acax_app.model.materialProp.SwitchTo(model.acax_app.path.Name(model_id)); unit.form.mainfrm.menu(3); unit.form.mainfrm.OnChangePicture(2, 1); unit.form.mainfrm.OnCueline('结构静力学材料设置', 'blue'); //将材料属性设置到面板 unit.form.mainfrm.setMaterial(info.prop); //切换到点击材料 ui.tree_Model.position = g_cur_index2id_cache[model_id]; }); break; default: break; } if(column === 1) { var clr = ui.ColorDialog(text); let cut_project_index = model.acax_app.view.GetCurrentProjectIndex(); let temp = model.acax_app.view.GetProperty(cut_project_index); temp.color[id] = clr; model.acax_app.view.SetProperty(cut_project_index, temp); let rgb = hexToRgb(clr); unit.form.mainfrm.LightFace(id, rgb); if(clr) { ui.tree_Model.column = [column, clr]; } } } //16进制转rgb function hexToRgb(hex) { // 去掉前缀 #(如果有) hex = hex.replace(/^#/, ''); // 如果是简写形式(#RGB),将其转换为完整形式(#RRGGBB) if (hex.length === 3) { hex = hex.split('').map(char => char + char).join(''); } // 解析 RGB 颜色值 const r = parseInt(hex.slice(0, 2), 16); const g = parseInt(hex.slice(2, 4), 16); const b = parseInt(hex.slice(4, 6), 16); return { r, g, b }; } //切换约束面板 function ChangeConstraint(constraint_name, prop) { let constraint = { "固定支撑":function(){ unit.form.mainfrm.OnChangeIndex(2); unit.form.mainfrm.menu(18); unit.form.mainfrm.changeConstrain(1, 0); // unit.form.mainfrm.OnChange unit.form.mainfrm.OnConChange(0); unit.form.mainfrm.setConstraint(prop); }, "梁":function(){ unit.form.mainfrm.OnChangeIndex(2); unit.form.mainfrm.menu(18); unit.form.mainfrm.changeConstrain(1, 1); unit.form.mainfrm.changeConstrain(2, 0); unit.form.mainfrm.OnConChange(1); unit.form.mainfrm.setConstraint(prop); }, "弹簧":function(){ unit.form.mainfrm.OnChangeIndex(2); unit.form.mainfrm.menu(18); unit.form.mainfrm.changeConstrain(1, 1); unit.form.mainfrm.changeConstrain(2, 1); unit.form.mainfrm.OnConChange(1); unit.form.mainfrm.setConstraint(prop); }, "连接":function(){ unit.form.mainfrm.OnChangeIndex(2); unit.form.mainfrm.menu(18); unit.form.mainfrm.changeConstrain(1, 1); unit.form.mainfrm.changeConstrain(2, 2); unit.form.mainfrm.OnConChange(1); unit.form.mainfrm.setConstraint(prop); }, "梁(非均匀)":function(){ }, "集中载荷压力":function(){ unit.form.mainfrm.OnChangeIndex(2); unit.form.mainfrm.menu(17); unit.form.mainfrm.changeConstrain(3, 0); unit.form.mainfrm.OnForceChange(0); unit.form.mainfrm.setConstraint(prop); }, "分布载荷压力":function(){ unit.form.mainfrm.OnChangeIndex(2); unit.form.mainfrm.menu(17); unit.form.mainfrm.changeConstrain(3, 1); unit.form.mainfrm.OnForceChange(1); unit.form.mainfrm.setConstraint(prop); }, "rb3":function(){ unit.form.mainfrm.OnChangeIndex(2); unit.form.mainfrm.menu(23); unit.form.mainfrm.setConstraint(prop); } }; constraint[constraint_name](); } //判断图标 function CheckPicture(idx) { switch (idx) { case 0: return "workarea"; case 2: return "project"; case 3: return "workcondition"; case 4: return "constrain"; case 5: return "materialproperty"; default: return null; // 或者抛出一个错误,比如 `throw new Error("Invalid index");` } } //切换工作区 function OpenWorkArea(fname) { let tree_color = []; fname = fname.replace(/\/+/g, "\\"); var work_path = model.acax_app.model.workArea.List(); //渲染模型树 for(var i = 0;i < work_path.length;++i) { work_path[i] = work_path[i].replace(/\/+/g, "\\"); if(fname === work_path[i]){ model.acax_app.control.workArea.SwitchTo(i); //渲染3d模型 if(model.acax_app.model.project.GetModel().step === "unimported") { unit.form.mainfrm.ClearCanvas(); model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; let color = ""; //设置id let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; }else if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) { cur_check_state = 2; } //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; if(index) { id2index[id] = index; index2id[index] = id; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree => { //赋值给dcip的树结构 tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; ui.tree_Model.column = [1, tree_color]; } ); }else{ model.acax_app.view.Render3D(info=>{ unit.form.mainfrm.OnloadModel(info.model3d.step); unit.form.mainfrm.SetColor(difference); CreateContrainShow(); }); } } } CheckCtrlProcess(); console.log(model.global_ctrl); } //切换工程 function ChangePro(pro_name) { let tree_color = []; model.acax_app.control.project.SwitchTo(pro_name); //渲染3d模型 if(model.acax_app.model.project.GetModel().step === "unimported") { unit.form.mainfrm.ClearCanvas(); model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; let color = ""; //设置id let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; }else if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) { cur_check_state = 2; } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } if(index) { id2index[id] = index; index2id[index] = id; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree => { //从工程中获取保存的model数据 //console.log(model.acax_app.model.project.GetModel().pro_model); if(model.acax_app.model.project.GetModel().pro_model){ //获取当前工程的名字 let pro_Index = model.acax_app.view.GetCurrentProjectIndex(); let pro_name = model.acax_app.path.Name(pro_Index); let cur_model = model.acax_app.model.project.GetModel().pro_model; findAndAppendByName(tree, pro_name, cur_model); } //赋值给dcip的树结构 tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; ui.tree_Model.column = [1, tree_color]; } ); }else{ model.acax_app.view.Render3D(info=>{ unit.form.mainfrm.OnloadModel(info.model3d.step); unit.form.mainfrm.SetColor(difference); }); } CheckCtrlProcess(); console.log(model.global_ctrl); } //切换工况 function ChangeWorkCondition(wor_name) { let tree_color = []; var old_data = model.acax_app.model.workCondition.Get(model.acax_app.model.workCondition.Current()); model.acax_app.control.workCondition.SwitchTo(wor_name); model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; let color = ""; //设置id let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; }else if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) { cur_check_state = 2; } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } if(index) { id2index[id] = index; index2id[index] = id; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree => { //从工程中获取保存的model数据 if(model.acax_app.model.project.GetModel().pro_model){ //获取当前工程的名字 let pro_Index = model.acax_app.view.GetCurrentProjectIndex(); let pro_name = model.acax_app.path.Name(pro_Index); let cur_model = model.acax_app.model.project.GetModel().pro_model; findAndAppendByName(tree, pro_name, cur_model); } //赋值给dcip的树结构 tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; } ); ui.tree_Model.column = [1, tree_color]; CheckCtrlProcess(); // console.log(model.global_ctrl); return old_data; } //创建工作区 function CreateWorkArea(name) { let tree_color = []; console.log("1111"); HideWorkcondition(); console.log("2222"); model.acax_app.control.workArea.Append(name); let cur_id; model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; let color = ""; //设置id let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; } if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) { cur_check_state = 2; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { tree_color.push(""); } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } if(index) { id2index[id] = index; index2id[index] = id; } if("workArea" === info.name) { cur_id = info.id; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree=>{ tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; }); ui.tree_Model.position = cur_id; //渲染3d模型 unit.form.mainfrm.ClearCanvas(); ui.tree_Model.column = [1, tree_color]; CheckCtrlProcess(); } //创建工程 function CreateProject(name) { let tree_color = []; //隐藏掉旧的工况 HideWorkcondition(); model.acax_app.control.project.Create(name); let cur_name = model.acax_app.model.project.Current(); let cur_index = model.acax_app.view.GetCurrentWorkAreaIndex(); let cur_id; model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; let color = ""; //设置id let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; } if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) { cur_check_state = 2; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { tree_color.push(""); } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } if(index) { id2index[id] = index; index2id[index] = id; } if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 0) === cur_index)) { cur_id = info.id; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree=>{ tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; }); ui.tree_Model.position = cur_id; //渲染3d模型 if(model.acax_app.model.project.GetModel().step === "unimported") { unit.form.mainfrm.ClearCanvas(); } ui.tree_Model.column = [1, tree_color]; CheckCtrlProcess(); } //导入模型 function OnOpenStepFile() { if(model.global_ctrl[0] && model.global_ctrl[1] ) { var model_file = myArray[parseFloat(ui.listbox.index)]; model.acax_app.control.ImportStep(model_file, (model_file, model_plyfile)=>{ model.acax_app.view.Render3D(info=>{ unit.form.mainfrm.OnloadModel(info.model3d.step); }); } ); }else{ unit.form.mainfrm.OnCueline('未创建工程', 'red'); return; } } //插入新子节点 function findAndAppendByName(json, targetName, newChild) { if (json.name === targetName) { // 拼接新的 JSON 数据 if (!json.children) { json.children = []; } json.children.unshift(newChild); return true; // 找到后返回 true } // 遍历子节点递归查找 if (json.children) { for (const child of json.children) { if (findAndAppendByName(child, targetName, newChild)) { return true; // 如果找到目标节点,结束递归 } } } return false; // 没找到返回 false } //给面节点改名字并添加check_state属性 function updateJsonNodes(jsonData) { let count = 1; // 用于计数生成 Face1, Face2... //let count_id = 100000; function traverse(node) { // 为每个节点添加 check_state: 2 属性 node.check_state = 3; node.icon = ''; node.r_id = node.id; node.id = node.faceId; //node.id = ++count_id; if(node.id === 100001) { node.icon = 'model2'; }else if(node.id === 100002) { node.icon = 'model3'; } // 如果存在 children 属性,则递归处理 if (node.children && Array.isArray(node.children)) { for (let child of node.children) { traverse(child); // 递归遍历子节点 } } else if (node.name && node.name.startsWith("Face_")) { // 修改 name 值为 Face1, Face2... node.name = `Face${count}`; node.icon = 'face'; count++; } } traverse(jsonData); return jsonData; } //查找模型的第一个节点值获取id function getFirstId(obj) { // 检查是否有 children 并提取第一个节点的 id if (obj.children && obj.children.length > 0) { return obj.children[0].id; } return null; // 如果没有子节点,返回 null } // 深度优先遍历函数 function getTreeColorsInOrder(tree) { // 定义存储颜色的数组 const tree_color = []; // 定义递归函数 function dfs(node) { // 如果当前节点有 color 属性,则加入数组 if (node.color !== undefined) { tree_color.push(node.color); } // 按顺序遍历子节点 if (node.children && node.children.length > 0) { node.children.forEach(child => dfs(child)); } } // 调用递归函数,传入根节点 dfs(tree); // 返回颜色数组 return tree_color; } //将模型颜色存成map function getTreeIdColorMap(tree) { // 定义存储 id 和 color 的对象 const idColorMap = {}; // 定义递归函数 function dfs(node) { // 检查当前节点的 name 属性是否包含 "face",以及是否具有 id 和 color 属性 if (node.name && node.name.includes("Face") && node.id !== undefined && node.color !== undefined) { idColorMap[node.id] = node.color; } // 如果存在子节点,递归遍历 if (node.children && node.children.length > 0) { node.children.forEach(child => dfs(child)); } } // 调用递归函数,传入根节点 dfs(tree); // 返回存储的 id 和 color 键值对对象 return idColorMap; } //获取模型面的颜色保存到project function SetModelColor(Idx) { let model_color = getTreeIdColorMap(Idx); let cut_project_index = model.acax_app.view.GetCurrentProjectIndex(); let model_prop = model.acax_app.view.GetProperty(cut_project_index); if(model_prop === undefined) { model_prop = {}; model_prop.color = model_color; model.acax_app.view.SetProperty(cut_project_index, model_prop); }else{ model_prop.color = model_color; model.acax_app.view.SetProperty(cut_project_index, model_prop); } //console.log(model.acax_app.view.GetProperty(cut_project_index)); } //将颜色给模型赋回去 function assignColorsToTree(tree, idColorMap) { // 定义递归函数 function dfs(node) { // 如果当前节点的 id 存在于 idColorMap 中,赋值回 color if (node.id !== undefined && idColorMap[node.id] !== undefined) { node.color = idColorMap[node.id]; } // 按顺序遍历子节点 if (node.children && node.children.length > 0) { node.children.forEach(child => dfs(child)); } } // 调用递归函数,传入根节点 dfs(tree); // 返回更新后的树 return tree; } //找记录颜色和生成颜色不同的键值对 function findDifferences(oldMap, newMap) { const differences = {}; for (const key in oldMap) { if (oldMap[key] !== newMap[key]) { differences[key] = newMap[key]; } } return differences; } var difference = {}; //获取工程中颜色,为模型涂色 function SetUserColor() { var dif_key = Object.keys(difference); console.log(dif_key.length); for(let i = 0;i < dif_key.length;++i) { let rgb = hexToRgb(difference[dif_key[i]]); try { unit.form.mainfrm.LightFace(dif_key[i], rgb); // 调用设置颜色 } catch (error) { console.error(`Failed to apply color for key ${dif_key[i]}`, error); } } } //导入模型树节点 function OnTree(Idx){ let tree_color = []; //console.log(JSON.stringify(Idx, null, 2)); updateJsonNodes(Idx); //模型树颜色 let cut_project_index = model.acax_app.view.GetCurrentProjectIndex(); if(model.acax_app.view.GetProperty(cut_project_index) !== undefined ) { //获取工程中的模型颜色,为树赋颜色 if(model.acax_app.view.GetProperty(cut_project_index).color!==undefined ) { var old_map = getTreeIdColorMap(Idx); //console.log(old_map); //console.log(model.acax_app.view.GetProperty(cut_project_index).color); difference = findDifferences(old_map, model.acax_app.view.GetProperty(cut_project_index).color); //console.log(difference); assignColorsToTree(Idx, model.acax_app.view.GetProperty(cut_project_index).color); } }else{ SetModelColor(Idx); } model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; //设置id let color = ""; let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; } if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) { cur_check_state = 2; } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } if(index) { id2index[id] = index; index2id[index] = id; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree => { //从工程中获取保存的model数据 //插入模型树节点与工程节点进行拼接 let pro_Index= model.acax_app.view.GetCurrentProjectIndex(); let pro_name = model.acax_app.path.Name(pro_Index); findAndAppendByName(tree, pro_name, Idx); //将模型树节点与工程节点拼接后保存到model中 let pro_model = model.acax_app.model.project.GetModel(); pro_model.pro_model = Idx; model.acax_app.model.project.SetModel(pro_model); tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; } ); ui.tree_Model.column = [1, tree_color]; ui.tree_Model.position = getFirstId(Idx); //表示模型已导入 model.global_ctrl[2] = true; } //创建工况 function CreateWorkCondition(name){ let tree_color = []; //隐藏掉旧的工况 HideWorkcondition(); let condition_index = model.acax_app.control.workCondition.Create(name); let cur_name = model.acax_app.model.workCondition.Current(); let cur_index = model.acax_app.view.GetCurrentProjectIndex(); let cur_id; //console.log(model.acax_app.path.Parent(cur_index, 2) === model.acax_app.view.GetCurrentProjectIndex()); model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; let color = ""; //设置id let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; } if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) { cur_check_state = 2; } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } if(index) { id2index[id] = index; index2id[index] = id; } if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 2) === cur_index)) { cur_id = info.id; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree => { //获取当前工程的名字 let pro_Index = model.acax_app.view.GetCurrentProjectIndex(); let pro_name = model.acax_app.path.Name(pro_Index); //模型存在在加载 if(model.acax_app.model.project.GetModel().pro_model) { let cur_model = model.acax_app.model.project.GetModel().pro_model; findAndAppendByName(tree, pro_name, cur_model); } //赋值给dcip的树结构 tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; } ); ui.tree_Model.position = cur_id; ui.tree_Model.column = [1, tree_color]; } //创建材料属性 function CreateMaterial(mat) { let tree_color = []; model.acax_app.control.materialProp.Create(mat); let cur_name = model.acax_app.model.materialProp.Current(); let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex(); let cur_id; model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; let color = ""; //设置id let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; }else if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) { cur_check_state = 2; } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } if(index) { id2index[id] = index; index2id[index] = id; } if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) { cur_id = info.id; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree => { //获取当前工程的名字 let pro_Index = model.acax_app.view.GetCurrentProjectIndex(); let pro_name = model.acax_app.path.Name(pro_Index); if(model.acax_app.model.project.GetModel().pro_model) { let cur_model = model.acax_app.model.project.GetModel().pro_model; findAndAppendByName(tree, pro_name, cur_model); } //赋值给dcip的树结构 tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; } ); //将材料属性添加到模型信息中 model.acax_app.view.Render3D(info=>{ console.log(info.materialProps); info.materialProps.push(mat); console.log("2222222"); }); ui.tree_Model.position = cur_id; ui.tree_Model.column = [1, tree_color]; model.global_ctrl[5] = true; } //修改材料面板属性属性 function ModifyMaterial(material) { //获取当前材料的名字 let material_name = model.acax_app.model.materialProp.Current(); model.acax_app.control.materialProp.Set(material, material_name); unit.form.mainfrm.OnCueline('修改成功', 'green'); } //创建载荷 function CreateBoundary(Load, name) { console.log(model.global_ctrl); if(!model.global_ctrl[0] || !model.global_ctrl[1] || !model.global_ctrl[2] || !model.global_ctrl[3]) { unit.form.mainfrm.OnCueline('未满足创建条件', 'red'); return; } let tree_color = []; let load = model.acax_app.control.constrain.Create(Load, name); let cur_name = model.acax_app.model.constrain.Current(); let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex(); var cur_id; model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let icon = ""; let color = ""; //设置id let cur_check_state = 0; let cur_type = model.acax_app.path.Type(info.index); if( cur_type === 0 || cur_type === 2 || cur_type === 5) { cur_check_state = 3; }else if((cur_type === 4 && model.acax_app.path.Parent(info.index, 3) === model.acax_app.view.GetCurrentWorkConditionIndex()) ||(info.index === model.acax_app.view.GetCurrentWorkConditionIndex())) { cur_check_state = 2; } let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; //赋予图标 if(CheckPicture(cur_type)){ icon = CheckPicture(cur_type); } if(index) { id2index[id] = index; index2id[index] = id; } if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) { cur_id = info.id; cur_check_state = 2; } if(cur_type === 0 || cur_type === 2 ||cur_type === 3) { color = "#bbbbbb"; } //获取约束颜色 if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) { color = model.acax_app.model.constrain.Get(info.name).color; } //将第一个节点设为无选择框 if(info.id === 1) { cur_check_state = 3; icon = "form"; } return { name : info.name, icon : icon, id : info.id, check_state : cur_check_state, color : color }; }, tree => { //获取当前工程的名字 let pro_Index = model.acax_app.view.GetCurrentProjectIndex(); let pro_name = model.acax_app.path.Name(pro_Index); if(model.acax_app.model.project.GetModel().pro_model) { let cur_model = model.acax_app.model.project.GetModel().pro_model; findAndAppendByName(tree, pro_name, cur_model); } //赋值给dcip的树结构 tree_color = getTreeColorsInOrder(tree); ui.tree_Model.tree = tree; } ); //将载荷属性添加到模型信息中 ui.tree_Model.position = cur_id; //console.log(tree_color); ui.tree_Model.column = [1, tree_color]; model.acax_app.view.Render3D(info=>{ info.constrains.push(Load); }); } //修改载荷面板属性 function ModifyConstraint(constrain) { let constrain_name = model.acax_app.model.constrain.Current(); model.acax_app.control.constrain.Set(constrain, constrain_name); unit.form.mainfrm.OnCueline('修改成功', 'green'); } function OnMessage(idx){ ui.cueline.value += idx + '\n'; ui.cueline.row = -1; } function OnChangeMenu(Idx){ ui.tree_menu.index = parseInt(Idx); } function OnDeleteFile() { myArray.splice(parseFloat(ui.listbox.index), 1); ui.listbox.list = [ myArray ]; } function OnOpenFile(){ var fname = ui.OpenFileDialog("Import File", unit.dir + 'data/', "Step Files(*.step *.stp);;Iges Files(*.iges *.igs);;Nastran Files(*.nas)"); model.write(fname, model.getCurrentDirectory() + '/data/address.txt'); myArray.push(fname); ui.listbox.list = [ myArray ]; } function OnChangeOptions(){ options = !options; ui.stack_options.visible = options; } function OnTopMenu(idx) { ui.stack_import.visible = true; ui.stack_import.index = parseInt(idx) - 1; ui.pb_import01.valid = ui.pb_import02.valid = ui.pb_import03.valid = ui.pb_import04.valid = ui.pb_import05.valid = false; //model.ide_info(idx); if (parseInt(idx) === 1) { ui.pb_import01.valid = true; } if (parseInt(idx) === 2) { ui.pb_import02.valid = true; } if (parseInt(idx) === 3) { ui.pb_import03.valid = true; } if (parseInt(idx) === 4) { ui.pb_import04.valid = true; } if (parseInt(idx) === 5) { ui.pb_import05.valid = true; } } //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; } ////////////////////////////////////////////////////////////////////////// // 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); } }