123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718 |
- ////////////////////////////////////////////////////////////////////////////
- // 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 = `<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");
- }
- 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;
- }
|