增加临时编辑器,重构封边和排钻的每条边属性编辑,解决历史记录错误的问题 #IYA6V

pull/349/MERGE
ChenX 5 years ago
parent 2df1358343
commit 0c7f3c7eb1

@ -1,43 +0,0 @@
import { Singleton } from "../../Common/Singleton";
import { Board } from "../../DatabaseServices/Entity/Board";
import { Scene } from "three";
import { app } from "../../ApplicationServices/Application";
import { DisposeThreeObj } from "../../Common/Dispose";
/**
* ,.
* .
*
* ,viewer(线,.)
* ,viewer
*/
export class BoardEdgesEditor extends Singleton
{
private EditorIng = false;
private editorScene = new Scene;
//还原旧的视图厂家
private viewerScene: Scene;
/**
*
* @param brs
* @param [showPositiveandNegative=false]
*/
Start(brs: Board[], showPositiveandNegative = false)
{
if (this.EditorIng)
throw "上一个板件边属性编辑器正在编辑中!";
this.EditorIng = true;
this.viewerScene = app.Viewer.Scene;
app.Viewer.Scene = this.editorScene;
//TODO: SHOW
}
End()
{
this.EditorIng = false;
app.Viewer.Scene = this.viewerScene;
DisposeThreeObj(this.editorScene);
}
}

