!1235 性能:异步进行反应器,优化用户操作性能

pull/1235/MERGE
ChenX 4 years ago
parent 48d5d27a18
commit a761d0c471

@ -10,7 +10,7 @@ export class AutoCuttingReactor
{
const cuttingCommands = new Set(["购买模块并插入", "插入模块"]);
app.CommandReactor.OnCommandEnd((cmdName, changeObjects, createObjects) =>
app.CommandReactor.OnCommandEnd(async (cmdName, changeObjects, createObjects) =>
{
let Enable = userConfig.openAutoCuttingReactor;;
if (!Enable || !cuttingCommands.has(cmdName)) return;
@ -25,10 +25,10 @@ export class AutoCuttingReactor
}
if (brs.length > 0)
this.StartReactor(brs);
await this.StartReactor(brs);
});
}
StartReactor(ents: Board[])
async StartReactor(ents: Board[])
{
let brs: Board[] = [];
for (let ent of app.Database.ModelSpace.Entitys)
@ -37,14 +37,14 @@ export class AutoCuttingReactor
brs.push(ent);
}
CuttingBoardByBoard(brs, ents);
await CuttingBoardByBoard(brs, ents);
}
}
/**
*
*/
export function AutoCutting(isRelevance: boolean)
export async function AutoCutting(isRelevance: boolean)
{
let knifBoards = app.CommandReactor._createObejcts.filter(o => !o.IsErase && o instanceof Board) as Board[];
let meatBoards: Board[] = [];
@ -53,5 +53,5 @@ export function AutoCutting(isRelevance: boolean)
if (!ent.IsErase && ent instanceof Board && !knifBoards.includes(ent))
meatBoards.push(ent);
}
CuttingBoardByBoard(meatBoards, knifBoards, isRelevance);
await CuttingBoardByBoard(meatBoards, knifBoards, isRelevance);
}

@ -6,12 +6,20 @@ import { Board } from "../../DatabaseServices/Entity/Board";
import { ExtrudeSolid } from "../../DatabaseServices/Entity/Extrude";
import { HardwareCompositeEntity } from "../../DatabaseServices/Hardware/HardwareCompositeEntity";
import { Box3Ext } from "../../Geometry/Box";
// import { DownPanelStore } from "../../UI/Store/DownPanelStore";
import { DownPanelStore } from "../../UI/Store/DownPanelStore";
export function CuttingBoardByBoard(meats: Board[], knifs: Board[], isRelevance = true)
export async function CuttingBoardByBoard(meats: Board[], knifs: Board[], isRelevance = true): Promise<void>
{
for (let br of meats)
// //进度条
// let down = DownPanelStore.GetInstance() as DownPanelStore;
// down.StartProgress("切割1:");
for (let i = 0; i < meats.length; i++)
{
// down.progress = Math.max(0.1, i / meats.length);
let br = meats[i];
//用于校验是否已经关联切割
let knifIds = new Set<number>();
for (let id of br.RelevanceKnifs)
@ -56,9 +64,11 @@ export function CuttingBoardByBoard(meats: Board[], knifs: Board[], isRelevance
Log("自动非关联切割失败!");
}
}
// down.EndProgress();
}
export function CuttingBoardByHardware(meats: Board[], hardwares: HardwareCompositeEntity[])
export async function CuttingBoardByHardware(meats: Board[], hardwares: HardwareCompositeEntity[]): Promise<void>
{
let knifeIdMap = new WeakMap<ExtrudeSolid, HardwareCompositeEntity>();
let hardwareEnts: ExtrudeSolid[] = [];
@ -79,15 +89,16 @@ export function CuttingBoardByHardware(meats: Board[], hardwares: HardwareCompos
}
}
// 因为我们现在的代码不是异步的,所以现在我们增加进度条还没有意义
// //进度条
// let down = DownPanelStore.GetInstance() as DownPanelStore;
// down.progressName = "切割(关联):";
// down.progress = 0.1;
// down.StartProgress("切割2:");
for (let i = 0; i < meats.length; i++)
try
{
let br = meats[i];
let auBak = br.AutoUpdate;
br.AutoUpdate = false;
// down.progress = Math.max(0.1, i / meats.length);
//用于校验是否已经关联切割
@ -118,11 +129,14 @@ export function CuttingBoardByHardware(meats: Board[], hardwares: HardwareCompos
tempBr = undefined;
}
}
br.AutoUpdate = auBak;
br.DeferUpdate();
}
catch (error)
{
Log("自动关联切割失败!");
}
// down.progressName = "";
// down.EndProgress();
}

