中化加油站项目
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.
 
 
 
 
 
 

266 lines
9.5 KiB

import { Component, ElementRef, OnInit } from '@angular/core';
import { Game } from 'src/app/babylon/game';
import { LoginSatus } from 'src/app/babylon/controller/status/login-status';
import { StatusManager } from 'src/app/babylon/controller/status/status-manager';
import { InsitutionDataSimple } from 'src/app/babylon/model/data/institution/institution-data-simple';
import { ModeManager } from 'src/app/babylon/controller/mode-manager';
import { ServeManager } from 'src/app/babylon/controller/serve-manager';
import { BuildingBasicInfosService } from 'src/app/service/babylon/building-basic-infos.service';
import { ObjectsService } from 'src/app/service/objects.service';
import { ToolbarWindow } from 'src/app/babylon/view/toolbar-window/toobar-window';
import { BuildingStatus } from 'src/app/babylon/controller/status/building-status';
import { BuildingUIItem } from 'src/app/babylon/view/building-window/building-ui-item';
import { BuildingType } from 'src/app/babylon/model/data/institution/building/building-data';
import { BuildingWindow } from 'src/app/babylon/view/building-window/building-window';
import { FacilityUIItem } from 'src/app/babylon/view/facility-window/facility-ui-item';
import { FacilityWindow } from 'src/app/babylon/view/facility-window/facility-window';
import { FacilityInfoUIItem } from 'src/app/babylon/view/facilityinfoinscene-window/facilityinfo-ui-item';
import { EventManager } from '@angular/platform-browser';
@Component({
selector: 'app-plan',
templateUrl: './plan.component.html',
styleUrls: ['./plan.component.scss', './publicPop.scss']
})
export class PlanComponent implements OnInit {
constructor(private element: ElementRef, private buildingBISrv: BuildingBasicInfosService, private objectsSrv: ObjectsService, private eventManager: EventManager) { }
static instance: PlanComponent;
public game: Game = new Game();
public beforeOneSatus; //当前 satus
public canvas: HTMLCanvasElement; //canvas 实例
ngOnInit(): void {
PlanComponent.instance = this;
ServeManager.Init(this.buildingBISrv, this.objectsSrv);
this.canvas = this.element.nativeElement.querySelector('#center') as HTMLCanvasElement;
this.game.init(this.canvas);
//监听 delete键盘事件
this.eventManager.addGlobalEventListener('window', 'keydown', (event: any) => {
if (event.keyCode == 46) { //delete
if (this.beforeOnePropertyData) {
let isDelete = confirm("是否删除已选择模型?");
if (isDelete) { this.beforeOnePropertyData.askDelete(false) };
}
}
})
//监听 delete键盘事件
}
ngAfterViewInit(): void {
let loginStatus = StatusManager.getStatus<LoginSatus>(LoginSatus);
loginStatus.getInstitutionListFromServe((result: InsitutionDataSimple[], data: any) => {
if (ModeManager.institutionDemoKey == ModeManager.c_demoKey_null) { //无指定测试单位,则为正式启动,根据当前单位key寻找
let key = 'ceshi';
console.log("获取数据", data);
let find = data.find(item => { return item.key === key })
if (find) { //如果在data中找到了对应的单位key,则表示已经有三维数据,直接进入
console.log("找到已有单位" + key);
this.beforeOneSatus = StatusManager.getStatus<LoginSatus>(LoginSatus);
this.beforeOneSatus.onSelectInsSuccess(find)
} else { //如果没有找到对应的单位key,则调用新建单位
let name = 'ceshi';
console.log("没找到单位,新建" + key);
loginStatus.createInsitution(key, name);
}
} else {
let find = data.find(item => { return item.key === ModeManager.institutionDemoKey })
if (find) {
sessionStorage.setItem('unitId', find.key)
this.beforeOneSatus = StatusManager.getStatus<LoginSatus>(LoginSatus);
this.beforeOneSatus.onSelectInsSuccess(find)
} else {
this.modelInit(data) //开发模式 选择单位 弹窗
}
}
});
}
ngOnDestroy(): void { //组件销毁前 销毁canvas
this.game.dispose();
this.game = null;
}
//开发模式 选择单位 弹窗
modelInit(InsList) { }
buildingUIItems: BuildingUIItem[] = []; //左侧 建筑list
beforeOneBuildingID: string = null; //选中 左侧建筑ID
modelBuilding: modelBuilding = new modelBuilding(); //创建/编辑 建筑ngModel数据
addBuildingPop: boolean = false; //显隐 新增左侧建筑弹窗
editBuildingPop: BuildingUIItem = null; //显隐 编辑左侧建筑弹窗
isShowLeftBuilding: boolean = true; //显隐 建筑list
toggleLeftBuilding(e) { this.isShowLeftBuilding = e }; //显隐 建筑list
uploadList: File[] = []; //多选上传文件
//选择文件
selectFile(e) {
if (e.target.files.length) {
this.uploadList = [] //多选上传
Object.keys(e.target.files).forEach(item => { this.uploadList.push(e.target.files[item]) })
}
}
//选择建筑
selectLeftBuilding(e) {
let item: BuildingUIItem = e;
this.beforeOneBuildingID = item.getBuildingID()
item.select();
}
//创建/编辑建筑
addModelBuilding(e: modelBuilding) {
if (this.addBuildingPop) { //新增
let order = this.buildingUIItems.length + 1;
this.beforeOneSatus = StatusManager.getStatus<BuildingStatus>(BuildingStatus);
let buildingWindow: BuildingWindow = this.beforeOneSatus.buildingWindow;
let newBuildingData = this.beforeOneSatus.createOneBuildingInData(e.name, e.name, e.modelType);
buildingWindow.changeModel(this.uploadList, newBuildingData);
buildingWindow.createOneBuildingItem(newBuildingData, order);
this.modelBuilding = new modelBuilding();
this.buildingUIItems = this.beforeOneSatus.buildingWindow.buildingUIItems; //更新 建筑列表list
this.addBuildingPop = false; //关闭弹窗
} else if (this.editBuildingPop) { //编辑
this.editBuildingPop.setBuildingName(e.name);
this.editBuildingPop.changeModel(this.uploadList);
this.editBuildingPop = null; //关闭弹窗
}
}
//打开编辑建筑 弹窗
editModelBuilding(event, e: BuildingUIItem) {
event.stopPropagation()
this.modelBuilding.name = JSON.parse(JSON.stringify(e.getBuildingName()))
this.modelBuilding.modelType = JSON.parse(JSON.stringify(e.getBuildingType()))
this.editBuildingPop = e; //打开弹窗
}
//聚焦 建筑
positionModelBuilding(event, e: BuildingUIItem) {
event.stopPropagation()
e.lookAt()
}
//删除建筑
deleteModelBuilding(event, e: BuildingUIItem) {
event.stopPropagation()
let isTrue = confirm('您确定要删除吗')
if (isTrue) {
this.beforeOneSatus = StatusManager.getStatus<BuildingStatus>(BuildingStatus);
let buildingWindow: BuildingWindow = this.beforeOneSatus.buildingWindow;
buildingWindow.deleteBuilding(e)
this.buildingUIItems = this.beforeOneSatus.buildingWindow.buildingUIItems; //更新 建筑列表list
}
}
allFacilityUIItemes: FacilityUIItem[] = []; //底部所有 图标
beforeOneIcon: string = null; //当前选择 图标
// 获取 底部图标栏list
getAllIcons(e: FacilityWindow) {
this.allFacilityUIItemes = e.allFacilityUIItemes
this.beforeOneIcon = null
}
//选择底部图标
selectBottomIcon(e: FacilityUIItem) {
if (this.beforeOneIcon != e.getIconID()) {
this.beforeOneIcon = e.getIconID()
e.select()
} else {
this.beforeOneIcon = null
e.unSelect()
}
}
//取消选择 底部图标
unSelectBottomIcon() {
if (this.beforeOneIcon) {
let e: FacilityUIItem = this.allFacilityUIItemes.find(item => { return item.getIconID() === this.beforeOneIcon })
e ? e.unSelect() : null
this.beforeOneIcon = null
}
}
//底部图标栏 滚动条
bottomScroll(e) {
let bootomDiv = this.element.nativeElement.querySelector('#bottomCenter')
e == 0 ? bootomDiv.scrollLeft = bootomDiv.scrollLeft + 50 : bootomDiv.scrollLeft = bootomDiv.scrollLeft - 50
}
beforeOnePropertyData: FacilityInfoUIItem = null; //当前选择 设备
beforeOnefacilityInfo: string = null; //当前选择 设备ID
//获取选择设备 属性
getPropertyData(e: FacilityInfoUIItem) {
this.beforeOnePropertyData = e
}
selectRightTopFast: number = 0; //当前选择功能 快捷栏
selectAdsorb: boolean = false; //吸附状态
topLevelView: boolean = false; //顶视图状态
//获取设备
getDevice() {
ToolbarWindow.instance.getModelAndCreateFacilityData()
}
//清空设备
clearDevice() {
let isClear = confirm('您确定要清空吗?')
if (isClear) {
ToolbarWindow.instance.clearHomeLessFacilityData()
}
}
//平移
translation() {
this.selectRightTopFast = 0
ToolbarWindow.instance.changeGizmoType_position();
}
//旋转
revolve() {
this.selectRightTopFast = 1
ToolbarWindow.instance.changeGizmoType_Rotation();
}
//缩放
scale() {
this.selectRightTopFast = 2
ToolbarWindow.instance.changeGizmoType_Scale();
}
//吸附
adsorb() {
ToolbarWindow.instance.changeMeshAdsorbY();
}
//获取吸附的状态
updateSelectAdsorb() {
this.selectAdsorb = ToolbarWindow.instance.isMeshAdsorb;
}
//切换至顶视图
toggleTopLevelView() {
this.topLevelView = !this.topLevelView
ToolbarWindow.instance.changeTopView(this.topLevelView)
}
//保存
preserve() {
ToolbarWindow.instance.onBtnSave();
}
}
//创建/编辑 建筑dataType
export class modelBuilding {
name: string = "";
modelType: BuildingType = BuildingType.Normal;
}