From 9a879e0b32edee4c45a2027db503f110e5e04d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=AF=97=E6=B4=A5?= <2723065175@qq.com> Date: Fri, 11 Nov 2022 02:05:18 +0000 Subject: [PATCH] =?UTF-8?q?!2003=20=E5=8A=9F=E8=83=BD:=E9=85=B7=E5=AE=B6?= =?UTF-8?q?=E4=B9=90=E4=BD=BF=E7=94=A8=E5=90=8D=E7=A7=B0=E5=8F=AF=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=92=8C=E9=85=B7=E5=AE=B6=E4=B9=90=E5=B0=81=E8=BE=B9?= =?UTF-8?q?=E5=80=BC=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/KJL/Import/KJLEdgeParse.ts | 61 +++++++++++++++++ src/Add-on/KJL/Import/KJLImport.ts | 17 +++-- src/Add-on/KJL/Import/KJLParse.ts | 44 ------------ src/Add-on/KJL/KJLImportConfig/KJLConfig.tsx | 53 +++++++++++++-- .../KJL/KJLImportConfig/KJLImportConfig.less | 68 ++++++++++++++++--- .../KJLImportConfig/KJLImportConfigStore.ts | 30 +++++++- src/Editor/DefaultConfig.ts | 7 +- src/UI/Store/BoardInterface.ts | 3 + 8 files changed, 216 insertions(+), 67 deletions(-) create mode 100644 src/Add-on/KJL/Import/KJLEdgeParse.ts diff --git a/src/Add-on/KJL/Import/KJLEdgeParse.ts b/src/Add-on/KJL/Import/KJLEdgeParse.ts new file mode 100644 index 000000000..8c35c5708 --- /dev/null +++ b/src/Add-on/KJL/Import/KJLEdgeParse.ts @@ -0,0 +1,61 @@ +import { arrayLast } from "../../../Common/ArrayExt"; +import { KJLImportConfigOption } from "../../../UI/Store/BoardInterface"; +import { KJL_Parameter, KJL_ParamModel } from "./KJLInterface"; + +export class KJLEdgeParse +{ + //(酷家乐封边值) -> 导入实际值 + KjlEdgeValueMap = new Map(); + + async LoadKJLEdgeValueMap(config: { [key: string]: KJLImportConfigOption; }) + { + if (!config?.option?.edgeValueMap) return; + for (const [key, value] of config.option.edgeValueMap) + { + if (key === 0 && value === 0) continue; + this.KjlEdgeValueMap.set(key, value); + } + } + + + //解析封边 + ParseSeals(model: KJL_ParamModel): number[] | undefined + { + let seals: number[] = []; + let maxIndex = 0;//避免漏掉,我们保存了最大的索引 + const Parse = (params: KJL_Parameter[]) => + { + if (!params) return; + for (let param of params) + { + if (param.name === "ET") + { + seals.push(parseFloat(param.value)); + for (let i = 0; i < maxIndex - 1; i++) + seals[i] = arrayLast(seals); + maxIndex++; + break; + } + else if (param.name.startsWith("ET")) + { + let index = parseInt(param.name.substring(2)) - 1; + seals[index] = parseFloat(param.value); + maxIndex = Math.max(index, maxIndex); + } + } + }; + + Parse(model.constParameters); + Parse(model.ignoreParameters); + Parse(model.parameters); + + for (let i = 0; i < maxIndex; i++) + { + if (seals[i] === undefined) + seals[i] = seals[maxIndex]; + } + + if (seals.length > 0) + return seals.map(e => this.KjlEdgeValueMap.get(e) ?? e); + } +} diff --git a/src/Add-on/KJL/Import/KJLImport.ts b/src/Add-on/KJL/Import/KJLImport.ts index e9faac172..9280d37f6 100644 --- a/src/Add-on/KJL/Import/KJLImport.ts +++ b/src/Add-on/KJL/Import/KJLImport.ts @@ -29,9 +29,11 @@ import { BoardType, DrillType, FaceDirection, IHighSealedItem, KJLImportConfigOp import { TopPanelStore } from "../../../UI/Store/TopPanelStore"; import { EZengZhiBaoId, userConfigStore } from "../../../UI/Store/UserConfigStore"; import { CuttingBoardByBoard } from "../../BoardCutting/CuttingUtils2"; +import { KJLUseName } from "../KJLImportConfig/KJLConfig"; +import { KJLEdgeParse } from "./KJLEdgeParse"; import { KJL_DrillData, KJL_JsonFile, KJL_ModelType, KJL_Parameter, KJL_ParamModel, KJL_ParamModel_Board, KJL_ParamModel_Hardware } from "./KJLInterface"; import { KJLMaterialLoader } from "./KJLMaterialLoader"; -import { ParseBCBZ, ParseBT, ParseCabNameMap, ParseDrilling, ParseEdgeBanding, ParseEdges, ParseKMFX, ParsePathOutlineAndHole, ParseRoomNameMap, ParseTopline } from "./KJLParse"; +import { ParseBCBZ, ParseBT, ParseCabNameMap, ParseDrilling, ParseEdges, ParseKMFX, ParsePathOutlineAndHole, ParseRoomNameMap, ParseTopline } from "./KJLParse"; import { ApplyMaterial, CreateHardware, ParseHardwareParam } from "./KJLUtils"; @@ -100,13 +102,15 @@ export async function ImportKJLData(fileData: KJL_JsonFile) let mtlLoader = new KJLMaterialLoader; await mtlLoader.LoadKJLConfigMaterials(config); + let edgeParse = new KJLEdgeParse; + await edgeParse.LoadKJLEdgeValueMap(config); let toplines: HardwareTopline[] = []; for (let m of fileData.paramModel) { let roomName = roomNameMap.get(m.roomId); let gName = cabNameMap.get(m.id) ?? m.modelBrandGoodName; - await ParseModel(m, roomName, gName, mtlLoader, config, toplines); + await ParseModel(m, roomName, gName, mtlLoader, edgeParse, config, toplines); } let ents = app.CommandReactor._createObejcts.filter(obj => obj instanceof Entity) as Entity[]; @@ -182,6 +186,7 @@ async function ParseModel(model: KJL_ParamModel, roomName: string, gName: string, mtlLoader: KJLMaterialLoader, + edgeParse: KJLEdgeParse, config: { [key: string]: KJLImportConfigOption; }, outToplines: HardwareTopline[], parentMatrix?: Matrix4, @@ -303,7 +308,7 @@ async function ParseModel(model: KJL_ParamModel, } let br = new Board(); - br.Name = model.modelName ?? ""; + br.Name = (config.option.kjlUseName !== KJLUseName.modelBrandGoodName ? model.modelName : model.modelBrandGoodName) ?? ""; br.BoardProcessOption[EBoardKeyList.Mat] = model.textureName ?? ""; br.BoardProcessOption[EBoardKeyList.BrMat] = model.baseTexture ?? ""; br.BoardProcessOption[EBoardKeyList.RoomName] = roomName; @@ -502,7 +507,7 @@ async function ParseModel(model: KJL_ParamModel, let templates: TemplateRecord[] = []; for (let m of model.subModels) { - let edgeBandings = ParseEdgeBanding(model); + let edgeBandings = edgeParse.ParseSeals(model); let holeFaceData = ParseDrilling(model.parameters) ?? ParseDrilling(model.ignoreParameters) ?? ParseDrilling(model.constParameters); let edgesData = ParseEdges(model.parameters) ?? ParseEdges(model.ignoreParameters) ?? ParseEdges(model.constParameters); @@ -510,7 +515,7 @@ async function ParseModel(model: KJL_ParamModel, if (holeFaceData) drillData.bigHole = holeFaceData.bigHole; let boardType = ParseBT(model.parameters) ?? ParseBT(model.ignoreParameters) ?? ParseBT(model.constParameters); - let obj = await ParseModel(m, roomName, gName, mtlLoader, config, outToplines, mtx, edgeBandings, drillData); + let obj = await ParseModel(m, roomName, gName, mtlLoader, edgeParse, config, outToplines, mtx, edgeBandings, drillData); if (obj) { if (obj instanceof Board) @@ -523,7 +528,7 @@ async function ParseModel(model: KJL_ParamModel, if (bcbz !== undefined) obj.BoardProcessOption.remarks.push(["KJLBCBZ", bcbz]); - if (model.modelBrandGoodName !== gName) + if (config.option.kjlUseName !== KJLUseName.modelName && model.modelBrandGoodName !== gName) obj.Name = model.modelBrandGoodName; if (boardType & 1) obj.IsChaiDan = false; diff --git a/src/Add-on/KJL/Import/KJLParse.ts b/src/Add-on/KJL/Import/KJLParse.ts index 6006e99ea..ab0f29380 100644 --- a/src/Add-on/KJL/Import/KJLParse.ts +++ b/src/Add-on/KJL/Import/KJLParse.ts @@ -39,50 +39,6 @@ export function ParseCabNameMap(data: KJL_AssemblyModel[]): Map return map; } -//解析封边 -export function ParseEdgeBanding(model: KJL_ParamModel): number[] | undefined -{ - let edgeBandings: number[] = []; - let maxIndex = 0; - const Parse = (params: KJL_Parameter[]) => - { - if (!params) return; - // console.table(params.map(p => - // { - // return { name: p.name, value: p.value }; - // })); - for (let param of params) - { - if (param.name === "ET") - { - edgeBandings.push(parseFloat(param.value)); - for (let i = 0; i < maxIndex - 1; i++) - edgeBandings[i] = arrayLast(edgeBandings); - maxIndex++; - break; - } - else if (param.name.startsWith("ET")) - { - let index = parseInt(param.name.substring(2)) - 1; - edgeBandings[index] = parseFloat(param.value); - maxIndex = Math.max(index, maxIndex); - } - } - }; - - Parse(model.constParameters); - Parse(model.ignoreParameters); - Parse(model.parameters); - - for (let i = 0; i < maxIndex; i++) - { - if (edgeBandings[i] === undefined) - edgeBandings[i] = edgeBandings[maxIndex]; - } - - if (edgeBandings.length > 0) - return edgeBandings; -} export async function ParseTopline(model: KJL_ParamModel, mtlLoader: KJLMaterialLoader, roomName: string, gName: string) { diff --git a/src/Add-on/KJL/KJLImportConfig/KJLConfig.tsx b/src/Add-on/KJL/KJLImportConfig/KJLConfig.tsx index 383f6a77e..3dde6bb11 100644 --- a/src/Add-on/KJL/KJLImportConfig/KJLConfig.tsx +++ b/src/Add-on/KJL/KJLImportConfig/KJLConfig.tsx @@ -1,25 +1,70 @@ -import { Checkbox } from "@blueprintjs/core"; +import { Checkbox, Radio, RadioGroup } from "@blueprintjs/core"; import { observer } from "mobx-react"; import React from "react"; import { KJLImportConfigStore } from "./KJLImportConfigStore"; - +export enum KJLUseName +{ + modelName = 0, + modelBrandGoodName = 1, +} @observer export default class KJLConfig extends React.Component<{ store: KJLImportConfigStore; }> { + EdgeValueMap = (edgeValueMap: [string, string][]) => + { + return ( +
+
封边值映射
+
+
+ +
酷家乐封边值
+
导入后实际值
+
+
+ { + edgeValueMap.map((d, i) => +
+ {i + 1} + d[0] = e.target.value} /> + d[1] = e.target.value} /> +
) + } +
+
+
+ ); + }; + render() { let store = this.props.store; return ( -
+
酷家乐导入配置信息
-
+
+ { store.m_Option.kjlUseName = parseInt(e.currentTarget.value); }} + > + + + { store.m_Option.isImportVirtualModel = !store.m_Option.isImportVirtualModel; }} /> +
+ { + this.EdgeValueMap(store.UIOption) + } +
diff --git a/src/Add-on/KJL/KJLImportConfig/KJLImportConfig.less b/src/Add-on/KJL/KJLImportConfig/KJLImportConfig.less index 5e998fdd2..f3ccb91ef 100644 --- a/src/Add-on/KJL/KJLImportConfig/KJLImportConfig.less +++ b/src/Add-on/KJL/KJLImportConfig/KJLImportConfig.less @@ -3,7 +3,7 @@ height: 550px; .bp3-tab-list { - font-weight:bold; + font-weight: bold; margin-left: 20px; .bp3-tab { @@ -24,7 +24,7 @@ .frame { border: 1px solid #ccc; - &>:nth-child(1) { + & > :nth-child(1) { font-size: 15px; font-weight: bold; margin-left: 20px; @@ -35,18 +35,66 @@ width: fit-content; } - &>:nth-child(2) { + & > :nth-child(2) { height: 480px; margin-left: 10px; overflow: scroll; - &>div{ + & > div { border: 1px solid #ccc; } } } - .KJLMaterialMap { + .kjl-config { + .radioGroup { + margin: 10px; + } + + .edge-value-map { + .edge-head { + margin: 3px; + font-weight: bold; + } + + .edge-body { + display: inline-block; + height: 234px; + border: 1px solid; + padding: 2px 10px; + + .edge-title { + padding-left: 20px; + display: flex; + + & > div { + width: 147px; + text-align: center; + } + } + + .edge-massage { + height: 209px; + overflow-y: scroll; + + .edge-massage-item { + :first-child { + display: inline-block; + width: 20px; + height: 20px; + text-align: center; + } + + input { + height: 20px; + } + } + } + } + } + } + + .KJLMaterialMap { .bp3-control { margin-bottom: 0; } @@ -57,11 +105,11 @@ grid-template-columns: 70px 1fr 289px 70px; - &>:nth-child(1) { + & > :nth-child(1) { margin-left: 10px; } - &>:nth-child(2) { + & > :nth-child(2) { margin-left: 20px; } } @@ -72,11 +120,11 @@ align-items: center; grid-template-columns: 70px 1fr 289px 70px; - &>:nth-child(1) { + & > :nth-child(1) { margin-left: 10px; } - &>:nth-child(2) { + & > :nth-child(2) { margin-left: 20px; input { @@ -102,7 +150,7 @@ cursor: pointer; } - &>:nth-child(3) { + & > :nth-child(3) { padding: 5px 0; height: 52px; display: grid; diff --git a/src/Add-on/KJL/KJLImportConfig/KJLImportConfigStore.ts b/src/Add-on/KJL/KJLImportConfig/KJLImportConfigStore.ts index ab6ec2ac8..495adceb7 100644 --- a/src/Add-on/KJL/KJLImportConfig/KJLImportConfigStore.ts +++ b/src/Add-on/KJL/KJLImportConfig/KJLImportConfigStore.ts @@ -7,8 +7,9 @@ import { Singleton } from "../../../Common/Singleton"; import { DefaultKJImportOption } from "../../../Editor/DefaultConfig"; import { IConfigOption } from "../../../UI/Components/Board/UserConfig"; import { AppToaster } from "../../../UI/Components/Toaster"; -import { KJLImportConfigOption } from "../../../UI/Store/BoardInterface"; +import { IUiOption, KJLImportConfigOption } from "../../../UI/Store/BoardInterface"; import { IConfigStore } from "../../../UI/Store/BoardStore"; +import { KJLUseName } from "./KJLConfig"; export interface MaterialOption { @@ -24,6 +25,7 @@ export class KJLImportConfigStore extends Singleton implements IConfigStore @observable configName: string = "默认"; @observable configsNames: string[] = []; @observable m_Option: KJLImportConfigOption = { ...DefaultKJImportOption }; + @observable m_uiEdgeValueMap: IUiOption<[string, string][]>; @observable materialList: MaterialOption[] = []; @observable selectAll = false; private queue = new PQueue({ concurrency: 100 }); @@ -31,9 +33,17 @@ export class KJLImportConfigStore extends Singleton implements IConfigStore InitOption() { Object.assign(this.m_Option, DefaultKJImportOption); + this.m_uiEdgeValueMap = Array.from({ length: 20 }, () => ["", ""]); this.LoadMaterials(); }; + get UIOption(): IUiOption<[string, string][]> + { + if (!this.m_uiEdgeValueMap) + this.m_uiEdgeValueMap = this.m_Option.edgeValueMap.map((d) => { return d[0] === 0 && d[1] === 0 ? ["", ""] : [d[0].toString(), d[1].toString()]; }); + return this.m_uiEdgeValueMap; + } + SaveConfig() { //保证保存的信息有效性 @@ -53,6 +63,14 @@ export class KJLImportConfigStore extends Singleton implements IConfigStore this.LoadMaterials(); } + let filter = this.m_uiEdgeValueMap.filter(d => { return !isNaN(parseFloat(d[0])) && !isNaN(parseFloat(d[1])); }); + this.m_uiEdgeValueMap = Array.from({ length: 20 }, () => ["", ""]); + for (let i = 0; i < filter.length; i++) + { + this.m_uiEdgeValueMap[i] = filter[i]; + } + this.m_Option.edgeValueMap = this.m_uiEdgeValueMap.map(d => { return [Number(d[0]), Number(d[1])]; }); + //新的配置 let newConfig: IConfigOption = {}; newConfig.option = toJS(this.m_Option); @@ -65,6 +83,16 @@ export class KJLImportConfigStore extends Singleton implements IConfigStore cof.option.version = 2; cof.option.isImportVirtualModel = true; } + if (cof.option.version < 3) + { + cof.option.version = 3; + cof.option.edgeValueMap = Array.from({ length: 20 }, () => [0, 0]); + } + if (cof.option.version < 4) + { + cof.option.version = 4; + cof.option.kjlUseName = KJLUseName.modelName; + } Object.assign(this.m_Option, cof.option); this.LoadMaterials(); } diff --git a/src/Editor/DefaultConfig.ts b/src/Editor/DefaultConfig.ts index 57c5d7a5f..ca1d2230f 100644 --- a/src/Editor/DefaultConfig.ts +++ b/src/Editor/DefaultConfig.ts @@ -1,3 +1,4 @@ +import { KJLUseName } from "../Add-on/KJL/KJLImportConfig/KJLConfig"; import { Curve2RecOption } from "../Add-on/twoD2threeD/Modals/Curve2RecOption"; import { IParseBoardNameOption, IRec2BrOption, IRect2Br2Option } from "../Add-on/twoD2threeD/R2bInterface"; import { EBoardKeyList } from "../Common/BoardKeyList"; @@ -191,9 +192,11 @@ export const DefaultModifyTextsOption: ModifyTextsConfigOption = { Object.freeze(DefaultModifyTextsOption); export const DefaultKJImportOption: KJLImportConfigOption = { - version: 2, + version: 4, materials: [], - isImportVirtualModel: true + isImportVirtualModel: true, + edgeValueMap: Array.from({ length: 20 }, () => [0, 0]), + kjlUseName: KJLUseName.modelName }; Object.freeze(DefaultKJImportOption); diff --git a/src/UI/Store/BoardInterface.ts b/src/UI/Store/BoardInterface.ts index 828668c93..9979a6d47 100644 --- a/src/UI/Store/BoardInterface.ts +++ b/src/UI/Store/BoardInterface.ts @@ -1,3 +1,4 @@ +import { KJLUseName } from "../../Add-on/KJL/KJLImportConfig/KJLConfig"; import { EBoardKeyList } from "../../Common/BoardKeyList"; import { ObjectId } from "../../DatabaseServices/ObjectId"; @@ -205,6 +206,8 @@ export interface KJLImportConfigOption extends IBaseOption { materials: MaterialMapOption[]; isImportVirtualModel: boolean; + edgeValueMap: [number, number][]; + kjlUseName: KJLUseName; } export interface MaterialMapOption {