mirror of https://gitee.com/cf-fz/WebCAD.git
!939 功能:设置见光面封边 命令:SetSmoothEdge
parent
4fde14ab05
commit
8423f5f25b
@ -0,0 +1,138 @@
|
||||
import { Button, Classes, H5, UL } from "@blueprintjs/core";
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from 'react';
|
||||
import { app } from "../../ApplicationServices/Application";
|
||||
import { CheckObjectType } from "../../Common/CheckoutVaildValue";
|
||||
import { Board } from "../../DatabaseServices/Entity/Board";
|
||||
import { Command } from "../../Editor/CommandMachine";
|
||||
import { PromptStatus } from "../../Editor/PromptResult";
|
||||
import { SetBoardDataItem } from "../../UI/Components/Board/BoardCommon";
|
||||
import { BoardModalType } from "../../UI/Components/Board/BoardModal";
|
||||
import { CommonModal } from "../../UI/Components/Modal/ModalContainer";
|
||||
import { userConfigStore } from "../../UI/Store/UserConfigStore";
|
||||
import { smoothEdgeStore, SmoothEdgeStore } from "./SmoothEdgeStore";
|
||||
import { SetSmoothEdges } from "./SetSmoothEdgeFace";
|
||||
|
||||
export class SetSmoothEdge implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let brRes = await app.Editor.GetSelection({
|
||||
Msg: "选择板件",
|
||||
Filter: { filterTypes: [Board] }
|
||||
});
|
||||
|
||||
if (brRes.Status === PromptStatus.Cancel) return;
|
||||
app.Editor.ModalManage.RenderModal(SetSmoothEdgeModal, { brs: brRes.SelectSet.SelectEntityList, store: smoothEdgeStore });
|
||||
|
||||
await app.Editor.ModalManage.Wait();
|
||||
}
|
||||
}
|
||||
|
||||
@observer
|
||||
class SetSmoothEdgeModal extends React.Component<{ brs: Board[]; store: SmoothEdgeStore; }>
|
||||
{
|
||||
renderItem = () =>
|
||||
{
|
||||
const store = this.props.store;
|
||||
const els: JSX.Element[] = [];
|
||||
const kv = {
|
||||
smoothEdge: "见光面封边",
|
||||
edge: "不见光封边",
|
||||
scale: "见光面比例",
|
||||
};
|
||||
for (let key in store.option)
|
||||
{
|
||||
if (key !== "filterArr")
|
||||
els.push(
|
||||
<SetBoardDataItem
|
||||
title={kv[key]}
|
||||
type={CheckObjectType.SmoothEdge}
|
||||
optKey={key}
|
||||
option={store.option}
|
||||
uiOption={store.UiOption}
|
||||
>
|
||||
{
|
||||
key === "scale" && "%"
|
||||
}
|
||||
</SetBoardDataItem>
|
||||
);
|
||||
}
|
||||
return els;
|
||||
};
|
||||
async UNSAFE_componentWillMount()
|
||||
{
|
||||
const smoothEdgeStore = this.props.store;
|
||||
if (!userConfigStore.readConfigs.has(BoardModalType.SmoothEdge))
|
||||
{
|
||||
await userConfigStore.UpdateBoardOption(smoothEdgeStore.configName, BoardModalType.SmoothEdge, smoothEdgeStore);
|
||||
}
|
||||
}
|
||||
render()
|
||||
{
|
||||
const { store } = this.props;
|
||||
|
||||
return (
|
||||
<CommonModal
|
||||
title="设置见光面封边"
|
||||
icon="bold"
|
||||
close={this.cancel}
|
||||
hasConfig={false}
|
||||
footerChildren={
|
||||
<>
|
||||
<Button
|
||||
className={Classes.INTENT_SUCCESS}
|
||||
text="确定"
|
||||
onClick={this.confirm} />
|
||||
<Button
|
||||
className={Classes.INTENT_DANGER}
|
||||
text="取消"
|
||||
onClick={this.cancel} />
|
||||
</>
|
||||
}
|
||||
footerStyle={{ width: "100%" }}
|
||||
>
|
||||
<div className="smooth-edge">
|
||||
{
|
||||
this.renderItem()
|
||||
}
|
||||
<H5>
|
||||
指定板名不参与计算
|
||||
</H5>
|
||||
<UL className={Classes.LIST_UNSTYLED}>
|
||||
{
|
||||
store.option.filterArr.map((s, i) => <li>
|
||||
<input type="text" value={store.option.filterArr[i]} onChange={e => store.option.filterArr[i] = e.target.value} />
|
||||
</li>)
|
||||
}
|
||||
</UL>
|
||||
</div>
|
||||
</CommonModal>
|
||||
);
|
||||
}
|
||||
confirm = () =>
|
||||
{
|
||||
const store = this.props.store;
|
||||
app.Editor.ModalManage.Destory();
|
||||
const brs = this.props.brs;
|
||||
if (this.props.brs.length === 1)
|
||||
{
|
||||
let edge = store.option.smoothEdge.toString();
|
||||
this.props.brs[0].BoardProcessOption.sealedLeft = edge;
|
||||
this.props.brs[0].BoardProcessOption.sealedRight = edge;
|
||||
this.props.brs[0].BoardProcessOption.sealedUp = edge;
|
||||
this.props.brs[0].BoardProcessOption.sealedDown = edge;
|
||||
this.props.brs[0].BoardProcessOption.highSealed.forEach(d => d.size = store.option.smoothEdge);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetSmoothEdges(brs, store.option);
|
||||
}
|
||||
|
||||
userConfigStore.SaveConfig(BoardModalType.SmoothEdge, store, { toaster: false });
|
||||
};
|
||||
cancel = () =>
|
||||
{
|
||||
app.Editor.ModalManage.Destory();
|
||||
};
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
import { BoardGetFace, GetSideFaceMtx, BoardFaceType, MatrixIsCoplane2 } from "../../Geometry/DrillParse/BoardGetFace";
|
||||
import { Curve } from "../../DatabaseServices/Entity/Curve";
|
||||
import { equaln } from "../../Geometry/GeUtils";
|
||||
import { Arc } from "../../DatabaseServices/Entity/Arc";
|
||||
import { GetBoardSealingCurves, GetBoardHighSeal, HandleRectBoardSealingData } from "../../GraphicsSystem/CalcEdgeSealing";
|
||||
import { Face } from "../../Geometry/DrillParse/Face";
|
||||
import { Matrix4 } from "three";
|
||||
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
|
||||
import { Board } from "../../DatabaseServices/Entity/Board";
|
||||
import { Box3Ext } from "../../Geometry/Box";
|
||||
import { ISmoothEdgeOption, IHighSealedItem } from "../../UI/Store/BoardInterface";
|
||||
|
||||
class SetSmoothEdgeFaces extends BoardGetFace
|
||||
{
|
||||
FaceSealingDataMap: Map<Face, number>;
|
||||
SmoothFace = new Set<Face>();
|
||||
highSealingData: IHighSealedItem[];
|
||||
private sealCus: Curve[];
|
||||
constructor(public Board: Board)
|
||||
{
|
||||
super(Board);
|
||||
}
|
||||
GetTopAndBottomFace()
|
||||
{
|
||||
super.GetTopAndBottomFace(true);
|
||||
}
|
||||
GetSideFaces()
|
||||
{
|
||||
this.FaceSealingDataMap = new Map();
|
||||
let con = this.Board.ContourCurve.Clone();
|
||||
let inverseZ = con.Area2 < 0;
|
||||
let sealCus = GetBoardSealingCurves(this.Board);
|
||||
this.highSealingData = GetBoardHighSeal(this.Board, sealCus);
|
||||
this.sealCus = sealCus;
|
||||
for (let i = 0; i < sealCus.length; i++)
|
||||
{
|
||||
let sealCu = sealCus[i];
|
||||
let cus: Curve[];
|
||||
if (sealCu instanceof Polyline)
|
||||
{
|
||||
cus = sealCu.Explode();
|
||||
}
|
||||
else
|
||||
cus = [sealCu];
|
||||
|
||||
for (let cu of cus)
|
||||
{
|
||||
let length = cu.Length;
|
||||
if (equaln(length, 0) || cu instanceof Arc)
|
||||
continue;
|
||||
let mtx = GetSideFaceMtx(cu, inverseZ);
|
||||
let f = new Face({
|
||||
type: BoardFaceType.Side,
|
||||
localBoard: this.Board,
|
||||
isPositiveFace: true,
|
||||
matrix4: new Matrix4().multiplyMatrices(this.Board.OCS.clone(), mtx),
|
||||
length,
|
||||
width: this.Board.Thickness,
|
||||
});
|
||||
this.FaceSealingDataMap.set(f, i);
|
||||
this.Faces.push(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
GetSmoothFaces(bg: this)
|
||||
{
|
||||
for (let f1 of this.Faces)
|
||||
{
|
||||
if (this.SmoothFace.has(f1)) continue;
|
||||
for (let f2 of bg.Faces)
|
||||
{
|
||||
if (bg.SmoothFace.has(f2)) continue;
|
||||
|
||||
//都是正面,或者不允许侧面同侧面并且2板件类型不一样就跳过
|
||||
if (f1.type === f2.type
|
||||
&& (f1.type === BoardFaceType.NoSide || bg.Board.BoardType !== this.Board.BoardType)
|
||||
)
|
||||
continue;
|
||||
//不共面
|
||||
if (!MatrixIsCoplane2(f1.OCS, f2.OCS, 1e-2))
|
||||
continue;
|
||||
if (f1.IsIntersect(f2))
|
||||
{
|
||||
if (f1.type === BoardFaceType.Side)
|
||||
{
|
||||
this.SmoothFace.add(f1);
|
||||
}
|
||||
if (f2.type === BoardFaceType.Side)
|
||||
{
|
||||
bg.SmoothFace.add(f2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
WriteSealingData(option: ISmoothEdgeOption)
|
||||
{
|
||||
let useIndex = new Set<number>();
|
||||
|
||||
for (let f of this.Faces)
|
||||
{
|
||||
if (f.type === BoardFaceType.Side && !this.SmoothFace.has(f))
|
||||
{
|
||||
let index = this.FaceSealingDataMap.get(f);
|
||||
if (index !== undefined)
|
||||
{
|
||||
this.highSealingData[index].size = option.smoothEdge;
|
||||
useIndex.add(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < this.highSealingData.length; i++)
|
||||
{
|
||||
if (!useIndex.has(i))
|
||||
this.highSealingData[i].size = option.edge;
|
||||
}
|
||||
|
||||
this.Board.BoardProcessOption.highSealed = this.highSealingData;
|
||||
HandleRectBoardSealingData(this.Board, this.highSealingData, this.sealCus);
|
||||
}
|
||||
}
|
||||
|
||||
export function SetSmoothEdges(brs: Board[], option: ISmoothEdgeOption)
|
||||
{
|
||||
if (brs.length === 0) return;
|
||||
let BoardGeList: SetSmoothEdgeFaces[] = [];
|
||||
let boxCache: Map<Board, Box3Ext> = new Map();
|
||||
let ocsInv = brs[0].OCSInv;
|
||||
|
||||
let filterArr = option.filterArr.filter(s => s);
|
||||
|
||||
for (let b of brs)
|
||||
{
|
||||
BoardGeList.push(new SetSmoothEdgeFaces(b));
|
||||
boxCache.set(b, b.GetBoundingBoxInMtx(ocsInv));
|
||||
}
|
||||
|
||||
for (let i = 0; i < BoardGeList.length; i++)
|
||||
{
|
||||
let f = BoardGeList[i];
|
||||
let localBox = boxCache.get(f.Board);
|
||||
if (filterArr.some(s => f.Board.Name.includes(s))) continue;
|
||||
|
||||
for (let j = i + 1; j < BoardGeList.length; j++)
|
||||
{
|
||||
let f1 = BoardGeList[j];
|
||||
|
||||
let interBox = boxCache.get(f1.Board);
|
||||
|
||||
//板件包围盒相交
|
||||
if (localBox.intersectsBox(interBox, 1e-2))
|
||||
f.GetSmoothFaces(f1);
|
||||
}
|
||||
}
|
||||
|
||||
for (let brGe of BoardGeList)
|
||||
{
|
||||
brGe.WriteSealingData(option);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
import { IConfigStore } from "../../UI/Store/BoardStore";
|
||||
import { observable, toJS } from "mobx";
|
||||
import { ISmoothEdgeOption, IUiOption } from "../../UI/Store/BoardInterface";
|
||||
import { IConfigOption } from "../../UI/Components/Board/UserConfig";
|
||||
import { DataAdapter } from "../../Common/DataAdapter";
|
||||
|
||||
export class SmoothEdgeStore implements IConfigStore
|
||||
{
|
||||
@observable option: ISmoothEdgeOption = {
|
||||
smoothEdge: 0,
|
||||
edge: 0,
|
||||
scale: 5,
|
||||
filterArr: new Array(10).fill(""),
|
||||
};
|
||||
@observable uiOption: IUiOption<ISmoothEdgeOption>;
|
||||
configName = "default";
|
||||
configsNames = ['default'];
|
||||
InitOption()
|
||||
{
|
||||
Object.assign(this.option, {
|
||||
smoothEdge: 0,
|
||||
edge: 0,
|
||||
scale: 5,
|
||||
filterArr: new Array(10).fill(""),
|
||||
});
|
||||
}
|
||||
get UiOption()
|
||||
{
|
||||
if (!this.uiOption)
|
||||
this.uiOption = DataAdapter.ConvertUIData(this.option);
|
||||
return this.uiOption;
|
||||
}
|
||||
SaveConfig()
|
||||
{
|
||||
//新的配置
|
||||
let newConfig: IConfigOption<ISmoothEdgeOption> = {};
|
||||
newConfig.option = toJS(this.option);
|
||||
return newConfig;
|
||||
}
|
||||
UpdateOption(cof: IConfigOption<ISmoothEdgeOption>)
|
||||
{
|
||||
Object.assign(this.option, cof.option);
|
||||
if (this.uiOption)
|
||||
Object.assign(this.uiOption, DataAdapter.ConvertUIData(cof.option));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const smoothEdgeStore = new SmoothEdgeStore();
|
@ -0,0 +1,20 @@
|
||||
#commonModal {
|
||||
.smooth-edge {
|
||||
padding-left: 30px;
|
||||
|
||||
.br-set {
|
||||
span {
|
||||
width: 70px;
|
||||
}
|
||||
}
|
||||
|
||||
&>ul {
|
||||
height: 100px;
|
||||
overflow: auto;
|
||||
|
||||
li {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue