YZProjectCloud/yanzhu-bigscreen/src/views/bim/briefingTools.js

236 lines
6.3 KiB
JavaScript

function groupData(data) {
let tmps = [];
let obj = {};
data.forEach((item) => {
let setName = item.propertySetName;
if (!obj[setName]) {
obj[setName] = [];
}
obj[setName].push(item);
});
for (let key in obj) {
tmps.push({
name: key,
data: obj[key],
});
}
return tmps;
}
//清除选中构件样式
function clearSelectFeature(that) {
let api = bimBriefingApi;
if (that.selFeatureId) {
let modelId = that.selFeatureId.split("^")[0];
api.Feature.setColor(that.selFeatureId, "rgba(255,255,255,1)", modelId);
that.selFeatureId = "";
}
}
//查询构件属性信息
function dataFiltering(that, id) {
const gild = id.split("^");
let modelName = "";
that.models.forEach((item) => {
if (item.gis?.lightweightName == gild[0]) {
modelName = item.gis.name;
}
});
if (!modelName || !gild[1]) {
return false;
}
let featureId = gild[1].split("_")[0];
that.$api.bim.modelPropertyByExternalId(gild[0], featureId).then((d) => {
let tmps = d.data || [];
that.propertyAttr = groupData(tmps.filter((d) => d.propertyTypeName == "properties"));
that.propertyType = groupData(tmps.filter((d) => d.propertyTypeName != "properties"));
that.propertyLoad = "end";
});
}
/**
* 获取构件属性信息
*/
function getProperty(that) {
let api = bimBriefingApi;
api.Feature.getByEvent(true, (n) => {
if (n && n["id"]) {
let featureId = n.id;
if (featureId.split("^")[1]) {
let modelId = featureId.split("^")[0];
clearSelectFeature(that);
api.Feature.setColor(featureId, "rgba(255,0,255,1)", modelId);
that.selFeatureId = featureId;
dataFiltering(that, featureId);
that.propertyLoad = "start";
that.attributeInformation = "查询中,请稍候~";
}
} else {
that.attributeInformation = "未选中构件";
}
});
}
function getModelUnit(that, modelId) {
let find = that.models.find((d) => d.modelId == modelId);
return find ? find.unit || 1.0 : 1.0;
}
/**
* 获取构件尺寸信息
*/
function subFeatureSize(that) {
let api = bimBriefingApi;
let result = [
{ name: "构建尺寸", data: [] },
{ name: "构建表面积", data: [] },
{ name: "构建体积", data: [] },
];
that.info = [];
api.Public.clearHandler();
api.Measurement.clearAllTrace();
api.Feature.getByEvent(true, (n) => {
if (n && n["id"]) {
let featureId = n.id;
let modelId = featureId.split("^")[0];
let unit = getModelUnit(that, modelId);
clearSelectFeature(that);
api.Feature.getGeometrySizeById(featureId, (res) => {
let size = res.size || {};
let x = (size.x || 0) * unit * 1.0;
let y = (size.y || 0) * unit * 1.0;
let z = (size.z || 0) * unit * 1.0;
result[0].data = [
{ name: "长", value: x.toFixed(2) + "" },
{ name: "宽", value: y.toFixed(2) + "" },
{ name: "高", value: z.toFixed(2) + "" },
];
result[1].data = [{ name: "面积", value: (x * y).toFixed(4) + "" }];
result[2].data = [{ name: "体积", value: (x * y * z).toFixed(6) }];
api.Feature.setColor(featureId, "rgba(255,0,255,1)", modelId);
that.selFeatureId = featureId;
that.info = result;
});
}
});
}
//构件面积
function measurementArea(that) {
let api = bimBriefingApi;
that.info = [];
api.Public.clearHandler(), api.Measurement.clearAllTrace();
api.Feature.getByEvent(true, (n) => {
console.log(n);
if (n && n["id"]) {
let featureId = n.id;
let modelId = featureId.split("^")[0];
clearSelectFeature(that);
api.Measurement.featureArea(featureId, (res) => {
that.info = [{ name: "面积", value: (+res || 0).toFixed(2) + "" }];
api.Feature.setColor(featureId, "rgba(255,0,255,1)", modelId);
that.selFeatureId = featureId;
});
}
});
}
//构件体积
function measuringVolume(that) {}
//构件距离
function distance(that) {
let api = bimBriefingApi;
let result = [{ name: "测量结果", data: [] }];
that.$message.info("请在模型中点击两点,右键结束测量");
api.Public.clearHandler();
api.Measurement.clearAllTrace();
let unit = 1;
api.Feature.getByEvent(true, (n) => {
if (n && n["id"]) {
let featureId = n.id;
let modelId = featureId.split("^")[0];
unit = getModelUnit(that, modelId);
}
});
//开始测量,左键选点
api.Measurement.distance(true, (data) => {
result[0].data = [
{
name: "距离",
value: (data.distance * unit).toFixed(2),
},
{ name: "X", value: data.x.toFixed(2) },
{ name: "Y", value: data.y.toFixed(2) },
{ name: "Z", value: data.z.toFixed(2) },
];
that.info = result;
});
api.Public.event("LEFT_CLICK", (res) => {
api.Measurement.clearAllTrace();
});
//右键结束测量
api.Public.event("RIGHT_CLICK", (res) => {
api.Measurement.distance(false);
});
}
function getModels(that) {
return that.models.map((d) => d.modelId);
}
//剖切
function initClipping(that) {
let api = bimBriefingApi;
api.Model.clipByBox(getModels(that));
}
//构件隐藏
function actorVisible(that) {
let api = bimBriefingApi;
that.hideFeatureIds = [];
api.Feature.getByEvent(true, (n) => {
if (n && n["id"]) {
let featureId = n.id;
let modelId = featureId.split("^")[0];
api.Feature.setVisible(featureId, false);
that.hideFeatureIds.push({
show:false,
id:featureId.split("^")[1],
modelId:modelId,
featureId:featureId
});
}
});
}
function clearEvent(that) {
let api = bimBriefingApi;
if (api) {
actorShow(that);
api.Feature.getByEvent(false);
api.Model.closeClip();
api.Model.clearBoundsBox();
api.Measurement.setFaceToFaceState(!1);
api.Measurement.setPointToFaceVerticalDistanceState(!1);
api.Public.clearAllDrawObject();
api.Feature.getByEvent(!1);
api.Measurement.angle(!1);
api.Measurement.distance(!1);
api.Measurement.clearAllTrace();
}
}
function actorShow(that) {
let api = bimBriefingApi;
getModels(that).forEach((id) => {
api.Model.original(id);
});
}
export default {
measurementArea,
clearSelectFeature,
getProperty,
subFeatureSize,
measuringVolume,
distance,
initClipping,
actorVisible,
actorShow,
clearEvent,
};