@ -11,7 +11,7 @@ export class HardwareCuttingReactor
{
const hardwareCmds = ["购买模块并插入", "插入模块", CommandNames.Door, CommandNames.Drawer];
app.CommandReactor.OnCommandEnd((cmdName, changeObjects, createObjects) =>
app.CommandReactor.OnCommandEnd(async (cmdName, changeObjects, createObjects) =>
{
if (app.Viewer.isLayout) return;
if (!this.EnableHardware && !hardwareCmds.includes(cmdName)) return;
@ -30,10 +30,10 @@ export class HardwareCuttingReactor
}
if (hardwares.length > 0)
this.StartReactor(hardwares, brs);
await this.StartReactor(hardwares, brs);
});
}
StartReactor(hardwares: HardwareCompositeEntity[], ents: Board[])
async StartReactor(hardwares: HardwareCompositeEntity[], ents: Board[])
{
let brs: Board[] = [];
for (let ent of app.Database.ModelSpace.Entitys)
@ -41,6 +41,6 @@ export class HardwareCuttingReactor
if (!ent.IsErase && ent instanceof Board && !ents.includes(ent))
brs.push(ent);
}
CuttingBoardByHardware(brs, hardwares);
await CuttingBoardByHardware(brs, hardwares);
}
}

@ -6,6 +6,7 @@ import { HardwareCompositeEntity } from "../../DatabaseServices/Hardware/Hardwar
import { ExtrudeSolid } from "../../DatabaseServices/Entity/Extrude";
import { ExtrudeHole } from "../../DatabaseServices/3DSolid/ExtrudeHole";
import { CuttingBoardByBoard, CuttingBoardByHardware } from "./CuttingUtils2";
import { Sleep } from "../../Common/Sleep";
export class NonAssociativeCutting implements Command
@ -82,8 +83,8 @@ export class NonAssociativeCutting implements Command
if (isRelevanceCut)
{
CuttingBoardByBoard(meatsBrs, brKnifes);
CuttingBoardByHardware(meatsBrs, hardwareKfs);
await CuttingBoardByBoard(meatsBrs, brKnifes);
await CuttingBoardByHardware(meatsBrs, hardwareKfs);
}
else
{
@ -102,8 +103,15 @@ export class NonAssociativeCutting implements Command
let knifes = [...hardwareEnts, ...brKnifes];
let i = 0;
for (let br of meatsBrs)
{
br.Subtract(knifes);
i++;
if (i % 20 === 0)
await Sleep(0);
}
}
}
}

@ -10,12 +10,12 @@ import { Hole } from "../DatabaseServices/3DSolid/Hole";
import { CylinderHole, GangDrillType } from "../DatabaseServices/3DSolid/CylinderHole";
import { Box3Ext } from "../Geometry/Box";
const drillTool = DrawDrillingTool.GetInstance() as DrawDrillingTool;
export class CheckHoles implements Command
{
async exec()
{
const drillTool = DrawDrillingTool.GetInstance() as DrawDrillingTool;
let brRes = await app.Editor.GetSelection({
Msg: "选择要检查排钻碰撞的板件",
Filter: { filterTypes: [Board] }
@ -111,6 +111,8 @@ export class CheckHoles implements Command
}
private IsCollsion(boxlist: Box3Ext[][], boxlist2: Box3Ext[][])
{
const drillTool = DrawDrillingTool.GetInstance() as DrawDrillingTool;
for (let boxs of boxlist)
{
for (let boxs2 of boxlist2)

@ -1,6 +1,7 @@
import { app } from '../ApplicationServices/Application';
import { arrayRemoveIf } from '../Common/ArrayExt';
import { Log } from '../Common/Log';
import { Sleep } from '../Common/Sleep';
import { UpdateDraw } from '../Common/Status';
import { CylinderHole, GangDrillType } from '../DatabaseServices/3DSolid/CylinderHole';
import { ExtrudeHole } from '../DatabaseServices/3DSolid/ExtrudeHole';
@ -11,6 +12,7 @@ import { Command } from '../Editor/CommandMachine';
import { JigUtils } from '../Editor/JigUtils';
import { PromptStatus } from '../Editor/PromptResult';
import { MoveMatrix } from '../Geometry/GeUtils';
import { UpdateEntityDrawTask } from './UpdateEntityDrawTask';
export class Command_Copy implements Command
{
@ -71,7 +73,8 @@ export class Command_Copy implements Command
{
let moveM = MoveMatrix(p.clone().sub(ptLast));
ptLast.copy(p);
jigEns.forEach(e => e.ApplyMatrix(moveM));
for (let e of jigEns)
e.ApplyMatrix(moveM);
},
BasePoint: ptRes.Point,
AllowDrawRubberBand: true
@ -80,6 +83,7 @@ export class Command_Copy implements Command
if (ptRes2.Status === PromptStatus.OK)
{
let moveM = MoveMatrix(ptRes2.Point.sub(ptBase));
await Sleep(0);
let cloneEns = app.Database.DeepCloneObjects(orgEns, app.Viewer.isLayout ? app.Database.LayoutSpace : app.Database.ModelSpace) as Entity[];
let set = new Set(cloneEns);
@ -121,16 +125,20 @@ export class Command_Copy implements Command
en.RestoreJigMaterial();
en.ApplyMatrix(moveM);
en.NeedUpdateFlag = UpdateDraw.None;
en.AutoUpdate = updateBak;
}
for (let e of cloneEns)
{
e.NeedUpdateFlag = UpdateDraw.Matrix;
e.DeferUpdate();
}
//这里我们不等待它,而是继续让用户拷贝
if (this.UpdateTask) this.UpdateTask.Stop();
this.UpdateTask = new UpdateEntityDrawTask(cloneEns);
}
else
break;
}
this.UpdateTask = undefined;
}
UpdateTask: UpdateEntityDrawTask;
}

@ -42,7 +42,7 @@ export abstract class DrawBoardTool implements Command
{
await this.SelectAndBuildBoard();
if (this.store.autoCutOption.isAutoCut)
AutoCutting(this.store.autoCutOption.isRelevance);
await AutoCutting(this.store.autoCutOption.isRelevance);
};
private async SelectAndBuildBoard()
{

@ -106,7 +106,7 @@ export class DrawClosingStrip implements Command
AppToaster.clear();
if (this.store.autoCutOption.isAutoCut)
AutoCutting(this.store.autoCutOption.isRelevance);
await AutoCutting(this.store.autoCutOption.isRelevance);
}
}
//构建收口条,更新总空间

@ -62,7 +62,7 @@ export class DrawDoor implements Command
await tool.Draw();
if (store.autoCutOption.isAutoCut)
AutoCutting(store.autoCutOption.isRelevance);
await AutoCutting(store.autoCutOption.isRelevance);
}
}
}

