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

644 lines
21 KiB

import { Quaternion, Vector3 } from '@babylonjs/core';
import {
BuildingData,
BuildingData_ChemicalPlant,
BuildingData_Environment,
BuildingData_Normal,
BuildingType,
} from '../model/data/institution/building/building-data';
import {
FacilityPosType,
FacilityType,
ModelData_facility,
} from '../model/data/model-data/model-data-facility';
import {
InstitutionData,
NormalData,
} from '../model/data/institution/institution-data';
import {
BuildingPosType,
ModelData,
} from '../model/data/model-data/model-data';
import { ModelData_building } from '../model/data/model-data/model-data-building';
import { TransformData } from '../model/data/transform-data';
import { BabylonTool } from '../tool/babylon-tool';
import { AllFacilityData } from '../model/data/institution/facility/all-facility-data';
import { plainToClass } from 'class-transformer';
import { ConfigManager } from './config-manager';
import { ModelEditData } from '../model/data/model-data/model-edit-data';
import { ServeManager } from './serve-manager';
import { InsitutionDataSimple } from '../model/data/institution/institution-data-simple';
import { PropertyData_Base } from '../model/data/institution/facility/property-data/property-data-base';
import { PropertyData_AQCK } from '../model/data/institution/facility/property-data/outdoor/property-data-aqck';
import { PropertyData_public } from '../model/data/institution/facility/property-data/property-data-public';
import { TsTool } from '../tool/ts-tool';
import { PropertyData_Base_XHS } from '../model/data/institution/facility/property-data/base/property-data-base-xhs';
import { PropertyData_Base_SBJHQ } from '../model/data/institution/facility/property-data/base/property-data-base-sbjhq';
import { PropertyData_PL } from '../model/data/institution/facility/property-data/outdoor/property-data-pl';
import { PropertyData_Base_IMG } from '../model/data/institution/facility/property-data/base/property-data-base-img';
import { PropertyData_Base_XFB } from '../model/data/institution/facility/property-data/base/property-data-base-xfb';
import { PropertyData_FHFQ } from '../model/data/institution/facility/property-data/indoor/property-data-fhfq';
import { PropertyData_SSLT } from '../model/data/institution/facility/property-data/indoor/property-data-sslt';
import { PropertyData_XFDT } from '../model/data/institution/facility/property-data/indoor/property-data-xfdt';
import { PropertyData_ZDQY } from '../model/data/institution/facility/property-data/indoor/property-data-zdqy';
import { PropertyData_DWBZ } from '../model/data/institution/facility/property-data/indoor/property-data-dwbz';
import { PropertyData_GD } from '../model/data/institution/facility/property-data/outdoor/property-data-gd';
import { ModeManager, ModeType } from './mode-manager';
import { AllMarkData } from '../model/data/mark/all-mark-data';
import { AllMarkPlanData } from '../model/data/mark/mark-plan-data';
import { HttpErrorResponse } from '@angular/common/http';
import { PropertyData_Q } from '../model/data/institution/facility/property-data/outdoor/property-data-q';
class Test {
id: string;
}
//数据管理器
export class DataManager {
static institutionData_simple: InsitutionDataSimple;//当前单位简易信息
static institutionData: InstitutionData; //当前单位信息
static allFacilityData: AllFacilityData; //所有可用的设备数据(将来读取自配置表)
/**
* 态势标绘的素材库
*/
static allMarkData: AllMarkData;
/**
* 当前单位的标绘方案信息
*/
static allMarkPlanData: AllMarkPlanData;
static initDebugData(institutionKey: string, onSuccess?: (key: string) => void, onError?: (key: string, error: string) => void) {
//本地捏造消防设备列表信息
DataManager.initDebugData_facility();
if (ModeManager.currentMode == ModeType.Look) {
DataManager.initDebugData_mark();
}
let dataFromServe = true;//true-表示数据来自服务器,false-表示来自本地捏造
if (dataFromServe) {
ServeManager.instance.getInstitutionData(institutionKey, (key, result) => {
if (onSuccess) {
DataManager.institutionData = plainToClass(InstitutionData, result);
DataManager.institutionData.normalData.name = DataManager.institutionData_simple.name;
// console.log(DataManager.institutionData);
onSuccess(key);
}
}, (key, error) => {
if (onError) {
console.error("获取单位信息失败" + key);
onError(key, error);
}
console.error("获取单位信息失败,本地捏造数据");
DataManager.initDebugData_institution();
if (onSuccess) {
onSuccess(key);
}
});
}
else {
//本地捏造测试数据
DataManager.initDebugData_institution();
onSuccess(DataManager.institutionData.normalData.key);
}
}
//初始化单位数据
static initDebugData_institution() {
DataManager.institutionData = new InstitutionData();
DataManager.institutionData.normalData = new NormalData();
DataManager.institutionData.normalData.key = 'Institution001';
DataManager.institutionData.normalData.name = '单位001';
DataManager.institutionData.environmentDatas = [
new BuildingData_Environment(),
];
DataManager.institutionData.environmentDatas[0].normalData = new NormalData();
DataManager.institutionData.environmentDatas[0].normalData.key =
'environment001';
DataManager.institutionData.environmentDatas[0].normalData.name = '环境001';
let environmentTransform = new TransformData(); //用于测试建筑的数据还原效果
environmentTransform.originalScaling = new Vector3(961.66, 5.17, 962.6);
environmentTransform.position = new Vector3(0, -2.939, 0);
environmentTransform.scaling = environmentTransform.originalScaling.clone();
DataManager.institutionData.environmentDatas[0].outdoorData = new ModelEditData();
DataManager.institutionData.environmentDatas[0].outdoorData.index = 1;
let resPath_en = DataManager.getResPath_building(
DataManager.institutionData.normalData.key.toLowerCase(),
DataManager.institutionData.environmentDatas[0].normalData.key.toLocaleLowerCase(),
BuildingPosType.Environment,
);
DataManager.institutionData.environmentDatas[0].outdoorData.modelData = new ModelData_building(
'modelEn001',
'环境001',
BuildingPosType.Environment,
'Terrain.gltf',
environmentTransform,
resPath_en
);
DataManager.institutionData.environmentDatas[0].describe = '这是环境';
let facilityTransform = new TransformData();
facilityTransform.position = new Vector3(-137, 3.3, 150);
facilityTransform.rotationQuaternion = Quaternion.FromEulerAngles(
0,
80 / BabylonTool.c_radian1,
0
);
facilityTransform.originalScaling = new Vector3(0.39, 0.7, 0.37);
facilityTransform.scaling = facilityTransform.originalScaling.multiplyByFloats(
2,
2,
2
);
// let facilityData = new ModelData_facility(
// 'facility001',
// FacilityType.DSXHS,
// '地上消火栓',
// 'DXXHS.gltf',
// facilityTransform,
// FacilityPosType.Outdoor
// );
// DataManager.institutionData.environmentDatas[0].outdoorData.facilities = [
// facilityData,
// ];
DataManager.institutionData.normalBuildingDatas = [
new BuildingData_Normal(),
];
DataManager.institutionData.normalBuildingDatas[0].normalData = new NormalData();
DataManager.institutionData.normalBuildingDatas[0].buildingType =
BuildingType.Normal;
DataManager.institutionData.normalBuildingDatas[0].normalData.key =
'building001';
DataManager.institutionData.normalBuildingDatas[0].normalData.name =
'大楼001';
DataManager.institutionData.normalBuildingDatas[0].describe =
'一个普通大楼';
DataManager.institutionData.normalBuildingDatas[0].outdoorData = new ModelEditData();
DataManager.institutionData.normalBuildingDatas[0].outdoorData.index = 1;
let resPath_out = DataManager.getResPath_building(
DataManager.institutionData.normalData.key.toLowerCase(),
DataManager.institutionData.normalBuildingDatas[0].normalData.key.toLocaleLowerCase(),
BuildingPosType.OutDoor,
);
DataManager.institutionData.normalBuildingDatas[0].outdoorData.modelData = new ModelData_building(
'modelOut001',
'外观模型1',
BuildingPosType.OutDoor,
'ZhuTi.gltf',
new TransformData(),
resPath_out
);
DataManager.institutionData.normalBuildingDatas[0].indoorsData = [];
let indoorData1 = new ModelEditData();
DataManager.institutionData.normalBuildingDatas[0].indoorsData.push(
indoorData1
);
indoorData1.index = 1;
let resPath_inDoor1 = DataManager.getResPath_building(
DataManager.institutionData.normalData.key.toLowerCase(),
DataManager.institutionData.normalBuildingDatas[0].normalData.key.toLocaleLowerCase(),
'nei1'
);
indoorData1.modelData = new ModelData_building(
'nei1',
'室内模型1层',
BuildingPosType.Indoor,
'nei1.gltf',
null,
resPath_inDoor1
);
let indoorData2 = new ModelEditData();
DataManager.institutionData.normalBuildingDatas[0].indoorsData.push(
indoorData2
);
indoorData2.index = 2;
let resPath_inDoor2 = DataManager.getResPath_building(
DataManager.institutionData.normalData.key.toLowerCase(),
DataManager.institutionData.normalBuildingDatas[0].normalData.key.toLocaleLowerCase(),
'nei2'
);
indoorData2.modelData = new ModelData_building(
'nei2',
'室内模型2层',
BuildingPosType.Indoor,
'nei2.gltf',
null,
resPath_inDoor2
);
indoorData2.facilities = [];
let indoorData2FacilityTransform = new TransformData();
indoorData2FacilityTransform.position = new Vector3(-6, -3.1, 29);
indoorData2FacilityTransform.rotationQuaternion = Quaternion.FromEulerAngles(
0,
30 / BabylonTool.c_radian1,
0
);
// let indoorData2FacilityData = new ModelData_facility(
// 'indoor2_facility001',
// FacilityType.DSXHS,
// '地下消火栓1',
// 'DSXHS.gltf',
// indoorData2FacilityTransform,
// FacilityPosType.Indoor
// );
// indoorData2.facilities.push(indoorData2FacilityData);
}
/**
* 获取建筑资源路径(不完整,前面需要添加ObjectsService.baseUrl)
* @param institutionKey
* @param buildingKey
* @param key
*/
static getResPath_building(
institutionKey: string,
buildingKey: string,
key: string
): string {
let result =
institutionKey.toLocaleLowerCase() +
'/' +
ServeManager.ngAssetsPath +
buildingKey.toLocaleLowerCase() +
'/' +
key +
'/';
return result;
}
//获取属性所需文件的路径
static getResPath_facilityProperty(institutionKey: string,
buildingKey: string, facilityType: FacilityType, facilityKey: string, key: string) {
let result =
institutionKey.toLocaleLowerCase() +
'/' +
ServeManager.ngAssetsPath +
buildingKey.toLocaleLowerCase() +
'/' +
ConfigManager.c_reaPath_facilityProperty +
"/" +
facilityType.toLocaleLowerCase() +
'/' +
facilityKey.toLocaleLowerCase() +
"/";
return result;
}
//获取设备资源完整路径
static getResPath_facility(facilityPosType: FacilityPosType, type: FacilityType): string {
let result = "facilities/";
result += facilityPosType.toString() + "/";
result += DataManager.getResName_facility(type).toLocaleLowerCase();
result += "/";
return result;
}
//获取设备的资源名(有些是公用的)
static getResName_facility(type: FacilityType): string {
let result = type.toString();
switch (type) {
case FacilityType.XKS:
case FacilityType.BF:
case FacilityType.SX:
case FacilityType.FHM:
case FacilityType.FHJL:
case FacilityType.SSLT:
case FacilityType.XFDT:
case FacilityType.PTDT:
case FacilityType.HT:
case FacilityType.WXY: result = "Location"; break;
}
return result;
}
//初始化设备信息
static initDebugData_facility() {
DataManager.allFacilityData = AllFacilityData.CreateAllFacilityData();
}
/**
* 初始化态势标绘的素材库
*/
static initDebugData_mark() {
DataManager.allMarkData = AllMarkData.CreateAllMarkData();
console.log(DataManager.allMarkData, "态势标会");
}
static init(simpleData: InsitutionDataSimple, onSuccess?: (key: string) => void) {
DataManager.institutionData_simple = simpleData;
DataManager.initDebugData(simpleData.key, onSuccess);
}
/**
* 新建当前单位的标绘信息
*/
static initAllMarkPlaneData() {
DataManager.allMarkPlanData = new AllMarkPlanData();
DataManager.allMarkPlanData.institutionID = DataManager.institutionData.normalData.key;
DataManager.allMarkPlanData.datas = [];
return DataManager.allMarkPlanData;
}
/**
* 初始化当前建筑的 态势标绘信息
*/
static initMarkData(onSuccess?: (data: AllMarkPlanData) => void) {
ServeManager.instance.getMarkData(DataManager.institutionData.normalData.key, (institutionID: string, data: string) => {
if (data == null) //新建单位的标绘信息
{
DataManager.initAllMarkPlaneData();
}
else //读取已有的标绘信息
{
DataManager.allMarkPlanData = plainToClass(AllMarkPlanData, data);
}
if (onSuccess != null) {
onSuccess(DataManager.allMarkPlanData);
}
}, (institutionID: string, data: any) => {
if (data instanceof HttpErrorResponse && data.status == 404) {
//404,新增单位标绘数据,不算错误
}
else {
ModeManager.log("获取态势标会失败" + institutionID, data);
}
})
}
//#region 创建类方法
/**
* 新建建筑
* @param key
* @param name
* @param buildingType
*/
static createBuilding(key: string, name: string, buildingType: BuildingType): BuildingData {
let result = false;
if (buildingType == null) {
throw new Error('create building buildingType is null');
}
if (key == null) {
throw new Error('create building key is null');
}
if (name == null || name == "") {
throw new Error('create building name is null');
}
let normalData = new NormalData(key, name);
let newBuilding: BuildingData_Normal | BuildingData_Environment | BuildingData_ChemicalPlant;
switch (buildingType) {
case BuildingType.Normal:
newBuilding = new BuildingData_Normal();
DataManager.institutionData.normalBuildingDatas.push(newBuilding as BuildingData_Normal);
break;
case BuildingType.Environment:
newBuilding = new BuildingData_Environment();
DataManager.institutionData.environmentDatas.push(newBuilding as BuildingData_Environment);
break;
case BuildingType.ChemicalPlant:
newBuilding = new BuildingData_ChemicalPlant();
DataManager.institutionData.chemicalPlantData.push(newBuilding as BuildingData_ChemicalPlant);
break;
}
newBuilding.normalData = normalData;
return newBuilding;
}
/**
* 创建属性
* @param key
* @param facilityType
*/
static createPropertyData(key: string, facilityType: FacilityType): PropertyData_Base {
let result: PropertyData_Base = null;
switch (facilityType) {
case FacilityType.AQCK: result = new PropertyData_AQCK(key, "", false, "安全出口", ""); break; //安全出口
case FacilityType.DSXHS:
case FacilityType.DXXHS:
case FacilityType.SZDSXHS:
case FacilityType.SZDXXHS: result = new PropertyData_Base_XHS(key, "", false, "", "", "", facilityType); break;
case FacilityType.DSSBJHQ:
case FacilityType.DXSBJHQ:
case FacilityType.QBSBJHQ:
case FacilityType.DGNSBJHQ: result = new PropertyData_Base_SBJHQ(key, "", "", "", "", facilityType); break;
case FacilityType.GD: result = new PropertyData_GD(key, "-"); break;
case FacilityType.PL: result = new PropertyData_PL(key, 0, "", []); break;
case FacilityType.JTQ:
case FacilityType.JJQ: result = new PropertyData_Q(key, "", "", "", null, facilityType); break;
case FacilityType.TPBZ:
case FacilityType.XKS:
case FacilityType.BF:
case FacilityType.SX: result = new PropertyData_Base_IMG(key, "", "", "", facilityType); break;
case FacilityType.LSXFB:
case FacilityType.WSXFB:
case FacilityType.CYXFB: result = new PropertyData_Base_XFB(key, "", "", "", "", "", "", facilityType); break;
case FacilityType.FHFQ: result = new PropertyData_FHFQ(key, "", ""); break;
case FacilityType.SSLT: result = new PropertyData_SSLT(key, "", "", ""); break;
case FacilityType.XFDT: result = new PropertyData_XFDT(key, "", "", ""); break;
case FacilityType.WXY: result = new PropertyData_Base_IMG(key, "", "", "", facilityType); break;
case FacilityType.ZDQY: result = new PropertyData_ZDQY(key, "", "", "", "", "", []); break;
case FacilityType.DWBZ: result = new PropertyData_DWBZ(key, "", ""); break;
//其他在表格中显示无
}
if (result == null) {
result = new PropertyData_public(key, facilityType);
}
return result;
}
/**
* 新建标绘方案
* @param name
*/
static createMarkPlane(name: string) {
if (DataManager.allMarkPlanData == null) {
console.error("当前单位没有标绘方案,无法新建");
return;
}
let index = 0;
}
//#endregion
//#region 查询类方法
/**
* 根据类型查询建筑列表
* @param buildingType 建筑类型
*/
static getBuildingDataListByType(buildingType: BuildingType): BuildingData_Normal[] | BuildingData_Environment[] | BuildingData_ChemicalPlant[] {
let buildingDatas: BuildingData_Normal[] | BuildingData_Environment[] | BuildingData_ChemicalPlant[];
switch (buildingType) {
case BuildingType.Normal:
buildingDatas = DataManager.institutionData.normalBuildingDatas;
break;
case BuildingType.Environment:
buildingDatas = DataManager.institutionData.environmentDatas;
break;
case BuildingType.ChemicalPlant:
buildingDatas = DataManager.institutionData.chemicalPlantData;
break;
}
return buildingDatas;
}
//#endregion
//#region 修改和删除类方法
//删除一个当前单位的buildingData
static deleteOneBuildingData(buildingType: BuildingType, key: string) {
let buildingDatas = DataManager.getBuildingDataListByType(buildingType);
for (let i = 0; i < buildingDatas.length; i++) {
if (buildingDatas[i].normalData.key == key) {
TsTool.arrayRemove(buildingDatas, buildingDatas[i]);
break;
}
}
}
/**
* 保存当前的标绘信息
*/
static saveallMarkPlanData() {
console.log("当前标绘", DataManager.allMarkPlanData);
ServeManager.instance.saveMarkData(DataManager.allMarkPlanData);
}
//#endregion
//#region 文件修改类
/**
* 创建manifest 类文件
* @param fileName //资源文件名,例如 zhuti.gltf
* @param version //版本号
*/
static createFile_manifest(fileName: string, version: number): File {
let file;
let data = [];
let info = {
"version": version,
"enableSceneOffline": true,
"enableTexturesOffline": true
};
data.push(JSON.stringify(info));
let properties = { type: 'text/cache-manifest' }; // 设置文件的 mime-type.
try {
// 使用文件构造函数指定文件名,如果 ...
file = new File(data, fileName + ".manifest", properties);
} catch (e) {
// ... 如果不支持Blob构造函数,请退回到Blob构造函数。
file = new Blob(data, properties);
}
console.log("创建版本号" + version);
return file;
}
/**
* 创建版本文件(版本号+1)
* @param indoorData
*/
static createManifestFile(modelData: ModelData): File {
modelData.version += 1;
let manifestFile = DataManager.createFile_manifest(modelData.resName, modelData.version);
return manifestFile;
}
/**
* 读取版本文件中的版本号
* @param file
*/
static readFile_manifest(file: File, onLoad: (result) => void): number {
let version = 1;
var reader = new FileReader();
reader.onload = function (evt) { // 指定异步读写后触发的函数
ModeManager.log(evt.target.result);
let object = JSON.parse(evt.target.result as string);
onLoad(object.version);
};
reader.readAsText(file);
return version;
}
//#endregion
}
//模型信息变化类型
export enum ModelChangeType {
Add,
Remove,
Update,
}