中化加油站项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

277 lines
7.0 KiB

import { PointerEventTypes } from "@babylonjs/core/Events/pointerEvents";
import { PointerInfo } from "@babylonjs/core/Events/pointerEvents";
import { EventState } from "@babylonjs/core/Misc/observable";
import { Button, Control, Rectangle } from "@babylonjs/gui";
import { PlanComponent } from "src/app/pages/plan/plan.component";
import { DataManager } from "../../controller/data-manager";
import { ModeManager } from "../../controller/mode-manager";
import { SceneManager } from "../../controller/scene-manager";
import { ServeManager } from "../../controller/serve-manager";
import { UIManager } from "../../controller/ui-manager";
import { BabylonUIStyleTool } from "../../tool/babylon-ui-style-tool";
import { GizmoTool, TransformUIType } from "../../tool/gizmo-tool";
import { MeasureTool, MeasureType } from "../../tool/measure-tool";
import { BuildingWindow } from "../building-window/building-window";
import { FacilityWindow } from "../facility-window/facility-window";
import { CopyFacilityInfo, FacilityInfoInSceneWindow } from "../facilityinfoinscene-window/facilityinfoinscene-window";
import { UIBase } from "../window-base/ui-base";
/**
* 工具栏
*/
export class ToolbarWindow extends UIBase {
static instance: ToolbarWindow;
compass: Rectangle;//指南针
compassImage: Button;
/**
* 摄像机为顶视
*/
isTopView: boolean = false;
//#region 前端对接
three: PlanComponent;//前端组件
compassAlpha: number;//指南针旋转 0-2π
/**
* 复制下来的设备数据
*/
copyFacilityData: CopyFacilityInfo;
/**
* 测量工具
*/
measureTool: MeasureTool;
//保存数据
onBtnSave() {
let data = DataManager.institutionData;
ModeManager.log(data);
ServeManager.instance.saveInstitutionData(data, DataManager.institutionData_simple.key, () => {
ModeManager.log("保存成功" + DataManager.institutionData_simple.key);
});
}
/***
* gizmo工具 改为位移
*/
changeGizmoType_position() {
GizmoTool.onTransformUITypeChange(TransformUIType.Position);
GizmoTool.currentGizmoType = TransformUIType.Position;
}
/**
* gizmo工具 改为旋转
*/
changeGizmoType_Rotation() {
GizmoTool.onTransformUITypeChange(TransformUIType.Rotation);
GizmoTool.currentGizmoType = TransformUIType.Rotation;
}
/**
* gizmo工具 改为缩放
*/
changeGizmoType_Scale() {
GizmoTool.onTransformUITypeChange(TransformUIType.Scale);
GizmoTool.currentGizmoType = TransformUIType.Scale;
}
/**
* 改相机为顶视图
* @param isTop true表示为顶视
*/
changeTopView(isTop: boolean) {
SceneManager.Instance.changeCameraMode(isTop);
this.isTopView = isTop;
}
//#endregion
/**
* 清空找不到具体模型的设备info和data
*/
clearHomeLessFacilityData() {
BuildingWindow.instance.clearHomeLessFacilityData();
}
/**
* 清空所有来自模型的设备info和data
*/
clearAllFacilityDataFromMesh() {
BuildingWindow.instance.clearAllFacilityFromMeshData();
}
/**
* 获取并创建建筑上的消防设备数据
*/
getModelAndCreateFacilityData() {
BuildingWindow.instance.getModelAndCreateFacilityData();
}
onInit() {
super.onInit();
ToolbarWindow.instance = this;
let instance = this;
SceneManager.Instance.scene.onBeforeRenderObservable.add(() => {
instance.onUpdate();
});
instance.measureTool = new MeasureTool(SceneManager.Instance.scene);
SceneManager.Instance.scene.onPointerObservable.add(
instance.onPointerObservable
);
//this.initUIBase();
//this.initCompass();
}
initUIBase() {
this.root = new Rectangle("ToolbarWindwow");
UIManager.Instance.uiRoot.addControl(this.root);
this.root.top = 10;
this.root.height = 0.1;
this.root.width = 0.2;
this.root.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
this.root.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_RIGHT;
this.root.thickness = 0;
this.root.zIndex = BabylonUIStyleTool.c_zIndex_topBar;
}
onUpdate() {
let alpha = SceneManager.Instance.defaultCamera.alpha + Math.PI / 2;
this.setCompass(alpha);
}
//#region 复制粘贴、多选设备
/**
* 多选设备
* @param multi
*/
multiSelectFacility(multi: boolean) {
FacilityInfoInSceneWindow.instance.changeMultiSelect(multi);
}
/**
* 复制设备
*/
copyFacility() {
this.copyFacilityData = FacilityInfoInSceneWindow.instance.copyFacility();
}
/**
* 粘贴设备
*/
pasteFacility() {
FacilityWindow.instance.pasteFacility(this.copyFacilityData);
}
//#endregion
//#region 指南针
//设置指南针朝向
setCompass(alpha: number) {
this.compassAlpha = Math.PI + alpha;
// this.three = ThreeDimensionalHomeComponent.instance;
// this.three.rotationAngle = `rotate(${this.compassAlpha * 180 / Math.PI}deg)`
}
//#endregion
//#region 模型吸附
/**
* 是否是吸附
*/
isMeshAdsorb = false;
//鼠标交互监听
onPointerObservable(eventData: PointerInfo, eventState: EventState) {
let instance = ToolbarWindow.instance;
if (!instance.isMeshAdsorb || GizmoTool.s_nowPickAim_mesh == null) {
return;
}
switch (eventData.type) {
case PointerEventTypes.POINTERUP:
if (eventData.pickInfo.hit && !SceneManager.s_isPointerDrag) {
if (GizmoTool.s_nowPickAim_mesh != eventData.pickInfo.pickedMesh) {
SceneManager.meshAdsorbY(GizmoTool.s_nowPickAim_mesh, eventData.pickInfo.pickedMesh, eventData.pickInfo.pickedPoint);
}
setTimeout(
function () {
instance.changeMeshAdsorbY();
},
100);
}
break;
}
}
//改变拾取状态
changeMeshAdsorbY() {
this.isMeshAdsorb = !this.isMeshAdsorb;
PlanComponent.instance.updateSelectAdsorb();
}
//#endregion
//#region 测量工具
/**
* 测距
*/
measureDistance() {
this.measureTool.changeMeasureType(MeasureType.Distance);
}
/**
* 测量高度
*/
measureHeight() {
this.measureTool.changeMeasureType(MeasureType.Height);
}
/**
* 测量面积
*/
measureArea() {
this.measureTool.changeMeasureType(MeasureType.Area);
}
/**
* 结束测量
*/
endMeasure() {
this.measureTool.changeMeasureType(MeasureType.None);
}
// /**
// * 中断测量
// */
// breakMeasure() {
// this.measureTool.changeMeasureType(MeasureType.break);
// }
//#endregion
}