@ -29,7 +29,7 @@ export class DrawLeftRight implements Command
else
await this.InsertByPoint();
if (store.autoCutOption.isAutoCut)
AutoCutting(store.autoCutOption.isRelevance);
await AutoCutting(store.autoCutOption.isRelevance);
});
}
private GetLRBoards()

@ -45,7 +45,7 @@ export class DrawSingleBoard implements Command
app.Database.ModelSpace.Append(board);
if (store.autoCutOption.isAutoCut)
AutoCutting(store.autoCutOption.isRelevance);
await AutoCutting(store.autoCutOption.isRelevance);
}
});
}

@ -48,7 +48,7 @@ export class DrawTopBottomBoard implements Command
await SetTemplatePositionAndSetParent(selectSpace.SpaceParse, temp);
if (store.autoCutOption.isAutoCut)
AutoCutting(store.autoCutOption.isRelevance);
await AutoCutting(store.autoCutOption.isRelevance);
}
}
}

@ -1,4 +1,5 @@
import { app } from "../../ApplicationServices/Application";
import { FixedNotZero } from "../../Common/Utils";
import { TemplateBehindBoard } from "../../DatabaseServices/Template/ProgramTempate/TemplateBehindBoard";
import { TemplateBoardRecord } from "../../DatabaseServices/Template/ProgramTempate/TemplateBoard";
import { TemplateLayerBoard } from "../../DatabaseServices/Template/ProgramTempate/TemplateLayerBoard";
@ -12,8 +13,6 @@ import { BoardModal, BoardModalType } from "../../UI/Components/Board/BoardModal
import { IConfigOption } from "../../UI/Components/Board/UserConfig";
import { BoardConfigOption, SideBoardOption } from "../../UI/Store/BoardInterface";
import { BehindBoardStore, BoardStore, LayerBoardStore, SideBoardStore, TopBottomBoardStore, VerticalBoardStore } from "../../UI/Store/BoardStore";
import { FixedNotZero } from "../../Common/Utils";
import { AutoCutting } from "../BoardCutting/AutoCuttingReactor";
export class EditorBoardTemplate implements Command
{

@ -22,6 +22,6 @@ export class DrawDrilling implements Command
const tool = DrawDrillingTool.GetInstance() as DrawDrillingTool;
tool.ClassifyAndDrilling(ens);
await tool.ClassifyAndDrilling(ens);
}
}

