!2429 拆单增加保存图纸文件,mes可调用分享图纸界面展示图形

pull/2443/head
cf-erp 12 months ago committed by ChenX
parent 2705367ddf
commit eae63a98b4

@ -2,7 +2,10 @@ import { Intent } from "@blueprintjs/core";
import { app } from "../../ApplicationServices/Application";
import { CheckInterfereTool } from "../../Common/InterfereUtil";
import { StoreageKeys } from "../../Common/StoreageKeys";
import { Hole } from "../../DatabaseServices/3DSolid/Hole";
import { BoardIsShort } from "../../DatabaseServices/BoardLinesReactor";
import { CADFiler } from "../../DatabaseServices/CADFiler";
import { Database } from "../../DatabaseServices/Database";
import { Board } from "../../DatabaseServices/Entity/Board";
import { Entity } from "../../DatabaseServices/Entity/Entity";
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
@ -17,6 +20,7 @@ import { IHardwareType } from "../../Production/Product";
import { AppConfirm } from "../../UI/Components/Common/Confirm";
import { AppToaster } from "../../UI/Components/Toaster";
import { BoardStore } from "../../UI/Store/BoardStore";
import { Purge } from "../Purge";
import { blockBuilder, objectBuilder } from './CheckBuilder';
import { ErpView } from "./ErpView";
import { ExceedMind } from "./ExceedBlocksMind";
@ -131,10 +135,10 @@ async function ExecChaiDan(chaiDanRoute: ErpRoutes)
{
let selction = await GetProductsEntitys();
if (!selction) return;
let intSelfBoards = new Set<Board>();
let minBoardCount = 0;
for (let br of selction.boardList)
const boardList = GetSelectionBoards(selction.selectEntityList, selction.selectRelativeHardware);
for (let br of boardList)
{
let b = br.__OriginalEnt__ ?? br;
if (!intSelfBoards.has(b))
@ -177,13 +181,13 @@ async function ExecChaiDan(chaiDanRoute: ErpRoutes)
app.Editor.SelectCtrl.UpdateView();
return;
}
const metalsList = GetSelectionMetals(selction.selectEntityList);
if (userConfig.chaidanOption.isCheckInterfere)
{
let originEns = new Set<Board>();
for (let b of selction.boardList)
for (let b of boardList)
originEns.add(b.__OriginalEnt__ ?? b);
CheckInterfereTool.GetInstance().Check([...originEns, ...selction.metalsList]).then(objMap =>
CheckInterfereTool.GetInstance().Check([...originEns, ...metalsList]).then(objMap =>
{
if (objMap.length > 0)
{
@ -208,7 +212,7 @@ async function ExecChaiDan(chaiDanRoute: ErpRoutes)
});
return;
}
let parseData = await new ErpParseData().GetCadData(selction.boardList, selction.metalsList);
let parseData = await new ErpParseData().GetCadData(boardList, metalsList);
if (!parseData)
{
AppToaster.show({
@ -247,7 +251,7 @@ async function ExecChaiDan(chaiDanRoute: ErpRoutes)
if (isNewErp === false)
{
// 简单拆单必须有板材
if (chaiDanRoute != ErpRoutes. && chaiDanRoute != ErpRoutes. && selction.boardList.length == 0)
if (chaiDanRoute != ErpRoutes. && chaiDanRoute != ErpRoutes. && boardList.length == 0)
{
AppToaster.show({
message: "没有选择板材,不能拆单",
@ -278,12 +282,17 @@ async function ExecChaiDan(chaiDanRoute: ErpRoutes)
}, "CD_checkDataError");
return;
}
//获取柜体的图纸文件
const boxFileList = getBoxFiles(selction.selectEntityList);
app.Editor.ModalManage.RenderModal(ErpView, {
erpRoute: routeInfo,
session: localStorage.getItem(StoreageKeys.PlatSession),
token: localStorage.getItem(StoreageKeys.PlatToken),
cadData: parseData,
store: store,
selectEntityIDs: [...boardList.map(t => t.objectId.Index), ...metalsList.map(t => t.objectId.Index)],
boxFileList: boxFileList
});
}
function CheckData(parseData: any): CheckResult
@ -353,7 +362,8 @@ async function DecomposeObject()
let store = BoardStore.GetInstance();
let routeInfo: ErpRouteInfo;
routeInfo = GetRouteInfo(ErpRoutes.);
let parseData = new ErpParseData().DecomposeObject(selction.metalsList);
const metalsList = GetSelectionMetals(selction.selectEntityList);
let parseData = new ErpParseData().DecomposeObject(metalsList);
if (parseData.length === 0)
{
AppToaster.show({
@ -431,10 +441,16 @@ export async function GetProductsEntitys()
if (!status)
return;
}
return {
selectEntityList: selction.SelectSet.SelectEntityList,
selectRelativeHardware
};
}
function GetSelectionBoards(selectEntityList: Entity[], selectRelativeHardware: boolean)
{
const boardList: Board[] = [];
const metalsIds: Set<ObjectId> = new Set();
for (let en of selction.SelectSet.SelectEntityList)
for (let en of selectEntityList)
{
if (en instanceof Board)
{
@ -442,7 +458,16 @@ export async function GetProductsEntitys()
if (selectRelativeHardware)
en.RelativeHardware.forEach(id => !id.IsErase && (id.Object instanceof HardwareCompositeEntity || id.Object instanceof HardwareTopline) && metalsIds.add(id));
}
else
}
return boardList;
}
function GetSelectionMetals(selectEntityList: Entity[])
{
const metalsIds: Set<ObjectId> = new Set();
for (let en of selectEntityList)
{
if (!(en instanceof Board))
{
metalsIds.add(en.Id);
}
@ -452,10 +477,7 @@ export async function GetProductsEntitys()
{
metalsList.push(id.Object as IHardwareType);
}
return {
boardList,
metalsList,
};
return metalsList;
}
function checkBlock(blockList: OrderDataBlock[]): { result: boolean, warnBlocks: OrderDataBlock[], warnMsg: string; }
{
@ -519,3 +541,64 @@ function checkBoxSize(blockList: OrderDataBlock[]): { result: boolean, warnMsg:
};
return { result: true, warnMsg: msg };
}
export function groupBy(data: any[], fileds: string[])
{
let groupList = {};
let groupArray = [];
for (const item of data)
{
let keyList = fileds.map(field => item[field]);
let key = keyList.join("-");
groupList[key] = groupList[key] || [];
groupList[key].push(item);
groupList[key].keyList = keyList;
}
for (const key in groupList)
{
groupArray.push({ key, keyList: groupList[key].keyList, value: groupList[key] });
}
return groupArray.sort();
}
//获取房间柜体分组Entitys图纸
function getBoxFiles(entitys: Entity[])
{
const list = entitys.map(t =>
{
if (t instanceof Board)
return { roomName: t.BoardProcessOption.roomName || '未命名', boxName: t.BoardProcessOption.cabinetName || '未命名', entity: t };
if (t instanceof HardwareTopline || t instanceof HardwareCompositeEntity)
return { roomName: t.HardwareOption.roomName || '未命名', boxName: t.HardwareOption.cabinetName || '未命名', entity: t };
});
const groupList = groupBy(list, ['roomName', 'boxName']);
let boxFileList = [];
for (const g of groupList)
{
const data = getGroupFiles(g.value.map(t => t.entity));
boxFileList.push({ roomName: g.keyList[0], boxName: g.keyList[1], data });
}
return boxFileList;
}
//获取房间柜体分组图纸
function getGroupFiles(entitys: Entity[])
{
let ents = new Set();
let hasBrOrHardw = false;
for (let e of entitys)
{
hasBrOrHardw = hasBrOrHardw || (e instanceof Board || e instanceof HardwareCompositeEntity || e instanceof HardwareTopline);
ents.add(e.Id.Index);
}
let f = new CADFiler();
app.Database.FileWrite(f);
let db = new Database(false, false, true);
db.FileRead(f);
for (let e of db.ModelSpace.Entitys)
{
if (!ents.has(e.Id.Index) && !(e instanceof Hole && e.FId && ents.has(e.FId.Index)))
e.Erase();
}
Purge(db);
f = new CADFiler;
db.FileWrite(f);
return f;
}

@ -19,6 +19,7 @@ interface ErpViewProp
token: string;
cadData: { blockList: OrderDataBlock[], objectList: OrderDataObject[]; processGroupList: ProcessGroupObject[]; };
store: BoardStore;
selectEntityIDs: number[];
}
export class ErpView extends React.Component<ErpViewProp, {}> {
iframe: React.RefObject<HTMLIFrameElement>;
@ -59,8 +60,8 @@ export class ErpView extends React.Component<ErpViewProp, {}> {
};
iframeLoaded = () =>
{
// console.log('iframeLoaded');
let fileName = FileServer.GetInstance().currentFileInfo.name;
const fileServer = FileServer.GetInstance();
let fileName = fileServer.currentFileInfo.name;
let option = Object.assign({}, userConfig.chaidanOption);
let singleData = { session: this.props.session, cadData: this.props.cadData, fileName: fileName };
switch (this.props.erpRoute.RouteType)
@ -71,7 +72,8 @@ export class ErpView extends React.Component<ErpViewProp, {}> {
chaidanOption: option,
permission: {
createOrder: userConfig.isMaster || userConfig.rights.includes('417')
}
},
boxFileList: this.props['boxFileList']
});
break;
case ErpRoutes.:

@ -74,6 +74,7 @@ export class OrderDataBlock
RemarkExtra: string;
AllRemarkList: [string, string][];
CustBlockNo: number;
ObjectID: number;//CAD实体ID关联Mes板材信息用
}
export enum CadType
{

@ -26,6 +26,7 @@ import { HardwareCompositeEntity } from './../../DatabaseServices/Hardware/Hardw
import { ProcessingGroupRecord } from './../../DatabaseServices/ProcessingGroup/ProcessingGroupRecord';
import { TemplateLatticeRecord } from './../../DatabaseServices/Template/ProgramTempate/TemplateLatticeRecord';
import { TemplateWineRackRecord } from './../../DatabaseServices/Template/ProgramTempate/TemplateWineRackRecord';
import { groupBy } from "./ErpCommands";
import { GetArray, GetPointInfoArray } from "./Models/ArrayHelper";
import { CadType, OrderDataBlock, WaveType } from "./Models/CadBlock";
import { BasePosition, CadBlockHoles, CadBlockInfo, CadBlockModel, CadBlockModelPoint, CadBlockPoint, FaceType, HoleType, ModelOffSetData } from "./Models/CadBlockInfo";
@ -198,6 +199,7 @@ export class ErpParseData
let hxdj = this.GetNumberBit(block.Thickness, 2) <= this.GetNumberBit(entity.Thickness, 2) && (this.GetNumberBit(block.Width, 2) != this.GetNumberBit(entity.Width, 2) || this.GetNumberBit(block.Height, 2) != this.GetNumberBit(entity.Height, 2));
block.IsHXDJX = hxdj && boardData.boardContour && boardData.boardContour.buls.some(t => t > 0);
block.CustBlockNo = entity.CustomNumber;
block.ObjectID = entity.Id.Index;
blockList.push(block);
}
@ -681,7 +683,7 @@ export class ErpParseData
//柜体名称
if (br instanceof Board)
{
brModelData.CabName = br.BoardProcessOption[EBoardKeyList.RoomName];
brModelData.CabName = br.BoardProcessOption[EBoardKeyList.CabinetName];
brModelData.BoardName = br.Name;
//纹路
brModelData.Grain = br.BoardProcessOption[EBoardKeyList.Lines];
@ -788,7 +790,7 @@ export class ErpParseData
{
return { roomName: t.BoardProcessOption.roomName || '未命名', boxName: t.BoardProcessOption.cabinetName || '未命名', board: t };
});
let groupList = this.groupBy(list, ['roomName', 'boxName']);
let groupList = groupBy(list, ['roomName', 'boxName']);
let options: GetCountOption = {
getHoles: (name: string, hole: CylinderHole) =>
{
@ -819,7 +821,7 @@ export class ErpParseData
{
let holeList = holeMap.get(name);
let groupList = this.groupBy(holeList.map(t => t.GroupId), ['Index']);
let groupList = groupBy(holeList.map(t => t.GroupId), ['Index']);
for (const g of groupList)
{
let spec = '';
@ -863,7 +865,7 @@ export class ErpParseData
specList.push({ spec });
}
}
let sGroupList = this.groupBy(specList, ['spec']);
let sGroupList = groupBy(specList, ['spec']);
return sGroupList.map(t => { return { spec: t.key, count: t.value.length }; });
};
for (const g of groupList)
@ -908,7 +910,7 @@ export class ErpParseData
const fun = (holes: IDrillingOption[], frontOrSide: FrontOrSide) =>
{
const holeList = holes.map(t => { return { name: t.type == (GangDrillType.Wood || t.type == GangDrillType.WoodPXL) ? '木销' : t.name, type: t.type, face: t.face }; });
let groupList = this.groupBy(holeList, ['name', 'type', 'face']);
let groupList = groupBy(holeList, ['name', 'type', 'face']);
let infos: { name: string, type: string, face: string, count: number; }[] = [];
for (const g of groupList)
{
@ -981,22 +983,4 @@ export class ErpParseData
return cadObj.Name === "层板" || cadObj.Name === "立板";
return false;
};
groupBy(data: any[], fileds: string[])
{
let groupList = {};
let groupArray = [];
for (const item of data)
{
let keyList = fileds.map(field => item[field]);
let key = keyList.join("-");
groupList[key] = groupList[key] || [];
groupList[key].push(item);
groupList[key].keyList = keyList;
}
for (const key in groupList)
{
groupArray.push({ key, keyList: groupList[key].keyList, value: groupList[key] });
}
return groupArray.sort();
}
}

@ -7,9 +7,12 @@ import { ErrorMonitoring } from "../../Common/ErrorMonitoring";
import { CURRENT_HOST } from "../../Common/HostUrl";
import { LogEnable, ReportErrorWrap } from "../../Common/Log";
import { RequestStatus } from "../../Common/Request";
import { Sleep } from "../../Common/Sleep";
import { safeEval } from "../../Common/eval";
import { inflateBase64 } from "../../Common/inflate";
import { CADFiler } from "../../DatabaseServices/CADFiler";
import { Database } from "../../DatabaseServices/Database";
import { Board } from "../../DatabaseServices/Entity/Board";
import { commandMachine } from "../../Editor/CommandMachine";
import { userConfig } from "../../Editor/UserConfig";
import { ARC_DRAW_CONFIG } from "../../Geometry/ExtrudeMeshGeomBuilder/SplitCurveParams";
@ -21,7 +24,7 @@ import "../../UI/Css/style.less";
import "../../UI/Css/switchTheme.less";
import { ShareViewLayout } from "./ShareViewLayout";
import { ViewAngleTypes, ViewStyleTypes } from "./ShareViewRules";
import { ICabinetFormatData } from "./ShareViewService";
import { BlockNoObj, ICabinetFormatData, ShareService } from "./ShareViewService";
import { ShareViewStore } from "./ShareViewStore";
import { ChangeThemeColor, GetBoxCovers, resetBoxView } from "./ShareViewUtil";
@ -32,7 +35,6 @@ interface ILoadData
cadFile: CADFiler;
urlSearch: URLSearchParams;
}
//禁止用户选中
document.addEventListener("selectionchange", () =>
{
@ -124,10 +126,9 @@ document.addEventListener("keydown", (e: KeyboardEvent) =>
}
}),
{ passive: false };
//接受所有输入框的快捷键(因为我们的输入框不多,如果输入框要避免响应,那么必须监听键盘按下事件,并且阻止默认和防止冒泡)
// hotkeys.filter = e => true;//我们将在inputhint中修改这个
const layout = new ShareViewLayout();
window.onload = async function ()
{
const loadingEl = document.getElementById("loader-wrapper");
@ -204,86 +205,49 @@ window.onload = async function ()
HostApplicationServices.ProxyObject = userConfig;
const layout = new ShareViewLayout();
// 修改默认为概念渲染
commandMachine.ExecCommand(CommandNames.Conceptual);
const shareViewStore: ShareViewStore = ShareViewStore.GetInstance();
window.addEventListener('message', setDataListenEvent);
try
{
//加载图纸
const { cadFile, urlSearch } = await LoadData();
if (cadFile)
const urlSearch = new URLSearchParams(location.search);
const viewId = urlSearch.get('view_id');
const is_iframe = urlSearch.get('is_iframe');
//需要先设置带线框颜色与视图样式
if (viewId)
{
const { cadFile } = await LoadData();
commandMachine.ExecCommand(CommandNames.Swiso); // 预览图默认西南
await layout.app.LoadFile(cadFile);
//在加载渲染完成后 初始化UI
let OnRenderdInit = async () =>
if (cadFile)
{
const cabinetObj: ICabinetFormatData = {};
await GetBoxCovers((url, item, index) =>
{
const roomName = item.roomName || '未命名';
const cabinetItemData = {
roomName: roomName,
item: item,
img: url,
index: index,
};
cabinetObj[roomName] ? cabinetObj[roomName].push(cabinetItemData) : cabinetObj[roomName] = [cabinetItemData];
});
ChangeThemeColor("light");
layout.app.BoxCtrl.SetCabinetFormatData(cabinetObj);
layout.app.BoxCtrl.SetCabinetVisible(layout.app.BoxCtrl.CabinetList.length - 1, false);
shareViewStore.RoomName = Object.keys(cabinetObj)[0];
// 展示第一个房间所有柜子
if (Object.keys(cabinetObj)[0])
{
const indexes: number[] = [];
cabinetObj[Object.keys(cabinetObj)[0]].forEach(item =>
{
indexes.push(item.index);
layout.app.BoxCtrl.SetCabinetVisible(item.index, true);
});
shareViewStore.CurSelectCabinetIndexs = indexes;
}
//预览图生成后视角跟随url
shareViewStore.viewUploadProps = {
...shareViewStore.viewUploadProps,
Viewport: safeEval(urlSearch.get("Viewport")),
};
const { Viewport } = shareViewStore.viewUploadProps;
const viewDirectionIndex = ViewAngleTypes.findIndex((v) => v.viewDirection === Viewport);
if (viewDirectionIndex > -1) commandMachine.ExecCommand(ViewAngleTypes[viewDirectionIndex].command);
else commandMachine.ExecCommand(CommandNames.Swiso); // 设置默认视图为 西南等轴测
layout.app.Viewer.OnSize();
layout.app.Viewer.Render();
resetBoxView();
loadingEl.remove();
};
//在渲染对象准备好之后在初始化UI (为了保证预览图正确)
let removeAop = end(layout.app.Viewer, layout.app.Viewer.RenderDatabaseEndEvent, () =>
UpdateView();
await layout.app.LoadFile(cadFile);
}
}
if (is_iframe)//iframe调用
{
if (window.parent)//页面加载完成通知iframe发送数据
{
OnRenderdInit();
app.Viewer.CameraControl.Update();//IOS的时候我们FIX了Target 所以我们需要更新
app.Viewer.UpdateRender(); //因为我们更新了相机 所以也要更新渲染
removeAop();
});
window.parent.postMessage({ command: 'viewMounted' }, '*');
}
}
else
loadingEl.remove();
} catch {
if (!viewId && !is_iframe)
shareViewStore.ViewIDErrorMsg = `url缺少view_id参数`;
} catch (err)
{
loadingEl.remove();
}
// LoadDefaultExr();
};
window.onbeforeunload = function ()
{
window.removeEventListener('message', setDataListenEvent);
};
// globalThis["copy"] = (text: string) => {
// console.log("你有2秒的时间让页面聚焦,否则将无法拷贝!");
// setTimeout(async () => {
@ -298,7 +262,6 @@ async function LoadData(): Promise<{ cadFile: CADFiler; urlSearch: URLSearchPara
const shareViewStore: ShareViewStore = ShareViewStore.GetInstance();
const urlSearch = new URLSearchParams(location.search);
const viewId = urlSearch.get('view_id');
//需要先设置带线框颜色与视图样式
InitPartShareConfiguration(urlSearch);
@ -314,7 +277,6 @@ async function LoadData(): Promise<{ cadFile: CADFiler; urlSearch: URLSearchPara
if (data.err_code === RequestStatus.Ok)
{
// userConfig.uese = data.fileInfo.uese;
const file = JSON.parse(inflateBase64(data.fileInfo.file));
document.title = data.fileInfo.name;
if (data.fileInfo.props && Object.prototype.toString.call(data.fileInfo.props) === '[object Object]')
@ -326,9 +288,6 @@ async function LoadData(): Promise<{ cadFile: CADFiler; urlSearch: URLSearchPara
{
shareViewStore.ViewIDErrorMsg = `${data.err_code}: ${data.err_msg}`;
}
} else
{
shareViewStore.ViewIDErrorMsg = `url缺少view_id参数`;
}
}
@ -346,7 +305,6 @@ function InitPartShareConfiguration(urlSearch: URLSearchParams)
const { VisualStyle, Physical2EdgeColor } = shareViewStore.viewUploadProps;
if (Physical2EdgeColor !== null) HostApplicationServices.Physical2EdgeColor = Physical2EdgeColor;
const viewStyleIndex = ViewStyleTypes.findIndex((v) => v.renderType === VisualStyle);
if (viewStyleIndex > -1) commandMachine.ExecCommand(ViewStyleTypes[viewStyleIndex].cmd);
else
@ -356,3 +314,164 @@ function InitPartShareConfiguration(urlSearch: URLSearchParams)
shareViewStore.viewUploadProps.VisualStyle = RenderType.Conceptual;
};
}
//设置图形数据
/**
* viewDataList:cadView
* viewFileList:cad
* viewFileList.file:
* viewFileList.blockDic
* filterIDsid,
**/
async function SetData(content: {
viewDataList: any[], viewFileList: { file: CADFiler, blockDic: { [index: number]: BlockNoObj; }; }[],
filterIDs: number[];
})
{
const shareViewStore: ShareViewStore = ShareViewStore.GetInstance();
if (content.viewDataList.length == 0 && content.viewFileList.length == 0)
{
const loadingEl = document.getElementById("loader-wrapper");
loadingEl.remove();
shareViewStore.ViewIDErrorMsg = `未找到图形数据!`;
return;
}
//更新视图回调
UpdateView();
let oldDb = new Database();
const startIndex = 101;
let blockNoDic: { [index: number]: BlockNoObj; } = {};//板件编号颜色map
let oldBlockNoDic: { [index: number]: BlockNoObj; } = {};//旧版图形数据板件编号颜色map
const oldEntitys = layout.app.GetEntitysByViewData(content.viewDataList, startIndex, oldBlockNoDic);
oldDb.ModelSpace.Entitys.push(...oldEntitys);
const oldFile = new CADFiler();
oldDb.FileWrite(oldFile);
const oldFiles = [oldFile].map(t => { return { file: t, blockDic: null }; });
content.viewFileList.map(t => t.file = Object.assign(new CADFiler, t.file));
const files = [...oldFiles, ...content.viewFileList];
//插入图纸
layout.app.insertFiles(files, content.filterIDs, oldBlockNoDic, blockNoDic);
layout.app.BoxCtrl = new ShareService();
await layout.app.BoxCtrl.Init();
layout.app.BoxCtrl.AddBlockNoDic(blockNoDic);
layout.app.Viewer.RenderDatabaseEndEvent();
}
//视图更新方法
function UpdateView()
{
const shareViewStore: ShareViewStore = ShareViewStore.GetInstance();
commandMachine.ExecCommand(CommandNames.Swiso); // 预览图默认西南
const loadingEl = document.getElementById("loader-wrapper");
//在加载渲染完成后 初始化UI
let OnRenderdInit = async () =>
{
const cabinetObj: ICabinetFormatData = {};
await Sleep(100);
await GetBoxCovers((url, item, index) =>
{
const roomName = item.roomName || '未命名';
const cabinetItemData = {
roomName: roomName,
item: item,
img: url,
index: index,
};
cabinetObj[roomName] ? cabinetObj[roomName].push(cabinetItemData) : cabinetObj[roomName] = [cabinetItemData];
});
ChangeThemeColor("light");
layout.app.BoxCtrl.SetCabinetFormatData(cabinetObj);
layout.app.BoxCtrl.SetCabinetVisible(layout.app.BoxCtrl.CabinetList.length - 1, false);
shareViewStore.RoomName = Object.keys(cabinetObj)[0];
const urlSearch = new URLSearchParams(location.search);
const blockNo = urlSearch.get('blockNo');
if (blockNo)//根据板编号选择指定的板,选择板所在的柜子
{
const kv = layout.app.BoxCtrl.BlockNoDict;
const getBlock = () =>
{
for (const key in kv)
{
if (kv[key].blockNo == blockNo)
{
const block = layout.app.Database.ModelSpace.Entitys.find(t => t.objectId.Index == Number(key));
if (block instanceof Board)
return block;
}
}
};
const block = getBlock();
if (block)
{
const setBlockBox = () =>
{
//查找柜子
const roomName = block.BoardProcessOption.roomName;
const boxName = block.BoardProcessOption.cabinetName;
for (const key in cabinetObj)
{
for (const item of cabinetObj[key])
{
if (item.roomName == roomName && item.item.cabinetName == boxName)
{
layout.app.BoxCtrl.SetCabinetVisible(item.index, true);
shareViewStore.RoomName = roomName;
shareViewStore.CurSelectCabinetIndexs = [item.index];
shareViewStore.SelectedBoard = block;
return;
}
}
}
};
setBlockBox();
}
} else
{
// 展示第一个房间所有柜子
if (Object.keys(cabinetObj)[0])
{
const indexes: number[] = [];
cabinetObj[Object.keys(cabinetObj)[0]].forEach(item =>
{
indexes.push(item.index);
layout.app.BoxCtrl.SetCabinetVisible(item.index, true);
});
shareViewStore.CurSelectCabinetIndexs = indexes;
}
}
//预览图生成后视角跟随url
shareViewStore.viewUploadProps = {
...shareViewStore.viewUploadProps,
Viewport: safeEval(urlSearch.get("Viewport")),
};
const { Viewport } = shareViewStore.viewUploadProps;
const viewDirectionIndex = ViewAngleTypes.findIndex((v) => v.viewDirection === Viewport);
if (viewDirectionIndex > -1) commandMachine.ExecCommand(ViewAngleTypes[viewDirectionIndex].command);
else commandMachine.ExecCommand(CommandNames.Swiso); // 设置默认视图为 西南等轴测
layout.app.Viewer.OnSize();
layout.app.Viewer.Render();
resetBoxView();
loadingEl && loadingEl.remove();
};
//在渲染对象准备好之后在初始化UI (为了保证预览图正确)
let removeAop = end(layout.app.Viewer, layout.app.Viewer.RenderDatabaseEndEvent, () =>
{
OnRenderdInit();
app.Viewer.CameraControl.Update();//IOS的时候我们FIX了Target 所以我们需要更新
app.Viewer.UpdateRender(); //因为我们更新了相机 所以也要更新渲染
removeAop();
});
}
//监听postMessage事件
async function setDataListenEvent(e)
{
let data = e.data;
switch (data.command)
{
case 'setData':
//插入数据
await SetData(data.content);
break;
default:
break;
}
}

@ -4,6 +4,8 @@ import { begin, end } from "xaop";
import { ApplicationService, app } from "../../ApplicationServices/Application";
import { HostApplicationServices } from "../../ApplicationServices/HostApplicationServices";
import { EBoardKeyList } from "../../Common/BoardKeyList";
import { DuplicateRecordCloning } from "../../Common/Status";
import { Hole } from "../../DatabaseServices/3DSolid/Hole";
import { BoardLinesReactor } from "../../DatabaseServices/BoardLinesReactor";
import { CADFiler } from "../../DatabaseServices/CADFiler";
import { Database } from "../../DatabaseServices/Database";
@ -11,8 +13,10 @@ import { Board } from "../../DatabaseServices/Entity/Board";
import { Entity } from "../../DatabaseServices/Entity/Entity";
import { HardwareCompositeEntity } from "../../DatabaseServices/Hardware/HardwareCompositeEntity";
import { HardwareTopline } from "../../DatabaseServices/Hardware/HardwareTopline";
import { ObjectId } from "../../DatabaseServices/ObjectId";
import { RoomParseReactor } from "../../DatabaseServices/Room/ParseService/RoomParseReactor";
import { FontLoader } from "../../DatabaseServices/Text/FontLoader";
import { WblockCloneFiler2 } from "../../DatabaseServices/WblockCloneFiler";
import { AutoSaveServer } from "../../Editor/AutoSave";
import { BoardMoveTool } from "../../Editor/BoardMoveTool";
import { CameraControls } from "../../Editor/CameraControls";
@ -38,10 +42,13 @@ import { ShowToasterClearSiteData } from "../../UI/Components/ToasterClearSiteDa
import { DownPanelStore } from "../../UI/Store/DownPanelStore";
import { HardwareCuttingReactor } from "../BoardCutting/HardwareCuttingReactor";
import { DrillingReactor } from "../DrawDrilling/DrillingReactor";
import { Purge } from "../Purge";
import { ShareViewStore } from "./ShareViewStore";
import { MaterialDetailScrollTo } from "./ShareViewUtil";
import { SimpleBoard } from "./SimpleBoard";
import { SetSelectedBoardChange } from "./StoreEvent";
export let shareViewApp: ShareViewService;
export type BlockNoObj = { blockNo: string, color: string; };
export class ShareViewService extends ApplicationService
{
// WebSocket: WebSocketClientServer = null;
@ -279,8 +286,91 @@ export class ShareViewService extends ApplicationService
this.BoxCtrl = new ShareService();
await this.BoxCtrl.Init();
}
//设置图形数据
/**
* viewDataList:cadView
* viewFileList:cad
* viewFileList.file:
* viewFileList.blockDic
* filterIDsid,
**/
//获取旧版板件数据
GetEntitysByViewData(dataList: any[], startIndex: number, blockNoDic: { [index: number]: BlockNoObj; })
{
const entitys: Entity[] = [];
let index = startIndex;
for (const d of dataList)
{
const simpleBoard = new SimpleBoard(d);
const boardEntitys = simpleBoard.createBoardEntity();
const board = boardEntitys.board;
board.objectId = new ObjectId(index);
board.CustomNumber = d.CustomNumber;
entitys.push(board);
const blockObj: BlockNoObj = { blockNo: simpleBoard.BlockNo, color: simpleBoard.Color };
blockNoDic[board.Id.Index] = blockObj;
index++;
for (const hole of boardEntitys.holes)
{
hole.objectId = new ObjectId(index);
hole.FId = board.Id;
hole.Visible = false;
entitys.push(hole);
index++;
}
}
return entitys;
}
//插入文件数据到当前视图
insertFiles(viewFileList: { file: CADFiler, blockDic: { [index: number]: BlockNoObj; }; }[], filterIDs: number[], oldBlockNoDic: { [index: number]: BlockNoObj; }, blockNoDic: { [index: number]: BlockNoObj; })
{
for (const vf of viewFileList)
{
const f = vf.file;
let db = new Database();
f.database = db;
db.FileRead(f);
if (vf.blockDic && filterIDs.length > 0)//过滤板材
for (let e of db.ModelSpace.Entitys)
{
if (!filterIDs.includes(e.Id.Index) && !(e instanceof Hole && filterIDs.includes(e.FId.Index)))
e.Erase();
}
Purge(db);
let ens = db.ModelSpace.Entitys as Entity[];
ens = ens.concat(db.Lights.Entitys.filter(id => id.Id.Index > 99));
if (ens.length > 0)
{
let filer = new WblockCloneFiler2();
let idMap = new Map();
app.Database.WblockCloneObejcts(ens, app.Database.ModelSpace, idMap, DuplicateRecordCloning.Ignore, filer) as Entity[];
//板编号颜色map对应处理
for (const e of ens.filter(t => t instanceof Board))
{
if (vf.blockDic)//新版数据map
{
const newID = idMap.get(e.Id);
if (newID)
{
const indexDic = vf.blockDic[e.Id.Index];
if (indexDic)
{
const blockObj: BlockNoObj = { blockNo: indexDic.blockNo, color: indexDic.color };
blockNoDic[newID.Index] = blockObj;
}
}
} else//旧版数据map
{
const newID = idMap.get(e.Id);
const dic = oldBlockNoDic[e.Id.Index];
blockNoDic[newID.Index] = dic;
}
}
}
}
}
}
class IgnoreAutoSave extends AutoSaveServer
{
override Do(): void { }
@ -309,6 +399,8 @@ export class ShareService
_CabinetList: CabinetInfo[] = [];
_CabinetDict: { [key: string]: Set<Entity>; } = {};
_CabinetFormatData: ICabinetFormatData;
//板编号,颜色字典
_BlockNoDict: { [index: string]: { blockNo: string, color: string; }; } = {};
get CabinetFormatData()
{
return this._CabinetFormatData;
@ -317,6 +409,11 @@ export class ShareService
{
return this._CabinetList;
}
//板编号,颜色字典
get BlockNoDict()
{
return this._BlockNoDict;
}
Init()
{
let ens: Entity[] = [];
@ -381,6 +478,7 @@ export class ShareService
SetCabinetVisible(cabinetIndex: number, visible: boolean)
{
if (cabinetIndex < 0) return;
const ens = this.GetCabinetEntities(cabinetIndex);
this.GetCabinetEntities(cabinetIndex).forEach((ent) =>
{
ent.Visible = visible;
@ -409,6 +507,12 @@ export class ShareService
});
});
//旧版数据排钻
let holes = app.Database.ModelSpace.Entitys.filter(t => t instanceof Hole && t.FId.Index == ent.Id.Index);
for (const h of holes)
{
h.Visible = visible;
}
}
});
}
@ -445,4 +549,14 @@ export class ShareService
else if (entity instanceof HardwareTopline)
return entity.HardwareOption;
}
//添加板编号,颜色字典
AddBlockNoDic(dic: { [index: number]: { blockNo: string, color: string; }; })
{
for (const key in dic)
{
this._BlockNoDict[key] = dic[key];
}
}
}

