测试重构

pull/215/MERGE
ChenX 6 years ago
parent 8dfd77072c
commit bf5c831c2e

@ -1,5 +1,5 @@
import { app } from "../../ApplicationServices/Application";
import { commandMachine } from "../../Editor/CommandMachine";
import { CommandState } from "../../Editor/CommandState";
export class DrawBoardServer
{
@ -13,7 +13,7 @@ export class DrawBoardServer
{
if (this.m_DrawMap.has(type))
{
if (commandMachine.m_CommandIng)
if (CommandState.CommandIng)
return;
commandMachine.CommandStart(type);

@ -1,6 +1,7 @@
import { CADFactory } from './CADFactory';
import { CADObject } from './CADObject';
import { Database } from './Database';
import { ISerialize } from './ISerialize';
import { ObjectId } from './ObjectId';
/**
@ -46,7 +47,7 @@ export class CADFile
this.readIndex++;
return str;
}
WriteObject(obj: CADObject)
WriteObject(obj: ISerialize)
{
if (!obj)
{

@ -2,6 +2,7 @@ import { Factory } from './CADFactory';
import { CADFile } from './CADFile';
import { CommandHistoryRecord } from './CommandHistoryRecord';
import { Database } from './Database';
import { ISerialize } from './ISerialize';
import { ObjectId } from './ObjectId';
export abstract class CADObject
@ -91,7 +92,7 @@ export abstract class CADObject
file.Write(this._isErase);
}
//局部撤销
ApplyPartialUndo(undoData: CADObject)
ApplyPartialUndo(undoData: ISerialize)
{
if (undoData instanceof AllObjectData)
{
@ -100,7 +101,7 @@ export abstract class CADObject
}
else if (undoData instanceof EraseEntityData)
{
this.Erase(undoData.IsErase);
this.Erase(undoData.isErase);
}
}
@ -189,6 +190,7 @@ export class AllObjectData extends CADObject
let ver = file.Read();
let data = file.Read();
this.file.Data = data;
return this;
}
//对象将自身数据写入到文件.
WriteFile(file: CADFile)
@ -196,16 +198,25 @@ export class AllObjectData extends CADObject
super.WriteFile(file);
file.Write(1);
file.Write(this.file.Data);
return this;
}
//#endregion
}
@Factory
export class EraseEntityData extends CADObject
export class EraseEntityData implements ISerialize
{
constructor(isErase = true)
ReadFile(file: CADFile): this
{
this.isErase = file.Read();
return this;
}
WriteFile(file: CADFile): this
{
file.Write(this.isErase);
return this;
}
constructor(public isErase = true)
{
super();
this._isErase = isErase;
}
}

@ -1,6 +1,7 @@
import { Factory } from './CADFactory';
import { CADFile } from './CADFile';
import { CADObject } from './CADObject';
import { ISerialize } from './ISerialize';
/**
* ,.
@ -12,10 +13,10 @@ import { CADObject } from './CADObject';
export class HistorycRecord extends CADObject
{
//指定撤销时所需要的数据
undoData: CADObject;
undoData: ISerialize;
//制定重做时所需要的数据
redoData: CADObject;
userData: CADObject;
redoData: ISerialize;
userData: ISerialize;
//#region -------------------------File-------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
@ -24,9 +25,9 @@ export class HistorycRecord extends CADObject
ReadFile(file: CADFile)
{
let ver = file.Read();
this.undoData = file.ReadObject(this._db);
this.redoData = file.ReadObject(this._db);
this.userData = file.ReadObject(this._db);
this.undoData = file.ReadObject();
this.redoData = file.ReadObject();
this.userData = file.ReadObject();
}
//对象将自身数据写入到文件.
WriteFile(file: CADFile)

@ -0,0 +1,7 @@
import { CADFile } from "./CADFile";
export interface ISerialize
{
ReadFile(file: CADFile);
WriteFile(file: CADFile);
}

@ -9,6 +9,7 @@ import { MouseKey, KeyBoard } from '../Common/KeyEnum';
import { InitRightMenu, RightMenuType, RightMenuCmdKW } from './InitRightMenu';
import { commandMachine } from './CommandMachine';
import { arrayRemoveOnce } from '../Common/ArrayExt';
import { CommandState } from './CommandState';
export class MouseControls
@ -74,7 +75,7 @@ export class MouseControls
let cmd: string = RightMenuCmdKW[res.StringResult] ? RightMenuCmdKW[res.StringResult] : res.StringResult;
if (commandMachine.isCommandExist(cmd))
{
if (!commandMachine.m_CommandIng)
if (!CommandState.CommandIng)
commandMachine.ExecCommand(cmd);
arrayRemoveOnce(historyCmdList, cmd);
historyCmdList.push(cmd);
@ -90,13 +91,13 @@ export class MouseControls
if ((app.m_Editor.m_KeyCtrl.KeyIsDown(KeyBoard.Control)
|| app.m_Editor.m_KeyCtrl.KeyIsDown(KeyBoard.Shift)))
return;
if (commandMachine.m_CommandIng && ssenlist.length < 1)//有执行无选中 退出
if (CommandState.CommandIng && ssenlist.length < 1)//有执行无选中 退出
return;
else if (commandMachine.m_CommandIng && ssenlist.length > 0)//有执行有选中 执行
else if (CommandState.CommandIng && ssenlist.length > 0)//有执行有选中 执行
{ }
else if (!commandMachine.m_CommandIng && ssenlist.length < 1)//无执行无选中 菜单NoSelect
else if (!CommandState.CommandIng && ssenlist.length < 1)//无执行无选中 菜单NoSelect
this.handleRightClick(RightMenuType.NoSelect);
else if (!commandMachine.m_CommandIng && ssenlist.length > 0)//无执行有选中 菜单Selected
else if (!CommandState.CommandIng && ssenlist.length > 0)//无执行有选中 菜单Selected
this.handleRightClick(RightMenuType.Selected);
else return;
}

@ -15,6 +15,7 @@ import { AppToaster } from '../Toaster';
import { Notes } from './BoardCommon';
import { BoardConfigModal } from './BoardConfigModal';
import { BoardProcessModal } from './BoardProcessModal';
import { CommandState } from '../../../Editor/CommandState';
export class BoardOptionModal extends React.Component<{ board: Board }, {}>
{
@ -63,7 +64,7 @@ export class BoardOptionModal extends React.Component<{ board: Board }, {}>
return;
}
commandMachine.m_CommandIng = true;
CommandState.CommandIng = true;
app.m_Database.hm.StartCmd("changeSize");
let board = this.m_CurrentBoard;

@ -8,6 +8,7 @@ import { JigUtils } from '../../../Editor/JigUtils';
import './ModalStyle/Modal.less';
import * as xaop from 'xaop';
import { Editor } from '../../../Editor/Editor';
import { CommandState } from '../../../Editor/CommandState';
export enum ModalPosition
{
Center = "center",
@ -136,7 +137,7 @@ export class ModalManage
}
async EndExecingCmd()
{
if (commandMachine.m_CommandIng)
if (CommandState.CommandIng)
{
app.m_Editor.Canel();
await Sleep(10);

@ -9,6 +9,7 @@ import SoucePanel from './SourceManage/SoucePanel';
import { SnapMenuFixed } from '../../Editor/SnapMenuFixed';
import { commandMachine } from '../../Editor/CommandMachine';
import { app } from '../../ApplicationServices/Application';
import { CommandState } from '../../Editor/CommandState';
interface TopPanelState
{
@ -128,7 +129,7 @@ export class TopPanel extends React.Component<{ store?: TopPanelStore }, {}>
private openFileManage = () =>
{
if (!commandMachine.m_CommandIng && app.m_Editor.m_InputState === 0)
if (!CommandState.CommandIng && app.m_Editor.m_InputState === 0)
this.props.store.m_FileManageOpen = true;
else
app.m_Editor.Prompt("图形正在执行命令!");

@ -1,3 +1,4 @@
import { Icon } from '@blueprintjs/core';
import { observer } from 'mobx-react';
import * as React from 'react';
import { end } from 'xaop';
@ -7,8 +8,8 @@ import { KeyWord } from '../../../Common/InputState';
import { KeyBoard } from '../../../Common/KeyEnum';
import { FixIndex, isLetter, isNum } from '../../../Common/Utils';
import { commandMachine } from '../../../Editor/CommandMachine';
import { CommandState } from '../../../Editor/CommandState';
import './InputHint.css';
import { Icon } from '@blueprintjs/core';
interface InputHintProps
{
@ -90,7 +91,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
let inputCmd = cmd.trim();
this.setState({ command: inputCmd });
//没有执行命令才会进行感知
if (commandMachine.m_CommandIng || this.state.isCNInput)
if (CommandState.CommandIng || this.state.isCNInput)
{
return;
}
@ -159,7 +160,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
public handleCallback(cmd: string)
{
if (!commandMachine.m_CommandIng)
if (!CommandState.CommandIng)
{
if (commandMachine.isCommandExist(cmd))
{
@ -195,7 +196,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
let cmd = this.m_InputEl.value;
if (this.state.intelliSenseCommand.length > 0)
cmd = this.state.intelliSenseCommand[this.state.intelliSenseIndex];
else if (cmd === "" && !commandMachine.m_CommandIng)
else if (cmd === "" && !CommandState.CommandIng)
cmd = this.props.historyCmdList[this.props.historyCmdList.length - 1]
e.stopPropagation();
@ -228,7 +229,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
else
{
//历史命令
if (!commandMachine.m_CommandIng && this.props.historyCmdList.length > 0)
if (!CommandState.CommandIng && this.props.historyCmdList.length > 0)
{
if (e.keyCode == KeyBoard.ArrowUp)
{

@ -1,9 +1,10 @@
import { observable } from 'mobx';
import { KeyWord } from '../../Common/InputState';
import { commandMachine } from '../../Editor/CommandMachine';
import { CommandState } from '../../Editor/CommandState';
import { Editor } from '../../Editor/Editor';
export interface CommandMsg
{
key: number;//react key
@ -49,7 +50,7 @@ export class CommandStore
HandleInput = (cmd: string) =>
{
if (commandMachine.m_CommandIng != true)
if (CommandState.CommandIng != true)
commandMachine.ExecCommand(cmd);
else
this.m_Editor.InputEvent(cmd);

Loading…
Cancel
Save