@ -1,36 +1,38 @@
import { Intent } from "@blueprintjs/core";
import { observable } from "mobx";
import { Box3, Matrix4, Vector3 } from "three";
import { begin } from "xaop";
import { app } from "../../ApplicationServices/Application";
import { appCache } from "../../Common/AppCache";
import { arrayLast, arrayRemoveIf } from "../../Common/ArrayExt";
import { EBoardKeyList } from "../../Common/BoardKeyList";
import { safeEval } from "../../Common/eval";
import { Log } from "../../Common/Log";
import { Singleton } from "../../Common/Singleton";
import { Sleep } from "../../Common/Sleep";
import { StoreageKeys } from "../../Common/StoreageKeys";
import { FixedNotZero } from "../../Common/Utils";
import { CylinderHole, GangDrillType } from "../../DatabaseServices/3DSolid/CylinderHole";
import { ExtrudeHole } from "../../DatabaseServices/3DSolid/ExtrudeHole";
import { Hole } from "../../DatabaseServices/3DSolid/Hole";
import { Contour } from "../../DatabaseServices/Contour";
import { Board } from "../../DatabaseServices/Entity/Board";
import { Entity } from "../../DatabaseServices/Entity/Entity";
import { ExtrudeSolid } from "../../DatabaseServices/Entity/Extrude";
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
import { GroupRecord } from "../../DatabaseServices/GroupTableRecord";
import { ObjectId } from "../../DatabaseServices/ObjectId";
import { IsPointInPolyLine } from "../../DatabaseServices/PointInPolyline";
import { Shape } from "../../DatabaseServices/Shape";
import { userConfig } from "../../Editor/UserConfig";
import { Box3Ext } from "../../Geometry/Box";
import { CollisionDetection } from "../../Geometry/DrillParse/CollisionDetection";
import { Face } from "../../Geometry/DrillParse/Face";
import { equaln, MoveMatrix, ZAxis, isParallelTo, YAxis } from "../../Geometry/GeUtils";
import { equaln, isParallelTo, MoveMatrix, YAxis, ZAxis } from "../../Geometry/GeUtils";
import { AppToaster } from "../../UI/Components/Toaster";
import { FaceDirection } from "../../UI/Store/BoardInterface";
import { DownPanelStore } from "../../UI/Store/DownPanelStore";
import { DrillingOption, SpacingType } from "../../UI/Store/drillInterface";
import { appCache } from "../../Common/AppCache";
import { StoreageKeys } from "../../Common/StoreageKeys";
import { Entity } from "../../DatabaseServices/Entity/Entity";
import { Box3Ext } from "../../Geometry/Box";
import { ExtrudeHole } from "../../DatabaseServices/3DSolid/ExtrudeHole";
import { Hole } from "../../DatabaseServices/3DSolid/Hole";
import { ExtrudeSolid } from "../../DatabaseServices/Entity/Extrude";
import { Shape } from "../../DatabaseServices/Shape";
import { Contour } from "../../DatabaseServices/Contour";
import { observable } from "mobx";
import { Log } from "../../Common/Log";
import { AppToaster } from "../../UI/Components/Toaster";
import { Intent } from "@blueprintjs/core";
export class DrawDrillingTool extends Singleton
{
@ -764,9 +766,9 @@ export class DrawDrillingTool extends Singleton
}
}
}
private StartGangDrill(brs: Board[])
private async StartGangDrill(brs: Board[]): Promise<void>
{
let checkRes = new CollisionDetection(this.GetSpliteBoards(brs));
let checkRes = new CollisionDetection(await this.GetSpliteBoards(brs));
//清理掉已经存在的排钻
this.ClearExitDrilling(brs);
@ -826,7 +828,7 @@ export class DrawDrillingTool extends Singleton
}
}
/**分类并排钻 */
ClassifyAndDrilling(brList: Board[] | Set<Board>)
async ClassifyAndDrilling(brList: Board[] | Set<Board>): Promise<void>
{
if (brList instanceof Set)
{
@ -839,7 +841,9 @@ export class DrawDrillingTool extends Singleton
for (let [, bs] of brMap)
{
if (bs.length > 1)
this.StartGangDrill(bs);
await this.StartGangDrill(bs);
await Sleep(0);
}
// if (this._collsionFaces.length > 0)
@ -851,15 +855,28 @@ export class DrawDrillingTool extends Singleton
intent: Intent.WARNING,
}, "holecollsion");
}
private GetSpliteBoards(brs: Board[])
private async GetSpliteBoards(brs: Board[])
{
//进度条
let down = DownPanelStore.GetInstance() as DownPanelStore;
down.StartProgress("分裂:");
let brList: Board[] = [];
let i = 0;
for (let e of brs)
{
let bs = e.SplitBoards;
bs.forEach(b => b.TempData = e.TempData);
brList.push(...bs);
i++;
if (i % 30 === 0)
{
down.progress = Math.max(0.1, i / brs.length);
await Sleep(0);
}
}
down.EndProgress();
return brList;
}
DrillIsCollsion(b1: Box3Ext, b2: Box3Ext)

