1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597 |
- ////////////////////////////////////////////////////////////////////////////
- // 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 = {};
- 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;
- 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 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);
- }
-
- /* if(self_prop.brep) {
- old_brep_path = model.acax_app.view.GetProperty(cut_workcondition_index).brep;
- brep_path = old_brep_path.concat(brep_path);
- brep_path = [...new Set(brep_path)];
- }
- let new_prop = model.acax_app.view.GetProperty(cut_workcondition_index);
- new_prop.brep = brep_path;
- model.acax_app.view.SetProperty(cut_workcondition_index, new_prop);*/
-
- //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);
-
- }
-
- }
- console.log("rb3");
- //集中载荷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$ con 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]["位置标记"] + " "+ 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.constrain.Database());
- GenerateFile() ;
- //console.log(model.acax_app.model.constrain.Get(model.acax_app.model.constrain.Current()));
- }
- //创建约束显示
- function CreateContrainShow() {
- if(model.acax_app.model.workArea.Current() !== false && model.acax_app.model.project.Current() !== "" &&model.acax_app.model.workCondition.Current() !== ""){
- //获取工况数据库
- 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.Database().list[0];
- 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 < 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();
- }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);
- console.log("集中载荷压力");
- }
- 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.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();
- workcondition.push(cur_name);
-
- }
- }
-
- }
- //已创建但被隐藏,显示点
- function ShowPoints() {
- 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);
- }
- }
- //加载点
- function OnLoadPoints() {
- 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.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);
- }
- }
- //隐藏旧的工况
- 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);
-
- 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 = [];
- }
- //旧的隐藏
- //紫色包围盒开关
- var flag = 1;
- for(let i = 0;i <old_arr_key.length;++i ) {
- let type = constrain_data.constrain.db[old_arr_key[i]].cons_type;
- unit.form.mainfrm.HideAndShow(type, constrain_data.constrain.db[old_arr_key[i]].unique, true);
- if(type === "rb3" && flag) {
- unit.form.mainfrm.HideAndShow("pick", "rb3", true);
- flag = 0;
- }
- }
- for(let i = 0;i < point_arr.length;++i) {
- unit.form.mainfrm.HideAndShow("points", point_model[point_arr[i]].name, true);
- }
- }
-
- }
- //获取当前工作区名称加当前工程名称加当前工况名称
- function GetCurUniqueName() {
- const path = model.acax_app.model.workArea.Database().list[0];
- const workarea_name =path.substring(path.lastIndexOf('/') + 1);
- const proj_name = model.acax_app.model.project.Current();
- const workcondition_name = model.acax_app.model.workCondition.Current();
- return workarea_name + proj_name + workcondition_name;
- }
- //生成点
- function SetPoint(node) {
- 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_prop = {};
- let point = {};
- point.point1 = node;
- console.log(point);
- model_prop.point = point;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
-
- }else if(model_prop.point === undefined){
- let point = {};
- point.point1 = node;
- console.log(point);
- model_prop.point = point;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
- }else{
-
- let len = Object.keys(model_prop.point).length;
- let temp = "point" + (len + 1);
- model_prop.point[temp] = node;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
-
- }
- //console.log(model.acax_app.view.GetProperty(cut_workcondition_index));
-
- }
- //生成brep文件
- function SetBrepFile(brep_path){
- 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_prop = {};
- let brep = {};
- brep.brep1 = brep_path;
- console.log(brep);
- model_prop.brep = brep;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
-
- }else if(model_prop.brep === undefined){
- let brep = {};
- brep.brep1 = brep_path;
- //console.log(brep);
- model_prop.brep = brep;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
- }else{
- let brep_arr = Object.keys(model_prop.brep);
-
- var i = 0;
- for( i = 0;i < brep_arr.length;++i) {
- console.log(model_prop.brep[brep_arr[i]].brep);
- console.log(brep_path.brep);
- if(model_prop.brep[brep_arr[i]].brep === brep_path.brep) {
- break;
- }
- }
- if(i === brep_arr.length) {
- let temp = "brep" + (brep_arr.length + 1);
- model_prop.brep[temp] = brep_path;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
- }
-
- }
- //console.log(model.acax_app.view.GetProperty(cut_workcondition_index));
- }
- //生成BPP
- function SetBPPProperty(BPP) {
-
- 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_prop = {};
- model_prop.BPP = BPP;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
- }else{
- model_prop.BPP = BPP;
- model.acax_app.view.SetProperty(cut_workcondition_index, model_prop);
- }
- console.log(model.acax_app.view.GetProperty(cut_workcondition_index));
- // console.log(model.acax_app.view.GetProperty(pro_index));
- }
- //修改约束属性的名字
- function ModifyConstraintName(new_name) {
- let cur_name = model.acax_app.model.constrain.Current();
- let flag = model.acax_app.control.constrain.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=>{
- //设置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(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;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : cur_check_state
- };
-
- },
- 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的树结构
- 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.position = cur_id;
- }
- //修改材料属性的名字
- function ModifyMaterialName(new_name) {
- 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=>{
- //设置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(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;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : cur_check_state
- };
-
- },
- 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的树结构
- 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.position = cur_id;
- }
- //修改的工程名
- function ModifyProName(new_name) {
- 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=>{
- //设置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(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;
- }
-
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : cur_check_state
- };
-
- },
- 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的树结构
- 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.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;
- }
-
- }
- var workcondition = [];
- //点击树
- function OnClickTree(){
- //获取模型树的对应节点
- //ui.tree_Model.
- 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;
- }
- }
- //切换约束面板
- function ChangeConstraint(constraint_name, prop) {
- let constraint = {
- "固定支撑":function(){
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 0);
- unit.form.mainfrm.setConstraint(prop);
- },
- "梁":function(){
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 1);
- unit.form.mainfrm.changeConstrain(2, 0);
- unit.form.mainfrm.setConstraint(prop);
- },
- "弹簧":function(){
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 1);
- unit.form.mainfrm.changeConstrain(2, 1);
- unit.form.mainfrm.setConstraint(prop);
- },
- "连接":function(){
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 1);
- unit.form.mainfrm.changeConstrain(2, 2);
- unit.form.mainfrm.setConstraint(prop);
- },
- "梁(非均匀)":function(){
- },
- "集中载荷压力":function(){
- unit.form.mainfrm.menu(17);
- unit.form.mainfrm.changeConstrain(3, 0);
- unit.form.mainfrm.setConstraint(prop);
- },
- "分布载荷压力":function(){
- unit.form.mainfrm.menu(17);
- unit.form.mainfrm.changeConstrain(3, 1);
- unit.form.mainfrm.setConstraint(prop);
- },
- "rb3":function(){
- unit.form.mainfrm.menu(23);
- unit.form.mainfrm.setConstraint(prop);
- }
- };
-
- constraint[constraint_name]();
- }
- //测试函数
- 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);
- }
- //切换工作区
- function OpenWorkArea(fname) {
- 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);
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- //设置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(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : cur_check_state
- };
-
- },
- 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的树结构
- 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);
- CreateContrainShow();
- });
- }
-
- }
- //切换工程
- function ChangePro(pro_name) {
- model.acax_app.control.project.SwitchTo(pro_name);
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
-
- //设置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(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : cur_check_state
- };
-
- },
- 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的树结构
- 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);
- });
- }
-
- }
- //切换工况
- function ChangeWorkCondition(wor_name) {
- 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=>{
- //设置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(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
-
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : cur_check_state
- };
-
- },
- 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的树结构
- 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);
- });
- }*/
- return old_data;
- }
- //创建工作区
- function CreateWorkArea(name) {
- let tree_color = [];
- HideWorkcondition();
- model.acax_app.control.workArea.Append(name);
- let cur_id;
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
-
- //设置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(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- if("workArea" === info.name) {
- cur_id = info.id;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : cur_check_state
- };
- },
- 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();
- }else{
- model.acax_app.view.Render3D(info=>{
- unit.form.mainfrm.OnloadModel(info.model3d.step);
- });
- }
- ui.tree_Model.column = [1, tree_color];
- }
- //创建工程
- 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=>{
- //设置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(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;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : cur_check_state
- };
-
- },
- 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();
- }else{
- model.acax_app.view.Render3D(info=>{
- unit.form.mainfrm.OnloadModel(info.model3d.step);
- });
- }
- ui.tree_Model.column = [1, tree_color];
- }
- //导入模型
- function OnOpenStepFile() {
-
- 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);
- });
- }
- );
-
- }
- //插入新子节点
- 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 = ++count_id;
- node.color = getRandomHexColor();
- // 如果存在 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}`;
- 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 dfsSetColor(node) {
- // 如果节点有 color 属性,加入数组
- if (node.color) {
- tree_color.push(node.color);
- }
- // 遍历子节点
- if (node.children && node.children.length > 0) {
- node.children.forEach(child => dfs(child));
- }
- }
- //导入模型树节点
- function OnTree(Idx){
- let tree_color = [];
- updateJsonNodes(Idx);
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- //设置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(cur_type === 0 || cur_type === 2 ||cur_type === 3) {
- color = "";
- }
- if(cur_type === 4 && model.acax_app.view.GetCurrentWorkConditionIndex() === model.acax_app.path.Parent(info.index, 3)) {
- console.log(JSON.stringify(model.acax_app.model.constrain.Get(info.name), null, 2));
- color = model.acax_app.model.constrain.Get(info.name).color;
- }
- if(index) {
- id2index[id] = index;
- index2id[index] = id;
- }
- return {
- name : info.name,
- icon : info.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);
- 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);
- console.log(JSON.stringify(tree, null, 2));
- dfsSetColor(tree);
- ui.tree_Model.tree = tree;
- }
- );
- ui.tree_Model.column = [1, tree_color];
- ui.tree_Model.position = getFirstId(Idx);
- }
- //创建工况
- function CreateWorkCondition(name){
- //隐藏掉旧的工况
- 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=>{
-
- //设置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(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;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : cur_check_state
- };
-
- },
- 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的树结构
- ui.tree_Model.tree = tree;
- }
- );
-
- ui.tree_Model.position = cur_id;
- tree_color.push("");
- ui.tree_Model.column = [1, tree_color];
- }
- //创建材料属性
- function CreateMaterial(mat) {
- 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=>{
-
- //设置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(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;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : cur_check_state
- };
-
- },
- 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的树结构
- ui.tree_Model.tree = tree;
- }
- );
- ui.tree_Model.position = cur_id;
- //将材料属性添加到模型信息中
- model.acax_app.view.Render3D(info=>{
- info.model3d.materialProps.push(mat);
- });
- tree_color.push(getRandomHexColor());
- ui.tree_Model.column = [1, tree_color];
-
- }
- //修改材料面板属性属性
- 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) {
- 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=>{
-
- //设置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(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;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : cur_check_state
- };
-
- },
- 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的树结构
- ui.tree_Model.tree = tree;
- }
- );
- //将载荷属性添加到模型信息中
- console.log(cur_id);
- ui.tree_Model.position = cur_id;
- model.acax_app.view.Render3D(info=>{
- info.model3d.constrains.push(Load);
-
- });
- tree_color.push(getRandomHexColor());
- ui.tree_Model.column = [1, tree_color];
-
- }
- //修改载荷面板属性
- 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);
- }
- }
|