@ -99,6 +99,16 @@ export function ChangeCylinderHoleVisible(index: number, visible: boolean)
{
if (ent instanceof Hole && !ent.IsErase)
ent.Visible = !visible;
//旧版数据排钻
if (ent instanceof Board)
{
let holes = app.Database.ModelSpace.Entitys.filter(t => t instanceof Hole && t.FId.Index == ent.Id.Index);
for (const h of holes)
{
h.Visible = !visible;
}
}
}
}
@ -449,3 +459,15 @@ export function ChangeThemeColor(type: 'light' | 'dark' | string)
{
shareViewApp.Viewer.Renderer.setClearColor(type === 'light' ? '#E0E0E0' : '#000', 1);
}
//获取板编号
export function GetBlockNo(index)
{
return shareViewApp.BoxCtrl.BlockNoDict[index]?.blockNo ?? '';
}
//获取板颜色
export function GetBlockColor(item)
{
const color = item.BoardProcessOption.color;
if (color && color.length > 0) return color;
return shareViewApp.BoxCtrl.BlockNoDict[item.Id.Index]?.color ?? '';
}

@ -0,0 +1,175 @@
import { Matrix4, Vector2, Vector3 } from "three";
import { ExtrudeHole } from "../../DatabaseServices/3DSolid/ExtrudeHole";
import { Board } from "../../DatabaseServices/Entity/Board";
import { LinesType } from "../../DatabaseServices/Entity/BoardInterface";
import { Circle } from "../../DatabaseServices/Entity/Circle";
import { ExtrudeSolid } from "../../DatabaseServices/Entity/Extrude";
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
import { JigUtils } from "../../Editor/JigUtils";
import { boardUVGenerator2 } from "../../Geometry/BoardUVGenerator";
function getVec(data: object): Vector3
{
return new Vector3(data["x"], data["y"], data["z"]);
}
enum BoardType
{
Layer = 0,
Vertical = 1,
Behind = 2
}
export class SimpleBoard
{
BoardName: string;
boardPts: any[];
boardBuls: any[];
xD: Vector3;
yD: Vector3;
zD: Vector3;
height: number;
width: number;
thickness: number;
pBase: Vector3;
SubBoardLocal: any[];
Drillings: any[];
DataID: number;
_BoardType: BoardType;
_CustomNumber: string;
RoomName: string = '';
BoxName: string = '';
Wave: number = 0;
PaiKong: number = 0;
HoleFace: number = 0;
SealedDown: number = 0;
SealedLeft: number = 0;
SealedUp: number = 0;
SealedRight: number = 0;
Color: string = '';
Material: string = '';
MaterialName: string = '';
BlockNo: string = '';
constructor(boardData: any)
{
this.boardPts = boardData["Pts"];
this.boardBuls = boardData["Buls"];
this.pBase = getVec(boardData["BasePoint"]);
this.xD = getVec(boardData["XVec"]);
this.yD = getVec(boardData["YVec"]);
this.zD = getVec(boardData["ZVec"]);
this.SubBoardLocal = boardData["SubBoardLocal"] ?? [];
this.Drillings = boardData["Drillings"] ?? [];
this.height = boardData["L"];
this.width = boardData["W"];
this.thickness = boardData["H"];
this.BoardName = boardData["BoardName"];
this.DataID = boardData['DataID'];
this._BoardType = boardData['BoardType'];
this._CustomNumber = boardData['CustomNumber'];
this.RoomName = boardData['RoomName'];
this.BoxName = boardData['BoxName'];
this.Color = boardData['Color'];
this.Material = boardData['Material'];
this.MaterialName = boardData['MaterialName'];
this.SealedDown = boardData['SealedDown'];
this.SealedUp = boardData['SealedUp'];
this.SealedLeft = boardData['SealedLeft'];
this.SealedRight = boardData['SealedRight'];
this.BlockNo = boardData['BlockNo'];
}
//生成板的拉伸实体
public Conver2Ext(): ExtrudeSolid
{
let pts: Vector2[] = [];
let buls: number[] = [];
let boardMat = new Matrix4();
let matInv: Matrix4 = new Matrix4();
this.pBase.add(this.zD.clone().multiplyScalar(-this.thickness));
boardMat.makeBasis(this.xD, this.yD, this.zD);
boardMat.setPosition(this.pBase);
matInv.getInverse(boardMat);
if (this.boardPts && this.boardPts.length !== 0)
for (let i = 0; i < this.boardPts.length; i++)
{
let pt = getVec(this.boardPts[i]);
if (this.boardPts[i].z !== undefined)
pt.applyMatrix4(matInv);
pts.push(new Vector2(pt.x, pt.y));
buls.push(this.boardBuls[i]);
}
else
{
pts.push(new Vector2(0, 0),
new Vector2(this.width, 0),
new Vector2(this.width, this.height),
new Vector2(0, this.height),
new Vector2(0, 0)
);
buls.push(0, 0, 0, 0, 0);
}
let ext = new ExtrudeSolid();
ext.OCSNoClone.copy(boardMat);
let pl = new Polyline(pts.map((p, i) => { return { pt: p, bul: buls[i] }; }));
ext.Thickness = this.thickness;
ext.ContourCurve = pl;
if (this.SubBoardLocal.length > 0)
ext.Grooves.push(...this.SubBoardLocal.map(sub => new SimpleBoard(sub).Conver2Ext()));
return ext;
}
//创建Board实体
createBoardEntity()
{
let board = Board.CreateBoard(this.height, this.width, this.thickness, this._BoardType);
board.BoardProcessOption.roomName = this.RoomName;
board.BoardProcessOption.cabinetName = this.BoxName;
const waveMap = { 0: LinesType.Positive, 1: LinesType.CanReversal, 2: LinesType.Reverse };
board.BoardProcessOption.lines = waveMap[this.Wave];
board.BoardProcessOption.composingFace = this.PaiKong;
board.BoardProcessOption.bigHoleDir = this.HoleFace;
board.BoardProcessOption.sealedDown = this.SealedDown.toString();
board.BoardProcessOption.sealedLeft = this.SealedLeft.toString();
board.BoardProcessOption.sealedUp = this.SealedUp.toString();
board.BoardProcessOption.sealedRight = this.SealedRight.toString();
board.BoardProcessOption.color = this.Color;
board.BoardProcessOption.material = this.Material;
board.BoardProcessOption.boardName = this.MaterialName;
const bp = this.pBase.add(this.zD.clone().multiplyScalar(-this.thickness));
board.OCS = new Matrix4().makeBasis(this.xD, this.yD, this.zD).setPosition(bp);
const groove = this.Conver2Ext();
board.ContourCurve = groove.ContourCurve;
board.AppendGrooves(groove.Grooves);
let ext = this.Conver2Ext();
if (this.BoardName === "地脚线")
Object.defineProperty(ext, "UCGenerator",
{
get: function ()
{
return boardUVGenerator2;
},
});
//孔位处理
let holes: ExtrudeHole[] = [];
if (this.Drillings.length > 0)
{
let dris = this.Drillings;
for (let dri of dris)
{
let hole = JigUtils.Draw(new ExtrudeHole());
let p: Vector3;
if (dri.f === 0) //0正
p = new Vector3(dri.x, dri.y, -dri.h + this.thickness);
else //1反
p = new Vector3(dri.x, dri.y, 0);
const circle = new Circle(new Vector3(), dri.r);
circle.Position = p;
circle.ApplyMatrix(board.OCS);
hole.ContourCurve = circle;
hole.Height = dri.h;
hole.ColorIndex = 1;
holes.push(hole);
}
}
return { board, holes };
}
}

