From e1821be7f4dedf26f3747fdfea75c75201576b9f Mon Sep 17 00:00:00 2001 From: ChenX Date: Tue, 13 Aug 2019 09:12:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9LWH=E7=9A=84=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Winerack/winerack.test.ts | 12 +++++------ src/Add-on/DrawBoard/DrawBehindBoard.ts | 5 +---- src/Add-on/DrawBoard/DrawLayerBoard.ts | 11 +++++----- src/Add-on/DrawBoard/DrawVerticalBoard.ts | 10 ++++----- src/Add-on/DrawWineRack/DrawWinRackTool.ts | 21 +++++++------------ src/Common/Utils.ts | 2 -- .../Template/TemplateWineRackRecord.ts | 2 +- src/UI/Components/Board/LayerBoardModal.tsx | 6 +++--- src/UI/Components/Board/WineRack.tsx | 4 ++-- src/UI/Store/BoardStore.ts | 4 ++-- src/UI/Store/WineRackStore.ts | 2 +- 11 files changed, 33 insertions(+), 46 deletions(-) diff --git a/__test__/Winerack/winerack.test.ts b/__test__/Winerack/winerack.test.ts index 74f9777a1..485a5a69a 100644 --- a/__test__/Winerack/winerack.test.ts +++ b/__test__/Winerack/winerack.test.ts @@ -1,11 +1,11 @@ -import { DrawUprightWineRackTool } from "../../src/Add-on/DrawWineRack/DrawUprightWineRackTool"; +import { Vector3 } from "three"; import { DrawBlisWineRackTool } from "../../src/Add-on/DrawWineRack/DrawBlisWineRackTool"; -import { IWineRackOption, EWineRackType, EWRackArrayType, EFullType, EFullDir } from "../../src/UI/Store/WineRackInterface"; -import { ISpaceParse } from "../../src/Geometry/SpaceParse/ISpaceParse"; -import { Box3, Vector3, Matrix4 } from "three"; +import { DrawUprightWineRackTool } from "../../src/Add-on/DrawWineRack/DrawUprightWineRackTool"; +import { Board } from "../../src/DatabaseServices/Entity/Board"; import { Box3Ext } from "../../src/Geometry/Box"; +import { ISpaceParse } from "../../src/Geometry/SpaceParse/ISpaceParse"; +import { EFullDir, EFullType, EWineRackType, EWRackArrayType, IWineRackOption } from "../../src/UI/Store/WineRackInterface"; import { LoadEntityFromFileData } from "../Utils/LoadEntity.util"; -import { Board } from "../../src/DatabaseServices/Entity/Board"; const UprightTool = DrawUprightWineRackTool.GetInstance() as DrawUprightWineRackTool; const blisTool = DrawBlisWineRackTool.GetInstance() as DrawBlisWineRackTool; @@ -21,7 +21,7 @@ const option: IWineRackOption = { isTotalDepth: true, depth: 0, gripWidth: 100, - calcDepth: "L", + calcDepth: "W", boardThick: 18, grooveWidthAdd: 0, leftEdge: 1, diff --git a/src/Add-on/DrawBoard/DrawBehindBoard.ts b/src/Add-on/DrawBoard/DrawBehindBoard.ts index bebb05ae7..c3dfb9e5d 100644 --- a/src/Add-on/DrawBoard/DrawBehindBoard.ts +++ b/src/Add-on/DrawBoard/DrawBehindBoard.ts @@ -30,10 +30,7 @@ export class DrawBehindBoard extends DrawBoardTool if (opt.boardPosition === BehindHeightPositon.AllHeight) height = size.z; else - { - let lengthExpr = opt.calcHeight.replace(/["H"|"L"]/, size.z.toString()); - height = eval(lengthExpr); - } + height = safeEval(opt.calcHeight, { L: size.x, W: size.y, H: size.z }); let moveDist = opt.moveDist; diff --git a/src/Add-on/DrawBoard/DrawLayerBoard.ts b/src/Add-on/DrawBoard/DrawLayerBoard.ts index fbc6e3c99..2fe55e7e7 100644 --- a/src/Add-on/DrawBoard/DrawLayerBoard.ts +++ b/src/Add-on/DrawBoard/DrawLayerBoard.ts @@ -1,14 +1,15 @@ import { Matrix4, Vector3 } from 'three'; import { app } from '../../ApplicationServices/Application'; +import { arrayLast } from '../../Common/ArrayExt'; +import { safeEval } from '../../Common/eval'; import { GangDrill, GangDrillType } from '../../DatabaseServices/3DSolid/GangDrill'; import { Board, BoardType } from '../../DatabaseServices/Entity/Board'; +import { ObjectId } from '../../DatabaseServices/ObjectId'; +import { JigUtils } from '../../Editor/JigUtils'; import { MoveMatrix } from '../../Geometry/GeUtils'; import { BrRelativePos, LayerBoardOption } from '../../UI/Store/BoardInterface'; import { LayerBoardStore } from '../../UI/Store/BoardStore'; import { DrawBoardTool } from './DrawBoardTool'; -import { ObjectId } from '../../DatabaseServices/ObjectId'; -import { arrayLast } from '../../Common/ArrayExt'; -import { JigUtils } from '../../Editor/JigUtils'; enum NailPos { @@ -40,9 +41,7 @@ export class DrawLayerBoard extends DrawBoardTool width = size.y; else { - //解析高度表达式 - let heightExpr = opt.calcHeight.replace(/["H"|"L"]/, size.y.toString()); - width = eval(heightExpr); + width = safeEval(opt.calcHeight, { L: size.x, W: size.y, H: size.z }); } let count = opt.count; let type = opt.boardRelative; diff --git a/src/Add-on/DrawBoard/DrawVerticalBoard.ts b/src/Add-on/DrawBoard/DrawVerticalBoard.ts index 479654486..e03b43a77 100644 --- a/src/Add-on/DrawBoard/DrawVerticalBoard.ts +++ b/src/Add-on/DrawBoard/DrawVerticalBoard.ts @@ -1,10 +1,11 @@ import { Vector3 } from 'three'; import { app } from '../../ApplicationServices/Application'; +import { safeEval } from '../../Common/eval'; import { Board, BoardType } from '../../DatabaseServices/Entity/Board'; +import { JigUtils } from '../../Editor/JigUtils'; import { MoveMatrix } from '../../Geometry/GeUtils'; import { BrRelativePos, VerticalBoardOption } from '../../UI/Store/BoardInterface'; import { DrawBoardTool } from './DrawBoardTool'; -import { JigUtils } from '../../Editor/JigUtils'; export class DrawVerticalBoard extends DrawBoardTool { @@ -24,9 +25,7 @@ export class DrawVerticalBoard extends DrawBoardTool width = size.y - frontShrink; else { - //解析宽度表达式 - let widthExpr = opt.calcWidth.replace(/["H"|"L"]/, size.y.toString()); - width = eval(widthExpr); + width = safeEval(opt.calcWidth, { L: size.x, W: size.y, H: size.z }); } let length: number; @@ -34,8 +33,7 @@ export class DrawVerticalBoard extends DrawBoardTool length = size.z - bottomShink; else { - let lengthExpr = opt.calcHeight.replace(/["H"|"L"]/, size.z.toString()); - length = eval(lengthExpr); + length = safeEval(opt.calcHeight, { L: size.x, W: size.y, H: size.z }); } let count = opt.count; diff --git a/src/Add-on/DrawWineRack/DrawWinRackTool.ts b/src/Add-on/DrawWineRack/DrawWinRackTool.ts index 793d47bfd..9d96143ac 100644 --- a/src/Add-on/DrawWineRack/DrawWinRackTool.ts +++ b/src/Add-on/DrawWineRack/DrawWinRackTool.ts @@ -1,10 +1,10 @@ -import { Singleton } from "../../Common/Singleton"; -import { ISpaceParse } from "../../Geometry/SpaceParse/ISpaceParse"; -import { EWRackArrayType, EFullType, EFullDir, IWineRackOption } from "../../UI/Store/WineRackInterface"; import { Vector3 } from "three"; -import { operationExpReg } from "../../Common/Utils"; +import { safeEval } from "../../Common/eval"; +import { Singleton } from "../../Common/Singleton"; import { Board, BoardType } from "../../DatabaseServices/Entity/Board"; -import { IHighSealedItem, DrillType, FaceDirection } from "../../UI/Store/BoardInterface"; +import { ISpaceParse } from "../../Geometry/SpaceParse/ISpaceParse"; +import { DrillType, FaceDirection, IHighSealedItem } from "../../UI/Store/BoardInterface"; +import { EFullDir, EFullType, EWRackArrayType, IWineRackOption } from "../../UI/Store/WineRackInterface"; export const SIN45 = Math.sin(Math.PI / 4); @@ -25,14 +25,10 @@ export class DrawWineRackTool extends Singleton //处理格子深 if (!config.isTotalDepth) { - let calcDepth = config.calcDepth.replace("L", space.Size.y.toString()); - if (operationExpReg.test(calcDepth)) + let depth = safeEval(config.calcDepth, { L: space.Size.x, W: space.Size.y, H: space.Size.z });; + if (!isNaN(depth)) { - let depth = eval(calcDepth); - if (depth) - { - space.m_SpaceBox.max.setY(space.m_SpaceBox.min.y + depth); - } + space.m_SpaceBox.max.setY(space.m_SpaceBox.min.y + depth); } } //处理前缩 @@ -159,4 +155,3 @@ export class DrawWineRackTool extends Singleton } } } - diff --git a/src/Common/Utils.ts b/src/Common/Utils.ts index 058ee08a9..10c84e42f 100644 --- a/src/Common/Utils.ts +++ b/src/Common/Utils.ts @@ -3,8 +3,6 @@ import { Entity } from "../DatabaseServices/Entity/Entity"; import { equaln } from "../Geometry/GeUtils"; import { safeEval } from "./eval"; -//四则运算表达式正则 -export const operationExpReg = /^(\d+([.]\d)?)+([+|\-|*|/](\d+([.]\d)?))*$/; export const commandReg = /[^A-Za-z0-9]/g; //仅可输入英文 export const onlyEnExpReg = /[^A-Za-z]/g; diff --git a/src/DatabaseServices/Template/TemplateWineRackRecord.ts b/src/DatabaseServices/Template/TemplateWineRackRecord.ts index b38d5ac44..73f3fb87e 100644 --- a/src/DatabaseServices/Template/TemplateWineRackRecord.ts +++ b/src/DatabaseServices/Template/TemplateWineRackRecord.ts @@ -34,7 +34,7 @@ export class TemplateWineRackRecord extends TemplateRecord isTotalDepth: true, depth: 0, gripWidth: 100, - calcDepth: "L", + calcDepth: "W", boardThick: 18, grooveWidthAdd: 0, leftEdge: 1, diff --git a/src/UI/Components/Board/LayerBoardModal.tsx b/src/UI/Components/Board/LayerBoardModal.tsx index 60795c3d4..5657f4497 100644 --- a/src/UI/Components/Board/LayerBoardModal.tsx +++ b/src/UI/Components/Board/LayerBoardModal.tsx @@ -28,7 +28,7 @@ export const LayerBoardModal = { brOpt.isTotalLength = !brOpt.isTotalLength; - uiOption["calcHeight"] = brOpt.isTotalLength ? "L" : uiOption["calcHeight"]; + uiOption["calcHeight"] = brOpt.isTotalLength ? "W" : uiOption["calcHeight"]; }} /> { @@ -40,8 +40,8 @@ export const LayerBoardModal = brOpt.leftShrink = 1; brOpt.rightShrink = 1; brOpt.isTotalLength = false; - uiOption['calcHeight'] = "L-1"; - brOpt.calcHeight = "L-1"; + uiOption['calcHeight'] = "W-1"; + brOpt.calcHeight = "W-1"; } else { diff --git a/src/UI/Components/Board/WineRack.tsx b/src/UI/Components/Board/WineRack.tsx index bd9a7f350..d11673519 100644 --- a/src/UI/Components/Board/WineRack.tsx +++ b/src/UI/Components/Board/WineRack.tsx @@ -196,8 +196,8 @@ export class WineRackModal extends React.Component<{ store?: WineRackStore }, {} m_Option.isTotalDepth = !m_Option.isTotalDepth; if (m_Option.isTotalDepth) { - m_Option.calcDepth = "L"; - UIOption.calcDepth = "L"; + m_Option.calcDepth = "W"; + UIOption.calcDepth = "W"; } }} /> diff --git a/src/UI/Store/BoardStore.ts b/src/UI/Store/BoardStore.ts index d61bfd51d..54866a0ef 100644 --- a/src/UI/Store/BoardStore.ts +++ b/src/UI/Store/BoardStore.ts @@ -277,7 +277,7 @@ export class LayerBoardStore extends BoardStore frontShrink: 0, leftShrink: 0, rightShrink: 0, - calcHeight: "L", + calcHeight: "W", isTotalLength: true, boardRelative: BrRelativePos.Div, thickness: 18, @@ -346,7 +346,7 @@ export class VerticalBoardStore extends BoardStore name: "立板", frontShrink: 0, bottomShrink: 0, - calcWidth: "L", + calcWidth: "W", calcHeight: "H", isTotalLength: true, isTotalWidth: true, diff --git a/src/UI/Store/WineRackStore.ts b/src/UI/Store/WineRackStore.ts index 79f1314a2..b10c7fdd7 100644 --- a/src/UI/Store/WineRackStore.ts +++ b/src/UI/Store/WineRackStore.ts @@ -19,7 +19,7 @@ export class WineRackStore extends BoardStore isTotalDepth: true, depth: 0, gripWidth: 100, - calcDepth: "L", + calcDepth: "W", boardThick: 18, grooveWidthAdd: 0, leftEdge: 1,