fix #IWMWU 实现简单命令反应器

pull/299/MERGE
ChenX 5 years ago
parent fe231128f9
commit 1acf79dbf3

@ -1,4 +1,4 @@
import { Vector3, Matrix4 } from 'three';
import { Matrix4, Vector3 } from 'three';
import * as xaop from 'xaop';
import { end } from 'xaop';
import { KeyCode, MouseKey } from '../Common/KeyEnum';
@ -15,6 +15,7 @@ import { RegisterGesture } from '../Editor/RegisterGesture';
import { SelectSetBase } from '../Editor/SelectBase';
import { ShowSnapMenu } from '../Editor/ShowSnapMenu';
import { Viewer } from '../GraphicsSystem/Viewer';
import { CommandReactor } from '../Reactor/CommandReactor';
import { appUi } from '../UI/Layout/ApplicationLayout';
import { DownPanelStore } from '../UI/Store/DownPanelStore';
import { HostApplicationServices } from './HostApplicationServices';
@ -28,6 +29,7 @@ export class ApplicationService
m_Database: Database;
m_Viewer: Viewer;
m_Editor: Editor;
m_CommandReactor: CommandReactor;
constructor()
{
app = this;
@ -66,7 +68,7 @@ export class ApplicationService
this.m_Viewer._GripScene.Append(obj);
}
this.m_Viewer.m_bNeedUpdate = true;
})
});
xaop.end(selectSet, selectSet.RemoveSelect, (ss: SelectSetBase) =>
{
for (let obj of ss.m_SelectList)
@ -74,25 +76,27 @@ export class ApplicationService
this.m_Viewer._GripScene.Remove(obj);
}
this.m_Viewer.m_bNeedUpdate = true;
})
});
}
xaop.end(this.m_Editor.m_SelectCtrl, this.m_Editor.m_SelectCtrl.Cancel, () =>
{
regGripEvent();
this.m_Viewer._GripScene.Clear();
this.m_Viewer.m_bNeedUpdate = true;
})
});
regGripEvent();
xaop.begin(commandMachine, commandMachine.CommandStart, () =>
{
this.m_Viewer._GripScene.visible = false;
this.m_Editor.m_SnapDragServices.HideDrawLine();
})
});
xaop.begin(commandMachine, commandMachine.CommandEnd, () =>
{
this.m_Viewer._GripScene.visible = true;
})
});
this.m_CommandReactor = new CommandReactor(this);
window["app"] = this;

@ -99,25 +99,8 @@ export class HistoricManage extends CADObject
let lastRec = this.historyRecord[this.curIndex];
if (lastRec)
{
//#region 合并子记录列表
if (this.m_SignalCommandHistory)
{
for (let rc of this.m_SignalCommandHistory.historyRecord)
{
for (let [id, hl] of rc.HistoryList)
{
for (let h of hl)
{
lastRec.WriteObjectHistoryPath(id.Object, h)
}
}
}
this.m_SignalCommandHistory.Clear();
}
//#endregion
this.MergeRecord(lastRec);
lastRec.EndCommand();
if (lastRec.HistoryList.size === 0)
{
this.historyRecord.pop();
@ -126,6 +109,46 @@ export class HistoricManage extends CADObject
}
}
/**
*
*/
get ChangeObjects(): CADObject[]
{
let lastRec = this.historyRecord[this.curIndex];
let objects: CADObject[] = [];
if (lastRec)
{
this.MergeRecord(lastRec);
for (let [id] of lastRec.HistoryList)
{
objects.push(id.Object);
}
}
return objects;
}
/**
* ,,,,.
*/
private MergeRecord(lastRec: CommandHistoryRecord)
{
if (this.m_SignalCommandHistory)
{
for (let rc of this.m_SignalCommandHistory.historyRecord)
{
for (let [id, hl] of rc.HistoryList)
{
for (let h of hl)
{
lastRec.WriteObjectHistoryPath(id.Object, h);
}
}
}
this.m_SignalCommandHistory.Clear();
}
}
HaveCommandHistory()
{
if (this.m_SignalCommandHistory)

@ -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…
Cancel
Save