@ -20,7 +20,7 @@ export class DrillingReactor
Enable = true;
constructor()
{
app.CommandReactor.OnCommandEnd((cmdName: string, changeObjects, createObjects) =>
app.CommandReactor.OnCommandEnd(async (cmdName: string, changeObjects, createObjects) =>
{
if (app.Viewer.isLayout) return;
@ -86,7 +86,7 @@ export class DrillingReactor
}
}
}
this.StartReactor(brs);
await this.StartReactor(brs);
app.Editor.UpdateScreen();
});
}
@ -113,7 +113,7 @@ export class DrillingReactor
return retBrs;
}
StartReactor(brs: Set<Board>)
async StartReactor(brs: Set<Board>)
{
if (brs.size === 0) return;
let sbs = this.GetSurroundBoards(brs);
@ -124,7 +124,7 @@ export class DrillingReactor
}
const tool = DrawDrillingTool.GetInstance() as DrawDrillingTool;
tool.ClassifyAndDrilling(brs);
await tool.ClassifyAndDrilling(brs);
for (let br of brs)
{

@ -1,13 +1,14 @@
import { app } from "../ApplicationServices/Application";
import { Sleep } from "../Common/Sleep";
import { GetEntity } from "../Common/Utils";
import { Board } from "../DatabaseServices/Entity/Board";
import { Entity } from "../DatabaseServices/Entity/Entity";
import { HardwareCompositeEntity } from "../DatabaseServices/Hardware/HardwareCompositeEntity";
import { Light } from "../DatabaseServices/Lights/Light";
import { TemplateRecord } from "../DatabaseServices/Template/TemplateRecord";
import { Command } from "../Editor/CommandMachine";
import { SelectSetBase } from "../Editor/SelectBase";
import { Board } from "../DatabaseServices/Entity/Board";
import { BoardOpenDir } from "../UI/Store/BoardInterface";
import { HardwareCompositeEntity } from "../DatabaseServices/Hardware/HardwareCompositeEntity";
import { GetEntity } from "../Common/Utils";
export class Command_HideSelected implements Command
{
@ -41,10 +42,14 @@ export class Command_ShowAll implements Command
return;
}
app.Database.ModelSpace.Entitys.forEach(o =>
let i = 0;
for (let en of app.Database.ModelSpace.Entitys)
{
o.Visible = true;
});
en.Visible = true;
i++;
if (i % 10 === 0)
await Sleep(0);
}
}
}

@ -162,7 +162,7 @@ export class Command_KJLImport implements Command
allBrs.push(br);
}
CuttingBoardByBoard(allBrs, bbrs);
await CuttingBoardByBoard(allBrs, bbrs);
}
return !ok;

@ -1,12 +1,10 @@
import { Matrix4 } from 'three';
import { app } from '../ApplicationServices/Application';
import { CylinderHole, GangDrillType } from '../DatabaseServices/3DSolid/CylinderHole';
import { Board } from '../DatabaseServices/Entity/Board';
import { Command } from '../Editor/CommandMachine';
import { JigUtils } from '../Editor/JigUtils';
import { PromptStatus } from '../Editor/PromptResult';
import { CylinderHole, GangDrillType } from '../DatabaseServices/3DSolid/CylinderHole';
import { Board } from '../DatabaseServices/Entity/Board';
import { Text } from '../DatabaseServices/Text/Text';
import { UpdateDraw } from '../Common/Status';
export class Command_Move implements Command
{
@ -48,6 +46,7 @@ export class Command_Move implements Command
AllowDrawRubberBand: true
});
if (ptRes.Status === PromptStatus.OK)
{
moveMatrix.setPosition(ptRes.Point.clone().sub(ptBase));
@ -80,5 +79,6 @@ export class Command_Move implements Command
en.ApplyMatrix(moveMatrix);
}
}
}
}

@ -6,6 +6,7 @@ import { Command } from '../Editor/CommandMachine';
import { JigUtils } from '../Editor/JigUtils';
import { PromptStatus } from '../Editor/PromptResult';
import { ZAxis } from '../Geometry/GeUtils';
import { UpdateEntityDrawTask } from './UpdateEntityDrawTask';
export class Command_Rotate implements Command
{
@ -80,19 +81,21 @@ export class Command_Rotate implements Command
else
break;
}
this.UpdateTask = undefined;//记得回收它
}
UpdateTask: UpdateEntityDrawTask;
Update(basePt: Vector3, an: number, ens: Entity[], isCopy = false, resetUpdate = false)
{
let moveMat = new Matrix4().setPosition(basePt);
let moveMatInv = new Matrix4().getInverse(moveMat);
let roMat = new Matrix4()
.makeRotationAxis(ZAxis.clone().applyMatrix4(app.Editor.UCSMatrix), MathUtils.degToRad(an));
let roMat = new Matrix4().makeRotationAxis(ZAxis.clone().applyMatrix4(app.Editor.UCSMatrix), MathUtils.degToRad(an));
let mtx = moveMat.multiply(roMat).multiply(moveMatInv);
for (let en of ens)
{
en.ApplyMatrix(mtx);
en.NeedUpdateFlag = UpdateDraw.Matrix;
en.DeferUpdate();
en.NeedUpdateFlag = UpdateDraw.None;
if (isCopy)
app.Database.ModelSpace.Append(en);
@ -100,5 +103,10 @@ export class Command_Rotate implements Command
if (resetUpdate)
en.AutoUpdate = true;
}
if (this.UpdateTask)
this.UpdateTask.Stop();
this.UpdateTask = new UpdateEntityDrawTask(ens);
}
}

