!2266 优化:门板拉手位置支持给出备注信息

pull/2338/head
黄诗津 1 year ago committed by ChenX
parent d6ef4049a7
commit 338225ca3e

@ -304,6 +304,18 @@ export class DrawDoorTool
handleTemp.LParam.expr = "0";
handleTemp.WParam.expr = "0";
handleTemp.RYParam.expr = this.option.handleAngle;
//在创建拉手时将关联信息写入到拉手和关联门板上
const door = doorTr.Entitys[0];
const handles = handleTemp.Entitys as HardwareCompositeEntity[];
for (const handle of handles)
{
handle.RelevanceBoards?.push(door.Id);
if (door instanceof Board)
door.RelativeHandle.push(handle.Id);
else if (door instanceof HardwareCompositeEntity)
door.RelevanceHandle.push(handle.Id);
}
}
}
protected GetHingeTemp(info: IDoorInfo, door: TemplateRecord)

@ -0,0 +1,141 @@
import { Vector2, Vector3 } from "three";
import { app } from "../../ApplicationServices/Application";
import { arrayPushArray } from "../../Common/ArrayExt";
import { Log } from "../../Common/Log";
import { Intent } from "../../Common/Toaster";
import { CADObject } from "../../DatabaseServices/CADObject";
import { Board } from "../../DatabaseServices/Entity/Board";
import { Entity } from "../../DatabaseServices/Entity/Entity";
import { HardwareCompositeEntity } from "../../DatabaseServices/Hardware/HardwareCompositeEntity";
import { ObjectId } from "../../DatabaseServices/ObjectId";
import { Command } from "../../Editor/CommandMachine";
import { PromptStatus } from "../../Editor/PromptResult";
import { ComparePointFnGenerate } from "../../Geometry/GeUtils";
import { AppToaster } from "../../UI/Components/Toaster";
import { FuzzyFactory } from "../../csg/core/FuzzyFactory";
import { IsDoor } from "../HideSelect/HideSelectUtils";
export class ParseHandle implements Command
{
async exec()
{
Log("注意:绘制的拉手五金名称必须包含\"拉手\"");
let res = await app.Editor.GetSelection({
Msg: "请选择需要分析拉手的门板:",
Filter: {
filterFunction: (o, e) => { return e && IsDoor(e); }
}
});
if (res.Status === PromptStatus.OK)
{
let doors = res.SelectSet.SelectEntityList as Entity[];
let succeedCount = 0;
let emptyCount = 0;
for (let door of doors)
{
let HandleMap = new Map<string, Vector2[]>(); // 关系表 <把手名,位置XY信息>
let dataList: [string, string][] = [];
let handleMarks: [string, string][] = [];
let handleObjId: ObjectId[] = [];
if (door instanceof Board)
{
handleObjId = door.RelativeHandle;
dataList = door.BoardProcessOption.remarks;
}
else if (door instanceof HardwareCompositeEntity)
{
handleObjId = door.RelevanceHandle;
dataList = door.DataList;
}
ParsehandleToDoor(door, handleObjId, HandleMap);
//会去掉所有之前的"ls"开头的备注
let remarks = dataList.filter(r => !(HandleMap.has(r[0]) || r[0].substring(0, 2) === "ls"));
convertToString(HandleMap, handleMarks);
handleMarks.sort((h1, h2) => h1[0].localeCompare(h2[0]));
if (handleMarks.length)
{
arrayPushArray(remarks, handleMarks);
if (door instanceof Board)
door.BoardProcessOption.remarks = remarks;
else if (door instanceof HardwareCompositeEntity)
door.DataList = remarks;
succeedCount++;
}
else
emptyCount++;
}
if (succeedCount)
{
AppToaster.show({
message: `成功分析${succeedCount}个门板的拉手位置!(已经写入到板件备注!)`,
timeout: 10000,
intent: Intent.SUCCESS,
});
}
if (emptyCount)
{
AppToaster.show({
message: `${emptyCount}个门板没有拉手!`,
timeout: 10000,
intent: Intent.WARNING,
});
}
}
}
}
function convertToString(hingeAndHandleMap: Map<string, Vector2[]>, hingeMarks: [string, string][])
{
for (let d of hingeAndHandleMap)
{
let arr = d[1];
arr.sort(ComparePointFnGenerate("xy"));
if (arr.every(p => p.x === arr[0].x)) //所有的X都相等
hingeMarks.push([d[0], `X:${arr[0].x} Y:${arr.map(p => p.y).join(",")}`]);
else if (arr.every(p => p.y === arr[0].y))
hingeMarks.push([d[0], `Y:${arr[0].y} X:${arr.map(p => p.x).join(",")}`]);
else
hingeMarks.push([d[0], "位置(x,y): " + arr.map(p => `(${p.x},${p.y})`).join(", ")]);
}
}
/**
*
* @param {Entity} door
* @param {ObjectId<CADObject>[]} handleObjId
* @param {Map<string, Vector2[]>} HandleMap <,XY>
*/
function ParsehandleToDoor(door: Entity, handleObjId: ObjectId<CADObject>[], HandleMap: Map<string, Vector2[]>)
{
let doorBox = door.Clone().ApplyMatrix(door.SpaceOCSInv).BoundingBox;
let fuzz = new FuzzyFactory(1, 0.1);
for (let hand of handleObjId)
{
let handle = hand?.Object;
if (!handle || handle.IsErase || !(handle instanceof HardwareCompositeEntity))
continue;
if (handle.HardwareOption.name.includes("拉手"))
{
let pos = new Vector3().setFromMatrixPosition(handle.Clone().ApplyMatrix(door.SpaceOCSInv).SpaceOCS).sub(doorBox.min);
let key = "ls-" + handle.HardwareOption.name;
let posArr = HandleMap.get(key);
if (!posArr)
{
posArr = [];
HandleMap.set(key, posArr);
}
posArr.push(new Vector2(fuzz.lookupOrCreate([pos.x], Math.round(pos.x)), Math.round(pos.z)));
}
}
}

