//////////////////////////////////////////////////////////////////////////// // 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; } //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 OnClickTree(){ //获取模型树的对应节点 let model_id = g_cur_id2index_cache[ui.tree_Model.position]; 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 => { OpenWorkArea(info.prop); }); } break; //选中材料库 case 1: break; //切换工程 case 2: //不是当前工程,切换工程 if(model_id !== cur_proj){ model.acax_app.view.RenderNode(model_id, info => { unit.form.physics_material.FindMateial(info.prop); }); } break; //切换工况 case 3: break; //选中约束 case 4: break; //选中材料属性 case 5: model.acax_app.view.RenderNode(model_id, info => { unit.form.mainfrm.menu(3); unit.form.mainfrm.OnChangePicture(2, 1); unit.form.mainfrm.OnCueline('结构静力学材料设置', 'blue'); console.log(info.prop); unit.form.mainfrm.setMaterial(info.prop); }); break; default: break; } } //测试函数 function OnTest(){ 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=>{ 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; } console.log(info); return { name : info.name, icon : info.icon, id : info.id, check_state : info.index }; }, 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 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=>{ 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; } console.log(info); return { name : info.name, icon : info.icon, id : info.id, check_state : info.index }; }, 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 CreateWorkArea(name) { model.acax_app.control.workArea.Append(name); model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ 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 : 3 }; }, 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); }); } } //创建工程 function CreateProject(name) { model.acax_app.control.project.Create(name); model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ let id2index = g_cur_id2index_cache; let index2id = g_cur_index2id_cache; let index = info.index; let id = info.id; return { name : info.name, icon : info.icon, id : info.id, check_state : 2 }; }, tree=>{ // console.log(model.acax_app.utils.FormatJSON(tree)+'\n'); 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 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); }); // unit.form.mainfrm.OnSend('openSTLFile ' + model.getCurrentDirectory() + ' ' + myArray[parseFloat(ui.listbox.index)]); //unit.form.mainfrm.OnCueline(`Loading ${myArray[parseFloat(ui.listbox.index)]} ...`, 'Blue'); //model.setStepPath(model_file); //console.log(model_file); } ); } //插入新子节点 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 } //将模型的id值加密与模型树一一对应 function printIds(node) { if (node.id !== undefined) { id2index[id] = model.acax_app.path.Path; } if (Array.isArray(node.children)) { node.children.forEach(child => printIds(child)); } } //导入模型树节点 function OnTree(Idx){ model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ 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 : info.index }; }, 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); ui.tree_Model.tree = tree; } ); } //创建工况 function CreateWorkCondition(name){ let condition_index = model.acax_app.control.workCondition.Create(name); model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ console.log(info); 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 : 2 }; }, tree => { //获取当前工程的名字 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; } ); } //创建材料属性 function CreateMaterial(mat) { let material = model.acax_app.control.materialProp.Create(mat); model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ console.log(info); 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 : 2 }; }, tree => { //获取当前工程的名字 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; } ); } //创建载荷 function CreateBoundary(Load) { let load = model.acax_app.control.constrain.Create(Load); model.acax_app.view.RenderTree(() => { g_cur_id2index_cache = {}; g_cur_index2id_cache = {}; }, info=>{ console.log(info); 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 : 2 }; }, tree => { //获取当前工程的名字 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; } ); } 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); } }