//////////////////////////////////////////////////////////////////////////// // 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; 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); //dock_widget1 = appendDockPane(unit.form.toolAF_bar, "", 4, 1|2|4); //dock_widget3 = appendDockPane(unit.form.toolAF, "", 4, 1|2|4); //dock_widget1 = appendDockPane(unit.form.toolAF_bar, "", 4, 1|2|4); //dock_widget1 = appendDockPane(unit.form.message, "消息反馈区", 8, 8|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) { /* sub_form.Show(); dock_widget = ui.docker.wrapWindow(sub_form.getWindowID(), "参数面板"); */ 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.time('Step Import'1 model.cueline('解析并加载STEP文件 ...'); model.updateGeometry(ui.geometry); ui.canvas.db = null; //comx.occore.Clear(); comx.occio.ImportStep(comx.occore.GetEntry(), fname_step); console.timeEnd('Step Import'); model.cueline('创建图形缓冲区 ...'); console.time('Step Buffer'); var gl_buf = comx.occrender.RenderToBuffer(comx.occore.GetEntry()); console.timeEnd('Step Buffer'); model.cueline('生成图形数据库并渲染 ...'); return gl_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()); 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. //显示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; } }; constraint[prop.constraint](); } //显示重命名界面 function RenameTreeNode(Idx) { if(Idx === 2) { unit.form.Rename.Show(); }else if(Idx === 5){ unit.form.RenameMaterial.Show(); } } function OnInitializeData(reload, preview) { //model.ide_info(model.uuid().length); vtkContext = comx.vtk.CreateContext(); ui.canvas.vtkContextInterface = vtkContext.Interface(); workData = comx.ply.InitWorkArea(); ui.pc_geo.value = model.getPicturePath('蓝灰色.png'); OnCueline('白色->未使用,蓝灰色->正在处理,绿色->未通过,蓝色->通过', 'blue'); InitCanvasIOEngine(); if (g_io) { ui.cons.appendWindowByID(g_wid); ui.Activate(); return; } g_io = model.startSubProcess(pid => { g_wid = ui.GetWinID(pid); ui.cons.appendWindowByID(g_wid); ui.Activate(); //ui.SetFocus(ui.pmsg.handle); }, msg => { //console.log(msg); unit.form.tree.OnMessage(msg); //console.log(msg); if(msg === 'step_file_loaded_flag') { ui.cueline.value = ''; unit.form.result_attribute.OnReset(); } //ui.cw_boundary_stress_more_Peidian.message = msg; ui.cw_result_Play_collision.frame = msg; /* if(msg === "*0"){ OnSetProp(0); }else if(msg === "*10"){ OnSetProp(10); }else if(msg === "*50"){ OnSetProp(50); }else if(msg === "*80"){ OnSetProp(80); }else if(msg === "*100"){ OnSetProp(100); //model.stop(); }*/ //ui.cw_boundary_beam.message = msg; }, attribute => { //console.log(msg); //myArray.push(attribute); ui.cw_result_Play_collision.Array = attribute; }, ids => { //ui.cw_boundary_beam.ID = ids; //ui.cw_boundary_spring.ID = ids; console.log('ll' + ids); ui.physics_mastk.pb_ID =ids; }, spring => { //ui.cw_boundary_spring.message = spring; const str = spring.split(' '); if(model.getStartEnd() === 0){ ui.cw_boundary_constraint_25.pb_x = str[0]; ui.cw_boundary_constraint_25.pb_y = str[1]; ui.cw_boundary_constraint_25.pb_z = str[2]; var strs = ""; for(var i = 3; i < str.length; i++){ strs += str[i] + ' '; } ui.cw_boundary_constraint_25.start_mes = strs; ui.cw_geometry_mark_22.pb_x = str[0]; ui.cw_geometry_mark_22.pb_y = str[1]; ui.cw_geometry_mark_22.pb_z = str[2]; } if(model.getStartEnd() === 1){ ui.cw_boundary_constraint_25.pb_X = str[0]; ui.cw_boundary_constraint_25.pb_Y = str[1]; ui.cw_boundary_constraint_25.pb_Z = str[2]; ui.cw_boundary_constraint_25.end_mes = str[3]; var strs = ""; for(var i = 3; i < str.length; i++){ strs += str[i] + ' '; } ui.cw_boundary_constraint_25.end_mes = strs; ui.cw_geometry_mark_22.pb_x = str[0]; ui.cw_geometry_mark_22.pb_y = str[1]; ui.cw_geometry_mark_22.pb_z = str[2]; } if(model.getBeam()){ var mes = '(' + str[0] + ',' + str[1] + ',' + str[2] + ')'; model.setStr(mes); ui.cw_boundary_constraint_25.listbox = model.getStr(); } /* if(model.getJudge() === 0) { //var str = val.split(' '); if(model.getStartEnd() === 0){ ui.cw_boundary_spring.pb_x = str[0]; ui.cw_boundary_spring.pb_y = str[1]; ui.cw_boundary_spring.pb_z = str[2]; console.log(str[0] + 's ' + str[1] + 's ' + str[2]); } if(model.getStartEnd() === 1){ ui.cw_boundary_spring.pb_X = str[0]; ui.cw_boundary_spring.pb_Y = str[1]; ui.cw_boundary_spring.pb_Z = str[2]; console.log(str[0] + 'd ' + str[1] + 'd ' + str[2]); } } if(model.getJudge() === 1) { //var str = val.split(' '); if(model.getStartEnd() === 0){ ui.cw_boundary_spring.pb_x = str[0]; ui.cw_boundary_spring.pb_y = str[1]; ui.cw_boundary_spring.pb_z = str[2]; ui.cw_boundary_spring.pb_startID = str[3]; console.log(str[0] + 'a ' + str[1] + ' a' + str[2]); } if(model.getStartEnd() === 1){ ui.cw_boundary_spring.pb_X = str[0]; ui.cw_boundary_spring.pb_Y = str[1]; ui.cw_boundary_spring.pb_Z = str[2]; ui.cw_boundary_spring.pb_endID = str[3]; console.log(str[0] + ' s' + str[1] + ' s' + str[2]); } }*/ }, selectFace => { const str = selectFace.split(' '); ui.cw_boundary_brep_23.list = str; }, Eigenvalue =>{ res.push(Eigenvalue); ui.cw_result_ModelAnsys_24.list = res; }, model.getCurrentDirectory() + "src_post/QFrameSelect.exe", model.getCurrentDirectory() + "src_post", 3000); parent.setTimeout(() => { OnInitDocker(); }, 0); } //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 OnPickup(){ } function OnMat(){ OnSend('MatIds'); } 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'); } 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; } } function OnPickUp() { if (!ui.canvas.hits) { return; } var rec = ui.canvas.hits[0]; //console.log(ui.canvas.hits[0]); var key = rec.keyRecord; var keyObj = ui.canvas.parseKey(key); console.log(keyObj.sid); //ui.cw_boundary_face.ID = keyObj.sid; //ui.cw_boundary_fix.ID = keyObj.sid; var hashCodes = comx.occio.GetFaceHashCodes(comx.occore.GetEntryEx()); console.log(hashCodes); //ui.cw_boundary_load.ID = JSON.parse(hashCodes)[parseInt(keyObj.sid)]; ui.cw_boundary_load.ID = keyObj.sid; if(model.getCon() === 0){ ui.canvas.view().setColor(0.0, 0.0, 1.0, 0.8); }else if(model.getCon() === 1){ ui.canvas.view().setColor(1.0, 0.0, 0.0, 0.8); } //ui.cw_geometry_nurbs.sci = comx.occore.GetBrepInfo(keyObj.sid); //ui.cw_geometry_nurbs.self = FilterNurbsInfo(); } 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) { if (fname) { 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){ /*console.log(ui.geometry.index); if(ui.geo.index === 0){ menu(0); } if(ui.geo.index === 1){ menu(2); } if(ui.geo.index === 2){ menu(5); } if(ui.geo.index === 3){ menu(10); } if(ui.geo.index === 4){ menu(12); } */ 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; }