//////////////////////////////////////////////////////////////////////////// // System Pre-define Functions // 95099372-ef3e-11ea-9c81-bf848405c62e var dock_widget = false; var dock_widget1 = false; var dock_widget2 = false; var dock_widget3 = false; var g_preview = false; var g_io = false; var g_wid = false; let myArray = []; var res = []; var judge = 0; var startEnd = 0; var vtkContext = null; var workData = null; var postManage = null; function OnDockerChange(){ updateDockerButtonStatus(); } function OnResize() { if (dock_widget && !ui.docker.isVisible(dock_widget)) { showLeftDocker(true); } } function OnInitDocker() { dock_widget1 = appendDockPane(unit.form.toolbar, "", 4, 1|2|4); dock_widget2 = appendDockPane(unit.form.tree, "模型树", 1, 1|2); } function updateDockerButtonStatus() { if (!dock_widget) { return; } //unit.form.cw_topmenu.onUpdateBtn(!ui.docker.isFloat(dock_widget), !ui.docker.isVisible(dock_widget)); } function appendDockPane(sub_form, title, init_pos, allow_pos, features) { let dw = sub_form.CreateDock(title); if (features) { ui.docker.setFeatures(features); } ui.docker.setAllowAreas(dw, allow_pos); ui.docker.dock(dw, init_pos); return dw; } function showLeftDocker(flag) { ui.docker.show(dock_widget, flag); updateDockerButtonStatus(); } function InitCanvasIOEngine() { ui.canvas.adaptor('nastran', function(fname_nas) { //console.log(fname_nas); console.time('Nastran Import'); model.cueline('解析并加载Nastran文件 ...'); model.updateGeometry(ui.geometry); ui.canvas.db = null; parent.mesh.shell.ClearCache(); parent.mesh.shell.LoadNastranToCache(fname_nas); console.timeEnd('Nastran Import'); model.cueline('创建图形缓冲区 ...'); console.time('Nastran Buffer'); var buf = parent.mesh.shell.RenderToGLCache(); console.timeEnd('Nastran Buffer'); model.cueline('生成图形数据库并渲染 ...'); return buf; }); ui.canvas.adaptor('step', function(fname_step) { console.log('Step'); console.time('Step Import'); model.cueline('解析并加载STEP文件 ...'); model.updateGeometry(ui.geometry); ui.canvas.db = null; comx.occore.Clear(); comx.occio.ImportStepEx(comx.occore.GetEntryEx(), fname_step); var modelTree = comx.occio.ImportStepEx(comx.occore.GetEntryEx(), fname_step); //ui.tree.tree = JSON.parse(modelTree); unit.form.tree.OnTree(JSON.parse(modelTree)); var hashCodes = comx.occio.GetFaceHashCodes(comx.occore.GetEntryEx()); //console.log(JSON.parse(hashCodes)); model.setHash(JSON.parse(hashCodes)); console.timeEnd('Step Import'); model.cueline('创建图形缓冲区 ...'); console.time('Step Buffer'); var gl_buf = comx.occrender.RenderToBufferEx(comx.occore.GetEntryEx(), true, false); console.timeEnd('Step Buffer'); model.cueline('生成图形数据库并渲染 ...'); return gl_buf; }); ui.canvas.adaptor('iges', function(fname_step) { console.time('Iges Import'); model.cueline('解析并加载IGES文件 ...'); model.updateGeometry(ui.geometry); ui.canvas.db = null; comx.occore.Clear(); comx.occio.ImportIges(comx.occore.GetEntry(), fname_step); console.timeEnd('Iges Import'); model.cueline('创建图形缓冲区 ...'); console.time('Iges Buffer'); var gl_buf = comx.occrender.RenderToBuffer(comx.occore.GetEntry()); console.timeEnd('Iges Buffer'); model.cueline('生成图形数据库并渲染 ...'); return gl_buf; }); } function SetCanvasProp() { ui.canvas.filter = [2025]; //面 if (ui.canvas.view()) { //ui.canvas.view().setColor(0.75, 0.75, 0.75, 0.5); ui.canvas.view().setColor(1.0, 1.0, 0, 1.0); ui.canvas.view().setVisible(true); ui.canvas.view().setBlend(false); } ui.canvas.lamp = true; } //Callback of data preparation stage before UI is fully loaded. //隐藏显示 function HideAndShow(type, name, flag) { comx.ply.hideShow(vtkContext.Interface(), workData, type, name, flag); } //显示3D模型 function OnloadModel(path) { ui.canvas.step = path; } //清除canvas function ClearCanvas() { ui.canvas.db = null; } //设置材料参数界面 function setMaterial(material) { ui.physics_mastk.setmaterial = material; } //设置约束 function setConstraint(prop) { let constraint = { "固定支撑":function(){ ui.cw_boundary_constraint_25.setConstraint0 = prop; }, "梁":function(){ ui.cw_boundary_constraint_25.setConstraint1 = prop; }, "弹簧":function(){ ui.cw_boundary_constraint_25.setConstraint2 = prop; }, "连接":function(){ ui.cw_boundary_constraint_25.setConstraint3 = prop; }, "梁(非均匀)":function(){ }, "集中载荷压力":function(){ ui.cw_boundary_force_24.setConstraint0 = prop; }, "分布载荷压力":function(){ ui.cw_boundary_force_24.setConstraint1 = prop; }, "rb3":function(){ ui.cw_boundary_brep_23.setConstraint = prop; } }; constraint[prop.constraint](); } //显示重命名界面 function RenameTreeNode(Idx) { if(Idx === 2) { unit.form.Rename.Show(); }else if(Idx === 5){ unit.form.RenameMaterial.Show(); } } //点亮面 function LightFace(id) { ui.canvas.view([ui.canvas.generateKey(2025, parseInt(id))]).setColor(1.0, 0.0, 0.0); } function OnInitializeData(reload, preview) { //model.ide_info(model.uuid().length); vtkContext = comx.vtk.CreateContext(); ui.canvas.vtkContextInterface = vtkContext.Interface(); workData = comx.ply.InitWorkArea(); postManage = comx.ply.InitPostManage(); ui.pc_geo.value = model.getPicturePath('蓝灰色.png'); OnCueline('白色->未使用,蓝灰色->正在处理,绿色->未通过,蓝色->通过', 'blue'); InitCanvasIOEngine(); parent.setTimeout(() => { OnInitDocker(); }, 0); ui.canvas.lamp = true; } //Callback after UI is fully loaded and displayed. function OnAnalysisShow(){ //unit.form.form.Show(); } function OnSolveShow(){ } function OnReady(reload, preview) { } function OnCloseForm() { //console.log(11); //model.deleteFile(model.getCurrentDirectory() + 'data/faceID'); //model.deleteFile(model.getCurrentDirectory() + 'data/face'); //model.deleteFile(model.getCurrentDirectory() + 'data/peidian'); //model.deleteFile(model.getCurrentDirectory() + 'data/restraint'); //model.deleteFile(model.getCurrentDirectory() + 'data/force'); //model.deleteFile(model.getCurrentDirectory() + 'data/beam'); } function OnException(err) { //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok); } ////////////////////////////////////////////////////////////////////////// // Callback Functions. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7 function OnSetChangePost(attribute){ comx.ply.setChangeData(vtkContext.Interface(), postManage, attribute); ui.canvas.update(); } function OnPostBar(attribute, isBar){ comx.ply.setPostBars(vtkContext.Interface(), postManage, attribute, isBar); ui.canvas.update(); } function OnGenerateGuass(id){ var res = comx.ply.generateBreps(vtkContext.Interface(), workData, id, model.getCurrentDirectory()); ui.canvas.update(); return res; } function OnGetName(){ return comx.ply.getCurrentActorName(vtkContext.Interface(), workData); } function mousePick(type){ if(type === "points"){ comx.ply.mousePick(vtkContext.Interface(), workData, "points"); } } function OnRenders(path, rate){ comx.ply.renderer(vtkContext.Interface(), postManage, path, rate); ui.canvas.update(); } function OnSpheres(x, y, z, radius, name){ var res = comx.ply.setSpheres(vtkContext.Interface(), workData, parseFloat(x), parseFloat(y), parseFloat(z), parseFloat(radius), name); ui.canvas.update(); return res; } function OnConnects(x, y, z, X, Y, Z, r, g, b, name){ var res = comx.ply.setConnects(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name); ui.canvas.update(); return res; } function OnSpring(x, y, z, X, Y, Z, r, g, b, name){ var res = comx.ply.setSprings(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, name); ui.canvas.update(); return res; } function OnPic(){ comx.ply.pickup(vtkContext.Interface(), workData, "points", 0); ui.canvas.update(); } function OnBeams(seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name){ var res = comx.ply.setBeams(vtkContext.Interface(), workData, seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name); ui.canvas.update(); return res; } function OnConstrains(x, y, z, name){ var res = comx.ply.setConstraints(vtkContext.Interface(), workData, x, y, z, name); ui.canvas.update(); return res; } function OnArrows(x, y, z, xn, yn, zn, name){ return comx.ply.setArrows(vtkContext.Interface(), workData, x, y, z, xn, yn, zn, name); ui.canvas.update(); } function OnSetPoints(x, y, z, radius, name){ comx.ply.setPoints(vtkContext.Interface(), workData, x, y, z, radius, name); ui.canvas.update(); } function OnMat(){ comx.ply.mousePick(vtkContext.Interface(), workData, "beams_point"); } function setExecs(index){ ui.cw_solve_setup.exec = index; } function OnWindowVisible(idx){ ui.stack_menu.visible = idx; ui.stack_switch.visible = idx; } function OnChangePicture(id, value){ if(id === 1){ if(value === 1){ ui.pc_geo.value = model.getPicturePath('蓝灰色.png'); }else if(value === 2){ ui.pc_geo.value = model.getPicturePath('绿色.png'); }else if(value === 3){ ui.pc_geo.value = model.getPicturePath('红色.png'); } }else if(id === 2){ if(value === 1){ ui.pc_mat.value = model.getPicturePath('蓝灰色.png'); }else if(value === 2){ ui.pc_mat.value = model.getPicturePath('绿色.png'); }else if(value === 3){ ui.pc_mat.value = model.getPicturePath('红色.png'); } }else if(id === 3){ if(value === 1){ ui.pc_bou.value = model.getPicturePath('蓝灰色.png'); }else if(value === 2){ ui.pc_bou.value = model.getPicturePath('绿色.png'); }else if(value === 3){ ui.pc_bou.value = model.getPicturePath('红色.png'); } }else if(id === 4){ if(value === 1){ ui.pc_sol.value = model.getPicturePath('蓝灰色.png'); }else if(value === 2){ ui.pc_sol.value = model.getPicturePath('绿色.png'); }else if(value === 3){ ui.pc_sol.value = model.getPicturePath('红色.png'); } }else if(id === 5){ if(value === 1){ ui.pc_res.value = model.getPicturePath('蓝灰色.png'); }else if(value === 2){ ui.pc_res.value = model.getPicturePath('绿色.png'); }else if(value === 3){ ui.pc_res.value = model.getPicturePath('红色.png'); } } } function OnCueline(msg, color){ let real_color = 'black'; if(color){real_color = color;} if(!msg) { ui.cueline.value = ""; return; } ui.cueline.value = `提示信息:${msg}`;// + msg; } function OnPoints(){ //OnSend('pointsCoord'); comx.ply.mousePick(vtkContext.Interface(), workData, "points"); } function OnMaterial(){ ui.stack_menu.index = 19; console.log(22); } function OnFalseOpacity(){ var id = parent.setTimeout(() => { OnSend('0'); }, 100); OnSend('Opacity 0'); } function OnOpacity(){ var id = parent.setTimeout(() => { OnSend('0'); }, 100); OnSend('Opacity 1'); } function OnFaceCanvas(){ ui.canvas.filter = [2025]; //面 if (ui.canvas.view()) { ui.canvas.view().setColor(0.5, 0.5, 0.5, 0.2); ui.canvas.view().setVisible(true); ui.canvas.view().setBlend(false); } } function OnLineCanvas(){ ui.canvas.filter = [2025]; //面 if (ui.canvas.view()) { //ui.canvas.view().setColor(1.0, 1.0, 0.0, 0.0); ui.canvas.view().setVisible(true); ui.canvas.view().setBlend(true); } } function OnHightFace(idx){ ui.canvas.view([ui.canvas.generateKey(2025, parseInt(idx))]).setColor(1.0, 0.0, 0.0); } function OnSetProp(index){ ui.prop.visible = true; ui.prop.value = parseFloat(index); if(parseFloat(index) === 100){ ui.prop.visible = false; } } function OnGetBeam(idx){ myArray.push(idx); ui.cw_boundary_spring.beam = myArray; } function OnDeleteBeam(idx){ myArray.splice(idx, 1); ui.cw_boundary_spring.beam = myArray; } function OnModuleChange(idx){ ui.stack_switch.index = parseInt(idx); } function OnTransform(idx) { //ui.pb_pan.valid = ui.pb_rotate.valid = ui.pb_zoom.valid = ui.pb_zoom_window.valid = false; if (idx === 1) { //ui.pb_pan.valid = true; ui.canvas.sensor = GL.Sensor.Pan; } if (idx === 2) { //ui.canvas.sensor = GL.Sensor.Rotate; ui.pb_rotate.valid = true; } if (idx === 3) { //ui.canvas.sensor = GL.Sensor.Scale; ui.pb_zoom.valid = true; } if (idx === 4) { //ui.canvas.sensor = GL.Sensor.RectScale; ui.pb_zoom_window.valid = true; } } function On3DPosition(idx) { //ui.pb_yox.valid = ui.pb_xoy.valid = ui.pb_zoy.valid = ui.pb_yoz.valid = ui.pb_zox.valid = ui.pb_xoz.valid = false; if (idx === 1) { //ui.pb_yox.valid = true; ui.canvas.sensor = GL.Sensor.YOX; } if (idx === 2) { //ui.pb_xoy.valid = true; ui.canvas.sensor = GL.Sensor.XOY; } if (idx === 3) { //ui.pb_zoy.valid = true; ui.canvas.sensor = GL.Sensor.ZOY; } if (idx === 4) { //ui.pb_yoz.valid = true; ui.canvas.sensor = GL.Sensor.YOZ; } if (idx === 5) { //ui.pb_xoz.valid = true; ui.canvas.sensor = GL.Sensor.XOZ; } if (idx === 6) { //ui.pb_zox.valid = true; ui.canvas.sensor = GL.Sensor.ZOX; } } //用树id取出真实id function findRIdById(jsonData, targetId) { let result = null; // 存储结果 function traverse(node) { // 如果当前节点的 id 匹配目标值,记录其 r_id if (node.id === targetId) { result = node.r_id; return; // 提前结束递归 } // 如果有子节点,则递归遍历子节点 if (node.children && Array.isArray(node.children)) { for (let child of node.children) { traverse(child); if (result !== null) {return;} // 如果已找到,停止遍历 } } } traverse(jsonData); // 开始遍历 return result; // 返回结果或 null } //将真实id转换为对应树id function findNodeIdByRId(jsonData, targetRId) { let result = null; // 用于存储找到的节点的 id function traverse(node) { // 如果当前节点的 r_id 与目标值匹配,记录其 id if (node.r_id === targetRId) { result = node.id; return; // 提前结束当前递归 } // 如果有子节点,则递归遍历子节点 if (node.children && Array.isArray(node.children)) { for (let child of node.children) { traverse(child); if (result !== null) {return;} // 如果已经找到,停止遍历 } } } traverse(jsonData); // 开始遍历 return result; // 返回找到的 id 或 null } function OnPickUp() { if (!ui.canvas.hits) { return; } //放brep路径 var rec = ui.canvas.hits[0]; var key = rec.keyRecord; var keyObj = ui.canvas.parseKey(key); let id = findNodeIdByRId(model.acax_app.model.project.GetModel().pro_model, keyObj.sid); var path = model.getCurrentDirectory() + "data/brep/face" + id + ".brep"; comx.occio.GetFaceBrep(comx.occore.GetEntryEx(), keyObj.sid, path); var facName = "type:F 0 " + id + " " + comx.occio.GetFacePoint(comx.occore.GetEntryEx(), keyObj.sid); OnSetFaceName(facName); let brep = { "brep":path.replace(/\\/g, "/") } ; unit.form.tree.SetBrepFile(brep); } function GetBrepPath() { return brep_path; } var faceName; function OnSetFaceName(input){ faceName = input; } function OnGetFaceName(){ return faceName; } function pick(idx) { console.log(idx); if (idx === 1) { ui.canvas.picker = { mode: GL.Picker.Mode.Single, autoHighlight: true, behavior: GL.Picker.Behavior.Point }; } if (idx === 2) { ui.canvas.picker = { mode: GL.Picker.Mode.Multi, autoHighlight: true, behavior: GL.Picker.Behavior.None }; } } function OnChangeWindows(Idx){ if(Idx === 1){ ui.pb_window.index = 0; } if(Idx === 2){ ui.pb_window.index = 1; } } function OnOpenSTL(){ var fname = ui.OpenFileDialog("Import File", unit.dir + 'data/', "Stl Files(*.stl *.STL)"); ui.cw_boundary_STL.path = fname; } function OnSend(Idx) { //console.log(33); if (g_io) { g_io.send(Idx); } } function OnOpenFile(fname) { //console.log(1000); if (fname) { //console.log(fname); model.execs(model.getCurrentDirectory() + "/src/generateBrep/generateBrep.exe " + fname + " " + model.getCurrentDirectory(), cb => { console.log(cb); }); var is_step = (fname.indexOf('.STEP') !== -1) || (fname.indexOf('.step') !== -1) || (fname.indexOf('.STP') !== -1) || (fname.indexOf('.stp') !== -1); var is_nas = (fname.indexOf('.nas') !== -1) || (fname.indexOf('.NAS') !== -1); model.wait(); ui.canvas.db = null; parent.setTimeout(() => { if (is_step) { console.time('Global Step Load'); ui.canvas.step = fname; console.timeEnd('Global Step Load'); } else if (is_nas) { console.time('Global Nastran Load'); ui.canvas.nastran = fname; console.timeEnd('Global Nastran Load'); SetCanvasProp(); } else { console.time('Global Iges Load'); ui.canvas.iges = fname; console.timeEnd('Global Iges Load'); } SetCanvasProp(); ui.canvas.lamp = true; model.stop(); }, 100); } ui.cw_geometry_check.path = fname; } function OnChangeValue(idx){ menu(idx); } function menu(Idx) { ui.stack_menu.index = parseInt(Idx); } function changeConstrain(index1, index2){ if(index1 === 1){ ui.cw_boundary_constraint_25.change1 = index2; } if(index1 === 2){ ui.cw_boundary_constraint_25.change2 = index2; } if(index1 === 3){ ui.cw_boundary_force_24.index = index2; } } //The message corresponding callback executed by the main form // when calling pui.fireEvent(type,para) in the Docker subform. function OnChildDockerMessage(type, para){ } ////////////////////////////////////////////////////////////////////////// // Utils Functions. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe function onDragFile(filepath) { } /*Usage of BLOCK_EVENT BLOCK_EVENT(()=>{ ui.[name].[var] = ...; }); */ function BLOCK_EVENT(cb) { ui.block_event = true; cb(); ui.block_event = false; }