@ -3,7 +3,6 @@ import { app } from "../../ApplicationServices/Application";
import { arrayPushArray } from "../../Common/ArrayExt";
import { Log } from "../../Common/Log";
import { Intent } from "../../Common/Toaster";
import { FuzzyFactory } from "../../csg/core/FuzzyFactory";
import { CADObject } from "../../DatabaseServices/CADObject";
import { Board } from "../../DatabaseServices/Entity/Board";
import { Entity } from "../../DatabaseServices/Entity/Entity";
@ -13,6 +12,7 @@ import { Command } from "../../Editor/CommandMachine";
import { PromptStatus } from "../../Editor/PromptResult";
import { ComparePointFnGenerate } from "../../Geometry/GeUtils";
import { AppToaster } from "../../UI/Components/Toaster";
import { FuzzyFactory } from "../../csg/core/FuzzyFactory";
import { IsDoor } from "../HideSelect/HideSelectUtils";
export class ParseHinge implements Command
@ -53,7 +53,8 @@ export class ParseHinge implements Command
ParseHingeToDoor(door, hingObjId, hingeMap);
let remarks = dataList.filter(r => !hingeMap.has(r[0]));
//会去掉所有之前的"jl"开头的备注
let remarks = dataList.filter(r => !(hingeMap.has(r[0]) || r[0].substring(0, 2) === "jl"));
convertToString(hingeMap, hingeMarks);
hingeMarks.sort((h1, h2) => h1[0].localeCompare(h2[0]));

@ -297,6 +297,7 @@ export enum CommandNames
R2B2 = "RECT2BOARD2",
FixIntSelfContour = "FIXINTSELFCONTOUR",
ParseHinge = "PARSEHINGE",//分析门板的铰链
ParseHandle = "PARSEHANDLE",//分析门板的拉手
ZhengWen = "ZHENGWEN",
FanWen = "FANWEN",
KeFanZuan = "KEFANZUAN",

@ -117,6 +117,7 @@ export class Board extends ExtrudeSolid
private _LayerNails: ObjectId[] = [];
@AutoRecord RelativeHardware: ObjectId[] = [];
private _OpenDir: BoardOpenDir = BoardOpenDir.None;
@AutoRecord RelativeHandle: ObjectId[] = [];
private _IsChaiDan: boolean = true;
private _2DModelingList: I2DModeling[] = [];
private _3DModelingList: I3DModeling[] = [];
@ -1968,12 +1969,24 @@ export class Board extends ExtrudeSolid
// if (this.width === 0 || this.height === 0) //板件变成0长度,无法绘制
// this._isErase = true;
if (ver > 12)
{
let count = file.Read();
this.RelativeHandle.length = 0;
for (let i = 0; i < count; i++)
{
let objId = file.ReadObjectId();
if (objId)
this.RelativeHandle.push(objId);
}
}
}
WriteFile(file: CADFiler)
{
super.WriteFile(file);
file.Write(12);
file.Write(13);
// file.Write(this._SpaceOCS.toArray()); ver < 6
file.Write(this._BoardType);
file.Write(this._Name);
@ -2018,6 +2031,10 @@ export class Board extends ExtrudeSolid
file.Write(id);
file.WriteObject(pl);
}
file.Write(this.RelativeHandle.length);
for (let id of this.RelativeHandle)
file.WriteObjectId(id);
}
}