@ -98,12 +98,14 @@ export class ApplicationService
});
//显示撤销重做命令
end(this.Database.hm, this.Database.hm.UndoEvent, (cmdName) =>
end(this.Database.hm, this.Database.hm.UndoEvent, (cmdName: string) =>
{
if (HostApplicationServices.ShowHistoryLog)
this.Editor.Prompt("撤销:" + cmdName);
});
end(this.Database.hm, this.Database.hm.RedoEvent, (cmdName) =>
end(this.Database.hm, this.Database.hm.RedoEvent, (cmdName: string) =>
{
if (HostApplicationServices.ShowHistoryLog)
this.Editor.Prompt("重做:" + cmdName);
});

@ -6,6 +6,7 @@ interface IHostApplicationServices
Application?: ApplicationService;
DefaultMeshMaterial?: MeshBasicMaterial | MeshStandardMaterial;
UseShadow?: boolean;
ShowHistoryLog?: boolean;
}
export let HostApplicationServices: IHostApplicationServices = {};
export let HostApplicationServices: IHostApplicationServices = { ShowHistoryLog: true };

@ -11,6 +11,7 @@ import { CommandHistoryRecord } from './CommandHistoryRecord';
export class HistoricManage extends CADObject
{
curIndex: number = -1; //当前执行位置,也就是当前的状态, undo时,撤销当前状态,redo时,应用下一个状态
lockIndex = -1; //锁定极限撤销索引(将无法在往前撤销)
historyRecord: CommandHistoryRecord[] = []; //历史记录
private doing: boolean = false;
@ -173,6 +174,8 @@ export class HistoricManage extends CADObject
if (this.HaveCommandHistory())
return this.m_SignalCommandHistory.Undo();
if (this.curIndex === this.lockIndex) return;//被锁定,无法撤销
this.EndCmd();
let historyRec = this.historyRecord[this.curIndex];
if (!historyRec)

@ -0,0 +1,63 @@
import { Scene } from "three";
import { app } from "../ApplicationServices/Application";
import { DisposeThreeObj } from "../Common/Dispose";
import { HostApplicationServices } from "../ApplicationServices/HostApplicationServices";
/**
* ,ACAD.
*/
export class TempEditor
{
private constructor() { }
private static EditorIng = false;
private static editorScene = new Scene;
//还原旧的视图厂家
private static viewerScene: Scene;
//缓存历史记录
private static hmIndex: number;
/**
* .
* ,.
* Viewer.Scenethis.editorScene()
*/
static Start()
{
if (this.EditorIng)
throw "重复进入临时编辑模式!";
this.EditorIng = true;
this.viewerScene = app.Viewer.Scene;
app.Viewer.Scene = this.editorScene;
//备份
this.hmIndex = app.Database.hm.curIndex;
app.Database.hm.lockIndex = this.hmIndex;
}
/**
*
* .(.)
* Viewer.Scene
*
*/
static End()
{
this.EditorIng = false;
app.Viewer.Scene = this.viewerScene;
DisposeThreeObj(this.editorScene);
let showLog = HostApplicationServices.ShowHistoryLog;
HostApplicationServices.ShowHistoryLog = false;
app.Database.hm.lockIndex = -1;
while (app.Database.hm.curIndex !== this.hmIndex)
app.Database.hm.Undo();
app.Database.hm.StartCmd("");
app.Database.hm.EndCmd();
HostApplicationServices.ShowHistoryLog = showLog;
app.Viewer.UpdateRender();
}
}

@ -469,7 +469,7 @@ export class DrillTypeSelectCom extends React.Component<IDrillTypeSelect, { isDa
let store = RightPanelStore.GetInstance() as RightPanelStore;
store.m_IsShow = true;
store.m_TabId = RightTabId.Drill;
store.drillingStore.EditorDrilling(br);
store.drillingStore.StartEditor(br);
AppToaster.show({
message: <div>,<br />&lt;&gt;,<br />&lt;&gt;,<br />&lt;退&gt;退</div>,
timeout: 0

@ -34,7 +34,7 @@ export class BoardProcessModal extends React.Component<BoardProcessProps, {}>{
let store = RightPanelStore.GetInstance() as RightPanelStore;
store.m_IsShow = true;
store.m_TabId = RightTabId.Seal;
store.sealingStore.EditorEdgeSealing(br);
store.sealingStore.StartEditor(br);
AppToaster.show({
message: <div>,<br />&lt;&gt;,<br />&lt;&gt;,<br />&lt;退&gt;退</div>,
timeout: 0

@ -71,9 +71,9 @@ export class DrillingComponent extends React.Component<{ store?: RightPanelStore
</li>
</ul>
<div className="flex-end">
<Button text="确定" intent={Intent.SUCCESS} onClick={() => store.WriteDrillData()}
<Button text="确定" intent={Intent.SUCCESS} onClick={() => store.EndEditor()}
/>
<Button text="退出" intent={Intent.DANGER} onClick={() => store.ExitEditor()}
<Button text="退出" intent={Intent.DANGER} onClick={() => store.EndEditor(true)}
/>
</div>
</>

@ -76,11 +76,11 @@ export class SealingComponent extends React.Component<{ store?: RightPanelStore
</ul>
<div className="flex-arround">
<Button text="写入" intent={Intent.SUCCESS}
onClick={() => store.WriteSealingData()} />
onClick={() => store.EndEditor()} />
<Button text="保存" intent={Intent.SUCCESS}
onClick={this.save} />
<Button text="退出" intent={Intent.DANGER}
onClick={() => store.ExitEditor()} />
onClick={() => store.EndEditor(true)} />
</div>
</>
)

@ -0,0 +1,90 @@
import { Matrix4 } from "three";
import { app } from "../../../ApplicationServices/Application";
import { Board } from "../../../DatabaseServices/Entity/Board";
import { Curve } from "../../../DatabaseServices/Entity/Curve";
import { Entity } from "../../../DatabaseServices/Entity/Entity";
import { commandMachine } from "../../../Editor/CommandMachine";
import { TempEditor } from "../../../Editor/TempEditor";
import { AppToaster } from "../../Components/Toaster";
export function ZoomToEntity(en: Entity)
{
app.Viewer.CameraCtrl.LookAt(en.Normal.negate());
app.Editor.UCSMatrix = new Matrix4().extractRotation(en.OCS);
app.Viewer.ZoomAll();
app.Editor.UpdateScreen();
}
export class BoardEdgesEditor
{
Board: Board;
CurveList: Curve[] = [];
Editoring = false;
//@重载
protected async InitData()
{
}
//@重载
protected InitCurve()
{
}
//@重载
protected ParseData()
{
}
//@重载
protected WriteData()
{
}
async StartEditor(br: Board)
{
if (this.Editoring)
throw "重复进入编辑模式!";
this.Board = br;
await this.InitData();
this.InitCurve();
this.Start();
this.Editoring = true;
}
EndEditor(cancel = false)
{
if (!this.Editoring)
{
return;
}
this.ParseData();
TempEditor.End();
if (!cancel)
this.WriteData();
AppToaster.clear();
this.CurveList.length = 0;
this.Editoring = false;
this.Board = undefined;
}
private Start()
{
TempEditor.Start();
commandMachine.CommandStart("");
for (let i = 0; i < this.CurveList.length; i++)
{
let cu = this.CurveList[i];
cu.ApplyMatrix(this.Board.OCS);
app.Database.ModelSpace.Append(cu);
}
commandMachine.CommandEnd();
app.Database.hm.lockIndex++;//禁止初始化动作被撤销
ZoomToEntity(this.Board);
}
}

@ -1,48 +1,32 @@
import { observable } from "mobx";
import { app } from "../../../ApplicationServices/Application";
import { Board } from "../../../DatabaseServices/Entity/Board";
import { Curve } from "../../../DatabaseServices/Entity/Curve";
import { commandMachine } from "../../../Editor/CommandMachine";
import { JigUtils } from "../../../Editor/JigUtils";
import { userConfig } from "../../../Editor/UserConfig";
import { AppToaster } from "../../Components/Toaster";
import { DrillType } from "../BoardInterface";
import { RightStoreEditorStore, toggleObject3DVisible, ZoomToEntity } from "./RightPanelEditorStore";
import { BoardEdgesEditor } from "./BoardEdgesEditor";
export class DrillingStore extends RightStoreEditorStore
export class DrillingStore extends BoardEdgesEditor
{
@observable drillDataList: string[] = []; //前2个为正反面排钻类型
@observable upDownIsdrill: [boolean, boolean] = [true, true]; //正反面
constructor()
{
super();
this.InitDrillingData();
}
InitDrillingData()
protected async InitData()
{
let drillData = [];
let types = [...userConfig.DrillConfigs.keys(), "不排"];
this.drillDataList.push(...userConfig.DrillConfigs.keys(), "不排");
this.upDownIsdrill[0] = true;
this.upDownIsdrill[1] = true;
for (let i = 0, len = types.length; i < len; i++)
{
drillData[i] = types[i];
}
observable(this.drillDataList).replace(drillData);
}
EditorDrilling(br: Board)
{
toggleObject3DVisible();
this.currentBoard = br;
this.cuList = br.ContourCurve.Explode() as Curve[];
protected async InitCurve()
{
this.CurveList = this.Board.ContourCurve.Explode() as Curve[];
let highDrillData = br.BoardProcessOption.highDrill;
this.InitDrillingData();
if (highDrillData.length === this.cuList.length)
let highDrillData = this.Board.BoardProcessOption.highDrill;
if (highDrillData.length === this.CurveList.length)
{
this.upDownIsdrill[0] = br.BoardProcessOption.frontDrill;
this.upDownIsdrill[1] = br.BoardProcessOption.backDrill;
this.upDownIsdrill[0] = this.Board.BoardProcessOption.frontDrill;
this.upDownIsdrill[1] = this.Board.BoardProcessOption.backDrill;
let drills = [...new Set(highDrillData)];
for (let i = 0; i < drills.length; i++)
{
@ -50,33 +34,23 @@ export class DrillingStore extends RightStoreEditorStore
}
for (let i = 0; i < highDrillData.length; i++)
{
this.cuList[i].ColorIndex = drills.indexOf(highDrillData[i]) + 1;
this.CurveList[i].ColorIndex = drills.indexOf(highDrillData[i]) + 1;
}
}
else
{
this.cuList.forEach(c => c.ColorIndex = 1);
this.CurveList.forEach(c => c.ColorIndex = 1);
}
this.ShowCurve();
ZoomToEntity(br);
}
WriteDrillData()
{
if (!this.currentBoard)
return;
if (!commandMachine.CommandStart("_editor"))
return;
let boardData = this.currentBoard.BoardProcessOption;
boardData.frontDrill = this.upDownIsdrill[0];
boardData.backDrill = this.upDownIsdrill[1];
const highDrill = boardData.highDrill;
highDrill.length = 0;
private highDrill: string[];
protected async ParseData()
{
this.highDrill = [];
let types = [...userConfig.DrillConfigs.keys(), DrillType.None];
let defaultType = types[0];
if (!types.includes(boardData.drillType))
boardData.drillType = defaultType;
for (let cu of this.cuList)
for (let cu of this.CurveList)
{
let type = this.drillDataList[cu.ColorIndex - 1];
if (!type)
@ -84,26 +58,29 @@ export class DrillingStore extends RightStoreEditorStore
AppToaster.show({ message: "未知色号,默认" + defaultType, timeout: 1000 });
type = defaultType;
}
highDrill.push(type);
this.highDrill.push(type);
}
}
let typeSet = new Set(highDrill);
protected WriteData()
{
if (!commandMachine.CommandStart("排钻属性编辑"))
return;
let typeSet = new Set(this.highDrill);
let boardData = this.Board.BoardProcessOption;
if (typeSet.size > 1)
{
boardData.frontDrill = this.upDownIsdrill[0];
boardData.backDrill = this.upDownIsdrill[1];
boardData.drillType = DrillType.More;
commandMachine.CommandEnd();
this.ExitEditor();
boardData.highDrill = this.highDrill;
}
ExitEditor()
{
toggleObject3DVisible(true);
for (let c of this.cuList)
else
{
!c.IsErase && app.Database.ModelSpace.Remove(c);
boardData.drillType = typeSet.values().next().value;
}
this.cuList.length = 0;
JigUtils.Destroy();
AppToaster.clear();
this.currentBoard = null;
this.highDrill = undefined;
commandMachine.CommandEnd();
}
}

@ -1,51 +0,0 @@
import { Matrix4 } from "three";
import { app } from "../../../ApplicationServices/Application";
import { Board } from "../../../DatabaseServices/Entity/Board";
import { Curve } from "../../../DatabaseServices/Entity/Curve";
import { Entity } from "../../../DatabaseServices/Entity/Entity";
import { JigUtils } from "../../../Editor/JigUtils";
import { AppToaster } from "../../Components/Toaster";
export function toggleObject3DVisible(visible = false, en?: Entity)
{
app.Database.ModelSpace.Entitys.forEach(e =>
{
if (e !== en)
e.Visible = visible;
})
}
export function ZoomToEntity(en: Entity)
{
app.Viewer.CameraCtrl.LookAt(en.Normal.negate());
app.Editor.UCSMatrix = new Matrix4().extractRotation(en.OCS);
app.Viewer.ZoomAll();
app.Editor.UpdateScreen();
}
export class RightStoreEditorStore
{
currentBoard: Board;
cuList: Curve[] = [];
ShowCurve()
{
for (let i = 0; i < this.cuList.length; i++)
{
let cu = this.cuList[i];
cu.ApplyMatrix(this.currentBoard.OCS);
app.Database.ModelSpace.Append(cu);
}
app.Editor.UpdateScreen();
}
ExitEditor()
{
toggleObject3DVisible(true);
for (let c of this.cuList)
{
!c.IsErase && app.Database.ModelSpace.Remove(c);
}
this.cuList.length = 0;
JigUtils.Destroy();
AppToaster.clear();
this.currentBoard = null;
}
}

@ -1,5 +1,4 @@
import { observable, toJS } from "mobx";
import { Board } from "../../../DatabaseServices/Entity/Board";
import { Curve } from "../../../DatabaseServices/Entity/Curve";
import { commandMachine } from "../../../Editor/CommandMachine";
import { paragraphCulist } from "../../../GraphicsSystem/CalcEdgeSealing";
@ -7,17 +6,13 @@ import { IndexedDbStore, StoreName } from "../../../IndexedDb/IndexedDbStore";
import { RightTabId } from "../../Components/RightPanel/RightPanel";
import { AppToaster } from "../../Components/Toaster";
import { IHighSealedItem } from "../BoardInterface";
import { RightStoreEditorStore, toggleObject3DVisible, ZoomToEntity } from "./RightPanelEditorStore";
import { BoardEdgesEditor } from "./BoardEdgesEditor";
export class SealingStore extends RightStoreEditorStore
export class SealingStore extends BoardEdgesEditor
{
@observable highSizes: string[] = [];
constructor()
{
super();
this.InitSealingData();
}
async InitSealingData()
protected async InitData()
{
let dbstore = await IndexedDbStore.CADStore();
//获取数据库中对应板类型的配置
@ -31,42 +26,36 @@ export class SealingStore extends RightStoreEditorStore
dbstore.Put(StoreName.ConfigData, RightTabId.Seal, toJS(this.highSizes));
}
}
async EditorEdgeSealing(br: Board)
protected InitCurve()
{
toggleObject3DVisible();
let cus = br.ContourCurve.Explode() as Curve[];
this.currentBoard = br;
let cus = this.Board.ContourCurve.Explode() as Curve[];
//曲线分段
paragraphCulist(cus);
//替换曲线列表
this.cuList = cus;
let highseals = br.BoardProcessOption.highSealed;
await this.InitSealingData();
this.CurveList = cus;
let highseals = this.Board.BoardProcessOption.highSealed;
if (highseals.length === cus.length)
{
for (let i = 0; i < highseals.length; i++)
{
let s = highseals[i];
let color = s.color;
this.cuList[i].ColorIndex = color;
this.CurveList[i].ColorIndex = color;
this.highSizes[color - 1] = s.size.toString();
}
}
else
{
this.cuList.forEach(cu => cu.ColorIndex = 1);
this.CurveList.forEach(cu => cu.ColorIndex = 1);
}
this.ShowCurve();
ZoomToEntity(br);
}
WriteSealingData()
{
if (!this.currentBoard)
return;
let highSeal: IHighSealedItem[] = [];
for (let cu of this.cuList)
private data: IHighSealedItem[];
protected ParseData()
{
this.data = [];
for (let cu of this.CurveList)
{
const color = cu.ColorIndex;
if (color > this.highSizes.length)
@ -75,19 +64,21 @@ export class SealingStore extends RightStoreEditorStore
message: color + "号色未设置数据",
timeout: 1500
})
highSeal = null;
this.data = null;
break;
}
const size = this.highSizes[color - 1];
highSeal.push({ size: parseFloat(size), color });
this.data.push({ size: parseFloat(size), color });
}
}
if (highSeal)
protected WriteData()
{
if (!commandMachine.CommandStart("_editor"))
if (!commandMachine.CommandStart("封边属性编辑"))
return;
this.currentBoard.BoardProcessOption.highSealed = highSeal;
this.Board.BoardProcessOption.highSealed = this.data;
this.data = undefined;
commandMachine.CommandEnd();
this.ExitEditor();
}
}
}

@ -106,7 +106,6 @@ export class UserConfigStore extends Singleton
if (type === BoardModalType.Dr)
{
userConfig.DrillConfigs = conf.ruleMap;
(RightPanelStore.GetInstance() as RightPanelStore).drillingStore.InitDrillingData();
}
}
}

Loading…
Cancel
Save