@ -83,7 +83,7 @@ export class TemplateSearchDialog extends React.Component<{ url: string; }, {}>{
nens.forEach(en => en.ApplyMatrix(MoveMatrix(ptRes.Point.clone().sub(pos))));
}
if (this.autoCutOption.isAutoCut)
AutoCutting(this.autoCutOption.isRelevance);
await AutoCutting(this.autoCutOption.isRelevance);
app.Editor.ModalManage.ToggleShow();
app.Editor.MaskManage.ShowMask();

@ -0,0 +1,46 @@
import { app } from '../ApplicationServices/Application';
import { Sleep } from '../Common/Sleep';
import { UpdateDraw } from '../Common/Status';
import { Entity } from '../DatabaseServices/Entity/Entity';
import { DownPanelStore } from '../UI/Store/DownPanelStore';
export class UpdateEntityDrawTask
{
private stop = false;
constructor(entitys: Entity[])
{
this.UpdateDraw(entitys);
}
Stop() { this.stop = true; }
async UpdateDraw(ens: Entity[])
{
let down = DownPanelStore.GetInstance() as DownPanelStore;
down.StartProgress("渲染:");
let i = 0;
for (let e of ens)
{
down.progress = Math.max(0.1, i / ens.length);
if (this.stop)
break;
e.NeedUpdateFlag = e.NeedUpdateFlag || UpdateDraw.Matrix;
e.DeferUpdate();
i++;
if (i % 20 === 0)
await Sleep(0);
if (i % 50 === 0)
app.Editor.UpdateScreen();
}
down.EndProgress();
app.Editor.UpdateScreen();
}
}

@ -135,10 +135,6 @@ export class ApplicationService
this.Viewer.GripScene.visible = false;
this.Editor.SnapDragServices.HideDrawLine();
});
begin(commandMachine, commandMachine.CommandEnd, () =>
{
this.Viewer.GripScene.visible = true;
});
//显示撤销重做命令
end(this.Database.hm, this.Database.hm.UndoEvent, (cmdName: string) =>

@ -232,6 +232,7 @@ export class Board extends ExtrudeSolid
}
return false;
}
protected GetRelevanceKnifes(knifs: ExtrudeSolid[])
{
super.GetRelevanceKnifes(knifs);
@ -270,40 +271,12 @@ export class Board extends ExtrudeSolid
this.RelativeHardware.length = 0;
super.ClearRelevance(en);
}
get SplitBoards()
{
let knifs: ExtrudeSolid[] = [];
this.GetRelevanceKnifes(knifs);
if (knifs.length > 0)
{
let tempExtrude = this.Clone();
let output: Board[] = [tempExtrude];
let ok = tempExtrude.Subtract(knifs, output);
if (ok)
{
if (output.length === 1)
{
//拆单,bbs时读取id
tempExtrude.objectId = this.objectId;
tempExtrude.__OriginalEnt__ = this;
return [tempExtrude];
}
else
{
for (let i = 0; i < output.length; i++)
{
output[i].AppendGrooves(tempExtrude.grooves);
output[i].objectId = new ObjectId(this.Id.Index * -100 - i);
output[i].__OriginalEnt__ = this;
}
return output;
}
}
}
return [this];
return this.SplitExtrudes;
}
get BoardModeling()
{
let models: IModeling[] = [];

@ -1471,7 +1471,14 @@ export class ExtrudeSolid extends Entity
return false;
}
//缓存当前被关联切割后的体积,如果体积有变化,证明多了拉槽或者少了拉槽
__CacheVolume__: number;
//每当我们去计算关联拉槽的时候,总会有这个分裂的图形数组,如果我们需要,我们也可以复用它去拆单,或者去排钻
__CacheSplitExtrudes: this[];
/**
* ,(MeshGeometryEdgeGeometry)
*/
private CalcRelevanceGroove()
{
//避免Jig实体更新,导致性能暴跌.
@ -1493,6 +1500,7 @@ export class ExtrudeSolid extends Entity
tempExtrude.__OriginalId__ = this.Id;//在读取文件时不打印日志
let output: ExtrudeSolid[] = [tempExtrude];
let ok = tempExtrude.Subtract(knifs, output);
this.__CacheSplitExtrudes = output as this[];
if (ok)
{
this.__CacheVolume__ = tempExtrude.Volume;
@ -1544,10 +1552,41 @@ export class ExtrudeSolid extends Entity
!equaln(this.__CacheVolume__, this.Volume)
)
Log(`${this.Name}(${this.Id.Index})关联槽已逃离或者被清除!`);
this.__CacheSplitExtrudes = [this];
this.__CacheVolume__ = undefined;
}
}
/**
* ,,
*/
get SplitExtrudes(): this[]
{
if (this.NeedUpdateRelevanceGroove)
this.Update(UpdateDraw.Geometry);//我们先直接更新绘制
if (this.NeedUpdateRelevanceGroove)//如果更新失败,那么我们更新这个槽(似乎也证明了我们没有绘制实体)
this.CalcRelevanceGroove();//注意,这也将更新绘制的实体(EdgeGeo,MeshGeo)(如果拆单也用这个,可能会带来性能损耗)
//我们加入一些拓展信息,以便排钻能够使用(或者其他的,比如发送到效果图?,BBS)
if (this.__CacheSplitExtrudes.length === 1)
{
//拆单,bbs时读取id
this.__CacheSplitExtrudes[0].objectId = this.objectId;
this.__CacheSplitExtrudes[0].__OriginalEnt__ = this;
}
else
{
for (let i = 0; i < this.__CacheSplitExtrudes.length; i++)
{
this.__CacheSplitExtrudes[i].objectId = new ObjectId(this.Id.Index * -100 - i);
this.__CacheSplitExtrudes[i].__OriginalEnt__ = this;
}
}
return this.__CacheSplitExtrudes;
}
protected GetRelevanceKnifes(knifs: ExtrudeSolid[])
{
for (let e of this.RelevanceKnifs)
@ -1571,7 +1610,6 @@ export class ExtrudeSolid extends Entity
arrayRemoveIf(this.RelevanceMeats, id => !id?.Object || id.Index === en.Id.Index);
if (oldLen !== this.RelevanceMeats.length)
arrayRemoveIf(en.RelevanceKnifs, id => !id?.Object || id.Index === this.Id.Index);
}
else
{

@ -67,7 +67,7 @@ class CommandMachine
ReportError(error.stack, `命令:${cmdName}`);
app.Editor.Prompt("抱歉,命令造成了错误,请联系开发人员.");
}
this.CommandEnd(abort, cmd.NoHistory);
await this.CommandEnd(abort, cmd.NoHistory);
}
else
app.Editor.Prompt('未知命令!');
@ -119,16 +119,19 @@ class CommandMachine
* ,,
* @param [abort] .
*/
CommandEnd(abort: boolean = false, noHistory = false)
async CommandEnd(abort: boolean = false, noHistory = false)
{
//先把Jig实体清除了,避免残影
JigUtils.End();
let hasHistory = !noHistory && app.Database.hm.CurrentHasHistory();
//先执行反应器
this.CommandEndEvent(!abort && hasHistory);
await app.CommandReactor.CommandEndReactor(!abort && hasHistory);
//还原状态
CommandState.CommandIng = false;
app.Viewer.GripScene.visible = true;
app.Viewer.GripScene.UpdateAll();
JigUtils.End();
app.Editor.UpdateScreen();
//在结束命令记录
@ -147,11 +150,6 @@ class CommandMachine
}
}
CommandEndEvent(hasRecord: boolean)
{
}
get CommandNameList(): Set<string>
{
return this._CommandNameList;
@ -178,5 +176,5 @@ export async function CommandWrap(exec: Function, cmdName: string = "")
ReportError(error.stack, `命令标识:${cmdName}`);
app.Editor.Prompt("抱歉,命令造成了错误,请联系开发人员.");
}
commandMachine.CommandEnd(abort);
await commandMachine.CommandEnd(abort);
}