@ -18,6 +18,7 @@ export class HardwareCompositeEntity extends CompositeEntity
@AutoRecord DataList: [string, string][] = [];
@AutoRecord RelevanceBoards: ObjectId[] = [];
@AutoRecord RelevanceHardware: ObjectId[] = []; //当这个实体为复合板时,关联五金的信息
@AutoRecord RelevanceHandle: ObjectId[] = []; //关联拉手
/**
*
* @param [checkIsHole=false] true: false:
@ -109,13 +110,25 @@ export class HardwareCompositeEntity extends CompositeEntity
for (let i = 0; i < count; i++)
this.RelevanceHardware.push(file.ReadSoftObjectId());
}
if (v > 4)
{
let count = file.Read();
this.RelevanceHandle.length = 0;
for (let i = 0; i < count; i++)
{
let objId = file.ReadObjectId();
if (objId)
this.RelevanceHandle.push(objId);
}
}
}
//对象将自身数据写入到文件.
WriteFile(file: CADFiler)
{
super.WriteFile(file);
file.Write(4);
file.Write(5);
file.Write(this.HardwareOption.type);
file.Write(this.HardwareOption.isSplite);
@ -150,5 +163,9 @@ export class HardwareCompositeEntity extends CompositeEntity
file.Write(this.RelevanceHardware.length);
for (let id of this.RelevanceHardware)
file.WriteSoftObjectId(id);
file.Write(this.RelevanceHandle.length);
for (let id of this.RelevanceHandle)
file.WriteSoftObjectId(id);
}
}

@ -65,7 +65,6 @@ import { DrawVerticalBoard } from "../Add-on/DrawBoard/DrawVerticalBoard";
import { EditorBoardTemplate } from "../Add-on/DrawBoard/EditorBoardTempate";
import { FindMaxOrMinSizeBoard } from "../Add-on/DrawBoard/FindMaxSizeBoard";
import { FixIntersectSelfContour } from "../Add-on/DrawBoard/FixIntersectSelfContour";
import { ParseHinge } from "../Add-on/DrawBoard/ParseHinge";
import { SetHoleNoneType } from "../Add-on/DrawBoard/SetHoleType";
import { DrawCircle } from "../Add-on/DrawCircle";
import { DrawCylineder } from "../Add-on/DrawCylinder";
@ -213,6 +212,8 @@ import { Command_GroovesModify } from "../Add-on/showModal/GroovesModify";
import { ShowEditorBBS } from "../Add-on/showModal/ShowModal";
// import { DrawFloor } from '../Add-on/DrawFloor';
// import { RevTarget, SaveTarget } from '../Add-on/RenderTarget';
import { ParseHandle } from "../Add-on/DrawBoard/ParseHandle";
import { ParseHinge } from "../Add-on/DrawBoard/ParseHinge";
import { TestFb } from "../Add-on/TestFb";
import { Command_TestPointPickParse } from "../Add-on/TestPointPickParse";
import { Text2Curve } from "../Add-on/Text2Curve";
@ -792,6 +793,7 @@ export function registerCommand()
commandMachine.RegisterCommand("fix2dpath", new Command_Fix2DPath());
commandMachine.RegisterCommand(CommandNames.ParseHinge, new ParseHinge());
commandMachine.RegisterCommand(CommandNames.ParseHandle, new ParseHandle());
commandMachine.RegisterCommand(CommandNames.ZhengWen, new SetBoardLines(0));
commandMachine.RegisterCommand(CommandNames.FanWen, new SetBoardLines(1));
commandMachine.RegisterCommand(CommandNames.KeFanZuan, new SetBoardLines(2));

@ -900,6 +900,15 @@ export const CommandList: ICommand[] = [
chName: "将铰链位置写入到门板备注",
chDes: "报表可写出",
},
{
typeId: "bjbj",
link: `#`,
defaultCustom: CommandNames.ParseHandle,
command: CommandNames.ParseHandle,
type: "板件编辑",
chName: "将拉手位置写入到门板备注",
chDes: "报表可写出",
},
{
typeId: "bjbj",
link: `${HelpUrlBase}Tool/SimulationTool`,

@ -636,16 +636,20 @@ export class TemplateManage extends React.Component<ITemplateManage, {}> {
{
//板换板
this.extendRelativeHinge(ent.RelativeHardware, template.Entitys);
this.ExtendRelativeHandle(ent.RelativeHandle, template.Entitys);
}
else if (ent instanceof HardwareCompositeEntity)
{
//铰链替换铰链
if (IsHinge(ent))
this.extendRelativeBoard(ent as HardwareCompositeEntity, template.Entitys);
this.extendRelativeBoard(ent, template.Entitys);
else if (IsHandle(ent))
this.ExtendHandleRelativeBoard(ent, template.Entitys);
else
{
//门板替换门板
this.extendRelativeHinge(ent.RelevanceHardware, template.Entitys);
this.ExtendRelativeHandle(ent.RelevanceHandle, template.Entitys);
}
}
}
@ -703,7 +707,7 @@ export class TemplateManage extends React.Component<ITemplateManage, {}> {
if (!template)
return;
let doors = brRes.SelectSet.SelectEntityList as Board[];
let doors = brRes.SelectSet.SelectEntityList as (Board | HardwareCompositeEntity)[];
for (let door of doors)
{
@ -812,6 +816,32 @@ export class TemplateManage extends React.Component<ITemplateManage, {}> {
}
}
/**
*
* @param handles
* @param templateEnts Ents
*/
private ExtendRelativeHandle = (handles: ObjectId<CADObject>[], templateEnts: Entity[]) =>
{
for (let hand of handles)
{
let handle = hand?.Object;
if (handle instanceof HardwareCompositeEntity)
{
//拉手的关联板只有当前门板id的集合,所以这里清空旧门板id
handle.RelevanceBoards = [];
for (let ent of templateEnts)
{
handle.RelevanceBoards.push(ent.Id);
if (ent instanceof Board)
ent.RelativeHandle.push(handle.Id);
else if (ent instanceof HardwareCompositeEntity)
ent.RelevanceHandle.push(handle.Id);
}
}
}
};
/**
* ()
* @param hardwareEnt ()
@ -867,6 +897,61 @@ export class TemplateManage extends React.Component<ITemplateManage, {}> {
}
}
/**
* ()
* @param handleEnt ()
* @param templateEnts Ents ()
*/
private ExtendHandleRelativeBoard(handleEnt: HardwareCompositeEntity, templateEnts: Entity[])
{
for (let boardId of handleEnt.RelevanceBoards)
{
let board = boardId?.Object; //门板的实体
if (!board) continue;
const relativeDoor = (handEnt: Entity, door: Entity) =>
{
if (handEnt instanceof Board)
{
// 拉手 是板类型的?
handEnt.RelativeHandle.push(door.Id);
}
else if (handEnt instanceof HardwareCompositeEntity)
{
if (!handEnt.RelevanceBoards.includes(door.Id))
handEnt.RelevanceBoards.push(door.Id);
}
};
if (board instanceof Board)
{
arrayRemoveOnce(board.RelativeHandle, handleEnt.objectId);
for (let ent of templateEnts)
{
//门板 重新关联新的拉手
if (!board.RelativeHandle.includes(ent.Id))
board.RelativeHandle.push(ent.Id);
//新的拉手 关联门板或者柜子
relativeDoor(ent, board);
}
}
else if (board instanceof HardwareCompositeEntity)
{
arrayRemoveOnce(board.RelevanceHandle, handleEnt.objectId);
for (let ent of templateEnts)
{
//门板 重新关联新的拉手
if (!board.RelevanceHandle.includes(ent.Id))
board.RelevanceHandle.push(ent.Id);
//新的拉手 关联门板
relativeDoor(ent, board);
}
}
}
}
getSpaceAllEntitys(door: Entity)
{
let box = door.BoundingBox.clone();

@ -173,6 +173,17 @@ export class TemplateDrawHandleTool
}
//#endregion
//在创建拉手时将关联信息写入到拉手和关联门板上
const handles = handleTemp.Entitys as HardwareCompositeEntity[];
for (const handle of handles)
{
handle.RelevanceBoards?.push(door.Id);
if (door instanceof Board)
door.RelativeHandle.push(handle.Id);
else if (door instanceof HardwareCompositeEntity)
door.RelevanceHandle.push(handle.Id);
}
await handleDoorSpaceTr.UpdateTemplateTree();
};
}

Loading…
Cancel
Save