From ae7d9f3e01b03996c14d2dafb41e86806ccddce8 Mon Sep 17 00:00:00 2001 From: ZoeLeeFZ Date: Tue, 23 Jun 2020 14:59:32 +0800 Subject: [PATCH] =?UTF-8?q?!1111=20=E5=8A=9F=E8=83=BD:=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E6=9D=BF=E6=9D=90=E4=BF=AE=E6=94=B9=E9=A2=9C=E8=89=B2,?= =?UTF-8?q?=E5=91=BD=E4=BB=A4CHANGECOLORBYMAT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/ChangeColorByBoardMaterial.ts | 36 +++++++++++++++++++ src/Common/CommandNames.ts | 2 ++ src/Editor/CommandRegister.ts | 5 ++- src/UI/Components/CommandPanel/CmdPanel.tsx | 6 ++-- src/UI/Components/CommandPanel/CommandList.ts | 20 +++++++++++ src/UI/Components/TopToolBar/TopToolBar.tsx | 2 ++ src/UI/IconEnum.ts | 2 ++ 7 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/Add-on/ChangeColorByBoardMaterial.ts diff --git a/src/Add-on/ChangeColorByBoardMaterial.ts b/src/Add-on/ChangeColorByBoardMaterial.ts new file mode 100644 index 000000000..b41456ee2 --- /dev/null +++ b/src/Add-on/ChangeColorByBoardMaterial.ts @@ -0,0 +1,36 @@ +import { Command } from "../Editor/CommandMachine"; +import { app } from "../ApplicationServices/Application"; +import { Board } from "../DatabaseServices/Entity/Board"; +import { PromptStatus } from "../Editor/PromptResult"; +import { EBoardKeyList } from "../Common/BoardKeyList"; + +export class ChangeColorByMaterial implements Command +{ + async exec() + { + let brRes = await app.Editor.GetSelection({ + Msg: "选择板件,根据板材名称修改颜色", + Filter: { filterTypes: [Board] } + }); + + if (brRes.Status === PromptStatus.Cancel) return; + + let brs = brRes.SelectSet.SelectEntityList as Board[]; + + let cache: string[] = []; + + for (let br of brs) + { + let key = `${br.BoardProcessOption[EBoardKeyList.BrMat]}-${br.BoardProcessOption[EBoardKeyList.Color]}-${br.BoardProcessOption[EBoardKeyList.Mat]}`; + let color = cache.indexOf(key); + if (color === -1) + { + color = cache.length + 1; + cache.push(key); + } + else + color += 1; + br.ColorIndex = color; + } + } +} diff --git a/src/Common/CommandNames.ts b/src/Common/CommandNames.ts index 3c58ec462..ec13984d1 100644 --- a/src/Common/CommandNames.ts +++ b/src/Common/CommandNames.ts @@ -163,4 +163,6 @@ export enum CommandNames Text2Curve = "TEXT2CURVE", R2b = "RECT2BOARD", RecyleBin = "RECYCLEBIN", + ChangeColorByMaterial = "CHANGECOLORBYMATERIAL", + RestoreColor = "RESTORECOLOR", } diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index d73276a79..152e5758e 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -184,6 +184,7 @@ import { ShowKinfeManageModal } from './../Add-on/showModal/ShowKnifeManageModal import { commandMachine } from './CommandMachine'; import { ShowRecycleBin } from "../Add-on/ShowRecycleBin"; import { Command_EntitytMoveToZ0 } from "../Add-on/EntityMoveToZ0"; +import { ChangeColorByMaterial } from "../Add-on/ChangeColorByBoardMaterial"; export function registerCommand() { @@ -192,7 +193,7 @@ export function registerCommand() commandMachine.RegisterCommand("end", new Command_EndTempEditor()); - commandMachine.RegisterCommand("RestoreColor", new Command_RestoreColor()); + commandMachine.RegisterCommand(CommandNames.RestoreColor, new Command_RestoreColor()); commandMachine.RegisterCommand("kjl", new Command_KJLImport()); commandMachine.RegisterCommand(CommandNames.KJLExport, new KjlExport()); @@ -514,6 +515,8 @@ export function registerCommand() commandMachine.RegisterCommand(CommandNames.RecyleBin, new ShowRecycleBin()); + commandMachine.RegisterCommand(CommandNames.ChangeColorByMaterial, new ChangeColorByMaterial()); + } export async function RegistCustomCommand() diff --git a/src/UI/Components/CommandPanel/CmdPanel.tsx b/src/UI/Components/CommandPanel/CmdPanel.tsx index d93cb6427..9954879dd 100644 --- a/src/UI/Components/CommandPanel/CmdPanel.tsx +++ b/src/UI/Components/CommandPanel/CmdPanel.tsx @@ -57,7 +57,6 @@ export class CommandPanel extends React.Component<{}, CommandPanelState> } componentDidMount() { - this.inputEl.focus(); this.UseLastScrollTop(); app.Editor.MaskManage.events.push( end(app.Editor.MaskManage, app.Editor.MaskManage.OnFocusEvent, () => @@ -65,6 +64,10 @@ export class CommandPanel extends React.Component<{}, CommandPanelState> app.Editor.ModalManage.Destory(); }) ); + setTimeout(() => + { + this.inputEl.focus(); + }, 0); } handleTabsClick = async () => @@ -97,7 +100,6 @@ export class CommandPanel extends React.Component<{}, CommandPanelState> className="bp3-input" placeholder=">输入命令..." type="search" - autoFocus={true} onKeyDown={(e) => { e.stopPropagation(); }} onChange={v => { diff --git a/src/UI/Components/CommandPanel/CommandList.ts b/src/UI/Components/CommandPanel/CommandList.ts index f6123a1fc..036b0fd45 100644 --- a/src/UI/Components/CommandPanel/CommandList.ts +++ b/src/UI/Components/CommandPanel/CommandList.ts @@ -516,6 +516,26 @@ export const CommandList: ICommand[] = [ chName: "根据板件名修改属性", chDes: "根据板件名修改属性", }, + { + icon: IconEnum.ChangeColorByMat, + typeId: "bjbj", + link: "#", + defaultCustom: "CHANGECOLORBYMAT", + command: CommandNames.ChangeColorByMaterial, + type: "板件编辑", + chName: "根据板材修改颜色", + chDes: "根据板材修改颜色", + }, + { + icon: IconEnum.RestoreColor, + typeId: "bjbj", + link: "#", + defaultCustom: CommandNames.RestoreColor, + command: CommandNames.RestoreColor, + type: "板件编辑", + chName: "恢复板件颜色", + chDes: "恢复板件颜色", + }, //灯光命令 { diff --git a/src/UI/Components/TopToolBar/TopToolBar.tsx b/src/UI/Components/TopToolBar/TopToolBar.tsx index c235e1695..9fae5c80e 100644 --- a/src/UI/Components/TopToolBar/TopToolBar.tsx +++ b/src/UI/Components/TopToolBar/TopToolBar.tsx @@ -71,6 +71,8 @@ export class TopToolBar extends React.Component<{}, {}> { svg: IconEnum.Curve2Rec, title: "线条变矩形", command: CommandNames.Curve2Rect }, { svg: IconEnum.Rec2Br, title: "矩形变板件", command: CommandNames.R2b }, { svg: IconEnum.UpdateInfo, title: "根据板名修改属性", command: CommandNames.UpdateBoardInfos }, + { svg: IconEnum.ChangeColorByMat, title: "根据板材修改颜色", command: CommandNames.ChangeColorByMaterial }, + { svg: IconEnum.RestoreColor, title: "恢复板件颜色", command: CommandNames.RestoreColor }, ]; store.iconList.brEdit = [ { svg: IconEnum.QG, title: "线性切割", command: CommandNames.LinearCutting }, diff --git a/src/UI/IconEnum.ts b/src/UI/IconEnum.ts index ba8817434..98a7e77ae 100644 --- a/src/UI/IconEnum.ts +++ b/src/UI/IconEnum.ts @@ -164,4 +164,6 @@ export enum IconEnum ExportView = "ExportView2.svg", UpdateInfo = "ChangeBoardAttributeFromBoardName.svg", Revolve = "Revolve.svg", + RestoreColor = "RestoreColor.svg", + ChangeColorByMat = "ChangeColorByMat.svg", }