| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585 |
- ////////////////////////////////////////////////////////////////////////////
- // 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 OnClickTree(){
- //获取模型树的对应节点
- let model_id = g_cur_id2index_cache[ui.tree_Model.position];
- 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);
- });
- }
- break;
- //选中材料库
- case 1:
-
- break;
- //切换工程
- case 2:
- //不是当前工程,切换工程
- if(model_id !== cur_proj){
- model.acax_app.view.RenderNode(model_id, info => {
-
- unit.form.physics_material.FindMateial(info.prop);
- });
-
- }
- break;
- //切换工况
- case 3:
-
- break;
- //选中约束
- case 4:
-
- break;
- //选中材料属性
- case 5:
- model.acax_app.view.RenderNode(model_id, info => {
- unit.form.mainfrm.menu(3);
- unit.form.mainfrm.OnChangePicture(2, 1);
- unit.form.mainfrm.OnCueline('结构静力学材料设置', 'blue');
- console.log(info.prop);
- unit.form.mainfrm.setMaterial(info.prop);
- });
- break;
- default:
- break;
- }
-
- }
- //测试函数
- function OnTest(){
- 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;
- }
- console.log(info);
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : info.index
- };
-
- },
- 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;
- }
- console.log(info);
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : info.index
- };
-
- },
- 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);
- 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 : 3
- };
- },
- 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);
- });
- }
- }
- //创建工程
- function CreateProject(name) {
- model.acax_app.control.project.Create(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;
-
- return {
- name : info.name,
- icon : info.icon,
- id : info.id,
- check_state : 2
- };
- },
- tree=>{
- // console.log(model.acax_app.utils.FormatJSON(tree)+'\n');
- 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 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));
- }
- }
- //导入模型树节点
- function OnTree(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 : info.index
- };
-
- },
- 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;
- }
- );
- }
- //创建工况
- function CreateWorkCondition(name){
- let condition_index = model.acax_app.control.workCondition.Create(name);
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- console.log(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 : 2
- };
-
- },
- tree => {
- //获取当前工程的名字
- 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;
- }
- );
-
- }
- //创建材料属性
- function CreateMaterial(mat) {
- let material = model.acax_app.control.materialProp.Create(mat);
-
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- console.log(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 : 2
- };
-
- },
- tree => {
- //获取当前工程的名字
- 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;
- }
- );
-
- }
- //创建载荷
- function CreateBoundary(Load) {
- let load = model.acax_app.control.constrain.Create(Load);
- model.acax_app.view.RenderTree(() => {
- g_cur_id2index_cache = {};
- g_cur_index2id_cache = {};
- }, info=>{
- console.log(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 : 2
- };
-
- },
- tree => {
- //获取当前工程的名字
- 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;
- }
- );
- }
- 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);
- }
- }
|