YZProjectCloud/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools.js

198 lines
4.9 KiB
JavaScript
Raw Normal View History

2025-06-27 18:14:29 +08:00
import { modelTreeAllChild } from "@/api/bim/bim";
function selectFeature(that, featureId) {
let api = bimSelectionDlgApi;
if (that.selectItems.includes(featureId)) {
api.Feature.setColor(featureId, "rgba(255,255,255,1)");
let index = that.selectItems.indexOf(featureId);
if (index > -1) {
that.selectItems.splice(index, 1);
}
} else {
api.Feature.setColor(featureId, "rgba(255,0,255,1)");
that.selectItems.push(featureId);
}
}
function hideFeatures(that) {
let tmps = that.allBimData.filter((it) => it.id != that.plan.id);
tmps.forEach((it) => {
console.log("hide-->", it.bim);
it.bim.forEach((it) => {
hideFeature(that, it);
});
});
}
function hideFeature(that, featureId) {
let api = bimSelectionDlgApi;
api.Feature.setVisible(featureId, false);
}
2025-06-27 12:04:58 +08:00
function selectSingle(that) {
let api = bimSelectionDlgApi;
api.Public.clearHandler();
api.Feature.getByEvent(true, (n) => {
if (n && n["id"]) {
let featureId = n.id;
let modelId = featureId.split("^")[0];
2025-06-27 18:14:29 +08:00
selectFeature(that, featureId);
}
});
}
function clearAllSelection(that) {
let api = bimSelectionDlgApi;
api.Public.clearHandler();
that.selectItems.forEach((it) => {
selectFeature(that, it);
});
}
function initBim(that) {
console.log("initBim");
let tmps = that.allBimData.filter((it) => it.id == that.plan.id);
if (tmps.length > 0) {
console.log("selected-->", tmps[0].bim);
tmps[0].bim.forEach((it) => {
selectFeature(that, it);
});
}
}
function getSelectFeatureIds(that) {
let tmps = that.allBimData.filter((it) => it.id == that.plan.id);
if (tmps.length > 0) {
return tmps[0].bim || [];
}
return [];
}
// 加载部分模型(计划中绑定的模型)
function partLoadModel(that) {
let featureIds = getSelectFeatureIds(that);
let api = bimSelectionDlgApi;
let obj = {};
for (let i = 0; i < featureIds.length; i++) {
let it = featureIds[i];
let tmps = it.split("^");
let modelId = tmps[0];
if (!obj[modelId]) {
obj[modelId] = [];
}
obj[modelId].push(it);
}
for (let modelId in obj) {
let tmps = that.models.filter((it) => it.modelId == modelId);
setTimeout(() => {
that.$refs.tree.setChecked(modelId, true, true);
}, 1000);
if (tmps.length > 0) {
let url = `${window.config.modelUrl}/Tools/output/model/${modelId}/root.glt`;
that.partLoad = true;
api.Model.addPart(
url,
modelId,
obj[modelId].join("#"),
(res) => {},
(res) => {
console.log("load part success", res);
that.viewPoint = p;
that.$message.info("模型加载完成");
that.doMenu(2);
initBim(that);
},
{
FlyTo: true,
2025-06-27 12:04:58 +08:00
}
2025-06-27 18:14:29 +08:00
);
2025-06-27 12:04:58 +08:00
}
2025-06-27 18:14:29 +08:00
}
}
//构建树形数据
function buildTreeData(that) {
that.modelTrees = [
{
title: "项目模型",
level: 0,
type: "root",
key: "root",
children: [],
hadLoad: true,
},
];
that.models.forEach((d) => {
let node = {
title: d.modelName,
level: 1,
type: "model",
hasLoad: false,
modelId: d.lightweightName,
key: d.lightweightName,
externalId: "0",
glid: "",
children: [],
data: d,
};
that.modelTrees[0].children.push(node);
getModelFeatures(that, d.lightweightName, node);
2025-06-27 12:04:58 +08:00
});
2025-06-27 18:14:29 +08:00
that.treeExpendedKeys.push("root");
2025-06-27 12:04:58 +08:00
}
2025-06-27 18:14:29 +08:00
//获取模型所有构件
function getModelFeatures(that, modelId, node) {
let tmps = that.allBimData.filter((it) => it.id != that.plan.id);
tmps.forEach((it) => {
console.log("hide-->", it.bim);
it.bim.forEach((it) => {
if (!that.readlyParts.includes(it)) {
that.readlyParts.push(it);
}
});
});
//获取模型构件
modelTreeAllChild(modelId, "").then((res) => {
let objs = res.data || []
objs.forEach((o) => {
o.modelId=modelId
o.featureId=o.modelId+"^"+o.externalId
o.name=o.name||'';
o.name=o.name.replaceAll('"',"").replaceAll("'","").replaceAll('\\','');
o.info=`[${o.externalId}]${o.groupname}-${o.name}`
if(o.externalId == "0"){
return;
}
let featureId=o.modelId+"^"+o.externalId;
if (!that.allParts.includes(featureId)) {
that.allParts.push(featureId);
}
});
that.allFeatures = objs;
let makeTree = (tmps) => {
tmps.forEach((item) => {
item.children = objs.filter((it) => it.pglid == item.glid);
if (item.children.length > 0) {
makeTree(item.children);
}
item.hasLoad = true;
item.title = item.name;
item.key = item.glid;
item.modelId = node.modelId;
});
return tmps;
};
node.children = makeTree(objs.filter((item) => item.level == 0));
that.treeKey++;
});
that.showParts = that.allParts.filter((it) => !that.hideParts.includes(it));
}
2025-06-27 12:04:58 +08:00
export default {
selectSingle,
2025-06-27 18:14:29 +08:00
initBim,
clearAllSelection,
partLoadModel,
buildTreeData,
2025-06-27 12:04:58 +08:00
};