1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030 |
- ////////////////////////////////////////////////////////////////////////////
- // 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 ModifyConstraintName(new_name) {
- let cur_name = model.acax_app.model.constrain.Current();
- let flag = model.acax_app.control.constrain.Rename(cur_name, new_name);
- let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let cur_id;
- if(flag === true) {
- unit.form.mainfrm.OnCueline('修改成功', 'green');
- }else{
- unit.form.mainfrm.OnCueline('修改失败', 'red');
- }
- 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;
- }
- if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
- cur_id = info.id;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : 0
- };
-
- },
- 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);
- });
- }
- ui.tree_Model.position = cur_id;
- }
- //修改材料属性的名字
- function ModifyMaterialName(new_name) {
- let cur_name = model.acax_app.model.materialProp.Current();
- let flag = model.acax_app.control.materialProp.Rename(cur_name, new_name);
- let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let cur_id;
- if(flag === true) {
- unit.form.mainfrm.OnCueline('修改成功', 'green');
- }else{
- unit.form.mainfrm.OnCueline('修改失败', 'red');
- }
- 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;
- }
- if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
- cur_id = info.id;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : 0
- };
-
- },
- 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);
- });
- }
- ui.tree_Model.position = cur_id;
- }
- //修改的工程名
- function ModifyProName(new_name) {
- let cur_name = model.acax_app.path.Name(model.acax_app.view.GetCurrentProjectIndex());
- model.acax_app.model.project.Rename(cur_name, new_name);
- let cur_index = model.acax_app.view.GetCurrentWorkAreaIndex();
- let cur_id;
- 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;
- }
- if((new_name === info.name) && (model.acax_app.path.Parent(info.index, 0) === cur_index)) {
- cur_id = info.id;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : 0
- };
-
- },
- 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);
- });
- }
- ui.tree_Model.position = cur_id;
- }
- //处理字符串截掉后五位
- function removeLastFiveCharacters(str) {
- str = String(str);
- if (str.length <= 5) {
- return ''; // 如果字符串长度小于等于 5,则返回空字符串
- }
- return str.substring(0, str.length - 5); // 提取从 0 到倒数第 5 位的子字符串
- }
- //点击弹出菜单
- function OnContentClick(){
- //获取一级子节点
- let str = removeLastFiveCharacters(ui.tree_Model.content_menu);
- let model_id = g_cur_id2index_cache[str];
- //let cur_name = model.acax_app.path.Name(model_id);
- switch (model.acax_app.path.Type(model_id)){
- case 2:
- unit.form.Rename.Show();
- break;
- case 3:
- break;
- case 4:
- unit.form.RenameConstraint.Show();
- break;
- case 5:
- unit.form.RenameMaterial.Show();
- break;
- default:
- break;
- }
- }
- //右键单击树效果
- function OnRightClick(){
- //console.log(ui.tree_Model.position);
- let model_id = g_cur_id2index_cache[ui.tree_Model.position];
- switch (model.acax_app.path.Type(model_id)){
- case 2:
- ui.tree_Model.content_menu =[{
- "name":"重命名",
- "icon":"",
- "id":ui.tree_Model.position + "13579"
- }];
- break;
- case 3:
- break;
- case 4:
- ui.tree_Model.content_menu =[{
- "name":"重命名",
- "icon":"",
- "id":ui.tree_Model.position + "13579"
- }];
- break;
- case 5:
- ui.tree_Model.content_menu =[{
- "name":"重命名",
- "icon":"",
- "id":ui.tree_Model.position + "13579"
- }];
- break;
- default:
- break;
- }
-
- }
- //点击树
- function OnClickTree(){
- //获取模型树的对应节点
- console.log(ui.tree_Model.position);
- let model_id = g_cur_id2index_cache[ui.tree_Model.position];
- let cur_workarea = model.acax_app.view.GetCurrentWorkAreaIndex();
- let cur_proj = model.acax_app.view.GetCurrentProjectIndex();
- let cur_workcondition = model.acax_app.view.GetCurrentWorkConditionIndex();
- 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);
- //切换到当前工作区
- ui.tree_Model.position = g_cur_index2id_cache[model_id];
- });
- }
- break;
- //选中材料库
- case 1:
-
- break;
- //切换工程
- case 2:
- //不是当前工程,切换工程
- if(model_id !== cur_proj){
- model.acax_app.view.RenderNode(model_id, info => {
- ChangePro(model.acax_app.path.Name(model_id));
- //切换到当前工程
- ui.tree_Model.position = g_cur_index2id_cache[model_id];
- });
-
- }
- break;
- //切换工况
- case 3:
- //不是当前工况,切换工况
- if(model_id !== cur_workcondition){
- model.acax_app.view.RenderNode(model_id, info => {
- console.log(model.acax_app.path.Name(model_id)) ;
- ChangeWorkCondition(model.acax_app.path.Name(model_id));
- //切换到当前工况
- ui.tree_Model.position = g_cur_index2id_cache[model_id];
- });
-
- }
- break;
- //选中约束
- case 4:
- model.acax_app.view.RenderNode(model_id, info => {
- //切换到当前约束
- model.acax_app.model.constrain.SwitchTo(model.acax_app.path.Name(model_id));
- //将约束属性设置到对应面板
- ChangeConstraint(Object.values(info.prop)[0], info.prop);
- //切换点击约束
- ui.tree_Model.position = g_cur_index2id_cache[model_id];
- });
- break;
- //选中材料属性
- case 5:
- model.acax_app.view.RenderNode(model_id, info => {
- //切换当前材料
- model.acax_app.model.materialProp.SwitchTo(model.acax_app.path.Name(model_id));
- unit.form.mainfrm.menu(3);
- unit.form.mainfrm.OnChangePicture(2, 1);
- unit.form.mainfrm.OnCueline('结构静力学材料设置', 'blue');
- //将材料属性设置到面板
- unit.form.mainfrm.setMaterial(info.prop);
- //切换到点击材料
- ui.tree_Model.position = g_cur_index2id_cache[model_id];
- });
- break;
- default:
- break;
- }
-
- }
- //切换约束面板
- function ChangeConstraint(constraint_name, prop) {
- let constraint = {
- "固定支撑":function(){
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 0);
- unit.form.mainfrm.setConstraint(prop);
- },
- "梁":function(){
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 1);
- unit.form.mainfrm.changeConstrain(2, 0);
- unit.form.mainfrm.setConstraint(prop);
- },
- "弹簧":function(){
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 1);
- unit.form.mainfrm.changeConstrain(2, 1);
- unit.form.mainfrm.setConstraint(prop);
- },
- "连接":function(){
- unit.form.mainfrm.menu(18);
- unit.form.mainfrm.changeConstrain(1, 1);
- unit.form.mainfrm.changeConstrain(2, 2);
- unit.form.mainfrm.setConstraint(prop);
- },
- "梁(非均匀)":function(){
- },
- "集中载荷压力":function(){
- unit.form.mainfrm.menu(17);
- unit.form.mainfrm.changeConstrain(3, 0);
- unit.form.mainfrm.setConstraint(prop);
- },
- "分布载荷压力":function(){
- unit.form.mainfrm.menu(17);
- unit.form.mainfrm.changeConstrain(3, 1);
- unit.form.mainfrm.setConstraint(prop);
- }
- };
-
- constraint[constraint_name]();
- }
- //测试函数
- function OnTest(){
-
- // console.log(model.acax_app.path.Name(g_cur_id2index_cache["131"]));
- //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;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : 0
- };
-
- },
- 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;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : 0
- };
-
- },
- 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 ChangeWorkCondition(wor_name) {
- model.acax_app.control.workCondition.SwitchTo(wor_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 : 0
- };
-
- },
- 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);
- let cur_id;
- 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;
- }
- if("workArea" === info.name) {
- cur_id = info.id;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : 0
- };
- },
- 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);
- });
- }
- ui.tree_Model.position = cur_id;
- }
- //创建工程
- function CreateProject(name) {
- model.acax_app.control.project.Create(name);
- let cur_name = model.acax_app.model.project.Current();
- let cur_index = model.acax_app.view.GetCurrentWorkAreaIndex();
- let cur_id;
- 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;
- }
- if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 0) === cur_index)) {
- cur_id = info.id;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : 0
- };
-
- },
- 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);
- });
- }
- ui.tree_Model.position = cur_id;
- }
- //导入模型
- 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));
- }
- }
- //给面节点改名字并添加check_state属性
- function updateJsonNodes(jsonData) {
- let count = 1; // 用于计数生成 Face1, Face2...
- function traverse(node) {
- // 为每个节点添加 check_state: 2 属性
- node.check_state = 2;
- node.icon = '';
- // 如果存在 children 属性,则递归处理
- if (node.children && Array.isArray(node.children)) {
- for (let child of node.children) {
- traverse(child); // 递归遍历子节点
- }
- } else if (node.name && node.name.startsWith("Face_")) {
- // 修改 name 值为 Face1, Face2...
- node.name = `Face${count}`;
- count++;
- }
- }
- traverse(jsonData);
- return jsonData;
- }
- //查找模型的第一个节点值获取id
- function getFirstId(obj) {
- // 检查是否有 children 并提取第一个节点的 id
- if (obj.children && obj.children.length > 0) {
- return obj.children[0].id;
- }
- return null; // 如果没有子节点,返回 null
- }
- //导入模型树节点
- function OnTree(Idx){
- updateJsonNodes(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 : 0
- };
-
- },
- 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;
- }
- );
- ui.tree_Model.position = getFirstId(Idx);
- }
- //创建工况
- function CreateWorkCondition(name){
- let condition_index = model.acax_app.control.workCondition.Create(name);
- let cur_name = model.acax_app.model.workCondition.Current();
- let cur_index = model.acax_app.view.GetCurrentProjectIndex();
- let cur_id;
- console.log(model.acax_app.path.Parent(cur_index, 2) === model.acax_app.view.GetCurrentProjectIndex());
- 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;
- }
- if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 2) === cur_index)) {
- cur_id = info.id;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : 0
- };
-
- },
- tree => {
- //获取当前工程的名字
- let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
- let pro_name = model.acax_app.path.Name(pro_Index);
- //模型存在在加载
- if(model.acax_app.model.project.GetModel().pro_model) {
- let cur_model = model.acax_app.model.project.GetModel().pro_model;
- findAndAppendByName(tree, pro_name, cur_model);
- }
-
- //赋值给dcip的树结构
- ui.tree_Model.tree = tree;
- }
- );
- ui.tree_Model.position = cur_id;
- }
- //创建材料属性
- function CreateMaterial(mat) {
- model.acax_app.control.materialProp.Create(mat);
- let cur_name = model.acax_app.model.materialProp.Current();
- let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let cur_id;
- 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;
- }
- if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
- cur_id = info.id;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : 0
- };
-
- },
- tree => {
- //获取当前工程的名字
- let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
- let pro_name = model.acax_app.path.Name(pro_Index);
- if(model.acax_app.model.project.GetModel().pro_model) {
- let cur_model = model.acax_app.model.project.GetModel().pro_model;
- findAndAppendByName(tree, pro_name, cur_model);
- }
- //赋值给dcip的树结构
- ui.tree_Model.tree = tree;
- }
- );
- ui.tree_Model.position = cur_id;
- }
- //修改材料面板属性属性
- function ModifyMaterial(material) {
- //获取当前材料的名字
- let material_name = model.acax_app.model.materialProp.Current();
- model.acax_app.control.materialProp.Set(material, material_name);
- unit.form.mainfrm.OnCueline('修改成功', 'green');
- }
- //创建载荷
- function CreateBoundary(Load, name) {
-
- let load = model.acax_app.control.constrain.Create(Load, name);
- let cur_name = model.acax_app.model.constrain.Current();
- let cur_index = model.acax_app.view.GetCurrentWorkConditionIndex();
- let cur_id;
- 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;
- }
- if((cur_name === info.name) && (model.acax_app.path.Parent(info.index, 3) === cur_index)) {
- cur_id = info.id;
- }
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : 0
- };
-
- },
- tree => {
- //获取当前工程的名字
- let pro_Index = model.acax_app.view.GetCurrentProjectIndex();
- let pro_name = model.acax_app.path.Name(pro_Index);
- if(model.acax_app.model.project.GetModel().pro_model) {
- let cur_model = model.acax_app.model.project.GetModel().pro_model;
- findAndAppendByName(tree, pro_name, cur_model);
- }
- //赋值给dcip的树结构
- ui.tree_Model.tree = tree;
- }
- );
- ui.tree_Model.position = cur_id;
- }
- //修改载荷面板属性
- function ModifyConstraint(constrain) {
- let constrain_name = model.acax_app.model.constrain.Current();
- model.acax_app.control.constrain.Set(constrain, constrain_name);
- unit.form.mainfrm.OnCueline('修改成功', 'green');
- }
- 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);
- }
- }
|