!180 命令局部撤销

Merge pull request !180 from ChenX/hsMark
pull/180/MERGE
ChenX 6 years ago
parent b1a9d3f3d5
commit 1157d84f87

@ -82,6 +82,8 @@ export class Command_Array implements Command
//鼠标点选
while (true)
{
app.m_Database.hm.StartMark();
let state = await app.m_Editor.m_ModalManage.Wait();
if (state === ModalState.Cancel)
return;

@ -21,6 +21,7 @@ export class Command_Break implements Command
while (true)
{
app.m_Database.hm.StartMark();
let ptRes = await app.m_Editor.GetPoint({
Msg: "请点击被打断的点:"
, KeyWordList: breakPts.length === 0 ? [{ key: "D", msg: "定距等分" }, { key: "S", msg: "定数等分" }] : []

@ -24,6 +24,7 @@ export class Command_Copy implements Command
while (true)
{
app.m_Database.hm.StartMark();
let ptRes2 = await app.m_Editor.GetPoint({
Msg: "请选择复制终点:",
Callback: (p) =>

@ -17,10 +17,7 @@ export class DrawCircle implements Command
switch (ptRes.Status)
{
case PromptStatus.Cancel:
{
app.m_Database.hm.EndCmd();
return;
}
return;
case PromptStatus.Keyword:
{
if (ptRes.StringResult == "3P") //三点画圆
@ -38,9 +35,7 @@ export class DrawCircle implements Command
}
break;
case PromptStatus.OK:
{
await this.DrawCircleUseRadious(ptRes.Value); //圆心半径画圆
}
await this.DrawCircleUseRadious(ptRes.Value); //圆心半径画圆
break;
default:
break;

@ -10,6 +10,7 @@ export class CMD_DrawPoint implements Command
{
while (true)
{
app.m_Database.hm.StartMark();
let ptRes = await app.m_Editor.GetPoint({ Msg: "请输入或点取点的位置" });
if (ptRes.Status != PromptStatus.OK)
break;

@ -41,6 +41,7 @@ export class Command_Extend implements Command
while (true)
{
app.m_Database.hm.StartMark();
//选择延伸的对象.
let exSs = await app.m_Editor.GetSelection({
Msg: "请选择延伸对象:",

@ -33,6 +33,8 @@ export class Command_Offset implements Command
let oldUCS = app.m_Editor.UCSMatrix;
while (true)
{
app.m_Database.hm.StartMark();
let enRes = await app.m_Editor.GetEntity({ Msg: "选择要偏移的对象:" });
if (enRes.Status === PromptStatus.OK)
{

@ -70,6 +70,8 @@ export class Command_Trim implements Command
if (!trSsRes.SelectSet)
continue;
app.m_Database.hm.StartMark();
let newCus = this.JigTrim(trSsRes, kniefCus, false);
for (let [c, cus] of newCus)
{

@ -70,7 +70,7 @@ export class CommandHistoryRecord extends CADObject
//console.log("优化掉重复的全部数据");
return;
}
if (history instanceof ObjectAllDataHistoryRecord)
if (history instanceof ObjectAllDataHistoryRecord && history.undoData === undefined)
{
history.WriteUndo();
}

@ -1,3 +1,4 @@
import { commandMachine } from '../Editor/CommandMachine';
import { Factory } from './CADFactory';
import { CADFile } from './CADFile';
import { CADObject } from './CADObject';
@ -13,11 +14,20 @@ export class HistoricManage extends CADObject
historyRecord: CommandHistoryRecord[] = []; //历史记录
private doing: boolean = false;
constructor()
private m_SignalCommandHistor: HistoricManage;
constructor(bInitCommandHistor = true)
{
super();
if (bInitCommandHistor)
this.m_SignalCommandHistor = new HistoricManage(false);
}
Clear()
{
this.historyRecord.length = 0;
this.curIndex = -1;
}
//对象从文件中读取数据,初始化自身
ReadFile(file: CADFile)
@ -43,30 +53,40 @@ export class HistoricManage extends CADObject
}
}
//命令正在当前状态
get IsNow(): boolean
{
return this.historyRecord.length !== 0 && this.curIndex === this.historyRecord.length - 1;
}
get UndoData(): CommandHistoryRecord
{
if (this.doing)
return undefined;
if (!this.IsNow)
this.StartCmd("");
return this.historyRecord[this.historyRecord.length - 1];
if (this.m_SignalCommandHistor && commandMachine.m_CommandIng)
return this.m_SignalCommandHistor.UndoData;
else
return this.historyRecord[this.historyRecord.length - 1];
}
StartCmd(cmdName: string)
StartMark()
{
this.EndCmd();
if (this.m_SignalCommandHistor)
this.m_SignalCommandHistor.StartCmd("");
}
StartCmd(cmdName: string)
{
//删除当前状态以后的所有状态
this.historyRecord.splice(this.curIndex + 1, this.historyRecord.length - (this.curIndex + 1));
this.historyRecord.push(new CommandHistoryRecord(cmdName));
this.curIndex = this.historyRecord.length - 1;
if (this.m_SignalCommandHistor)
this.m_SignalCommandHistor.StartCmd("");
}
//结束当前的命令.
@ -77,7 +97,25 @@ export class HistoricManage extends CADObject
let lastRec = this.historyRecord[this.curIndex];
if (lastRec)
{
//#region 合并子记录列表
if (this.m_SignalCommandHistor)
{
for (let rc of this.m_SignalCommandHistor.historyRecord)
{
for (let [id, hl] of rc.HistoryList)
{
for (let h of hl)
{
lastRec.WriteObjectHistoryPath(id.Object, h)
}
}
}
this.m_SignalCommandHistor.Clear();
}
//#endregion
lastRec.EndCommand();
if (lastRec.HistoryList.size === 0)
{
this.historyRecord.pop();
@ -88,6 +126,10 @@ export class HistoricManage extends CADObject
Undo(): boolean
{
//如果命令执行中,那么进行局部撤销.
if (this.m_SignalCommandHistor && commandMachine.m_CommandIng)
return this.m_SignalCommandHistor.Undo();
this.EndCmd();
let historyRec = this.historyRecord[this.curIndex];
if (!historyRec)
@ -106,6 +148,9 @@ export class HistoricManage extends CADObject
}
Redo()
{
if (this.m_SignalCommandHistor && commandMachine.m_CommandIng)
return this.m_SignalCommandHistor.Redo();
let historyRec = this.historyRecord[this.curIndex + 1];
if (!historyRec)
return false;

@ -35,10 +35,10 @@ export class DBClickPolyline
{ key: "U", msg: "放弃" }
];
//操作记录数,用于撤销双击后的操作
let totalRecCount = 0;
while (true)
{
app.m_Database.hm.StartMark();
let pl = this.entity as Polyline;
defaultKW[0].key = pl.CloseMark ? "O" : "C";
@ -57,24 +57,15 @@ export class DBClickPolyline
switch (res.StringResult)
{
case "C": //闭合
app.m_Database.hm.StartCmd("");
totalRecCount++;
pl.CloseMark = true;
app.m_Database.hm.EndCmd();
break;
case "O": //打开
app.m_Database.hm.StartCmd("");
totalRecCount++;
pl.CloseMark = false;
app.m_Database.hm.EndCmd();
break;
case "J": //合并
if (!pl.CloseMark)
{
app.m_Database.hm.StartCmd("");
totalRecCount++;
execStatus = await this.Join();
app.m_Database.hm.EndCmd();
}
else
log("无法合并闭合多段线")
@ -85,22 +76,13 @@ export class DBClickPolyline
JigUtils.Destroy();
break;
case "D": //非曲线化
totalRecCount++;
this.TransfromNonCurve();
break;
case "R": //反转
totalRecCount++;
app.m_Database.hm.StartCmd("");
pl.Reverse();
app.m_Database.hm.EndCmd();
break;
case "U": //放弃
if (totalRecCount > 0)
{
totalRecCount--;
app.m_Database.hm.Undo();
}
app.m_Database.hm.Undo();
break;
}
app.m_Editor.UpdateScreen();
@ -133,6 +115,8 @@ export class DBClickPolyline
while (true)
{
app.m_Database.hm.StartMark();
app.m_Editor.UpdateScreen();
let res = await app.m_Editor.GetKeyWords({
@ -161,14 +145,10 @@ export class DBClickPolyline
execStatus = await this.ExecEditor(vertex, indexList, "B");
break;
case "I": //插入
app.m_Database.hm.StartCmd("");
execStatus = await this.ChangeVertex(vertex, false);
app.m_Database.hm.EndCmd();
break;
case "M": //移动
app.m_Database.hm.StartCmd("");
execStatus = await this.ChangeVertex(vertex, true);
app.m_Database.hm.EndCmd();
break;
case "S": //拉直
indexList.push(vertex.index);
@ -195,6 +175,8 @@ export class DBClickPolyline
while (true)
{
app.m_Database.hm.StartMark();
let res = await app.m_Editor.GetKeyWords({
Msg: "请输入选项",
KeyWordList: execKW
@ -323,7 +305,6 @@ export class DBClickPolyline
}
private ExecSAndBCommand(indexList: number[], vertex: IVertex, editorCommand: string)
{
app.m_Database.hm.StartCmd("");
if (!equaln(indexList[0], vertex.index))
indexList.push(vertex.index);
//执行并更新顶点信息
@ -339,11 +320,9 @@ export class DBClickPolyline
}
vertex.index = indexList[0];
vertex.point.Position = this.entity.GetPointAtParam(indexList[0]);
app.m_Database.hm.EndCmd();
}
private TransfromNonCurve()
{
app.m_Database.hm.StartCmd("d");
let pl = this.entity;
if (pl instanceof Polyline)
{
@ -369,11 +348,9 @@ export class DBClickPolyline
this.entity = new Polyline(data);
app.m_Database.ModelSpace.Append(this.entity);
}
app.m_Database.hm.EndCmd();
}
private TransfromSpline()
{
app.m_Database.hm.StartCmd("s");
let pl = this.entity;
if (pl instanceof Polyline)
{
@ -384,6 +361,5 @@ export class DBClickPolyline
spl.CloseMark = pl.CloseMark;
this.entity = spl;
}
app.m_Database.hm.EndCmd();
}
}

@ -108,7 +108,7 @@ export class DynamicInput
break;
}
if (e.keyCode !== KeyBoard.F8)
if (e.keyCode !== KeyBoard.F8 && e.keyCode !== KeyBoard.KeyZ)
e.stopPropagation();
}

Loading…
Cancel
Save