@ -5,7 +5,7 @@ import { Board } from "../../../DatabaseServices/Entity/Board";
import { ICompHardwareOption, IHardwareOption, IToplineOption } from "../../../UI/Components/RightPanel/RightPanelInterface";
import { shareViewApp } from "../ShareViewService";
import { ShareViewStore } from "../ShareViewStore";
import { GetBoxItemInfo, MaterialDetailScrollTo, SPGetSpiteSize } from "../ShareViewUtil";
import { GetBlockColor, GetBlockNo, GetBoxItemInfo, MaterialDetailScrollTo, SPGetSpiteSize } from "../ShareViewUtil";
import BoardRemarksWidget from "./BoardRemarksWidget";
interface IProps
@ -154,6 +154,8 @@ const MaterialBottomSheet: React.FC<IProps> = forwardRef((props, ref) =>
return useObserver(() =>
{
const search = new URLSearchParams(location.search);
const view_id = search.get('view_id');
return (
<div
@ -202,13 +204,14 @@ const MaterialBottomSheet: React.FC<IProps> = forwardRef((props, ref) =>
<tr>
<th style={{ width: 44 }}></th>
<th></th>
<th className="st-td-number" ></th>
<th className="st-td-number" ></th>
{!view_id && <th className="st-td-number"></th>}
<th className="st-td-number"></th>
<th className="st-td-number"></th>
<th style={{ width: 50 }} className="st-td-number"></th>
<th></th>
<th style={{ width: 44 }}></th>
</tr>
</thead>
</tr >
</thead >
<tbody>
{flagRef.current && item.boardList.length == 0 ? (
<tr>
@ -217,6 +220,8 @@ const MaterialBottomSheet: React.FC<IProps> = forwardRef((props, ref) =>
) : item.boardList.map((item: Board, i) =>
{
const size = SPGetSpiteSize(item);
const blockNo = GetBlockNo(item.Id.Index);
const color = GetBlockColor(item);
return (
<tr
className={`sp-material-list ${checkBoardHasSelected(item) ? 'active' : ''}
@ -234,10 +239,11 @@ const MaterialBottomSheet: React.FC<IProps> = forwardRef((props, ref) =>
>
<td>{i + 1}</td>
<td>{item.Name}</td>
{!view_id && <td className="st-td-number">{blockNo}</td>}
<td className="st-td-number">{size.height}</td>
<td className="st-td-number">{size.width}</td>
<td className="st-td-number">{size.thickness}</td>
<td>{item.BoardProcessOption.color}</td>
<td>{color}</td>
<td style={{ textAlign: "center", padding: 0 }}>
<BoardRemarksWidget
remarks={item.BoardProcessOption.remarks}
@ -245,11 +251,11 @@ const MaterialBottomSheet: React.FC<IProps> = forwardRef((props, ref) =>
isPhone={isPhone}
/>
</td>
</tr>
</tr >
);
})}
</tbody>
</table>
</tbody >
</table >
{
Array.isArray(item.hardwareCompositeList) && item.hardwareCompositeList.length ? (
<table className="sp-table" style={{ marginTop: 8 }}>
@ -282,12 +288,12 @@ const MaterialBottomSheet: React.FC<IProps> = forwardRef((props, ref) =>
) : null
}
{/* <div className="sp-sticky-divider"></div> */}
</div>
</div >
);
})
}
</div>
</div>
</div >
</div >
);
}
);

@ -6,13 +6,14 @@ import { resetBoxView } from '../ShareViewUtil';
import BoardHideIcon from './BoardHideIcon';
import ShareWidget from './ShareWidget';
import ThemeButton from './ThemeButton';
const search = new URLSearchParams(location.search);
const view_id = search.get('view_id');
const SideBar = () =>
{
return (
<div className="sp-side-container">
<ThemeButton />
<ShareWidget />
{view_id && <ShareWidget />}
{
[
{

Loading…
Cancel
Save