mirror of https://gitee.com/cf-fz/WebCAD.git
parent
fe231128f9
commit
1acf79dbf3
@ -0,0 +1,57 @@
|
||||
import { ApplicationService } from "../ApplicationServices/Application";
|
||||
import { CADObject } from "../DatabaseServices/CADObject";
|
||||
import { begin } from "xaop";
|
||||
import { commandMachine } from "../Editor/CommandMachine";
|
||||
import { Entity } from "../DatabaseServices/Entity";
|
||||
import { CommandState } from "../Editor/CommandState";
|
||||
|
||||
type CommandEndListener = (cmdName: string, changeObjects: CADObject[], createObjects: CADObject[]) => void;
|
||||
|
||||
export class CommandReactor
|
||||
{
|
||||
private _cmdName: string;
|
||||
private _changeObjects: CADObject[] = [];
|
||||
private _createObejcts: CADObject[] = [];
|
||||
constructor(private app: ApplicationService)
|
||||
{
|
||||
begin(commandMachine, commandMachine.CommandStart, (cmdName: string) =>
|
||||
{
|
||||
this._cmdName = cmdName;
|
||||
this._createObejcts.length = 0;
|
||||
});
|
||||
|
||||
//由于创建实体的操作是修改模型空间,所以使用这个方法来得到命令创建了哪些实体
|
||||
begin(app.m_Database.ModelSpace, app.m_Database.ModelSpace.AppendEvent, (e: Entity) =>
|
||||
{
|
||||
if (CommandState.CommandIng && this._commandEndListeners.length > 0)
|
||||
this._createObejcts.push(e);
|
||||
});
|
||||
|
||||
begin(commandMachine, commandMachine.CommandEnd, (abort: boolean) =>
|
||||
{
|
||||
if (abort)
|
||||
{
|
||||
this._changeObjects.length = 0;
|
||||
this._createObejcts.length = 0;
|
||||
return;
|
||||
}
|
||||
if (this._commandEndListeners.length === 0)
|
||||
return;
|
||||
|
||||
this._changeObjects = this.app.m_Database.hm.ChangeObjects;
|
||||
|
||||
for (let listener of this._commandEndListeners)
|
||||
{
|
||||
listener(this._cmdName, this._changeObjects, this._createObejcts);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _commandEndListeners: CommandEndListener[] = [];
|
||||
|
||||
OnCommandEnd(listener: CommandEndListener)
|
||||
{
|
||||
this._commandEndListeners.push(listener);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue