1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021 |
- ////////////////////////////////////////////////////////////////////////////
- // 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 isEnablePost(isUse){
- ui.pb_open.enable = isUse;
- ui.pb_close.enable = isUse;
- ui.pb_colorMap.enable = isUse;
- }
- function OnTest1(){
- changeColor("rb3", "121rb3 0", 1, 0, 0);
- }
- function changeColor(type, name, r, g, b) {
- comx.ply.changeColor(vtkContext.Interface(), workData, type, name, r, g, b);
- }
- function HideAndShow(type, name, flag) {
- comx.ply.hideShow(vtkContext.Interface(), workData, type, name, flag);
- }
- function upDateCanvas() {
- ui.canvas.update();
- }
- //显示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, rgb) {
- let r_id = findRIdById(model.acax_app.model.project.GetModel().pro_model, parseInt(id));
- ui.canvas.view([ui.canvas.generateKey(2025, parseInt(r_id))]).setColor(parseFloat(rgb.r)/255, parseFloat(rgb.g)/255, parseFloat(rgb.b)/255);
- }
- //加载涂色
- function SetColor(color) {
- let color_arr = Object.keys(color);
- for (let i = 0; i < color_arr.length; ++i) {
- try {
- //console.log(i + " ");
-
- // 查找 r_id
- let r_id = findRIdById(
- model.acax_app.model.project.GetModel().pro_model,
- parseInt(color_arr[i])
- );
- if (!r_id) {
- throw new Error(`r_id not found for id: ${color_arr[i]}`);
- }
- // 转换颜色为 RGB
- let rgb = hexToRgb(color[color_arr[i]]);
- if (!rgb || rgb.r === undefined || rgb.g === undefined || rgb.b === undefined) {
- throw new Error(`Invalid color value: ${color[color_arr[i]]}`);
- }
- // 设置颜色
- ui.canvas
- .view([ui.canvas.generateKey(2025, parseInt(r_id))])
- .setColor(
- parseFloat(rgb.r) / 255,
- parseFloat(rgb.g) / 255,
- parseFloat(rgb.b) / 255
- );
- } catch (error) {
- console.error(
- `Failed to set color for id ${color_arr[i]}: `,
- error.message
- );
- }
- }
- }
- //设置面高亮并选中
- function PickFaceLight(id) {
- let idx = findRIdById(model.acax_app.model.project.GetModel().pro_model, id);
- //console.log(idx);
- if(idx){
- ui.canvas.view([ui.canvas.generateKey(2025, parseInt(idx))]).setColor(235/255, 152/255, 20/255);
- var path = model.getCurrentDirectory() + "data/brep/face" + id + ".brep";
-
- comx.occio.GetFaceBrep(comx.occore.GetEntryEx(), idx, path);
- var facName = "type:F 0 " + id + " " + comx.occio.GetFacePoint(comx.occore.GetEntryEx(), idx);
- OnSetFaceName(facName);
- let brep = {
- "brep":path.replace(/\\/g, "/")
- } ;
- unit.form.tree.SetBrepFile(brep);
- }
-
- }
- function hexToRgb(hex) {
- // 去掉前缀 #(如果有)
- hex = hex.replace(/^#/, '');
- // 如果是简写形式(#RGB),将其转换为完整形式(#RRGGBB)
- if (hex.length === 3) {
- hex = hex.split('').map(char => char + char).join('');
- }
- // 解析 RGB 颜色值
- const r = parseInt(hex.slice(0, 2), 16);
- const g = parseInt(hex.slice(2, 4), 16);
- const b = parseInt(hex.slice(4, 6), 16);
- return { r, g, b };
- }
- function 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;
- OnPoints();
- }
- //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 OnColorMap(){
- unit.form.colorMap.Show();
- }
-
- function OnLight(isLight){
- if(isLight){
- ui.canvas.lamp = true;
- ui.canvas.update();
- }else{
- ui.canvas.lamp = false;
- ui.canvas.update();
- }
- }
- function OnCanvasContentMenu(){
-
- if(ui.canvas.content_menu === 1){
- OnTransform(1);
- }
-
- if(ui.canvas.content_menu === 2){
- OnTransform(2);
- }
-
- if(ui.canvas.content_menu === 3){
- On3DPosition(1);
- }
-
- if(ui.canvas.content_menu === 4){
- On3DPosition(2);
- }
-
- if(ui.canvas.content_menu === 5){
- On3DPosition(3);
- }
-
- if(ui.canvas.content_menu === 6){
- On3DPosition(4);
- }
-
- if(ui.canvas.content_menu === 7){
- On3DPosition(5);
- }
-
- if(ui.canvas.content_menu === 8){
- On3DPosition(6);
- }
- }
- function OnCanvasRightClick(){
- ui.canvas.content_menu = [
- {
- name: '旋转',
- icon: 'bar10',
- id: 1
- },
- {
- name: '平移',
- icon: 'bar11',
- id: 2
- },
- {
- name: '-'
- },
- {
- name: 'YOX',
- icon: 'bar19',
- id: 3
- },
- {
- name: 'XOY',
- icon: 'bar20',
- id: 4
- },
- {
- name: 'ZOX',
- icon: 'bar21',
- id: 5
- },
- {
- name: 'XOZ',
- icon: 'bar22',
- id: 6
- },
- {
- name: 'ZOY',
- icon: 'bar23',
- id: 7
- },
- {
- name: 'YOZ',
- icon: 'bar24',
- id: 8
- }
-
- ];
- }
- function OnClear(){
- ui.canvas.db = null;
- }
- /*
- function OnHide(){
- comx.ply.hideShow(vtkContext.Interface(), workData, "mark", "mark", true);
- }*/
- function OnLoad(){
- return comx.ply.loadFiles(vtkContext.Interface(), postManage, model.getCurrentDirectory(), model.getCurrentDirectory() + '/data/modelAnsys/unitfcm5-0-1e-10-451');
- }
- function OnLoad1(){
- return comx.ply.loadFiles(vtkContext.Interface(), postManage, model.getCurrentDirectory(), model.getCurrentDirectory() + '/data/modelAnsys/danbianguding');
- }
- function OnLoad2(){
- return comx.ply.loadFiles(vtkContext.Interface(), postManage, model.getCurrentDirectory(), model.getCurrentDirectory() + '/data/modelAnsys/ziyouzhendong');
- }
- function OnRendererMoTi(idx, size){
- var res = comx.ply.rendererMoTi(vtkContext.Interface(), postManage, model.getCurrentDirectory(), idx, size);
- ui.canvas.update();
- return res;
- }
- function OnForceChange(idx){
- ui.cw_boundary_force_24.idx = idx;
- }
- function OnConChange(idx){
- ui.cw_boundary_constraint_25.idx = idx;
- }
- function OnCut(x, y, z, xn, yn, zn){
- comx.ply.cutters(vtkContext.Interface(), postManage, x, y, z, xn, yn, zn);
- }
- function OnRGBMap4(r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4, r5, g5, b5){
- comx.ply.colorRGBS4(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2, r3, g3, b3, r4, g4, b4, r5, g5, b5);
- }
- function OnRGBMap3(r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4){
- comx.ply.colorRGBS3(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2, r3, g3, b3, r4, g4, b4);
- }
- function OnRGBMap2(r1, g1, b1, r2, g2, b2, r3, g3, b3){
- comx.ply.colorRGBS2(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2, r3, g3, b3);
- }
- function OnRGBMap1(r1, g1, b1, r2, g2, b2){
- comx.ply.colorRGBS1(vtkContext.Interface(), postManage, r1, b1, g1, r2, b2, g2);
- }
- function OnMotifyMarks(x, y, z, r, g, b, size, mark, name){
- comx.ply.modifyMarks(vtkContext.Interface(), workData, x, y, z, r, g, b, size, mark, name);
- }
- function OnSetMarks(x, y, z, r, g, b, size, mark, name){
-
- comx.ply.setMarks(vtkContext.Interface(), workData, x, y, z, r, g, b, size, mark, name);
- }
- 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 OnModifySpheres(x, y, z, radius, name){
- var res = comx.ply.modifySpheres(vtkContext.Interface(), workData, parseFloat(x), parseFloat(y), parseFloat(z), parseFloat(radius), name);
- ui.canvas.update();
- return res;
- }
- 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 OnModifyConnects(x, y, z, X, Y, Z, r, g, b, name){
- var res = comx.ply.modifyConnects(vtkContext.Interface(), workData, x, y, z, X, Y, Z, r, g, b, 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 OnModifySpring(x, y, z, X, Y, Z, r, g, b, name){
- var res = comx.ply.modifySprings(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 OnModifyBeams(seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name){
- var res = comx.ply.modifyBeams(vtkContext.Interface(), workData, seg, x1, y1, z1, x2, y2, z2, r, g, b, radius, name);
- ui.canvas.update();
- return res;
- }
- 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 OnModifyConstrains(x, y, z, name){
- var res = comx.ply.modifyConstraints(vtkContext.Interface(), workData, x, y, z, 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 OnModifyArrows(x, y, z, xn, yn, zn, name){
- var res = comx.ply.modifyArrows(vtkContext.Interface(), workData, x, y, z, xn, yn, zn, name);
- ui.canvas.update();
- return res;
- }
- function OnArrows(x, y, z, xn, yn, zn, name){
- var res = comx.ply.setArrows(vtkContext.Interface(), workData, x, y, z, xn, yn, zn, name);
- ui.canvas.update();
- return res;
- }
- function OnModifyPoints(x, y, z, radius, name){
- comx.ply.modifyPoints(vtkContext.Interface(), workData, x, y, z, radius, 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");
- ui.pb_Points.valid = false;
- ui.pb_beam.valid = true;
- }
- 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 = `<span style=\"color:black\"><u><b>提示信息</b></u>:</span><span style="color:${real_color}">${msg}</span>`;// + msg;
- }
- function OnPoints(){
- //OnSend('pointsCoord');
- comx.ply.mousePick(vtkContext.Interface(), workData, "points");
- ui.pb_Points.valid = true;
- ui.pb_beam.valid = false;
- }
- function OnMaterial(){
- ui.stack_menu.index = 19;
- console.log(22);
- }
- function OnFalseOpacity(){
- comx.ply.openCloseOpacity(vtkContext.Interface(), postManage, false);
- }
- function OnOpacity(){
- comx.ply.openCloseOpacity(vtkContext.Interface(), postManage, true);
- }
- 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.canvas.sensor = GL.Sensor.Rotate;
- //ui.pb_pan.valid = true;
- //ui.canvas.sensor = GL.Sensor.Pan;
- }
- if (idx === 2) {
- ui.canvas.sensor = GL.Sensor.Pan;
- //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);
- console.log("keyObj", keyObj);
- let id = findNodeIdByRId(model.acax_app.model.project.GetModel().pro_model, keyObj.sid);
- console.log("id", id);
- 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;
- }
- var isPick = false;
- var color_face = "";
- function GetFlag() {
- return !isPick;
- }
- function pick(idx) {
- isPick = !isPick;
- let cur_proj = model.acax_app.view.GetCurrentProjectIndex();
- color_face = unit.form.tree.GetColorFace();
- unit.form.tree.Light3DFace(cur_proj, 11);
- ui.pb_pick.valid = isPick;
- if(isPick){
- ui.canvas.picker = {
- mode: GL.Picker.Mode.Single,
- autoHighlight: true,
- behavior: GL.Picker.Behavior.Point
- };
- }else{
- 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 OnChangeIndex(idx){
- ui.geo.index = 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;
- }
|