@ -7,7 +7,7 @@ import { Entity } from "../DatabaseServices/Entity/Entity";
import { commandMachine } from "../Editor/CommandMachine";
import { CommandState } from "../Editor/CommandState";
type CommandEndListener = (cmdName: string, changeObjects: CADObject[], createObjects: CADObject[]) => void;
type CommandEndListener = (cmdName: string, changeObjects: CADObject[], createObjects: CADObject[]) => void | Promise<void>;
export class CommandReactor
{
@ -33,39 +33,40 @@ export class CommandReactor
if (CommandState.CommandIng && this._commandEndListeners.length > 0)
this._createObejcts.push(e);
});
}
begin(commandMachine, commandMachine.CommandEndEvent, (hasRecord: boolean) =>
{
if (this._commandEndListeners.length === 0)
return;
async CommandEndReactor(hasRecord: boolean)
{
if (this._commandEndListeners.length === 0)
return;
for (let listener of this._commandEndListeners)
for (let listener of this._commandEndListeners)
{
try
{
try
if (hasRecord)
{
if (hasRecord)
{
//反应器可能相互影响,所以不缓存这个
let changeObjects = this.app.Database.hm.ChangeObjects;
for (let obj of this._createObejcts)
changeObjects.delete(obj);
listener(this._cmdName, [...changeObjects], this._createObejcts);
}
else
{
listener(this._cmdName, [], []);
}
//反应器可能相互影响,所以不缓存这个
let changeObjects = this.app.Database.hm.ChangeObjects;
for (let obj of this._createObejcts)
changeObjects.delete(obj);
await listener(this._cmdName, [...changeObjects], this._createObejcts);
}
catch (error)
else
{
ReportError(error.stack, "命令反应器发生错误!");
await listener(this._cmdName, [], []);
}
}
});
catch (error)
{
ReportError(error.stack, "命令反应器发生错误!");
}
}
}
private _commandEndListeners: CommandEndListener[] = [];
//注入:在命令结束时运行函数
OnCommandEnd(listener: CommandEndListener): Function
{
this._commandEndListeners.push(listener);

@ -1,51 +1,76 @@
import { ApplicationService } from "../ApplicationServices/Application";
import { Board } from "../DatabaseServices/Entity/Board";
import { end } from "xaop";
import { app, ApplicationService } from "../ApplicationServices/Application";
import { Sleep } from "../Common/Sleep";
import { CADObject } from "../DatabaseServices/CADObject";
import { CommandHistoryRecord } from "../DatabaseServices/CommandHistoryRecord";
import { RemoveObjectData } from "../DatabaseServices/RemoveObjectData";
import { CreateObjectData } from "../DatabaseServices/CreateObjectData";
import { Board } from "../DatabaseServices/Entity/Board";
import { Entity } from "../DatabaseServices/Entity/Entity";
import { end } from "xaop";
import { ExtrudeSolid } from "../DatabaseServices/Entity/Extrude";
import { CADObject } from "../DatabaseServices/CADObject";
import { HardwareCompositeEntity } from "../DatabaseServices/Hardware/HardwareCompositeEntity";
import { ObjectId } from "../DatabaseServices/ObjectId";
import { RemoveObjectData } from "../DatabaseServices/RemoveObjectData";
import { DownPanelStore } from "../UI/Store/DownPanelStore";
function UpdateRelevanceGroove(ents: CADObject[])
//更新关联拉槽的绘制
async function UpdateRelevanceGroove(ents: CADObject[])
{
let needUpdateBoardSet = new Set<ObjectId>();
for (let e of ents)
for (let i = 0; i < ents.length; i++)
{
let e = ents[i];
if (e instanceof Board)
{
e.RelevanceMeats.forEach(id => needUpdateBoardSet.add(id));
for (let id of e.RelevanceMeats)
needUpdateBoardSet.add(id);
needUpdateBoardSet.add(e.Id);//修改逻辑,该实体可能被添加新的关联切割,所以没有更新槽
}
else if (e instanceof HardwareCompositeEntity)
{
e.RelevanceBoards.forEach(id => needUpdateBoardSet.add(id));
for (let id of e.RelevanceBoards)
needUpdateBoardSet.add(id);
}
}
//进度条
let down = DownPanelStore.GetInstance() as DownPanelStore;
down.StartProgress("更新:");
let allCount = needUpdateBoardSet.size;
let i = -1;
for (let id of needUpdateBoardSet)
{
i++;
if (!id || id.IsErase) continue;
let br = id.Object as ExtrudeSolid;
if (br.NeedUpdateRelevanceGroove)
br.Update();
if (i % 30 === 0)
{
down.progress = Math.max(0.1, i / allCount);
await Sleep(0);
}
}
app.Editor.UpdateScreen();
down.EndProgress();
}
export class RelevanceCuttingReactor
{
constructor(private app: ApplicationService)
{
app.CommandReactor.OnCommandEnd((cmdName, changeObjects, createObjects) =>
app.CommandReactor.OnCommandEnd(async (cmdName, changeObjects, createObjects) =>
{
if (app.Viewer.isLayout) return;
//不等待这个,因为这个方法不需要改变实体,只需要改变绘制
UpdateRelevanceGroove([...changeObjects, ...createObjects]);
});
end(app.Database.hm, app.Database.hm.RedoEvent, (cmdName: string, historyRec: CommandHistoryRecord) =>
end(app.Database.hm, app.Database.hm.RedoEvent, async (cmdName: string, historyRec: CommandHistoryRecord) =>
{
let createEntitys: Entity[] = [];
let changeEntitys: Entity[] = [];
@ -84,7 +109,7 @@ export class RelevanceCuttingReactor
}
}
}
//不等待这个,因为这个方法不需要改变实体,只需要改变绘制
UpdateRelevanceGroove([...changeEntitys, ...createEntitys, ...deleteEntitys]);
});
@ -127,7 +152,7 @@ export class RelevanceCuttingReactor
}
}
}
//不等待这个,因为这个方法不需要改变实体,只需要改变绘制
UpdateRelevanceGroove([...changeEntitys, ...createEntitys, ...deleteEntitys]);
});
}

@ -271,7 +271,7 @@ export class TemplateManage extends React.Component<ITemplateManage, {}> {
await this.handleInsertBySpace();
if (this.autoCutOption.isAutoCut)
AutoCutting(this.autoCutOption.isRelevance);
await AutoCutting(this.autoCutOption.isRelevance);
}, "插入模块");
this.option.cabName = this.option.originCabName + (++this.option.cabIndex);
app.Editor.ModalManage.ToggleShow();

@ -237,4 +237,16 @@ export class DownPanelStore extends Singleton
}
}
}
@action StartProgress(name = "", progress = 0.1)
{
this.progressName = name;
this.progress = progress;
}
@action EndProgress()
{
this.progress = 1;
this.progressName = "";
}
}

Loading…
Cancel
Save